<?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() {
                $keyword=$_POST['keyword'];
                $model = parent::model('position', 'oa');
	        $searchsql = "";
                if ($keyword!='') {
                    $searchsql .= " AND position_no LIKE '%".$keyword."%' OR name LIKE '%".$keyword."%'";
                }
                list($total, $data) = $model->getList(array('page'=>$this->page, 'pagesize'=>$this->pagesize, 'searchsql'=>$searchsql));
                $url = XRequest::getPhpSelf();
                $url .= '?c=Position';
                $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.'position/position.tpl');
        }
        
        	/**编辑页面 **/
	public function action_read() {
                $id=$_REQUEST['id'];
		$model = parent::model('position', 'oa');
		$vo = $model -> get_top_menu_data($id);
		
			if (!empty($vo)) {// 读取成功
				$return['data'] = $vo;
				$return['status'] = 1;
				$return['info'] = "读取成功";
				echo json_encode($return);
			} else {
				$return['status'] = 0;
				$return['info'] = "读取错误";
				echo json_encode($return);
			}
		
		//$this -> assign('vo', $vo);
	//	$this -> display();
		//return $vo;
	}
        public function action_add(){
             	
             TPL::display($this->cptpl.'position/add.tpl');
        }

        public function action_save(){
            $arr=$_POST;
            $id=$arr['id'];
            $model = parent::model('position', 'oa');
              $arr=$this->SafeFilter($arr);
            if($arr['opmode']=='add'){
                $result = $model->doadd($arr);
                 $data['status']=1;
                $data['info']="编辑成功";
            
                 echo json_encode($data);die;
            }else{
                $result = $model->doEdit($id, $arr);
            }
            if (true === $result) {
                XHandle::halt('编辑成功', $this->cpfile.'?c=Position', 0);    
            }
            else {
                XHandle::halt('操作失败', $this->cpfile.'?c=Position', 0);    
            }
         
        }
        
 
        public function action_del(){
                $id=$_POST['id'];
                if($id==''){
                     $data['info']='操作失败';
                     echo json_encode($data);
                die;
                }
                $model = parent::model('position', 'oa');
		
		$res=$model->del($id);
                if($res){
                     $data['status']=1;
                     $data['info']='删除成功';
                } else {
                     $data['info']='操作失败';
                }
                 echo json_encode($data);
                die;
	}
    
}
?>
