Location: PHPKode > scripts > Encaps Gallery > encaps-2.3.22s/core/shopcart.class.php
<?php 
class ShopCart extends BaseController
{
	function ShopCart($_db,$_conf,$items_ctl=null)
	{
		$this->db = $_db;
		$this->config = $_conf;	
		$this->items_ctl = $items_ctl;	
		$this->model = new BaseModel($this->db,$this->config["db_prefix"]."shopcart");
		$this->model->fields["payment_date"] = null;
		$this->model->fields["item_number"] = null;
		$this->model->fields["item_name"] = null;
		$this->model->fields["quantity"] = null;
		$this->model->fields["mc_gross"] = null;
		$this->model->fields["payer_email"] = null;
		$this->model->fields["payer_business_name"] = null;
		$this->model->fields["first_name"] = null;
		$this->model->fields["last_name"] = null;
		$this->model->fields["address_name"] = null;
		$this->model->fields["address_country"] = null;
		$this->model->fields["address_city"] = null;
		$this->model->fields["address_state"] = null;
		$this->model->fields["address_zip"] = null;
		$this->model->fields["address_street"] = null;
		$this->model->fields["payment_status"] = null;
		$this->model->fields["VERIFIED"] = null;
	}
		
	function item_add($item_id)
	{
		//echo " \n<br>".basename(__FILE__).":".__LINE__;
		$shopcart = (isset($_SESSION["shopcart"]))?$_SESSION["shopcart"]:array();
		foreach($shopcart as $item)
			if($item["id"] == $item_id)
				return;

		$shopcart[] = array("id"=>$item_id,"qty"=>1);
		$_SESSION["shopcart"] = $shopcart;
	}
	
	function item_delete($item_id)
	{
		$shopcart = $_SESSION["shopcart"];
		$shopcart_tmp = array();
		if(count($shopcart))
		foreach($shopcart as $item)
			if($item["id"] != $item_id)
				$shopcart_tmp[] = $item;
		$_SESSION["shopcart"] = $shopcart_tmp;
	}
	
	function items_delete()
	{
		$_SESSION["shopcart"] = array();
	}
	
	function recalc($_params)
	{
		foreach($_params as $key=>$value)
		{
			if(strpos($key,"del_")===0)
			{
	                        $this->item_delete(substr($key,4));
				continue;
			}
			if(strpos($key,"qty_")===0)
				$this->item_update(substr($key,4),(int)$value);
		}
	}
	
	function item_update($_id,$_qty)
	{
		$shopcart = $_SESSION["shopcart"];
		for($i=0;$i<count($shopcart);$i++)
			if($shopcart[$i]["id"] == $_id)
				$shopcart[$i]["qty"] = $_qty;
		$_SESSION["shopcart"] = $shopcart;
	}

	function ipn($_post,$_verified)//save order
	{
		for($i=1;$i<=$_post["num_cart_items"];$i++)
		{
			$param["item_number"] = $_post["item_number".$i];
			$param["item_name"] = urlencode(stripslashes($_post["item_name".$i]));
			$param["quantity"] = $_post["quantity".$i];
			$param["mc_gross"] = $_post["mc_gross_".$i];
			
			$param["payer_email"] = (stripslashes($_post["payer_email"]));
			$param["payer_business_name"] = urlencode(stripslashes($_post["payer_business_name"]));
			@$param["first_name"] = urlencode(stripslashes($_post["first_name"]));
			@$param["last_name"] = urlencode(stripslashes($_post["last_name"]));
			$param["address_name"] = urlencode(stripslashes($_post["address_name"]));
			@$param["address_country"] = urlencode(stripslashes($_post["address_country"]));
			@$param["address_city"] = urlencode(stripslashes($_post["address_city"]));
			@$param["address_state"] = urlencode(stripslashes($_post["address_state"]));
			@$param["address_zip"] = urlencode(stripslashes($_post["address_zip"]));
			@$param["address_street"] = urlencode(stripslashes($_post["address_street"]));
			@$param["payment_status"] = urlencode(stripslashes($_post["payment_status"]));

			$param["payment_date"] = date("Y-m-d H:i:s");//$_post["payment_date"];			
			$param["VERIFIED"] = $_verified;
			
			$sql = "INSERT INTO ".$this->config["db_prefix"]."shopcart (payment_date,item_number,item_name,quantity,mc_gross,payer_email,payer_business_name,first_name,last_name,address_name,address_country,address_city,address_state,address_zip,address_street,payment_status,VERIFIED) 
				VALUES ('".$param["payment_date"]."','".$param["item_number"]."','".$param["item_name"]."','".$param["quantity"]."','".$param["mc_gross"]."','".$param["payer_email"]."','".$param["payer_business_name"]."','".$param["first_name"]."','".$param["last_name"]."','".$param["address_name"]."','".$param["address_country"]."','".$param["address_city"]."','".$param["address_state"]."','".$param["address_zip"]."','".$param["address_street"]."','".$param["payment_status"]."','".$param["VERIFIED"]."') ";
			$this->db->query($sql);
		}		
	}

	function get_session_items()
	{
		if (isset($_SESSION['shopcart']))
		{
			foreach ($_SESSION['shopcart'] as $key=>$value)
			{
				$result = $this->items_ctl->get(" WHERE id=".$value['id']);

				if (!$result)
				{
					unset($_SESSION['shopcart'][$key]);
				}
			}
		}
		return (isset($_SESSION["shopcart"]))?$_SESSION["shopcart"]:array();
	}

	function get_orders($_offset=0,$_limit=0)
	{
		return $this->db->query("SELECT * FROM ".$this->config["db_prefix"]."shopcart ORDER BY id DESC LIMIT $_offset,$_limit;");
	}

	function get_db_count()
	{
		return $this->model->count_();
	}
	
}
?>
Return current item: Encaps Gallery