Esempio n. 1
0
		private function ValidateCustomerGroupData($data, &$error)
		{
			if (trim($data['groupname']) == '') {
				$error = GetLang('CustomerGroupEnterName');
				return false;
			}

			$nameCheckSQL = "
				SELECT *
				FROM [|PREFIX|]customer_groups
				WHERE groupname = '" . $GLOBALS['ISC_CLASS_DB']->Quote($data['groupname']) . "'
			";

			if (isId($data['customergroupid'])) {
				$nameCheckSQL .= " AND customergroupid != " . (int)$data['customergroupid'];
			}

			if ($GLOBALS['ISC_CLASS_DB']->CountResult($nameCheckSQL)) {
				$error = sprintf(GetLang('CustomerGroupAlreadyExists'), isc_html_escape($data['groupname']));
				return false;
			}

			if (isc_strtolower($data['categoryaccesstype']) == 'specific' && (!is_array($data['accesscategorieslist']) || empty($data['accesscategorieslist']))) {
				$error = GetLang('CustomerGroupsEmptyCategoryList');
				return false;
			}

			if (isc_strtolower($data['discountmethod']) == 'percent' && (CFloat($data['discount']) < 0 || CFloat($data['discount']) > 100)) {
				$error = GetLang('CustomerGroupEnterStoreDiscount');
				return false;
			}

			if (isc_strtolower($data['discountmethod']) !== 'percent' && CPrice($data['discount']) == '') {
				$error = GetLang('CustomerGroupEnterStoreDiscount');
				return false;
			}

			$products = array();
			$categories = array();

			if (is_array($data['discountlist']) && !empty($data['discountlist'])) {
				foreach ($data['discountlist'] as $discount) {

					if (isc_strtolower($discount['discounttype']) == 'product') {
						$stack =& $products;
						$countSQL = "SELECT * FROM [|PREFIX|]products WHERE productid = " . (int)$discount['catorprodid'];
						$pageNavVar = 'pageNavToProduct';
					} else {
						$stack =& $categories;
						$countSQL = "SELECT * FROM [|PREFIX|]categories WHERE categoryid = " . (int)$discount['catorprodid'];
						$pageNavVar = 'pageNavToCategory';
					}

					if (!isId($discount['catorprodid']) || !$GLOBALS['ISC_CLASS_DB']->CountResult($countSQL)) {
						$GLOBALS[$pageNavVar] = max(1, ceil($discount['discountid'] / ISC_GROUPDISCOUNT_ITEMS_PER_PAGE));
						$error = sprintf(GetLang('CustomerGroupsInvalid' . ucfirst(isc_strtolower($discount['discounttype']))), $discount['discountid']);
						return false;
					}

					if (array_key_exists($discount['catorprodid'], $stack)) {
						$GLOBALS[$pageNavVar] = max(1, ceil($discount['discountid'] / ISC_GROUPDISCOUNT_ITEMS_PER_PAGE));
						$error = sprintf(GetLang('CustomerGroupsDuplicate' . ucfirst(isc_strtolower($discount['discounttype']))), $discount['discountid'], $stack[$discount['catorprodid']]);
						return false;
					} else {
						$stack[$discount['catorprodid']] = $discount['discountid'];
					}

					if (trim($discount['discountpercent']) == '') {
						$GLOBALS[$pageNavVar] = max(1, ceil($discount['discountid'] / ISC_GROUPDISCOUNT_ITEMS_PER_PAGE));
						$error = sprintf(GetLang('CustomerGroupsInvalid' . ucfirst(isc_strtolower($discount['discounttype'])) . 'Amount'), $discount['discountid']);
						return false;
					}

					if (isc_strtolower($discount['discountmethod']) == 'percent' && (CFloat($discount['discountpercent']) < 0 || CFloat($discount['discountpercent']) > 100)) {
						$GLOBALS[$pageNavVar] = max(1, ceil($discount['discountid'] / ISC_GROUPDISCOUNT_ITEMS_PER_PAGE));
						$error = sprintf(GetLang('CustomerGroupsInvalid' . ucfirst(isc_strtolower($discount['discounttype'])) . 'Amount'), $discount['discountid']);
						return false;
					}

					if (isc_strtolower($discount['discountmethod']) !== 'percent' && CPrice($discount['discountpercent']) == '') {
						$GLOBALS[$pageNavVar] = max(1, ceil($discount['discountid'] / ISC_GROUPDISCOUNT_ITEMS_PER_PAGE));
						$error = sprintf(GetLang('CustomerGroupsInvalid' . ucfirst(isc_strtolower($discount['discounttype'])) . 'Amount'), $discount['discountid']);
						return false;
					}
				}
			}

			return true;
		}
 /**
  * Validate discount rules data
  *
  * Method will validate all the discount rules POST data
  *
  * @access private
  * @param string &$error The referenced string to store the error in, if any were found
  * @return bool TRUE if POST data is valid, FALSE if there were errors
  */
 private function ValidateDiscountRulesData(&$error)
 {
     $discounts = $this->GetDiscountRulesData(0);
     // Check to see if we have anything to validate
     if (empty($discounts)) {
         return true;
     }
     // Variable to check for overlapping
     $overlap = array(0 => array(), 1 => array());
     // This is to check for the previous quantities
     $prevMax = null;
     // OK, we have some, now check each rule
     foreach ($discounts as $key => $discount) {
         // Check first to see if these are empty records. If so then just continue
         if ($discount['quantitymin'] == '' && $discount['quantitymax'] == '' && $discount['amount'] == '') {
             continue;
         }
         if ($discount['quantitymin'] == '') {
             $error = sprintf(GetLang('DiscountRulesQuantityMinRequired'), $key + 1);
             return false;
         }
         if (!isId($discount['quantitymin']) && $discount['quantitymin'] !== '*') {
             $error = sprintf(GetLang('DiscountRulesQuantityMinInvalid'), $key + 1);
             return false;
         }
         if ($discount['quantitymax'] == '') {
             $error = sprintf(GetLang('DiscountRulesQuantityMaxRequired'), $key + 1);
             return false;
         }
         if (!isId($discount['quantitymax']) && $discount['quantitymax'] !== '*') {
             $error = sprintf(GetLang('DiscountRulesQuantityMaxInvalid'), $key + 1);
             return false;
         }
         // Check to see if the min is still lower than the maximum quantity
         if ($discount['quantitymin'] !== '*' && $discount['quantitymax'] !== '*' && $discount['quantitymin'] > $discount['quantitymax']) {
             $error = sprintf(GetLang('DiscountRulesQuantityMinHigher'), $key + 1);
             return false;
         }
         // Both min and max values cannot be astrix
         if ($discount['quantitymin'] == '*' && $discount['quantitymax'] == '*') {
             $error = sprintf(GetLang('DiscountRulesQuantityBothAstrix'), $key + 1);
             return false;
         }
         // Check to see if the previous max and current min quantities are both astrixes
         if (!is_null($prevMax) && $prevMax == '*' && $discount['quantitymin'] == '*') {
             $error = sprintf(GetLang('DiscountRulesQuantityMinPrevMaxAstrix'), $key + 1);
             return false;
         }
         // Check for overlapping
         if ($discount['quantitymin'] !== '*' && CheckNumericOverlapping($discount['quantitymin'], $overlap) == 1) {
             $error = sprintf(GetLang('DiscountRulesQuantityMinOverlap'), $key + 1);
             return false;
         }
         if ($discount['quantitymax'] !== '*' && CheckNumericOverlapping($discount['quantitymin'], $overlap) == 1) {
             $error = sprintf(GetLang('DiscountRulesQuantityMinOverlap'), $key + 1);
             return false;
         }
         // Check those values for our next loop
         if ($discount['quantitymin'] !== '*') {
             $overlap[0][] = $discount['quantitymin'];
         } else {
             $overlap[0][] = '';
         }
         if ($discount['quantitymax'] !== '*') {
             $overlap[1][] = $discount['quantitymax'];
         } else {
             $overlap[1][] = '';
         }
         $type = isc_strtolower(isc_html_escape($discount['type']));
         // Do we have the currect type?
         if ($type !== 'price' && $type !== 'percent' && $type !== 'fixed') {
             $error = sprintf(GetLang('DiscountRulesTypeInvalid'), $key + 1);
             return false;
         }
         if ($discount['amount'] == '') {
             $error = sprintf(GetLang('DiscountRulesAmountRequired'), $key + 1);
             return false;
         }
         // Do we have a valit price/percentage?
         if (!isId($discount['amount']) && CPrice($discount['amount']) == '') {
             $error = sprintf(GetLang('DiscountRulesAmountInvalid'), $key + 1);
             return false;
         }
         // Now we do some checking compared againt the product price
         switch ($type) {
             case 'price':
                 if ($discount['amount'] >= $_POST['prodPrice']) {
                     $error = sprintf(GetLang('DiscountRulesAmountPriceInvalid'), $key + 1);
                     return false;
                 }
                 break;
             case 'percent':
                 if ((int) $discount['amount'] >= 100) {
                     $error = sprintf(GetLang('DiscountRulesAmountPercentInvalid'), $key + 1);
                     return false;
                 } else {
                     if (strpos($discount['amount'], '.') !== false) {
                         $error = sprintf(GetLang('DiscountRulesAmountPercentIsFloat'), $key + 1);
                         return false;
                     }
                 }
                 break;
             case 'fixed':
                 if ($discount['amount'] >= $_POST['prodPrice']) {
                     $error = sprintf(GetLang('DiscountRulesAmountFixedInvalid'), $key + 1);
                     return false;
                 }
                 break;
         }
         // Store value to be used as previous value next time
         $prevMax = $discount['quantitymax'];
     }
     return true;
 }
 private function EditCouponStep1()
 {
     // Show the form to edit a news
     $couponId = (int) $_GET['couponId'];
     $arrData = array();
     $sel_cats = array();
     if (GetConfig('CurrencyLocation') == 'right') {
         $GLOBALS['CurrencyTokenLeft'] = '';
         $GLOBALS['CurrencyTokenRight'] = GetConfig('CurrencyToken');
     } else {
         $GLOBALS['CurrencyTokenLeft'] = GetConfig('CurrencyToken');
         $GLOBALS['CurrencyTokenRight'] = '';
     }
     $GLOBALS['CurrencyToken'] = GetConfig('CurrencyToken');
     if (CouponExists($couponId)) {
         $this->_GetCouponData($couponId, $arrData);
         $GLOBALS['Title'] = GetLang('EditCoupon');
         $GLOBALS['Intro'] = GetLang('EditCouponIntro');
         $GLOBALS['FormAction'] = "editCoupon2";
         $GLOBALS['CouponCode'] = isc_html_escape($arrData['couponcode']);
         $GLOBALS['CouponName'] = isc_html_escape($arrData['couponname']);
         $GLOBALS['MaxUses'] = (int) $arrData['couponmaxuses'];
         if ($GLOBALS['MaxUses'] > 0) {
             $GLOBALS['MaxUsesChecked'] = 'checked="checked"';
         } else {
             $GLOBALS['MaxUsesHide'] = 'none';
         }
         if ($arrData['couponappliesto'] == "categories") {
             // Show the categories list
             $GLOBALS['ToggleUsedFor'] = "ToggleUsedFor(0);";
             $sel_cats = explode(",", $arrData['couponappliestovalues']);
             if ($arrData['couponappliestovalues'] == "0") {
                 $GLOBALS['AllCategoriesSelected'] = "selected=\"selected\"";
             }
         } else {
             // Show the products textbox
             $GLOBALS['ToggleUsedFor'] = "ToggleUsedFor(1);";
             // Select a list of the products that this coupon is active for
             if ($arrData['couponappliestovalues'] != "") {
                 $GLOBALS['SelectedProducts'] = '';
                 $GLOBALS['ProductIds'] = '';
                 $query = sprintf("SELECT productid, prodname FROM [|PREFIX|]products WHERE productid IN (%s) ORDER BY prodname ASC", $arrData['couponappliestovalues']);
                 $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
                 while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
                     $GLOBALS['SelectedProducts'] .= sprintf("<option value='%d'>%s</option>", $row['productid'], $row['prodname']);
                     $GLOBALS['ProductIds'] .= $row['productid'] . ",";
                 }
                 $GLOBALS['ProductIds'] = isc_substr($GLOBALS['ProductIds'], 0, -1);
             }
         }
         $GLOBALS['ISC_CLASS_ADMIN_CATEGORY'] = GetClass('ISC_ADMIN_CATEGORY');
         $GLOBALS['CategoryList'] = $GLOBALS["ISC_CLASS_ADMIN_CATEGORY"]->GetCategoryOptions($sel_cats, "<option %s value='%d'>%s</option>", "selected=\"selected\"", "- ", false);
         if ($arrData['coupontype'] == 1) {
             $GLOBALS['SelDiscount1'] = "selected=\"selected\"";
         } else {
             $GLOBALS['SelDiscount2'] = "selected=\"selected\"";
         }
         $GLOBALS['DiscountAmount'] = $arrData['couponamount'];
         if ($arrData['couponminpurchase'] == 0) {
             $GLOBALS['MinPurchase'] = 0;
         } else {
             $GLOBALS['MinPurchase'] = CPrice($arrData['couponminpurchase']);
         }
         if ($arrData['couponexpires'] > 0) {
             $GLOBALS['ExpiryDate'] = isc_date("m/d/Y", $arrData['couponexpires']);
         }
         if ($arrData['couponenabled'] == 1) {
             $GLOBALS['Enabled'] = 'checked="checked"';
         }
         $GLOBALS['CouponId'] = (int) $arrData['couponid'];
         $GLOBALS["ISC_CLASS_TEMPLATE"]->SetTemplate("coupon.form");
         $GLOBALS["ISC_CLASS_TEMPLATE"]->ParseTemplate();
     } else {
         // The coupon doesn't exist
         if ($GLOBALS["ISC_CLASS_ADMIN_AUTH"]->HasPermission(AUTH_Manage_Coupons)) {
             $this->ManageCoupons(GetLang('CouponDoesntExist'), MSG_ERROR);
         } else {
             $GLOBALS['ISC_CLASS_ADMIN_ENGINE']->DoHomePage(GetLang('Unauthorized'), MSG_ERROR);
         }
     }
 }
 /**
  * Reformat the products array
  *
  * Method will reformat the products aray into something more standardised
  *
  * @access private
  * @param array &$input The referenced input data
  */
 private function reformatProducts(&$input)
 {
     if (!array_key_exists('products', $input) || !is_array($input['products'])) {
         return null;
     }
     $newProducts = array();
     foreach ($input['products'] as $product) {
         $tmpProd = array();
         $price = 0;
         if (array_key_exists('type', $product) && strtolower($product['type']) == 'giftcertificate') {
             $price = $product['giftamount'];
         } else {
             if (array_key_exists('discount_price', $product)) {
                 $price = $product['discount_price'];
             } else {
                 $price = $product['product_price'];
             }
         }
         $tmpProd['productid'] = $product['product_id'];
         $tmpProd['name'] = $product['product_name'];
         $tmpProd['amount'] = DefaultPriceFormat(CPrice($price));
         $tmpProd['quantity'] = $product['quantity'];
         $newProducts[] = $tmpProd;
     }
     $input['products'] = $newProducts;
 }
 private function EditCompanyGiftCertificate()
 {
     // Show the form to edit a news
     $cgcId = (int) $_GET['cgcid'];
     $GLOBALS['AmountReadOnly'] = 'readonly';
     $arrData = array();
     $sel_cats = array();
     if (GetConfig('CurrencyLocation') == 'right') {
         $GLOBALS['CurrencyTokenLeft'] = '';
         $GLOBALS['CurrencyTokenRight'] = GetConfig('CurrencyToken');
     } else {
         $GLOBALS['CurrencyTokenLeft'] = GetConfig('CurrencyToken');
         $GLOBALS['CurrencyTokenRight'] = '';
     }
     $GLOBALS['CurrencyToken'] = GetConfig('CurrencyToken');
     $this->_GetCGCData($cgcId, $arrData);
     if (count($arrData) > 0) {
         if ($arrData['cgcstatus'] == 2 || $arrData['cgcsended']) {
             $this->ManageGiftCertificates(GetLang('CompanyGiftCertificateCanNotEdit'), MSG_ERROR);
             return;
         }
         $GLOBALS['Title'] = GetLang('EditCompanyGiftCertificate');
         $GLOBALS['Intro'] = GetLang('EditCompanyGiftCertificateIntro');
         $GLOBALS['FormAction'] = "editCompanyGiftCertificate2";
         $GLOBALS['cgcCode'] = isc_html_escape($arrData['cgccode']);
         $GLOBALS['cgcName'] = isc_html_escape($arrData['cgcname']);
         //applies to
         if ($arrData['cgcappliesto'] == "categories") {
             // Show the categories list
             $GLOBALS['UsedForCat'] = 'checked="checked"';
             $GLOBALS['ToggleUsedFor'] = "ToggleUsedFor(0);";
             $sel_cats = explode(",", $arrData['cgcappliestovalues']);
             if ($arrData['cgcappliestovalues'] == "0") {
                 $GLOBALS['AllCategoriesSelected'] = "selected=\"selected\"";
             }
         } else {
             // Show the products textbox
             $GLOBALS['ToggleUsedFor'] = "ToggleUsedFor(1);";
             $GLOBALS['UsedForProd'] = 'checked="checked"';
             // Select a list of the products that this coupon is active for
             if ($arrData['cgcappliestovalues'] != "") {
                 $GLOBALS['SelectedProducts'] = '';
                 $GLOBALS['ProductIds'] = '';
                 $query = sprintf("SELECT productid, prodname FROM [|PREFIX|]products WHERE productid IN (%s) ORDER BY prodname ASC", $arrData['cgcappliestovalues']);
                 $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
                 while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
                     $GLOBALS['SelectedProducts'] .= sprintf("<option value='%d'>%s</option>", $row['productid'], $row['prodname']);
                     $GLOBALS['ProductIds'] .= $row['productid'] . ",";
                 }
                 $GLOBALS['ProductIds'] = isc_substr($GLOBALS['ProductIds'], 0, -1);
             }
         }
         $GLOBALS['ISC_CLASS_ADMIN_CATEGORY'] = GetClass('ISC_ADMIN_CATEGORY');
         $GLOBALS['CategoryList'] = $GLOBALS["ISC_CLASS_ADMIN_CATEGORY"]->GetCategoryOptions($sel_cats, "<option %s value='%d'>%s</option>", "selected=\"selected\"", "- ", false);
         if ($arrData['cgcminpurchase'] == 0) {
             $GLOBALS['MinPurchase'] = 0;
         } else {
             $GLOBALS['MinPurchase'] = CPrice($arrData['cgcminpurchase']);
         }
         if ($arrData['cgcexpirydate'] > 0) {
             $GLOBALS['ExpiryDate'] = isc_date("m/d/Y", $arrData['cgcexpirydate'], 0);
         }
         if ($arrData['cgcenabled'] == 1) {
             $GLOBALS['Enabled'] = 'checked="checked"';
         }
         if (isset($arrData['cgcamount'])) {
             $GLOBALS['Amount'] = CPrice($arrData['cgcamount']);
         }
         if (isset($arrData['cgcbalance'])) {
             $GLOBALS['Balance'] = CPrice($arrData['cgcbalance']);
         }
         if ($arrData['cgcto']) {
             $GLOBALS['to_name'] = $arrData['cgcto'];
         }
         if ($arrData['cgctoemail']) {
             $GLOBALS['to_email'] = $arrData['cgctoemail'];
         }
         $to_name = explode('$', $arrData['cgcto']);
         $to_email = explode('$', $arrData['cgctoemail']);
         $GLOBALS['recipientcount'] = count($to_name);
         if ($GLOBALS['recipientcount'] <= 0) {
             $GLOBALS['recipientcount'] = 1;
         }
         $GLOBALS['to_name_1'] = $to_name[0];
         $GLOBALS['to_email_1'] = $to_email[0];
         if (count($to_name) > 1) {
             for ($i = 1; $i < count($to_name); $i++) {
                 $GLOBALS['recipient_other'] .= "<p id=\"recipient_" . ($i + 1) . "\">Name:<input type=\"text\" class=\"Textbox Field200\" value=\"" . $to_name[$i] . "\" id=\"to_name_" . ($i + 1) . "\" name=\"to_name_" . ($i + 1) . "\" onkeyup=\"getCustomerNameandEmail('to_name_result_" . ($i + 1) . "', " . ($i + 1) . ", this.value)\" >&nbsp;&nbsp;Email:<input type=\"text\" class=\"Textbox Field200\" value=\"" . $to_email[$i] . "\" id=\"to_email_" . ($i + 1) . "\" name=\"to_email_" . ($i + 1) . "\">" . '<a href="#" onclick="deleteRecipient(' . ($i + 1) . ');return false;">delete</a>' . "<div id=\"to_name_result_" . ($i + 1) . "\" name=\"to_name_result_1" . ($i + 1) . "\" class=\"ProductSearchResults  returnname\" ></div></p>";
             }
         }
         $GLOBALS['CompanyGiftCertificateMessage'] = $arrData['cgcmessage'];
         //theme
         // Get a list of the gift certificate themes
         $themes = @scandir(dirname(__FILE__) . "/../../../templates/__gift_themes/");
         //$enabledThemes = explode(",", GetConfig('GiftCertificateThemes'));
         $enabledThemes = $this->getEnabledThemes();
         $GLOBALS['GiftCertificateThemes'] = '';
         if (count($enabledThemes) == 1) {
             $GLOBALS['HideThemeSelect'] = "none";
         }
         foreach ($enabledThemes as $theme) {
             // Just double check this theme still actually exists
             if (in_array($theme, $themes)) {
                 $themeName = preg_replace('#\\.html$#i', "", $theme);
                 $sel = '';
                 if (isset($arrData['cgctemplate']) && $arrData['cgctemplate'] == $theme || count($enabledThemes) == 1) {
                     $sel = 'checked="checked"';
                     $GLOBALS['SelectedCertificateTheme'] = $theme;
                 }
                 $GLOBALS['GiftCertificateThemes'] .= sprintf('<label><input type="radio" class="themeCheck" name="certificate_theme" value="%s" %s /> %s</label><br />', $theme, $sel, $themeName);
             }
         }
         if (!GetConfig('GiftCertificateThemes')) {
             $GLOBALS['HideErrorMessage'] = '';
             $GLOBALS['ErrorMessage'] = GetLang('NoGiftCertificateThemes');
             $GLOBALS['HideGiftCertificateForm'] = "none";
         }
         $GLOBALS['cgcId'] = (int) $arrData['cgcid'];
         // Add NI_20100901_Jack
         $GLOBALS['GiftCertificateMinimum'] = ConvertPriceToCurrency(GetConfig('CompanyGiftCertificateMinimum'));
         $GLOBALS['GiftCertificateMaximum'] = ConvertPriceToCurrency(GetConfig('CompanyGiftCertificateMaximum'));
         $GLOBALS["ISC_CLASS_TEMPLATE"]->SetTemplate("company.giftcertificates.form");
         $GLOBALS["ISC_CLASS_TEMPLATE"]->ParseTemplate();
     } else {
         // The coupon doesn't exist
         if ($GLOBALS["ISC_CLASS_ADMIN_AUTH"]->HasPermission(AUTH_Manage_Company_GiftCertificates)) {
             $this->ManageGiftCertificates(GetLang('CompanyGiftCertificateDoesntExist'), MSG_ERROR);
         } else {
             $GLOBALS['ISC_CLASS_ADMIN_ENGINE']->DoHomePage(GetLang('Unauthorized'), MSG_ERROR);
         }
     }
 }
