Location: PHPKode > scripts > Encaps Gallery > encaps-2.3.22s/shopcart.php
<?php 
include("common.ini.php");
$html["head_title"] = " :: shopcart ";
$html["categs"] = $catalog->categs_gets();

include_once("catalog_head.html");
$cart = new ShopCart($db,$config,$catalog->items);
switch(@$postget['action'])
{
	case "add":$cart->item_add($postget['item_id']);break;
	case "del":$cart->item_delete($postget['item_id']);break;
	case "recalc":$cart->recalc($postget);break;
}
$tpl['items'] = $cart->get_session_items();
?>
<h1>Shopcart</h1>
<table width="100%">
<tr>
	<td valign="top" align="center" class="common">
<?php if(file_exists("html/catalog_categs_select.html"))include("html/catalog_categs_select.html")?><br>
<?php if(file_exists("html/search_form.html"))include("html/search_form.html")?><br>
<?php if(file_exists("html/shopcart_preview.html"))if($config["shopcart_is_enabled"])include("html/shopcart_preview.html");?>

	</td>
	<td valign="top" align="center" class="common">

<div align="center">
<form method="post" action="">
<table class="tbl" >
<tr >
	<th >Remove</th>
	<th >Products</th>
	<th >Price</th>
	<th >Qty</th>
	<th >Total</th>
</tr>
<?php 
$subtotal = 0;
foreach($tpl['items'] as $item_cart){
$item_catalog = $catalog->items->get("WHERE id=".$item_cart['id']);
?>
<tr bgcolor="#EFEFEF">
	<td align="center"><input type="button" value="X" onclick="location.href='?action=recalc&amp;del_<?php echo $item_catalog['id']?>'"></td>
	<td align="left"><table ><tr><td><img src="./rwx/<?php echo $item_catalog['file_thumb']?>" alt="<?php echo $item_catalog['title']?>"></td><td><a href="catalog.php?id=<?php echo $item_catalog['id']?>" style="color:#000000"><?php echo $item_catalog['title']?></a></td></tr></table></td>
	<td style="color:#000000">$<?php echo sprintf("%.2f",$item_catalog['price'])?></td>
	<td><input type="text" size="2" value="<?php echo $item_cart['qty']?>" name="qty_<?php echo $item_cart['id']?>"></td>
	<td style="color:#000000">$<?php  echo sprintf("%.2f",$total = $item_cart['qty']*$item_catalog['price']); $subtotal += $total?></td>
</tr>
<?php }?>
<tr><td colspan="4" align="right"><input type="submit" value="Recalculate Sub-Total:" class="button" ></td><td><b>$<?php echo sprintf("%.2f",$subtotal)?></b></td></tr>
</table>
<p>Any changes above should be verified by pressing 'Recalculate Sub-Total' before click on 'Checkout&raquo;'</p>
<input type="hidden" name="action" value="recalc">
</form>
<?php 
if ($config["shopcart_type"] == 'paypal')
{
?>
<form action="<?php echo "https://www.";if($config["shopcart_paypal_sandbox"]) echo "sandbox."; echo "paypal.com/cgi-bin/webscr";?>" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="<?php echo $config["admin_email"]?>">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="notify_url" value="<?php echo $config["url_root"]?>/shopcart_ipn.php">
<?php 
$i = 0;
foreach($tpl['items'] as $item_cart){
$i++;
$item_catalog = $catalog->items->get("WHERE id=".$item_cart['id']);
?>
<input type="hidden" name="item_number_<?php echo $i?>" value="<?php echo $item_catalog['id']?>">
<input type="hidden" name="item_name_<?php echo $i?>" value="<?php echo $item_catalog['title']?$item_catalog['title']:"Item # ".$item_catalog['id']; ?>">
<input type="hidden" name="amount_<?php echo $i?>" value="<?php echo (double)$item_catalog['price'] ?>">
<input type="hidden" name="quantity_<?php echo $i?>" value="<?php echo $item_cart['qty'] ?>">
<?php } ?>
<table>
<tr>
<td colspan="3" align="center"><input type="button" value="&laquo;Continue shopping" onclick="location.href='index.php'" class="button" >
&nbsp;&nbsp;&nbsp;<?php if (count($tpl['items']) ){?><input type="submit" value="Proceed to Checkout&raquo;" class="button" ><?php } ?></td>
</tr>
</table>
</form>
<?php } //if paypal ?>

