[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/ -> checkout_shipping_address.php (source)

   1  <?php
   2  /*

   3  $Id: checkout_shipping_address.php 3 2006-05-27 04:59:07Z user $

   4  

   5    osCMax Power E-Commerce

   6    http://oscdox.com

   7  

   8    Copyright 2006 osCMax

   9  

  10    Released under the GNU General Public License

  11  */
  12  
  13  // Most of this file is changed or moved to BTS - Basic Template System - format.

  14  // For adding in contribution or modification - parts of this file has been moved to: catalog\templates\fallback\contents\<filename>.tpl.php as a default (sub 'fallback' with your current template to see if there is a template specife change).

  15  //       catalog\templates\fallback\contents\<filename>.tpl.php as a default (sub 'fallback' with your current template to see if there is a template specife change).

  16  // (Sub 'fallback' with your current template to see if there is a template specific file.)

  17  
  18  
  19    require ('includes/application_top.php');
  20  
  21  // if the customer is not logged on, redirect them to the login page

  22    if (!tep_session_is_registered('customer_id')) {
  23      $navigation->set_snapshot();
  24      tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
  25    }
  26  
  27  // if there is nothing in the customers cart, redirect them to the shopping cart page

  28    if ($cart->count_contents() < 1) {
  29      tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
  30    }
  31  
  32    // needs to be included earlier to set the success message in the messageStack

  33    require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_CHECKOUT_SHIPPING_ADDRESS);
  34  
  35    require (DIR_WS_CLASSES . 'order.php');
  36    $order = new order;
  37  
  38  // if the order contains only virtual products, forward the customer to the billing page as

  39  // a shipping address is not needed

  40    if ($order->content_type == 'virtual') {
  41      if (!tep_session_is_registered('shipping')) tep_session_register('shipping');
  42      $shipping = false;
  43      if (!tep_session_is_registered('sendto')) tep_session_register('sendto');
  44      $sendto = false;
  45      tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
  46    }
  47  
  48    $error = false;
  49    $process = false;
  50    if (isset($HTTP_POST_VARS['action']) && ($HTTP_POST_VARS['action'] == 'submit')) {
  51  // process a new shipping address

  52      if (tep_not_null($HTTP_POST_VARS['firstname']) && tep_not_null($HTTP_POST_VARS['lastname']) && tep_not_null($HTTP_POST_VARS['street_address'])) {
  53        $process = true;
  54  
  55        if (ACCOUNT_GENDER == 'true') $gender = tep_db_prepare_input($HTTP_POST_VARS['gender']);
  56        if (ACCOUNT_COMPANY == 'true') $company = tep_db_prepare_input($HTTP_POST_VARS['company']);
  57        $firstname = tep_db_prepare_input($HTTP_POST_VARS['firstname']);
  58        $lastname = tep_db_prepare_input($HTTP_POST_VARS['lastname']);
  59        $street_address = tep_db_prepare_input($HTTP_POST_VARS['street_address']);
  60        if (ACCOUNT_SUBURB == 'true') $suburb = tep_db_prepare_input($HTTP_POST_VARS['suburb']);
  61        $postcode = tep_db_prepare_input($HTTP_POST_VARS['postcode']);
  62        $city = tep_db_prepare_input($HTTP_POST_VARS['city']);
  63        $country = tep_db_prepare_input($HTTP_POST_VARS['country']);
  64        if (ACCOUNT_STATE == 'true') {
  65          if (isset($HTTP_POST_VARS['zone_id'])) {
  66            $zone_id = tep_db_prepare_input($HTTP_POST_VARS['zone_id']);
  67          } else {
  68            $zone_id = false;
  69          }
  70          $state = tep_db_prepare_input($HTTP_POST_VARS['state']);
  71        }
  72  
  73        if (ACCOUNT_GENDER == 'true') {
  74          if ( ($gender != 'm') && ($gender != 'f') ) {
  75            $error = true;
  76  
  77            $messageStack->add('checkout_address', ENTRY_GENDER_ERROR);
  78          }
  79        }
  80  
  81        if (strlen($firstname) < ENTRY_FIRST_NAME_MIN_LENGTH) {
  82          $error = true;
  83  
  84          $messageStack->add('checkout_address', ENTRY_FIRST_NAME_ERROR);
  85        }
  86  
  87        if (strlen($lastname) < ENTRY_LAST_NAME_MIN_LENGTH) {
  88          $error = true;
  89  
  90          $messageStack->add('checkout_address', ENTRY_LAST_NAME_ERROR);
  91        }
  92  
  93        if (strlen($street_address) < ENTRY_STREET_ADDRESS_MIN_LENGTH) {
  94          $error = true;
  95  
  96          $messageStack->add('checkout_address', ENTRY_STREET_ADDRESS_ERROR);
  97        }
  98  
  99        if (strlen($postcode) < ENTRY_POSTCODE_MIN_LENGTH) {
 100          $error = true;
 101  
 102          $messageStack->add('checkout_address', ENTRY_POST_CODE_ERROR);
 103        }
 104  
 105        if (strlen($city) < ENTRY_CITY_MIN_LENGTH) {
 106          $error = true;
 107  
 108          $messageStack->add('checkout_address', ENTRY_CITY_ERROR);
 109        }
 110  
 111        if (ACCOUNT_STATE == 'true') {
 112          $zone_id = 0;
 113          $check_query = tep_db_query("select count(*) as total from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country . "'");
 114          $check = tep_db_fetch_array($check_query);
 115          $entry_state_has_zones = ($check['total'] > 0);
 116          if ($entry_state_has_zones == true) {
 117            $zone_query = tep_db_query("select distinct zone_id from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country . "' and (zone_name like '" . tep_db_input($state) . "%' or zone_code like '%" . tep_db_input($state) . "%')");
 118            if (tep_db_num_rows($zone_query) == 1) {
 119              $zone = tep_db_fetch_array($zone_query);
 120              $zone_id = $zone['zone_id'];
 121            } else {
 122              $error = true;
 123  
 124              $messageStack->add('checkout_address', ENTRY_STATE_ERROR_SELECT);
 125            }
 126          } else {
 127            if (strlen($state) < ENTRY_STATE_MIN_LENGTH) {
 128              $error = true;
 129  
 130              $messageStack->add('checkout_address', ENTRY_STATE_ERROR);
 131            }
 132          }
 133        }
 134  
 135        if ( (is_numeric($country) == false) || ($country < 1) ) {
 136          $error = true;
 137  
 138          $messageStack->add('checkout_address', ENTRY_COUNTRY_ERROR);
 139        }
 140  
 141        if ($error == false) {
 142          $sql_data_array = array('customers_id' => $customer_id,
 143                                  'entry_firstname' => $firstname,
 144                                  'entry_lastname' => $lastname,
 145                                  'entry_street_address' => $street_address,
 146                                  'entry_postcode' => $postcode,
 147                                  'entry_city' => $city,
 148                                  'entry_country_id' => $country);
 149  
 150          if (ACCOUNT_GENDER == 'true') $sql_data_array['entry_gender'] = $gender;
 151          if (ACCOUNT_COMPANY == 'true') $sql_data_array['entry_company'] = $company;
 152          if (ACCOUNT_SUBURB == 'true') $sql_data_array['entry_suburb'] = $suburb;
 153          if (ACCOUNT_STATE == 'true') {
 154            if ($zone_id > 0) {
 155              $sql_data_array['entry_zone_id'] = $zone_id;
 156              $sql_data_array['entry_state'] = '';
 157            } else {
 158              $sql_data_array['entry_zone_id'] = '0';
 159              $sql_data_array['entry_state'] = $state;
 160            }
 161          }
 162  
 163          if (!tep_session_is_registered('sendto')) tep_session_register('sendto');
 164  
 165          tep_db_perform(TABLE_ADDRESS_BOOK, $sql_data_array);
 166  
 167          $sendto = tep_db_insert_id();
 168  
 169          if (tep_session_is_registered('shipping')) tep_session_unregister('shipping');
 170  
 171          tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
 172        }
 173  // process the selected shipping destination

 174      } elseif (isset($HTTP_POST_VARS['address'])) {
 175        $reset_shipping = false;
 176        if (tep_session_is_registered('sendto')) {
 177          if ($sendto != $HTTP_POST_VARS['address']) {
 178            if (tep_session_is_registered('shipping')) {
 179              $reset_shipping = true;
 180            }
 181          }
 182        } else {
 183          tep_session_register('sendto');
 184        }
 185  
 186        $sendto = $HTTP_POST_VARS['address'];
 187  
 188        $check_address_query = tep_db_query("select count(*) as total from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customer_id . "' and address_book_id = '" . (int)$sendto . "'");
 189        $check_address = tep_db_fetch_array($check_address_query);
 190  
 191        if ($check_address['total'] == '1') {
 192          if ($reset_shipping == true) tep_session_unregister('shipping');
 193          tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
 194        } else {
 195          tep_session_unregister('sendto');
 196        }
 197      } else {
 198        if (!tep_session_is_registered('sendto')) tep_session_register('sendto');
 199        $sendto = $customer_default_address_id;
 200  
 201        tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
 202      }
 203    }
 204  // BOF: MOD - Country-State Selector

 205    if (isset($HTTP_POST_VARS['action']) && ($HTTP_POST_VARS['action'] == 'refresh')) {
 206        if (ACCOUNT_GENDER == 'true') $gender = tep_db_prepare_input($HTTP_POST_VARS['gender']);
 207        if (ACCOUNT_COMPANY == 'true') $company = tep_db_prepare_input($HTTP_POST_VARS['company']);
 208        $firstname = tep_db_prepare_input($HTTP_POST_VARS['firstname']);
 209        $lastname = tep_db_prepare_input($HTTP_POST_VARS['lastname']);
 210        $street_address = tep_db_prepare_input($HTTP_POST_VARS['street_address']);
 211        if (ACCOUNT_SUBURB == 'true') $suburb = tep_db_prepare_input($HTTP_POST_VARS['suburb']);
 212        $postcode = tep_db_prepare_input($HTTP_POST_VARS['postcode']);
 213        $city = tep_db_prepare_input($HTTP_POST_VARS['city']);
 214        $country = tep_db_prepare_input($HTTP_POST_VARS['country']);
 215        if (ACCOUNT_STATE == 'true') {
 216          if (isset($HTTP_POST_VARS['zone_id'])) {
 217            $zone_id = tep_db_prepare_input($HTTP_POST_VARS['zone_id']);
 218          } else {
 219            $zone_id = false;
 220          }
 221          $state = tep_db_prepare_input($HTTP_POST_VARS['state']);
 222        }
 223  
 224    } else
 225  // EOF: MOD - Country-State Selector

 226  // if no shipping destination address was selected, use their own address as default

 227    if (!tep_session_is_registered('sendto')) {
 228      $sendto = $customer_default_address_id;
 229    }
 230  // LINE ADDED: MOD - Country-State Selector

 231    if (!isset($country)){$country = DEFAULT_COUNTRY;}
 232  
 233    $breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
 234    $breadcrumb->add(NAVBAR_TITLE_2, tep_href_link(FILENAME_CHECKOUT_SHIPPING_ADDRESS, '', 'SSL'));
 235  
 236    $addresses_count = tep_count_customer_address_book_entries();
 237  
 238    $content = CONTENT_CHECKOUT_SHIPPING_ADDRESS;
 239    $javascript = $content . '.js.php';
 240  
 241    include (bts_select('main', $content_template)); // BTSv1.5

 242  
 243    require (DIR_WS_INCLUDES . 'application_bottom.php');
 244  ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7