⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 general.php

📁 全新且完善的强大网上商店系统
💻 PHP
📖 第 1 页 / 共 3 页
字号:
<?php
/*
  [SOOBIC!] includes/functions/general.php 

	Version: 1.5
	Author: soolan (soolan@qq.com)
	Copyright: soolan (www.soobic.com)

	Last Modified: 2005/4/18 10:00
  
*/


function tep_redirect($url) {
    if ( (ENABLE_SSL == true) && (getenv('HTTPS') == 'on') ) { 
       if (substr($url, 0, strlen(HTTP_SERVER)) == HTTP_SERVER) { 
           $url = HTTPS_SERVER . substr($url, strlen(HTTP_SERVER)); 
       }
    }
    header('Location: ' . $url);
    soobic_exit();
}

function tep_parse_input_field_data($data, $parse) {
    return strtr(trim($data), $parse);
}

function tep_output_string($string, $translate = false, $protected = false) {
    if ($protected == true) {
      return htmlspecialchars($string);
    } else {
      if ($translate == false) {
        return tep_parse_input_field_data($string, array('"' => '&quot;'));
      } else {
        return tep_parse_input_field_data($string, $translate);
      }
    }
}

function tep_output_string_protected($string) {
    return tep_output_string($string, false, true);
}

function tep_sanitize_string($string) {
    $string = ereg_replace(' +', ' ', trim($string));
    return preg_replace("/[<>]/", '_', $string);
}


function tep_get_products_name($product_id, $language = '') {
    global $languages_id,$db,$table_products_description;
    if (empty($language)) $language = $languages_id;
    $product_query = $db->query("select products_name from $table_products_description where products_id = '" . (int)$product_id . "' and language_id = '" . (int)$language . "'");
    $product = $db->fetch_array($product_query);
    return $product['products_name'];
}


function tep_get_products_stock($products_id) {
    global $db,$table_products;
		$products_id = tep_get_prid($products_id);
    $stock_query = $db->query("select products_quantity from $table_products where products_id = '" . (int)$products_id . "'");
    $stock_values = $db->fetch_array($stock_query);

    return $stock_values['products_quantity'];
}

function tep_check_stock($products_id, $products_quantity) {
    $stock_left = tep_get_products_stock($products_id) - $products_quantity;
    $out_of_stock = '';

    if ($stock_left < 0) {
      $out_of_stock = '<span class="markProductOutOfStock">' . STOCK_MARK_PRODUCT_OUT_OF_STOCK . '</span>';
    }

    return $out_of_stock;
}

function tep_break_string($string, $len, $break_char = '-') {
    $l = 0;
    $output = '';
    for ($i=0, $n=strlen($string); $i<$n; $i++) {
      $char = substr($string, $i, 1);
      if ($char != ' ') {
        $l++;
      } else {
        $l = 0;
      }
      if ($l > $len) {
        $l = 1;
        $output .= $break_char;
      }
      $output .= $char;
    }
    return $output;
}

function tep_get_all_get_params($exclude_array = '') {
    global $HTTP_GET_VARS;
    if (!is_array($exclude_array)) $exclude_array = array();
    $get_url = '';
    if (is_array($HTTP_GET_VARS) && (sizeof($HTTP_GET_VARS) > 0)) {
      reset($HTTP_GET_VARS);
      while (list($key, $value) = each($HTTP_GET_VARS)) {
        if ( (strlen($value) > 0) && ($key != tep_session_name()) && ($key != 'error') && (!in_array($key, $exclude_array)) && ($key != 'x') && ($key != 'y') ) {
          $get_url .= $key . '=' . rawurlencode(stripslashes($value)) . '&';
        }
      }
    }
    return $get_url;
}

function tep_get_countries($countries_id = '', $with_iso_codes = false) {
    global $db,$table_countries;
		$countries_array = array();
    if (!empty($countries_id)) {
      if ($with_iso_codes == true) {
        $countries = $db->query("select countries_name, countries_iso_code_2, countries_iso_code_3 from $table_countries where countries_id = '" . (int)$countries_id . "' order by countries_name");
        $countries_values = $db->fetch_array($countries);
        $countries_array = array('countries_name' => $countries_values['countries_name'],
                                 'countries_iso_code_2' => $countries_values['countries_iso_code_2'],
                                 'countries_iso_code_3' => $countries_values['countries_iso_code_3']);
      } else {
        $countries = $db->query("select countries_name from $table_countries where countries_id = '" . (int)$countries_id . "'");
        $countries_values = $db->fetch_array($countries);
        $countries_array = array('countries_name' => $countries_values['countries_name']);
      }
    } else {
      $countries = $db->query("select countries_id, countries_name from $table_countries order by countries_name");
      while ($countries_values = $db->fetch_array($countries)) {
           $countries_array[] = array('id' => $countries_values['countries_id'],
                                   'text' => $countries_values['countries_name']);
      }
    }
    return $countries_array;
}

function tep_get_countries_with_iso_codes($countries_id) {
    return tep_get_countries($countries_id, true);
}

