<?php 
class Online_cart_Controller extends Front_Controller{
	function __construct(){
		parent::__construct();
		$this->html		=	new Html_Model();
		$this->channel	=	new Model_Channel_Model();
		$this->content	=	new Model_content_Model();
		$this->modelhtml=	new Model_html_Model();
		$this->db	=	new Database();
		$this->cat		=	new Model_category_Model();
		if(!@$_SESSION['order_number']){	$_SESSION['order_number']	=	date("YmdHis",time());	}
		if(@$_SESSION['order_number']){	
			if(is_array(@$_SESSION['order_data'])){
				$this->sum	=	count($_SESSION['order_data']);
			}	
		}
	}
	function index(){
		$this->lmtpl->content->title	=	"在线订购";
		$this->lmtpl->render("skins/web/online.html");
	}
	function add($contentid=false){
		if($this->input->post()){
			$order_number		=	$_SESSION['order_number'];
			$formdata			=	$this->input->post("form");
			$data			=	array("order_number"=>$order_number,"times"=>time(),"data"=>var_export($formdata,true));
			$this->db->insert("order",$data);
			unset($_SESSION['order_number']);
			unset($_SESSION['order_data']);
			$this->Report($message='提交订单成功',$url='/',$encode=true);
		}
		else{	
			$this->Report($message='操作非法',$url='/',$encode=true);
		}
	}
	function cart(){
		$ls			=	$this->db->in("content_id",$_SESSION['order_data'])->get("product_content")->result_array();
		$this->lmtpl->content->title	=	"我的购物车";
		$this->lmtpl->l	=	$ls;
		$this->lmtpl->render("skins/web/online2.html");
	}
	function delete($contentid){
		foreach($_SESSION['order_data'] as $conid){
			if($contentid!=$conid)			$ids[]	=	$conid;
		}
		$_SESSION['order_data']		=	$ids;
		$this->cart();
	}
}