<?php
/**
 * Page Template
 *
 * Loaded automatically by index.php?main_page=shopping_cart.<br />
 * Displays shopping-cart contents
 *
 * @package templateSystem
 * @copyright Portions Copyright 2011 Frank Riegel
 * @copyright Copyright 2003-2010 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_shopping_cart_default.php 15881 2010-04-11 16:32:39Z wilt $
 */
?>
<div class="centerColumn" id="shoppingCartDefault">
<?php
  if ($flagHasCartContents) {
?>

<?php
  if ($_SESSION['cart']->count_contents() > 0) {
?>
<div class="forward"><?php echo TEXT_VISITORS_CART; ?></div>
<?php
  }
?>

<h1 id="cartDefaultHeading"><?php echo HEADING_TITLE; ?></h1>

<?php if ($messageStack->size('shopping_cart') > 0) echo $messageStack->output('shopping_cart'); ?>

<?php echo zen_draw_form('cart_quantity', zen_href_link(FILENAME_SHOPPING_CART, 'action=update_product', $request_type)); ?>
<div id="cartInstructionsDisplay" class="content"><?php echo TEXT_INFORMATION; ?></div>

<!--BOF Free Shipping Qualifier -->
<div class="cartAlert">
<?php
/**
 * check if cart qualifies for free shipping
 */

if (MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') {
  $free_limit = MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER;
  if ($_SESSION['cart']->count_contents() > 0) { 
     $_SESSION['cart']->get_products(); 
     $basket_total = $_SESSION['cart']->show_total(); 
     if ($basket_total < $free_limit) { 
        $diff_to_free = ($free_limit - $basket_total);
        echo  TEXT_ALERT_IN_CART . $currencies->format($diff_to_free) . TEXT_ALERT_QUALIFY;
     } 
      else { 
        echo TEXT_ALERT_NOW_QUALIFIED; 
     }  
   } 
 }

/**
 * end of check if cart qualifies for free shipping
 */
?>
<br /><br />
<?php
  if ($basket_total < $free_limit) {
  echo  TEXT_ALERT_FREE_SHIPPING . $currencies->format($free_limit) . TEXT_ALERT_OR_MORE;
  }
?>
<br /><br />
</div>
<!--EOF Free Shipping Qualifier -->

<?php if (!empty($totalsDisplay)) { ?>
  <div class="cartTotalsDisplay important"><?php echo $totalsDisplay; ?></div>
  <br class="clearBoth" />
<?php } ?>

<?php  if ($flagAnyOutOfStock) { ?>

<?php    if (STOCK_ALLOW_CHECKOUT == 'true') {  ?>

<div class="messageStackError"><?php echo OUT_OF_STOCK_CAN_CHECKOUT; ?></div>

<?php    } else { ?>
<div class="messageStackError"><?php echo OUT_OF_STOCK_CANT_CHECKOUT; ?></div>

<?php    } //endif STOCK_ALLOW_CHECKOUT ?>
<?php  } //endif flagAnyOutOfStock ?>

<table  border="0" width="100%" cellspacing="0" cellpadding="0" id="cartContentsDisplay">
     <tr class="tableHeading">
        <th scope="col" id="scQuantityHeading"><?php echo TABLE_HEADING_QUANTITY; ?></th>
        <th scope="col" id="scUpdateQuantity">&nbsp;</th>
        <th scope="col" id="scProductsHeading"><?php echo TABLE_HEADING_PRODUCTS; ?></th>
        <th scope="col" id="scUnitHeading"><?php echo TABLE_HEADING_PRICE; ?></th>
        <th scope="col" id="scTotalHeading"><?php echo TABLE_HEADING_TOTAL; ?></th>
        <th scope="col" id="scRemoveHeading">&nbsp;</th>
     </tr>
         <!-- Loop through all products /-->
<?php
  foreach ($productArray as $product) {
?>
     <tr class="<?php echo $product['rowClass']; ?>">
       <td class="cartQuantity">
<?php
  if ($product['flagShowFixedQuantity']) {
    echo $product['showFixedQuantityAmount'] . '<br /><span class="alert bold">' . $product['flagStockCheck'] . '</span><br /><br />' . $product['showMinUnits'];
  } else {
    echo $product['quantityField'] . '<br /><span class="alert bold">' . $product['flagStockCheck'] . '</span><br /><br />' . $product['showMinUnits'];
  }
?>
       </td>
       <td class="cartQuantityUpdate">
<?php
  if ($product['buttonUpdate'] == '') {
    echo '' ;
  } else {
    echo $product['buttonUpdate'];
  }
?>
       </td>
       <td class="cartProductDisplay">
<a href="<?php echo $product['linkProductsName']; ?>"><span id="cartImage" class="back"><?php echo $product['productsImage']; ?></span><span id="cartProdTitle"><?php echo $product['productsName'] . '<span class="alert bold">' . $product['flagStockCheck'] . '</span>'; ?></span></a>
<br class="clearBoth" />


<?php
  echo $product['attributeHiddenField'];
  if (isset($product['attributes']) && is_array($product['attributes'])) {
  echo '<div class="cartAttribsList">';
  echo '<ul>';
    reset($product['attributes']);
    foreach ($product['attributes'] as $option => $value) {
?>

<li><?php echo $value['products_options_name'] . TEXT_OPTION_DIVIDER . nl2br($value['products_options_values_name']); ?></li>

<?php
    }
  echo '</ul>';
  echo '</div>';
  }
?>
       </td>
      <td class="cartUnitDisplay"><?php  $product['products_discount_type']; if($product['products_discount_type'] != 0 ){ echo $product['org_price']; } else { echo $product['productsPriceEach'];  }  ?></td>
       <td class="cartTotalDisplay"><?php if($product['products_discount_type'] != 0 ){ echo $product['productsPrice']; } else { echo $product['productsPrice'];  } ?></td>
       <td class="cartRemoveItemDisplay">
<?php
  if ($product['buttonDelete']) {
?>
           <a href="<?php echo zen_href_link(FILENAME_SHOPPING_CART, 'action=remove_product&product_id=' . $product['id']); ?>"><?php echo zen_image($template->get_template_dir(ICON_IMAGE_TRASH, DIR_WS_TEMPLATE, $current_page_base,'images/icons'). '/' . ICON_IMAGE_TRASH, ICON_TRASH_ALT); ?></a>
<?php
  }
  if ($product['checkBoxDelete'] ) {
    echo zen_draw_checkbox_field('cart_delete[]', $product['id']);
  }
?>
</td>
     </tr>
<?php
  } // end foreach ($productArray as $product)
?>
       <!-- Finished loop through all products /-->
      </table>



<!-- bof Discount Preview logic -->
<?php 
 require_once(DIR_WS_CLASSES . 'order.php');
 $order = new order();

/*
 // build tax groups for UK VAT people who have embedded taxes
 if ($order->info['tax'] == 0) {
   $order->info['tax_groups'] = array();
   if (isset($_SESSION['customer_zone_id'])) {
      $zone = $_SESSION['customer_zone_id']; 
   } else {
      $zone = -1; 
   }
   $order->info['tax_groups'] = zen_get_multiple_tax_rates(1,-1,$zone); 
 }
*/

 // Reorder or delete as appropriate for your shop.
 // group pricing, better together, quantity discounts,
 // and combination discounts.
 include_once(DIR_WS_MODULES . $template_dir . '/inc_gp.php'); // Group Discount
 include_once(DIR_WS_MODULES . $template_dir . '/inc_bt.php'); // Better Together
 include_once(DIR_WS_MODULES . $template_dir . '/inc_qd.php'); // Quantity Discount
 include_once(DIR_WS_MODULES . $template_dir . '/inc_td.php'); // Table Discounts
 include_once(DIR_WS_MODULES . $template_dir . '/inc_md.php'); // Manufacturer Discount
 include_once(DIR_WS_MODULES . $template_dir . '/inc_cd.php'); // Combination Discounts
 include_once(DIR_WS_MODULES . $template_dir . '/inc_bs.php'); // Big Spender Discounts
 include_once(DIR_WS_MODULES . $template_dir . '/inc_bo.php'); // BOGO Discounts
 include_once(DIR_WS_MODULES . $template_dir . '/inc_bc.php'); // Big Chooser Discounts
 include_once(DIR_WS_MODULES . $template_dir . '/inc_fgc.php'); // Free Gift Chooser Discounts
 include_once(DIR_WS_MODULES . $template_dir . '/inc_fgs.php'); // Free Gift Spender Discounts
 include_once(DIR_WS_MODULES . $template_dir . '/inc_cased.php'); // Case Discounts
 include_once(DIR_WS_MODULES . $template_dir . '/inc_fd.php'); // Frequency Discount
?>

<?php 

//$newsub = $order->info['subtotal'];
$newsub = $cartShowTotalWithDIsc;
// UK VAT use this instead 
// $newsub = $_SESSION['cart']->show_total();
$shownewsub = 0; 
if (isset($gp['total']) && $gp['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $gp['total']; 
}
if (isset($bt['total']) && $bt['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $bt['total']; 
}
if (isset($qd['total']) && $qd['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $qd['total']; 
}
if (isset($td['total']) && $td['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $td['total']; 
}
if (isset($md['total']) && $md['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $md['total']; 
}
if (isset($cd['total']) && $cd['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $cd['total']; 
}
if (isset($bc['total']) && $bc['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $bc['total']; 
}
if (isset($bs['total']) && $bs['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $bs['total']; 
}
if (isset($bo['total']) && $bo['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $bo['total']; 
}
if (isset($fgc['total']) && $fgc['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $fgc['total']; 
}
if (isset($fgs['total']) && $fgs['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $fgs['total']; 
}
if (isset($cased['total']) && $cased['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $cased['total']; 
}
if (isset($fd['total']) && $fd['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $fd['total']; 
}
if ($shownewsub) { 
	echo '<div id="cartSubTotal">';
	echo SUB_TITLE_SUB_TOTAL . ": "; 
	echo $currencies->format($cartShowTotalWithDIsc, true, $order->info['currency'], $order->info['currency_value']);
	echo '</div>';
	echo '<div id="cartNewSubTotal">';
	echo SUBTOTAL_POSTDISCOUNT . ": "; 
	echo $currencies->format($newsub, true, $order->info['currency'], $order->info['currency_value']);
	echo '</div>';
} else {
?>
<div id="cartSubTotal"><?php echo SUB_TITLE_SUB_TOTAL; ?> <?php echo $cartShowTotal; ?></div>

<?php } ?>
<br class="clearBoth" />
<!-- eof Discount Preview logic -->
<br class="clearBoth" />

<!--bof shopping cart buttons-->
<div class="buttonRow forward"><?php echo '<a href="' . zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL') . '">' . zen_image_button(BUTTON_IMAGE_CHECKOUT, BUTTON_CHECKOUT_ALT) . '</a>'; ?></div>
<div class="buttonRow back"><?php echo zen_back_link() . zen_image_button(BUTTON_IMAGE_CONTINUE_SHOPPING, BUTTON_CONTINUE_SHOPPING_ALT) . '</a>'; ?></div>
<?php
// show update cart button
  if (SHOW_SHOPPING_CART_UPDATE == 2 or SHOW_SHOPPING_CART_UPDATE == 3) {
?>
<div class="buttonRow back"><?php echo zen_image_submit(ICON_IMAGE_UPDATE, ICON_UPDATE_ALT); ?></div>
<?php
  } else { // don't show update button below cart
?>
<?php
  } // show update button
?>
<!--eof shopping cart buttons-->
</form>

<br class="clearBoth" />
<?php
    if (SHOW_SHIPPING_ESTIMATOR_BUTTON == '1') {
?>

<div class="buttonRow back"><?php echo '<a href="javascript:popupWindow(\'' . zen_href_link(FILENAME_POPUP_SHIPPING_ESTIMATOR) . '\')">' .
 zen_image_button(BUTTON_IMAGE_SHIPPING_ESTIMATOR, BUTTON_SHIPPING_ESTIMATOR_ALT) . '</a>'; ?></div>
<?php
    }
?>

<!-- ** BEGIN PAYPAL EXPRESS CHECKOUT ** -->
<?php  // the tpl_ec_button template only displays EC option if cart contents >0 and value >0
if (defined('MODULE_PAYMENT_PAYPALWPP_STATUS') && MODULE_PAYMENT_PAYPALWPP_STATUS == 'True') {
  include(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/paypal/tpl_ec_button.php');
}
?>
<!-- ** END PAYPAL EXPRESS CHECKOUT ** -->

<?php
      if (SHOW_SHIPPING_ESTIMATOR_BUTTON == '2') {
/**
 * load the shipping estimator code if needed
 */
?>
      <?php require(DIR_WS_MODULES . zen_get_module_directory('shipping_estimator.php')); ?>

<?php
      }
?>
<?php
  } else {
?>

<h2 id="cartEmptyText"><?php echo TEXT_CART_EMPTY; ?></h2>

<?php
$show_display_shopping_cart_empty = $db->Execute(SQL_SHOW_SHOPPING_CART_EMPTY);

while (!$show_display_shopping_cart_empty->EOF) {
?>

<?php
  if ($show_display_shopping_cart_empty->fields['configuration_key'] == 'SHOW_SHOPPING_CART_EMPTY_FEATURED_PRODUCTS') { ?>
<?php
/**
 * display the Featured Products Center Box
 */
?>
<?php require($template->get_template_dir('tpl_modules_featured_products.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_featured_products.php'); ?>
<?php } ?>

<?php
  if ($show_display_shopping_cart_empty->fields['configuration_key'] == 'SHOW_SHOPPING_CART_EMPTY_SPECIALS_PRODUCTS') { ?>
<?php
/**
 * display the Special Products Center Box
 */
?>
<?php require($template->get_template_dir('tpl_modules_specials_default.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_specials_default.php'); ?>
<?php } ?>

<?php
  if ($show_display_shopping_cart_empty->fields['configuration_key'] == 'SHOW_SHOPPING_CART_EMPTY_NEW_PRODUCTS') { ?>
<?php
/**
 * display the New Products Center Box
 */
?>
<?php require($template->get_template_dir('tpl_modules_whats_new.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_whats_new.php'); ?>
<?php } ?>

<?php
  if ($show_display_shopping_cart_empty->fields['configuration_key'] == 'SHOW_SHOPPING_CART_EMPTY_UPCOMING') {
    include(DIR_WS_MODULES . zen_get_module_directory(FILENAME_UPCOMING_PRODUCTS));
  }
?>
<?php
  $show_display_shopping_cart_empty->MoveNext();
} // !EOF
?>
<?php
  }
?>
</div>
