<?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 positionOModel 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."position ".$where;
                    $total      = parent::$obj->fetch_count($countsql);
                    $sql        = "SELECT * FROM ".DB_PREFIXOA."position ".$where." ORDER BY sort asc LIMIT ".$start.", ".$items['pagesize']."";
                    $array = parent::$obj->getall($sql);
                    return array($total, $array);
        }

  
        public function get_top_menu_data($id){
	        $sql = "SELECT * FROM ".DB_PREFIXOA."position WHERE id='".$id."'";
                return parent::$obj->fetch_first($sql);
	}
        public function get_menu_list(){
            $sql='SELECT `id`,`name` FROM `oa_position` ORDER BY sort asc';
            $list = parent::$obj->getall($sql);
            return $list;
        }


               public function doEdit($id,$arr){
                 
                unset($arr['id']);
                unset($arr['opmode']);
                unset($arr['ajax']);           
                $result = parent::$obj->update(DB_PREFIXOA.'position', $arr, 'id='.$id.'');
                return $result;
        }  
        public function doAdd($array) {
          
             unset($array['ajax']);
             unset($array['opmode']);
             unset($array['position_no']);
              
           return parent::$obj->insert(DB_PREFIXOA.'position', $array); 
      }
      public function del($id){
        $sql = "DELETE FROM ".DB_PREFIXOA."position WHERE id='".intval($id)."'";
        return parent::$obj->query($sql);
      }
      
      public function popup($id){
          $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.position_id = '$id' AND User.is_del = 0 ";
     $array = parent::$obj->getall($sql);
		return $array;
          }
        
}
?>
