WikiFormatting: checkout_shipping.php.txt

File checkout_shipping.php.txt, 21.0 KB (added by ashokmca31, 3 years ago)
Line 
1<?php
2/*
3  $Id: checkout_shipping.php 1739 2007-12-20 00:52:16Z hpdl $
4
5  osCommerce, Open Source E-Commerce Solutions
6  http://www.oscommerce.com
7
8  Copyright (c) 2003 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')) tep_session_register('cartID');
50  $cartID = $cart->cartID;
51
52// if the order contains only virtual products, forward the customer to the billing page as
53// a shipping address is not needed
54  if ($order->content_type == 'virtual') {
55    if (!tep_session_is_registered('shipping')) tep_session_register('shipping');
56    $shipping = false;
57    $sendto = false;
58    tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
59  }
60
61  $total_weight = $cart->show_weight();
62  $total_count = $cart->count_contents();
63
64// load all enabled shipping modules
65  require(DIR_WS_CLASSES . 'shipping.php');
66  $shipping_modules = new shipping;
67
68  if ( defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING') && (MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') ) {
69    $pass = false;
70
71    switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION) {
72      case 'national':
73        if ($order->delivery['country_id'] == STORE_COUNTRY) {
74          $pass = true;
75        }
76        break;
77      case 'international':
78        if ($order->delivery['country_id'] != STORE_COUNTRY) {
79          $pass = true;
80        }
81        break;
82      case 'both':
83        $pass = true;
84        break;
85    }
86
87    $free_shipping = false;
88    if ( ($pass == true) && ($order->info['total'] >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) ) {
89      $free_shipping = true;
90
91      include(DIR_WS_LANGUAGES . $language . '/modules/order_total/ot_shipping.php');
92    }
93  } else {
94    $free_shipping = false;
95  }
96
97// process the selected shipping method
98  if ( isset($HTTP_POST_VARS['action']) && ($HTTP_POST_VARS['action'] == 'process') ) {
99    if (!tep_session_is_registered('comments')) tep_session_register('comments');
100    if (tep_not_null($HTTP_POST_VARS['comments'])) {
101      $comments = tep_db_prepare_input($HTTP_POST_VARS['comments']);
102    }
103
104    if (!tep_session_is_registered('shipping')) tep_session_register('shipping');
105
106    if ( (tep_count_shipping_modules() > 0) || ($free_shipping == true) ) {
107      if ( (isset($HTTP_POST_VARS['shipping'])) && (strpos($HTTP_POST_VARS['shipping'], '_')) ) {
108        $shipping = $HTTP_POST_VARS['shipping'];
109
110        list($module, $method) = explode('_', $shipping);
111        if ( is_object($$module) || ($shipping == 'free_free') ) {
112          if ($shipping == 'free_free') {
113            $quote[0]['methods'][0]['title'] = FREE_SHIPPING_TITLE;
114            $quote[0]['methods'][0]['cost'] = '0';
115          } else {
116            $quote = $shipping_modules->quote($method, $module);
117          }
118          if (isset($quote['error'])) {
119            tep_session_unregister('shipping');
120          } else {
121            if ( (isset($quote[0]['methods'][0]['title'])) && (isset($quote[0]['methods'][0]['cost'])) ) {
122              $shipping = array('id' => $shipping,
123                                'title' => (($free_shipping == true) ?  $quote[0]['methods'][0]['title'] : $quote[0]['module'] . ' (' . $quote[0]['methods'][0]['title'] . ')'),
124                                'cost' => $quote[0]['methods'][0]['cost']);
125
126//---PayPal WPP Modification START ---//
127              tep_paypal_wpp_checkout_shipping_redirect($show_payment_page, $ec_enabled);
128//---PayPal WPP Modification END ---//
129            }
130          }
131        } else {
132          tep_session_unregister('shipping');
133        }
134      }
135    } else {
136      $shipping = false;
137               
138//---PayPal WPP Modification START ---//
139     tep_paypal_wpp_checkout_shipping_redirect($show_payment_page, $ec_enabled);
140//---PayPal WPP Modification END ---//
141    }   
142  }
143
144// get all available shipping quotes
145  $quotes = $shipping_modules->quote();
146
147// if no shipping method has been selected, automatically select the cheapest method.
148// if the modules status was changed when none were available, to save on implementing
149// a javascript force-selection method, also automatically select the cheapest shipping
150// method if more than one module is now enabled
151  if ( !tep_session_is_registered('shipping') || ( tep_session_is_registered('shipping') && ($shipping == false) && (tep_count_shipping_modules() > 1) ) ) $shipping = $shipping_modules->cheapest();
152
153  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_CHECKOUT_SHIPPING);
154
155  $breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
156  $breadcrumb->add(NAVBAR_TITLE_2, tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
157?>
158<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
159<html <?php echo HTML_PARAMS; ?>>
160<head>
161<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
162<title><?php echo TITLE; ?></title>
163<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
164<link rel="stylesheet" type="text/css" href="stylesheet.css">
165<script language="javascript"><!--
166var selected;
167
168function selectRowEffect(object, buttonSelect) {
169  if (!selected) {
170    if (document.getElementById) {
171      selected = document.getElementById('defaultSelected');
172    } else {
173      selected = document.all['defaultSelected'];
174    }
175  }
176
177  if (selected) selected.className = 'moduleRow';
178  object.className = 'moduleRowSelected';
179  selected = object;
180
181// one button is not an array
182  if (document.checkout_address.shipping[0]) {
183    document.checkout_address.shipping[buttonSelect].checked=true;
184  } else {
185    document.checkout_address.shipping.checked=true;
186  }
187}
188
189function rowOverEffect(object) {
190  if (object.className == 'moduleRow') object.className = 'moduleRowOver';
191}
192
193function rowOutEffect(object) {
194  if (object.className == 'moduleRowOver') object.className = 'moduleRow';
195}
196//--></script>
197</head>
198<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
199<!-- header //-->
200<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
201<!-- header_eof //-->
202
203<!-- body //-->
204<table border="0" width="100%" cellspacing="3" cellpadding="3">
205  <tr>
206    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
207<!-- left_navigation //-->
208<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
209<!-- left_navigation_eof //-->
210    </table></td>
211<!-- body_text //-->
212    <td width="100%" valign="top"><?php echo tep_draw_form('checkout_address', tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL')) . tep_draw_hidden_field('action', 'process'); ?><table border="0" width="100%" cellspacing="0" cellpadding="0">
213      <tr>
214        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
215          <tr>
216            <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
217            <td class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES . 'table_background_delivery.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
218          </tr>
219        </table></td>
220      </tr>
221<?php
222//---PayPal WPP Modification START ---//
223  tep_paypal_wpp_checkout_shipping_error_display($ec_checkout);
224//---PayPal WPP Modification END ---//
225?>
226      <tr>
227        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
228      </tr>
229      <tr>
230        <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
231          <tr>
232            <td class="main"><b><?php echo TABLE_HEADING_SHIPPING_ADDRESS; ?></b></td>
233          </tr>
234        </table></td>
235      </tr>
236      <tr>
237        <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
238          <tr class="infoBoxContents">
239            <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
240              <tr>
241                <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
242                <td class="main" width="50%" valign="top"><?php echo TEXT_CHOOSE_SHIPPING_DESTINATION . '<br><br><a href="' . tep_href_link(FILENAME_CHECKOUT_SHIPPING_ADDRESS, '', 'SSL') . '">' . tep_image_button('button_change_address.gif', IMAGE_BUTTON_CHANGE_ADDRESS) . '</a>'; ?></td>
243                <td align="right" width="50%" valign="top"><table border="0" cellspacing="0" cellpadding="2">
244                  <tr>
245                    <td class="main" align="center" valign="top"><?php echo '<b>' . TITLE_SHIPPING_ADDRESS . '</b><br>' . tep_image(DIR_WS_IMAGES . 'arrow_south_east.gif'); ?></td>
246                    <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
247                    <td class="main" valign="top"><?php echo tep_address_label($customer_id, $sendto, true, ' ', '<br>'); ?></td>
248                    <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
249                  </tr>
250                </table></td>
251              </tr>
252            </table></td>
253          </tr>
254        </table></td>
255      </tr>
256      <tr>
257        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
258      </tr>
259<?php
260  if (tep_count_shipping_modules() > 0) {
261?>
262      <tr>
263        <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
264          <tr>
265            <td class="main"><b><?php echo TABLE_HEADING_SHIPPING_METHOD; ?></b></td>
266          </tr>
267        </table></td>
268      </tr>
269      <tr>
270        <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
271          <tr class="infoBoxContents">
272            <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
273<?php
274    if (sizeof($quotes) > 1 && sizeof($quotes[0]) > 1) {
275?>
276              <tr>
277                <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
278                <td class="main" width="50%" valign="top"><?php echo TEXT_CHOOSE_SHIPPING_METHOD; ?></td>
279                <td class="main" width="50%" valign="top" align="right"><?php echo '<b>' . TITLE_PLEASE_SELECT . '</b><br>' . tep_image(DIR_WS_IMAGES . 'arrow_east_south.gif'); ?></td>
280                <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
281              </tr>
282<?php
283    } elseif ($free_shipping == false) {
284?>
285              <tr>
286                <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
287                <td class="main" width="100%" colspan="2"><?php echo TEXT_ENTER_SHIPPING_INFORMATION; ?></td>
288                <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
289              </tr>
290<?php
291    }
292
293    if ($free_shipping == true) {
294?>
295              <tr>
296                <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
297                <td colspan="2" width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="2">
298                  <tr>
299                    <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
300                    <td class="main" colspan="3"><b><?php echo FREE_SHIPPING_TITLE; ?></b>&nbsp;<?php echo $quotes[$i]['icon']; ?></td>
301                    <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
302                  </tr>
303                  <tr id="defaultSelected" class="moduleRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="selectRowEffect(this, 0)">
304                    <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
305                    <td class="main" width="100%"><?php echo sprintf(FREE_SHIPPING_DESCRIPTION, $currencies->format(MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER)) . tep_draw_hidden_field('shipping', 'free_free'); ?></td>
306                    <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
307                  </tr>
308                </table></td>
309                <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
310              </tr>
311<?php
312    } else {
313      $radio_buttons = 0;
314      for ($i=0, $n=sizeof($quotes); $i<$n; $i++) {
315?>
316              <tr>
317                <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
318                <td colspan="2"><table border="0" width="100%" cellspacing="0" cellpadding="2">
319                  <tr>
320                    <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
321                    <td class="main" colspan="3"><b><?php echo $quotes[$i]['module']; ?></b>&nbsp;<?php if (isset($quotes[$i]['icon']) && tep_not_null($quotes[$i]['icon'])) { echo $quotes[$i]['icon']; } ?></td>
322                    <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
323                  </tr>
324<?php
325        if (isset($quotes[$i]['error'])) {
326?>
327                  <tr>
328                    <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
329                    <td class="main" colspan="3"><?php echo $quotes[$i]['error']; ?></td>
330                    <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
331                  </tr>
332<?php
333        } else {
334          for ($j=0, $n2=sizeof($quotes[$i]['methods']); $j<$n2; $j++) {
335// set the radio button to be checked if it is the method chosen
336            $checked = (($quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'] == $shipping['id']) ? true : false);
337
338            if ( ($checked == true) || ($n == 1 && $n2 == 1) ) {
339              echo '                  <tr id="defaultSelected" class="moduleRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="selectRowEffect(this, ' . $radio_buttons . ')">' . "\n";
340            } else {
341              echo '                  <tr class="moduleRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="selectRowEffect(this, ' . $radio_buttons . ')">' . "\n";
342            }
343?>
344                    <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
345                    <td class="main" width="75%"><?php echo $quotes[$i]['methods'][$j]['title']; ?></td>
346<?php
347            if ( ($n > 1) || ($n2 > 1) ) {
348?>
349                    <td class="main"><?php echo $currencies->format(tep_add_tax($quotes[$i]['methods'][$j]['cost'], (isset($quotes[$i]['tax']) ? $quotes[$i]['tax'] : 0))); ?></td>
350                    <td class="main" align="right"><?php echo tep_draw_radio_field('shipping', $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'], $checked); ?></td>
351<?php
352            } else {
353?>
354                    <td class="main" align="right" colspan="2"><?php echo $currencies->format(tep_add_tax($quotes[$i]['methods'][$j]['cost'], $quotes[$i]['tax'])) . tep_draw_hidden_field('shipping', $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id']); ?></td>
355<?php
356            }
357?>
358                    <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
359                  </tr>
360<?php
361            $radio_buttons++;
362          }
363        }
364?>
365                </table></td>
366                <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
367              </tr>
368<?php
369      }
370    }
371?>
372            </table></td>
373          </tr>
374        </table></td>
375      </tr>
376      <tr>
377        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
378      </tr>
379<?php
380  }
381?>
382      <tr>
383        <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
384          <tr>
385            <td class="main"><b><?php echo TABLE_HEADING_COMMENTS; ?></b></td>
386          </tr>
387        </table></td>
388      </tr>
389      <tr>
390        <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
391          <tr class="infoBoxContents">
392            <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
393              <tr>
394                <td><?php echo tep_draw_textarea_field('comments', 'soft', '60', '5'); ?></td>
395              </tr>
396            </table></td>
397          </tr>
398        </table></td>
399      </tr>
400      <tr>
401        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
402      </tr>
403      <tr>
404        <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
405          <tr class="infoBoxContents">
406            <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
407              <tr>
408                <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
409                <td class="main"><?php echo '<b>' . TITLE_CONTINUE_CHECKOUT_PROCEDURE . '</b><br>' . TEXT_CONTINUE_CHECKOUT_PROCEDURE; ?></td>
410                <td class="main" align="right"><?php echo tep_image_submit('button_continue.gif', IMAGE_BUTTON_CONTINUE); ?></td>
411                <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
412              </tr>
413            </table></td>
414          </tr>
415        </table></td>
416      </tr>
417      <tr>
418        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
419      </tr>
420      <tr>
421        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
422          <tr>
423            <td width="25%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
424              <tr>
425                <td width="50%" align="right"><?php echo tep_image(DIR_WS_IMAGES . 'checkout_bullet.gif'); ?></td>
426                <td width="50%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>
427              </tr>
428            </table></td>
429<?php //---PayPal WPP Modification START ---//-- ?>
430<?php if ($show_payment_page || !$ec_enabled) { ?>
431            <td width="25%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>
432<?php } ?>
433<?php //---PayPal WPP Modification END ---//-- ?>
434            <td width="25%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>
435            <td width="25%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
436              <tr>
437                <td width="50%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>
438                <td width="50%"><?php echo tep_draw_separator('pixel_silver.gif', '1', '5'); ?></td>
439              </tr>
440            </table></td>
441          </tr>
442          <tr>
443            <td align="center" width="25%" class="checkoutBarCurrent"><?php echo CHECKOUT_BAR_DELIVERY; ?></td>
444<?php
445  //---PayPal WPP Modification START ---//
446  if ($show_payment_page || !$ec_enabled) {
447?>
448            <td align="center" width="25%" class="checkoutBarTo"><?php echo CHECKOUT_BAR_PAYMENT; ?></td>
449<?php   
450  }
451//---PayPal WPP Modification END ---//
452?>
453            <td align="center" width="25%" class="checkoutBarTo"><?php echo CHECKOUT_BAR_CONFIRMATION; ?></td>
454            <td align="center" width="25%" class="checkoutBarTo"><?php echo CHECKOUT_BAR_FINISHED; ?></td>
455          </tr>
456        </table></td>
457      </tr>
458    </table></form></td>
459<!-- body_text_eof //-->
460    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
461<!-- right_navigation //-->
462<?php require(DIR_WS_INCLUDES . 'column_right.php'); ?>
463<!-- right_navigation_eof //-->
464    </table></td>
465  </tr>
466</table>
467<!-- body_eof //-->
468
469<!-- footer //-->
470<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
471<!-- footer_eof //-->
472<br>
473</body>
474</html>
475<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>