[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path Zen Cart 源代码 functions_lookups.php
<?php /** * functions_lookups.php * Lookup Functions for various Zen Cart activities such as countries, prices, products, product types, etc * * @package functions * @copyright Copyright 2003-2013 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 * @version GIT: $Id: Author: DrByte Tue Jul 23 19:29:41 2013 -0400 Modified in v1.5.2 $ */
/** * Returns an array with countries * * @param int If set limits to a single country * @param boolean If true adds the iso codes to the array */ function zen_get_countries($countries_id = '', $with_iso_codes = false, $activeOnly = TRUE) { global $db; $countries_array = array(); if (zen_not_null($countries_id)) { $countries_array['countries_name'] = ''; $countries = "select countries_name, countries_iso_code_2, countries_iso_code_3 from " . TABLE_COUNTRIES . " where countries_id = '" . (int)$countries_id . "'"; if ($activeOnly) $countries .= " and status != 0 "; $countries .= " order by countries_name"; $countries_values = $db->Execute($countries);
if ($with_iso_codes == true) { $countries_array['countries_iso_code_2'] = ''; $countries_array['countries_iso_code_3'] = ''; if (!$countries_values->EOF) { $countries_array = array('countries_name' => $countries_values->fields['countries_name'], 'countries_iso_code_2' => $countries_values->fields['countries_iso_code_2'], 'countries_iso_code_3' => $countries_values->fields['countries_iso_code_3']); } } else { if (!$countries_values->EOF) $countries_array = array('countries_name' => $countries_values->fields['countries_name']); } } else { $countries = "select countries_id, countries_name from " . TABLE_COUNTRIES . " "; if ($activeOnly) $countries .= " where status != 0 "; $countries .= " order by countries_name"; $countries_values = $db->Execute($countries); while (!$countries_values->EOF) { $countries_array[] = array('countries_id' => $countries_values->fields['countries_id'], 'countries_name' => $countries_values->fields['countries_name']); $countries_values->MoveNext(); } }
return $countries_array; }
/* * Alias function to zen_get_countries() */ function zen_get_country_name($country_id, $activeOnly = TRUE) { $country_array = zen_get_countries($country_id, FALSE, $activeOnly); return $country_array['countries_name']; }
/** * Alias function to zen_get_countries, which also returns the countries iso codes * * @param int If set limits to a single country */ function zen_get_countries_with_iso_codes($countries_id, $activeOnly = TRUE) { return zen_get_countries($countries_id, true, $activeOnly); }
/* * Return the zone (State/Province) name * TABLES: zones */ function zen_get_zone_name($country_id, $zone_id, $default_zone) { global $db; $zone_query = "select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country_id . "' and zone_id = '" . (int)$zone_id . "'";
/* * validate products_id */ function zen_products_id_valid($valid_id) { global $db; $check_valid = $db->Execute("select p.products_id from " . TABLE_PRODUCTS . " p where products_id='" . (int)$valid_id . "' limit 1"); if ($check_valid->EOF) { return false; } else { return true; } }
/** * Return a product's name. * * @param int The product id of the product who's name we want * @param int The language id to use. If this is not set then the current language is used */ function zen_get_products_name($product_id, $language = '') { global $db;
if (empty($language)) $language = $_SESSION['languages_id'];
$product_query = "select products_name from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$product_id . "' and language_id = '" . (int)$language . "'";
$product = $db->Execute($product_query);
return $product->fields['products_name']; }
/** * Return a product's stock count. * * @param int The product id of the product who's stock we want */ function zen_get_products_stock($products_id) { global $db; $products_id = zen_get_prid($products_id); $stock_query = "select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'";
/** * Check if the required stock is available. * * If insufficent stock is available return an out of stock message * * @param int The product id of the product whos's stock is to be checked * @param int Is this amount of stock available * * @TODO naughty html in a function */ function zen_check_stock($products_id, $products_quantity) { $stock_left = zen_get_products_stock($products_id) - $products_quantity; $out_of_stock = '';
/* * List manufacturers (returned in an array) */ function zen_get_manufacturers($manufacturers_array = '', $have_products = false) { global $db; if (!is_array($manufacturers_array)) $manufacturers_array = array();
if ($have_products == true) { $manufacturers_query = "select distinct m.manufacturers_id, m.manufacturers_name from " . TABLE_MANUFACTURERS . " m left join " . TABLE_PRODUCTS . " p on m.manufacturers_id = p.manufacturers_id where p.manufacturers_id = m.manufacturers_id and (p.products_status = 1 and p.products_quantity > 0) order by m.manufacturers_name"; } else { $manufacturers_query = "select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name"; }
/* * Check if product has attributes */ function zen_has_product_attributes($products_id, $not_readonly = 'true') { global $db;
if (PRODUCTS_OPTIONS_TYPE_READONLY_IGNORED == '1' and $not_readonly == 'true') { // don't include READONLY attributes to determin if attributes must be selected to add to cart $attributes_query = "select pa.products_attributes_id from " . TABLE_PRODUCTS_ATTRIBUTES . " pa left join " . TABLE_PRODUCTS_OPTIONS . " po on pa.options_id = po.products_options_id where pa.products_id = '" . (int)$products_id . "' and po.products_options_type != '" . PRODUCTS_OPTIONS_TYPE_READONLY . "' limit 1"; } else { // regardless of READONLY attributes no add to cart buttons $attributes_query = "select pa.products_attributes_id from " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . (int)$products_id . "' limit 1"; }
/* * Check if product has attributes values */ function zen_has_product_attributes_values($products_id) { global $db; $attributes_query = "select sum(options_values_price) as total from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "'";
/* * Find category name from ID, in indicated language */ function zen_get_category_name($category_id, $fn_language_id) { global $db; $category_query = "select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . $category_id . "' and language_id = '" . $fn_language_id . "'";
$category = $db->Execute($category_query);
return $category->fields['categories_name']; }
/* * Find category description, from category ID, in given language */ function zen_get_category_description($category_id, $fn_language_id) { global $db; $category_query = "select categories_description from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . $category_id . "' and language_id = '" . $fn_language_id . "'";
/* * Return category's name from ID, assuming current language * TABLES: categories_description */ function zen_get_categories_name($who_am_i) { global $db; $the_categories_name_query= "select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id= '" . $who_am_i . "' and language_id= '" . $_SESSION['languages_id'] . "'";
/* * Return a product's manufacturer's name, from ID * TABLES: products, manufacturers */ function zen_get_products_manufacturers_name($product_id) { global $db;
$product_query = "select m.manufacturers_name from " . TABLE_PRODUCTS . " p, " . TABLE_MANUFACTURERS . " m where p.products_id = '" . (int)$product_id . "' and p.manufacturers_id = m.manufacturers_id";
/* * Return a product's manufacturer's image, from Prod ID * TABLES: products, manufacturers */ function zen_get_products_manufacturers_image($product_id) { global $db;
$product_query = "select m.manufacturers_image from " . TABLE_PRODUCTS . " p, " . TABLE_MANUFACTURERS . " m where p.products_id = '" . (int)$product_id . "' and p.manufacturers_id = m.manufacturers_id";
$product =$db->Execute($product_query);
return $product->fields['manufacturers_image']; }
/* * Return a product's manufacturer's id, from Prod ID * TABLES: products */ function zen_get_products_manufacturers_id($product_id) { global $db;
$product_query = "select p.manufacturers_id from " . TABLE_PRODUCTS . " p where p.products_id = '" . (int)$product_id . "'";
$product =$db->Execute($product_query);
return $product->fields['manufacturers_id']; }
/* * Return attributes products_options_sort_order * TABLE: PRODUCTS_ATTRIBUTES */ function zen_get_attributes_sort_order($products_id, $options_id, $options_values_id) { global $db; $check = $db->Execute("select products_options_sort_order from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and options_id = '" . (int)$options_id . "' and options_values_id = '" . (int)$options_values_id . "' limit 1");
/* * configuration key value lookup * TABLE: configuration */ function zen_get_configuration_key_value($lookup) { global $db; $configuration_query= $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key='" . $lookup . "'"); $lookup_value= $configuration_query->fields['configuration_value']; if ( !($lookup_value) ) { $lookup_value='<span class="lookupAttention">' . $lookup . '</span>'; } return $lookup_value; }
/* * Return products description, based on specified language (or current lang if not specified) */ function zen_get_products_description($product_id, $language = '') { global $db;
if (empty($language)) $language = $_SESSION['languages_id'];
$product_query = "select products_description from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$product_id . "' and language_id = '" . (int)$language . "'";
/* * configuration key value lookup in TABLE_PRODUCT_TYPE_LAYOUT * Used to determine keys/flags used on a per-product-type basis for template-use, etc */ function zen_get_configuration_key_value_layout($lookup, $type=1) { global $db; $configuration_query= $db->Execute("select configuration_value from " . TABLE_PRODUCT_TYPE_LAYOUT . " where configuration_key='" . $lookup . "' and product_type_id='". (int)$type . "'"); $lookup_value= $configuration_query->fields['configuration_value']; if ( !($lookup_value) ) { $lookup_value='<span class="lookupAttention">' . $lookup . '</span>'; } return $lookup_value; }
/* * look up a products image and send back the image's HTML \<IMG...\> tag */ function zen_get_products_image($product_id, $width = SMALL_IMAGE_WIDTH, $height = SMALL_IMAGE_HEIGHT) { global $db;
$sql = "select p.products_image from " . TABLE_PRODUCTS . " p where products_id='" . (int)$product_id . "'"; $look_up = $db->Execute($sql);
/* * Look up whether the given product ID is allowed to be added to cart, according to product-type switches set in Admin */ function zen_get_products_allow_add_to_cart($lookup) { global $db;
$sql = "select products_type from " . TABLE_PRODUCTS . " where products_id='" . (int)$lookup . "'"; $type_lookup = $db->Execute($sql);
/* * Look up SHOW_XXX_INFO switch for product ID and product type */ function zen_get_show_product_switch_name($lookup, $field, $suffix= 'SHOW_', $prefix= '_INFO', $field_prefix= '_', $field_suffix='') { global $db;
$sql = "select products_type from " . TABLE_PRODUCTS . " where products_id='" . (int)$lookup . "'"; $type_lookup = $db->Execute($sql);
/* * Look up SHOW_XXX_INFO switch for product ID and product type */ function zen_get_show_product_switch($lookup, $field, $suffix= 'SHOW_', $prefix= '_INFO', $field_prefix= '_', $field_suffix='') { global $db;
$sql = "select products_type from " . TABLE_PRODUCTS . " where products_id='" . $lookup . "'"; $type_lookup = $db->Execute($sql);
/* * stop regular behavior based on customer/store settings * Used to disable various activities if store is in an operating mode that should prevent those activities */ function zen_run_normal() { $zc_run = false; switch (true) { case (strstr(EXCLUDE_ADMIN_IP_FOR_MAINTENANCE, $_SERVER['REMOTE_ADDR'])): // down for maintenance not for ADMIN $zc_run = true; break; case (DOWN_FOR_MAINTENANCE == 'true'): // down for maintenance $zc_run = false; break; case (STORE_STATUS >= 1): // showcase no prices $zc_run = false; break; case (CUSTOMERS_APPROVAL == '1' and $_SESSION['customer_id'] == ''): // customer must be logged in to browse $zc_run = false; break; case (CUSTOMERS_APPROVAL == '2' and $_SESSION['customer_id'] == ''): // show room only // customer may browse but no prices $zc_run = false; break; case (CUSTOMERS_APPROVAL == '3'): // show room only $zc_run = false; break; case (CUSTOMERS_APPROVAL_AUTHORIZATION != '0' and $_SESSION['customer_id'] == ''): // customer must be logged in to browse $zc_run = false; break; case (CUSTOMERS_APPROVAL_AUTHORIZATION != '0' and $_SESSION['customers_authorization'] > '0'): // customer must be logged in to browse $zc_run = false; break; default: // proceed normally $zc_run = true; break; } return $zc_run; }
/* * Look up whether to show prices, based on customer-authorization levels */ function zen_check_show_prices() { if (!(CUSTOMERS_APPROVAL == '2' and $_SESSION['customer_id'] == '') and !((CUSTOMERS_APPROVAL_AUTHORIZATION > 0 and CUSTOMERS_APPROVAL_AUTHORIZATION < 3) and ($_SESSION['customers_authorization'] > '0' or $_SESSION['customer_id'] == '')) and STORE_STATUS != 1) { return true; } else { return false; } }
/* * Return any field from products or products_description table * Example: zen_products_lookup('3', 'products_date_added'); */ function zen_products_lookup($product_id, $what_field = 'products_name', $language = '') { global $db;
if (empty($language)) $language = $_SESSION['languages_id'];
$product_lookup = $db->Execute("select " . $what_field . " as lookup_field from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id ='" . (int)$product_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$language . "'");
/* * Return any field from categories or categories_description table * Example: zen_categories_lookup('10', 'parent_id'); */ function zen_categories_lookup($categories_id, $what_field = 'categories_name', $language = '') { global $db;
if (empty($language)) $language = $_SESSION['languages_id'];
$category_lookup = $db->Execute("select " . $what_field . " as lookup_field from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id ='" . (int)$categories_id . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$language . "'");
//// // get define of New Products function zen_get_products_new_timelimit($time_limit = false) { if ($time_limit == false) { $time_limit = SHOW_NEW_PRODUCTS_LIMIT; } switch (true) { case ($time_limit == '0'): $display_limit = ''; break; case ($time_limit == '1'): $display_limit = " and date_format(p.products_date_added, '%Y%m') >= date_format(now(), '%Y%m')"; break; case ($time_limit == '7'): $display_limit = ' and TO_DAYS(NOW()) - TO_DAYS(p.products_date_added) <= 7'; break; case ($time_limit == '14'): $display_limit = ' and TO_DAYS(NOW()) - TO_DAYS(p.products_date_added) <= 14'; break; case ($time_limit == '30'): $display_limit = ' and TO_DAYS(NOW()) - TO_DAYS(p.products_date_added) <= 30'; break; case ($time_limit == '60'): $display_limit = ' and TO_DAYS(NOW()) - TO_DAYS(p.products_date_added) <= 60'; break; case ($time_limit == '90'): $display_limit = ' and TO_DAYS(NOW()) - TO_DAYS(p.products_date_added) <= 90'; break; case ($time_limit == '120'): $display_limit = ' and TO_DAYS(NOW()) - TO_DAYS(p.products_date_added) <= 120'; break; } return $display_limit; }
//// // check if Product is set to use downloads // does not validate download filename function zen_has_product_attributes_downloads_status($products_id) { global $db; if (DOWNLOAD_ENABLED == 'true') { $download_display_query_raw ="select pa.products_attributes_id, pad.products_attributes_filename from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad where pa.products_id='" . (int)$products_id . "' and pad.products_attributes_id= pa.products_attributes_id";
if (SHOW_NEW_PRODUCTS_UPCOMING_MASKED == 0) { // do nothing upcoming shows in new } else { // do not include upcoming in new $new_range .= " and (p.products_date_available <=" . $upcoming_mask . " or p.products_date_available IS NULL)"; } return $new_range; }
// build date range for upcoming products function zen_get_upcoming_date_range() { // 120 days; 24 hours; 60 mins; 60secs $date_range = time(); $zc_new_date = date('Ymd', $date_range); // need to check speed on this for larger sites // $new_range = ' and date_format(p.products_date_available, \'%Y%m%d\') >' . $zc_new_date; $new_range = ' and p.products_date_available >' . $zc_new_date . '235959';