📄 general.php
字号:
return $new_array;
}
}
function twe_remove($source) {
global $messageStack, $twe_remove_error;
if (isset($twe_remove_error)) $twe_remove_error = false;
if (is_dir($source)) {
$dir = dir($source);
while ($file = $dir->read()) {
if ( ($file != '.') && ($file != '..') ) {
if (is_writeable($source . '/' . $file)) {
twe_remove($source . '/' . $file);
} else {
$messageStack->add(sprintf(ERROR_FILE_NOT_REMOVEABLE, $source . '/' . $file), 'error');
$twe_remove_error = true;
}
}
}
$dir->close();
if (is_writeable($source)) {
rmdir($source);
} else {
$messageStack->add(sprintf(ERROR_DIRECTORY_NOT_REMOVEABLE, $source), 'error');
$twe_remove_error = true;
}
} else {
if (is_writeable($source)) {
unlink($source);
} else {
$messageStack->add(sprintf(ERROR_FILE_NOT_REMOVEABLE, $source), 'error');
$twe_remove_error = true;
}
}
}
////
// Wrapper for constant() function
// Needed because its only available in PHP 4.0.4 and higher.
function twe_constant($constant) {
if (function_exists('constant')) {
$temp = constant($constant);
} else {
eval("\$temp=$constant;");
}
return $temp;
}
////
// Output the tax percentage with optional padded decimals
function twe_display_tax_value($value, $padding = TAX_DECIMAL_PLACES) {
if (strpos($value, '.')) {
$loop = true;
while ($loop) {
if (substr($value, -1) == '0') {
$value = substr($value, 0, -1);
} else {
$loop = false;
if (substr($value, -1) == '.') {
$value = substr($value, 0, -1);
}
}
}
}
if ($padding > 0) {
if ($decimal_pos = strpos($value, '.')) {
$decimals = strlen(substr($value, ($decimal_pos+1)));
for ($i=$decimals; $i<$padding; $i++) {
$value .= '0';
}
} else {
$value .= '.';
for ($i=0; $i<$padding; $i++) {
$value .= '0';
}
}
}
return $value;
}
function twe_get_tax_class_title($tax_class_id) {
if ($tax_class_id == '0') {
return TEXT_NONE;
} else {
$classes_query = twe_db_query("select tax_class_title from " . TABLE_TAX_CLASS . " where tax_class_id = '" . $tax_class_id . "'");
$classes = twe_db_fetch_array($classes_query);
return $classes['tax_class_title'];
}
}
function twe_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 twe_round($value, $precision) {
return round($value, $precision);
}
////
// Add tax to a products price
/*
function twe_add_tax($price, $tax) {
global $currencies;
if (DISPLAY_PRICE_WITH_TAX == 'true') {
return twe_round($price, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']) + twe_calculate_tax($price, $tax);
} else {
return twe_round($price, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
}
}
*/
// Calculates Tax rounding the result
function twe_calculate_tax($price, $tax) {
global $currencies;
return twe_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 twe_get_tax_rate($class_id, $country_id = -1, $zone_id = -1) {
global $customer_zone_id, $customer_country_id;
if ( ($country_id == -1) && ($zone_id == -1) ) {
if (!isset($_SESSION['customer_id'])) {
$country_id = STORE_COUNTRY;
$zone_id = STORE_ZONE;
} else {
$country_id = $customer_country_id;
$zone_id = $customer_zone_id;
}
}
$tax_query = twe_db_query("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 = '" . $country_id . "') AND (za.zone_id IS NULL OR za.zone_id = '0' OR za.zone_id = '" . $zone_id . "') AND tr.tax_class_id = '" . $class_id . "' GROUP BY tr.tax_priority");
if (twe_db_num_rows($tax_query)) {
$tax_multiplier = 0;
while ($tax = twe_db_fetch_array($tax_query)) {
$tax_multiplier += $tax['tax_rate'];
}
return $tax_multiplier;
} else {
return 0;
}
}
*/
function twe_call_function($function, $parameter, $object = '') {
if ($object == '') {
return call_user_func($function, $parameter);
} else {
return call_user_func(array($object, $function), $parameter);
}
}
function twe_get_zone_class_title($zone_class_id) {
if ($zone_class_id == '0') {
return TEXT_NONE;
} else {
$classes_query = twe_db_query("select geo_zone_name from " . TABLE_GEO_ZONES . " where geo_zone_id = '" . $zone_class_id . "'");
$classes = twe_db_fetch_array($classes_query);
return $classes['geo_zone_name'];
}
}
function twe_cfg_pull_down_template_sets() {
$name = (($key) ? 'configuration[' . $key . ']' : 'configuration_value');
if ($dir= opendir(DIR_FS_CATALOG.'templates/')){
while (($templates = readdir($dir)) !==false) {
if (is_dir( DIR_FS_CATALOG.'templates/'."//".$templates) and ($templates !="CVS") and ($templates!=".") and ($templates !="..")) {
$templates_array[]=array(
'id' => $templates,
'text' => $templates);
}
}
closedir($dir);
sort($templates_array);
return twe_draw_pull_down_menu($name, $templates_array, 0);
}
}
function twe_cfg_pull_down_zone_classes($zone_class_id, $key = '') {
$name = (($key) ? 'configuration[' . $key . ']' : 'configuration_value');
$zone_class_array = array(array('id' => '0', 'text' => TEXT_NONE));
$zone_class_query = twe_db_query("select geo_zone_id, geo_zone_name from " . TABLE_GEO_ZONES . " order by geo_zone_name");
while ($zone_class = twe_db_fetch_array($zone_class_query)) {
$zone_class_array[] = array('id' => $zone_class['geo_zone_id'],
'text' => $zone_class['geo_zone_name']);
}
return twe_draw_pull_down_menu($name, $zone_class_array, $zone_class_id);
}
function twe_cfg_pull_down_order_statuses($order_status_id, $key = '') {
$name = (($key) ? 'configuration[' . $key . ']' : 'configuration_value');
$statuses_array = array(array('id' => '0', 'text' => TEXT_DEFAULT));
$statuses_query = twe_db_query("select orders_status_id, orders_status_name from " . TABLE_ORDERS_STATUS . " where language_id = '" . $_SESSION['languages_id'] . "' order by orders_status_name");
while ($statuses = twe_db_fetch_array($statuses_query)) {
$statuses_array[] = array('id' => $statuses['orders_status_id'],
'text' => $statuses['orders_status_name']);
}
return twe_draw_pull_down_menu($name, $statuses_array, $order_status_id);
}
function twe_get_order_status_name($order_status_id, $language_id = '') {
if ($order_status_id < 1) return TEXT_DEFAULT;
if (!is_numeric($language_id)) $language_id = $_SESSION['languages_id'];
$status_query = twe_db_query("select orders_status_name from " . TABLE_ORDERS_STATUS . " where orders_status_id = '" . $order_status_id . "' and language_id = '" . $language_id . "'");
$status = twe_db_fetch_array($status_query);
return $status['orders_status_name'];
}
////
// Return a random value
function twe_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 twe_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);
}
}
// Return all customers statuses for a specified language_id and return an array(array())
// Use it to make pull_down_menu, checkbox....
function twe_get_customers_statuses() {
$customers_statuses_array = array(array());
$customers_statuses_query = twe_db_query("select customers_status_id, customers_status_name, customers_status_image, customers_status_discount, customers_status_ot_discount_flag, customers_status_ot_discount from " . TABLE_CUSTOMERS_STATUS . " where language_id = '" . $_SESSION['languages_id'] . "' order by customers_status_id");
$i=1; // this is changed from 0 to 1 in cs v1.2
while ($customers_statuses = twe_db_fetch_array($customers_statuses_query)) {
$i=$customers_statuses['customers_status_id'];
$customers_statuses_array[$i] = array('id' => $customers_statuses['customers_status_id'],
'text' => $customers_statuses['customers_status_name'],
'csa_public' => $customers_statuses['customers_status_public'],
'csa_image' => $customers_statuses['customers_status_image'],
'csa_discount' => $customers_statuses['customers_status_discount'],
'csa_ot_discount_flag' => $customers_statuses['customers_status_ot_discount_flag'],
'csa_ot_discount' => $customers_statuses['customers_status_ot_discount'],
'csa_graduated_prices' => $customers_statuses['customers_status_graduated_prices']
);
}
return $customers_statuses_array;
}
function twe_get_customer_status($customers_id) {
$customer_status_array = array();
$customer_status_query = twe_db_query("select customers_status, member_flag, customers_status_name, customers_status_public, customers_status_image, customers_status_discount, customers_status_ot_discount_flag, customers_status_ot_discount, customers_status_graduated_prices FROM " . TABLE_CUSTOMERS . " left join " . TABLE_CUSTOMERS_STATUS . " on customers_status = customers_status_id
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -