From: <dai...@us...> - 2016-04-25 09:53:55
|
Revision: 7494 http://sourceforge.net/p/web-erp/reponame/7494 Author: daintree Date: 2016-04-25 09:53:53 +0000 (Mon, 25 Apr 2016) Log Message: ----------- Jan Bakke: improvements to allow gif and png images Modified Paths: -------------- trunk/ContractBOM.php trunk/Contracts.php trunk/FixedAssetItems.php trunk/GetStockImage.php trunk/GoodsReceived.php trunk/Manufacturers.php trunk/PDFPriceList.php trunk/PO_Items.php trunk/SalesCategories.php trunk/SelectCreditItems.php trunk/SelectProduct.php trunk/StockClone.php trunk/StockDispatch.php trunk/Stocks.php trunk/SupplierTenderCreate.php trunk/SupplierTenders.php trunk/WorkOrderEntry.php trunk/WorkOrderIssue.php trunk/Z_ChangeStockCode.php trunk/Z_ItemsWithoutPicture.php trunk/doc/Change.log Modified: trunk/ContractBOM.php =================================================================== --- trunk/ContractBOM.php 2016-04-16 01:37:00 UTC (rev 7493) +++ trunk/ContractBOM.php 2016-04-25 09:53:53 UTC (rev 7494) @@ -370,10 +370,19 @@ $k=1; } - if (file_exists( $_SESSION['part_pics_dir'] . '/' . $myrow['stockid'] . '.jpg') ) { - $ImageSource = '<img src="GetStockImage.php?automake=1&textcolor=FFFFFF&bgcolor=CCCCCC&StockID=' . $myrow['stockid']. '&text=&width=50&height=50" />'; + $SupportedImgExt = array('png','jpg','jpeg'); + $imagefile = reset((glob($_SESSION['part_pics_dir'] . '/' . $myrow['stockid'] . '.{' . implode(",", $SupportedImgExt) . '}', GLOB_BRACE))); + if (extension_loaded('gd') && function_exists('gd_info') && file_exists ($imagefile) ) { + $ImageSource = '<img src="GetStockImage.php?automake=1&textcolor=FFFFFF&bgcolor=CCCCCC'. + '&StockID='.urlencode($myrow['stockid']). + '&text='. + '&width=64'. + '&height=64'. + '" alt="" />'; + } else if (file_exists ($imagefile)) { + $ImageSource = '<img src="' . $imagefile . '" height="100" width="100" />'; } else { - $ImageSource = '<i>' . _('No Image') . '</i>'; + $ImageSource = _('No Image'); } echo '<td>' . $myrow['stockid'] . '</td> Modified: trunk/Contracts.php =================================================================== --- trunk/Contracts.php 2016-04-16 01:37:00 UTC (rev 7493) +++ trunk/Contracts.php 2016-04-25 09:53:53 UTC (rev 7494) @@ -110,16 +110,20 @@ echo '<a href="'. $RootPath . '/SelectContract.php">' . _('Back to Contract Selection'). '</a><br />'; +$SupportedImgExt = array('png','jpg','jpeg'); + //attempting to upload the drawing image file if (isset($_FILES['Drawing']) AND $_FILES['Drawing']['name'] !='' AND $_SESSION['Contract'.$identifier]->ContractRef!='') { $result = $_FILES['Drawing']['error']; + $ImgExt = pathinfo($_FILES['Drawing']['name'], PATHINFO_EXTENSION); + $UploadTheFile = 'Yes'; //Assume all is well to start off with - $filename = $_SESSION['part_pics_dir'] . '/' . $_SESSION['Contract'.$identifier]->ContractRef . '.jpg'; + $filename = $_SESSION['part_pics_dir'] . '/' . $_SESSION['Contract'.$identifier]->ContractRef . '.' . $ImgExt; - //But check for the worst - if (mb_strtoupper(mb_substr(trim($_FILES['Drawing']['name']),mb_strlen($_FILES['Drawing']['name'])-3))!='JPG'){ - prnMsg(_('Only jpg files are supported - a file extension of .jpg is expected'),'warn'); + //But check for the worst + if (!in_array ($ImgExt, $SupportedImgExt)) { + prnMsg(_('Only ' . implode(", ", $SupportedImgExt) . ' files are supported - a file extension of ' . implode(", ", $SupportedImgExt) . ' is expected'),'warn'); $UploadTheFile ='No'; } elseif ( $_FILES['Drawing']['size'] > ($_SESSION['MaxImageSize']*1024)) { //File Size Check prnMsg(_('The file size is over the maximum allowed. The maximum size allowed in KB is') . ' ' . $_SESSION['MaxImageSize'],'warn'); @@ -127,12 +131,15 @@ } elseif ( $_FILES['Drawing']['type'] == 'text/plain' ) { //File Type Check prnMsg( _('Only graphics files can be uploaded'),'warn'); $UploadTheFile ='No'; - } elseif (file_exists($filename)){ - prnMsg(_('Attempting to overwrite an existing item image'),'warn'); - $result = unlink($filename); - if (!$result){ - prnMsg(_('The existing image could not be removed'),'error'); - $UploadTheFile ='No'; + } + foreach ($SupportedImgExt as $ext) { + $file = $_SESSION['part_pics_dir'] . '/' . $_SESSION['Contract'.$identifier]->ContractRef . '.' . $ext; + if (file_exists ($file) ) { + $result = unlink($file); + if (!$result){ + prnMsg(_('The existing image could not be removed'),'error'); + $UploadTheFile ='No'; + } } } @@ -913,9 +920,14 @@ <td>' . _('Contract Description') . ':</td> <td><textarea name="ContractDescription" style="width:100%" required="required" title="' . _('A description of the contract is required') . '" minlength="5" rows="5" cols="40">' . $_SESSION['Contract'.$identifier]->ContractDescription . '</textarea></td> </tr><tr> - <td>' . _('Drawing File') . ' .jpg' . ' ' . _('format only') .':</td> - <td><input type="file" id="Drawing" name="Drawing" /></td> - </tr>'; + <td>' . _('Drawing File') . ' ' . implode(", ", $SupportedImgExt) . ' ' . _('format only') .':</td> + <td><input type="file" id="Drawing" name="Drawing" /> + + </td>'; + + $imagefile = reset((glob($_SESSION['part_pics_dir'] . '/' . $_SESSION['Contract'.$identifier]->ContractRef . '.{' . implode(",", $SupportedImgExt) . '}', GLOB_BRACE))); + echo '<td> ' . $imagefile . '</td>'; + echo '</tr>'; if (!isset($_SESSION['Contract'.$identifier]->RequiredDate)) { $_SESSION['Contract'.$identifier]->RequiredDate = DateAdd(date($_SESSION['DefaultDateFormat']),'m',1); Modified: trunk/FixedAssetItems.php =================================================================== --- trunk/FixedAssetItems.php 2016-04-16 01:37:00 UTC (rev 7493) +++ trunk/FixedAssetItems.php 2016-04-25 09:53:53 UTC (rev 7494) @@ -27,15 +27,17 @@ $AssetID = ''; } +$SupportedImgExt = array('png','jpg','jpeg'); + if (isset($_FILES['ItemPicture']) AND $_FILES['ItemPicture']['name'] !='') { + $ImgExt = pathinfo($_FILES['ItemPicture']['name'], PATHINFO_EXTENSION); $result = $_FILES['ItemPicture']['error']; $UploadTheFile = 'Yes'; //Assume all is well to start off with - $filename = $_SESSION['part_pics_dir'] . '/ASSET_' . $AssetID . '.jpg'; - - //But check for the worst - if (mb_strtoupper(mb_substr(trim($_FILES['ItemPicture']['name']),mb_strlen($_FILES['ItemPicture']['name'])-3))!='JPG'){ - prnMsg(_('Only jpg files are supported - a file extension of .jpg is expected'),'warn'); + $filename = $_SESSION['part_pics_dir'] . '/ASSET_' . $AssetID . '.' . $ImgExt; + //But check for the worst + if (!in_array ($ImgExt, $SupportedImgExt)) { + prnMsg(_('Only ' . implode(", ", $SupportedImgExt) . ' files are supported - a file extension of ' . implode(", ", $SupportedImgExt) . ' is expected'),'warn'); $UploadTheFile ='No'; } elseif ( $_FILES['ItemPicture']['size'] > ($_SESSION['MaxImageSize']*1024)) { //File Size Check prnMsg(_('The file size is over the maximum allowed. The maximum size allowed in KB is') . ' ' . $_SESSION['MaxImageSize'],'warn'); @@ -43,12 +45,15 @@ } elseif ( $_FILES['ItemPicture']['type'] == 'text/plain' ) { //File Type Check prnMsg( _('Only graphics files can be uploaded'),'warn'); $UploadTheFile ='No'; - } elseif (file_exists($filename)){ - prnMsg(_('Attempting to overwrite an existing item image'),'warn'); - $result = unlink($filename); - if (!$result){ - prnMsg(_('The existing image could not be removed'),'error'); - $UploadTheFile ='No'; + } + foreach ($SupportedImgExt as $ext) { + $file = $_SESSION['part_pics_dir'] . '/ASSET_' . $AssetID . '.' . $ext; + if (file_exists ($file) ) { + $result = unlink($file); + if (!$result){ + prnMsg(_('The existing image could not be removed'),'error'); + $UploadTheFile ='No'; + } } } @@ -367,6 +372,14 @@ $result=DB_query($sql, _('Could not delete the asset record'),'',true); $result = DB_Txn_Commit(); + + // Delete the AssetImage + foreach ($SupportedImgExt as $ext) { + $file = $_SESSION['part_pics_dir'] . '/ASSET_' . $AssetID . '.' . $ext; + if (file_exists ($file) ) { + unlink($file); + } + } prnMsg(_('Deleted the asset record for asset number' ) . ' ' . $AssetID ); unset($_POST['LongDescription']); @@ -482,22 +495,23 @@ if (!isset($New) ) { //ie not new at all! echo '<tr> - <td>' . _('Image File (.jpg)') . ':</td> - <td><input type="file" id="ItemPicture" name="ItemPicture" /></td>'; + <td>' . _('Image File (' . implode(", ", $SupportedImgExt) . ')') . ':</td> + <td><input type="file" id="ItemPicture" name="ItemPicture" /> + <br /><input type="checkbox" name="ClearImage" id="ClearImage" value="1" > '._('Clear Image').' + </td>'; - if (function_exists('imagecreatefromjpg')){ + $imagefile = reset((glob($_SESSION['part_pics_dir'] . '/ASSET_' . $AssetID . '.{' . implode(",", $SupportedImgExt) . '}', GLOB_BRACE))); + if (extension_loaded ('gd') && function_exists ('gd_info') && file_exists ($imagefile) ) { $AssetImgLink = '<img src="GetStockImage.php?automake=1&textcolor=FFFFFF&bgcolor=CCCCCC'. - '&AssetID='.urlencode($AssetID). + '&StockID='.urlencode('ASSET_' . $AssetID). '&text='. '&width=64'. '&height=64'. '" />'; + } else if (file_exists ($imagefile)) { + $AssetImgLink = '<img src="' . $imagefile . '" height="64" width="64" />'; } else { - if( isset($AssetID) and file_exists($_SESSION['part_pics_dir'] . '/ASSET_' .$AssetID.'.jpg') ) { - $AssetImgLink = '<img src="' . $_SESSION['part_pics_dir'] . '/ASSET_' .$AssetID.'.jpg" />'; - } else { - $AssetImgLink = _('No Image'); - } + $AssetImgLink = _('No Image'); } if ($AssetImgLink!=_('No Image')) { @@ -509,6 +523,22 @@ // EOR Add Image upload for New Item - by Ori } //only show the add image if the asset already exists - otherwise AssetID will not be set - and the image needs the AssetID to save +if (isset($_POST['ClearImage']) ) { + foreach ($SupportedImgExt as $ext) { + $file = $_SESSION['part_pics_dir'] . '/ASSET_' . $AssetID . '.' . $ext; + if (file_exists ($file) ) { + //workaround for many variations of permission issues that could cause unlink fail + @unlink($file); + if(is_file($imagefile)) { + prnMsg(_('You do not have access to delete this item image file.'),'error'); + } else { + $AssetImgLink = _('No Image'); + } + } + } +} + + echo '<tr> <td>' . _('Asset Category') . ':</td> <td><select name="AssetCategoryID">'; Modified: trunk/GetStockImage.php =================================================================== --- trunk/GetStockImage.php 2016-04-16 01:37:00 UTC (rev 7493) +++ trunk/GetStockImage.php 2016-04-25 09:53:53 UTC (rev 7494) @@ -2,7 +2,7 @@ /* $Id$*/ -//include ('includes/session.inc'); +include ('includes/session.inc'); /* http://127.0.0.1/~brink/webERP/GetStockImage.php ?automake=1&width=81&height=74&stockid=&textcolor=FFFFF0&bevel=3&text=aa&bgcolor=007F00 @@ -49,13 +49,6 @@ return array('red' => $Red, 'green' => $Green, 'blue' => $Blue ); } -if (!function_exists('imagecreatefrompng')){ - $Title = _('Image Manipulation Script Problem'); - include('includes/header.inc'); - prnMsg(_('This script requires the gd image functions to be available to php - this needs to be enabled in your server php version before this script can be used'),'error'); - include('includes/footer.inc'); - exit; -} $DefaultImage = 'webERPsmall.png'; $FilePath = $_SESSION['part_pics_dir'] . '/'; Modified: trunk/GoodsReceived.php =================================================================== --- trunk/GoodsReceived.php 2016-04-16 01:37:00 UTC (rev 7493) +++ trunk/GoodsReceived.php 2016-04-25 09:53:53 UTC (rev 7494) @@ -182,8 +182,15 @@ //Now Display LineItem + $SupportedImgExt = array('png','jpg','jpeg'); + $imagefile = reset((glob($_SESSION['part_pics_dir'] . '/' . $LnItm->StockID . '.{' . implode(",", $SupportedImgExt) . '}', GLOB_BRACE))); + if ($imagefile) { + $ImageLink = '<a href="' . $imagefile . '" target="_blank">' . $LnItm->StockID . '</a>'; + } else { + $ImageLink = $LnItm->StockID; + } - echo '<td><a href="' . $RootPath . '/' . $_SESSION['part_pics_dir'] . '/' . $LnItm->StockID . '.jpg" target="_blank">' . $LnItm->StockID . '</a></td> + echo '<td>' . $ImageLink . '</td> <td>' . $LnItm->Suppliers_PartNo . '</td> <td>' . $LnItm->ItemDescription . '</td> <td class="number">' . $DisplaySupplierQtyOrd . '</td> Modified: trunk/Manufacturers.php =================================================================== --- trunk/Manufacturers.php 2016-04-16 01:37:00 UTC (rev 7493) +++ trunk/Manufacturers.php 2016-04-25 09:53:53 UTC (rev 7494) @@ -15,6 +15,8 @@ $SelectedManufacturer = $_POST['SelectedManufacturer']; } +$SupportedImgExt = array('png','jpg','jpeg'); + if (isset($_POST['submit'])) { @@ -30,11 +32,13 @@ $result = $_FILES['BrandPicture']['error']; $UploadTheFile = 'Yes'; //Assume all is well to start off with - $FileName = $_SESSION['part_pics_dir'] . '/BRAND-' . $SelectedManufacturer . '.jpg'; + + $ImgExt = pathinfo($_FILES['BrandPicture']['name'], PATHINFO_EXTENSION); + $FileName = $_SESSION['part_pics_dir'] . '/BRAND-' . $SelectedManufacturer . '.' . $ImgExt; //But check for the worst - if (mb_strtoupper(mb_substr(trim($_FILES['BrandPicture']['name']),mb_strlen($_FILES['BrandPicture']['name'])-3))!='JPG'){ - prnMsg(_('Only jpg files are supported - a file extension of .jpg is expected'),'warn'); + if (!in_array ($ImgExt, $SupportedImgExt)) { + prnMsg(_('Only ' . implode(", ", $SupportedImgExt) . ' files are supported - a file extension of ' . implode(", ", $SupportedImgExt) . ' is expected'),'warn'); $UploadTheFile ='No'; } elseif ( $_FILES['BrandPicture']['size'] > ($_SESSION['MaxImageSize']*1024)) { //File Size Check prnMsg(_('The file size is over the maximum allowed. The maximum size allowed in KB is') . ' ' . $_SESSION['MaxImageSize'],'warn'); @@ -42,12 +46,15 @@ } elseif ( $_FILES['BrandPicture']['type'] == 'text/plain' ) { //File Type Check prnMsg( _('Only graphics files can be uploaded'),'warn'); $UploadTheFile ='No'; - } elseif (file_exists($FileName)){ - prnMsg(_('Attempting to overwrite an existing item image'),'warn'); - $result = unlink($FileName); - if (!$result){ - prnMsg(_('The existing image could not be removed'),'error'); - $UploadTheFile ='No'; + } + foreach ($SupportedImgExt as $ext) { + $file = $_SESSION['part_pics_dir'] . '/BRAND-' . $SelectedManufacturer . '.' . $ext; + if (file_exists ($file) ) { + $result = unlink($file); + if (!$result){ + prnMsg(_('The existing image could not be removed'),'error'); + $UploadTheFile ='No'; + } } } @@ -60,13 +67,30 @@ } } if( isset($_POST['ManufacturersImage'])){ - if (file_exists($_SESSION['part_pics_dir'] . '/' .'BRAND-' . $SelectedManufacturer . '.jpg') ) { - $_POST['ManufacturersImage'] = 'BRAND-' . $SelectedManufacturer . '.jpg'; - } else { - $_POST['ManufacturersImage'] = ''; + foreach ($SupportedImgExt as $ext) { + $file = $_SESSION['part_pics_dir'] . '/BRAND-' . $SelectedManufacturer . '.' . $ext; + if (file_exists ($file) ) { + $_POST['ManufacturersImage'] = 'BRAND-' . $SelectedManufacturer; + break; + } else { + $_POST['ManufacturersImage'] = ''; + } } + } - + if (isset($_POST['ClearImage']) ) { + foreach ($SupportedImgExt as $ext) { + $file = $_SESSION['part_pics_dir'] . '/BRAND-' . $SelectedManufacturer . '.' . $ext; + if (file_exists ($file) ) { + @unlink($file); + $_POST['ManufacturersImage'] = ''; + if(is_file($imagefile)) { + prnMsg(_('You do not have access to delete this item image file.'),'error'); + } + } + } + } + $sql = "UPDATE manufacturers SET manufacturers_name='" . $_POST['ManufacturersName'] . "', manufacturers_url='" . $_POST['ManufacturersURL'] . "'"; if (isset($_POST['ManufacturersImage'])){ @@ -102,11 +126,13 @@ $result = $_FILES['BrandPicture']['error']; $UploadTheFile = 'Yes'; //Assume all is well to start off with - $FileName = $_SESSION['part_pics_dir'] . '/BRAND-' . $_SESSION['LastInsertId'] . '.jpg'; + + $ImgExt = pathinfo($_FILES['BrandPicture']['name'], PATHINFO_EXTENSION); + $FileName = $_SESSION['part_pics_dir'] . '/BRAND-' . $_SESSION['LastInsertId'] . '.' . $ImgExt; //But check for the worst - if (mb_strtoupper(mb_substr(trim($_FILES['BrandPicture']['name']),mb_strlen($_FILES['BrandPicture']['name'])-3))!='JPG'){ - prnMsg(_('Only jpg files are supported - a file extension of .jpg is expected'),'warn'); + if (!in_array ($ImgExt, $SupportedImgExt)) { + prnMsg(_('Only ' . implode(", ", $SupportedImgExt) . ' files are supported - a file extension of ' . implode(", ", $SupportedImgExt) . ' is expected'),'warn'); $UploadTheFile ='No'; } elseif ( $_FILES['BrandPicture']['size'] > ($_SESSION['MaxImageSize']*1024)) { //File Size Check prnMsg(_('The file size is over the maximum allowed. The maximum size allowed in KB is') . ' ' . $_SESSION['MaxImageSize'],'warn'); @@ -114,19 +140,25 @@ } elseif ( $_FILES['BrandPicture']['type'] == 'text/plain' ) { //File Type Check prnMsg( _('Only graphics files can be uploaded'),'warn'); $UploadTheFile ='No'; - } elseif (file_exists($FileName)){ - prnMsg(_('Attempting to overwrite an existing item image'),'warn'); - $result = unlink($FileName); - if (!$result){ - prnMsg(_('The existing image could not be removed'),'error'); - $UploadTheFile ='No'; + } + foreach ($SupportedImgExt as $ext) { + $file = $_SESSION['part_pics_dir'] . '/BRAND-' . $_SESSION['LastInsertId'] . '.' . $ext; + if (file_exists ($file) ) { + $result = unlink($file); + if (!$result){ + prnMsg(_('The existing image could not be removed'),'error'); + $UploadTheFile ='No'; + } } } if ($UploadTheFile=='Yes'){ $result = move_uploaded_file($_FILES['BrandPicture']['tmp_name'], $FileName); $message = ($result)?_('File url') . '<a href="' . $FileName .'">' . $FileName . '</a>' : _('Something is wrong with uploading a file'); - DB_query("UPDATE manufacturers SET manufacturers_image='" . $FileName . "'"); + DB_query("UPDATE manufacturers + SET manufacturers_image='" . 'BRAND-' . $_SESSION['LastInsertId'] . "' + WHERE manufacturers_id = '" . $_SESSION['LastInsertId'] . "' + "); } } @@ -138,7 +170,6 @@ unset($SelectedManufacturer); } - } elseif (isset($_GET['delete'])) { //the link to delete a selected record was clicked instead of the submit button @@ -155,10 +186,13 @@ } if (!$CancelDelete) { - + $result = DB_query("DELETE FROM manufacturers WHERE manufacturers_id='" . $SelectedManufacturer . "'"); - if( file_exists($_SESSION['part_pics_dir'] . '/BRAND-' . $SelectedManufacturer . '.jpg') ) { - unlink($_SESSION['part_pics_dir'] . '/BRAND-' . $SelectedManufacturer . '.jpg'); + foreach ($SupportedImgExt as $ext) { + $file = $_SESSION['part_pics_dir'] . '/BRAND-' . $SelectedManufacturer . '.' . $ext; + if (file_exists ($file) ) { + @unlink($file); + } } prnMsg( _('Manufacturer') . ' ' . $SelectedManufacturer . ' ' . _('has been deleted') . '!', 'success'); unset ($SelectedManufacturer); @@ -205,16 +239,25 @@ $k=1; } - if( file_exists($_SESSION['part_pics_dir'] . '/BRAND-' . $myrow['manufacturers_id'] . '.jpg') ) { - $BrandImgLink = '<img width="120" height="120" src="' . $_SESSION['part_pics_dir'] . '/BRAND-' . $myrow['manufacturers_id'] . '.jpg" />'; + $imagefile = reset((glob($_SESSION['part_pics_dir'] . '/BRAND-' . $myrow['manufacturers_id'] . '.{' . implode(",", $SupportedImgExt) . '}', GLOB_BRACE))); + if (extension_loaded('gd') && function_exists('gd_info') && file_exists($imagefile)){ + $BrandImgLink = '<img src="GetStockImage.php?automake=1&textcolor=FFFFFF&bgcolor=CCCCCC'. + '&StockID='.urlencode('/BRAND-' . $myrow['manufacturers_id']). + '&text='. + '&width=120'. + '&height=120'. + '" alt="" />'; + } else if (file_exists ($imagefile)) { + $BrandImgLink = '<img src="' . $imagefile . '" height="120" width="120" />'; } else { $BrandImgLink = _('No Image'); } + printf('<td>%s</td> <td>%s</td> <td><a target="_blank" href="%s">%s</a></td> <td>%s</td> - <td><a href="%sSelectedManufacturer=%s">' . _('Edit') . '</a></td> + <td><a href="%sSelectedManufacturer=%s&edit=1">' . _('Edit') . '</a></td> <td><a href="%sSelectedManufacturer=%s&delete=1" onclick="return confirm(\'' . _('Are you sure you wish to delete this brand?') . '\');">' . _('Delete') . '</a></td> </tr>', $myrow['manufacturers_id'], @@ -297,13 +340,33 @@ <td><input type="text" name="ManufacturersURL" value="' . $_POST['ManufacturersURL'] . '" size="50" maxlength="50" /></td> </tr> <tr> - <td>' . _('Brand Image File (.jpg)') . ':</td> - <td><input type="file" id="BrandPicture" name="BrandPicture" /></td> + <td>' . _('Brand Image File (' . implode(", ", $SupportedImgExt) . ')') . ':</td> + <td><input type="file" id="BrandPicture" name="BrandPicture" />'; + + if (isset ($_GET['edit']) ) { + echo ' <br /><input type="checkbox" name="ClearImage" id="ClearImage" value="1" > '._('Clear Image').' '; + } + + echo ' </td> </tr>'; if (isset($SelectedManufacturer)){ - if(file_exists($_SESSION['part_pics_dir'] . '/' .'BRAND-' . $SelectedManufacturer . '.jpg') ) { - echo '</tr><td colspan="2"><img width="100" height="100" src="' . $_SESSION['part_pics_dir'] . '/' .'BRAND-' . $SelectedManufacturer . '.jpg" /></tr></tr>'; - } + + $imagefile = reset((glob($_SESSION['part_pics_dir'] . '/BRAND-' . $SelectedManufacturer . '.{' . implode(",", $SupportedImgExt) . '}', GLOB_BRACE))); + if (extension_loaded('xgd') && function_exists('gd_info') && file_exists($imagefile)){ + $BrandImgLink = '<img src="GetStockImage.php?automake=1&textcolor=FFFFFF&bgcolor=CCCCCC'. + '&StockID='.urlencode('/BRAND-' . $SelectedManufacturer). + '&text='. + '&width=100'. + '&height=100'. + '" alt="" />'; + } else { + if( isset($SelectedManufacturer) AND !empty($SelectedManufacturer) AND file_exists($imagefile) ) { + $BrandImgLink = '<img src="' . $imagefile . '" height="100" width="100" />'; + } else { + $BrandImgLink = _('No Image'); + } + } + echo '<tr><td colspan="2">' . $BrandImgLink . '</td></tr>'; } echo '</table> Modified: trunk/PDFPriceList.php =================================================================== --- trunk/PDFPriceList.php 2016-04-16 01:37:00 UTC (rev 7493) +++ trunk/PDFPriceList.php 2016-04-25 09:53:53 UTC (rev 7494) @@ -230,14 +230,14 @@ $YPos -= $FontSize; // Prints item image: + $SupportedImgExt = array('png','jpg','jpeg'); + $imagefile = reset((glob($_SESSION['part_pics_dir'] . '/' . $PriceList['stockid'] . '.{' . implode(",", $SupportedImgExt) . '}', GLOB_BRACE))); $YPosImage = $YPos;// Initializes the image bottom $YPos. - if(file_exists($_SESSION['part_pics_dir'] . '/' .$PriceList['stockid'].'.jpg') ) { - $img = imagecreatefromjpeg($_SESSION['part_pics_dir'] . '/' . $PriceList['stockid'] . '.jpg'); + if (file_exists($imagefile) ) { if($YPos-36 < $Bottom_Margin) {// If the image bottom reaches the bottom margin, do PageHeader(). PageHeader(); } - $LeftOvers = $pdf->Image($_SESSION['part_pics_dir'] . '/'.$PriceList['stockid'].'.jpg', - $Left_Margin+3, $Page_Height-$YPos, 36, 36); + $LeftOvers = $pdf->Image($imagefile,$Left_Margin+3, $Page_Height-$YPos, 36, 36); $YPosImage = $YPos-36;// Stores the $YPos of the image bottom (see bottom). } // Prints stockmaster.longdescription: Modified: trunk/PO_Items.php =================================================================== --- trunk/PO_Items.php 2016-04-16 01:37:00 UTC (rev 7493) +++ trunk/PO_Items.php 2016-04-25 09:53:53 UTC (rev 7494) @@ -1147,7 +1147,7 @@ echo '</select></td> <td>' . _('Enter text extracts in the description') . ':</td> <td><input type="text" name="Keywords" size="20" maxlength="25" value="' . $_POST['Keywords'] . '" /></td></tr> - <tr><td>' . _('Only items defined as from this Supplier') . ' <input type="checkbox" name="SupplierItemsOnly" '; + <tr><td>' . _('Only items defined as from this Supplier') . ' <input type="checkbox" checked name="SupplierItemsOnly" '; if (isset($_POST['SupplierItemsOnly']) AND $_POST['SupplierItemsOnly']=='on'){ echo 'checked'; } @@ -1207,11 +1207,19 @@ $k=1; } - $FileName = $myrow['stockid'] . '.jpg'; - if (file_exists( $_SESSION['part_pics_dir'] . '/' . $FileName) ) { - $ImageSource = '<img src="'.$RootPath . '/' . $_SESSION['part_pics_dir'] . '/' . $myrow['stockid'] . '.jpg" width="50" height="50" />'; + $SupportedImgExt = array('png','jpg','jpeg'); + $imagefile = reset((glob($_SESSION['part_pics_dir'] . '/' . $myrow['stockid'] . '.{' . implode(",", $SupportedImgExt) . '}', GLOB_BRACE))); + if (extension_loaded('gd') && function_exists('gd_info') && file_exists ($imagefile) ) { + $ImageSource = '<img src="GetStockImage.php?automake=1&textcolor=FFFFFF&bgcolor=CCCCCC'. + '&StockID='.urlencode($myrow['stockid']). + '&text='. + '&width=64'. + '&height=64'. + '" alt="" />'; + } else if (file_exists ($imagefile)) { + $ImageSource = '<img src="' . $imagefile . '" height="100" width="100" />'; } else { - $ImageSource = '<i>' . _('No Image') . '</i>'; + $ImageSource = _('No Image'); } /*Get conversion factor and supplier units if any */ Modified: trunk/SalesCategories.php =================================================================== --- trunk/SalesCategories.php 2016-04-16 01:37:00 UTC (rev 7493) +++ trunk/SalesCategories.php 2016-04-25 09:53:53 UTC (rev 7494) @@ -32,29 +32,36 @@ $EditName = $_POST['EditName']; } +$SupportedImgExt = array('png','jpg','jpeg'); + if (isset($SelectedCategory) AND isset($_FILES['CategoryPicture']) AND $_FILES['CategoryPicture']['name'] !='') { - + $ImgExt = pathinfo($_FILES['CategoryPicture']['name'], PATHINFO_EXTENSION); + $result = $_FILES['CategoryPicture']['error']; $UploadTheFile = 'Yes'; //Assume all is well to start off with // Stock is always capatalized so there is no confusion since "cat_" is lowercase - $FileName = $_SESSION['part_pics_dir'] . '/SALESCAT_' . $SelectedCategory . '.jpg'; + $FileName = $_SESSION['part_pics_dir'] . '/SALESCAT_' . $SelectedCategory . '.' . $ImgExt; - //But check for the worst - if (mb_strtoupper(mb_substr(trim($_FILES['CategoryPicture']['name']),mb_strlen($_FILES['CategoryPicture']['name'])-3))!='JPG'){ - prnMsg(_('Only jpg files are supported - a file extension of .jpg is expected'),'warn'); + //But check for the worst + if (!in_array ($ImgExt, $SupportedImgExt)) { + prnMsg(_('Only ' . implode(", ", $SupportedImgExt) . ' files are supported - a file extension of ' . implode(", ", $SupportedImgExt) . ' is expected'),'warn'); $UploadTheFile ='No'; - } elseif ( $_FILES['CategoryPicture']['size'] > ($_SESSION['MaxImageSize']*1024)) { //File Size Check + } else if ( $_FILES['CategoryPicture']['size'] > ($_SESSION['MaxImageSize']*1024)) { //File Size Check prnMsg(_('The file size is over the maximum allowed. The maximum size allowed in KB is') . ' ' . $_SESSION['MaxImageSize'],'warn'); $UploadTheFile ='No'; - } elseif ( $_FILES['CategoryPicture']['type'] == 'text/plain' ) { //File Type Check + } else if ( $_FILES['CategoryPicture']['type'] == 'text/plain' ) { //File Type Check prnMsg( _('Only graphics files can be uploaded'),'warn'); $UploadTheFile ='No'; - } elseif (file_exists($FileName)){ - prnMsg(_('Attempting to overwrite an existing item image'),'warn'); - $result = unlink($FileName); - if (!$result){ - prnMsg(_('The existing image could not be removed'),'error'); - $UploadTheFile ='No'; + } + foreach ($SupportedImgExt as $ext) { + $file = $_SESSION['part_pics_dir'] . '/SALESCAT_' . $SelectedCategory . '.' . $ext; + if (file_exists ($file) ) { + //prnMsg(_('Attempting to overwrite an existing item image'.$FileName),'warn'); + $result = unlink($file); + if (!$result){ + prnMsg(_('The existing image could not be removed'),'error'); + $UploadTheFile ='No'; + } } } @@ -65,8 +72,21 @@ /* EOR Add Image upload for New Item - by Ori */ } +if (isset($_POST['ClearImage']) ) { + foreach ($SupportedImgExt as $ext) { + $file = $_SESSION['part_pics_dir'] . '/SALESCAT_' . $SelectedCategory . '.' . $ext; + if (file_exists ($file) ) { + //workaround for many variations of permission issues that could cause unlink fail + @unlink($file); + if(is_file($imagefile)) { + prnMsg(_('You do not have access to delete this item image file.'),'error'); + } else { + $AssetImgLink = _('No Image'); + } + } + } +} - if (isset($_POST['submit']) AND isset($EditName) ) { // Creating or updating a category //initialise no input errors assumed initially before we test @@ -110,7 +130,6 @@ $result = DB_query($sql); prnMsg($msg,'success'); } - unset ($SelectedCategory); unset($_POST['SalesCatName']); unset($_POST['Active']); @@ -138,9 +157,18 @@ $result = DB_query($sql); prnMsg(_('The sales category') . ' ' . $SelectedCategory . ' ' . _('has been deleted') . ' !','success'); - if( file_exists($_SESSION['part_pics_dir'] . '/SALESCAT_' . $SelectedCategory . '.jpg') ) { - unlink($_SESSION['part_pics_dir'] . '/SALESCAT_' . $SelectedCategory . '.jpg'); + + //if( file_exists($_SESSION['part_pics_dir'] . '/SALESCAT_' . $SelectedCategory . '.jpg') ) { + // unlink($_SESSION['part_pics_dir'] . '/SALESCAT_' . $SelectedCategory . '.jpg'); + //} + + foreach ($SupportedImgExt as $ext) { + $file = $_SESSION['part_pics_dir'] . '/SALESCAT_' . $SelectedCategory . '.' . $ext; + if (file_exists ($file) ) { + unlink($file); + } } + unset ($SelectedCategory); } } //end if stock category used in debtor transactions @@ -254,12 +282,22 @@ echo '<tr class="OddTableRows">'; $k=1; } - - if( file_exists($_SESSION['part_pics_dir'] . '/SALESCAT_' . $myrow['salescatid'] . '.jpg') ) { - $CatImgLink = '<img src="GetStockImage.php?automake=1&textcolor=FFFFFF&bgcolor=CCCCCC&StockID=' . 'SALESCAT_' . $myrow['salescatid'] . '&text=&width=120&height=120" alt="" />'; + + $SupportedImgExt = array('png','jpg','jpeg'); + $imagefile = reset((glob($_SESSION['part_pics_dir'] . '/SALESCAT_' . $myrow['salescatid'] . '.{' . implode(",", $SupportedImgExt) . '}', GLOB_BRACE))); + if( extension_loaded('gd') && function_exists('gd_info') && file_exists($imagefile) ) { + $CatImgLink = '<img src="GetStockImage.php?automake=1&textcolor=FFFFFF&bgcolor=CCCCCC'. + '&StockID='.urlencode('SALESCAT_' . $myrow['salescatid']). + '&text='. + '&width=64'. + '&height=64'. + '" alt="" />'; + } else if (file_exists ($imagefile)) { + $CatImgLink = '<img src="' . $imagefile . '" height="64" width="64" />'; } else { $CatImgLink = _('No Image'); } + if ($myrow['active'] == 1){ $Active = _('Yes'); }else{ @@ -321,7 +359,7 @@ $_POST['Active'] = $myrow['active']; echo '<input type="hidden" name="SelectedCategory" value="' . $SelectedCategory . '" />'; - echo '<input type="hidden" name="ParentCategory" value="' . (isset($_POST['ParentCatId'])?($_POST['ParentCategory']):('0')) . '" />'; + echo '<input type="hidden" name="ParentCategory" value="' . $myrow['parentcatid'] . '" />'; $FormCaps = _('Edit Sub Category'); } else { //end of if $SelectedCategory only do the else when a new record is being entered @@ -347,7 +385,7 @@ echo '<tr> <td>' . _('Display in webSHOP?') . ':</td> <td><select name="Active">'; -if ($_POST['Active'] == '1') { +if (isset ($_POST['Active']) && $_POST['Active'] == '1') { echo '<option selected="selected" value="1">' . _('Yes') . '</option>'; echo '<option value="0">' . _('No') . '</option>'; } else { @@ -360,8 +398,10 @@ // Image upload only if we have a selected category if (isset($SelectedCategory)) { echo '<tr> - <td>' . _('Image File (.jpg)') . ':</td> - <td><input type="file" id="CategoryPicture" name="CategoryPicture" /></td> + <td>' . _('Image File (' . implode(", ", $SupportedImgExt) . ')') . ':</td> + <td><input type="file" id="CategoryPicture" name="CategoryPicture" /> + <br /><input type="checkbox" name="ClearImage" id="ClearImage" value="1" > '._('Clear Image').' + </td> </tr>'; } Modified: trunk/SelectCreditItems.php =================================================================== --- trunk/SelectCreditItems.php 2016-04-16 01:37:00 UTC (rev 7493) +++ trunk/SelectCreditItems.php 2016-04-25 09:53:53 UTC (rev 7494) @@ -1032,11 +1032,20 @@ echo '<tr class="OddTableRows">'; $k++; } - if(file_exists($_SESSION['part_pics_dir'] . '/' .mb_strtoupper($myrow['stockid']).'.jpg') ) { + + $SupportedImgExt = array('png','jpg','jpeg'); + $imagefile = reset((glob($_SESSION['part_pics_dir'] . '/' . $myrow['stockid'] . '.{' . implode(",", $SupportedImgExt) . '}', GLOB_BRACE))); + if (extension_loaded('gd') && function_exists('gd_info') && file_exists ($imagefile) ) { + $ImageSource = '<img src="GetStockImage.php?automake=1&textcolor=FFFFFF&bgcolor=CCCCCC'. + '&StockID='.urlencode($myrow['stockid']). + '&text='. + '&width=64'. + '&height=64'. + '" alt="" />'; printf('<td><input type="submit" name="NewItem" value="%s" /></td> <td>%s</td> <td>%s</td> - <td><img src="GetStockImage.php?automake=1&textcolor=FFFFFF&bgcolor=CCCCCC&StockID=%s&text=&width=120&height=120" /></td></tr>', + <td>' . $ImageSource . '</td></tr>', $myrow['stockid'], $myrow['description'], $myrow['units'], Modified: trunk/SelectProduct.php =================================================================== --- trunk/SelectProduct.php 2016-04-16 01:37:00 UTC (rev 7493) +++ trunk/SelectProduct.php 2016-04-25 09:53:53 UTC (rev 7494) @@ -399,7 +399,10 @@ if ($Its_A_Kitset_Assembly_Or_Dummy == False) { echo '<a href="' . $RootPath . '/PO_SelectOSPurchOrder.php?SelectedStockItem=' . $StockID . '">' . _('Search Outstanding Purchase Orders') . '</a><br />'; echo '<a href="' . $RootPath . '/PO_SelectPurchOrder.php?SelectedStockItem=' . $StockID . '">' . _('Search All Purchase Orders') . '</a><br />'; - echo '<a href="' . $RootPath . '/' . $_SESSION['part_pics_dir'] . '/' . $StockID . '.jpg">' . _('Show Part Picture (if available)') . '</a><br />'; + + $SupportedImgExt = array('png','jpg','jpeg'); + $imagefile = reset((glob($_SESSION['part_pics_dir'] . '/' . $StockID . '.{' . implode(",", $SupportedImgExt) . '}', GLOB_BRACE))); + echo '<a href="' . $RootPath . '/' . $imagefile . '" target="_blank">' . _('Show Part Picture (if available)') . '</a><br />'; } if ($Its_A_Dummy == False) { echo '<a href="' . $RootPath . '/BOMInquiry.php?StockID=' . $StockID . '">' . _('View Costed Bill Of Material') . '</a><br />'; @@ -414,8 +417,9 @@ if ($Its_A_Kitset_Assembly_Or_Dummy == false) { echo '<a href="' . $RootPath . '/StockAdjustments.php?StockID=' . $StockID . '">' . _('Quantity Adjustments') . '</a><br />'; echo '<a href="' . $RootPath . '/StockTransfers.php?StockID=' . $StockID . '&NewTransfer=true">' . _('Location Transfers') . '</a><br />'; + //show the item image if it has been uploaded - if (function_exists('imagecreatefromjpg')){ + if ( extension_loaded ('gd') && function_exists ('gd_info') && file_exists ($imagefile) ) { if ($_SESSION['ShowStockidOnImages'] == '0'){ $StockImgLink = '<img src="GetStockImage.php?automake=1&textcolor=FFFFFF&bgcolor=CCCCCC'. '&StockID='.urlencode($StockID). @@ -431,17 +435,14 @@ '&height=100'. '" alt="" />'; } + } else if (file_exists ($imagefile)) { + $StockImgLink = '<img src="' . $imagefile . '" height="100" width="100" />'; } else { - if( isset($StockID) AND file_exists($_SESSION['part_pics_dir'] . '/' .$StockID.'.jpg') ) { - $StockImgLink = '<img src="' . $_SESSION['part_pics_dir'] . '/' . $StockID . '.jpg" height="100" width="100" />'; - } else { - $StockImgLink = _('No Image'); - } + $StockImgLink = _('No Image'); } echo '<div class="centre">' . $StockImgLink . '</div>'; - if (($myrow['mbflag'] == 'B') AND (in_array($SuppliersSecurity, $_SESSION['AllowedPageSecurityTokens'])) AND $myrow['discontinued']==0){ Modified: trunk/StockClone.php =================================================================== --- trunk/StockClone.php 2016-04-16 01:37:00 UTC (rev 7493) +++ trunk/StockClone.php 2016-04-25 09:53:53 UTC (rev 7494) @@ -53,17 +53,33 @@ <img src="'.$RootPath.'/css/'.$Theme.'/images/inventory.png" title="' . _('Stock') . '" alt="" />' . ' ' . $Title . ' </p>'; echo '<div class="page_help_text">' . _('Cloning will create a new item with the same properties, image, cost, purchasing and pricing data as the selected item. Item image and general item details can be changed below prior to cloning.') . '.</div><br />'; + +$SupportedImgExt = array('png','jpg','jpeg'); + +// Check extention for existing old file +foreach ($SupportedImgExt as $ext) { + $oldfile = $_SESSION['part_pics_dir'] . '/' . $_POST['OldStockID'] . '.' . $ext; + if (file_exists ($oldfile) ) { + break; + $ext = pathinfo($oldfile, PATHINFO_EXTENSION); + } +} + if (!empty($_POST['OldStockID'])) { //only show this if there is a valid call to this script if (isset($_FILES['ItemPicture']) AND $_FILES['ItemPicture']['name'] !='') { //we are uploading a new file - $newfilename = ($_POST['OldStockID'] == $_POST['StockID']) || $_POST['StockID'] == ''? $_POST['OldStockID'].'-TEMP': $_POST['StockID'] ; //so we can add a new file but not remove an existing item file + $newfilename = ($_POST['OldStockID'] == $_POST['StockID']) || $_POST['StockID'] == ''? $_POST['OldStockID'].'-TEMP': $_POST['StockID'] ; //so we can add a new file but not remove an existing item file $result = $_FILES['ItemPicture']['error']; $UploadTheFile = 'Yes'; //Assume all is well to start off with - $filename = $_SESSION['part_pics_dir'] . '/' . $newfilename . '.jpg'; + if (pathinfo($_FILES['ItemPicture']['name'], PATHINFO_EXTENSION) != $ext) { + $ext = pathinfo($_FILES['ItemPicture']['name'], PATHINFO_EXTENSION); + } + $filename = $_SESSION['part_pics_dir'] . '/' . $newfilename . '.' . $ext; + //But check for the worst - if (mb_strtoupper(mb_substr(trim($_FILES['ItemPicture']['name']),mb_strlen($_FILES['ItemPicture']['name'])-3))!='JPG'){ - prnMsg(_('Only jpg files are supported - a file extension of .jpg is expected'),'warn'); - $UploadTheFile ='No'; + if (!in_array ($ext, $SupportedImgExt)) { + prnMsg(_('Only ' . implode(", ", $SupportedImgExt) . ' files are supported - a file extension of ' . implode(", ", $SupportedImgExt) . ' is expected'),'warn'); + $UploadTheFile ='No'; } elseif ( $_FILES['ItemPicture']['size'] > ($_SESSION['MaxImageSize']*1024)) { //File Size Check prnMsg(_('The image file size is over the maximum allowed. The maximum size allowed in KB is') . ' ' . $_SESSION['MaxImageSize'],'warn'); $UploadTheFile ='No'; @@ -87,21 +103,21 @@ $result = move_uploaded_file($_FILES['ItemPicture']['tmp_name'], $filename); $message = ($result)?_('File url') . '<a href="' . $filename .'">' . $filename . '</a>' : _('Something is wrong with uploading a file'); } - } elseif (!empty($_POST['StockID']) AND ($_POST['StockID'] != $_POST['OldStockID']) AND file_exists($_SESSION['part_pics_dir'] . '/' . $_POST['OldStockID'].'-TEMP'.'.jpg') ) { - //rename the temp one to the new name - $oldfile = $_SESSION['part_pics_dir'] . '/' .$_POST['OldStockID'].'-TEMP'.'.jpg'; - if (!copy($oldfile, $_SESSION['part_pics_dir'] . '/' .$_POST['StockID'].'.jpg')) { + } elseif (!empty($_POST['StockID']) AND ($_POST['StockID'] != $_POST['OldStockID']) AND file_exists($_SESSION['part_pics_dir'] . '/' . $_POST['OldStockID'] . '-TEMP' . '.' . $ext) ) { + //rename the temp one to the new name + $oldfile = $_SESSION['part_pics_dir'] . '/' .$_POST['OldStockID'].'-TEMP' . '.' . $ext; + if (!copy($oldfile, $_SESSION['part_pics_dir'] . '/' .$_POST['StockID'] . '.' . $ext)) { prnMsg(_('There was an image file to clone but there was an error copying. Please upload a new image if required.'),'warn'); } - @unlink($_SESSION['part_pics_dir'] . '/' .$_POST['OldStockID'].'-TEMP'.'.jpg'); - if (is_file($_SESSION['part_pics_dir'] . '/' .$_POST['OldStockID'].'-TEMP'.'.jpg')) { + @unlink($_SESSION['part_pics_dir'] . '/' .$_POST['OldStockID'].'-TEMP' . '.' . $ext); + if (is_file($_SESSION['part_pics_dir'] . '/' .$_POST['OldStockID'].'-TEMP' . '.' . $ext)) { prnMsg(_('Unable to delete the temporary image file for cloned item.'),'error'); } else { $StockImgLink = _('No Image'); } - } elseif (isset( $_POST['OldStockID']) AND file_exists($_SESSION['part_pics_dir'] . '/' . $_POST['OldStockID'].'.jpg') AND !file_exists($_SESSION['part_pics_dir'] . '/' . $_POST['OldStockID'].'-TEMP'.'.jpg') ) { - //we should copy - if (!copy($_SESSION['part_pics_dir'] . '/' .$_POST['OldStockID'].'.jpg', $_SESSION['part_pics_dir'] . '/' .$_POST['StockID'].'.jpg')) { + } elseif (isset( $_POST['OldStockID']) AND file_exists($_SESSION['part_pics_dir'] . '/' . $_POST['OldStockID'] . '.' . $ext) AND !file_exists($_SESSION['part_pics_dir'] . '/' . $_POST['OldStockID'].'-TEMP' . '.' . $ext) ) { + //we should copy + if (!copy($_SESSION['part_pics_dir'] . '/' .$_POST['OldStockID'] . '.' . $ext, $_SESSION['part_pics_dir'] . '/' . $_POST['StockID'] . '.' . $ext)) { prnMsg(_('There was an image file to clone but there was an error copying. Please upload a new image if required.'),'warn'); } } @@ -706,7 +722,7 @@ $tempid = $_POST['StockID']; } - if (function_exists('imagecreatefromjpg') && isset($tempfile)){ + if (extension_loaded('gd') && function_exists ('gd_info') && isset ($tempfile) ) { $StockImgLink = '<img src="GetStockImage.php?automake=1&textcolor=FFFFFF&bgcolor=CCCCCC'. '&StockID='.urlencode($tempid). '&text='. @@ -714,22 +730,22 @@ '&height=100'. '" alt="" />'; } else { - if( !empty($tempid) AND file_exists($_SESSION['part_pics_dir'] . '/' .$tempid.'.jpg') ) { - $StockImgLink = '<img src="' . $_SESSION['part_pics_dir'] . '/' . $tempid . '.jpg" height="100" width="100" />'; + if( !empty($tempid) AND file_exists($_SESSION['part_pics_dir'] . '/' .$tempid.'.' . $ext) ) { + $StockImgLink = '<img src="' . $_SESSION['part_pics_dir'] . '/' . $tempid . '.' . $ext . '" height="100" width="100" />'; if (isset($_POST['ClearImage']) ) { //workaround for many variations of permission issues that could cause unlink fail - @unlink($_SESSION['part_pics_dir'] . '/' .$tempid.'.jpg'); - if (is_file($_SESSION['part_pics_dir'] . '/' .$tempid.'.jpg')) { + @unlink($_SESSION['part_pics_dir'] . '/' .$tempid.'.' . $ext); + if (is_file($_SESSION['part_pics_dir'] . '/' .$tempid.'.' . $ext)) { prnMsg(_('You do not have access to delete this item image file.'),'error'); } else { $StockImgLink = _('No Image'); } } - } elseif ( !empty($tempid) AND !file_exists($_SESSION['part_pics_dir'] . '/' .$tempid.'.jpg') AND file_exists($_SESSION['part_pics_dir'] . '/' .$_POST['OldStockID'].'.jpg')) { - if (!copy($_SESSION['part_pics_dir'] . '/' .$_POST['OldStockID'].'.jpg', $_SESSION['part_pics_dir'] . '/' .$_POST['OldStockID'].'-TEMP'.'.jpg')) { + } elseif ( !empty($tempid) AND !file_exists($_SESSION['part_pics_dir'] . '/' .$tempid.'.' . $ext) AND file_exists($_SESSION['part_pics_dir'] . '/' .$_POST['OldStockID'].'.' . $ext)) { + if (!copy($_SESSION['part_pics_dir'] . '/' .$_POST['OldStockID'].'.' . $ext, $_SESSION['part_pics_dir'] . '/' .$_POST['OldStockID'].'-TEMP' . '.' . $ext)) { $StockImgLink = _('No Image'); } else { - $StockImgLink = '<img src="' . $_SESSION['part_pics_dir'] . '/' .$_POST['OldStockID'].'-TEMP'.'.jpg" height="100" width="100" />'; + $StockImgLink = '<img src="' . $_SESSION['part_pics_dir'] . '/' .$_POST['OldStockID'].'-TEMP' . '.' . $ext . '" height="100" width="100" />'; } } else { $StockImgLink = _('No Image'); Modified: trunk/StockDispatch.php =================================================================== --- trunk/StockDispatch.php 2016-04-16 01:37:00 UTC (rev 7493) +++ trunk/StockDispatch.php 2016-04-25 09:53:53 UTC (rev 7494) @@ -223,8 +223,10 @@ } else { //for full template $pdf->addTextWrap(50,$YPos,70,$FontSize,$myrow['stockid'],'',0,$fill); - if(file_exists($_SESSION['part_pics_dir'] . '/' .$myrow['stockid'].'.jpg') ) { - $pdf->Image($_SESSION['part_pics_dir'] . '/'.$myrow['stockid'].'.jpg',135,$Page_Height-$Top_Margin-$YPos+10,45,35); + $SupportedImgExt = array('png','jpg','jpeg'); + $imagefile = reset((glob($_SESSION['part_pics_dir'] . '/' . $myrow['stockid'] . '.{' . implode(",", $SupportedImgExt) . '}', GLOB_BRACE))); + if (file_exists ($imagefile) ) { + $pdf->Image($imagefile,135,$Page_Height-$Top_Margin-$YPos+10,35,35); }/*end checked file exist*/ $pdf->addTextWrap(180,$YPos,200,$FontSize,$myrow['description'],'',0,$fill); $pdf->addTextWrap(355,$YPos,40,$FontSize,locale_number_format($myrow['fromquantity'] - $InTransitQuantityAtFrom,$myrow['decimalplaces']),'right',0,$fill); Modified: trunk/Stocks.php =================================================================== --- trunk/Stocks.php 2016-04-16 01:37:00 UTC (rev 7493) +++ trunk/Stocks.php 2016-04-25 09:53:53 UTC (rev 7494) @@ -63,15 +63,17 @@ <img src="'.$RootPath.'/css/'.$Theme.'/images/inventory.png" title="' . _('Stock') . '" alt="" />' . ' ' . $Title . ' </p>'; +$SupportedImgExt = array('png','jpg','jpeg'); + if (isset($_FILES['ItemPicture']) AND $_FILES['ItemPicture']['name'] !='') { - + $ImgExt = pathinfo($_FILES['ItemPicture']['name'], PATHINFO_EXTENSION); + $result = $_FILES['ItemPicture']['error']; $UploadTheFile = 'Yes'; //Assume all is well to start off with - $filename = $_SESSION['part_pics_dir'] . '/' . $StockID . '.jpg'; - + $filename = $_SESSION['part_pics_dir'] . '/' . $StockID . '.' . $ImgExt; //But check for the worst - if (mb_strtoupper(mb_substr(trim($_FILES['ItemPicture']['name']),mb_strlen($_FILES['ItemPicture']['name'])-3))!='JPG'){ - prnMsg(_('Only jpg files are supported - a file extension of .jpg is expected'),'warn'); + if (!in_array ($ImgExt, $SupportedImgExt)) { + prnMsg(_('Only ' . implode(", ", $SupportedImgExt) . ' files are supported - a file extension of ' . implode(", ", $SupportedImgExt) . ' is expected'),'warn'); $UploadTheFile ='No'; } elseif ( $_FILES['ItemPicture']['size'] > ($_SESSION['MaxImageSize']*1024)) { //File Size Check prnMsg(_('The file size is over the maximum allowed. The maximum size allowed in KB is') . ' ' . $_SESSION['MaxImageSize'],'warn'); @@ -82,12 +84,15 @@ } elseif ( $_FILES['ItemPicture']['error'] == 6 ) { //upload temp directory check prnMsg( _('No tmp directory set. You must have a tmp directory set in your PHP for upload of files. '),'warn'); $UploadTheFile ='No'; - } elseif (file_exists($filename)){ - prnMsg(_('Attempting to overwrite an existing item image'),'warn'); - $result = unlink($filename); - if (!$result){ - prnMsg(_('The existing image could not be removed'),'error'); - $UploadTheFile ='No'; + } + foreach ($SupportedImgExt as $ext) { + $file = $_SESSION['part_pics_dir'] . '/' . $StockID . '.' . $ext; + if (file_exists ($file) ) { + $result = unlink($file); + if (!$result){ + prnMsg(_('The existing image could not be removed'),'error'); + $UploadTheFile ='No'; + } } } @@ -1041,38 +1046,43 @@ } echo '<tr> - <td>' . _('Image File (.jpg)') . ':</td> + <td>' . _('Image File (' . implode(", ", $SupportedImgExt) . ')') . ':</td> <td><input type="file" id="ItemPicture" name="ItemPicture" /> <br /><input type="checkbox" name="ClearImage" id="ClearImage" value="1" > '._('Clear Image').' </td>'; -if (function_exists('imagecreatefromjpg') && isset($StockID) && !empty($StockID)){ +$imagefile = reset((glob($_SESSION['part_pics_dir'] . '/' . $StockID . '.{' . implode(",", $SupportedImgExt) . '}', GLOB_BRACE))); +if (extension_loaded('gd') && function_exists('gd_info') && isset($StockID) && !empty($StockID)){ $StockImgLink = '<img src="GetStockImage.php?automake=1&textcolor=FFFFFF&bgcolor=CCCCCC'. '&StockID='.urlencode($StockID). '&text='. - '&width=100'. - '&height=100'. + '&width=64'. + '&height=64'. '" alt="" />'; +} else if (file_exists ($imagefile)) { + $StockImgLink = '<img src="' . $imagefile . '" height="64" width="64" />'; } else { - if( isset($StockID) AND !empty($StockID) AND file_exists($_SESSION['part_pics_dir'] . '/' .$StockID.'.jpg') ) { - $StockImgLink = '<img src="' . $_SESSION['part_pics_dir'] . '/' . $StockID . '.jpg" height="100" width="100" />'; - if (isset($_POST['ClearImage']) ) { - //workaround for many variations of permission issues that could cause unlink fail - @unlink($_SESSION['part_pics_dir'] . '/' .$StockID.'.jpg'); - if(is_file($_SESSION['part_pics_dir'] . '/' .$StockID.'.jpg')) { - prnMsg(_('You do not have access to delete this item image file.'),'error'); - } else { - $StockImgLink = _('No Image'); - } - } - } else { - $StockImgLink = _('No Image'); - } + $StockImgLink = _('No Image'); } if ($StockImgLink!=_('No Image')) { echo '<td>' . _('Image') . '<br />' . $StockImgLink . '</td>'; } + +if (isset($_POST['ClearImage']) ) { + foreach ($SupportedImgExt as $ext) { + $file = $_SESSION['part_pics_dir'] . '/' . $StockID . '.' . $ext; + if (file_exists ($file) ) { + //workaround for many variations of permission issues that could cause unlink fail + @unlink($file); + if(is_file($imagefile)) { + prnMsg(_('You do not have access to delete this item image file.'),'error'); + } else { + $StockImgLink = _('No Image'); + } + } + } +} echo '</tr>'; echo '<tr> Modified: trunk/SupplierTenderCreate.php =================================================================== --- trunk/SupplierTenderCreate.php 2016-04-16 01:37:00 UTC (rev 7493) +++ trunk/SupplierTenderCreate.php 2016-04-25 09:53:53 UTC (rev 7494) @@ -869,15 +869,21 @@ $k=1; } - $FileName = $myrow['stockid'] . '.jpg'; - if (file_exists( $_SESSION['part_pics_dir'] . '/' . $FileName) ) { + $SupportedImgExt = array('png','jpg','jpeg'); + $imagefile = reset((glob($_SESSION['part_pics_dir'] . '/' . $myrow['stockid'] . '.{' . implode(",", $SupportedImgExt) . '}', GLOB_BRACE))); + if (extension_loaded('gd') && function_exists('gd_info') && file_exists ($imagefile) ) { + $ImageSource = '<img src="GetStockImage.php?automake=1&textcolor=FFFFFF&bgcolor=CCCCCC'. + '&StockID='.urlencode($myrow['stockid']). + '&text='. + '&width=64'. + '&height=64'. + '" alt="" />'; + } else if (file_exists ($imagefile)) { + $ImageSource = '<img src="' . $imagefile . '" height="64" width="64" />'; + } else { + $ImageSource = _('No Image'); + } - $ImageSource = '<img src="'.$RootPath . '/' . $_SESSION['part_pics_dir'] . '/' . $FileName . '" width="50" height="50" />'; - - } else { - $ImageSource = '<i>' . _('No Image') . '</i>'; - } - echo '<td>' . $myrow['stockid'] . '</td> <td>' . $myrow['description'] . '</td> <td>' . $myrow['units'] . '</td> Modified: trunk/SupplierTenders.php =================================================================== --- trunk/SupplierTenders.php 2016-04-16 01:37:00 UTC (rev 7493) +++ trunk/SupplierTenders.php 2016-04-25 09:53:53 UTC (rev 7494) @@ -705,13 +705,19 @@ $k=1; } - $FileName = $myrow['stockid'] . '.jpg'; - if (file_exists( $_SESSION['part_pics_dir'] . '/' . $FileName) ) { - - $ImageSource = '<img src="'.$RootPath . '/' . $_SESSION['part_pics_dir'] . '/' . $myrow['stockid'] . '.jpg" width="50" height="50" />'; - + $SupportedImgExt = array('png','jpg','jpeg'); + $imagefile = reset((glob($_SESSION['part_pics_dir'] . '/' . $myrow['stockid'] . '.{' . implode(",", $SupportedImgExt) . '}', GLOB_BRACE))); + if (extension_loaded('gd') && function_exists('gd_info') && file_exists ($imagefile) ) { + $ImageSource = '<img src="GetStockImage.php?automake=1&textcolor=FFFFFF&bgcolor=CCCCCC'. + '&StockID='.urlencode($myrow['stockid']). + '&text='. + '&width=64'. + '&height=64'. + '" alt="" />'; + } else if (file_exists ($imagefile)) { + $ImageSource = '<img src="' . $imagefile . '" height="64" width="64" />'; } else { - $ImageSource = '<i>' . _('No Image') . '</i>'; + $ImageSource = _('No Image'); } $UOMsql="SELECT conversionfactor, Modified: trunk/WorkOrderEntry.php =================================================================== --- trunk/WorkOrderEntry.php 2016-04-16 01:37:00 UTC (rev 7493) +++ trunk/WorkOrderEntry.php 2016-04-25 09:53:53 UTC (rev 7494) @@ -744,14 +744,20 @@ while ($myrow=DB_fetch_array($SearchResult)) { if (!in_array($myrow['stockid'],$ItemCodes)){ - if (function_exists('imagecreatefrompng') ){ - $ImageSource = '<img src="GetStockImage.php?automake=1&textcolor=FFFFFF&bgcolor=CCCCCC&StockID=' . urlencode($myrow['stockid']). '&text=&width=64&height=64" />'; + + $SupportedImgExt = array('png','jpg','jpeg'); + $imagefile = reset((glob($_SESSION['part_pics_dir'] . '/' . $myrow['stockid'] . '.{' . implode(",", $SupportedImgExt) . '}', GLOB_BRACE))); + if (extension_loaded('gd') && function_exists('gd_info') && file_exists ($imagefile) ) { + $ImageSource = '<img src="GetStockImage.php?automake=1&textcolor=FFFFFF&bgcolor=CCCCCC'. + '&StockID='.urlencode($myrow['stockid']). + '&text='. + '&width=64'. + '&height=64'. + '" alt="" />'; + } else if (file_exists ($imagefile)) { + $ImageSource = '<img src="' . $imagefile . '" height="64" width="64" />'; } else { - if(file_exists($_SERVER['DOCUMENT_ROOT'] . $RootPath . '/' . $_SESSION['part_pics_dir'] . '/' . $myrow['stockid'] . '.jpg')) { - $ImageSource = '<img src="' .$_SERVER['DOCUMENT_ROOT'] . $RootPath . '/' . $_SESSION['part_pics_dir'] . '/' . $myrow['stockid'] . '.jpg" />'; - } else { - $ImageSource = _('No Image'); - } + $ImageSource = _('No Image'); } if ($k==1){ Modified: trunk/WorkOrderIssue.php =================================================================== --- trunk/WorkOrderIssue.php 2016-04-16 01:37:00 UTC (rev 7493) +++ trunk/WorkOrderIssue.php 2016-04-25 09:53:53 UTC (rev 7494) @@ -792,15 +792,20 @@ while ($myrow=DB_fetch_array($SearchResult)) { + $SupportedImgExt = array('png','jpg','jpeg'); if (!in_array($myrow['stockid'],$ItemCodes)){ - if (function_exists('imagecreatefrompng') ){ - $ImageSource = '<img src="GetStockImage.php?automake=1&textcolor=FFFFFF&bgcolor=CCCCCC&StockID=' . urlencode($myrow['stockid']). '&text=&width=64&height=64" alt="" />'; + $imagefile = reset((glob($_SESSION['part_pics_dir'] . '/' . $myrow['stockid'] . '.{' . implode(",", $SupportedImgExt) . '}', GLOB_BRACE))); + if (extension_loaded('gd') && function_exists('gd_info') && file_exists ($imagefile) ) { + $ImageSource = '<img src="GetStockImage.php?automake=1&textcolor=FFFFFF&bgcolor=CCCCCC'. + '&StockID='.urlencode($myrow['stockid']). + '&text='. + '&width=64'. + '&height=64'. + '" alt="" />'; + } else if (file_exists ($imagefile)) { + $ImageSource = '<img src="' . $imagefile . '" height="64" width="64" />'; } else { - if(file_exists($_SERVER['DOCUMENT_ROOT'] . $RootPath. '/' . $_SESSION['part_pics_dir'] . '/' . $myrow['stockid'] . '.jpg')) { - $ImageSource = '<img src="' .$_SERVER['DOCUMENT_ROOT'] . $RootPath . '/' . $_SESSION['part_pics_dir'] . '/' . $myrow['stockid'] . '.jpg" alt="" />'; - } else { - $ImageSource = _('No Image'); - } + $ImageSource = _('No Image'); } if ($k==1){ Modified: trunk/Z_ChangeStockCode.php =================================================================== --- trunk/Z_ChangeStockCode.php 2016-04-16 01:37:00 UTC (rev 7493) +++ trunk/Z_ChangeStockCode.php 2016-04-25 09:53:53 UTC (rev 7494) @@ -161,15 +161,19 @@ /* ChangeFieldInTable("Stockdescriptions", "stockid", $_POST['OldStockID'], $_POST['NewStockID'], $db);// Updates the translated item descriptions (StockDescriptions)*/ echo '<br />' . _('Changing any image files'); - if (file_exists($_SESSION['part_pics_dir'] . '/' .$_POST['OldStockID'].'.jpg')){ - if (rename($_SESSION['part_pics_dir'] . '/' .$_POST['OldStockID'].'.jpg', - $_SESSION['part_pics_dir'] . '/' .$_POST['NewStockID'].'.jpg')) { - echo ' ... ' . _('completed'); + $SupportedImgExt = array('png','jpg','jpeg'); + foreach ($SupportedImgExt as $ext) { + $file = $_SESSION['part_pics_dir'] . '/' . $_POST['OldStockID'] . '.' . $ext; + if (file_exists ($file) ) { + if (rename($file, + $_SESSION['part_pics_dir'] . '/' .$_POST['NewStockID'] . '.' . $ext)) { + echo ' ... ' . _('completed'); + } else { + echo ' ... ' . _('failed'); + } } else { - echo ' ... ' . _('failed'); + echo ' .... ' . _('no image to rename'); } - } else { - echo ' .... ' . _('no image to rename'); } ChangeFieldInTable("stockitemproperties", "stockid", $_POST['OldStockID'], $_POST['NewStockID'], $db); Modified: trunk/Z_ItemsWithoutPicture.php =================================================================== --- trunk/Z_ItemsWithoutPicture.php 2016-04-16 01:37:00 UTC (rev 7493) +++ trunk/Z_ItemsWithoutPicture.php 2016-04-25 09:53:53 UTC (rev 7494) @@ -23,8 +23,10 @@ echo '<table class="selection">'; $k = 0; //row colour counter $i = 1; + $SupportedImgExt = array('png','jpg','jpeg'); while ($myrow = DB_fetch_array($result)) { - if(!file_exists($_SESSION['part_pics_dir'] . '/' .$myrow['stockid'].'.jpg') ) { + $imagefile = reset((glob($_SESSION['part_pics_dir'] . '/' . $myrow['stockid'] . '.{' . implode(",", $SupportedImgExt) . '}', GLOB_BRACE))); + if(!file_exists($imagefile) ) { if($PrintHeader){ $TableHeader = '<tr> <th>' . '#' . '</th> @@ -42,15 +44,15 @@ echo '<tr class="OddTableRows">'; $k = 1; } - $CodeLink = '<a href="' . $RootPath . '/SelectProduct.php?StockID=' . $myrow['stockid'] . '">' . $myrow['stockid'] . '</a>'; + $CodeLink = '<a href="' . $RootPath . '/SelectProduct.php?StockID=' . $myrow['stockid'] . '" target="_blank">' . $myrow['stockid'] . '</a>'; printf('<td class="number">%s</td> <td>%s</td> <td>%s</td> <td>%s</td> - </tr>', - $i, + </tr>', + $i, $myrow['categorydescription'], - $CodeLink, + $CodeLink, $myrow['description'] ); $i++; Modified: trunk/doc/Change.log =================================================================== --- trunk/doc/Change.log 2016-04-16 01:37:00 UTC (rev 7493) +++ trunk/doc/Change.log 2016-04-25 09:53:53 UTC (rev 7494) @@ -1,4 +1,6 @@ webERP Change Log + +25/4/16 Jan Bakke: Improvements to allow .png and .gif images 15/04/16 PaulT: add missing } causing error. 12/04/16 Exson: add cost security ... [truncated message content] |