[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 源代码 checkout_new_address.php

Zen Cart 源代码 checkout_new_address.php




下载文件

文件名: checkout_new_address.php
文件类型: PHP文件
文件大小: 10.85 KiB
MD5: 779f49728237065c7382ce3195a1f8eb

checkout_new_address.php - 关闭高亮
  1. <?php
  2. /**
  3.  * checkout_new_address.php
  4.  *
  5.  * @package modules
  6.  * @copyright Copyright 2003-2007 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: checkout_new_address.php 6772 2007-08-21 12:33:29Z drbyte $
  10.  */
  11. // This should be first line of the script:
  12. $zco_notifier->notify('NOTIFY_MODULE_START_CHECKOUT_NEW_ADDRESS');
  13.  
  14. if (!defined('IS_ADMIN_FLAG')) {
  15.   die('Illegal Access');
  16. }
  17. /**
  18.  * Set some defaults
  19.  */
  20.   $process = false;
  21.   $zone_name = '';
  22.   $entry_state_has_zones = '';
  23.   $error_state_input = false;
  24.   $state = '';
  25.   $zone_id = 0;
  26.   $error = false;
  27.  
  28. if (isset($_POST['action']) && ($_POST['action'] == 'submit')) {
  29.   // process a new address
  30.   if (zen_not_null($_POST['firstname']) && zen_not_null($_POST['lastname']) && zen_not_null($_POST['street_address'])) {
  31.     $process = true;
  32.     if (ACCOUNT_GENDER == 'true') $gender = zen_db_prepare_input($_POST['gender']);
  33.     if (ACCOUNT_COMPANY == 'true') $company = zen_db_prepare_input($_POST['company']);
  34.     $firstname = zen_db_prepare_input($_POST['firstname']);
  35.     $lastname = zen_db_prepare_input($_POST['lastname']);
  36.     $street_address = zen_db_prepare_input($_POST['street_address']);
  37.     if (ACCOUNT_SUBURB == 'true') $suburb = zen_db_prepare_input($_POST['suburb']);
  38.     $postcode = zen_db_prepare_input($_POST['postcode']);
  39.     $city = zen_db_prepare_input($_POST['city']);
  40.     if (ACCOUNT_STATE == 'true') {
  41.       $state = zen_db_prepare_input($_POST['state']);
  42.       if (isset($_POST['zone_id'])) {
  43.         $zone_id = zen_db_prepare_input($_POST['zone_id']);
  44.       } else {
  45.         $zone_id = false;
  46.       }
  47.     }
  48.     $country = zen_db_prepare_input($_POST['zone_country_id']);
  49. //echo ' I SEE: country=' . $country . '&nbsp;&nbsp;&nbsp;state=' . $state . '&nbsp;&nbsp;&nbsp;zone_id=' . $zone_id;
  50.     if (ACCOUNT_GENDER == 'true') {
  51.       if ( ($gender != 'm') && ($gender != 'f') ) {
  52.         $error = true;
  53.         $messageStack->add('checkout_address', ENTRY_GENDER_ERROR);
  54.       }
  55.     }
  56.  
  57.     if (strlen($firstname) < ENTRY_FIRST_NAME_MIN_LENGTH) {
  58.       $error = true;
  59.       $messageStack->add('checkout_address', ENTRY_FIRST_NAME_ERROR);
  60.     }
  61.  
  62.     if (strlen($lastname) < ENTRY_LAST_NAME_MIN_LENGTH) {
  63.       $error = true;
  64.       $messageStack->add('checkout_address', ENTRY_LAST_NAME_ERROR);
  65.     }
  66.  
  67.     if (strlen($street_address) < ENTRY_STREET_ADDRESS_MIN_LENGTH) {
  68.       $error = true;
  69.       $messageStack->add('checkout_address', ENTRY_STREET_ADDRESS_ERROR);
  70.     }
  71.  
  72.     if (strlen($city) < ENTRY_CITY_MIN_LENGTH) {
  73.       $error = true;
  74.       $messageStack->add('checkout_address', ENTRY_CITY_ERROR);
  75.     }
  76.  
  77.     if (ACCOUNT_STATE == 'true') {
  78.       $check_query = "SELECT count(*) AS total
  79.                      FROM " . TABLE_ZONES . "
  80.                      WHERE zone_country_id = :zoneCountryID";
  81.       $check_query = $db->bindVars($check_query, ':zoneCountryID', $country, 'integer');
  82.       $check = $db->Execute($check_query);
  83.       $entry_state_has_zones = ($check->fields['total'] > 0);
  84.       if ($entry_state_has_zones == true) {
  85.       $zone_query = "SELECT distinct zone_id, zone_name, zone_code
  86.                       FROM " . TABLE_ZONES . "
  87.                       WHERE zone_country_id = :zoneCountryID
  88.                       AND " .
  89.                      ((trim($state) != '' && $zone_id == 0) ? "(upper(zone_name) like ':zoneState%' OR upper(zone_code) like '%:zoneState%') OR " : "") .
  90.                       "zone_id = :zoneID
  91.                       ORDER BY zone_code ASC, zone_name";
  92.  
  93.         $zone_query = $db->bindVars($zone_query, ':zoneCountryID', $country, 'integer');
  94.         $zone_query = $db->bindVars($zone_query, ':zoneState', strtoupper($state), 'noquotestring');
  95.         $zone_query = $db->bindVars($zone_query, ':zoneID', $zone_id, 'integer');
  96.         $zone = $db->Execute($zone_query);
  97.  
  98.       //look for an exact match on zone ISO code
  99.       $found_exact_iso_match = ($zone->RecordCount() == 1);
  100.       if ($zone->RecordCount() > 1) {
  101.         while (!$zone->EOF && !$found_exact_iso_match) {
  102.           if (strtoupper($zone->fields['zone_code']) == strtoupper($state) ) {
  103.             $found_exact_iso_match = true;
  104.             continue;
  105.           }
  106.           $zone->MoveNext();
  107.         }
  108.       }
  109.  
  110.       if ($found_exact_iso_match) {
  111.         $zone_id = $zone->fields['zone_id'];
  112.         $zone_name = $zone->fields['zone_name'];
  113.       } else {
  114.         $error = true;
  115.         $error_state_input = true;
  116.         $messageStack->add('checkout_address', ENTRY_STATE_ERROR_SELECT);
  117.       }
  118.     } else {
  119.       if (strlen($state) < ENTRY_STATE_MIN_LENGTH) {
  120.         $error = true;
  121.         $error_state_input = true;
  122.         $messageStack->add('checkout_address', ENTRY_STATE_ERROR);
  123.       }
  124.     }
  125.   }
  126.  
  127.     if (strlen($postcode) < ENTRY_POSTCODE_MIN_LENGTH) {
  128.       $error = true;
  129.       $messageStack->add('checkout_address', ENTRY_POST_CODE_ERROR);
  130.     }
  131.  
  132.     if ( (is_numeric($country) == false) || ($country < 1) ) {
  133.       $error = true;
  134.       $messageStack->add('checkout_address', ENTRY_COUNTRY_ERROR);
  135.     }
  136.  
  137.     if ($error == false) {
  138.       $sql_data_array = array(array('fieldName'=>'customers_id', 'value'=>$_SESSION['customer_id'], 'type'=>'integer'),
  139.                               array('fieldName'=>'entry_firstname', 'value'=>$firstname, 'type'=>'string'),
  140.                               array('fieldName'=>'entry_lastname','value'=>$lastname, 'type'=>'string'),
  141.                               array('fieldName'=>'entry_street_address','value'=>$street_address, 'type'=>'string'),
  142.                               array('fieldName'=>'entry_postcode', 'value'=>$postcode, 'type'=>'string'),
  143.                               array('fieldName'=>'entry_city', 'value'=>$city, 'type'=>'string'),
  144.                               array('fieldName'=>'entry_country_id', 'value'=>$country, 'type'=>'integer')
  145.       );
  146.  
  147.       if (ACCOUNT_GENDER == 'true') $sql_data_array[] = array('fieldName'=>'entry_gender', 'value'=>$gender, 'type'=>'enum:m|f');
  148.       if (ACCOUNT_COMPANY == 'true') $sql_data_array[] = array('fieldName'=>'entry_company', 'value'=>$company, 'type'=>'string');
  149.       if (ACCOUNT_SUBURB == 'true') $sql_data_array[] = array('fieldName'=>'entry_suburb', 'value'=>$suburb, 'type'=>'string');
  150.       if (ACCOUNT_STATE == 'true') {
  151.         if ($zone_id > 0) {
  152.           $sql_data_array[] = array('fieldName'=>'entry_zone_id', 'value'=>$zone_id, 'type'=>'integer');
  153.           $sql_data_array[] = array('fieldName'=>'entry_state', 'value'=>'', 'type'=>'string');
  154.         } else {
  155.           $sql_data_array[] = array('fieldName'=>'entry_zone_id', 'value'=>0, 'type'=>'integer');
  156.           $sql_data_array[] = array('fieldName'=>'entry_state', 'value'=>$state, 'type'=>'string');
  157.         }
  158.       }
  159.       $db->perform(TABLE_ADDRESS_BOOK, $sql_data_array);
  160.       $zco_notifier->notify('NOTIFY_MODULE_CHECKOUT_ADDED_ADDRESS_BOOK_RECORD', array_merge(array('address_id' => $db->Insert_ID() ), $sql_data_array));
  161.       switch($addressType) {
  162.         case 'billto':
  163.         $_SESSION['billto'] = $db->Insert_ID();
  164.         $_SESSION['payment'] = '';
  165.         zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
  166.         break;
  167.         case 'shipto':
  168.         $_SESSION['sendto'] = $db->Insert_ID();
  169.         $_SESSION['shipping'] = '';
  170.         zen_redirect(zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
  171.         break;
  172.       }
  173.     }
  174.   } elseif (isset($_POST['address'])) {
  175.     switch($addressType) {
  176.       case 'billto':
  177.       $reset_payment = false;
  178.       if ($_SESSION['billto']) {
  179.         if ($_SESSION['billto'] != $_POST['address']) {
  180.           if ($_SESSION['payment']) {
  181.             $reset_payment = true;
  182.           }
  183.         }
  184.       }
  185.       $_SESSION['billto'] = $_POST['address'];
  186.  
  187.       $check_address_query = "SELECT count(*) AS total
  188.                              FROM " . TABLE_ADDRESS_BOOK . "
  189.                              WHERE customers_id = :customersID
  190.                              AND address_book_id = :addressBookID";
  191.  
  192.       $check_address_query = $db->bindVars($check_address_query, ':customersID', $_SESSION['customer_id'], 'integer');
  193.       $check_address_query = $db->bindVars($check_address_query, ':addressBookID', $_SESSION['billto'], 'integer');
  194.       $check_address = $db->Execute($check_address_query);
  195.  
  196.       if ($check_address->fields['total'] == '1') {
  197.         if ($reset_payment == true) $_SESSION['payment'] = '';
  198.         zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
  199.       } else {
  200.         $_SESSION['billto'] = '';
  201.       }
  202.       // no addresses to select from - customer decided to keep the current assigned address
  203.       break;
  204.       case 'shipto':
  205.       $reset_shipping = false;
  206.       if ($_SESSION['sendto']) {
  207.         if ($_SESSION['sendto'] != $_POST['address']) {
  208.           if ($_SESSION['shipping']) {
  209.             $reset_shipping = true;
  210.           }
  211.         }
  212.       }
  213.      $_SESSION['sendto'] = $_POST['address'];
  214.       $check_address_query = "SELECT count(*) AS total
  215.                              FROM " . TABLE_ADDRESS_BOOK . "
  216.                              WHERE customers_id = :customersID
  217.                              AND address_book_id = :addressBookID";
  218.  
  219.       $check_address_query = $db->bindVars($check_address_query, ':customersID', $_SESSION['customer_id'], 'integer');
  220.       $check_address_query = $db->bindVars($check_address_query, ':addressBookID', $_SESSION['sendto'], 'integer');
  221.       $check_address = $db->Execute($check_address_query);
  222.       if ($check_address->fields['total'] == '1') {
  223.         if ($reset_shipping == true) $_SESSION['shipping'] = '';
  224.         zen_redirect(zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
  225.       } else {
  226.         $_SESSION['sendto'] = '';
  227.       }
  228.       break;
  229.     }
  230.   } else {
  231.     switch($addressType) {
  232.       case 'billto':
  233.       $_SESSION['billto'] = $_SESSION['customer_default_address_id'];
  234.       zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
  235.       break;
  236.       case 'shipto':
  237.       $_SESSION['sendto'] = $_SESSION['customer_default_address_id'];
  238.       zen_redirect(zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
  239.       break;
  240.     }
  241.   }
  242. }
  243.  
  244.  
  245. /*
  246.  * Set flags for template use:
  247.  */
  248.   $selected_country = (isset($_POST['zone_country_id']) && $_POST['zone_country_id'] != '') ? $country : SHOW_CREATE_ACCOUNT_DEFAULT_COUNTRY;
  249.   $flag_show_pulldown_states = ((($process == true || $entry_state_has_zones == true) && $zone_name == '') || ACCOUNT_STATE_DRAW_INITIAL_DROPDOWN == 'true' || $error_state_input) ? true : false;
  250.   $state = ($flag_show_pulldown_states) ? $state : $zone_name;
  251.   $state_field_label = ($flag_show_pulldown_states) ? '' : ENTRY_STATE;
  252.  
  253. // This should be last line of the script:
  254. $zco_notifier->notify('NOTIFY_MODULE_END_CHECKOUT_NEW_ADDRESS');
  255. ?>