<?php
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); 
/**
* @version $Id: basket.php,v 1.16 2005/01/27 19:34:00 soeren_nb Exp $
* @package mambo-phpShop
* @subpackage HTML
* Contains code from PHPShop(tm):
* 	@copyright (C) 2000 - 2004 Edikon Corporation (www.edikon.com)
*	Community: www.phpshop.org, forums.phpshop.org
* Conversion to Mambo and the rest:
* 	@copyright (C) 2004-2005 Soeren Eberhardt
*
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* mambo-phpShop is Free Software.
* mambo-phpShop comes with absolute no warranty.
*
* www.mambo-phpshop.net
*/
mm_showMyFileName( __FILE__ );

require_once(CLASSPATH. 'ps_product.php' );
$ps_product = new ps_product;
require_once(CLASSPATH. 'ps_checkout.php' );
$ps_checkout = new ps_checkout;
require_once(CLASSPATH . 'ps_shipping_method.php' );

global $weight_total, $total;

  if ($cart["idx"] == 0) {
     echo $PHPSHOP_LANG->_PHPSHOP_EMPTY_CART;
     $checkout = False;
  }
  else {
     $checkout = True;
?>
<table width="100%" cellspacing="0" cellpadding="4" border="0">
<tr align="left" class="sectiontableheader">
<th><?php 
      echo $PHPSHOP_LANG->_PHPSHOP_CART_NAME
     ?></th>
<th><?php 
      echo $PHPSHOP_LANG->_PHPSHOP_CART_SKU;
     ?></th>
<th><?php 
      echo $PHPSHOP_LANG->_PHPSHOP_CART_PRICE;
     ?></th>
<th><?php 
      echo $PHPSHOP_LANG->_PHPSHOP_CART_QUANTITY;
     ?></th>
<th><?php 
      echo $PHPSHOP_LANG->_PHPSHOP_CART_SUBTOTAL;
     ?></th>
<th colspan="2" align="center"><?php 
      echo $PHPSHOP_LANG->_PHPSHOP_CART_ACTION;
     ?></th>
</tr>
<?php
  $total = 0;
  // Added for the zone shipping module
  $vars["zone_qty"] = 0;
  $weight_total = 0;
  $weight_subtotal = 0;
  $tax_total = 0;
  $shipping_total = 0;
  
  for ($i=0;$i<$cart["idx"];$i++) {
    // Added for the zone shipping module
    $vars["zone_qty"] += $cart[$i]["quantity"];

    if ($i % 2) $row_color = "sectiontableentry2";
       else $row_color = "sectiontableentry1";
?>
  <tr valign="top" class="<?php echo $row_color ?>">
    <form action="<?php echo $_SERVER['SERVER_PORT']=="443" ? SECUREURL : URL ?>index.php" method="post" />
    <input type="hidden" name="option" value="com_phpshop" />
    
    <td><?php
        // Get product parent id if exists
        $product_parent_id=$ps_product->get_field($cart[$i]["product_id"],"product_parent_id");
        // Get flypage for this product
        $flypage = $ps_product->get_flypage($cart[$i]["product_id"]);
        // Build URL based on whether item or product
        if ($product_parent_id)
           $url = $sess->url(URL . "index.php?page=shop.product_details&flypage=$flypage&product_id=$product_parent_id");
        else
           $url = $sess->url(URL . "index.php?page=shop.product_details&flypage=$flypage&product_id=" . $_SESSION['cart'][$i]["product_id"]);
        echo "<a href=\"$url\">";
        // Display product name
        echo "<strong>" . $ps_product->get_field($_SESSION['cart'][$i]["product_id"], "product_name") . "</strong>";
        echo "</a>";
        // Display advanced attribute values
        echo "<br />".$_SESSION['cart'][$i]["description"];
        
        // Display attribute values if this an item
        if ($product_parent_id) {
          $db_detail=$ps_product->attribute_sql($cart[$i]["product_id"],$product_parent_id);
          while ($db_detail->next_record()) {
             echo "<br />" . $db_detail->f("attribute_name") . "&nbsp;";
         echo "(" . $db_detail->f("attribute_value") . ")"; 
          }
        } ?>
    </td>
    <td><?php
          echo $ps_product->get_field($cart[$i]["product_id"], "product_sku");
         ?></td>
    <td><?php 
          $price = $ps_product->get_adjusted_attribute_price($cart[$i]["product_id"], $cart[$i]["description"]);
          $product_price = $price["product_price"];
          echo $CURRENCY_DISPLAY->getFullValue($product_price);
         ?></td>
    <td>
        <input type="text" class="inputbox" size="4" maxlength="4" name="quantity" 
        value="<?php echo $cart[$i]["quantity"];?>" />
        </td>
    <td><?php
    
    /* WEIGHT CALCULATION */
          $weight_subtotal = ps_shipping_method::get_weight($cart[$i]["product_id"]) * $cart[$i]['quantity'];
          $weight_total += $weight_subtotal;
          
    /* SUBTOTAL CALCULATION */
          $my_taxrate = $ps_product->get_product_taxrate($cart[$i]["product_id"], $weight_subtotal);
          $tax = $my_taxrate * 100;
          $subtotal = $price["product_price"] * $cart[$i]["quantity"];
          
          $total += $subtotal;
          echo $CURRENCY_DISPLAY->getFullValue($subtotal);
          if (!empty($my_taxrate) && MULTIPLE_TAXRATES_ENABLE=='1') {
              $message = " (+ $tax% ".$PHPSHOP_LANG->_PHPSHOP_CART_TAX.")";
              echo $message;
          }
          
    /* UPDATE CART / DELETE FROM CART */
         ?></td>
    <td>
      <input type="hidden" name="page" value="<?php echo $_REQUEST['page'] ?>" />
      <input type="hidden" name="func" value="cartUpdate" />
      <input type="hidden" name="product_id" value="<?php echo $_SESSION['cart'][$i]["product_id"]?>" />
      <input type="hidden" name="Itemid" value="<?php echo @$_REQUEST['Itemid'] ?>" />
      <input type="hidden" name="description" value="<?php echo $cart[$i]["description"]?>" />
      <input type="image" name="update" title="<?php echo $PHPSHOP_LANG->_PHPSHOP_CART_UPDATE ?>" src="<?php echo IMAGEURL ?>ps_image/edit_f2.gif" border="0"  value="<?php echo $PHPSHOP_LANG->_PHPSHOP_UPDATE ?>" />
    </form>
    </td>
    <td>
      <form action="<?php echo $_SERVER['SERVER_PORT']=="443" ? SECUREURL : URL ?>index.php" method="post" name="delete" />
      <input type="hidden" name="option" value="com_phpshop" />
      <input type="hidden" name="page" value="<?php echo $_REQUEST['page'] ?>" />
      <input type="hidden" name="Itemid" value="<?php echo @$_REQUEST['Itemid'] ?>" />
      <input type="hidden" name="func" value="cartDelete" />
      <input type="hidden" name="product_id" value="<?php echo $_SESSION['cart'][$i]["product_id"]?>" />
      <input type="hidden" name="description" value="<?php echo $cart[$i]["description"]?>" />
    <input type="image" name="delete" title="<?php echo $PHPSHOP_LANG->_PHPSHOP_CART_DELETE ?>" src="<?php echo IMAGEURL ?>ps_image/delete_f2.gif" border="0" value="<?php echo $PHPSHOP_LANG->_PHPSHOP_CART_DELETE ?>" />
    </form>
    </td>
  </tr>
<?php
  } // End for loop

/* make sure this is the checkout screen */

if ($_REQUEST["page"] == "checkout.index") {

	if (!empty($_POST["do_coupon"])) {
	    
		/* process the coupon */
		
		/* make sure they arent trying to run it twice */
		if (@$_SESSION['coupon_redeemed'] == true) { 
			echo $PHPSHOP_LANG->_PHPSHOP_COUPON_ALREADY_REDEEMED;
		}
		else {
			require_once( CLASSPATH . "ps_coupon.php" );
			ps_coupon::process_coupon_code( $vars );
		}
	} 
	
}
?>
  <tr class="sectiontableentry2">
    <td colspan="4" align="right"><?php echo $PHPSHOP_LANG->_PHPSHOP_CART_SUBTOTAL ?>:
    </td> 
    <td colspan=3"><?php  
      $total = round($total, 2);
      echo $CURRENCY_DISPLAY->getFullValue($total); ?>
    </td>
  </tr>
<?php 

/* COUPON DISCOUNT */
if( PSHOP_COUPONS_ENABLE=='1' && @$_SESSION['coupon_redeemed']==true && PAYMENT_DISCOUNT_BEFORE=='1') {
  $total -= $_SESSION['coupon_discount'];
?>
  <tr class="sectiontableentry1">
    <td colspan="4" align="right"><?php echo $PHPSHOP_LANG->_PHPSHOP_COUPON_DISCOUNT ?>:
    </td> 
    <td colspan="3"><?php
      echo "- ".$CURRENCY_DISPLAY->getFullValue( $_SESSION['coupon_discount'] ); ?>
    </td>
  </tr>
<?php
}
/* SHOW TAX */
if (!empty($_REQUEST['ship_to_info_id']) || SHOW_PRICE_WITH_TAX=='1') { ?>
  <tr class="sectiontableentry2">
      <td colspan="4" align="right"><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_TOTAL_TAX ?>: </td> 
  <td colspan="3"><?php
      if ($weight_total != 0 or TAX_VIRTUAL=='1') {
          $order_taxable = $ps_checkout->calc_order_taxable($vars);
          $tax_total = $ps_checkout->calc_order_tax($order_taxable, $vars);
      } else {
          $tax_total = 0;
      }
      $tax_total = round( $tax_total, 2 );
      echo $CURRENCY_DISPLAY->getFullValue($tax_total); ?>
  </td>
  </tr>
<?php
}
/* SHOW SHIPPING COSTS */
  if (((PSHOP_SHIPPING_MODULE == 'zone_shipping' && !empty($ship_to_info_id)) 
      || (!empty($shipping_rate_id))) && (CHECKOUT_STYLE =='1' || CHECKOUT_STYLE=='3')
      ) { ?>
      <tr class="sectiontableentry1">
        <td colspan="4" align="right"><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_SHIPPING ?>: </td> 
        <td colspan="3"><?php
          $vars["weight"] = $weight_total;
          $shipping_total = round( $ps_checkout->_SHIPPING->get_rate ( $vars ), 2 );
          echo $CURRENCY_DISPLAY->getFullValue($shipping_total); ?>
        </td>
      </tr>
  <?php
  }
  else {
    $shipping_total = 0;
  } 
/* COUPON DISCOUNT */
if( PSHOP_COUPONS_ENABLE=='1' && @$_SESSION['coupon_redeemed']==true && PAYMENT_DISCOUNT_BEFORE!='1') {
  $total -= $_SESSION['coupon_discount'];
?>
  <tr class="sectiontableentry1">
    <td colspan="4" align="right"><?php echo $PHPSHOP_LANG->_PHPSHOP_COUPON_DISCOUNT ?>:
    </td> 
    <td colspan="3"><?php
      echo "- ".$CURRENCY_DISPLAY->getFullValue( $_SESSION['coupon_discount'] ); ?>
    </td>
  </tr>
<?php
}?>
  <tr>
    <td colspan="3">&nbsp;</td>
    <td colspan="4"><hr /></td>
  </tr>
  <tr>
    <td colspan="4" align="right"><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_TOTAL ?>: </td>
    <td colspan="3"><strong><?php
     $order_total = $tax_total + $shipping_total + $total;

     echo $CURRENCY_DISPLAY->getFullValue($order_total); ?></strong>
    </td>
  </tr>
  <tr>
    <td colspan="7"><hr /></td>
  </tr>
</table>
<?php
  if( PSHOP_COUPONS_ENABLE=='1' && $page == "checkout.index" && !@$_SESSION['coupon_redeemed']) {
  
      include (PAGEPATH."coupon.coupon_field.php");
  
  }
 }
?>
