<?php
require "./FCKeditor/fckeditor.php";
class singleAction extends CommonAction{
	private $single;
	function __construct(){
			parent::__construct();
			$this->single = new singleModel();
			$this->oFCKeditor = new FCKeditor("content") ;          // 创建FCKeditor实例，可创建多个实例
			$this->oFCKeditor->BasePath = './FCKeditor/';
		}

	function single_mod(){
			if($_REQUEST[channelid]){
				$where="where channelid=$_REQUEST[channelid]";
			}
			if($_REQUEST['do']=='add' || $_REQUEST['do']=='edit'){
			$this->assign("do",$_REQUEST['do']);
    		$this->assign("fieldform","true");
    		}
    		if($_REQUEST[id]){
    			$_POST=$this->single->find($_REQUEST[id]);

    			$this->assign("post",$_POST);
    			$this->oFCKeditor->Value=$_POST["content"];
    		}
			$total = count( $this->single->total($where));
			$this->page = new page($total,5,'');
			$val = $this->single->findAll("",$this->page->getOffset(),5,$where,"ordering");
			$fpage =$this->page->fpage();
			$this->assign("fpage",$fpage);
			$this->assign("single",$val);
			$this->assign("channelid",$_REQUEST['channelid']);
			$this->assign("FCKeditor",$this->oFCKeditor->Create());
			$this->display("admin/single/singlemod.html");
		}

	function single_insert(){

				if($_REQUEST['do']=='edit' && !empty($_REQUEST['id'])){
					if($this->single->chech_form()){
						if($this->single->mod($_POST)){
						$this->showMsg("成功修改单页","admin.php?m=single&a=single_mod&channelid=$_REQUEST[channelid]");
						}else{
							$this->showMsg("修改单页失败","admin.php?m=single&a=single_mod&channelid=$_REQUEST[channelid]");;
						}

					}else{
						$this->showMsg($this->single->getMessList(),"admin.php?m=single&a=single_mod&channelid=$_REQUEST[channelid]");
					}

				}else{
					if($this->single->chech_form()){
						if($this->single->add($_POST)){
						$this->showMsg("成功添加单页","admin.php?m=single&a=single_mod&channelid=$_REQUEST[channelid]");
						}else{
							$this->showMsg("添加单页失败","admin.php?m=single&a=single_mod&channelid=$_REQUEST[channelid]");;
						}

					}else{
						$this->showMsg($this->single->getMessList(),"admin.php?m=single&a=single_mod&channelid=$_REQUEST[channelid]");
					}
				}

	}

	function single_del(){
		if($_REQUEST["id"]=="data"){
			$_REQUEST["id"]=$_REQUEST["xm"];
		}
		if($this->single->del($_REQUEST["id"])){
			$this->showMsg("成功删除单页","admin.php?m=single&a=single_mod&channelid=$_REQUEST[channelid]");
		}else{
			$this->showMsg("删除单页失败","admin.php?m=single&a=single_mod&channelid=$_REQUEST[channelid]");
		}
	}

}
?>
