<?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() {
                $id= $_SESSION['USER_AUTH_KEY'];
                $model = parent::model('customer', 'oa');
                $searchsql = " AND user_id='$id'";
                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.'customer/index.tpl');
    }
    
        public function action_add(){
            $id=$_REQUEST['id'];
            $opmode="add";
            if($id){
                $opmode="edit";
                $model = parent::model('customer', 'oa');
                $vo=$model->get_data($id);
                
            }
             $var_array = array(
                    'opmode'=>$opmode,
                    'vo'=>$vo
                );            
            TPL::assign($var_array);          
            TPL::display($this->cptpl.'customer/add.tpl');
    }
        public function action_save(){
            $arr=$_POST;
            $id=$arr['id'];
            $model = parent::model('customer', '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(){
                $ids=$_POST['id'];
                if(empty($ids)){
                     $data['info']='操作失败';
                     echo json_encode($data);
                die;
                }
                $model = parent::model('customer', 'oa');
                foreach($ids as $v){
                   $res=$model->del($v);
                }
	
                if($res){
                     $data['status']=1;
                     $data['info']='删除成功';
                } else {
                     $data['info']='操作失败';
                }
                 echo json_encode($data);
                die;
	}
}