<?php

Doo::loadCore('db/DooModel');

class action_log extends DooModel {

    public $aid;
    public $updatetime;
    public $time;
    public $action;
    public $sid;
    public $class;
   	public $cid;
    
   	public $status;
   	public $districtid;
   	public $city;
   	public $province;
   	public $nature;
   	public $company;
   	
    public $_table = 'CLD_action_log';
    public $_primarykey = 'aid';
    public $_fields = array('aid', 'updatetime','time', 'action','sid','class','cid','status','districtid','city','province','nature','company');

    public $iconGenerate="iconGenerate";
	public $iconReceive="iconReceive";
	public $iconBorrow="iconBorrow";
	public $iconSell="iconSell";
	public $iconUpdate="iconUpdate";
	public $iconReplace="iconReplace";
	public $iconRecycle="iconRecycle";
	public $iconLock="iconLock";
	public $iconContacts="iconContacts";

    /**
     * 拷贝日志表到存储
     */
	function copyActionLogToBakTable($tableNmae=''){
		
		if (empty($tableNmae))
			return '';
		
		$sql = "SELECT table_name FROM information_schema.TABLES WHERE table_name ='".$tableNmae."'" ;
		$query = Doo::db ()->query ( $sql );
		$result = $query->fetch ();
		if (!empty($result))
			return '';
		
		$sql = "create table ".$tableNmae." as (select * from ".$this->_table.")" ;
		$query = Doo::db ()->query ( $sql );
	}
	
	function delActionLogByAid($aid=''){
		if (empty($aid))
			return '';
		$sql ="DELETE FROM " . $this->_table . " WHERE `aid`>".$aid;
		$query = Doo::db ()->query ( $sql );
	}
	
    function getClientByCid($cid){
    	$sql = "select * from " . $this->_table . " as a left join CLD_staff as b on (a.sid=b.sid)  where a.cid= '".$cid."' " ;
		
    	$query = Doo::db ()->query ( $sql );
		
		$result = $query->fetch ();
		
		return $result;
    }
    
	function getClientByStaff($condition,$limit){
    	
    	$sql = "select * from " . $this->_table . " as a left join CLD_client as b on (a.cid=b.cid)  where 1 ".$condition." ".$limit ;
		
    	$query = Doo::db ()->query ( $sql );
		
		$result = $query->fetchAll ();
		
		return $result;
    	
    }
    
    public function getProject(){
    	
    	return $this->find ( array ('asc' => 'pid', 'asArray' => TRUE ) );
    }
    
    public function getProjectByIdList($projectid){
    	return $this->find ( array ('where' => "pid= '".$projectid."'", 'asArray' => TRUE ) );
    }
    
}

?>