<?php 
class Flink_Controller extends Base_Controller{
	function __construct(){
		parent::__construct();
		$this->flink	=	new Flink_Model();
	}
	function index(){
		$this->view			=	new View("flink/index");
		$this->view->flinks	=	$this->flink->lists();
		$this->display();
	}
	function add(){
		if($this->input->post()){
			$flink	=	$this->input->post("flink");
			$flink['time']=time();
			$this->flink->add($flink);
			$this->main->message		=	"添加新友情连接成功";
			$this->main->message_type	=	"success";
			$this->index();
		}
		else{
			$this->view	=	new View("flink/add");
			$this->main->formAction="flink/add";
			$this->main->is_validator=true;
			$this->display();
		}
	}
	function edit($fid=0){
		if($this->input->post()){
			$flink	=	$this->input->post("flink");
			$fid	=	$this->input->post("fid");
			$this->flink->update($fid,$flink);
			$this->main->message		=	"操作成功";
			$this->main->message_type	=	"success";
			$this->index();
		}
		else{
			$this->view=	new View("flink/add");
			$this->main->formAction="flink/edit";
			$this->main->is_validator=true;
			$this->view->flink	=	$this->flink->getFlink($fid);
			$this->display();
		}
	}
	function delete($fid=0){
		if($this->input->post()){
			$id	=	$this->input->post('select_id');
		}
		else{
			$id[]=	$fid;
		}
		$this->flink->delete($id);
		$this->index();
	}
	
}