Example #1
0
}elseif(file_exists($TemplateImageFile)) {
	if(!is_dir(ISC_BASE_PATH . '/cache/tplthumbs/')) {
		isc_mkdir(ISC_BASE_PATH . '/cache/tplthumbs/');
	}
	if((strtolower(substr($TemplateImageFile,-4)) == ".jpg" || strtolower(substr($TemplateImageFile,-5)) == ".jpeg") && function_exists('imagejpeg')) {
		// jpeg image
		header("Content-type: image/jpeg");
		$writeOptions = new ISC_IMAGE_WRITEOPTIONS_JPEG();
	}elseif(strtolower(substr($TemplateImageFile,-4)) == ".gif" && function_exists('imagegif') ) {
		// gif image
		header("Content-type: image/gif");
		$writeOptions = new ISC_IMAGE_WRITEOPTIONS_GIF();
	}
	header("Last-Modified: " . gmdate("r"));

	$image = ISC_IMAGE_LIBRARY_FACTORY::getImageLibraryInstance($TemplateImageFile);
	$image->loadImageFileToScratch();
	$image->resampleScratchToMaximumDimensions(200, 200);
	$image->saveScratchToFile($CacheTemplateImageFile, $writeOptions);
	unset($image);

	if(file_exists($CacheTemplateImageFile)) {
		echo file_get_contents($CacheTemplateImageFile);
	}
	else {
		OutputNoImage();
	}
	die();

}else {
	OutputNoImage();
Example #2
0
	/**
	 * Save an incoming vendor image (from the user's browser) in to the file system.
	 *
	 * @param int The vendor ID that this image should be attached to.
	 * @param string The type of image to upload - either self::VENDOR_LOGO or self::VENDOR_PHOTO
	 * @return string The path to the vendor image uploaded.
	 */
	private function SaveVendorImage($vendorId, $imageType)
	{
		// No image to save, so it's OK
		if(!isset($_FILES['vendor'.$imageType]) || !is_uploaded_file($_FILES['vendor'.$imageType]['tmp_name'])) {
			return '';
		}

		$maxDimensions = GetConfig('Vendor'.ucfirst($imageType).'Size');
		if(!$maxDimensions) {
			@unlink($_FILES['vendor'.$imageType]['tmp_name']);
			return '';
		}
		list($maxWidth, $maxHeight) = explode('x', $maxDimensions);

		$ext = GetFileExtension($_FILES['vendor'.$imageType]['name']);
		$imageName = 'vendor_images/'.$vendorId.'_'.$imageType.'.'.$ext;
		$destLocation = ISC_BASE_PATH.'/'.GetConfig('ImageDirectory').'/'.$imageName;

		// Attempt to move the image over (some hosts have problems working with files in the temp directory)
		if(!move_uploaded_file($_FILES['vendor'.$imageType]['tmp_name'], $destLocation)) {
			@unlink($_FILES['vendor'.$imageType]['tmp_name']);
			return false;
		}

		try {
			$image = ISC_IMAGE_LIBRARY_FACTORY::getImageLibraryInstance($destLocation);
			$image->loadImageFileToScratch();
			$image->resampleScratchToMaximumDimensions($maxWidth, $maxHeight);

			// simulate behaviour of old GenerateThumbnail function which would save to the same format as the original
			switch ($image->getImageType()) {
				case IMAGETYPE_GIF:
					$writeOptions = new ISC_IMAGE_WRITEOPTIONS_GIF;
					break;

				case IMAGETYPE_JPEG:
					$writeOptions = new ISC_IMAGE_WRITEOPTIONS_JPEG;
					break;

				case IMAGETYPE_PNG:
					$writeOptions = new ISC_IMAGE_WRITEOPTIONS_PNG;
					break;
			}

			$image->saveScratchToFile($destLocation, $writeOptions);
		} catch (Exception $exception) {
			return false;
		}

		// Otherwise, return the location of the image
		return $imageName;
	}
Example #3
0
		private function SaveCategoryImage()
		{
			if (!array_key_exists('catimagefile', $_FILES) || $_FILES['catimagefile']['error'] !== 0 || strtolower(substr($_FILES['catimagefile']['type'], 0, 6)) !== 'image/') {
				return false;
			}

			// Attempt to set the memory limit so we can resize this image
			ISC_IMAGE_LIBRARY_FACTORY::setImageFileMemLimit($_FILES['catimagefile']['tmp_name']);

			// Determine the destination directory
			$randomDir = strtolower(chr(rand(65, 90)));
			$destPath = realpath(ISC_BASE_PATH.'/' . GetConfig('ImageDirectory'));

			if (!is_dir($destPath . '/' . $randomDir)) {
				if (!isc_mkdir($destPath . '/' . $randomDir)) {
					$randomDir = '';
				}
			}

			$destFile = GenRandFileName($_FILES['catimagefile']['name'], 'category');
			$destPath = $destPath . '/' . $randomDir . '/' . $destFile;
			$returnPath = $randomDir . '/' . $destFile;

			$tmp = explode('.', $_FILES['catimagefile']['name']);
			$ext = strtolower($tmp[count($tmp)-1]);

			if ($ext == 'jpg') {
				$srcImg = imagecreatefromjpeg($_FILES['catimagefile']['tmp_name']);
			} else if($ext == 'gif') {
				$srcImg = imagecreatefromgif($_FILES['catimagefile']['tmp_name']);
				if(!function_exists('imagegif')) {
					$gifHack = 1;
				}
			} else {
				$srcImg = imagecreatefrompng($_FILES['catimagefile']['tmp_name']);
			}

			$srcWidth = imagesx($srcImg);
			$srcHeight = imagesy($srcImg);
			$widthLimit = GetConfig('CategoryImageWidth');
			$heightLimit = GetConfig('CategoryImageHeight');

			// If the image is small enough, simply move it
			if($srcWidth <= $widthLimit && $srcHeight <= $heightLimit) {
				imagedestroy($srcImg);
				move_uploaded_file($_FILES['catimagefile']['tmp_name'], $destPath);
				// set image to be writable
				isc_chmod($destPath, ISC_WRITEABLE_FILE_PERM);
				return $returnPath;
			}

			// Otherwise, resize it
			$attribs = getimagesize($_FILES['catimagefile']['tmp_name']);
			$width = $attribs[0];
			$height = $attribs[1];

			if($width > $widthLimit) {
				$height = ceil(($widthLimit/$width)*$height);
				$width = $widthLimit;
			}

			if($height > $heightLimit) {
				$width = ceil(($heightLimit/$height)*$width);
				$height = $heightLimit;
			}

			$dstImg = imagecreatetruecolor($width, $height);
			if($ext == "gif" && !isset($gifHack)) {
				$colorTransparent = imagecolortransparent($srcImg);
				imagepalettecopy($srcImg, $dstImg);
				imagecolortransparent($dstImg, $colorTransparent);
				imagetruecolortopalette($dstImg, true, 256);
			}
			else if($ext == "png") {
				ImageColorTransparent($dstImg, ImageColorAllocate($dstImg, 0, 0, 0));
				ImageAlphaBlending($dstImg, false);
			}

			imagecopyresampled($dstImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);

			if ($ext == "jpg") {
				imagejpeg($dstImg, $destPath, 100);
			} else if($ext == "gif") {
				if(isset($gifHack) && $gifHack == true) {
					$thumbFile = isc_substr($destPath, 0, -3)."jpg";
					imagejpeg($dstImg, $destPath, 100);
				}
				else {
					imagegif($dstImg, $destPath);
				}
			} else {
				imagepng($dstImg, $destPath);
			}

			@imagedestroy($dstImg);
			@imagedestroy($srcImg);
			@unlink($_FILES['catimagefile']['tmp_name']);

			// Change the permissions on the thumbnail file
			isc_chmod($destPath, ISC_WRITEABLE_FILE_PERM);

			return $returnPath;
		}
Example #4
0
		public function EditProductStep1($MsgDesc = "", $MsgStatus = "", $PreservePost=false)
		{
			if ($MsgDesc != "") {
				$GLOBALS['Message'] = MessageBox($MsgDesc, $MsgStatus);
			}

			// Show the form to edit a product
			$prodId = (int)$_REQUEST['productId'];
			$z = 0;
			$arrData = array();
			$arrCustomFields = array();

			// assign product comparison options to the template
			$this->template->assign('shoppingComparisonModules', $this->getComparisonOptions($prodId));

			if (GetConfig('CurrencyLocation') == 'right') {
				$GLOBALS['CurrencyTokenLeft'] = '';
				$GLOBALS['CurrencyTokenRight'] = GetConfig('CurrencyToken');
			} else {
				$GLOBALS['CurrencyTokenLeft'] = GetConfig('CurrencyToken');
				$GLOBALS['CurrencyTokenRight'] = '';
			}

			$GLOBALS['ServerFiles'] = $this->_GetImportFilesOptions();

			$GLOBALS['ISC_CLASS_ADMIN_CATEGORY'] = GetClass('ISC_ADMIN_CATEGORY');

			// load image manager language file as the lang vars are used by product image management
			$GLOBALS['ISC_CLASS_ADMIN_ENGINE']->LoadLangFile('imagemanager');

			// Make sure the product exists
			if (ProductExists($prodId)) {
				$this->_GetProductData($prodId, $arrData);

				// Does this user have permission to edit this product?
				if($GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId() && $arrData['prodvendorid'] != $GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId()) {
					FlashMessage(GetLang('Unauthorized'), MSG_ERROR, 'index.php?ToDo=viewProducts');
				}

				if($PreservePost == true) {
					$this->_GetProductData(0, $arrData);
					$this->_GetCustomFieldData(0, $arrCustomFields);
					$GLOBALS['ProductFields'] = $this->_GetProductFieldsLayout(0);
				} else {
					$this->_GetCustomFieldData($prodId, $arrCustomFields);
					$GLOBALS['ProductFields'] = $this->_GetProductFieldsLayout($prodId);
				}

				$this->template->assign('product', $arrData);

				if(isset($_POST['currentTab'])) {
					$GLOBALS['CurrentTab'] = (int)$_POST['currentTab'];
				}
				else {
					$GLOBALS['CurrentTab'] = 0;
				}

				$GLOBALS['FormAction'] = "editProduct2";
				$GLOBALS['ProductId'] = $prodId;
				$GLOBALS['Title'] = GetLang('EditProductTitle');
				$GLOBALS['Intro'] = GetLang('EditProductIntro');
				$GLOBALS["ProdType_" . $arrData['prodtype']] = 'checked="checked"';
				$GLOBALS['ProdType'] = $arrData['prodtype'] - 1;
				$GLOBALS['ProdCode'] = isc_html_escape($arrData['prodcode']);
				$GLOBALS['ProdHash'] = '';

				// set videos data
				$GLOBALS['YouTubeVideos'] = '';
				$videosArray = array();
				if(isset($arrData['product_videos']) && !empty($arrData['product_videos'])) {
					foreach($arrData['product_videos'] as $videoId => $videoData) {
						$videosArray[] = $videoId;
					}
					$GLOBALS['YouTubeVideos'] = isc_html_escape(implode(',', $videosArray));
				}

				// --- BEGIN PRODUCT IMAGES

				// create a html template for use in javascript when adding product image rows and store it as a javascript string
				$GLOBALS['productImage_thumbnailWidth'] = ISC_PRODUCT_IMAGE::getSizeWidth(ISC_PRODUCT_IMAGE_SIZE_THUMBNAIL);
				$GLOBALS['productImage_thumbnailHeight'] = ISC_PRODUCT_IMAGE::getSizeHeight(ISC_PRODUCT_IMAGE_SIZE_THUMBNAIL);
				$GLOBALS['productImage_newRowTemplate_js'] = isc_json_encode($this->template->render('product.form.images.row.tpl'));
				$GLOBALS['sessionid'] = session_id();
				$_SESSION['STORESUITE_CP_TOKEN'] = $_COOKIE['STORESUITE_CP_TOKEN'];

				// send through the file extensions that should be accepted as images
				$extensions = '*.' . implode(';*.', ISC_IMAGE_LIBRARY_FACTORY::getSupportedImageExtensions());
				$GLOBALS['productImage_swfUploadFileTypes_js'] = isc_json_encode($extensions);

				// generate statements to initialise new productimages as javascript objects
				$GLOBALS['productImage_javascriptInitialiseCode'] = '';
				foreach ($arrData['product_images'] as /** @var ISC_PRODUCT_IMAGE */$productImage) {

					$baseThumbnail = 'false';
					if ($productImage->getIsThumbnail()) {
						$baseThumbnail = 'true';
					}

					try {
						$preview = $productImage->getResizedUrl(ISC_PRODUCT_IMAGE_SIZE_THUMBNAIL, true);
						$zoom = $productImage->getResizedUrl(ISC_PRODUCT_IMAGE_SIZE_ZOOM, true);
						$original = $productImage->getSourceUrl();
					} catch (Exception $Exception) {
						$preview = false;
						$zoom = false;
						$original = false;
					}

					$GLOBALS['productImage_javascriptInitialiseCode'] .= sprintf(
						'new ProductImages.Image({id:%1$d,product:%8$d,preview:%2$s,zoom:%3$s,original:%9$s,description:%4$s,baseThumbnail:%5$s,sort:%7$d});',
						/*1*/ $productImage->getProductImageId(),
						/*2*/ isc_json_encode($preview),
						/*3*/ isc_json_encode($zoom),
						/*4*/ isc_json_encode($productImage->getDescription()),
						/*5*/ $baseThumbnail,
						/*6*/ null,
						/*7*/ $productImage->getSort(),
						/*8*/ $productImage->getProductId(),
						/*9*/ isc_json_encode($original)
					);
				}

				// done setting up the product images template, render it and put it into the main template
				$GLOBALS['productImagesList'] = $this->template->render('product.form.images.tpl');

				// --- END PRODUCT IMAGES

				// Get the list of tax classes and assign them
				$this->template->assign('taxClasses', array(
					0 => getLang('DefaultTaxClass')
				) + getClass('ISC_TAX')->getTaxClasses());

				$GLOBALS['ProdTags'] = isc_html_escape($arrData['prodtags']);


				$GLOBALS['ProdName'] = isc_html_escape($arrData['prodname']);
				$visibleCategories = array();
				if($GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId()) {
					$vendorData = $GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendor();
					if($vendorData['vendoraccesscats']) {
						$visibleCategories = explode(',', $vendorData['vendoraccesscats']);
					}
				}

				$GLOBALS['CategoryOptions'] = $GLOBALS["ISC_CLASS_ADMIN_CATEGORY"]->GetCategoryOptions($arrData['prodcats'], "<option %s value='%d'>%s</option>", "selected=\"selected\"", "", false, '', $visibleCategories);
				$GLOBALS['RelatedCategoryOptions'] = $GLOBALS["ISC_CLASS_ADMIN_CATEGORY"]->GetCategoryOptions(0, "<option %s value='%d'>%s</option>", "selected=\"selected\"", "- ", false);

				$wysiwygOptions = array(
					'id'		=> 'wysiwyg',
					'width'		=> '100%',
					'height'	=> '500px',
					'value'		=> $arrData['proddesc']
				);
				$GLOBALS['WYSIWYG'] = GetClass('ISC_ADMIN_EDITOR')->GetWysiwygEditor($wysiwygOptions);

				$GLOBALS['ProdSearchKeywords'] = isc_html_escape($arrData['prodsearchkeywords']);
				$GLOBALS['ProdAvailability'] = isc_html_escape($arrData['prodavailability']);
				$GLOBALS['ProdPrice'] = number_format($arrData['prodprice'], GetConfig('DecimalPlaces'), GetConfig('DecimalToken'), "");

				if (CFloat($arrData['prodcostprice']) > 0) {
					$GLOBALS['ProdCostPrice'] = number_format($arrData['prodcostprice'], GetConfig('DecimalPlaces'), GetConfig('DecimalToken'), "");
				}

				if (CFloat($arrData['prodretailprice']) > 0) {
					$GLOBALS['ProdRetailPrice'] = number_format($arrData['prodretailprice'], GetConfig('DecimalPlaces'), GetConfig('DecimalToken'), "");
				}

				if (CFloat($arrData['prodsaleprice']) > 0) {
					$GLOBALS['ProdSalePrice'] = number_format($arrData['prodsaleprice'], GetConfig('DecimalPlaces'), GetConfig('DecimalToken'), "");
				}

				$GLOBALS['ProdSortOrder'] = $arrData['prodsortorder'];

				if ($arrData['prodvisible'] == 1) {
					$GLOBALS['ProdVisible'] = "checked";
				}

				if ($arrData['prodfeatured'] == 1) {
					$GLOBALS['ProdFeatured'] = "checked";
				}

				if($GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId()) {
					$GLOBALS['HideStoreFeatured'] = 'display: none';
				}
				else if(!gzte11(ISC_HUGEPRINT) || !$arrData['prodvendorid']) {
					$GLOBALS['HideVendorFeatured'] = 'display: none';
				}

				if($arrData['prodvendorfeatured'] == 1) {
					$GLOBALS['ProdVendorFeatured'] = 'checked="checked"';
				}

				if($arrData['prodallowpurchases'] == 1) {
					$GLOBALS['ProdAllowPurchases'] = 'checked="checked"';
				}
				else {
					if($arrData['prodhideprice'] == 1) {
						$GLOBALS['ProdHidePrice'] = 'checked="checked"';
					}
					$GLOBALS['ProdCallForPricingLabel'] = isc_html_escape($arrData['prodcallforpricinglabel']);
				}

				$GLOBALS['ProdWarranty'] = $arrData['prodwarranty'];
				$GLOBALS['ProdWeight'] = number_format($arrData['prodweight'], GetConfig('DimensionsDecimalPlaces'), GetConfig('DimensionsDecimalToken'), "");

				if (CFloat($arrData['prodwidth']) > 0) {
					$GLOBALS['ProdWidth'] = number_format($arrData['prodwidth'], GetConfig('DimensionsDecimalPlaces'), GetConfig('DimensionsDecimalToken'), "");
				}

				if (CFloat($arrData['prodheight']) > 0) {
					$GLOBALS['ProdHeight'] = number_format($arrData['prodheight'], GetConfig('DimensionsDecimalPlaces'), GetConfig('DimensionsDecimalToken'), "");
				}

				if (CFloat($arrData['proddepth']) > 0) {
					$GLOBALS['ProdDepth'] = number_format($arrData['proddepth'], GetConfig('DimensionsDecimalPlaces'), GetConfig('DimensionsDecimalToken'), "");
				}

				if (CFloat($arrData['prodfixedshippingcost']) > 0) {
					$GLOBALS['ProdFixedShippingCost'] = number_format($arrData['prodfixedshippingcost'], GetConfig('DecimalPlaces'), GetConfig('DecimalToken'), "");
				}

				if ($arrData['prodfreeshipping'] == 1) {
					$GLOBALS['FreeShipping'] = 'checked="checked"';
				}

				if($arrData['prodrelatedproducts'] == -1) {
					$GLOBALS['IsProdRelatedAuto'] = 'checked="checked"';
				}
				else if(isset($arrData['prodrelated'])) {
					$GLOBALS['RelatedProductOptions'] = "";

					foreach ($arrData['prodrelated'] as $r) {
						$GLOBALS['RelatedProductOptions'] .= sprintf("<option value='%d'>%s</option>", (int) $r[0], isc_html_escape($r[1]));
					}
				}

				$GLOBALS['CurrentStockLevel'] = $arrData['prodcurrentinv'];
				$GLOBALS['LowStockLevel'] = $arrData['prodlowinv'];
				$GLOBALS["InvTrack_" . $arrData['prodinvtrack']] = 'checked="checked"';

				if ($arrData['prodinvtrack'] == 1) {
					$GLOBALS['OptionButtons'] = "ToggleProductInventoryOptions(true);";
				} else {
					$GLOBALS['OptionButtons'] = "ToggleProductInventoryOptions(false);";
				}

				if ($arrData['prodoptionsrequired'] == 1) {
					$GLOBALS['OptionsRequired'] = 'checked="checked"';
				}

				if ($arrData['prodtype'] == 1) {
					$GLOBALS['HideProductInventoryOptions'] = "none";
				}

				$GLOBALS['EnterOptionPrice'] = sprintf(GetLang('EnterOptionPrice'), GetConfig('CurrencyToken'), GetConfig('CurrencyToken'));
				$GLOBALS['EnterOptionWeight'] = sprintf(GetLang('EnterOptionWeight'), GetConfig('WeightMeasurement'));
				$GLOBALS['HideCustomFieldLink'] = "none";

				if(getConfig('taxEnteredWithPrices') == TAX_PRICES_ENTERED_INCLUSIVE) {
					$this->template->assign('enterPricesWithTax', true);
				}

				$GLOBALS['ProductFields'] = $this->_GetProductFieldsLayout($prodId);

				$GLOBALS['CustomFields'] = '';
				$GLOBALS['CustomFieldKey'] = 0;

				if (!empty($arrCustomFields)) {
					foreach ($arrCustomFields as $f) {
						$GLOBALS['CustomFieldName'] = isc_html_escape($f['name']);
						$GLOBALS['CustomFieldValue'] = isc_html_escape($f['value']);
						$GLOBALS['CustomFieldLabel'] = $this->GetFieldLabel(($GLOBALS['CustomFieldKey']+1), GetLang('CustomField'));

						if (!$GLOBALS['CustomFieldKey']) {
							$GLOBALS['HideCustomFieldDelete'] = 'none';
						} else {
							$GLOBALS['HideCustomFieldDelete'] = '';
						}

						$GLOBALS['CustomFields'] .= $this->template->render('Snippets/CustomFields.html');

						$GLOBALS['CustomFieldKey']++;
					}
				}

				// Add one more custom field
				$GLOBALS['CustomFieldName'] = '';
				$GLOBALS['CustomFieldValue'] = '';
				$GLOBALS['CustomFieldLabel'] = $this->GetFieldLabel(($GLOBALS['CustomFieldKey']+1), GetLang('CustomField'));

				if (!$GLOBALS['CustomFieldKey']) {
					$GLOBALS['HideCustomFieldDelete'] = 'none';
				} else {
					$GLOBALS['HideCustomFieldDelete'] = '';
				}

				$GLOBALS['CustomFields'] .= $this->template->render('Snippets/CustomFields.html');

				$GLOBALS['ProductHash'] = '';

				// Get a list of any downloads associated with this product
				$GLOBALS['DownloadsGrid'] = $this->GetDownloadsGrid($prodId);
				$GLOBALS['ISC_LANG']['MaxUploadSize'] = sprintf(GetLang('MaxUploadSize'), GetMaxUploadSize());
				if($GLOBALS['DownloadsGrid'] == '') {
					$GLOBALS['DisplayDownloaadGrid'] = "none";
				}

				// Get the brands as select options
				$GLOBALS['ISC_CLASS_ADMIN_BRANDS'] = GetClass('ISC_ADMIN_BRANDS');
				$GLOBALS['BrandNameOptions'] = $GLOBALS['ISC_CLASS_ADMIN_BRANDS']->GetBrandsAsOptions($arrData['prodbrandid']);
				$GLOBALS['SaveAndAddAnother'] = GetLang('SaveAndContinueEditing');

				// Get a list of all layout files
				$layoutFile = 'product.html';
				if($arrData['prodlayoutfile'] != '') {
					$layoutFile = $arrData['prodlayoutfile'];
				}
				$GLOBALS['LayoutFiles'] = GetCustomLayoutFilesAsOptions("product.html", $layoutFile);

				$GLOBALS['ProdPageTitle'] = isc_html_escape($arrData['prodpagetitle']);
				$GLOBALS['ProdMetaKeywords'] = isc_html_escape($arrData['prodmetakeywords']);
				$GLOBALS['ProdMetaDesc'] = isc_html_escape($arrData['prodmetadesc']);
				$GLOBALS['SaveAndAddAnother'] = GetLang('SaveAndContinueEditing');

				if(!gzte11(ISC_MEDIUMPRINT)) {
					$GLOBALS['HideInventoryOptions'] = "none";
				}
				else {
					$GLOBALS['HideInventoryOptions'] = '';
				}

				// Does this product have a variation assigned to it?
				$GLOBALS['ProductVariationExisting'] = $arrData['prodvariationid'];

				if($arrData['prodvariationid'] > 0) {
					$GLOBALS['IsYesVariation'] = 'checked="checked"';
				}
				else {
					$GLOBALS['IsNoVariation'] = 'checked="checked"';
					$GLOBALS['HideVariationList'] = "none";
					$GLOBALS['HideVariationCombinationList'] = "none";
				}

				// If there are no variations then disable the option to choose one
				$numVariations = 0;
				$GLOBALS['VariationOptions'] = $this->GetVariationsAsOptions($numVariations, $arrData['prodvariationid']);

				if($numVariations == 0) {
					$GLOBALS['VariationDisabled'] = "DISABLED";
					$GLOBALS['VariationColor'] = "#CACACA";
					$GLOBALS['IsNoVariation'] = 'checked="checked"';
					$GLOBALS['IsYesVariation'] = "";
					$GLOBALS['HideVariationCombinationList'] = "none";
				}
				else {
					// Load the variation combinations
					if($arrData['prodinvtrack'] == 2) {
						$show_inv_fields = true;
					}
					else {
						$show_inv_fields = false;
					}

					$GLOBALS['VariationCombinationList'] = $this->_LoadVariationCombinationsTable($arrData['prodvariationid'], $show_inv_fields, $arrData['productid']);
				}

				$GLOBALS['WrappingOptions'] = $this->BuildGiftWrappingSelect(explode(',', $arrData['prodwrapoptions']));
				$GLOBALS['HideGiftWrappingOptions'] = 'display: none';
				if($arrData['prodwrapoptions'] == 0) {
					$GLOBALS['WrappingOptionsDefaultChecked'] = 'checked="checked"';
				}
				else if($arrData['prodwrapoptions'] == -1) {
					$GLOBALS['WrappingOptionsNoneChecked'] = 'checked="checked"';
				}
				else {
					$GLOBALS['HideGiftWrappingOptions'] = '';
					$GLOBALS['WrappingOptionsCustomChecked'] = 'checked="checked"';
				}

				if(!gzte11(ISC_HUGEPRINT)) {
					$GLOBALS['HideVendorOption'] = 'display: none';
				}
				else {
					$vendorData = $GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendor();
					if(isset($vendorData['vendorid'])) {
						$GLOBALS['HideVendorSelect'] = 'display: none';
						$GLOBALS['CurrentVendor'] = isc_html_escape($vendorData['vendorname']);
					}
					else {
						$GLOBALS['HideVendorLabel'] = 'display: none';
						$GLOBALS['VendorList'] = $this->BuildVendorSelect($arrData['prodvendorid']);
					}
				}

				// Display the discount rules
				if ($PreservePost == true) {
					$GLOBALS['DiscountRules'] = $this->GetDiscountRules(0);
				} else {
					$GLOBALS['DiscountRules'] = $this->GetDiscountRules($prodId);
				}

				// Hide if we are not enabled
				if (!GetConfig('BulkDiscountEnabled')) {
					$GLOBALS['HideDiscountRulesWarningBox'] = '';
					$GLOBALS['DiscountRulesWarningText'] = GetLang('DiscountRulesNotEnabledWarning');
					$GLOBALS['DiscountRulesWithWarning'] = 'none';

				// Also hide it if this product has variations
				} else if (isset($arrData['prodvariationid']) && isId($arrData['prodvariationid'])) {
					$GLOBALS['HideDiscountRulesWarningBox'] = '';
					$GLOBALS['DiscountRulesWarningText'] = GetLang('DiscountRulesVariationWarning');
					$GLOBALS['DiscountRulesWithWarning'] = 'none';
				} else {
					$GLOBALS['HideDiscountRulesWarningBox'] = 'none';
					$GLOBALS['DiscountRulesWithWarning'] = '';
				}

				$GLOBALS['DiscountRulesEnabled'] = (int)GetConfig('BulkDiscountEnabled');

				if(!$GLOBALS['ISC_CLASS_ADMIN_AUTH']->HasPermission(AUTH_Create_Category)) {
					$GLOBALS['HideCategoryCreation'] = 'display: none';
				}

				$GLOBALS['EventDateFieldName'] = $arrData['prodeventdatefieldname'];

				if ($GLOBALS['EventDateFieldName'] == null) {
					$GLOBALS['EventDateFieldName'] = GetLang('EventDateDefault');
				}

				if ($arrData['prodeventdaterequired'] == 1) {
					$GLOBALS['EventDateRequired'] = 'checked="checked"';
					$from_stamp = $arrData['prodeventdatelimitedstartdate'];
					$to_stamp = $arrData['prodeventdatelimitedenddate'];
				} else {
					$from_stamp = isc_gmmktime(0, 0, 0, isc_date("m"), isc_date("d"), isc_date("Y"));
					$to_stamp = isc_gmmktime(0, 0, 0, isc_date("m")+1, isc_date("d"), isc_date("Y"));
				}
				if ($arrData['prodeventdatelimited'] == 1) {
					$GLOBALS['LimitDates'] = 'checked="checked"';
				}

				$GLOBALS['LimitDateOption1'] = '';
				$GLOBALS['LimitDateOption2'] = '';
				$GLOBALS['LimitDateOption3'] = '';

				switch ($arrData['prodeventdatelimitedtype']) {

					case 1 :
						$GLOBALS['LimitDateOption1'] = 'selected="selected"';
					break;
					case 2 :
						$GLOBALS['LimitDateOption2'] = 'selected="selected"';
					break;
					case 3 :
						$GLOBALS['LimitDateOption3'] = 'selected="selected"';
					break;
				}

				// Set the global variables for the select boxes

				$from_day = isc_date("d", $from_stamp);
				$from_month = isc_date("m", $from_stamp);
				$from_year = isc_date("Y", $from_stamp);

				$to_day = isc_date("d", $to_stamp);
				$to_month = isc_date("m", $to_stamp);
				$to_year = isc_date("Y", $to_stamp);

				$GLOBALS['OverviewFromDays'] = $this->_GetDayOptions($from_day);
				$GLOBALS['OverviewFromMonths'] = $this->_GetMonthOptions($from_month);
				$GLOBALS['OverviewFromYears'] = $this->_GetYearOptions($from_year);

				$GLOBALS['OverviewToDays'] = $this->_GetDayOptions($to_day);
				$GLOBALS['OverviewToMonths'] = $this->_GetMonthOptions($to_month);
				$GLOBALS['OverviewToYears'] = $this->_GetYearOptions($to_year);

				$GLOBALS['ProdMYOBAsset'] = isc_html_escape($arrData['prodmyobasset']);
				$GLOBALS['ProdMYOBIncome'] = isc_html_escape($arrData['prodmyobincome']);
				$GLOBALS['ProdMYOBExpense'] = isc_html_escape($arrData['prodmyobexpense']);

				$GLOBALS['ProdPeachtreeGL'] = isc_html_escape($arrData['prodpeachtreegl']);

				$GLOBALS['ProdCondition' . $arrData['prodcondition'] . 'Selected'] = 'selected="selected"';
				if ($arrData['prodshowcondition']) {
					$GLOBALS['ProdShowCondition'] = 'checked="checked"';
				}

				//Google website optimizer
				$GLOBALS['GoogleWebsiteOptimizerIntro'] = GetLang('ProdGoogleWebsiteOptimizerIntro');

				$GLOBALS['HideOptimizerConfigForm'] = 'display:none;';
				$GLOBALS['CheckEnableOptimizer'] = '';

				$GLOBALS['SkipOptimizerConfirmMsg'] = 'true';
				$enabledOptimizers = GetConfig('OptimizerMethods');
				if(!empty($enabledOptimizers)) {
					foreach ($enabledOptimizers as $id => $date) {
						GetModuleById('optimizer', $optimizerModule, $id);
						if ($optimizerModule->_testPage == 'products' || $optimizerModule->_testPage == 'all') {
							$GLOBALS['SkipOptimizerConfirmMsg'] = 'false';
							break;
						}
					}
				}

				if($arrData['product_enable_optimizer'] == '1') {
					$GLOBALS['HideOptimizerConfigForm'] = '';
					$GLOBALS['CheckEnableOptimizer'] = 'Checked';
				}

				if ($arrData['prodminqty']) {
					$this->template->assign('prodminqty', $arrData['prodminqty']);
				}

				if ($arrData['prodmaxqty']) {
					$this->template->assign('prodmaxqty', $arrData['prodmaxqty']);
				}

				$optimizer = getClass('ISC_ADMIN_OPTIMIZER');
				$GLOBALS['OptimizerConfigForm'] = $optimizer->showPerItemConfigForm('product', $prodId, prodLink($arrData['prodname']));

				if ($arrData['prodpreorder'] && $arrData['prodreleasedateremove'] && time() >= $arrData['prodreleasedate']) {
					// pre-order release date has passed and remove is ticked, remove it now for the edit form at least - saving it will commit it to the db
					$arrData['prodpreorder'] = 0;
					$arrData['prodreleasedate'] = 0;
					$arrData['prodreleasedateremove'] = 0;
				}

				// note: prodpreorder is a database column does not map directly to a form field, it'll be set to 1 if _prodorderable is 'pre', along with prodallowpurchases to 1
				// note: _prodorderable is a form field that does not map to a database column
				if (!$arrData['prodallowpurchases']) {
					$this->template->assign('_prodorderable', 'no');
				} else if ($arrData['prodpreorder']) {
					$this->template->assign('_prodorderable', 'pre');
				} else {
					$this->template->assign('_prodorderable', 'yes');
				}

				$this->template->assign('prodreleasedateremove', $arrData['prodreleasedateremove']);

				if (isset($arrData['prodpreordermessage']) && $arrData['prodpreordermessage']) {
					$this->template->assign('prodpreordermessage', $arrData['prodpreordermessage']);
				} else {
					$this->template->assign('prodpreordermessage', GetConfig('DefaultPreOrderMessage'));
				}

				if ($arrData['prodreleasedate']) {
					$this->template->assign('prodreleasedate', isc_date('m/d/Y', $arrData['prodreleasedate']));
				}

				// Open Graph Settings
				$this->template->assign('openGraphTypes', ISC_OPENGRAPH::getObjectTypes(true));
				$this->template->assign('openGraphSelectedType', $arrData['opengraph_type']);
				$this->template->assign('openGraphUseProductName', (bool)$arrData['opengraph_use_product_name']);
				$this->template->assign('openGraphTitle', $arrData['opengraph_title']);
				$this->template->assign('openGraphUseMetaDescription', (bool)$arrData['opengraph_use_meta_description']);
				$this->template->assign('openGraphDescription', $arrData['opengraph_description']);
				$this->template->assign('openGraphUseImage', (bool)$arrData['opengraph_use_image']);

				// UPC
				$this->template->assign('ProdUPC', isc_html_escape($arrData['upc']));

				// Google Checkout
				$this->template->assign('ProdDisableGoogleCheckout', isc_html_escape($arrData['disable_google_checkout']));

				$GLOBALS['SaveAndAddAnother'] = GetLang('SaveAndContinueEditing');
				$this->setupProductLanguageString();
				$this->template->display('product.form.tpl');
			} else {
				// The product doesn't exist
				if ($GLOBALS["ISC_CLASS_ADMIN_AUTH"]->HasPermission(AUTH_Manage_Products)) {
					$this->ManageProducts(GetLang('ProductDoesntExist'), MSG_ERROR);
				} else {
					$GLOBALS['ISC_CLASS_ADMIN_ENGINE']->DoHomePage(GetLang('Unauthorized'), MSG_ERROR);
				}
			}
		}
Example #5
0
	/**
	* Returns the width and height of the actual resized version of a product image in the form of an arrray where index 0 is width, index 1 is height.
	*
	* @param int $size One of the defined ISC_PRODUCT_IMAGE_SIZE_? constants
	* @param bool $generate If necessary, generate the resized image to determine it's size otherwise will rely purely on any internally cached values. If this is called with $generate as false and no value has been stored yet, null will be returned.
	* @param bool $save If necessary, update image in the database with the correct sizes
	* @throws ISC_PRODUCT_IMAGE_INVALIDSIZE_EXCEPTION If an invalid size is specified
	* @return array index 0 is width, index 1 is height
	*/
	public function getResizedFileDimensions($size, $generate = true, $save = true)
	{
		if ($generate || $this->_resizedFileDimensions[$size] === null) {
			$imageFilePath = $this->getAbsoluteResizedFilePath($size, $generate, $save);

			// if the call above actually generated the file then the size will now be cached and we don't need to calculate it again
			if ($this->_resizedFileDimensions[$size] === null) {
				try {
					$library = ISC_IMAGE_LIBRARY_FACTORY::getImageLibraryInstance($imageFilePath);
					$this->_resizedFileDimensions[$size] = array($library->getWidth(), $library->getHeight());
				} catch (ISC_IMAGE_LIBRARY_FACTORY_FILEDOESNTEXIST_EXCEPTION $exception) {
					// do nothing, keep size as null
				}
			}
		}

		return $this->_resizedFileDimensions[$size];
	}
	public function getImageTypeExtension($includeDot = true)
	{
		$ext = ISC_IMAGE_LIBRARY_FACTORY::getExtensionForImageType($this->getImageType());

		if ($includeDot) {
			$ext = '.' . $ext;
		}

		return $ext;
	}
	/**
	* Load the current file from disk to in-memory resource
	*
	* @return void
	*/
	public function loadImageFileToScratch()
	{
		$filePath = $this->getFilePath();
		$imageType = $this->getImageType();

		// Attempt to increase the memory limit before loading in the image, to ensure it'll fit in memory
		ISC_IMAGE_LIBRARY_FACTORY::setImageFileMemLimit($filePath);

		switch ($imageType) {
			case IMAGETYPE_GIF:
				$this->_scratchResource = @imagecreatefromgif($filePath);
				if ($this->getScratchResource()) {
					imagecolortransparent($this->getScratchResource());
				}
				break;

			case IMAGETYPE_PNG:
				$this->_scratchResource = @imagecreatefrompng($filePath);
				if ($this->_scratchResource) {
					// this sets up alpha transparency support when manipulating and saving the in-memory image
					imagealphablending($this->getScratchResource(), false);
					imagesavealpha($this->getScratchResource(), true);
				}
				break;

			case IMAGETYPE_JPEG:
				$this->_scratchResource = @imagecreatefromjpeg($filePath);
				break;

			default:
				throw new ISC_IMAGE_LIBRARY_GD_UNSUPPORTEDIMAGETYPE_EXCEPTION($imageType);
		}

		$this->_updateImageInformation(true);

		if (!$this->getScratchResource()) {
			throw new ISC_IMAGE_LIBRARY_GD_IMAGECREATEFROMFILE_EXCEPTION($imageType, $filePath);
		}
	}