<?php if ($config['shopcart_type'] == ''){ 
$error = false;
if (@$postget['action']=="checkout_submit")
{
	$postget['payer_business_name']    = strip_tags($postget['payer_business_name']);
	$postget['payer_email']   = strip_tags($postget['payer_email']);
	$postget['address_name'] = strip_tags($postget['address_name']); 
	
	if ($postget['payer_business_name'] == '')
	{
		$error = 1;
		$_show_error_on_page['payer_business_name'] = 1;
		Misc::_show_message_color ("Please enter Your Name","RED");
	}
	if ($postget['payer_email'] == '')
	{
		$error = 1;
		$_show_error_on_page['payer_email'] = 1;
		Misc::_show_message_color ('Please enter Your E-mail','RED');
	}
	if ($postget['address_name'] == '')
	{
		$error = 1;
		$_show_error_on_page['address_name'] = 1;
		Misc::_show_message_color ('Please enter Delivery Address','RED');
	}
	
	if ($error == false)
	{
		$cart->ipn($postget,"");
		$subject  = "Purchase request";
		$message = "<table border=1><tr><th colspan=2 >$subject</th></tr>";
		$message .= "\n<tr><th>Name:</th><td>".$postget['payer_business_name']."</td></tr>";
		$message .= "\n<tr><th>E-mail:</th><td>".$postget['payer_email']."</td></tr>";
		$message .= "\n<tr><th>Delivery address:</th><td>".$postget['address_name']."</td></tr>";
		$message .= "\n<tr><td colspan=2 align=center></td></tr>";						
		$message .= "\n<tr><td colspan=2><table border=0>";	
		$message .= "\n<tr><th style=' color:#666666'>Products</th><th style=' color:#666666'>Price</th><th style=' color:#666666'>Qty</th><th style=' color:#666666'>Total</th></tr>";
		$i=0;
		foreach($tpl['items'] as $item_cart)
		{
			$i++;
			$item_catalog = $catalog->items->get("WHERE id=".$item_cart['id']);
			$message .= "\n<tr bgcolor='#EFEFEF'><td align='left'>".$item_catalog['title']."</td><td>$".$item_catalog['price']."</td><td>".$item_cart['qty']."</td><td>$".$item_cart['qty'] * $item_catalog['price']."</td></tr>";
		}		
		$message .= "\n</table></td></tr>";
		$message .= "\n<tr><td colspan=2 align=right>Sub-Total&nbsp;:&nbsp;$".$subtotal."</td></tr>";
		$message .= "\n</table>";
		$res = func_send_mail($postget['payer_business_name'],$postget['payer_email'],$config["admin_email"],$subject,$message);
		if ($res)
		{
			Misc::_show_message_color ('Thank you for your interest, we will contact you soon.','GREEN');
			func_send_mail($postget['payer_business_name'],$config["admin_email"],$postget['payer_email'],$subject,$message);
			$cart->items_delete();
		}
		else
			Misc::_show_message_color ('Sorry, request delivery error. Please try again in a minute.','RED');
	}
}
?>
<script type="text/javascript">
function form_validate(_form)
{
	error = "";
	if(_form.payer_business_name.value == "")
		error += "\n Your Name";
	if(_form.payer_email.value == "")
		error += "\n Your E-mail";
	if(_form.address_name.value == "")
		error += "\n Delivery address";			
		
	if(	error != "")
	{
		alert("Missing values:"+error);
		return false;
	}
	return true;
}
</script>
<input type="button" value="&laquo;Continue shopping" onclick="location.href='index.php'" class="button" >
<form action="" method="post" onSubmit="return form_validate(this)">
<?php if(count($tpl['items'])){ ?>
<table style="border: 1px dashed #999999 ">
	<tr>
		<td style=" color:#666666"><b>Your Name*:</b></td>
		<td><input type="text" name="payer_business_name" value="<?php echo @$postget['payer_business_name'] ?>" <?php if (@$_show_error_on_page['payer_business_name'] == 1) echo 'style="border: 1px solid red"'; ?>></td>
	</tr>
	<tr>
		<td style=" color:#666666"><b>Your E-mail*:</b></td>
		<td><input type="text" name="payer_email" value="<?php echo @$postget['payer_email'] ?>" <?php if (@$_show_error_on_page['payer_email'] == 1) echo 'value="'.$postget['payer_email'].'" style="border: 1px solid red"'; ?>></td>
	<tr>
		<td style=" color:#666666"><b>Delivery Address*:</b></td>
		<td><textarea name="address_name"><?php echo @$postget['address_name'] ?><?php if (@$_show_error_on_page['address_name'] == 1) echo 'value="'.$postget['address_name'].'" style="border: 1px solid red"'; ?></textarea></td>
	</tr>
	<tr><td colspan="2" align="center"><input type="submit" value="Checkout&raquo;" class="button" ></td></tr>
</table>
<?php 
$i = 0;
foreach($tpl['items'] as $item_cart)
{
	$i++;
	$item_catalog = $catalog->items->get("WHERE id=".$item_cart['id']);
?>
<input type="hidden" name="item_number<?php echo $i?>" value="<?php echo $item_catalog['id']?>">
<input type="hidden" name="item_name<?php echo $i?>" value="<?php echo $item_catalog['title']?>">
<input type="hidden" name="amount<?php echo $i?>" value="<?php echo $item_catalog['price'] ?>">
<input type="hidden" name="quantity<?php echo $i?>" value="<?php echo $item_cart['qty'] ?>">
<input type="hidden" name="mc_gross_<?php echo $i?>" value="<?php echo $item_cart['qty']*$item_catalog['price'] ?>">
<?php }//foreach ?>
<?php }//if count($tpl['items']) ?>
<input type="hidden" name="num_cart_items" value="<?php echo count($tpl['items'])?>">
<input type="hidden" name="action" value="checkout_submit">
</form>
<?php }//if shopcart_type !=paypal ?>

</div>

</td>
</tr>
</table>

<?php  include_once("catalog_foot.html");?>
Return current item: Encaps Gallery