📄 general.php
字号:
return TEXT_NONE;
} else {
$classes = $db->Execute("select tax_class_title
from " . TABLE_TAX_CLASS . "
where tax_class_id = '" . (int)$tax_class_id . "'");
return $classes->fields['tax_class_title'];
}
}
function zen_banner_image_extension() {
if (function_exists('imagetypes')) {
if (imagetypes() & IMG_PNG) {
return 'png';
} elseif (imagetypes() & IMG_JPG) {
return 'jpg';
} elseif (imagetypes() & IMG_GIF) {
return 'gif';
}
} elseif (function_exists('imagecreatefrompng') && function_exists('imagepng')) {
return 'png';
} elseif (function_exists('imagecreatefromjpeg') && function_exists('imagejpeg')) {
return 'jpg';
} elseif (function_exists('imagecreatefromgif') && function_exists('imagegif')) {
return 'gif';
}
return false;
}
////
// Wrapper function for round()
function zen_round($number, $precision) {
/// fix rounding error on GVs etc.
$number = round($number, $precision);
return $number;
}
////
// Add tax to a products price
function zen_add_tax($price, $tax) {
global $currencies;
if (DISPLAY_PRICE_WITH_TAX_ADMIN == 'true') {
return zen_round($price, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']) + zen_calculate_tax($price, $tax);
} else {
return zen_round($price, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
}
}
// Calculates Tax rounding the result
function zen_calculate_tax($price, $tax) {
global $currencies;
return zen_round($price * $tax / 100, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
}
////
// Returns the tax rate for a zone / class
// TABLES: tax_rates, zones_to_geo_zones
function zen_get_tax_rate($class_id, $country_id = -1, $zone_id = -1) {
global $db;
global $customer_zone_id, $customer_country_id;
if ( ($country_id == -1) && ($zone_id == -1) ) {
if (!$_SESSION['customer_id']) {
$country_id = STORE_COUNTRY;
$zone_id = STORE_ZONE;
} else {
$country_id = $customer_country_id;
$zone_id = $customer_zone_id;
}
}
$tax = $db->Execute("select SUM(tax_rate) as tax_rate
from (" . TABLE_TAX_RATES . " tr
left join " . TABLE_ZONES_TO_GEO_ZONES . " za
ON tr.tax_zone_id = za.geo_zone_id
left join " . TABLE_GEO_ZONES . " tz ON tz.geo_zone_id = tr.tax_zone_id )
WHERE (za.zone_country_id IS NULL
OR za.zone_country_id = 0
OR za.zone_country_id = '" . (int)$country_id . "')
AND (za.zone_id IS NULL OR za.zone_id = 0
OR za.zone_id = '" . (int)$zone_id . "')
AND tr.tax_class_id = '" . (int)$class_id . "'
GROUP BY tr.tax_priority");
if ($tax->RecordCount() > 0) {
$tax_multiplier = 0;
while (!$tax->EOF) {
$tax_multiplier += $tax->fields['tax_rate'];
$tax->MoveNext();
}
return $tax_multiplier;
} else {
return 0;
}
}
////
// Returns the tax rate for a tax class
// TABLES: tax_rates
function zen_get_tax_rate_value($class_id) {
global $db;
$tax = $db->Execute("select SUM(tax_rate) as tax_rate
from " . TABLE_TAX_RATES . "
where tax_class_id = '" . (int)$class_id . "'
group by tax_priority");
if ($tax->RecordCount() > 0) {
$tax_multiplier = 0;
while (!$tax->EOF) {
$tax_multiplier += $tax->fields['tax_rate'];
$tax->MoveNext();
}
return $tax_multiplier;
} else {
return 0;
}
}
function zen_call_function($function, $parameter, $object = '') {
if ($object == '') {
return call_user_func($function, $parameter);
} elseif (PHP_VERSION < 4) {
return call_user_method($function, $object, $parameter);
} else {
return call_user_func(array($object, $function), $parameter);
}
}
function zen_get_zone_class_title($zone_class_id) {
global $db;
if ($zone_class_id == '0') {
return TEXT_NONE;
} else {
$classes = $db->Execute("select geo_zone_name
from " . TABLE_GEO_ZONES . "
where geo_zone_id = '" . (int)$zone_class_id . "'");
return $classes->fields['geo_zone_name'];
}
}
////
function zen_cfg_pull_down_zone_classes($zone_class_id, $key = '') {
global $db;
$name = (($key) ? 'configuration[' . $key . ']' : 'configuration_value');
$zone_class_array = array(array('id' => '0', 'text' => TEXT_NONE));
$zone_class = $db->Execute("select geo_zone_id, geo_zone_name
from " . TABLE_GEO_ZONES . "
order by geo_zone_name");
while (!$zone_class->EOF) {
$zone_class_array[] = array('id' => $zone_class->fields['geo_zone_id'],
'text' => $zone_class->fields['geo_zone_name']);
$zone_class->MoveNext();
}
return zen_draw_pull_down_menu($name, $zone_class_array, $zone_class_id);
}
////
function zen_cfg_pull_down_order_statuses($order_status_id, $key = '') {
global $db;
$name = (($key) ? 'configuration[' . $key . ']' : 'configuration_value');
$statuses_array = array(array('id' => '0', 'text' => TEXT_DEFAULT));
$statuses = $db->Execute("select orders_status_id, orders_status_name
from " . TABLE_ORDERS_STATUS . "
where language_id = '" . (int)$_SESSION['languages_id'] . "'
order by orders_status_name");
while (!$statuses->EOF) {
$statuses_array[] = array('id' => $statuses->fields['orders_status_id'],
'text' => $statuses->fields['orders_status_name'] . ' [' . $statuses->fields['orders_status_id'] . ']');
$statuses->MoveNext();
}
return zen_draw_pull_down_menu($name, $statuses_array, $order_status_id);
}
function zen_get_order_status_name($order_status_id, $language_id = '') {
global $db;
if ($order_status_id < 1) return TEXT_DEFAULT;
if (!is_numeric($language_id)) $language_id = $_SESSION['languages_id'];
$status = $db->Execute("select orders_status_name
from " . TABLE_ORDERS_STATUS . "
where orders_status_id = '" . (int)$order_status_id . "'
and language_id = '" . (int)$language_id . "'");
return $status->fields['orders_status_name'] . ' [' . (int)$order_status_id . ']';
}
////
// Return a random value
function zen_rand($min = null, $max = null) {
static $seeded;
if (!$seeded) {
mt_srand((double)microtime()*1000000);
$seeded = true;
}
if (isset($min) && isset($max)) {
if ($min >= $max) {
return $min;
} else {
return mt_rand($min, $max);
}
} else {
return mt_rand();
}
}
// nl2br() prior PHP 4.2.0 did not convert linefeeds on all OSs (it only converted \n)
function zen_convert_linefeeds($from, $to, $string) {
if ((PHP_VERSION < "4.0.5") && is_array($from)) {
return ereg_replace('(' . implode('|', $from) . ')', $to, $string);
} else {
return str_replace($from, $to, $string);
}
}
function zen_string_to_int($string) {
return (int)$string;
}
////
// Parse and secure the cPath parameter values
function zen_parse_category_path($cPath) {
// make sure the category IDs are integers
$cPath_array = array_map('zen_string_to_int', explode('_', $cPath));
// make sure no duplicate category IDs exist which could lock the server in a loop
$tmp_array = array();
$n = sizeof($cPath_array);
for ($i=0; $i<$n; $i++) {
if (!in_array($cPath_array[$i], $tmp_array)) {
$tmp_array[] = $cPath_array[$i];
}
}
return $tmp_array;
}
////
// Create a Coupon Code. length may be between 1 and 16 Characters
// $salt needs some thought.
function create_coupon_code($salt="secret", $length=SECURITY_CODE_LENGTH) {
global $db;
$ccid = md5(uniqid("","salt"));
$ccid .= md5(uniqid("","salt"));
$ccid .= md5(uniqid("","salt"));
$ccid .= md5(uniqid("","salt"));
srand((double)microtime()*1000000); // seed the random number generator
$random_start = @rand(0, (128-$length));
$good_result = 0;
while ($good_result == 0) {
$id1=substr($ccid, $random_start,$length);
$query = $db->Execute("select coupon_code
from " . TABLE_COUPONS . "
where coupon_code = '" . $id1 . "'");
if ($query->RecordCount() < 1 ) $good_result = 1;
}
return $id1;
}
////
// Update the Customers GV account
function zen_gv_account_update($customer_id, $gv_id) {
global $db;
$customer_gv = $db->Execute("select amount
from " . TABLE_COUPON_GV_CUSTOMER . "
where customer_id = '" . $customer_id . "'");
$coupon_gv = $db->Execute("select coupon_amount
from " . TABLE_COUPONS . "
where coupon_id = '" . $gv_id . "'");
if ($customer_gv->RecordCount() > 0) {
$new_gv_amount = $customer_gv->fields['amount'] + $coupon_gv->fields['coupon_amount'];
$gv_query = $db->Execute("update " . TABLE_COUPON_GV_CUSTOMER . "
set amount = '" . $new_gv_amount . "'
where customer_id = '" . $customer_id . "'");
} else {
$db->Execute("insert into " . TABLE_COUPON_GV_CUSTOMER . " (customer_id, amount) values ('" . $customer_id . "', '" . $coupon_gv->fields['coupon_amount'] . "')");
}
}
////
// Output a day/month/year dropdown selector
function zen_draw_date_selector($prefix, $date='') {
$month_array = array();
$month_array[1] =_JANUARY;
$month_array[2] =_FEBRUARY;
$month_array[3] =_MARCH;
$month_array[4] =_APRIL;
$month_array[5] =_MAY;
$month_array[6] =_JUNE;
$month_array[7] =_JULY;
$month_array[8] =_AUGUST;
$month_array[9] =_SEPTEMBER;
$month_array[10] =_OCTOBER;
$month_array[11] =_NOVEMBER;
$month_array[12] =_DECEMBER;
$usedate = getdate($date);
$day = $usedate['mday'];
$month = $usedate['mon'];
$year = $usedate['year'];
$date_selector = '<select name="'. $prefix .'_day">';
for ($i=1;$i<32;$i++){
$date_selector .= '<option value="' . $i . '"';
if ($i==$day) $date_selector .= 'selected';
$date_selector .= '>' . $i . '</option>';
}
$date_selector .= '</select>';
$date_selector .= '<select name="'. $prefix .'_month">';
for ($i=1;$i<13;$i++){
$date_selector .= '<option value="' . $i . '"';
if ($i==$month) $date_selector .= 'selected';
$date_selector .= '>' . $month_array[$i] . '</option>';
}
$date_selector .= '</select>';
$date_selector .= '<select name="'. $prefix .'_year">';
for ($i=2001;$i<2019;$i++){
$date_selector .= '<option value="' . $i . '"';
if ($i==$year) $date_selector .= 'selected';
$date_selector .= '>' . $i . '</option>';
}
$date_selector .= '</select>';
return $date_selector;
}
////
// Validate Option Name and Option Type Match
function zen_validate_options_to_options_value($products_options_id, $products_options_values_id) {
global $db;
$check_options_to_values_query= $db->Execute("select products_options_id
from "
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -