<?php 
class Fav_Controller extends Front_Controller{
	function __construct(){
		parent::__construct();
		$this->lmtpl->user		=	$_SESSION['user'];
		$this->html				=	new Html_Model();
		$this->fav				=	new Fav_Model();
	}
	function index(){
		$this->lmtpl->fav		=	$this->fav->getFavs($_SESSION['user']->user_id)->result_array();
		$this->lmtpl->title		=	"我的收藏夹";
		$this->lmtpl->render(self::tplpath("member_fav"));
	}
	function add($channelid,$catid,$contentid){
		if(@$_SESSION['user']){
			$data	=	array(
				"channel_id"	=>	$channelid,
				"content_id"	=>	$contentid,
				"memberid"		=>	$_SESSION['user']->user_id,
				"url"			=>	$this->html->url($channelid,$catid,$contentid)
			);
			
			if($this->fav->getfav($data)->count()==0){
				$data['time']	=	time();
				$this->fav->add($data);
				$res['statusmessage']=	"收藏成功！";
			}
			else{
				$res['statusmessage']=	"已经收藏过了！";
			}
		}
		else{
			$res['statusmessage']=	"你未登录！";
		}
		echo json_encode($res);
	}
	function delete($favid){
		if($this->input->post()){
		}
		else{
			$favids[]	=	$favid;
		}
		$this->fav->delete($favids,$_SESSION['user']->user_id);
		unset($_POST);
		$this->index();
	}
}