<?php
/**
 * [LJCMS] (C)2012-2099 LJdev,Inc.
 * <E-Mail：aspcms@qq.com>
 * Url http://www.liangjing.org
 *     http://www.8CMS.com
 * Update 2014.04.03
*/

class control extends oabase {
    
	public function action_run() {
                $model = parent::model('notice', 'oa');
	        $searchsql = "";
                list($total, $data) = $model->getList(array('page'=>$this->page, 'pagesize'=>$this->pagesize, 'searchsql'=>$searchsql));
                $url = XRequest::getPhpSelf();
                $url .= '?c=Notice';
                $var_array = array(
                    'page'=>$this->page,
                    'nextpage'=>$this->page+1,
                    'prepage'=>$this->page-1,
                    'pagecount'=>ceil($total/$this->pagesize),
                    'pagesize'=>$this->pagesize,
                    'total'=>$total,
                    'showpage'=>XPage::index($total, $this->pagesize, $this->page, $url, 10),
                    'list'=>$data,
                );
                 unset($model);
		TPL::assign($var_array);
	       TPL::display($this->cptpl.'notice/index.tpl');
        }
        public function action_add(){
               $id=$_REQUEST['id'];
               $opmode="add";
               if($id){
                   $opmode="edit";
                   $model = parent::model('notice', 'oa');
                   $vo=$model->get_top_menu_data($id);

               }
                $var_array = array(
                       'opmode'=>$opmode,
                       'vo'=>$vo
                   );            
               TPL::assign($var_array);          
               TPL::display($this->cptpl.'notice/add.tpl');           
        }
        public function action_save(){
            $arr=$_POST;
            $id=$arr['id'];
            $model = parent::model('notice', 'oa');
             $arr=$this->SafeFilter($arr);
            if($arr['opmode']=='add'){
                $result = $model->doadd($arr);
            }else{
                $result = $model->doEdit($id, $arr);
            }
            if (true === $result) {
                $data['status']=1;
                $data['info']="编辑成功";
            }
            else {
                $data['info']="编辑失败";
            }
            echo json_encode($data);
        }
               public function action_del(){
                $id=$_GET['id'];
                if(empty($id)){
                       XHandle::halt('操作失败', '', 1);
                die;
                }
                $model = parent::model('notice', 'oa');

                $res=$model->del($id);
         
	
                if($res){
                        XHandle::halt('删除成功', $this->cpfile.'?c=Notice', 0);
                } else {
                     XHandle::halt('删除失败', '', 1);
                }
	}
}