<?php
/**
 * Copyright (C) LJCMS All rights reserved.
 * <E-Mail：aspcms@qq.com>
 * Url http://www.liangjing.org
 *     http://www.8CMS.com
 * Update 2016.03.19
 */

class signOModel extends X {
         public function getList($items){
                    $where      = " WHERE 1=1".$items['searchsql'];
                    $start      = ($items['page']-1)*$items['pagesize'];
                    $countsql   = "SELECT COUNT(*) AS my_count FROM ".DB_PREFIXOA."sign ".$where;
                    $total      = parent::$obj->fetch_count($countsql);
                    $sql        = "SELECT * FROM ".DB_PREFIXOA."sign ".$where." ORDER BY id desc LIMIT ".$start.", ".$items['pagesize']."";
                    $array = parent::$obj->getall($sql);
                    return array($total, $array);
        }
        
        public function get_list($where){
                $sql = "SELECT * FROM ".DB_PREFIXOA."sign WHERE ".$where."ORDER BY create_time desc";
                $array = parent::$obj->getall($sql);
		return $array;
        }
         public function get_count($where,$status){
                    $countsql   = "SELECT COUNT(*) AS my_count FROM ".DB_PREFIXOA."sign WHERE status='$status' AND ".$where;
                    $total    = parent::$obj->fetch_count($countsql);
                    return $total;
        }
  
        public function get_data($id){
	        $sql = "SELECT * FROM ".DB_PREFIXOA."sign WHERE id='".$id."'";
                return parent::$obj->fetch_first($sql);
	}


        public function get_data1($where){
	        $sql = "SELECT * FROM ".DB_PREFIXOA."sign WHERE ".$where;
                return parent::$obj->fetch_first($sql);
	}





                public function doEdit($id,$arr){
                unset($arr['id']);
                unset($arr['opmode']);   
                 unset($arr['ajax']);   
                $result = parent::$obj->update(DB_PREFIXOA.'schedule', $arr, 'id='.$id.'');
                return $result;
        }  
        public function doAdd($array) {
             $userid=$array['user_id']= $_SESSION['USER_AUTH_KEY']; 
             $sql = "SELECT * FROM ".DB_PREFIXOA."user WHERE id='".$userid."'";
             $user=parent::$obj->fetch_first($sql);
             $array['user_name']=$user['name'];
             $dept_id=$array['dept_id']=$user['dept_id'];
             $position_id=$user['position_id'];
             $sql1 = "SELECT * FROM ".DB_PREFIXOA."dept WHERE id='".$dept_id."'";
             $dept=parent::$obj->fetch_first($sql1);
             $sql2 = "SELECT * FROM ".DB_PREFIXOA."position WHERE id='".$position_id."'";
             $position=parent::$obj->fetch_first($sql2);
             $array['dept_name']=$dept['name'];
             $array['position_name']=$position['name'];
           return parent::$obj->insert(DB_PREFIXOA.'sign', $array); 
      }
      public function del($id){
        $sql = "DELETE FROM ".DB_PREFIXOA."schedule WHERE id='".intval($id)."'";
        return parent::$obj->query($sql);
      }
        
      public function popup($dept){
          $sql="SELECT User.id AS id,User.emp_no AS emp_no,User.name AS name,User.letter AS letter,User.dept_id AS dept_id,User.position_id AS position_id,User.email AS email,User.duty AS duty,User.office_tel AS office_tel,User.mobile_tel AS mobile_tel,User.pic AS pic,User.birthday AS birthday,User.sex AS sex,User.password AS password,User.is_del AS is_del,Position.name AS position_name,Dept.name AS dept_name FROM oa_user User  JOIN oa_position Position ON Position.id=User.position_id  JOIN oa_dept Dept ON Dept.id=User.dept_id WHERE User.dept_id IN ($dept) AND User.is_del = 0 ";
                          $array = parent::$obj->getall($sql);
		return $array;
      }
}
?>
