[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
[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

Zen Cart 源代码 functions_lookups.php




下载文件

文件名: functions_lookups.php
文件类型: PHP文件
文件大小: 33.35 KiB
MD5: 16aaa19f80dea5f4d7dc8e023869a329

functions_lookups.php - 关闭高亮
  1. <?php
  2. /**
  3.  * functions_lookups.php
  4.  * Lookup Functions for various Zen Cart activities such as countries, prices, products, product types, etc
  5.  *
  6.  * @package functions
  7.  * @copyright Copyright 2003-2009 Zen Cart Development Team
  8.  * @copyright Portions Copyright 2003 osCommerce
  9.  * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  10.  * @version $Id: functions_lookups.php 14141 2009-08-10 19:34:47Z wilt $
  11.  */
  12.  
  13.  
  14. /**
  15.  * Returns an array with countries
  16.  *
  17.  * @param int If set limits to a single country
  18.  * @param boolean If true adds the iso codes to the array
  19. */
  20.   function zen_get_countries($countries_id = '', $with_iso_codes = false) {
  21.     global $db;
  22.     $countries_array = array();
  23.     if (zen_not_null($countries_id)) {
  24.       if ($with_iso_codes == true) {
  25.         $countries = "select countries_name, countries_iso_code_2, countries_iso_code_3
  26.                      from " . TABLE_COUNTRIES . "
  27.                      where countries_id = '" . (int)$countries_id . "'
  28.                      order by countries_name";
  29.  
  30.         $countries_values = $db->Execute($countries);
  31.  
  32.         $countries_array = array('countries_name' => $countries_values->fields['countries_name'],
  33.                                  'countries_iso_code_2' => $countries_values->fields['countries_iso_code_2'],
  34.                                  'countries_iso_code_3' => $countries_values->fields['countries_iso_code_3']);
  35.       } else {
  36.         $countries = "select countries_name
  37.                      from " . TABLE_COUNTRIES . "
  38.                      where countries_id = '" . (int)$countries_id . "'";
  39.  
  40.         $countries_values = $db->Execute($countries);
  41.  
  42.         $countries_array = array('countries_name' => $countries_values->fields['countries_name']);
  43.       }
  44.     } else {
  45.       $countries = "select countries_id, countries_name
  46.                    from " . TABLE_COUNTRIES . "
  47.                    order by countries_name";
  48.  
  49.       $countries_values = $db->Execute($countries);
  50.  
  51.       while (!$countries_values->EOF) {
  52.         $countries_array[] = array('countries_id' => $countries_values->fields['countries_id'],
  53.                                    'countries_name' => $countries_values->fields['countries_name']);
  54.  
  55.         $countries_values->MoveNext();
  56.       }
  57.     }
  58.  
  59.     return $countries_array;
  60.   }
  61.  
  62. /*
  63.  *  Alias function to zen_get_countries()
  64.  */
  65.   function zen_get_country_name($country_id) {
  66.     $country_array = zen_get_countries($country_id);
  67.  
  68.     return $country_array['countries_name'];
  69.   }
  70.  
  71. /**
  72.  * Alias function to zen_get_countries, which also returns the countries iso codes
  73.  *
  74.  * @param int If set limits to a single country
  75. */
  76.   function zen_get_countries_with_iso_codes($countries_id) {
  77.     return zen_get_countries($countries_id, true);
  78.   }
  79.  
  80. /*
  81.  * Return the zone (State/Province) name
  82.  * TABLES: zones
  83.  */
  84.   function zen_get_zone_name($country_id, $zone_id, $default_zone) {
  85.     global $db;
  86.     $zone_query = "select zone_name
  87.                   from " . TABLE_ZONES . "
  88.                   where zone_country_id = '" . (int)$country_id . "'
  89.                   and zone_id = '" . (int)$zone_id . "'";
  90.  
  91.     $zone = $db->Execute($zone_query);
  92.  
  93.     if ($zone->RecordCount()) {
  94.       return $zone->fields['zone_name'];
  95.     } else {
  96.       return $default_zone;
  97.     }
  98.   }
  99.  
  100. /*
  101.  * Returns the zone (State/Province) code
  102.  * TABLES: zones
  103.  */
  104.   function zen_get_zone_code($country_id, $zone_id, $default_zone) {
  105.     global $db;
  106.     $zone_query = "select zone_code
  107.                   from " . TABLE_ZONES . "
  108.                   where zone_country_id = '" . (int)$country_id . "'
  109.                   and zone_id = '" . (int)$zone_id . "'";
  110.  
  111.     $zone = $db->Execute($zone_query);
  112.  
  113.     if ($zone->RecordCount() > 0) {
  114.       return $zone->fields['zone_code'];
  115.     } else {
  116.       return $default_zone;
  117.     }
  118.   }
  119.  
  120.  
  121. /*
  122.  *  validate products_id
  123.  */
  124.   function zen_products_id_valid($valid_id) {
  125.     global $db;
  126.     $check_valid = $db->Execute("select p.products_id
  127.                                 from " . TABLE_PRODUCTS . " p
  128.                                 where products_id='" . (int)$valid_id . "' limit 1");
  129.     if ($check_valid->EOF) {
  130.       return false;
  131.     } else {
  132.       return true;
  133.     }
  134.   }
  135.  
  136. /**
  137.  * Return a product's name.
  138.  *
  139.  * @param int The product id of the product who's name we want
  140.  * @param int The language id to use. If this is not set then the current language is used
  141. */
  142.   function zen_get_products_name($product_id, $language = '') {
  143.     global $db;
  144.  
  145.     if (empty($language)) $language = $_SESSION['languages_id'];
  146.  
  147.     $product_query = "select products_name
  148.                      from " . TABLE_PRODUCTS_DESCRIPTION . "
  149.                      where products_id = '" . (int)$product_id . "'
  150.                      and language_id = '" . (int)$language . "'";
  151.  
  152.     $product = $db->Execute($product_query);
  153.  
  154.     return $product->fields['products_name'];
  155.   }
  156.  
  157.  
  158. /**
  159.  * Return a product's stock count.
  160.  *
  161.  * @param int The product id of the product who's stock we want
  162. */
  163.   function zen_get_products_stock($products_id) {
  164.     global $db;
  165.     $products_id = zen_get_prid($products_id);
  166.     $stock_query = "select products_quantity
  167.                    from " . TABLE_PRODUCTS . "
  168.                    where products_id = '" . (int)$products_id . "'";
  169.  
  170.     $stock_values = $db->Execute($stock_query);
  171.  
  172.     return $stock_values->fields['products_quantity'];
  173.   }
  174.  
  175. /**
  176.  * Check if the required stock is available.
  177.  *
  178.  * If insufficent stock is available return an out of stock message
  179.  *
  180.  * @param int The product id of the product whos's stock is to be checked
  181.  * @param int Is this amount of stock available
  182.  *
  183.  * @TODO naughty html in a function
  184. */
  185.   function zen_check_stock($products_id, $products_quantity) {
  186.     $stock_left = zen_get_products_stock($products_id) - $products_quantity;
  187.     $out_of_stock = '';
  188.  
  189.     if ($stock_left < 0) {
  190.       $out_of_stock = '<span class="markProductOutOfStock">' . STOCK_MARK_PRODUCT_OUT_OF_STOCK . '</span>';
  191.     }
  192.  
  193.     return $out_of_stock;
  194.   }
  195.  
  196. /*
  197.  * List manufacturers (returned in an array)
  198.  */
  199.   function zen_get_manufacturers($manufacturers_array = '', $have_products = false) {
  200.     global $db;
  201.     if (!is_array($manufacturers_array)) $manufacturers_array = array();
  202.  
  203.     if ($have_products == true) {
  204.       $manufacturers_query = "select distinct m.manufacturers_id, m.manufacturers_name
  205.                              from " . TABLE_MANUFACTURERS . " m
  206.                              left join " . TABLE_PRODUCTS . " p on m.manufacturers_id = p.manufacturers_id
  207.                              where p.manufacturers_id = m.manufacturers_id
  208.                              and (p.products_status = 1
  209.                              and p.products_quantity > 0)
  210.                              order by m.manufacturers_name";
  211.     } else {
  212.       $manufacturers_query = "select manufacturers_id, manufacturers_name
  213.                              from " . TABLE_MANUFACTURERS . " order by manufacturers_name";
  214.     }
  215.  
  216.     $manufacturers = $db->Execute($manufacturers_query);
  217.  
  218.     while (!$manufacturers->EOF) {
  219.       $manufacturers_array[] = array('id' => $manufacturers->fields['manufacturers_id'], 'text' => $manufacturers->fields['manufacturers_name']);
  220.       $manufacturers->MoveNext();
  221.     }
  222.  
  223.     return $manufacturers_array;
  224.   }
  225.  
  226. /*
  227.  *  Check if product has attributes
  228.  */
  229.   function zen_has_product_attributes($products_id, $not_readonly = 'true') {
  230.     global $db;
  231.  
  232.     if (PRODUCTS_OPTIONS_TYPE_READONLY_IGNORED == '1' and $not_readonly == 'true') {
  233.       // don't include READONLY attributes to determin if attributes must be selected to add to cart
  234.       $attributes_query = "select pa.products_attributes_id
  235.                           from " . TABLE_PRODUCTS_ATTRIBUTES . " pa left join " . TABLE_PRODUCTS_OPTIONS . " po on pa.options_id = po.products_options_id
  236.                           where pa.products_id = '" . (int)$products_id . "' and po.products_options_type != '" . PRODUCTS_OPTIONS_TYPE_READONLY . "' limit 1";
  237.     } else {
  238.       // regardless of READONLY attributes no add to cart buttons
  239.       $attributes_query = "select pa.products_attributes_id
  240.                           from " . TABLE_PRODUCTS_ATTRIBUTES . " pa
  241.                           where pa.products_id = '" . (int)$products_id . "' limit 1";
  242.     }
  243.  
  244.     $attributes = $db->Execute($attributes_query);
  245.  
  246.     if ($attributes->recordCount() > 0 && $attributes->fields['products_attributes_id'] > 0) {
  247.       return true;
  248.     } else {
  249.       return false;
  250.     }
  251.   }
  252.  
  253. /*
  254.  *  Check if product has attributes values
  255.  */
  256.   function zen_has_product_attributes_values($products_id) {
  257.     global $db;
  258.     $attributes_query = "select sum(options_values_price) as total
  259.                         from " . TABLE_PRODUCTS_ATTRIBUTES . "
  260.                         where products_id = '" . (int)$products_id . "'";
  261.  
  262.     $attributes = $db->Execute($attributes_query);
  263.  
  264.     if ($attributes->fields['total'] != 0) {
  265.       return true;
  266.     } else {
  267.       return false;
  268.     }
  269.   }
  270.  
  271. /*
  272.  * Find category name from ID, in indicated language
  273.  */
  274.   function zen_get_category_name($category_id, $fn_language_id) {
  275.     global $db;
  276.     $category_query = "select categories_name
  277.                       from " . TABLE_CATEGORIES_DESCRIPTION . "
  278.                       where categories_id = '" . $category_id . "'
  279.                       and language_id = '" . $fn_language_id . "'";
  280.  
  281.     $category = $db->Execute($category_query);
  282.  
  283.     return $category->fields['categories_name'];
  284.   }
  285.  
  286.  
  287. /*
  288.  * Find category description, from category ID, in given language
  289.  */
  290.   function zen_get_category_description($category_id, $fn_language_id) {
  291.     global $db;
  292.     $category_query = "select categories_description
  293.                       from " . TABLE_CATEGORIES_DESCRIPTION . "
  294.                       where categories_id = '" . $category_id . "'
  295.                       and language_id = '" . $fn_language_id . "'";
  296.  
  297.     $category = $db->Execute($category_query);
  298.  
  299.     return $category->fields['categories_description'];
  300.   }
  301.  
  302. /*
  303.  * Return a product's category
  304.  * TABLES: products_to_categories
  305.  */
  306.   function zen_get_products_category_id($products_id) {
  307.     global $db;
  308.  
  309.     $the_products_category_query = "select products_id, master_categories_id from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'";
  310.     $the_products_category = $db->Execute($the_products_category_query);
  311.  
  312.     return $the_products_category->fields['master_categories_id'];
  313.   }
  314.  
  315.  
  316. /*
  317.  * Return category's image
  318.  * TABLES: categories
  319.  */
  320.   function zen_get_categories_image($what_am_i) {
  321.     global $db;
  322.  
  323.     $the_categories_image_query= "select categories_image from " . TABLE_CATEGORIES . " where categories_id= '" . $what_am_i . "'";
  324.     $the_products_category = $db->Execute($the_categories_image_query);
  325.  
  326.     return $the_products_category->fields['categories_image'];
  327.   }
  328.  
  329. /*
  330.  *  Return category's name from ID, assuming current language
  331.  *  TABLES: categories_description
  332.  */
  333.   function zen_get_categories_name($who_am_i) {
  334.     global $db;
  335.     $the_categories_name_query= "select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id= '" . $who_am_i . "' and language_id= '" . $_SESSION['languages_id'] . "'";
  336.  
  337.     $the_categories_name = $db->Execute($the_categories_name_query);
  338.  
  339.     return $the_categories_name->fields['categories_name'];
  340.   }
  341.  
  342. /*
  343.  * Return a product's manufacturer's name, from ID
  344.  * TABLES: products, manufacturers
  345.  */
  346.   function zen_get_products_manufacturers_name($product_id) {
  347.     global $db;
  348.  
  349.     $product_query = "select m.manufacturers_name
  350.                      from " . TABLE_PRODUCTS . " p, " .
  351.                             TABLE_MANUFACTURERS . " m
  352.                      where p.products_id = '" . (int)$product_id . "'
  353.                      and p.manufacturers_id = m.manufacturers_id";
  354.  
  355.     $product =$db->Execute($product_query);
  356.  
  357.     return ($product->RecordCount() > 0) ? $product->fields['manufacturers_name'] : "";
  358.   }
  359.  
  360. /*
  361.  * Return a product's manufacturer's image, from Prod ID
  362.  * TABLES: products, manufacturers
  363.  */
  364.   function zen_get_products_manufacturers_image($product_id) {
  365.     global $db;
  366.  
  367.     $product_query = "select m.manufacturers_image
  368.                      from " . TABLE_PRODUCTS . " p, " .
  369.                             TABLE_MANUFACTURERS . " m
  370.                      where p.products_id = '" . (int)$product_id . "'
  371.                      and p.manufacturers_id = m.manufacturers_id";
  372.  
  373.     $product =$db->Execute($product_query);
  374.  
  375.     return $product->fields['manufacturers_image'];
  376.   }
  377.  
  378. /*
  379.  * Return a product's manufacturer's id, from Prod ID
  380.  * TABLES: products
  381.  */
  382.   function zen_get_products_manufacturers_id($product_id) {
  383.     global $db;
  384.  
  385.     $product_query = "select p.manufacturers_id
  386.                      from " . TABLE_PRODUCTS . " p
  387.                      where p.products_id = '" . (int)$product_id . "'";
  388.  
  389.     $product =$db->Execute($product_query);
  390.  
  391.     return $product->fields['manufacturers_id'];
  392.   }
  393.  
  394. /*
  395.  * Return attributes products_options_sort_order
  396.  * TABLE: PRODUCTS_ATTRIBUTES
  397.  */
  398.   function zen_get_attributes_sort_order($products_id, $options_id, $options_values_id) {
  399.     global $db;
  400.       $check = $db->Execute("select products_options_sort_order
  401.                             from " . TABLE_PRODUCTS_ATTRIBUTES . "
  402.                             where products_id = '" . (int)$products_id . "'
  403.                             and options_id = '" . (int)$options_id . "'
  404.                             and options_values_id = '" . (int)$options_values_id . "' limit 1");
  405.  
  406.       return $check->fields['products_options_sort_order'];
  407.   }
  408.  
  409. /*
  410.  *  return attributes products_options_sort_order
  411.  *  TABLES: PRODUCTS_OPTIONS, PRODUCTS_ATTRIBUTES
  412.  */
  413.   function zen_get_attributes_options_sort_order($products_id, $options_id, $options_values_id, $lang_num = '') {
  414.     global $db;
  415.       if ($lang_num == '') $lang_num = (int)$_SESSION['languages_id'];
  416.       $check = $db->Execute("select products_options_sort_order
  417.                             from " . TABLE_PRODUCTS_OPTIONS . "
  418.                             where products_options_id = '" . (int)$options_id . "' and language_id = '" . $lang_num . "' limit 1");
  419.  
  420.       $check_options_id = $db->Execute("select products_id, options_id, options_values_id, products_options_sort_order
  421.                             from " . TABLE_PRODUCTS_ATTRIBUTES . "
  422.                             where products_id='" . (int)$products_id . "'
  423.                             and options_id='" . (int)$options_id . "'
  424.                             and options_values_id = '" . (int)$options_values_id . "' limit 1");
  425.  
  426.  
  427.       return $check->fields['products_options_sort_order'] . '.' . str_pad($check_options_id->fields['products_options_sort_order'],5,'0',STR_PAD_LEFT);
  428.   }
  429.  
  430. /*
  431.  *  check if attribute is display only
  432.  */
  433.   function zen_get_attributes_valid($product_id, $option, $value) {
  434.     global $db;
  435.  
  436. // regular attribute validation
  437.     $check_attributes = $db->Execute("select attributes_display_only, attributes_required from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id='" . (int)$product_id . "' and options_id='" . (int)$option . "' and options_values_id='" . (int)$value . "'");
  438.  
  439.     $check_valid = true;
  440.  
  441. // display only cannot be selected
  442.     if ($check_attributes->fields['attributes_display_only'] == '1') {
  443.       $check_valid = false;
  444.     }
  445.  
  446. // text required validation
  447.     if (preg_match('/^txt_/', $option)) {
  448.       $check_attributes = $db->Execute("select attributes_display_only, attributes_required from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id='" . (int)$product_id . "' and options_id='" . (int)preg_replace('/txt_/', '', $option) . "' and options_values_id='0'");
  449. // text cannot be blank
  450.       if ($check_attributes->fields['attributes_required'] == '1' and empty($value)) {
  451.         $check_valid = false;
  452.       }
  453.     }
  454.  
  455.     return $check_valid;
  456.   }
  457.  
  458. /*
  459.  * Return Options_Name from ID
  460.  */
  461.  
  462.   function zen_options_name($options_id) {
  463.     global $db;
  464.  
  465.     $options_id = str_replace('txt_','',$options_id);
  466.  
  467.     $options_values = $db->Execute("select products_options_name
  468.                                    from " . TABLE_PRODUCTS_OPTIONS . "
  469.                                    where products_options_id = '" . (int)$options_id . "'
  470.                                    and language_id = '" . (int)$_SESSION['languages_id'] . "'");
  471.  
  472.     return $options_values->fields['products_options_name'];
  473.   }
  474.  
  475. /*
  476.  * Return Options_values_name from value-ID
  477.  */
  478.   function zen_values_name($values_id) {
  479.     global $db;
  480.  
  481.     $values_values = $db->Execute("select products_options_values_name
  482.                                   from " . TABLE_PRODUCTS_OPTIONS_VALUES . "
  483.                                   where products_options_values_id = '" . (int)$values_id . "'
  484.                                   and language_id = '" . (int)$_SESSION['languages_id'] . "'");
  485.  
  486.     return $values_values->fields['products_options_values_name'];
  487.   }
  488.  
  489. /*
  490.  *  configuration key value lookup
  491.  *  TABLE: configuration
  492.  */
  493.   function zen_get_configuration_key_value($lookup) {
  494.     global $db;
  495.     $configuration_query= $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key='" . $lookup . "'");
  496.     $lookup_value= $configuration_query->fields['configuration_value'];
  497.     if ( !($lookup_value) ) {
  498.       $lookup_value='<span class="lookupAttention">' . $lookup . '</span>';
  499.     }
  500.     return $lookup_value;
  501.   }
  502.  
  503. /*
  504.  *  Return products description, based on specified language (or current lang if not specified)
  505.  */
  506.   function zen_get_products_description($product_id, $language = '') {
  507.     global $db;
  508.  
  509.     if (empty($language)) $language = $_SESSION['languages_id'];
  510.  
  511.     $product_query = "select products_description
  512.                      from " . TABLE_PRODUCTS_DESCRIPTION . "
  513.                      where products_id = '" . (int)$product_id . "'
  514.                      and language_id = '" . (int)$language . "'";
  515.  
  516.     $product = $db->Execute($product_query);
  517.  
  518.     return $product->fields['products_description'];
  519.   }
  520.  
  521. /*
  522.  * look up the product type from product_id and return an info page name (for template/page handling)
  523.  */
  524.   function zen_get_info_page($zf_product_id) {
  525.     global $db;
  526.     $sql = "select products_type from " . TABLE_PRODUCTS . " where products_id = '" . (int)$zf_product_id . "'";
  527.     $zp_type = $db->Execute($sql);
  528.     if ($zp_type->RecordCount() == 0) {
  529.       return 'product_info';
  530.     } else {
  531.       $zp_product_type = $zp_type->fields['products_type'];
  532.       $sql = "select type_handler from " . TABLE_PRODUCT_TYPES . " where type_id = '" . (int)$zp_product_type . "'";
  533.       $zp_handler = $db->Execute($sql);
  534.       return $zp_handler->fields['type_handler'] . '_info';
  535.     }
  536.   }
  537.  
  538. /*
  539.  * Get accepted credit cards
  540.  * There needs to be a define on the accepted credit card in the language file credit_cards.php example: TEXT_CC_ENABLED_VISA
  541.  */
  542.   function zen_get_cc_enabled($text_image = 'TEXT_', $cc_seperate = ' ', $cc_make_columns = 0) {
  543.     global $db;
  544.     $cc_check_accepted_query = $db->Execute(SQL_CC_ENABLED);
  545.     $cc_check_accepted = '';
  546.     $cc_counter = 0;
  547.     if ($cc_make_columns == 0) {
  548.       while (!$cc_check_accepted_query->EOF) {
  549.         $check_it = $text_image . $cc_check_accepted_query->fields['configuration_key'];
  550.         if (defined($check_it)) {
  551.           $cc_check_accepted .= constant($check_it) . $cc_seperate;
  552.         }
  553.         $cc_check_accepted_query->MoveNext();
  554.       }
  555.     } else {
  556.       // build a table
  557.       $cc_check_accepted = '<table class="ccenabled">' . "\n";
  558.       $cc_check_accepted .= '<tr class="ccenabled">' . "\n";
  559.       while (!$cc_check_accepted_query->EOF) {
  560.         $check_it = $text_image . $cc_check_accepted_query->fields['configuration_key'];
  561.         if (defined($check_it)) {
  562.           $cc_check_accepted .= '<td class="ccenabled">' . constant($check_it) . '</td>' . "\n";
  563.         }
  564.         $cc_check_accepted_query->MoveNext();
  565.         $cc_counter++;
  566.         if ($cc_counter >= $cc_make_columns) {
  567.           $cc_check_accepted .= '</tr>' . "\n" . '<tr class="ccenabled">' . "\n";
  568.           $cc_counter = 0;
  569.         }
  570.       }
  571.       $cc_check_accepted .= '</tr>' . "\n" . '</table>' . "\n";
  572.     }
  573.     return $cc_check_accepted;
  574.   }
  575.  
  576. ////
  577. // TABLES: categories_name from products_id
  578.   function zen_get_categories_name_from_product($product_id) {
  579.     global $db;
  580.  
  581. //    $check_products_category= $db->Execute("select products_id, categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id='" . $product_id . "' limit 1");
  582.     $check_products_category = $db->Execute("select products_id, master_categories_id from " . TABLE_PRODUCTS . " where products_id = '" . (int)$product_id . "'");
  583.     $the_categories_name= $db->Execute("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id= '" . $check_products_category->fields['master_categories_id'] . "' and language_id= '" . $_SESSION['languages_id'] . "'");
  584.  
  585.     return $the_categories_name->fields['categories_name'];
  586.   }
  587.  
  588.  
  589. /*
  590.  * configuration key value lookup in TABLE_PRODUCT_TYPE_LAYOUT
  591.  * Used to determine keys/flags used on a per-product-type basis for template-use, etc
  592.  */
  593.   function zen_get_configuration_key_value_layout($lookup, $type=1) {
  594.     global $db;
  595.     $configuration_query= $db->Execute("select configuration_value from " . TABLE_PRODUCT_TYPE_LAYOUT . " where configuration_key='" . $lookup . "' and product_type_id='". (int)$type . "'");
  596.     $lookup_value= $configuration_query->fields['configuration_value'];
  597.     if ( !($lookup_value) ) {
  598.       $lookup_value='<span class="lookupAttention">' . $lookup . '</span>';
  599.     }
  600.     return $lookup_value;
  601.   }
  602.  
  603. /*
  604.  * look up a products image and send back the image's HTML \<IMG...\> tag
  605.  */
  606.   function zen_get_products_image($product_id, $width = SMALL_IMAGE_WIDTH, $height = SMALL_IMAGE_HEIGHT) {
  607.     global $db;
  608.  
  609.     $sql = "select p.products_image from " . TABLE_PRODUCTS . " p  where products_id='" . (int)$product_id . "'";
  610.     $look_up = $db->Execute($sql);
  611.  
  612.     return zen_image(DIR_WS_IMAGES . $look_up->fields['products_image'], zen_get_products_name($product_id), $width, $height);
  613.   }
  614.  
  615. /*
  616.  * look up whether a product is virtual
  617.  */
  618.   function zen_get_products_virtual($lookup) {
  619.     global $db;
  620.  
  621.     $sql = "select p.products_virtual from " . TABLE_PRODUCTS . " p  where p.products_id='" . (int)$lookup . "'";
  622.     $look_up = $db->Execute($sql);
  623.  
  624.     if ($look_up->fields['products_virtual'] == '1') {
  625.       return true;
  626.     } else {
  627.       return false;
  628.     }
  629.   }
  630.  
  631. /*
  632.  * Look up whether the given product ID is allowed to be added to cart, according to product-type switches set in Admin
  633.  */
  634.   function zen_get_products_allow_add_to_cart($lookup) {
  635.     global $db;
  636.  
  637.     $sql = "select products_type from " . TABLE_PRODUCTS . " where products_id='" . (int)$lookup . "'";
  638.     $type_lookup = $db->Execute($sql);
  639.  
  640.     $sql = "select allow_add_to_cart from " . TABLE_PRODUCT_TYPES . " where type_id = '" . (int)$type_lookup->fields['products_type'] . "'";
  641.     $allow_add_to_cart = $db->Execute($sql);
  642.  
  643.     return $allow_add_to_cart->fields['allow_add_to_cart'];
  644.   }
  645.  
  646. /*
  647.  * Look up SHOW_XXX_INFO switch for product ID and product type
  648.  */
  649.     function zen_get_show_product_switch_name($lookup, $field, $suffix= 'SHOW_', $prefix= '_INFO', $field_prefix= '_', $field_suffix='') {
  650.       global $db;
  651.  
  652.       $sql = "select products_type from " . TABLE_PRODUCTS . " where products_id='" . (int)$lookup . "'";
  653.       $type_lookup = $db->Execute($sql);
  654.  
  655.       $sql = "select type_handler from " . TABLE_PRODUCT_TYPES . " where type_id = '" . (int)$type_lookup->fields['products_type'] . "'";
  656.       $show_key = $db->Execute($sql);
  657.  
  658.  
  659.       $zv_key = strtoupper($suffix . $show_key->fields['type_handler'] . $prefix . $field_prefix . $field . $field_suffix);
  660.  
  661.       return $zv_key;
  662.     }
  663.  
  664. /*
  665.  * Look up SHOW_XXX_INFO switch for product ID and product type
  666.  */
  667.     function zen_get_show_product_switch($lookup, $field, $suffix= 'SHOW_', $prefix= '_INFO', $field_prefix= '_', $field_suffix='') {
  668.       global $db;
  669.  
  670.       $sql = "select products_type from " . TABLE_PRODUCTS . " where products_id='" . $lookup . "'";
  671.       $type_lookup = $db->Execute($sql);
  672.  
  673.       $sql = "select type_handler from " . TABLE_PRODUCT_TYPES . " where type_id = '" . $type_lookup->fields['products_type'] . "'";
  674.       $show_key = $db->Execute($sql);
  675.  
  676.  
  677.       $zv_key = strtoupper($suffix . $show_key->fields['type_handler'] . $prefix . $field_prefix . $field . $field_suffix);
  678.  
  679.       $sql = "select configuration_key, configuration_value from " . TABLE_PRODUCT_TYPE_LAYOUT . " where configuration_key='" . $zv_key . "'";
  680.       $zv_key_value = $db->Execute($sql);
  681.       if ($zv_key_value->RecordCount() > 0) {
  682.         return $zv_key_value->fields['configuration_value'];
  683.       } else {
  684.         $sql = "select configuration_key, configuration_value from " . TABLE_CONFIGURATION . " where configuration_key='" . $zv_key . "'";
  685.         $zv_key_value = $db->Execute($sql);
  686.         if ($zv_key_value->RecordCount() > 0) {
  687.           return $zv_key_value->fields['configuration_value'];
  688.         } else {
  689.           return false;
  690.         }
  691.       }
  692.     }
  693.  
  694. /*
  695.  *  Look up whether a product is always free shipping
  696.  */
  697.   function zen_get_product_is_always_free_shipping($lookup) {
  698.     global $db;
  699.  
  700.     $sql = "select p.product_is_always_free_shipping from " . TABLE_PRODUCTS . " p  where p.products_id='" . (int)$lookup . "'";
  701.     $look_up = $db->Execute($sql);
  702.  
  703.     if ($look_up->fields['product_is_always_free_shipping'] == '1') {
  704.       return true;
  705.     } else {
  706.       return false;
  707.     }
  708.   }
  709.  
  710. /*
  711.  *  stop regular behavior based on customer/store settings
  712.  *  Used to disable various activities if store is in an operating mode that should prevent those activities
  713.  */
  714.   function zen_run_normal() {
  715.     $zc_run = false;
  716.     switch (true) {
  717.       case (strstr(EXCLUDE_ADMIN_IP_FOR_MAINTENANCE, $_SERVER['REMOTE_ADDR'])):
  718.       // down for maintenance not for ADMIN
  719.         $zc_run = true;
  720.         break;
  721.       case (DOWN_FOR_MAINTENANCE == 'true'):
  722.       // down for maintenance
  723.         $zc_run = false;
  724.         break;
  725.       case (STORE_STATUS >= 1):
  726.       // showcase no prices
  727.         $zc_run = false;
  728.         break;
  729.       case (CUSTOMERS_APPROVAL == '1' and $_SESSION['customer_id'] == ''):
  730.       // customer must be logged in to browse
  731.         $zc_run = false;
  732.         break;
  733.       case (CUSTOMERS_APPROVAL == '2' and $_SESSION['customer_id'] == ''):
  734.       // show room only
  735.       // customer may browse but no prices
  736.         $zc_run = false;
  737.         break;
  738.       case (CUSTOMERS_APPROVAL == '3'):
  739.       // show room only
  740.         $zc_run = false;
  741.         break;
  742.       case (CUSTOMERS_APPROVAL_AUTHORIZATION != '0' and $_SESSION['customer_id'] == ''):
  743.       // customer must be logged in to browse
  744.         $zc_run = false;
  745.         break;
  746.       case (CUSTOMERS_APPROVAL_AUTHORIZATION != '0' and $_SESSION['customers_authorization'] > '0'):
  747.       // customer must be logged in to browse
  748.         $zc_run = false;
  749.         break;
  750.       default:
  751.       // proceed normally
  752.         $zc_run = true;
  753.         break;
  754.     }
  755.     return $zc_run;
  756.   }
  757.  
  758. /*
  759.  *  Look up whether to show prices, based on customer-authorization levels
  760.  */
  761.   function zen_check_show_prices() {
  762.     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) {
  763.       return true;
  764.     } else {
  765.       return false;
  766.     }
  767.   }
  768.  
  769. /*
  770.  * Return any field from products or products_description table
  771.  * Example: zen_products_lookup('3', 'products_date_added');
  772.  */
  773.   function zen_products_lookup($product_id, $what_field = 'products_name', $language = '') {
  774.     global $db;
  775.  
  776.     if (empty($language)) $language = $_SESSION['languages_id'];
  777.  
  778.     $product_lookup = $db->Execute("select " . $what_field . " as lookup_field
  779.                              from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd
  780.                              where p.products_id ='" . (int)$product_id . "'
  781.                              and pd.products_id = p.products_id
  782.                              and pd.language_id = '" . (int)$language . "'");
  783.  
  784.     $return_field = $product_lookup->fields['lookup_field'];
  785.  
  786.     return $return_field;
  787.   }
  788.  
  789. /*
  790.  * Return any field from categories or categories_description table
  791.  * Example: zen_categories_lookup('10', 'parent_id');
  792.  */
  793.   function zen_categories_lookup($categories_id, $what_field = 'categories_name', $language = '') {
  794.     global $db;
  795.  
  796.     if (empty($language)) $language = $_SESSION['languages_id'];
  797.  
  798.     $category_lookup = $db->Execute("select " . $what_field . " as lookup_field
  799.                              from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
  800.                              where c.categories_id ='" . (int)$categories_id . "'
  801.                              and c.categories_id = cd.categories_id
  802.                              and cd.language_id = '" . (int)$language . "'");
  803.  
  804.     $return_field = $category_lookup->fields['lookup_field'];
  805.  
  806.     return $return_field;
  807.   }
  808.  
  809. /*
  810.  * Find index_filters directory
  811.  * suitable for including template-specific immediate /modules files, such as:
  812.  * new_products, products_new_listing, featured_products, featured_products_listing, product_listing, specials_index, upcoming,
  813.  * products_all_listing, products_discount_prices, also_purchased_products
  814.  */
  815.   function zen_get_index_filters_directory($check_file, $dir_only = 'false') {
  816.     global $template_dir;
  817.  
  818.     $zv_filename = $check_file;
  819.     if (!strstr($zv_filename, '.php')) $zv_filename .= '.php';
  820.  
  821.     if (file_exists(DIR_WS_INCLUDES . 'index_filters/' . $template_dir . '/' . $zv_filename)) {
  822.       $template_dir_select = $template_dir . '/';
  823.     } else {
  824.       $template_dir_select = '';
  825.     }
  826.  
  827.     if (!file_exists(DIR_WS_INCLUDES . 'index_filters/' . $template_dir_select . '/' . $zv_filename)) {
  828.       $zv_filename = 'default';
  829.     }
  830.  
  831.     if ($dir_only == 'true') {
  832.       return 'index_filters/' . $template_dir_select;
  833.     } else {
  834.       return 'index_filters/' . $template_dir_select . $zv_filename;
  835.     }
  836.   }
  837.  
  838. ////
  839. // get define of New Products
  840.   function zen_get_products_new_timelimit($time_limit = false) {
  841.     if ($time_limit == false) {
  842.       $time_limit = SHOW_NEW_PRODUCTS_LIMIT;
  843.     }
  844.     switch (true) {
  845.       case ($time_limit == '0'):
  846.         $display_limit = '';
  847.         break;
  848.       case ($time_limit == '1'):
  849.         $display_limit = " and date_format(p.products_date_added, '%Y%m') >= date_format(now(), '%Y%m')";
  850.         break;
  851.       case ($time_limit == '7'):
  852.         $display_limit = ' and TO_DAYS(NOW()) - TO_DAYS(p.products_date_added) <= 7';
  853.         break;
  854.       case ($time_limit == '14'):
  855.         $display_limit = ' and TO_DAYS(NOW()) - TO_DAYS(p.products_date_added) <= 14';
  856.         break;
  857.       case ($time_limit == '30'):
  858.         $display_limit = ' and TO_DAYS(NOW()) - TO_DAYS(p.products_date_added) <= 30';
  859.         break;
  860.       case ($time_limit == '60'):
  861.         $display_limit = ' and TO_DAYS(NOW()) - TO_DAYS(p.products_date_added) <= 60';
  862.         break;
  863.       case ($time_limit == '90'):
  864.         $display_limit = ' and TO_DAYS(NOW()) - TO_DAYS(p.products_date_added) <= 90';
  865.         break;
  866.       case ($time_limit == '120'):
  867.         $display_limit = ' and TO_DAYS(NOW()) - TO_DAYS(p.products_date_added) <= 120';
  868.         break;
  869.     }
  870.     return $display_limit;
  871.   }
  872.  
  873. ////
  874. // check if Product is set to use downloads
  875. // does not validate download filename
  876.   function zen_has_product_attributes_downloads_status($products_id) {
  877.     global $db;
  878.     if (DOWNLOAD_ENABLED == 'true') {
  879.       $download_display_query_raw ="select pa.products_attributes_id, pad.products_attributes_filename
  880.                                    from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
  881.                                    where pa.products_id='" . (int)$products_id . "'
  882.                                      and pad.products_attributes_id= pa.products_attributes_id";
  883.  
  884.       $download_display = $db->Execute($download_display_query_raw);
  885.       if ($download_display->RecordCount() != 0) {
  886.         $valid_downloads = false;
  887.       } else {
  888.         $valid_downloads = true;
  889.       }
  890.     } else {
  891.       $valid_downloads = false;
  892.     }
  893.     return $valid_downloads;
  894.   }
  895.  
  896. // build date range for new products
  897.   function zen_get_new_date_range($time_limit = false) {
  898.     if ($time_limit == false) {
  899.       $time_limit = SHOW_NEW_PRODUCTS_LIMIT;
  900.     }
  901.     // 120 days; 24 hours; 60 mins; 60secs
  902.     $date_range = time() - ($time_limit * 24 * 60 * 60);
  903.     $upcoming_mask_range = time();
  904.     $upcoming_mask = date('Ymd', $upcoming_mask_range);
  905.  
  906. // echo 'Now:      '. date('Y-m-d') ."<br />";
  907. // echo $time_limit . ' Days: '. date('Ymd', $date_range) ."<br />";
  908.     $zc_new_date = date('Ymd', $date_range);
  909.     switch (true) {
  910.     case (SHOW_NEW_PRODUCTS_LIMIT == 0):
  911.       $new_range = '';
  912.       break;
  913.     case (SHOW_NEW_PRODUCTS_LIMIT == 1):
  914.       $zc_new_date = date('Ym', time()) . '01';
  915.       $new_range = ' and p.products_date_added >=' . $zc_new_date;
  916.       break;
  917.     default:
  918.       $new_range = ' and p.products_date_added >=' . $zc_new_date;
  919.     }
  920.  
  921.     if (SHOW_NEW_PRODUCTS_UPCOMING_MASKED == 0) {
  922.       // do nothing upcoming shows in new
  923.     } else {
  924.       // do not include upcoming in new
  925.       $new_range .= " and (p.products_date_available <=" . $upcoming_mask . " or p.products_date_available IS NULL)";
  926.     }
  927.     return $new_range;
  928.   }
  929.  
  930.  
  931. // build date range for upcoming products
  932.   function zen_get_upcoming_date_range() {
  933.     // 120 days; 24 hours; 60 mins; 60secs
  934.     $date_range = time();
  935.     $zc_new_date = date('Ymd', $date_range);
  936. // need to check speed on this for larger sites
  937. //    $new_range = ' and date_format(p.products_date_available, \'%Y%m%d\') >' . $zc_new_date;
  938.     $new_range = ' and p.products_date_available >' . $zc_new_date . '235959';
  939.  
  940.     return $new_range;
  941.   }
  942.  
  943. ?>


cron