[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_customers.php

Zen Cart 源代码 functions_customers.php




下载文件

文件名: functions_customers.php
文件类型: PHP文件
文件大小: 7.63 KiB
MD5: d25bb1942125a2bd2af90f6de29018ec

functions_customers.php - 关闭高亮
  1. <?php
  2. /**
  3.  * functions_customers
  4.  *
  5.  * @package functions
  6.  * @copyright Copyright 2003-2005 Zen Cart Development Team
  7.  * @copyright Portions Copyright 2003 osCommerce
  8.  * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  9.  * @version $Id: functions_customers.php 4793 2006-10-20 05:25:20Z ajeh $
  10.  */
  11.  
  12. ////
  13. // Returns the address_format_id for the given country
  14. // TABLES: countries;
  15.   function zen_get_address_format_id($country_id) {
  16.     global $db;
  17.     $address_format_query = "select address_format_id as format_id
  18.                             from " . TABLE_COUNTRIES . "
  19.                             where countries_id = '" . (int)$country_id . "'";
  20.  
  21.     $address_format = $db->Execute($address_format_query);
  22.  
  23.     if ($address_format->RecordCount() > 0) {
  24.       return $address_format->fields['format_id'];
  25.     } else {
  26.       return '1';
  27.     }
  28.   }
  29.  
  30. ////
  31. // Return a formatted address
  32. // TABLES: address_format
  33.   function zen_address_format($address_format_id, $address, $html, $boln, $eoln) {
  34.     global $db;
  35.     $address_format_query = "select address_format as format
  36.                             from " . TABLE_ADDRESS_FORMAT . "
  37.                             where address_format_id = '" . (int)$address_format_id . "'";
  38.  
  39.     $address_format = $db->Execute($address_format_query);
  40.     $company = zen_output_string_protected($address['company']);
  41.     if (isset($address['firstname']) && zen_not_null($address['firstname'])) {
  42.       $firstname = zen_output_string_protected($address['firstname']);
  43.       $lastname = zen_output_string_protected($address['lastname']);
  44.     } elseif (isset($address['name']) && zen_not_null($address['name'])) {
  45.       $firstname = zen_output_string_protected($address['name']);
  46.       $lastname = '';
  47.     } else {
  48.       $firstname = '';
  49.       $lastname = '';
  50.     }
  51.     $street = zen_output_string_protected($address['street_address']);
  52.     $suburb = zen_output_string_protected($address['suburb']);
  53.     $city = zen_output_string_protected($address['city']);
  54.     $state = zen_output_string_protected($address['state']);
  55.     if (isset($address['country_id']) && zen_not_null($address['country_id'])) {
  56.       $country = zen_get_country_name($address['country_id']);
  57.  
  58.       if (isset($address['zone_id']) && zen_not_null($address['zone_id'])) {
  59.         $state = zen_get_zone_code($address['country_id'], $address['zone_id'], $state);
  60.       }
  61.     } elseif (isset($address['country']) && zen_not_null($address['country'])) {
  62.       if (is_array($address['country'])) {
  63.         $country = zen_output_string_protected($address['country']['countries_name']);
  64.       } else {
  65.       $country = zen_output_string_protected($address['country']);
  66.       }
  67.     } else {
  68.       $country = '';
  69.     }
  70.     $postcode = zen_output_string_protected($address['postcode']);
  71.     $zip = $postcode;
  72.  
  73.     if ($html) {
  74. // HTML Mode
  75.       $HR = '<hr />';
  76.       $hr = '<hr />';
  77.       if ( ($boln == '') && ($eoln == "\n") ) { // Values not specified, use rational defaults
  78.         $CR = '<br />';
  79.         $cr = '<br />';
  80.         $eoln = $cr;
  81.       } else { // Use values supplied
  82.         $CR = $eoln . $boln;
  83.         $cr = $CR;
  84.       }
  85.     } else {
  86. // Text Mode
  87.       $CR = $eoln;
  88.       $cr = $CR;
  89.       $HR = '----------------------------------------';
  90.       $hr = '----------------------------------------';
  91.     }
  92.  
  93.     $statecomma = '';
  94.     $streets = $street;
  95.     if ($suburb != '') $streets = $street . $cr . $suburb;
  96.     if ($country == '') {
  97.       if (is_array($address['country'])) {
  98.         $country = zen_output_string_protected($address['country']['countries_name']);
  99.       } else {
  100.       $country = zen_output_string_protected($address['country']);
  101.       }
  102.     }
  103.     if ($state != '') $statecomma = $state . ', ';
  104.  
  105.     $fmt = $address_format->fields['format'];
  106.     eval("\$address_out = \"$fmt\";");
  107.  
  108.     if ( (ACCOUNT_COMPANY == 'true') && (zen_not_null($company)) ) {
  109.       $address_out = $company . $cr . $address_out;
  110.     }
  111.  
  112.     return $address_out;
  113.   }
  114.  
  115. ////
  116. // Return a formatted address
  117. // TABLES: customers, address_book
  118.   function zen_address_label($customers_id, $address_id = 1, $html = false, $boln = '', $eoln = "\n") {
  119.     global $db;
  120.     $address_query = "select entry_firstname as firstname, entry_lastname as lastname,
  121.                             entry_company as company, entry_street_address as street_address,
  122.                             entry_suburb as suburb, entry_city as city, entry_postcode as postcode,
  123.                             entry_state as state, entry_zone_id as zone_id,
  124.                             entry_country_id as country_id
  125.                      from " . TABLE_ADDRESS_BOOK . "
  126.                      where customers_id = '" . (int)$customers_id . "'
  127.                      and address_book_id = '" . (int)$address_id . "'";
  128.  
  129.     $address = $db->Execute($address_query);
  130.  
  131.     $format_id = zen_get_address_format_id($address->fields['country_id']);
  132.     return zen_address_format($format_id, $address->fields, $html, $boln, $eoln);
  133.   }
  134.  
  135. ////
  136. // Return a customer greeting
  137.   function zen_customer_greeting() {
  138.  
  139.     if (isset($_SESSION['customer_id']) && $_SESSION['customer_first_name']) {
  140.       $greeting_string = sprintf(TEXT_GREETING_PERSONAL, zen_output_string_protected($_SESSION['customer_first_name']), zen_href_link(FILENAME_PRODUCTS_NEW));
  141.     } else {
  142.       $greeting_string = sprintf(TEXT_GREETING_GUEST, zen_href_link(FILENAME_LOGIN, '', 'SSL'), zen_href_link(FILENAME_CREATE_ACCOUNT, '', 'SSL'));
  143.     }
  144.  
  145.     return $greeting_string;
  146.   }
  147.  
  148.   function zen_count_customer_orders($id = '', $check_session = true) {
  149.     global $db;
  150.  
  151.     if (is_numeric($id) == false) {
  152.       if ($_SESSION['customer_id']) {
  153.         $id = $_SESSION['customer_id'];
  154.       } else {
  155.         return 0;
  156.       }
  157.     }
  158.  
  159.     if ($check_session == true) {
  160.       if ( ($_SESSION['customer_id'] == false) || ($id != $_SESSION['customer_id']) ) {
  161.         return 0;
  162.       }
  163.     }
  164.  
  165.     $orders_check_query = "select count(*) as total
  166.                           from " . TABLE_ORDERS . "
  167.                           where customers_id = '" . (int)$id . "'";
  168.  
  169.     $orders_check = $db->Execute($orders_check_query);
  170.  
  171.     return $orders_check->fields['total'];
  172.   }
  173.  
  174.   function zen_count_customer_address_book_entries($id = '', $check_session = true) {
  175.     global $db;
  176.  
  177.     if (is_numeric($id) == false) {
  178.       if ($_SESSION['customer_id']) {
  179.         $id = $_SESSION['customer_id'];
  180.       } else {
  181.         return 0;
  182.       }
  183.     }
  184.  
  185.     if ($check_session == true) {
  186.       if ( ($_SESSION['customer_id'] == false) || ($id != $_SESSION['customer_id']) ) {
  187.         return 0;
  188.       }
  189.     }
  190.  
  191.     $addresses_query = "select count(*) as total
  192.                        from " . TABLE_ADDRESS_BOOK . "
  193.                        where customers_id = '" . (int)$id . "'";
  194.  
  195.     $addresses = $db->Execute($addresses_query);
  196.  
  197.     return $addresses->fields['total'];
  198.   }
  199.  
  200. ////
  201. // validate customer matches session
  202.   function zen_get_customer_validate_session($customer_id) {
  203.     global $db, $messageStack;
  204.     $zc_check_customer = $db->Execute("SELECT customers_id from " . TABLE_CUSTOMERS . " WHERE customers_id=" . (int)$customer_id);
  205.     if ($zc_check_customer->RecordCount() <= 0) {
  206.       $db->Execute("DELETE from " . TABLE_CUSTOMERS_BASKET . " WHERE customers_id= " . $customer_id);
  207.       $db->Execute("DELETE from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " WHERE customers_id= " . $customer_id);
  208.       unset($_SESSION['customer_id']);
  209.       $messageStack->add_session('header', ERROR_CUSTOMERS_ID_INVALID, 'error');
  210.       return false;
  211.     }
  212.     return true;
  213.   }
  214. ?>