/**
	 * Add a new shipping zone.
	 */
	private function AddShippingZone()
	{
		if(!$GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId() && !$GLOBALS['ISC_CLASS_ADMIN_AUTH']->HasPermission(AUTH_Manage_Settings)) {
			$GLOBALS['ISC_CLASS_ADMIN_ENGINE']->DoHomePage(GetLang('Unauthorized'), MSG_ERROR);
			return;
		}

		$GLOBALS['Message'] = GetFlashMessageBoxes();

		$GLOBALS['FormAction']	= 'SaveNewShippingZone';
		$GLOBALS['Intro']		= GetLang('AddShippingZoneIntro');

		// Generate the breadcrumb
		if(isset($_REQUEST['vendorId']) || $GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId()) {
			if($GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId()) {
				$vendorId = $GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId();
			}
			else {
				$vendorId = (int)$_REQUEST['vendorId'];
			}

			$vendorCache = $GLOBALS['ISC_CLASS_DATA_STORE']->Read('Vendors');
			$vendor = $vendorCache[$vendorId];
			if ($GLOBALS['ISC_CLASS_ADMIN_AUTH']->HasPermission(AUTH_Manage_Vendors)) {
				$GLOBALS['BreadcrumEntries'][GetLang('Vendors')] = "index.php?ToDo=viewVendors";
				$GLOBALS['BreadcrumEntries'][isc_html_escape($vendor['vendorname'])] = 'index.php?ToDo=editVendor&vendorId='.$vendor['vendorid'];
			}
			else {
				$GLOBALS['BreadcrumEntries'][GetLang('VendorProfile')] = 'index.php?ToDo=editVendor&vendorId='.$vendor['vendorid'];
			}
		}
		else {
			$GLOBALS['BreadcrumEntries'][GetLang('Settings')] = "index.php?ToDo=viewSettings";
			$GLOBALS['BreadcrumEntries'][GetLang('ShippingSettings')] = "index.php?ToDo=viewShippingSettings";
		}
		$GLOBALS['BreadcrumEntries'][GetLang('AddShippingZone')] = '';

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

		$GLOBALS['HideZoneTypeCountry']		= 'display: none';
		$GLOBALS['HideZoneTypeStates']		= 'display: none';
		$GLOBALS['HideStateSelect']			= 'display: none';
		$GLOBALS['HideZoneTypePostCodes']	= 'display: none';
		$GLOBALS['HideFreeShipping']		= 'display: none';
		$GLOBALS['HideHandlingFeeGlobal']	= 'display: none';
		$GLOBALS['HideShippingMethods']		= 'display: none';
		$GLOBALS['HideDefaultZoneType']		= 'display: none;';
		$GLOBALS['HideHandlingSeparate']	= 'display: none';

		$GLOBALS['NextButton'] = "Next »";

		$GLOBALS['Title'] = GetLang('AddShippingZone');

		$selectedCountries = array();
		$selectedStates = array();
		$selectedPostCodes = array();

		// If we're coming back here - set up the values
		if($_SERVER['REQUEST_METHOD'] == "POST") {
			$GLOBALS['ZoneName'] = isc_html_escape($_POST['zonename']);

			// Was free shipping checked?
			if(isset($_POST['zonefreeshipping'])) {
				$GLOBALS['FreeShippingChecked'] = 'checked="checked"';
				$GLOBALS['FreeShippingTotal'] = number_format($_POST['zonefreeshippingtotal'], GetConfig('DecimalPlaces'), GetConfig('DecimalToken'), "");
			}
			else {
				$GLOBALS['HideFreeShipping'] = 'display: none';
			}

			// Handling set up?
			if(isset($_POST['zonehandlingtype'])) {

				// No handling applied? Check that box
				if($_POST['zonehandlingtype'] == 'none') {
					$GLOBALS['HandlingNoneChecked'] = 'checked="checked"';
				}
				// Handling is specified on a global level for this zone
				else if($_POST['zonehandlingtype'] == 'global') {
					$GLOBALS['HandlingGlobalChecked'] = 'checked="checked"';
					$GLOBALS['HideHandlingFeeGlobal'] = '';
					$GLOBALS['HandlingFee'] = number_format($_POST['zonehandlingfee'], GetConfig('DecimalPlaces'), GetConfig('DecimalToken'), "");
				}
				// Handling is specified per shipping option in this zone
				else if($_POST['zonehandlingtype'] == 'module') {
					$GLOBALS['HandlingOptionChecked'] = 'checked="checked"';
				}
			}

			if(isset($_POST['zonehandlingseparate'])) {
				$GLOBALS['HandlingSeparateChecked'] = 'checked="checked"';
			}
			else {
				$zone['zonehandlingseparate'] = 0;
			}

			// if the zone is country based, then show the country options
			if($_POST['zonetype'] == 'country') {
				$GLOBALS['HideZoneTypeCountry'] = '';
				$GLOBALS['TypeCountriesChecked'] = 'checked="checked"';
				$selectedCountries = $_POST['zonetype_country_list'];
			}

			// If the zone type is state based, then show the state options
			else if($_POST['zonetype'] == 'state') {
				$GLOBALS['HideZoneTypeStates'] = '';
				$GLOBALS['HideStateSelect'] = '';
				$GLOBALS['HideStateSelectNode'] = 'display: none;';
				$GLOBALS['TypeStatesChecked'] = 'checked="checked"';
				foreach($_POST['zonetype_states'] as $state) {
					$state = explode('-', $state);
					$selectedStates[$state[0]][] = $state[1];
					$selectedCountries[$state[0]] = $state[0];
				}
			}

			// Finally, if it's post code/zip code based then we show the zip code textbox
			else if($_POST['zonetype'] == 'zip') {
				$GLOBALS['HideZoneTypePostCodes'] = '';
				$GLOBALS['TypeZipChecked'] = 'checked="checked"';
				$selectedCountries[] = $_POST['zonetype_zip_country'];
				$GLOBALS['ZonePostCodes'] = isc_html_escape($_POST['zonetype_zip_list']);
			}

			// Now we can build the select lists
			$GLOBALS['SingleCountrySelect']		= GetCountryList($selectedCountries);
			$GLOBALS['MultipleCountrySelect']	= GetCountryList($selectedCountries, false);
			if(!empty($selectedStates)) {
				$GLOBALS['StateSelect'] 		= GetMultiCountryStateOptions($selectedStates);
				$GLOBALS['HideStateSelectNone'] = "display: none;";
			}
		}

		// Fetch & set up the defaults
		else {
			$GLOBALS['SingleCountrySelect']		= GetCountryList();
			$GLOBALS['MultipleCountrySelect']	= GetCountryList('', false);

			$GLOBALS['HandlingSeparateChecked'] = 'checked="checked"';
			$GLOBALS['HandlingNoneChecked']		= "checked=\"checked\"";
		}

		if(isset($_POST['zoneenabled']) || $_SERVER['REQUEST_METHOD'] != 'POST') {
			$GLOBALS['ZoneEnabledCheck'] = 'checked="checked"';
		}

		$GLOBALS['ISC_CLASS_ADMIN_ENGINE']->PrintHeader();
		$this->template->display('shippingzone.form.tpl');
		$GLOBALS['ISC_CLASS_ADMIN_ENGINE']->PrintFooter();
	}
 private function GetMultiCountryStates()
 {
     echo GetMultiCountryStateOptions(array((int) $_REQUEST['c']));
     exit;
 }
Example #3
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'];
		}