  <?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: 			*/
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2004-2010 ARMIA INC                                    |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts EasyCart                      |
// +----------------------------------------------------------------------+
// | Authors: Jipson<jipson.thomas@armiasystems.com>                      |
// +----------------------------------------------------------------------+
?>
<?php echo $javascript->link('jquery.js'); ?>
<?php echo $javascript->link('alphanumeric.js'); ?>
<script language="javascript" type="text/javascript">
function frmsubm(){
	document.cart.submit();
}

function chkForm()
{  
    window.location='<?php echo $html->url('/users/checkoutlogin');?>';  
	return true;    
}


</script>
<!--<br /><br />-->
<?php if($session->check('Message.flash')) { ?>
<div id="okbox"><font color="#446423"><?php $session->flash(); ?></font></div><?php } ?>

<div align="left" id="item_details_mycart" class="cart-width">
<!--items display area start -->
<div style="padding-left:100px;"><?php if($session->check('Message.flash')) { ?><font color="#FF0000"><?php $session->flash(); ?></font><br /><?php } ?></div>
<form name="cart" method="post" action="<?php echo $html->url('/carts/update');?>">			
<div class="row">
		<div class="col-md-12">
			<h2 class="title text-center mainhd">My Cart</h2>
		</div>

<!--item details-->
		<div class="col-md-12">
		<div class="table-responsive">
		 <table class="table" width="100%"  border="0" cellspacing="0" cellpadding="0" id="items_display_area_admin_table">
		  <tr>
			<td align="left" valign="top">
			<table width="100%"  border="0" cellspacing="0" cellpadding="5">
			  <tr>
				<td class="boxtopheader">Items Details </td>
			  </tr>
			</table>
			<table width="100%"  border="0" cellspacing="1" cellpadding="6" class="item-table">
			 <?php if( (isset($itemlist) &&  empty($itemlist)===false && sizeof($itemlist) > 0) || (isset($giftcard) &&  empty($giftcard)===false && sizeof($giftcard) > 0))
			 { ?>
			  <tr align="left" valign="middle" id="list_admin_top">
				<td width="5%">Sl.No.</td>
				<td width="24%">Product Name</td>
				<?php  if($cmbtype_flag == 'yes') { ?> 
				<td width="31%">Selected Combination </td>
				<?php } ?>
				<td width="12%" align="center">Quantity </td>
				<td width="19%" align="center">Price</td>        
				<td width="9%" align="center">Option</td>
				</tr>
				 <?php } ?>
							
			  <?php 
			  $i=0;
			  $sum = 0;
			  $final_price=0;
			 if(isset($itemlist) &&  empty($itemlist)===false && sizeof($itemlist) > 0)
			  {
				foreach($itemlist as $item)
				   { 
					 $i++;  ?>									   
				<tr align="left" valign="middle" id="list_admin">
					<td align="center"><?php echo $i;?></td>
					<td><?php echo $item["Product"]["pname"]; ?></td>
					<?php  if($cmbtype_flag == 'yes') { ?> 
					<td>
					<?php 
					if(isset($item["Cart"]["combn_values"]) && isset($item["Cart"]["combn_values"])<>'')
					echo $item["Cart"]["combn_values"];
					else
					echo "Not Applicable";
					?>
					</td>
					<?php }?>
					<td align="center">
					<input type="hidden" value="<?php echo $item["Cart"]["id"]; ?>" name="id[]">
					<input type="hidden" value="<?php echo $item["Cart"]["type"]; ?>" name="ptype[]">
					<input type="hidden" value="<?php echo $item["Cart"]["option_id"]; ?>" name="optionid[]">
					<!-- <input type="text" value="<?php echo $item["Cart"]["quantity"]; ?>" name="qty[]" style="width:20px;"> -->
					<select name="qty[]" style="width:50px; ">
					<?php 
					$limit=0;
					if($item["Product"]["stock"] > 1000)
					$limit=1000;
					else
					$limit=$item["Product"]["stock"];
					for($pqty=1;$pqty <= $limit;$pqty++)
					{ ?>			
					<option value="<?php echo $pqty;?>" <?php if($item["Cart"]["quantity"]==$pqty) print "selected=selected";?>><?php echo $pqty;?></option>			
					<?php } ?>			
					</select>
					 </td>
					<td align="center">			
					<?php
												$combined_price=($item["Cart"]["product_price"] + $item["Cart"]["extra_price"]);			
												 if(isset($item["Cart"]["discount_type"]) && $item["Cart"]["discount_type"] <> '')
												  { 
													if($item["Cart"]["discount_type"]=='per')
													 {
													  if(isset($item["Cart"]["discount"]) && $item["Cart"]["discount"] <> '' && $item["Cart"]["discount"] > 0)
														{
														 $discounted_price=($combined_price-(($combined_price * $item["Cart"]["discount"])/100));
														 $final_price=($discounted_price)*$item["Cart"]["quantity"];
														 echo "<strike>".$curlogo.number_format(($combined_price * $item["Cart"]["quantity"]),2,'.','')."</strike>&nbsp;&nbsp;".$curlogo.number_format($final_price,2,'.','');							 
														}		
														 else
														 {
															$final_price=($item["Cart"]["product_price"] + $item["Cart"]["extra_price"])*$item["Cart"]["quantity"];
															echo $curlogo.number_format($final_price,2,'.','');		
														 }										 
													 }
													 else if($item["Cart"]["discount_type"]=='amnt')
													 {	 
														 if(isset($item["Cart"]["discount"]) && $item["Cart"]["discount"] <> '' && $item["Cart"]["discount"] > 0)
														 {
															$final_price=(($combined_price)-$item["Cart"]["discount"])*$item["Cart"]["quantity"];						
															echo "<strike>".$curlogo.number_format(($combined_price * $item["Cart"]["quantity"]),2,'.','')."</strike>&nbsp;&nbsp;".$curlogo.number_format($final_price,2,'.','');								 
														 }		
														 else
														 {
															$final_price=($item["Cart"]["product_price"] + $item["Cart"]["extra_price"])*$item["Cart"]["quantity"];
															echo $curlogo.number_format($final_price,2,'.','');		
														 }
													}
												  }
												 else
												 {
												  $final_price=($item["Cart"]["product_price"] + $item["Cart"]["extra_price"])*$item["Cart"]["quantity"];
												  echo $curlogo.number_format($final_price,2,'.','');			
												 }	
												 $sum = $sum +  $final_price; 			 								
												 ?>	
					</td>			
					<td align="center"><a href="<?php echo $html->url('/carts/delete/'.$item["Cart"]["id"]);?>">
					<?php echo $html->image('/img/remove.gif', array('width' => 15, 'height' => 15 , 'border' => 0 ,'text-decoration' => 'none' ,'title' => 'Remove Item'));?>
					  </a></td>
				</tr>     
			 <?php } } ?>
			 
			 
			 <?php if(isset($giftcard) &&  empty($giftcard)===false && sizeof($giftcard) > 0)
			  {			
				  foreach($giftcard as $gitem)
				   { 
					 $i++;  ?>									   
				<tr align="left" valign="middle" id="list_admin">
					<td align="center"><?php echo $i;?></td>
					<td><?php echo $gitem["Cart"]["gift_code"]; ?> [Gift Card]</td>
					<?php  if($cmbtype_flag == 'yes') { ?> 
					<td>Not Applicable</td>
					<?php } ?>
					<td align="center">
					<input type="hidden" value="<?php echo $gitem["Cart"]["id"]; ?>" name="id[]">
					<input type="hidden" value="<?php echo $gitem["Cart"]["type"]; ?>" name="ptype[]">
					<!-- <input type="text" value="<?php echo $gitem["Cart"]["quantity"]; ?>" name="qty[]" style="width:20px;"> -->
					<select name="qty[]" style="width:50px;">
					<?php 
					$limit1=0;
					if($gitem["Product"]["stock"] > 1000)
					$limit1=1000;
					else
					$limit1=$gitem["Product"]["stock"];
					for($gqty=1;$gqty <= $limit1;$gqty++)
					{ ?>			
					<option value="<?php echo $gqty;?>" <?php if($gitem["Cart"]["quantity"]==$gqty) print "selected=selected";?>><?php echo $gqty;?></option>			
					<?php } ?>			
					</select>
					</td>
					<td align="center"><?php 
					echo $curlogo.($gitem["Cart"]["product_price"]*$gitem["Cart"]["quantity"]);
					$sum = $sum +  ($gitem["Cart"]["product_price"]*$gitem["Cart"]["quantity"]); 		
					 ?></td>			
					<td align="center"><a href="<?php echo $html->url('/carts/delete/'.$gitem["Cart"]["id"]);?>">
					<?php echo $html->image('/img/remove.gif', array('width' => 15, 'height' => 15 , 'border' => 0 ,'text-decoration' => 'none' ,'title' => 'Remove Item'));?>
					  </a></td>
				</tr>     
			 <?php } } ?>
			 
			 
			 <?php if(empty($itemlist)===true && empty($giftcard)===true )
			   { 
                              
                             
                             ?>
				<tr align="left" valign="middle" id="list_admin">
				 <td colspan="6" align="center"><span class="bodytext2"><strong>Your cart is empty!</strong></span></td>      
				</tr>
			  <?php } ?>
			</table>
			  <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="admin_bottom">
				<tr>
				  <td>&nbsp;</td>
				</tr>
			  </table></td>
		  </tr>
		</table>
		</div>
		<div class="clear"></div>
		</div>