Esempio n. 6
0
		protected function _SetFormData($arrData)
		{
			$GLOBALS['CouponCode'] = isc_html_escape($arrData['couponcode']);
			$GLOBALS['CouponName'] = isc_html_escape($arrData['couponname']);

			// "Number of Uses" settings
			$GLOBALS['MaxUses'] = (int) $arrData['couponmaxuses'];
			$GLOBALS['CouponMaxUsesEnabled'] = false;
			if($GLOBALS['MaxUses'] > 0) {
				$GLOBALS['CouponMaxUsesEnabled'] = true;
			}
			$GLOBALS['MaxUsesPerCus'] = (int) $arrData['couponmaxusespercus'];
			$GLOBALS['CouponMaxUsesPerCustomerEnabled'] = false;
			if($GLOBALS['MaxUsesPerCus'] > 0) {
				$GLOBALS['CouponMaxUsesPerCustomerEnabled'] = true;
			}

			$sel_cats = '';
			if($arrData['couponappliesto'] == "categories") {
				// Show the categories list
				$GLOBALS['ToggleUsedFor'] = "ToggleUsedFor(0);";
				$sel_cats = $arrData['couponappliestovalues'];
				if(in_array('0', $sel_cats)) {
					$GLOBALS['AllCategoriesSelected'] = "selected=\"selected\"";
				}
			}
			else {
				// Show the products textbox
				$GLOBALS['ToggleUsedFor'] = "ToggleUsedFor(1);";

				// Select a list of the products that this coupon is active for
				if($arrData['couponappliestovalues'] != "") {
					$GLOBALS['SelectedProducts'] = '';
					$GLOBALS['ProductIds'] = '';
					$query = sprintf("SELECT productid, prodname FROM [|PREFIX|]products WHERE productid IN (%s) ORDER BY prodname ASC", implode(",", $arrData['couponappliestovalues']));
					$result = $GLOBALS['ISC_CLASS_DB']->Query($query);
					while($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
						$GLOBALS['SelectedProducts'] .= sprintf("<option value='%d'>%s</option>", $row['productid'], $row['prodname']);
						$GLOBALS['ProductIds'] .= $row['productid'].",";
					}
					$GLOBALS['ProductIds'] = isc_substr($GLOBALS['ProductIds'], 0, -1);
				}
			}
			$GLOBALS['ISC_CLASS_ADMIN_CATEGORY'] = GetClass('ISC_ADMIN_CATEGORY');
			$GLOBALS['CategoryList'] = $GLOBALS["ISC_CLASS_ADMIN_CATEGORY"]->GetCategoryOptions($sel_cats, "<option %s value='%d'>%s</option>", "selected=\"selected\"", "- ", false);
			if ($arrData['coupontype'] != 1) {
				$GLOBALS['DiscountAmount'] = $arrData['couponamount'];
			}
			else {
				$GLOBALS['DiscountAmount'] = (int)$arrData['couponamount'];
			}
			if ($arrData['couponminpurchase'] == 0) {
				$GLOBALS['MinPurchase'] = 0;
			} else {
				$GLOBALS['MinPurchase'] = CPrice($arrData['couponminpurchase']);
			}
			if ($arrData['couponexpires'] > 0) {
				$GLOBALS['ExpiryDate'] = isc_date("m/d/Y", $arrData['couponexpires']);
			}
			if ($arrData['couponenabled'] == 1) {
				$GLOBALS['Enabled'] = 'checked="checked"';
			}


			// Advanced tab
			$availableCountries = GetCountryListAsIdValuePairs();
			$availableShippers = array();

			// retrieve data related to location restrictions.
			if ($arrData['location_restricted']) {

				$locationValueIds = $this->_getNameValueArray($arrData['restrictedLocations'], 'value_id');
				$locationValues = $this->_getNameValueArray($arrData['restrictedLocations'], 'value');
				$locationCountryIds = $this->_getNameValueArray($arrData['restrictedLocations'], 'country_id');

				if ($arrData['restrictedLocationType'] == 'country') {
					$this->template->assign('locationTypeCountries', $locationValueIds);
				} else if ($arrData['restrictedLocationType'] == 'state') {
					$locationTypeStatesSelect = array();
					$locationCountriesStatesIds = $this->_getNameValueArray($arrData['restrictedLocations'], array('country_id', 'value_id'));
					if (!empty ($locationCountriesStatesIds)) {
						$locationTypeStatesSelect = GetMultiCountryStateOptions($locationCountriesStatesIds);
					}
					$this->template->assign('locationTypeStatesCountries', $locationCountryIds);
					$this->template->assign('locationTypeStatesSelect', $locationTypeStatesSelect);
				} else if ($arrData['restrictedLocationType'] == 'zip') {
					$this->template->assign('locationTypeZipCountry', current($locationCountryIds));
					$this->template->assign('locationTypeZipPostCodes', implode("\n", $locationValues));
				}
				$this->template->assign('restrictedLocationType', $arrData['restrictedLocationType']);
			}

			// retrieve data related to shipping method restrictions.
			$shippers = GetAvailableModules('shipping', false, false, true);
			foreach ($shippers as $eachShipper) {
				$availableShippers[$eachShipper['id']] = $eachShipper['name'];
			}
			if ($arrData['shipping_method_restricted']) {
				$this->template->assign('selectedShippers', $arrData['restrictedShippingMethods']);
			}

			$this->template->assign('CurrentTab', 0);
			$this->template->assign('availableCountries', $availableCountries);
			$this->template->assign('shippingMethodRestricted', (int)$arrData['shipping_method_restricted']);
			$this->template->assign('availableShippers', $availableShippers);
			$this->template->assign('locationRestricted', (int)$arrData['location_restricted']);
			$this->template->assign('availableCountries', $availableCountries);

			$this->template->assign('coupon', $arrData);
			$GLOBALS['CouponId'] = (int)$arrData['couponid'];
		}