<?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() {
               //公告列表
               $public = parent::model('public', 'oa');
               $notice_list=$public->get_notice();
               
               //任务列表
               $task = parent::model('task', 'oa');
                //我未完成的任务
               $searchsql = " AND is_del='0'";  
               $user_id=$_SESSION['USER_AUTH_KEY']; 
               $sql = "SELECT `task_id` FROM ".DB_PREFIXOA."task_log WHERE type='1' AND status<'20' AND executor='$user_id'";
               $task_list=parent::$obj->getall($sql);
               if (!empty($task_list)) {
                    $task_ids="";
                    foreach ($task_list as $v){
                        $task_ids .= $v['task_id'].",";
                     }
                    $task_ids=substr($task_ids, 0, -1);
                    $searchsql .= " AND id in ($task_ids)";
                } else {
                     $searchsql .= " AND id =''";
                }
                list($total, $not_tasklist) = $task->getList(array('page'=>$this->page, 'pagesize'=>$this->pagesize, 'searchsql'=>$searchsql));
                
                //代接任务
                 $searchsql1 = " AND is_del='0'";  
				$sql1 = "select id from ".DB_PREFIXOA."task task where status=0 and not exists (select * from ".DB_PREFIXOA."task_log task_log where task.id=task_log.task_id)";
                                $task_list1=parent::$obj->getall($sql1);
                                if (!empty($task_list1)) {
                                      $task_ids1="";
                                                foreach ($task_list1 as $v){
                                                    $task_ids1 .= $v['id'].",";
                                                }
                                               $task_ids1=substr($task_ids1, 0, -1);
                                               $searchsql1 .= " AND id in ($task_ids1)";
                                }else {
                                     $searchsql1 .= " AND id =''";
                                }
                list($total1, $dai_tasklist) = $task->getList(array('page'=>$this->page, 'pagesize'=>$this->pagesize, 'searchsql'=>$searchsql1));
                
                //待办事项
                $todo = parent::model('todo', 'oa'); 
                $where=" 1=1 AND user_id='$user_id' AND status in ('1','2') ";
                $todo_list=$todo->get_list($where);
                
                //日程
                $schedul = parent::model('schedul', 'oa'); 
                $where1= " `user_id` = '$user_id' AND `is_del` = 0 ";         
		$data_list=$schedul->get_list($where1);
                $var_array = array(
                    'notice_list'=>$notice_list,
                    'not_tasklist'=>$not_tasklist,
                    'dai_tasklist'=>$dai_tasklist,
                    'todo_list'=>$todo_list,
                    'data_list'=>$data_list
                  );            
               TPL::assign($var_array);
	       TPL::display($this->cptpl.'index.tpl');
        }
        public function action_notice(){
            $id=$_REQUEST['id'];
              $public = parent::model('public', 'oa');
              $vo=$public->get_notice_data($id);
                $var_array = array(
                    'vo'=>$vo,
                  );            
               TPL::assign($var_array);
             TPL::display($this->cptpl.'notice.tpl');
        }
    
}
?>
