<?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('work', '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=Work';
                $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.'work/index.tpl');
    }
    
        public function action_add(){
            $id=$_REQUEST['id'];
            $opmode="add";
            if($id){
                $opmode="edit";
                $model = parent::model('work', 'oa');
                $vo=$model->get_data($id);
                
            }
             $var_array = array(
                    'opmode'=>$opmode,
                    'vo'=>$vo
                );            
            TPL::assign($var_array);          
            TPL::display($this->cptpl.'work/add.tpl');
    }
        public function action_save(){
            $arr=$_POST;
            $id=$arr['id'];
            $model = parent::model('work', '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;
	}
        
                public function action_work_shen() {
               $keyword=$_POST['keyword'];

	        $searchsql = "";
                if ($keyword!='') {
                    $searchsql .= " AND user_name LIKE '%".$keyword."%'";
                }
                $dept = parent::model('dept', 'oa');
                $dept_id=$_SESSION['dept_id'];
                $deptinfo = $dept -> get_top_menu_data($dept_id);
                $searchsql.=" AND status='0'";
                if($deptinfo['pid']!=0){
                    $user = parent::model('user', 'oa');
                    $where ="dept_id='$dept_id' AND is_del='0'";
                    $user_list=$user->get_List($where);
                    $search="";
                    foreach($user_list as $v){
                         $search .=$v['id'].",";
                    }
                    $search=substr($search,0,strlen($search)-1); 
                    $searchsql .=" AND user_id in ($search)";
                }
                $model = parent::model('work', 'oa');
                list($total, $data) = $model->getList(array('page'=>$this->page, 'pagesize'=>$this->pagesize, 'searchsql'=>$searchsql));
                $url = XRequest::getPhpSelf();
                $url .= '?c=Work';
                $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.'work/work_shen.tpl');
    }
           public function action_work_edit(){
              $id=$_REQUEST['id'];
              $type=$_REQUEST['type'];
              if($type==1){
                  $arr['status']=1;
                  $arr['shen_msg']="审核通过";
              } elseif ($type==2){
                  $arr['status']=2;
                  $arr['shen_msg']=$_REQUEST['replay'];
              }
              $arr['auditor']=$_SESSION['user_name'];
              $arr['update_time']= time();
           //   print_r($arr);die;
              $model = parent::model('work', 'oa');
  
               $result = $model->doEdit($id, $arr);
                
                if (true === $result) {
                    $data['status']=1;
                    $data['info']="编辑成功";
                }
                else {
                    $data['info']="编辑失败";
                }
                echo json_encode($data);              
        }
                  public function action_work_replay(){
               $id=$_REQUEST['id'];
                $var_array = array(
                       'id'=>$id,
                   );            
               TPL::assign($var_array);          
               TPL::display($this->cptpl.'work/work_reply.tpl');           
        }
}