<!--<br />-->
<!--price details-->
<div class="col-md-6 col-md-offset-6">
<?php if( ( isset($itemlist) && sizeof($itemlist) > 0  )|| (isset($giftcard) && sizeof($giftcard) > 0))
	 { ?>
	<div class="table-responsive">
    <table  class="table" width="100%"  border="0" cellspacing="0" cellpadding="0" id="items_display_area_admin_table">
       <tr>
         <td align="left" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="5">
             <tr>
               <td class="boxtopheader">Price Details </td>
             </tr>
           </table>
             <table width="100%"  border="0" cellspacing="1" cellpadding="6" class="item-table">
               <tr align="left" valign="middle" id="list_admin_top">
                 <td width="44%">Total Price</td>
                 <td width="56%">
				 <?php if(isset($sum) && $sum!='') { echo $curlogo."&nbsp;".number_format($sum,2,'.',''); } ?></td>
               </tr>
			    
			    <?php
					$discamt	=	0;
					if(isset($allow_giftcoupon) && $allow_giftcoupon == "Y"){?>
            <tr align="left" valign="middle" id="list_admin">
                 <td>Enter Promo Code</td>
                 <td><input  type="text" class="box2_admin"  name="code" onBlur="javascript:frmsubm();" value="<?php echo isset($promo_code) ? $promo_code : "";?>" /></td>
               </tr> 
			   <?php
                            $flg = 0;
                            
				if(isset($couparray) && is_array($couparray)){
                                   
					$tdat	=	date("Y-m-d");													
					//if(strtotime($tdat) > strtotime($couparray["Coupon"]["from_date"]) &&  strtotime($tdat) <  strtotime($couparray["Coupon"]["to_date"]) && $sum >= $couparray["Coupon"]["minamt"])
                                       if(strtotime($tdat) >= strtotime($couparray["Coupon"]["from_date"]) &&  strtotime($tdat) <=  strtotime($couparray["Coupon"]["to_date"]))
					{
					  if($sum >= $couparray["Coupon"]["minamt"]){
                                          if($couparray["Coupon"]["type"] == "Amt")
					  {
						 //$discamt	=	$couparray["Coupon"]["giftvalue"];
						 if($couparray["Coupon"]["giftvalue"] > $sum)
						 $discamt	=	$sum;
						 else
						 $discamt	=	$couparray["Coupon"]["giftvalue"];
                                                 
					  }
					  else
					  {
						 $discamt	=	$sum * ($couparray["Coupon"]["giftvalue"] / 100);
                                                 
					  }					
					}else{
                                            $discamt = 0;
                                            $flg =1;
                                            
                                        }

                                        }else{
                                             $discamt = 0;
                                             $flg =1;
                                             
                                        }
                                        
					?>
		 <?php }  ?>	
              <tr align="left" valign="middle" id="list_admin">
											 <td>Promo Code Discount </td>
											 <td class="regular"><?php  echo $curlogo.number_format($discamt,2,'.','');
                                                                                         if(($discamt) == 0 && $promo_code != "" && $flg == 1) {//echo ' (Discount not available)';
                                                                                            echo '</br>( Promo Code might have expired or total amount is too low than minimum  applicable amount for this Promo Code.)';
                                                                                         }
                                                                                         ?></td>
										   </tr>
										   <?php } ?>
             </table>
             <table width="100%"  border="0" cellspacing="0" cellpadding="3" id="admin_bottom" class="admin_btm">
               <tr>
                 <td width="44%">Grand Total</td>
                 <td width="55%" class="toplinks"><?php  if(($sum - $discamt)<0) { echo "0.00";} else {echo $curlogo.number_format(($sum - $discamt),2,'.','');} ?></td>
               </tr>
           </table></td>
       </tr>
     </table>
     </div>
       
<?php } ?>
<div style="clear:both"></div>
</div> 

<div class="btn-row">
 <table width="100%"  border="0" cellspacing="0" cellpadding="0">
   <tr>
     <td align="left">
		 <input  type="button" value="Back" class="btn-bk margin-10px-upbt" onClick="javascript:history.go(-1);"/>	   
	 <?php
	  if( (isset($itemlist) &&  empty($itemlist)===false && sizeof($itemlist) > 0) || (isset($giftcard) &&  empty($giftcard)===false && sizeof($giftcard) > 0))	 
	 { ?>
         <input  type="submit" class="btn-usr margin-10px-upbt" value="Update Cart" />        
         <input  type="button" class="btn-usr margin-10px-upbt" value="Checkout" onClick="return chkForm();"/>								
         <input  type="button" value="Continue shopping" class="btn-usr margin-10px-upbt" onClick="javascript:window.location='<?php echo $html->url('/index.php');?>';"/>
		 <input  type="hidden" name="hidamnt" id="hidamnt" value=""/>

	    <?php }?>		
		 <!--<input  type="button" value="Back" class="buttn_user" onClick="javascript:history.go(-1);"/>	-->   
	     </td></tr>
	</table>
	
</div>

  </form>
 </div>

<script type="text/javascript">
$('#giftamnt').numeric({allow:"."});
</script>