<?php

class channelAction extends CommonAction{
	private $channel;
	private $mode;

    function __construct(){
			parent::__construct();
			$this->channel=new channelModel();
	}

	function add(){


		$this->model=new manageModel();
		$list = $this->model->getModelList();
		$this->assign("model_list",$list);
		$this->display("admin/public/channel.html");

	}

	function insert(){
		if($this->channel->validate($_POST['isexternal'])){
			$_POST['htmldir']= !empty($_POST['htmldir']) ? $_POST['htmldir']   : Common::pinyin($_POST['cnname'])."/";
			$this->upload = new upload(array('filepath'=>ATTCHMENT_REAL_PATH.'channel'));
			if($this->upload->uploadFile('picdir')){
				$picname =$this->upload->getNewFileName();

				$_POST['channelpic']='channel/'.$picname;
			}else{
				$this->showMsg($this->upload->getErrorMsg(),"admin.php?m=channel&a=add");
			}


			if($this->channel->add($_POST)){
				$this->showMsg("成功添加频道","admin.php?m=channel&a=add");
			}else{
				$this->showMsg("频道添加失败","admin.php?m=channel&a=add");
			}

		}else{
			$this->showMsg($this->channel->getMessList(),"admin.php?m=channel&a=add");
		}

	}


	function edit(){
		$this->assign("channellist",$this->channel->getChannelList());
		$this->display("admin/public/channeledit.html");
	}


	function del(){
	if($_REQUEST["id"]=="data"){
		$_REQUEST["id"]=$_REQUEST["xm"];
	}
	if($this->channel->del($_REQUEST["id"])){
				$this->showMsg("成功删除频道","admin.php?m=channel&a=edit");
	}else{
				$this->showMsg("删除频道失败","admin.php?m=channel&a=edit");;
	}
	}

	function ordering(){
		if(empty($_POST['order'])){
			$this->showMsg("没有需要排序的频道","admin.php?m=channel&a=edit");
		}
		if($this->channel->valorder()){
			if($this->channel->ordering()){
				$this->showMsg("排序修改成功","admin.php?m=channel&a=edit");
			}else{
				$this->showMsg("排序修改失败","admin.php?m=channel&a=edit");
			}

		}else{
			$this->showMsg($this->channel->getMessList(),"admin.php?m=channel&a=edit");
		}
	}


	function mod(){
		$_POST=$this->channel->find($_REQUEST["id"]);
		$this->assign("post",$_POST);
		$this->model=new manageModel();
		$list = $this->model->getModelList();
		$this->assign('attchment_path',ATTCHMENT_PATH);
		$this->assign("model_list",$list);
		$this->display("admin/public/channelmod.html");
	}

	function update(){
		if($this->channel->validate($_POST['isexternal'])){
			$_POST['htmldir']= !empty($_POST['htmldir']) ? $_POST['htmldir']   : Common::pinyin($_POST['cnname'])."/";
			if(!empty($_FILES['picdir']['name'])){

				$this->upload = new upload(array('filepath'=>ATTCHMENT_REAL_PATH.'channel'));
				if($this->upload->uploadFile('picdir')){
					$picname =$this->upload->getNewFileName();
					@unlink(ATTCHMENT_REAL_PATH.$_POST['channelpic']);
					$_POST['channelpic']='channel/'.$picname;

				}else{
					$this->showMsg($this->upload->getErrorMsg(),"admin.php?m=channel&a=add");
				}

			}
			if($this->channel->mod($_POST)){
				$this->showMsg("成功修改频道","admin.php?m=channel&a=mod&id=".$_REQUEST["id"]."");
			}else{
				$this->showMsg("频道修改失败","admin.php?m=channel&a=mod&id=".$_REQUEST["id"]."");
			}

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

	}





}
?>
