Advertisement
Guest User

Untitled

a guest
May 29th, 2014
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3.   $Id$
  4.  
  5.   osCommerce, Open Source E-Commerce Solutions
  6.   http://www.oscommerce.com
  7.  
  8.   Copyright (c) 2014 osCommerce
  9.  
  10.   Released under the GNU General Public License
  11. */
  12.  
  13.   require('includes/application_top.php');
  14.   require('includes/classes/http_client.php');
  15.  
  16. // if the customer is not logged on, redirect them to the login page
  17.   if (!tep_session_is_registered('customer_id')) {
  18.     $navigation->set_snapshot();
  19.     tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
  20.   }
  21.  
  22. // if there is nothing in the customers cart, redirect them to the shopping cart page
  23.   if ($cart->count_contents() < 1) {
  24.     tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
  25.   }
  26.  
  27. // if no shipping destination address was selected, use the customers own address as default
  28.   if (!tep_session_is_registered('sendto')) {
  29.     tep_session_register('sendto');
  30.     $sendto = $customer_default_address_id;
  31.   } else {
  32. // verify the selected shipping address
  33.     if ( (is_array($sendto) && empty($sendto)) || is_numeric($sendto) ) {
  34.       $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 . "'");
  35.       $check_address = tep_db_fetch_array($check_address_query);
  36.  
  37.       if ($check_address['total'] != '1') {
  38.         $sendto = $customer_default_address_id;
  39.         if (tep_session_is_registered('shipping')) tep_session_unregister('shipping');
  40.       }
  41.     }
  42.   }
  43.  
  44.   require(DIR_WS_CLASSES . 'order.php');
  45.   $order = new order;
  46.  
  47. // register a random ID in the session to check throughout the checkout procedure
  48. // against alterations in the shopping cart contents
  49.   if (!tep_session_is_registered('cartID')) {
  50.     tep_session_register('cartID');
  51.   } elseif (($cartID != $cart->cartID) && tep_session_is_registered('shipping')) {
  52.     tep_session_unregister('shipping');
  53.   }
  54.  
  55.   $cartID = $cart->cartID = $cart->generate_cart_id();
  56.  
  57. // if the order contains only virtual products, forward the customer to the billing page as
  58. // a shipping address is not needed
  59.   if ($order->content_type == 'virtual') {
  60.     if (!tep_session_is_registered('shipping')) tep_session_register('shipping');
  61.     $shipping = false;
  62.     $sendto = false;
  63.     tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
  64.   }
  65.  
  66.   $total_weight = $cart->show_weight();
  67.   $total_count = $cart->count_contents();
  68.  
  69. // load all enabled shipping modules
  70.   require(DIR_WS_CLASSES . 'shipping.php');
  71.   $shipping_modules = new shipping;
  72.  
  73.   if ( defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING') && (MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') ) {
  74.     $pass = false;
  75.  
  76.     switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION) {
  77.       case 'national':
  78.         if ($order->delivery['country_id'] == STORE_COUNTRY) {
  79.           $pass = true;
  80.         }
  81.         break;
  82.       case 'international':
  83.         if ($order->delivery['country_id'] != STORE_COUNTRY) {
  84.           $pass = true;
  85.         }
  86.         break;
  87.       case 'both':
  88.         $pass = true;
  89.         break;
  90.     }
  91.  
  92.     $free_shipping = false;
  93.  
  94.     if ( ($pass == true) && ($order->info['total'] >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) ) {
  95.       $free_shipping = true;
  96.  
  97.       include(DIR_WS_LANGUAGES . $language . '/modules/order_total/ot_shipping.php');
  98.     }
  99.   } else {
  100.     $free_shipping = false;
  101.   }
  102.  
  103. // process the selected shipping method
  104.   if ( isset($HTTP_POST_VARS['action']) && ($HTTP_POST_VARS['action'] == 'process') && isset($HTTP_POST_VARS['formid']) && ($HTTP_POST_VARS['formid'] == $sessiontoken) ) {
  105.     if (!tep_session_is_registered('comments')) tep_session_register('comments');
  106.     if (tep_not_null($HTTP_POST_VARS['comments'])) {
  107.       $comments = tep_db_prepare_input($HTTP_POST_VARS['comments']);
  108.     }
  109.  
  110.     if (!tep_session_is_registered('shipping')) tep_session_register('shipping');
  111.  
  112.     if ( (tep_count_shipping_modules() > 0) || ($free_shipping == true) ) {
  113.       if ( (isset($HTTP_POST_VARS['shipping'])) && (strpos($HTTP_POST_VARS['shipping'], '_')) ) {
  114.         $shipping = $HTTP_POST_VARS['shipping'];
  115.  
  116.         list($module, $method) = explode('_', $shipping);
  117.         if ( is_object($$module) || ($shipping == 'free_free') ) {
  118.           if ($shipping == 'free_free') {
  119.             $quote[0]['methods'][0]['title'] = FREE_SHIPPING_TITLE;
  120.             $quote[0]['methods'][0]['cost'] = '0';
  121.           } else {
  122.             $quote = $shipping_modules->quote($method, $module);
  123.           }
  124.           if (isset($quote['error'])) {
  125.             tep_session_unregister('shipping');
  126.           } else {
  127.             if ( (isset($quote[0]['methods'][0]['title'])) && (isset($quote[0]['methods'][0]['cost'])) ) {
  128.               $shipping = array('id' => $shipping,
  129.                                 'title' => (($free_shipping == true) ?  $quote[0]['methods'][0]['title'] : $quote[0]['module'] . ' (' . $quote[0]['methods'][0]['title'] . ')'),
  130.                                 'cost' => $quote[0]['methods'][0]['cost']);
  131.  
  132.               tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
  133.             }
  134.           }
  135.         } else {
  136.           tep_session_unregister('shipping');
  137.         }
  138.       }
  139.     } else {
  140.       $shipping = false;
  141.  
  142.       tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
  143.     }
  144.   }
  145.  
  146. // get all available shipping quotes
  147.   $quotes = $shipping_modules->quote();
  148.  
  149. // if no shipping method has been selected, automatically select the cheapest method.
  150. // if the modules status was changed when none were available, to save on implementing
  151. // a javascript force-selection method, also automatically select the cheapest shipping
  152. // method if more than one module is now enabled
  153.   if ( !tep_session_is_registered('shipping') || ( tep_session_is_registered('shipping') && ($shipping == false) && (tep_count_shipping_modules() > 1) ) ) $shipping = $shipping_modules->cheapest();
  154.  
  155.   require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_CHECKOUT_SHIPPING);
  156.  
  157.   $breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
  158.   $breadcrumb->add(NAVBAR_TITLE_2, tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
  159.  
  160.   require(DIR_WS_INCLUDES . 'template_top.php');
  161. ?>
  162.  
  163. <div class="page-header">
  164.   <h1><?php echo HEADING_TITLE; ?></h1>
  165. </div>
  166.  
  167. <?php echo tep_draw_form('checkout_address', tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'), 'post', 'class="form-horizontal"', true) . tep_draw_hidden_field('action', 'process'); ?>
  168.  
  169. <div class="contentContainer">
  170.   <h2><?php echo TABLE_HEADING_SHIPPING_ADDRESS; ?></h2>
  171.  
  172.   <div class="contentText row">
  173.     <div class="col-sm-8">
  174.       <div class="alert alert-warning">
  175.         <?php echo TEXT_CHOOSE_SHIPPING_DESTINATION; ?>
  176.         <div class="clearfix"></div>
  177.         <div class="pull-right">
  178.           <?php echo tep_draw_button(IMAGE_BUTTON_CHANGE_ADDRESS, 'glyphicon-home', tep_href_link(FILENAME_CHECKOUT_SHIPPING_ADDRESS, '', 'SSL')); ?>
  179.         </div>
  180.         <div class="clearfix"></div>
  181.       </div>
  182.     </div>
  183.     <div class="col-sm-4">
  184.       <div class="panel panel-primary">
  185.         <div class="panel-heading"><?php echo TITLE_SHIPPING_ADDRESS; ?></div>
  186.         <div class="panel-body">
  187.           <?php echo tep_address_label($customer_id, $sendto, true, ' ', '<br />'); ?>
  188.         </div>
  189.       </div>
  190.     </div>
  191.  
  192.  
  193.   </div>
  194.  
  195.   <div class="clearfix"></div>
  196.  
  197. <?php
  198.   if (tep_count_shipping_modules() > 0) {
  199. ?>
  200.  
  201.   <h2><?php echo TABLE_HEADING_SHIPPING_METHOD; ?></h2>
  202.  
  203. <?php
  204.     if (sizeof($quotes) > 1 && sizeof($quotes[0]) > 1) {
  205. ?>
  206.  
  207.   <div class="contentText">
  208.     <div class="alert alert-warning">
  209.       <div class="row">
  210.         <div class="col-xs-8">
  211.           <?php echo TEXT_CHOOSE_SHIPPING_METHOD; ?>
  212.         </div>
  213.         <div class="col-xs-4 text-right">
  214.           <?php echo '<strong>' . TITLE_PLEASE_SELECT . '</strong>'; ?>
  215.         </div>
  216.       </div>
  217.     </div>
  218.   </div>
  219.  
  220. <?php
  221.     } elseif ($free_shipping == false) {
  222. ?>
  223.  
  224.   <div class="contentText">
  225.     <div class="alert alert-info"><?php echo TEXT_ENTER_SHIPPING_INFORMATION; ?></div>
  226.   </div>
  227.  
  228. <?php
  229.     }
  230. ?>
  231.  
  232.   <div class="contentText">
  233.     <table class="table table-striped table-condensed table-hover table-options">
  234.       <tbody>
  235.  
  236. <?php
  237.     if ($free_shipping == true) {
  238. ?>
  239.  
  240.     <div class="contentText">
  241.       <div class="panel panel-success">
  242.         <div class="panel-heading"><strong><?php echo FREE_SHIPPING_TITLE; ?></strong>&nbsp;<?php echo $quotes[$i]['icon']; ?></div>
  243.         <div class="panel-body">
  244.           <?php echo sprintf(FREE_SHIPPING_DESCRIPTION, $currencies->format(MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER)) . tep_draw_hidden_field('shipping', 'free_free'); ?>
  245.         </div>
  246.       </div>
  247.     </div>
  248.  
  249. <?php
  250.     } else {
  251.       for ($i=0, $n=sizeof($quotes); $i<$n; $i++) {
  252.         for ($j=0, $n2=sizeof($quotes[$i]['methods']); $j<$n2; $j++) {
  253. // set the radio button to be checked if it is the method chosen
  254.           $checked = (($quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'] == $shipping['id']) ? true : false);
  255.  
  256.             echo '      <tr>' . "\n";
  257.  
  258. ?>
  259.  
  260.         <td>
  261.           <strong><?php echo $quotes[$i]['module']; ?></strong>
  262.           <?php
  263.           if (isset($quotes[$i]['icon']) && tep_not_null($quotes[$i]['icon'])) echo '&nbsp;' . $quotes[$i]['icon'];
  264.           ?>
  265.          
  266.           <?php
  267.           if (isset($quotes[$i]['error'])) {
  268.             echo '<div class="help-block">' . $quotes[$i]['error'] . '</div>';
  269.           }
  270.           ?>
  271.        
  272.           <?php
  273.           if (tep_not_null($quotes[$i]['methods'][$j]['title'])) echo '<div class="help-block">' . $quotes[$i]['methods'][$j]['title'] . '</div>';
  274.           ?>
  275.           </td>
  276.  
  277. <?php
  278.             if ( ($n > 1) || ($n2 > 1) ) {
  279. ?>
  280.  
  281.         <td align="right">
  282.           <?php
  283.           if (isset($quotes[$i]['error'])) {
  284.             // nothing
  285.             echo '&nbsp;';
  286.           }
  287.           else {
  288.             echo $currencies->format(tep_add_tax($quotes[$i]['methods'][$j]['cost'], (isset($quotes[$i]['tax']) ? $quotes[$i]['tax'] : 0))); ?>&nbsp;&nbsp;<?php echo tep_draw_radio_field('shipping', $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'], $checked, 'required aria-required="true"');
  289.           }
  290.           ?>
  291.         </td>
  292.  
  293. <?php
  294.             } else {
  295. ?>
  296.  
  297.         <td align="right"><?php echo $currencies->format(tep_add_tax($quotes[$i]['methods'][$j]['cost'], (isset($quotes[$i]['tax']) ? $quotes[$i]['tax'] : 0))) . tep_draw_hidden_field('shipping', $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id']); ?></td>
  298.  
  299. <?php
  300.             }
  301. ?>
  302.  
  303.       </tr>
  304.  
  305. <?php
  306.         }
  307.       }
  308.     }
  309. ?>
  310.  
  311.       </tbody>
  312.     </table>
  313.   </div>
  314.  
  315. <?php
  316.   }
  317. ?>
  318.  
  319.   <hr>
  320.  
  321.   <div class="contentText">
  322.     <div class="form-group">
  323.       <label for="inputComments" class="control-label col-xs-4"><?php echo TABLE_HEADING_COMMENTS; ?></label>
  324.       <div class="col-xs-8">
  325.         <?php
  326.         echo tep_draw_textarea_field('comments', 'soft', 60, 5, $comments, 'id="inputComments" placeholder="' . TABLE_HEADING_COMMENTS . '"');
  327.         ?>
  328.       </div>
  329.     </div>
  330.   </div>
  331.  
  332.   <div class="buttonSet">
  333.     <span class="buttonAction"><?php echo tep_draw_button(IMAGE_BUTTON_CONTINUE, 'glyphicon-chevron-right', null, 'primary'); ?></span>
  334.   </div>
  335.  
  336.   <div class="clearfix"></div>
  337.  
  338.   <div class="contentText">
  339.     <div class="stepwizard">
  340.       <div class="stepwizard-row">
  341.         <div class="stepwizard-step">
  342.           <button type="button" class="btn btn-primary btn-circle">1</button>
  343.           <p><?php echo CHECKOUT_BAR_DELIVERY; ?></p>
  344.         </div>
  345.         <div class="stepwizard-step">
  346.           <button type="button" class="btn btn-default btn-circle" disabled="disabled">2</button>
  347.           <p><?php echo CHECKOUT_BAR_PAYMENT; ?></p>
  348.         </div>
  349.         <div class="stepwizard-step">
  350.           <button type="button" class="btn btn-default btn-circle" disabled="disabled">3</button>
  351.           <p><?php echo CHECKOUT_BAR_CONFIRMATION; ?></p>
  352.         </div>
  353.       </div>
  354.     </div>
  355.   </div>
  356.  
  357. </div>
  358.  
  359. </form>
  360.  
  361. <?php
  362.   require(DIR_WS_INCLUDES . 'template_bottom.php');
  363.   require(DIR_WS_INCLUDES . 'application_bottom.php');
  364. ?>
  365.  
  366. <script>
  367. $('.table-options tr').click(function() {
  368.   $('.table-options tr').removeClass('success').find('input').prop('checked', false);
  369.   $(this).addClass('success').find('input').prop('checked', true);
  370. });
  371. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement