<?php

class User_setup {
 
 
	/*************************************************
	/ This function add new Agent to user_setup
	*************************************************/
	
	
	
	public static function AddUserSetup($data) {
		global $db;
				
		$id = $db->query_insert(TABLEUSETUP, $data);
		if($db->affected_rows > 0){
			//$db->query_insert("vrs_logs", $data);
			return $id;
		}else{
			return false;
		}
	
	} // AddBranch
	
	 
	/*************************************************
	/ This function update agentid to user_setup
	*************************************************/
	
	
	public static function UpdateUserSetup($id,$data) {
		global $db;
				
		$id = $db->query_update(TABLEUSETUP,$data,"us_id='$id'");
		
		if($db->affected_rows > 0){
			
			//$db->query_insert("vrs_logs", $data2);
			
			return $id;
		}else{
			return $id;
		}
	
	} // UpdateBranch
	/**********************************************************
	/ This function will return of selected agent user_setup
	**********************************************************/
		
	public static function GetUserAgent($agentid) {
	
		global $db;
		$query = "SELECT * from ".TABLEUSETUP." WHERE agentid ='$agentid'";
		//print($query);exit;
		$rows = $db->query_first($query);
	
                if($db->affected_rows > 0){
			
                        return $rows;
                }else{
			
                        return false;
                }
	}//agentid

	/**********************************************************
	/ This function will return of selected GetSurveyorByUser
	 **********************************************************/

	public static function GetSurveyorByUser($userid) {

		global $db;
		$query = "SELECT *, sur.id AS surveyorid from ".TABLEUSETUP." AS us JOIN ".TABLE_SOSETUP." AS sur ON us.profile_id = sur.id WHERE us.type = 'surveyor' AND us_id ='$userid'";
		//print($query);exit;
		$rows = $db->query_first($query);

		if($db->affected_rows > 0){

			return $rows;
		}else{

			return false;
		}
	}//GetSurveyorByUser

	/**********************************************************
	/ This function will check user by email
	**********************************************************/
		
	public static function CheckUserSetupByEmail($email,$id) {
	
		global $db;
		$query = "SELECT * from ".TABLEUSETUP." WHERE email ='$email' && us_id <> '$id'";
		//print($query);exit;
		$rows = $db->query_first($query);
			if ($db->affected_rows  > 0 ) {
				return true; 
			}
			else{
				return false; 
			}

	}

/*
	public static function CheckAgentCode($a_code, $id) {
	
		global $db;
		$query = "SELECT * from ".TABLE_AGENTSETUP." WHERE agency_code ='$a_code' && a_id <> '$id'";
		//print($query);exit;
		$rows = $db->query_first($query);
	
                if($db->affected_rows > 0){
			
                        return $rows;
                }else{
			
                        return false;
                }
	}



*/
	public static function CheckUserSetupByUsername($name, $id) {
	
		global $db;
		$query = "SELECT * from ".TABLEUSETUP." WHERE username ='$name' && us_id <> '$id'";
		//print($query);exit;
		$rows = $db->query_first($query);
			if ($db->affected_rows  > 0 ) {
				return true; 
			}
			else{
				return false; 
			}

	}


	/**********************************************************
	/ This function will check user by ID
	**********************************************************/
		
	
	public static function GetUserSetupId($id) {

			global $db;
			$query = "SELECT * from ".TABLEUSETUP."  where us_id='$id'";
			//print($query);exit;
			$rows = $db->query_first($query);

				if($db->affected_rows > 0){

							return $rows;
					}else{

							return false;
					}
		}//GetPolicy 


	/**********************************************************
	/ This function will check user by ID
	**********************************************************/
		
	
	public static function GetUserSetupEmail($username) {

			global $db;
			$query = "SELECT * from ".TABLEUSETUP."  where username = '$username'";
			//print($query);exit;
			$rows = $db->query_first($query);

				if($db->affected_rows > 0){

							return $rows;
					}else{

							return false;
					}
		}//GetPolicy 
	
	/**********************************************************
	/ This function will return   agent user_setup list 
	/ This function will return   agent user_setup list 
	**********************************************************/
		
	public static function GetUserSetupList($filter="",$pageno="null",$pagesize="null") {
	
		global $db;
		$query = "SELECT * from ".TABLEUSETUP." AS us ". $filter;
		//print($query);exit;
		$rows = $db->fetch_all_array($query,$pageno,$pagesize);
	
			if($db->affected_rows > 0){
			
                        return $rows;
                }else{
			
                        return false;
                }
	}//GetagentList
	
	
	/**********************************************************
	/ This function will delete the agent user_setup
	**********************************************************/
		
	public static function DeleteUserAgent($agentid) {
	
		global $db;
		
		$data['status']='D';
		$db->query_update(TABLEUSETUP,$data,"agentid='$agentid'");
		
		if($db->affected_rows > 0){
			 
			//$db->query_insert("vrs_logs", $data2);
			
			return true;
		}else{
			return false;
		}		
		
	}//DeleteAgent
	
	
	
	
	public static function GetNumRows() { global $db; return $db->GetNumRows(); }
	public static function GetNumberOfPages() { global $db; return $db->GetNumberOfPages(); }
		
	
}

?>
