<?
include "../../inc/functions.php";
if(!$_SESSION['log_mobile']){die();}

$prod['taxes']			=	implode(',',$_POST['tax']);
$prod['title']			=	$_POST['product_name'];
$prod['qty']			=	$_POST['product_qty'];
$prod['price']			=	$_POST['product_price'];
$prod['description']	=	$_POST['product_description'];

if(empty($_SESSION['products']))$_SESSION['products']=array();
	if($_POST['action']=='add'){
		$_SESSION['products'][]=$prod;
	}
	if($_POST['action']=='delete'){
		unset($_SESSION['products'][$_POST['id']]);
	}	
	
	if($_POST['action']=='update'){
		if($_POST['rule']==0)$_SESSION['products'][$_POST['id']]['qty']-=1;
		if($_POST['rule']==1)$_SESSION['products'][$_POST['id']]['qty']+=1;
	}
?>
<div id='products_box' style='border:1px solid #ccc;'>
	<table width='100%'>
		<tr style='background:#e2e2e2; color:#000;'>
			<td width='30'>&nbsp;</td>
			<td width='500'>Title</td>
			<td width='120'>Qty</td>
			<td>Net</td>
			<td>Taxes</td>
			<td>Total</td>
			<td>&nbsp;</td>
		</tr>
		<?$i=1;
			foreach($_SESSION['products'] as $tag=>$val){
			unset($tx);
				$tx		=array();
				$taxprod=0;
				$tx=explode(',',$val['taxes']);
					foreach($tx as $tax){
						$pos1 = stripos($tax,'%' );
							$tm=str_replace('%','',$tax);
							if ($pos1 !== false) {
								$taxprod+=($tm*$val['price']*$val['qty'])/100;
							}else{
								$taxprod+=$tm;
							}
					}
			?>
		<tr>
			<td width='30'><?=$i?></td>
			<td width='500'><b><?=$val['title']?></b><br><i style='font-size:11px'><?=$val['description']?></i></td>
			<td width='120'>
				<table cellspacing='0' cellpadding='0'>
					<tr>
						<td><a href="index.html" onclick="return update_prod('<?=$tag?>','0')" data-ajax="false"><i class='icon-minus'></i></a></td>
						<td><input type='text' class='settings' style='width:30px;' value='<?=$val['qty']?>'/></td>
						<td><a href="index.html" onclick="return update_prod('<?=$tag?>','1')" data-ajax="false"><i class='icon-plus'></i></a></td>
					</tr>
				</table>	
			</td>
			<td><?=$val['qty']*$val['price']?> <?=$cfg['currency']?></td>
			<td><?=$taxprod?> <?=$cfg['currency']?></td>
			<td><b><?=($val['qty']*$val['price'])+$taxprod?> <?=$cfg['currency']?></b></td>
			<td width='15'><a href="index.html" onclick="return deleteprod('<?=$tag?>')" data-ajax="false"><i class='icon-times'></i></a></td>
		</tr>			
		<?$i++;
			$totalmare+=($val['qty']*$val['price'])+$taxprod;
			$subtotal+=$val['qty']*$val['price'];
			$taxes+=$taxprod;
		}?>
	</table>
</div>
<div id='total_price' style='border:1px solid #000; font-size:14px; width:auto; float:right;'>
	<table cellspacing='0' cellpadding='0' width='100%'>
		<tr>
			<td>Subtotal:</td>
			<td style='padding-left:20px;'><b style='font-size:10px;'><?=$subtotal?> <?=$cfg['currency']?></b></td>
		</tr>
		<tr>
			<td>Taxes:</td>
			<td style='padding-left:20px;'><b style='font-size:10px;'><?=$taxes?> <?=$cfg['currency']?></b></td>
		</tr>
		<tr>
			<td>TOTAL:</td>
			<td style='padding-left:20px;'><b style='font-size:13px;'><?=$totalmare?> <?=$cfg['currency']?> <?$_SESSION['total_order']=$totalmare?></b></td>
		</tr>
	</table>
</div>