function tep_get_path($current_category_id = '') {
    global $cPath_array, $db, $table_categories;

    if (tep_not_null($current_category_id)) {
      $cp_size = sizeof($cPath_array);
      if ($cp_size == 0) {
        $cPath_new = $current_category_id;
      } else {
        $cPath_new = '';
        $last_category_query = $db->query("select parent_id from $table_categories where categories_id = '" . (int)$cPath_array[($cp_size-1)] . "'");
        $last_category = $db->fetch_array($last_category_query);

        $current_category_query = $db->query("select parent_id from $table_categories where categories_id = '" . (int)$current_category_id . "'");
        $current_category = $db->fetch_array($current_category_query);

        if ($last_category['parent_id'] == $current_category['parent_id']) {
          for ($i=0; $i<($cp_size-1); $i++) {
            $cPath_new .= '_' . $cPath_array[$i];
          }
        } else {
          for ($i=0; $i<$cp_size; $i++) {
            $cPath_new .= '_' . $cPath_array[$i];
          }
        }
        $cPath_new .= '_' . $current_category_id;

        if (substr($cPath_new, 0, 1) == '_') {
          $cPath_new = substr($cPath_new, 1);
        }
      }
    } else {
      $cPath_new = implode('_', $cPath_array);
    }
    return 'cPath=' . $cPath_new;
}

function tep_browser_detect($component) {
    global $HTTP_USER_AGENT;
    return stristr($HTTP_USER_AGENT, $component);
}

function tep_get_country_name($country_id) {
    $country_array = tep_get_countries($country_id);
    return $country_array['countries_name'];
}

function tep_get_zone_name($country_id, $zone_id, $default_zone) {
    global $db, $table_zones;
		$zone_query = $db->query("select zone_name from $table_zones where zone_country_id = '" . (int)$country_id . "' and zone_id = '" . (int)$zone_id . "'");
    if ($db->num_rows($zone_query)) {
        $zone = $db->fetch_array($zone_query);
        return $zone['zone_name'];
    } else {
        return $default_zone;
    }
}

function tep_get_zone_code($country_id, $zone_id, $default_zone) {
    global $db, $table_zones;
		$zone_query = $db->query("select zone_code from $table_zones where zone_country_id = '" . (int)$country_id . "' and zone_id = '" . (int)$zone_id . "'");
    if ($db->num_rows($zone_query)) {
      $zone = $db->fetch_array($zone_query);
      return $zone['zone_code'];
    } else {
      return $default_zone;
    }
}

function tep_round($number, $precision) {
    if (strpos($number, '.') && (strlen(substr($number, strpos($number, '.')+1)) > $precision)) {
      $number = substr($number, 0, strpos($number, '.') + 1 + $precision + 1);

      if (substr($number, -1) >= 5) {
        if ($precision > 1) {
          $number = substr($number, 0, -1) + ('0.' . str_repeat(0, $precision-1) . '1');
        } elseif ($precision == 1) {
          $number = substr($number, 0, -1) + 0.1;
        } else {
          $number = substr($number, 0, -1) + 1;
        }
      } else {
        $number = substr($number, 0, -1);
      }
    }
    return $number;
}

function tep_get_tax_rate($class_id, $country_id = -1, $zone_id = -1) {
    global $db, $table_tax_rates, $table_zones_to_geo_zones, $table_geo_zones , $customer_zone_id, $customer_country_id;
    if ( ($country_id == -1) && ($zone_id == -1) ) {
        if (!tep_session_is_registered('customer_id')) {
           $country_id = STORE_COUNTRY;
           $zone_id = STORE_ZONE;
      } else {
        $country_id = $customer_country_id;
        $zone_id = $customer_zone_id;
      }
    }
    $tax_query = $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 = '" . (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 ($db->num_rows($tax_query)) {
      $tax_multiplier = 1.0;
      while ($tax = $db->fetch_array($tax_query)) {
        $tax_multiplier *= 1.0 + ($tax['tax_rate'] / 100);
      }
      return ($tax_multiplier - 1.0) * 100;
    } else {
      return 0;
    }
}

function tep_get_tax_description($class_id, $country_id, $zone_id) {
    global $db, $table_tax_rates , $table_zones_to_geo_zones , $table_geo_zones ;
		$tax_query = $db->query("select tax_description 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 . "' order by tr.tax_priority");
    if ($db->num_rows($tax_query)) {
        $tax_description = '';
        while ($tax = $db->fetch_array($tax_query)) {
           $tax_description .= $tax['tax_description'] . ' + ';
        }
        $tax_description = substr($tax_description, 0, -3);

        return $tax_description;
    } else {
        return TEXT_UNKNOWN_TAX_RATE;
    }
}

function tep_add_tax($price, $tax) {
    global $currencies;

    if ( (DISPLAY_PRICE_WITH_TAX == 'true') && ($tax > 0) ) {
      return tep_round($price, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']) + tep_calculate_tax($price, $tax);
    } else {
      return tep_round($price, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
    }
}

function tep_calculate_tax($price, $tax) {
    global $currencies;

    return tep_round($price * $tax / 100, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
}

function tep_get_address_format_id($country_id) {
    global $db,$table_countries;
		$query = $db->query("select address_format_id as format_id from $table_countries where countries_id = '" . (int)$country_id . "'");
    if ($db->num_rows($query)) {
      $address_format = $db->fetch_array($query);
      return $address_format['format_id'];
    } else {
      return '1';
    }
}

function tep_row_number_format($number) {
    if ( ($number < 10) && (substr($number, 0, 1) != '0') ) $number = '0' . $number;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -