/** * Return the discount product/category grid * * Method will return either the products or categories HTML grid * * @access public * @return string The email accounts HTML grid */ public function ManageGroupDiscountGrid($data=null) { if (!is_array($data)) { $data = $_POST; } if (!is_array($data)) { $data = array(); } if (!isset($data['items']) || !is_array($data['items'])) { $data['items'] = array(); } if (!isset($data['type']) || !is_string($data['type'])) { $data['type'] = ''; } if (!isset($data['total']) || !isc_is_int($data['total'])) { $data['total'] = 0; } $items = $data['items']; $type = isc_strtolower($data['type']); $total = $data['total']; if (isset($_GET['page']) && $_GET['page'] > 1) { $page = $_GET['page']; } else { $page = 1; } /** * Special global for naving ot a page when displaying an error */ if (isc_strtolower($type) == 'product' && isset($GLOBALS['pageNavToProduct'])) { $page = $GLOBALS['pageNavToProduct']; } else if (isc_strtolower($type) == 'category' && isset($GLOBALS['pageNavToCategory'])) { $page = $GLOBALS['pageNavToCategory']; } if ($page == 1) { $start = 1; } else { $start = ($page * ISC_GROUPDISCOUNT_ITEMS_PER_PAGE) - (ISC_GROUPDISCOUNT_ITEMS_PER_PAGE - 1); } $start = $start-1; $numPages = ceil($total / ISC_GROUPDISCOUNT_ITEMS_PER_PAGE); if ($total > ISC_GROUPDISCOUNT_ITEMS_PER_PAGE) { $GLOBALS['Nav'] = sprintf('(%s %d of %d) ', GetLang('Page'), $page, $numPages); $GLOBALS['Nav'] .= BuildPagination($total, ISC_GROUPDISCOUNT_ITEMS_PER_PAGE, $page, 'index.php?ToDo=viewCustomerGroupDiscounts&type=' . urlencode($type), 'getGroupDiscountDataBlock'); } else { $GLOBALS['Nav'] = ''; } $html = ''; foreach ($items as $item) { $GLOBALS['DiscountMethodPercent'] = ''; $GLOBALS['DiscountMethodPrice'] = ''; $GLOBALS['DiscountMethodFixed'] = ''; if ($type == 'product') { $GLOBALS['ProductId'] = (int)$item['discountid']; $GLOBALS['CatOrProdId'] = (int)$item['catorprodid']; if (isId($item['discountid'])) { $result = $GLOBALS['ISC_CLASS_DB']->Query("SELECT prodname FROM [|PREFIX|]products WHERE productid=" . (int)$item['catorprodid']); $prodname = $GLOBALS['ISC_CLASS_DB']->FetchOne($result, 'prodname'); } if (!isId($item['discountid']) || $prodname == '') { $item['catorprodid'] = ''; $GLOBALS['SelectedItemName'] = GetLang('NoneSelected'); } else { $GLOBALS['SelectedItemName'] = isc_html_escape($prodname); } } else { $GLOBALS['CategoryId'] = (int)$item['discountid']; $GLOBALS['CategoryOptions'] = $GLOBALS["ISC_CLASS_ADMIN_CATEGORY"]->GetCategoryOptions(array($item['catorprodid']), "<option %s value='%d'>%s</option>", "selected=\"selected\"", "", false); $GLOBALS['DiscountCatTypeCat'] = ''; $GLOBALS['DiscountCatTypeCatAndSub'] = ''; if (isc_strtolower($item['appliesto']) == 'category_and_subcats') { $GLOBALS['DiscountCatTypeCatAndSub'] = 'selected'; } else { $GLOBALS['DiscountCatTypeCat'] = 'selected'; } } if ($item['discountmethod'] == 'percent') { $GLOBALS['AmountPrefix'] = ''; $GLOBALS['AmountPostfix'] = '%'; $GLOBALS['DiscountMethodPercent'] = 'selected'; } else { if ($item['discountmethod'] == 'fixed') { $GLOBALS['DiscountMethodFixed'] = 'selected'; } else { $GLOBALS['DiscountMethodPrice'] = 'selected'; } if (GetConfig('CurrencyLocation') == 'right') { $GLOBALS['AmountPrefix'] = ''; $GLOBALS['AmountPostfix'] = GetConfig('CurrencyToken'); } else { $GLOBALS['AmountPrefix'] = GetConfig('CurrencyToken'); $GLOBALS['AmountPostfix'] = ''; } } if ((int)$item['discountpercent'] == $item['discountpercent']) { $GLOBALS['DiscountAmount'] = (int)$item['discountpercent']; } else { $GLOBALS['DiscountAmount'] = CFloat($item['discountpercent']); } $html .= $this->template->render('Snippets/CustomerGroup'.ucfirst(isc_strtolower($type)).'Row.html'); } if ($numPages <= 1) { $GLOBALS['HidePagingNav'] = 'none'; } else { $GLOBALS['HidePagingNav'] = ''; } $GLOBALS['Type'] = isc_html_escape($type); $GLOBALS['CustomerGroupDiscountGrid'] = $html; return $this->template->render('customers.groups.discount.grid.tpl'); }
/** * Check if the passed string is indeed valid ID for an item. * * @param string The string to check that's a valid ID. * @return boolean True if valid, false if not. */ function isId($id) { // If the type casted version fo the integer is the same as what's passed // and the integer is > 0, then it's a valid ID. if(isc_is_int($id) && $id > 0) { return true; } else { return false; } }
/** * NiceSize * * Returns a datasize formatted into the most relevant units * @return string The formatted filesize * @param int Size In Bytes * @param int How many decimal places to use in the return * @param string Optionally force size into this format ('B', 'KB', 'MB', 'GB') */ public static function niceSize($SizeInBytes=0, $Precision=2, $ForceToFormat='', $noPostFix=false) { static $map = array( 'GB' => 1073741824, // 1024 to the power of 3 'MB' => 1048576, // 1024 to the power of 2 'KB' => 1024, 'B' => 1 ); $key = ''; if ($ForceToFormat !== '') { $key = strtoupper($ForceToFormat); if (!array_key_exists($key, $map)) { return false; } } else { foreach ($map as $k => $v) { if ($SizeInBytes >= $v) { $key = $k; break; } } } if (!isc_is_int($Precision)) { $Precision = 2; } else { $Precision = (int)$Precision; } if ($key == '') { $key = 'B'; } if ($noPostFix) { return sprintf("%01." . $Precision . "f", $SizeInBytes / $map[$key]); } else { return sprintf("%01." . $Precision . "f %s", $SizeInBytes / $map[$key], $key); } }
protected function _ValidateInput($CouponId = 0) { if (!isset($_POST["couponcode"]) || !trim($_POST["couponcode"])) { return GetLang('EnterCouponCode'); } if (!isset($_POST["couponname"]) || !trim($_POST["couponname"])) { return GetLang('EnterCouponName'); } if (!isset($_POST['coupontype']) || !isc_is_int($_POST['coupontype'])) { return GetLang('EnterCouponType'); } // if account type is freeshipping, the discount amount always set to 0 else if ($_POST['coupontype'] == 4) { $_POST['couponamount'] = 0; } // check for existing coupon code $couponcode = trim($_POST['couponcode']); $query = "SELECT * FROM [|PREFIX|]coupons WHERE couponcode = '" . $GLOBALS['ISC_CLASS_DB']->Quote($couponcode) . "'"; if ($CouponId) { $query .= " AND couponid != '" . $GLOBALS['ISC_CLASS_DB']->Quote($CouponId) . "'"; } $result = $GLOBALS['ISC_CLASS_DB']->Query($query); if ($GLOBALS['ISC_CLASS_DB']->CountResult($result)) { return sprintf(GetLang('CouponCodeExists'), $couponcode); } // check for exisiting coupon name $couponname = trim($_POST['couponname']); $query = "SELECT * FROM [|PREFIX|]coupons WHERE couponname = '" . $GLOBALS['ISC_CLASS_DB']->Quote($couponname) . "'"; if ($CouponId) { $query .= " AND couponid != '" . $GLOBALS['ISC_CLASS_DB']->Quote($CouponId) . "'"; } $result = $GLOBALS['ISC_CLASS_DB']->Query($query); if ($GLOBALS['ISC_CLASS_DB']->CountResult($result)) { return sprintf(GetLang('CouponNameExists'), $couponname); } // check coupon amount is valid if (!(is_numeric($_POST['couponamount']) && $_POST['couponamount'] > 0)) { if ($_POST['coupontype'] != 4) { return GetLang('EnterValidAmount'); } } // check min purchase amount is valid $minPurchase = str_replace(',', '', $_POST['couponminpurchase']); if ($_POST['couponminpurchase'] && !(is_numeric($minPurchase) && $minPurchase >= 0)) { return GetLang('EnterValidMinPrice'); } // check max uses is valid if (!(isc_is_int($_POST['couponmaxuses']) && $_POST['couponmaxuses'] >= 0)) { return GetLang('EnterValidMaxUses'); } if (!(isc_is_int($_POST['couponmaxusespercus']) && $_POST['couponmaxusespercus'] >= 0)) { return GetLang('EnterValidMaxUsesPerCus'); } // check that at least one category or product is ticked if ($_POST['usedfor'] == "categories" && empty($_POST['catids'])) { return GetLang('ChooseCouponCategory'); } elseif ($_POST['usedfor'] == "products" && empty($_POST['prodids'])) { return GetLang('EnterCouponProductId'); } // Validation of coupon location restriction $validLocationOptions = array('country', 'state', 'zip'); if (!empty ($_POST['YesLimitByLocation'])) { if (empty ($_POST['LocationType']) || !in_array($_POST['LocationType'], $validLocationOptions)) { return GetLang('EnterLocationOption'); } if ($_POST['LocationType'] == 'country') { if (empty ($_POST['LocationTypeCountries'])) { return GetLang('EnterLocationTypeCountries'); } } else if ($_POST['LocationType'] == 'state') { if (empty ($_POST['LocationTypeStatesCountries'])) { return GetLang('EnterLocationTypeStatesCountries'); } if (empty ($_POST['LocationTypeStatesSelect'])) { return GetLang('EnterLocationTypeStatesSelect'); } } else if ($_POST['LocationType'] == 'zip') { if (empty ($_POST['LocationTypeZipCountry'])) { return GetLang('EnterLocationTypeZipCountry'); } $_POST['LocationTypeZipPostCodes'] = trim($_POST['LocationTypeZipPostCodes']); if (empty ($_POST['LocationTypeZipPostCodes'])) { return GetLang('EnterLocationTypeZipPostCodes'); } } } // Validation for shipping methods restriction. if (!empty ($_POST['YesLimitByShipping'])) { if (empty ($_POST['LocationTypeShipping'])) { return GetLang('EnterLocationTypeShipping'); } } }