<?php

class Menu {

	
	
	/*************************************************
	/ This function add new Branch
	*************************************************/
	
	public static function AddMenu($data) {
		global $db;
				
		$id = $db->query_insert(TABLE_MENU_SETUP, $data);
		if($db->affected_rows > 0){
		
			$data2['userid']=$_SESSION['sess_userid'];
			$data2['action']='INSERT';
			$data2['type']=$_SESSION['sess_type'];
			$data2['description']=$_SESSION['sess_username']." has added the branch(".$data['name']."/".$data['number'].") ";
			$data2['ip']=$_SERVER['REMOTE_ADDR'];
			$data2['xip']=@getenv("HTTP_X_FORWARDED_FOR");
			$data2['lastupdated']='now()';
			
			$db->query_insert("vrs_logs", $data2);
			
			return $id;
		}else{
			return false;
		}
	
	} // AddMenu

	public static function AddMenuInUser($data) {
		global $db;
				
		$id = $db->query_insert(TABLE_USER_MENU_RIGHTS_SETUP, $data);
		if($db->affected_rows > 0){			
			return $id;
		}else{
			return false;
		}
	
	} // AddMenu In User Rights Menu

	public static function DeleteMenuSetup($userId) {
	
		global $db;
		$query = "DELETE  FROM ".TABLE_USER_MENU_RIGHTS_SETUP." WHERE us_id ='$userId'";
		//print($query);exit;
		$rows = $db->fetch_all_array($query);
	
                if($db->affected_rows > 0){
			
                        return $rows;
                }else{
			
                        return false;
                }
	}//GetBranch
	
	
	/*************************************************
	/ This function update Branchid 
	*************************************************/
	
	public static function UpdateBranch($branchid,$data) {
		global $db;
				
		$id = $db->query_update(TABLE_BRANCH,$data,"id='$branchid'");
		
		if($db->affected_rows > 0){
			
			$data2['userid']=$_SESSION['sess_userid'];
			$data2['action']='UPDATE';
			$data2['type']=$_SESSION['sess_type'];
			$data2['description']=$_SESSION['sess_username']." has updated the branch info (".$data['name']."/".$data['number'].") ";
			$data2['ip']=$_SERVER['REMOTE_ADDR'];
			$data2['xip']=@getenv("HTTP_X_FORWARDED_FOR");
			$data2['lastupdated']='now()';
			
			//$db->query_insert("vrs_logs", $data2);
			
			return $id;
		}else{
			return false;
		}
	
	} // UpdateBranch

	/*************************************************
	/ This function update UpdateMenu
	 *************************************************/

	public static function UpdateMenu($id,$data) {
		global $db;

		$id = $db->query_update(TABLE_MENU_SETUP,$data,"menu_id='$id'");

		if($db->affected_rows > 0){
			return $id;
		}else{
			return false;
		}

	} // UpdateMenu

	/**********************************************************
	/ This function will return of selected Branch
	**********************************************************/
		
	public static function GetMenu($menuid) {
	
		global $db;
		$query = "SELECT * from ".TABLE_MENU_SETUP." WHERE menu_id ='$menuid'";
		//print($query);exit;
		$rows = $db->query_first($query);
	
                if($db->affected_rows > 0){
			
                        return $rows;
                }else{
			
                        return false;
                }
	}//branchid

	public static function GetSelectedMenu($userid) {
	
		global $db;
		$query = "SELECT * from ".TABLE_USER_MENU_RIGHTS_SETUP." WHERE us_id = ".$userid."";
		//print($query);exit;
		$rows = $db->query_first($query);
	
                if($db->affected_rows > 0){
			
                        return $rows;
                }else{
			
                        return false;
                }
	}//branchid


	/**********************************************************
	/ This function will return of selected Branch
	**********************************************************/
		
	public static function GetBranchByNumber($number) {
	
		global $db;
		$query = "SELECT * from ".TABLE_MENU_SETUP." WHERE number ='$number'";
		//print($query);exit;
		$rows = $db->query_first($query);
	
                if($db->affected_rows > 0){
			
                        return $rows;
                }else{
			
                        return false;
                }
	}//GetBranch
	
	/**********************************************************
	/ This function will return   Branch list
	**********************************************************/
		
	public static function GetMenuList($filter="",$pageno="null",$pagesize="null") {
	
		global $db;
		$query = "SELECT * from ".TABLE_MENU_SETUP." ". $filter;
		//print($query);exit;
		$rows = $db->fetch_all_array($query,$pageno,$pagesize);
	
			if($db->affected_rows > 0){
			
                        return $rows;
                }else{
			
                        return false;
                }
	}//GetBranchList
	
	
	/**********************************************************
	/ This function will delete the Branch
	**********************************************************/
		
	public static function DeleteBranch($branchid) {
	
		global $db;
		
		$data['status']='D';
		$db->query_update(TABLE_BRANCH,$data,"id='$branchid'");
		
		if($db->affected_rows > 0){
			$branch=Branch::GetBranch($branchid);
			$data2['userid']=$_SESSION['sess_userid'];
			$data2['action']='DELETE';
			$data2['type']=$_SESSION['sess_type'];
			$data2['description']=$_SESSION['sess_username']." has deleted the branch (".$branch->name."/".$branch->number.") ";
			$data2['ip']=$_SERVER['REMOTE_ADDR'];
			$data2['xip']=@getenv("HTTP_X_FORWARDED_FOR");
			$data2['lastupdated']='now()';
			
			//$db->query_insert("vrs_logs", $data2);
			
			return true;
		}else{
			return false;
		}		
		
	}//DeleteBranch
	
	
	
	
	public static function GetNumRows() { global $db; return $db->GetNumRows(); }
	public static function GetNumberOfPages() { global $db; return $db->GetNumberOfPages(); }
		
	
}

?>
