<?php
/**
 * Page Template
 *
 * Loaded automatically by index.php?main_page=checkout_shipping.<br />
 * Displays allowed shipping modules for selection by customer.
 *
 * @package templateSystem
 * @copyright Copyright 2003-2009 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: tpl_checkout_shipping_default.php 14807 2009-11-13 17:22:47Z drbyte $
 */
?>
<div class="centerColumn" id="checkoutShipping">
  <div class="stacked-layout">
    <?php echo zen_draw_form('checkout_address', zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL')) . zen_draw_hidden_field('action', 'process'); ?>

    <h2 id="checkoutShippingHeading" class="page-default-heading"><?php echo HEADING_TITLE; ?></h2><br>
    <?php if ($messageStack->size('checkout_shipping') > 0) echo $messageStack->output('checkout_shipping'); ?>

    <h3 id="checkoutShippingHeadingAddress" class="section-title"><?php echo TITLE_SHIPPING_ADDRESS; ?></h3>

    <div class="ship-to row">
      <div id="checkoutShipto" class="col-lg-6">
      <address class=""><?php echo zen_address_label($_SESSION['customer_id'], $_SESSION['sendto'], true, ' ', '<br />'); ?></address>
      </div>
      <div class="col-lg-6">
        <?php echo TEXT_CHOOSE_SHIPPING_DESTINATION; ?>
        <?php if ($displayAddressEdit) { ?>
        <div class="buttonRow"><br><?php echo '<a href="' . $editShippingButtonLink . '" class="button">' . BUTTON_CHANGE_ADDRESS_ALT . '</a>'; ?></div>
        <?php } ?>  
      </div>
    </div><br><br>

    <?php if (zen_count_shipping_modules() > 0) { ?>

    <h3 id="checkoutShippingHeadingMethod" class="section-title"><?php echo TABLE_HEADING_SHIPPING_METHOD; ?></h3>

    <?php if (sizeof($quotes) > 1 && sizeof($quotes[0]) > 1) { ?>

    <div id="checkoutShippingContentChoose" class="important"><?php echo TEXT_CHOOSE_SHIPPING_METHOD; ?></div><br>

    <?php } elseif ($free_shipping == false) { ?>
    <div id="checkoutShippingContentChoose" class="important"><?php echo TEXT_ENTER_SHIPPING_INFORMATION; ?></div><br>

    <?php } ?>
    <?php if ($free_shipping == true) { ?>
    <div id="freeShip" class="important" ><?php echo FREE_SHIPPING_TITLE; ?>&nbsp;<?php echo $quotes[$i]['icon']; ?></div>
    <div id="defaultSelected"><?php echo sprintf(FREE_SHIPPING_DESCRIPTION, $currencies->format(MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER)) . zen_draw_hidden_field('shipping', 'free_free'); ?></div>

    <?php
        } else {
          $radio_buttons = 0;
          for ($i=0, $n=sizeof($quotes); $i<$n; $i++) {
          if ($quotes[$i]['module'] != '') { 
    ?>
    <div class="checkout-section">
      <?php if (isset($quotes[$i]['error'])) { ?>
        <div class="important"><?php echo $quotes[$i]['error']; ?></div>
      <?php } else { ?>
        <?php for ($j=0, $n2=sizeof($quotes[$i]['methods']); $j<$n2; $j++) { ?>
          <div class="shipping-detail">
            <?php $checked = (($quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'] == $_SESSION['shipping']['id']) ? true : false); ?>
            <label for="ship-<?php echo $quotes[$i]['id'] . '-' . str_replace(' ', '-', $quotes[$i]['methods'][$j]['id']); ?>" class="checkboxLabel radio-inline" >
              <?php echo zen_draw_radio_field('shipping', $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'], $checked, 'id="ship-'.$quotes[$i]['id'] . '-' . str_replace(' ', '-', $quotes[$i]['methods'][$j]['id']) .'"'); ?>
              <div class="shipping-info">
                <div class="shipping-module-title"><?php echo $quotes[$i]['module']; ?>&nbsp;<?php if (isset($quotes[$i]['icon']) && zen_not_null($quotes[$i]['icon'])) { echo $quotes[$i]['icon']; } ?></div>
                <div class="shipping-module-subtitle"><?php echo $quotes[$i]['methods'][$j]['title']; ?></div>
                <?php if ( ($n > 1) || ($n2 > 1) ) { ?>
                  <div class="shipping-module-quote important"><?php echo $currencies->format(zen_add_tax($quotes[$i]['methods'][$j]['cost'], (isset($quotes[$i]['tax']) ? $quotes[$i]['tax'] : 0))); ?></div>
                <?php } else { ?>
                  <div class="shipping-module-quote important"><?php echo $currencies->format(zen_add_tax($quotes[$i]['methods'][$j]['cost'], $quotes[$i]['tax'])) . zen_draw_hidden_field('shipping', $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id']); ?></div>
                <?php } ?>
              </div>
            </label>
          </div>
          <div class="clearfix"></div>
          <?php $radio_buttons++; ?>
        <?php } ?>
      <?php } ?>
    </div>
    <?php
        }
      }
    }
    ?>

    <?php
      } else {
    ?>
    <h2 id="checkoutShippingHeadingMethod" class="page-default-heading"><?php echo TITLE_NO_SHIPPING_AVAILABLE; ?></h2>
    <div id="checkoutShippingContentChoose" class="important"><?php echo TEXT_NO_SHIPPING_AVAILABLE; ?></div>
    <?php
      }
    ?>

    <?php echo zen_draw_textarea_field('comments', '45', '3', '~*~*#', 'class="order-comment" placeholder="' . TABLE_HEADING_COMMENTS . '"'); ?> 

    <div class="clearfix"></div>

    <div class="buttonRow pull-right"><button type="submit" class="pt-button pt-button-m"><?php echo BUTTON_CONTINUE_ALT; ?> &rarr;</button></div>
    <div class="buttonRow pull-left"><?php echo '<strong>' . TITLE_CONTINUE_CHECKOUT_PROCEDURE . '</strong><br />' . TEXT_CONTINUE_CHECKOUT_PROCEDURE; ?></div>

    </form>
  </div>
</div>