<?php
include_once 'include/Database.class.php';


class register
{
	 private $general;
	function __construct()
	{
	
			date_default_timezone_set("Asia/Kolkata");
			$this->now		= date("Y-m-d");
			$this->date		= date("Y-m-d H:i:s");
			$this->general	= new General();	
			$this->db		= new database();
			
			if(!$this->db->dbConnect())
			die("Error Connection".$this->db->ErrorInfo);
	}
		
	function __destruct()
	{
			$this->db->dbClose();
	}
	///user Login............////////////
	function checkLogin($POST)
	{
		$username	=	addslashes($POST['frm_username']);
		$password	=	addslashes($POST['frm_password']);
		$qry	=	"select * from user where email='$username' and password='$password' and type='User' and  						             		                 status='Active'";
	
		$row	= $this ->db ->readValue($qry);
		
		if($row)
		{
			$_SESSION['yummyuserID']=$row['user_id'];
			$_SESSION['yummyuserNAME']=$row['name'];
			$_SESSION['yummytype']=$row['type'];
			$_SESSION['yummyemail']=$row['email'];
			
			$userid	=$_SESSION['yummyuserID'];
			$this->checklastlogin($userid);
			
			$IPtrackinguser=$this->IPtrackinguser();
			
			return "Login successfull";
		}
		else
		{
			return "Invalid Username/Password";
		}
		
		
	}
	function IPtrackinguser()
	{
		$date=$this->date;
		$ip=$_SERVER['REMOTE_ADDR'];
		$user_id=$_SESSION['yummyuserID'];
		
		$sql="insert into ip_tracker(ip_address,start_time,end_time,user_id) values('$ip','$date','0000-00-00 00:00:00','$user_id')";
		$res			= 	$this->db->setQuery($sql);
		$getInsertId=$this->db->getInsertId();
		$_SESSION['ip_tracker_id_user']=$getInsertId;
		
		return "";
	}
	
	
	function ForgotPassword($POST)
	{
		$email=addslashes($POST['emailid']);
		$sql="select * from user where email='$email' and type='Hotel' and status='Active'";
		//echo $sql;exit;
		$res	= $this->db->readValue($sql);
		if($res)
		{
			return $res;
		}
		else
		{
			return "";
		}
	}


/////////////////LOGIN/////////////////////

///////////Registration////////////////////
	function selectAllCountry()
	{
		$qry  = "select * from country_database";
		$row	= $this ->db ->readValues($qry);
		return $row;
	}
	function selectAllStates()
	{
		$qry  = "select * from states";
		$row	= $this ->db ->readValues($qry);
		return $row;
	}
	function selectAllDistrict()
	{
		$qry  = "select * from districts";
		$row	= $this ->db ->readValues($qry);
		return $row;
	}
	function selectAllDistricts()
	{
		$qry  = "select * from districts";
		$row	= $this ->db ->readValues($qry);
		return $row;
	}
	function selectAllFoodTypes()
	{
		$qry  = "select * from foodtypes order by food_type ASC";
		$row	= $this ->db ->readValues($qry);
		return $row;
	}
	function insert_register($POST)
	{
		$name			=	addslashes($POST['name']);
		$gender			=	addslashes($POST['gender']);
		$dob			=	addslashes($POST['dob']);
		$emailid		=	addslashes($POST['emailid']);
		$password		=	addslashes($POST['password']);
		$address		=	addslashes($POST['address']);
		$mobno			=	addslashes($POST['mobno']);
		$phno			=	addslashes($POST['phno']);
		$location		=	addslashes($POST['location']);
		$state			=	addslashes($POST['state']);
		$country		=	addslashes($POST['country']);
		$pincode		=	addslashes($POST['pincode']);
		
		$date	=	$this->date;
		$qry	= "insert into
		user(user_id,name,email,gender,password,mobile,phone,dob,address,pin,city,state,country,description,delivery_area
		register_date,type,status) 
				  values(NULL,'$name','$emailid','$gender','$password','$mobno','$phno','$dob','$address','$pincode','$location',
						'$state','$country','','','$date','User','Active')";									
	    $res	= $this->db ->setQuery($qry);
		$id				=	mysql_insert_id();
		$Folder			=	"images/Userimages/ImageLarg/";
		$Folder1		=	"images/Userimages/ImageThumb/";
			if($_FILES['image']['name']!="")
			{
			 $ForWeb=explode(".",$_FILES['image']['name']);
			 $image			=	uniqid(rand(1,99999),false).".".$ForWeb[1];
			 $imagePath1	=	$Folder.$image;
 			 $copy			=	copy($_FILES['image']['tmp_name'],$imagePath1);
			 $size			=	getimagesize($_FILES['image']['tmp_name']);
			 $width			=	$size[0];
			 $height		=	$size[1];
			$this->general->resizeImageWdthHegt($imagePath1,$width,$height);
				
			 $imagePath2	=	$Folder1.$image;
			 $copy1			=	copy($_FILES['image']['tmp_name'],$imagePath2);
			 $size			=	getimagesize($_FILES['image']['tmp_name']);
			  
			$this->general->resizeImageWdthHegt($imagePath2,160,160);
				
			$qry1			=	"update user SET image='".$image."' where user_id='$id'";
			$res			=	$this->db->setQuery($qry1);
			}
	
		return $res;
	  }
//////***Registration**//////

/////Pagelists////////////
	function updatePages($POST,$id)
	{
		$pagename	=	trim(addslashes($POST['page_name']));
		$pagedesc	=	trim(addslashes($POST['page_desc']));
	
		$qry		=	"update pages SET  page_name='$pagename',page_desc='$pagedesc' where page_id='$id'";
		$res		= 	$this->db ->setQuery($qry);
	}

	function Insert_Pages($POST)
	{
	  $pagename	=	trim(addslashes($POST['page_name']));
	  $pagedesc	=	trim(addslashes($POST['page_desc']));
	  $qry		=	"Insert into pages (page_name,page_desc,status) values('$pagename','$pagedesc','Active')";  
	  $res		= $this->db ->setQuery($qry);
	   return $res; 
	}
//////**Pagelists**//////

//////Manage Users///////
	function getAllhotelusers($table,$field=array())
	{
		$sql	=	"select * from ".$table." where type='Hotel' ";
		if(!empty($field))
		{
		$field1=array_keys($field);
		$field2=$field1[0];
		$field3=$field[$field2];
		$sql.=" and ".$field2."='$field3' ";
		}
		$rows	= $this ->db ->readValues($sql);
		$cnt	= count($rows);
		return $cnt;
	}
	
	function getAllusers($Offset='',$RowsPerPage='',$txt_search='')
	{
		$sql="select * from user where 1=1 and type='User' and status!='Deleted' ";
		
		if($txt_search!="")
		{
			$sql.=" and (name like '%$txt_search%' or email like '%$txt_search%' or mobile like '%$txt_search%' or city like '%$txt_search%')";
		}
		
		$sql.=" order by user_id desc ";

		
		if(trim($Offset)!="" && trim($RowsPerPage)!="")
			{	$sql.=	" LIMIT $Offset,$RowsPerPage";	}
			
		$res	= $this->db ->readValues($sql);
		return $res;
	}

	function getAlluserscnt($txt_search='')
	{
		$sql="select * from user where 1=1 and type='User' and status!='Deleted' ";
		
		if($txt_search!="")
		{
			$sql.=" and (name like '%$txt_search%' or email like '%$txt_search%' or mobile like '%$txt_search%' or city like '%$txt_search%')";
		}
		
		$sql.=" order by user_id desc ";
		$res	= $this->db ->readValues($sql);
		$cnt=count($res);
		return $cnt;
	}
/////////////**Manage Users**///////////
function checklastlogin($id)
	{
		$date	=	$this->date;
		 $qry	=	"update user SET  last_login='".$date."'  where user_id='$id'";
		$res	= $this->db ->setQuery($qry);
	}
	function checklastlogin_subadmin($id)
	{
		$date	=	$this->date;
		$qry	=	"update tbl_admin SET  last_login='".$date."'  where id='$id'";
		$res	= $this->db ->setQuery($qry);
	}
////Admin Login//////
	function checkAdminLogin($POST)
	{
		$qry	=	"select * from user where email='".$POST['username']."' and password='".$POST['password']."' and  status='Active' and (type='Hotel' or type='SuperAdmin' or type='Admin')";
		$row	=  $this ->db ->readValue($qry);
		
		if($row)
		{
			$_SESSION['userID']=$row['user_id'];
			$_SESSION['type']=$row['type'];
			$_SESSION['email']=$row['email'];

			$userid	=@$_SESSION['userID'];
			$this->checklastlogin($userid);
			
			$IPtracking=$this->IPtracking();
		}else{
		$qry	=	"select * from tbl_admin where email='".$POST['username']."' and password='".$POST['password']."'  and (status='1')";
		$row	=  $this ->db ->readValue($qry);
		$_SESSION['userID']=$row['id'];
			$_SESSION['type']=$row['type'];
			$_SESSION['email']=$row['email'];

			$userid	=@$_SESSION['userID'];
			$this->checklastlogin_subadmin($userid);
			
			$IPtracking=$this->IPtracking();
		
		}
		return $row;
	}
	function IPtracking()
	{
		$date=$this->date;
		$ip=$_SERVER['REMOTE_ADDR'];
		$user_id=$_SESSION['userID'];
		
		$sql="insert into ip_tracker(ip_address,start_time,end_time,user_id) values('$ip','$date','0000-00-00 00:00:00','$user_id')";
		$res			= 	$this->db->setQuery($sql);
		$getInsertId=$this->db->getInsertId();
		$_SESSION['ip_tracker_id']=$getInsertId;
		
		return "";
	}
	function updateIPendtime()
	{
		$date=$this->date;
		$ip_tracker_id=$_SESSION['ip_tracker_id'];
		$sql="update ip_tracker set end_time='$date' where ip_tracker_id='$ip_tracker_id'";
		$res			= 	$this->db->setQuery($sql);
		return "";
	}
///*Admin login**///

////Change password///
	function Validateoldpassword($POST)
	{
		$oldpassword	=	addslashes($POST['oldpassword']);
		$user_id		=	@$_SESSION['userID'];
		
		$sql			=	"select * from user where user_id='$user_id' and password='$oldpassword' and (type='SuperAdmin' or                             type='Hotel')";
		$row			=   $this ->db ->readValue($sql);
		if($row)
		return "";
		else
		return "Oldpassword Incorrect";
	}
	function changeAdminPassword($POST)
	{

		$newpassword  	=	trim(addslashes($_POST['newpassword']));
		$user_id		=	@$_SESSION['userID'];
		$sql			=	"update user set password='$newpassword' where user_id='$user_id'";
		$res			= 	$this->db->setQuery($sql);
		return "Password changed successfully";
	}
//**change password**///

///Email Templates//////

	function updateTemplates($POST,$id)
	{

		$tempname	=	trim(addslashes($POST['temp_name']));
		$tempdesc	=	trim(addslashes($POST['temp_desc']));
		$qry		=	"update emailtemplates SET  temp_name='$tempname',temp_desc='$tempdesc' where temp_id='$id'";
		$res		= 	$this->db ->setQuery($qry);
	}

	function Insert_Templates($POST)
	{

		$tempname	=	trim(addslashes($POST['temp_name']));
		$tempdesc	=	trim(addslashes($POST['temp_desc']));
		$qry		=	"Insert into emailtemplates (temp_name,temp_desc,status) values('$tempname','$tempdesc','Active')";  
		$res		= $this->db ->setQuery($qry);
		return $res; 
	}
///**Email Templates**//////

////Questions//////
	function updateQuestions($POST,$id)
	{

		$date		=	$this->date;
		$questions	=	trim(addslashes($POST['questions']));
		$qry		=	"update question_details SET  questions='$questions',date='$date' where question_id='$id'";
		//echo $qry;exit;
		$res		= 	$this->db ->setQuery($qry);

	}

	function Insert_Questions($POST)
	{

		$date		=	$this->date;
		$questions	=	trim(addslashes($POST['questions']));
		$qry		=	"Insert into question_details (questions,date,status) values('$questions','$date','Active')";  
		$res		= 	$this->db ->setQuery($qry);
		return $res; 
	
	}
///**Questions**//////

////Restaurant Profile////////
	function Insert_Profile($POST)
	{
 		$name	=	trim(addslashes($POST['name']));
		$sub_type=  trim(addslashes($POST['sub_type']));
 		$emailid=	trim(addslashes($POST['emailid']));
		$password=	trim(addslashes($POST['password']));
 		$mobno  =	trim(addslashes($POST['mobno']));	
 		$phno   =	trim(addslashes($POST['phno']));	
 		$address=	trim(addslashes($POST['address']));
		$address2= 	trim(addslashes($POST['address2']));
		$location= 	trim(addslashes($POST['location']));
 		$pin    =	trim(addslashes($POST['pin']));	
 		$city   =	trim(addslashes($POST['city']));
 		$state  =	trim(addslashes($POST['state']));
		$district=  trim(addslashes($POST['district']));
 		$country=	trim(addslashes($POST['country']));
		$desc	=	trim(addslashes($POST['desc']));		
		$food_type		=	$POST['food_type'];
		$rest_category	=	$POST['rest_category'];
		$delivery_area=trim(addslashes($POST['delivery_area']));

		$date	=	$this->date;
		$qry	=	"Insert into user(name,email,password,mobile,phone,address,address2,address3,pin,city,state,district,country,description,
					delivery_area,register_date,type,rest_type,verification) values('$name','$emailid','$password','$mobno','$phno','$address','$address2','$location',						                          '$pin','$city','$state','$district','$country','$desc','$delivery_area','$date','Hotel','$sub_type','')"; 
		//echo $qry;exit;		
 	    $res	= 	$this->db ->setQuery($qry);
 		$id		=	mysql_insert_id();
		$insertFoodTypes=$this->insertFoodTypes($id,$food_type);
		$insertRestCategory=$this->insertRestCategory($id,$rest_category);

		
		$Folder	=	"../images/Restaurantimages/ImageLarg/";
		$Folder1=	"../images/Restaurantimages/ImageThumb/";
			if($_FILES['image']['name']!="")
			{
			 	$ForWeb=explode(".",$_FILES['image']['name']);
				$image		=   uniqid(rand(1,99999),false).".".$ForWeb[1];
			 	$imagePath1	=   $Folder.$image;
 			  	$copy		=   copy($_FILES['image']['tmp_name'],$imagePath1);
			  	$size		=	getimagesize($_FILES['image']['tmp_name']);
			  	$width		=	$size[0];
			  	$height		=	$size[1];
				$this->general->resizeImageWdthHegt($imagePath1,112,104);
				
				$imagePath2	=	$Folder1.$image;
			    $copy1		=	copy($_FILES['image']['tmp_name'],$imagePath2);
			    $size		=	getimagesize($_FILES['image']['tmp_name']);
			  
				$this->general->resizeImageWdthHegt($imagePath2,144,132);
				$qry1		=	"update user SET image='".$image."' where user_id='$id'";
			    $res	    =   $this->db->setQuery($qry1);				
			}
			

		return $res;
	 }
	function insertFoodTypes($id,$food_type)
	{
	 	$sql="delete from rest_foodtypes where user_id='$id'";
		$res	= 	$this->db ->setQuery($sql);		
		foreach($food_type as $food_id)
		{
			$sql1="insert into rest_foodtypes(user_id,food_id) values('$id','$food_id')";
			$res1	= 	$this->db ->setQuery($sql1);
		}
		return "";
	
	}
	function insertRestCategory($id,$rest_category)
	{
		$sql="delete from rest_includes where user_id='$id'";
		$res	= 	$this->db ->setQuery($sql);
		foreach($rest_category as $category)
		{
			$sql1="insert into rest_includes(user_id,rest_category_id) values('$id','$category')";
			$res1	= 	$this->db ->setQuery($sql1);
		}
		return "";
	}
	function insertRestDeliveryAreas($id,$delivery_areas)
	{
		$sql="delete from delivery_areas where user_id='$id'";
		$res	= 	$this->db ->setQuery($sql);
		foreach($delivery_areas as $delivery_area)
		{
			$sql1="insert into delivery_areas(user_id,delivery_area_id) values('$id','$delivery_area')";
			$res1	= 	$this->db ->setQuery($sql1);
		}
		return "";
	}
	
	
	function selectProfileById($id)
	{
			$qry	=	"Select * from `user` where `user_id`=$id";
			$res	=	$this->db->readValue($qry);
			return $res;
  	}	
	function updateProfile($POST,$id)
	{
		$name	=	trim(addslashes($POST['name']));
		$sub_type=  trim(addslashes($POST['sub_type']));
		$emailid=	trim(addslashes($POST['emailid']));
		$mobno  =	trim(addslashes($POST['mobno']));	
		$phno   =	trim(addslashes($POST['phno']));	
		$address=	trim(addslashes($POST['address']));
		$address2=	trim(addslashes($POST['address2']));
		$location=	trim(addslashes($POST['location']));
		$pin    =	trim(addslashes($POST['pin']));	
		$city   =	trim(addslashes($POST['city']));
		$state  =	trim(addslashes($POST['state']));
		$district=  trim(addslashes($POST['district']));
		$country=	trim(addslashes($POST['country']));
		$desc	=	trim(addslashes($POST['desc']));
		$food_type	=	$POST['food_type'];
		$rest_category	=	$POST['rest_category'];
		$delivery_area=trim(addslashes($POST['delivery_area']));
		$url=trim(addslashes($POST['url']));
		$old_url=trim(addslashes($POST['old_url']));
		$date		=	$this->date;
		$insertFoodTypes=$this->insertFoodTypes($id,$food_type);
		$insertRestCategory=$this->insertRestCategory($id,$rest_category);
			if($_FILES['image']['name']!="")
			{
				$Folder		=	"../images/Restaurantimages/ImageLarg/";
				$Folder1	=	"../images/Restaurantimages/ImageThumb/";
				$pic    	=   $this->selectProfileById($id);
 				$file		=	$pic['image'];
  				if(is_file($Folder.$file))
				{
 				unlink($Folder.$file);
				}
				if(is_file($Folder1.$file))
				{
 				unlink($Folder1.$file);
				}	
				 $ForWeb=explode(".",$_FILES['image']['name']);
				 $image		=   uniqid(rand(1,99999),false).".".$ForWeb[1];
				 $imagePath =   $Folder.$image;
 			   	 $copy		=   copy($_FILES['image']['tmp_name'],$imagePath);
			  	 $size		=	getimagesize($_FILES['image']['tmp_name']);
			  	 $width		=	$size[0];
			  	 $height	=	$size[1];
				 $this->general->resizeImageWdthHegt($imagePath,$width,$height);
				 $imagePath1=	$Folder1.$image;
			     $copy1		=	copy($_FILES['image']['tmp_name'],$imagePath1);
			     $size		=	getimagesize($_FILES['image']['tmp_name']);
				 $this->general->resizeImageWdthHegt($imagePath1,144,132);
				$qry1		=	"update user SET image='".$image."' where user_id='$id'";
			    $res	=$this->db->setQuery($qry1);
			}
			
		$qry		=	"update user SET name='$name',email='$emailid',mobile='$mobno',phone='$phno',address='$address',address2='$address2',address3='$location',pin='$pin',				city='$city',state='$state',district='$district',country='$country',description='$desc',delivery_area='$delivery_area',last_update='$date',rest_type='$sub_type',menu_url='$url' where user_id='$id'";
		//echo $qry;
		$res		= 	$this->db ->setQuery($qry);
		
		if($old_url!=$url)
		{
			$updateWebconfig=$this->updateWebconfig($url,$old_url);
			
			$addToWebConfig=$this->addToWebConfig($id,$url);
		}
		//echo "hinew";
		return "Profile updated successfully";
	}
	function addToWebConfig($id,$url)
	 {
	 			$xml = new DomDocument('1.0');
				$xml->load('../Web.config');
			
				/* first to create a list of categories */
				$categories = array();
				$XMLCategories = $xml->getElementsByTagName('rules')->item(0);
				
				$addrule=$this->addrule($xml,$url,'');
					
			$xml->save('../Web.config'); 
			// save the whole file
			$categories = $xml->saveXML($XMLCategories); 
			
			
			$xml1 = new DomDocument('1.0');
				$xml1->load('../Web.config');
			
				/* first to create a list of categories */
				$categories = array();
				$XMLCategories = $xml1->getElementsByTagName('rule');
				
				$i=0;
				foreach($XMLCategories as $key=>$values)
				{
					$i++;					
				}
				
				$addmatch=$this->addmatch($xml1,$url,'',$i);
				$addaction=$this->addaction($xml1,array('Rewrite',"menudetails.php?user_id=$id",'true'),'',$i);
				
			
			
			
			
			$xml1->save('../Web.config'); 
			// save the whole file
			@$categories = $xml1->saveXML($XMLCategories); 
			return "";
	 }
	 function addrule(DOMDocument $xml, $catID, $catName)
	 {
				$catName = $xml->createTextNode($catName); // create a node to hold the text
				$category = $xml->createElement('rule'); // create a category element
				$category->appendChild($catName); // add the text to the category element
				$category->setAttribute('name', $catID); // set the category id
					
				$XMLCategories = $xml->getElementsByTagName('rules')->item(0);
				$XMLCategories->appendChild($category); // add the new category
				return "";
					
	 } 
	 function addmatch(DOMDocument $xml, $catID, $catName,$i)
	 {
				$catName = $xml->createTextNode($catName); // create a node to hold the text
				$category = $xml->createElement('match'); // create a category element
				$category->appendChild($catName); // add the text to the category element
				$category->setAttribute('url', $catID); // set the category id
					
				$XMLCategories = $xml->getElementsByTagName('rule')->item($i-1);
				$XMLCategories->appendChild($category); // add the new category 
				return "";
					
	 } 
	 function addaction(DOMDocument $xml, $catID=array(), $catName,$i)
	 {
				$catName = $xml->createTextNode($catName); // create a node to hold the text
				$category = $xml->createElement('action'); // create a category element
				$category->appendChild($catName); // add the text to the category element
				$category->setAttribute('type', $catID[0]);
				$category->setAttribute('url', $catID[1]);
				$category->setAttribute('appendQueryString', $catID[2]); // set the category id
					
				$XMLCategories = $xml->getElementsByTagName('rule')->item($i-1);
				$XMLCategories->appendChild($category); // add the new category
				return "";
	 }
	function updateWebconfig($url,$old_url)
	{
		//echo $old_url;
		$xml = new DomDocument('1.0');
		$xml->load('../Web.config');
		
		$set="";
		/* first to create a list of categories */
		$categories = array();
		$XMLCategories = $xml->getElementsByTagName('rule');
		$i=0;
		foreach($XMLCategories as $key=>$node)
		{
			//echo $node->getAttribute('name')."<br/>";
			if($node->getAttribute('name')==$old_url)
			{
				$set=$key;
				//echo 'yes'."<br/>";
				$XMLCategories = $node->removeChild($node);
			}
		}
		$xml->save('../Web.config'); 
		$xml->saveXML($XMLCategories);
		//echo $set;exit;
		if($set!="")
		{
			$rules = $xml->documentElement;
			
			$rule = $rules->getElementsByTagName('rule')->item($set);
			
			$XMLCategories = $rule->removeChild($rule);
			$xml->save('../Web.config'); 
			$xml->saveXML($XMLCategories);
		}
		exit;
	}
	function deleteImage($id)
	{
	    $img_larg = '../images/Restaurantimages/ImageLarg/';
  		$img_thmb = '../images/Restaurantimages/ImageThumb/';
		$pic      =   $this->selectProfileById($id);
 		$image_name=	 $pic['image'];
		$img_larg1=$img_larg.$image_name;
		$img_thmb1=$img_thmb.$image_name;
   		if(file_exists($img_larg1)) 
		{
			unlink($img_larg1);
		}
		if(file_exists($img_thmb1)) 
		{
			unlink($img_thmb1);
		}
    	
		$qry	=	"update `user` set image='' where `user_id`=$id";
		$res	=	$this->db->setQuery($qry);
		return $res;
	}

    function getRestaurantById($id)
	{
		$qry	=	"Select * from `user` where `user_id`=$id";
		$res	=	$this->db->readValue($qry);
		return $res;
  	}	
	function nameExistsupdate($name,$user_id)
	{
		$name=addslashes($name);
		$sql="select * from user where type='Hotel' and name='$name' and user_id!='$user_id' and status!='Deleted'";
		$res1	= $this->db ->readValue($sql);
		return $res1;
	}
	function emailExistsupdate($emailid,$user_id)
	{
		$sql="select * from user where type='Hotel' and email='$emailid' and user_id!='$user_id' and status!='Deleted'";
		$res1	= $this->db ->readValue($sql);
		return $res1;
	}
	function emailExistsAdd($emailid)
	{
		$sql="select * from user where type='Hotel' and email='$emailid'  and status!='Deleted'";
		$res1	= $this->db ->readValue($sql);
		return $res1;
	}
	function mobileExistsupdate($mobile,$user_id)
	{
		$sql="select * from user where type='Hotel' and mobile='$mobile' and user_id!='$user_id' and status!='Deleted'";
		$res1	= $this->db ->readValue($sql);
		return $res1;
	}
	
///**Restaurant Profile***//////////

//// Advertisement //////////
function insert_Advertisement($POST)
	{
	$advt_name  = 	addslashes($POST['advt_name']);
	$state		=   $POST['advt_state'];
	//echo $state;exit;
	$advt_url   = 	addslashes($POST['advt_url']);
	$qry		=	"insert into advertisements(advt_name,advt_state,advt_url,status) values('$advt_name','$state','$advt_url','Active')";
	//echo $qry;exit;
	$res		= 	$this->db ->setQuery($qry);
	
 		$id		=	mysql_insert_id();
		$Folder	=	"../images/Advtimages/ImageLarg/";
		$Folder1=	"../images/Advtimages/ImageThumb/";
			if($_FILES['image']['name']!="")
			{
				$ForWeb=explode(".",$_FILES['image']['name']);
			 	$image		=   uniqid(rand(1,99999),false).".".$ForWeb[1];
			 	$imagePath1	=   $Folder.$image;
 			  	$copy		=   copy($_FILES['image']['tmp_name'],$imagePath1);
			  	$size		=	getimagesize($_FILES['image']['tmp_name']);
			  	$width		=	$size[0];
			  	$height		=	$size[1];
				$this->general->resizeImageWdthHegt($imagePath1,$width,$height);
				
				$imagePath2	=	$Folder1.$image;
			    $copy1		=	copy($_FILES['image']['tmp_name'],$imagePath2);
			    $size		=	getimagesize($_FILES['image']['tmp_name']);
			  
				$this->general->resizeImageWdthHegt($imagePath2,$width,$height);
				$qry1		=	"update advertisements SET advt_image='".$image."' where advt_id='$id'";
			    $res	    =   $this->db->setQuery($qry1);
			}
		return $res;
	 }
	function selectAdvtById($id)
		{
			$qry	=	"Select * from `advertisements` where `advt_id`=$id";
			$res	=	$this->db->readValue($qry);
			return $res;
  		}

	function updateAdvertisement($POST,$id)
	{
		$advt_name	=	trim(stripslashes($POST['advt_name']));
		$state		=	$POST['advt_state'];
		$advt_url	=	trim(stripslashes($POST['advt_url']));
	    $qry		=	"update advertisements SET advt_name='$advt_name',advt_state='$state',advt_url='$advt_url',status='Active' where advt_id='$id'";
		//echo $qry;exit;
		$res		= 	$this->db ->setQuery($qry);
 			if($_FILES['image']['name']!="")
			{
			    $Folder			=	"../images/Advtimages/ImageLarg/";
				$Folder1		=	"../images/Advtimages/ImageThumb/";
				$pic    =   $this->selectAdvtById($id);
 				$file	=	$pic['advt_image'];
  				if(is_file($Folder.$file))
				{
 				unlink($Folder.$file);
				}
				if(is_file($Folder1.$file))
				{
 				unlink($Folder1.$file);
				}	
				 $ForWeb=explode(".",$_FILES['image']['name']);
				 $image		=   uniqid(rand(1,99999),false).".".$ForWeb[1];
				 $imagePath =   $Folder.$image;
 			   	 $copy		=   copy($_FILES['image']['tmp_name'],$imagePath);
			  	 $size		=	getimagesize($_FILES['image']['tmp_name']);
			  	 $width		=	$size[0];
			  	 $height	=	$size[1];
				 $this->general->resizeImageWdthHegt($imagePath,$width,$height);
				 $imagePath1=	$Folder1.$image;
			     $copy1		=	copy($_FILES['image']['tmp_name'],$imagePath1);
			     $size		=	getimagesize($_FILES['image']['tmp_name']);
				 $this->general->resizeImageWdthHegt($imagePath1,$width,$height);
			   $qry1		=	"update advertisements SET advt_image='".$image."' where advt_id='$id'";	
			   $res			=	 $this->db->setQuery($qry1);
			}
	
		return $res;
	}
	
	function advt_imageExistsupdate($advt_image,$advt_id)
	{
		$sql="select * from advertisements where advt_image='$advt_image' and advt_id!='$advt_id'";
		$res1	= $this->db ->readValue($sql);
		return $res1;
	}
///****AAddvertisement*****//////////

/////Customer Reviews //////

	function getAllreviewcnt($rest_id,$user_id)
	{
		$sql="select * from customer_review where 1=1";
		if($rest_id!='')
		{
			$sql.=" and rest_id='$rest_id'";
		}
		if($user_id!='')
		{
			$sql.=" and user_id='$user_id'";
		}
		$res	= $this->db ->readValues($sql);
		
		$cnt=count($res);
		return $cnt;
	}
	function getAllreviews($Offset='',$RowsPerPage='',$rest_id='',$user_id='')
	{

		$sql="select customer_review.*,user.user_id,user.name from customer_review left join user on user.user_id=customer_review.user_id where 1=1";
		if($user_id!='')
		{
			$sql.=" and customer_review.user_id='$user_id'";
		}
		if($rest_id!='')
		{
			$sql.=" and customer_review.rest_id='$rest_id'";
		}
		if(trim($Offset)!="" && trim($RowsPerPage)!="")
		{	
			$sql.=	" LIMIT $Offset,$RowsPerPage";	
		}
		$res	= $this->db ->readValues($sql);
		//print_r($res);exit;
		return $res;
	}
	function getAllreviews1($Offset='',$RowsPerPage='',$rest_id='',$user_id='')
	{
		$sql="select user.* from customer_review left join user on user.user_id=customer_review.rest_id  where 1=1";
		
		if($user_id!='')
		{
			$sql.=" and customer_review.user_id='$user_id'";
		}
		if($rest_id!='')
		{
			$sql.=" and customer_review.rest_id='$rest_id'";
		}
		if(trim($Offset)!="" && trim($RowsPerPage)!="")
		{	
			$sql.=	" LIMIT $Offset,$RowsPerPage";	
		}
			
		$res1	= $this->db ->readValues($sql);
		return $res1;
	}

////***Customer Reviews***//////////

/////////////Partners Details////
function insert_Partners($POST)
	{
	$partner_name  = 	addslashes($POST['partner_name']);
	$qry		=	"insert into  partners(partner) values('$partner_name')";
	$res		= 	$this->db ->setQuery($qry);
	
 		$id		=	mysql_insert_id();
		//$Folder	=	"../images/PartnersLogos/ImageLarg/";
		$Folder1=	"../images/PartnersLogos/ImageThumb/";
			if($_FILES['image']['name']!="")
			{
				$ForWeb=explode(".",$_FILES['image']['name']);
			 	$image		=   uniqid(rand(1,99999),false).".".$ForWeb[1];
			 	/*$imagePath1	=   $Folder.$image;
 			  	$copy		=   copy($_FILES['image']['tmp_name'],$imagePath1);
			  	$size		=	getimagesize($_FILES['image']['tmp_name']);
			  	$width		=	$size[0];
			  	$height		=	$size[1];
				$this->general->resizeImageWdthHegt($imagePath1,$width,$height);*/
				$imagePath2	=	$Folder1.$image;
			    $copy1		=	copy($_FILES['image']['tmp_name'],$imagePath2);
			    $size		=	getimagesize($_FILES['image']['tmp_name']);
			  
				$this->general->resizeImageWdthHegt($imagePath2,81,70);
				$qry1		=	"update  partners SET logo='".$image."' where partner_id='$id'";
			    $res	    =   $this->db->setQuery($qry1);
			}
		return $res;
	 }
	function selectPartnersById($id)
	{
			$qry	=	"Select * from `partners` where `partner_id`=$id";
			$res	=	$this->db->readValue($qry);
			return $res;
  	}

	function updatePartners($POST,$id)
	{
		$partner_name	=	trim(addslashes($POST['partner_name']));
	    $qry		=	"update partners SET partner='$partner_name' where partner_id='$id'";
		$res		= 	$this->db ->setQuery($qry);
 			if($_FILES['image']['name']!="")
			{
				//$Folder	=	"../images/PartnersLogos/ImageLarg/";
				$Folder1=	"../images/PartnersLogos/ImageThumb/";
				$pic    =   $this->selectPartnersById($id);
 				$file	=	$pic['logo'];
  			/*if(is_file($Folder.$file))
				{
 				unlink($Folder.$file);
				}*/
				if(is_file($Folder1.$file))
				{
 				unlink($Folder1.$file);
				}	
				 $ForWeb=explode(".",$_FILES['image']['name']);
				 $image		=   uniqid(rand(1,99999),false).".".$ForWeb[1];
				 /*$imagePath =   $Folder.$image;
 			   	 $copy		=   copy($_FILES['image']['tmp_name'],$imagePath);
			  	 $size		=	getimagesize($_FILES['image']['tmp_name']);
			  	 $width		=	$size[0];
			  	 $height	=	$size[1];
				 $this->general->resizeImageWdthHegt($imagePath,$width,$height);*/
				 $imagePath1=	$Folder1.$image;
			     $copy1		=	copy($_FILES['image']['tmp_name'],$imagePath1);
			     $size		=	getimagesize($_FILES['image']['tmp_name']);
				 $this->general->resizeImageWdthHegt($imagePath1,81,70);
			     $qry1		=	"update partners SET logo='".$image."' where partner_id='$id'";			  
			     $res		=	 $this->db->setQuery($qry1);
		   }
		return $res;
	}

////***Partners Details**//////
///////Offers/////////////
function insert_Offer($POST)
	{
	$offer_name  = 	addslashes($POST['offer_name']);
	$vouchercode =  $POST['vouchercode'];
	$userids = $POST['userids'];
	$state		=   $POST['offer_state'];
	$rest_type		=	$_POST['restaurant_type'];
	//echo $state;exit;
	$offer_url   = 	addslashes($POST['offer_url']);
	$image_url   = 	addslashes($POST['image_url']);
	$qry		=	"insert into offers(user_id,offer_name,vouchercode,offerrest_type,offer_url,offer_state,image_url,offer_image,status) values('$userids','$offer_name','$vouchercode','$rest_type','$offer_url','$state','image_url','','Active')";
	//echo $qry;exit;
	$res		= 	$this->db ->setQuery($qry);
	
 		$id		=	mysql_insert_id();
		$Folder	=	"../images/Offerimages/ImageLarg/";
		$Folder1=	"../images/Offerimages/ImageThumb/";
			if($_FILES['image']['name']!="")
			{
				$ForWeb=explode(".",$_FILES['image']['name']);
			 	$image		=   uniqid(rand(1,99999),false).".".$ForWeb[1];
			 	$imagePath1	=   $Folder.$image;
 			  	$copy		=   copy($_FILES['image']['tmp_name'],$imagePath1);
			  	$size		=	getimagesize($_FILES['image']['tmp_name']);
			  	$width		=	$size[0];
			  	$height		=	$size[1];
				$this->general->resizeImageWdthHegt($imagePath1,$width,$height);
				
				$imagePath2	=	$Folder1.$image;
			    $copy1		=	copy($_FILES['image']['tmp_name'],$imagePath2);
			    $size		=	getimagesize($_FILES['image']['tmp_name']);
			  
				$this->general->resizeImageWdthHegt($imagePath2,$width,$height);
				$qry1		=	"update offers SET offer_image='".$image."' where offer_id='$id'";
			    $res	    =   $this->db->setQuery($qry1);
			}
		return $res;
	 }
	function selectOfferById($id)
		{
			$qry	=	"Select * from `offers` where `offer_id`=$id";
			$res	=	$this->db->readValue($qry);
			return $res;
  		}

	function updateOffer($POST,$id)
	{
		$offer_name	=	trim(stripslashes($POST['offer_name']));
		$vouchercode=	$POST['vouchercode'];
		$state		=	$POST['offer_state'];
		$offer_url	=	trim(stripslashes($POST['offer_url']));
		$image_url	=   trim(stripslashes($POST['image_url']));
	    $qry		=	"update offers SET offer_name='$offer_name',vouchercode='$vouchercode',
		offer_url='$offer_url',offer_state ='$state',image_url='$image_url',status='Active' where offer_id='$id'";
		//echo $qry;exit;
		$res		= 	$this->db ->setQuery($qry);
 			if($_FILES['image']['name']!="")
			{
			    $Folder			=	"../images/Offerimages/ImageLarg/";
				$Folder1		=	"../images/Offerimages/ImageThumb/";
				$pic    =   $this->selectOfferById($id);
 				$file	=	$pic['offer_image'];
  				if(is_file($Folder.$file))
				{
 				unlink($Folder.$file);
				}
				if(is_file($Folder1.$file))
				{
 				unlink($Folder1.$file);
				}	
				 $ForWeb=explode(".",$_FILES['image']['name']);
				 $image		=   uniqid(rand(1,99999),false).".".$ForWeb[1];
				 $imagePath =   $Folder.$image;
 			   	 $copy		=   copy($_FILES['image']['tmp_name'],$imagePath);
			  	 $size		=	getimagesize($_FILES['image']['tmp_name']);
			  	 $width		=	$size[0];
			  	 $height	=	$size[1];
				 $this->general->resizeImageWdthHegt($imagePath,$width,$height);
				 $imagePath1=	$Folder1.$image;
			     $copy1		=	copy($_FILES['image']['tmp_name'],$imagePath1);
			     $size		=	getimagesize($_FILES['image']['tmp_name']);
				 $this->general->resizeImageWdthHegt($imagePath1,$width,$height);
			   $qry1		=	"update offers SET offer_image='".$image."' where offer_id='$id'";	
			   $res			=	 $this->db->setQuery($qry1);
			}
	
		return $res;
	}
	
	function offer_imageExistsupdate($offer_image,$offer_id)
	{
		$sql="select * from offers where offer_image='$offer_image' and offer_id!='$offer_id'";
		$res1	= $this->db ->readValue($sql);
		return $res1;
	}

//////////Offers////////////

	function getUsersMailid()
	{
		$sql	=	"select email,name,mobile from user where type='User' and status='Active'";
		//echo $sql;exit;
		$res	= $this->db ->readValues($sql);
		return $res;
	}
	function insert_foodtype($POST)
	{
		$food_type		=	$POST['food_type'];
		
		$sql="insert into foodtypes(food_type) values('$food_type')";
		$res			=	 $this->db->setQuery($sql);
		
		return "Food type added successfully";
	}
	function update_foodtype($POST,$food_id)
	{
		$food_type		=	$POST['food_type'];
		
		$sql="update foodtypes set food_type='$food_type' where food_id='$food_id'";
		$res			=	 $this->db->setQuery($sql);
	}
	//---------------------------------------Careers-sibu------------------------------ 
	function Add_opportunity()
	{
	     $sql= "insert into ".$this->tablename."(".$this->fields.") values(".$this->vals.")";
		 	
		//print $sql;exit;
		mysql_query($sql)or die(mysql_error());
		$this->data_id = mysql_insert_id();
	}
	
	function updatecareers($POST,$page_id)
	{
		$pagename	=	trim(addslashes($POST['page_name']));
		$pagedesc	=	trim(addslashes($POST['page_desc']));
		
		$qry		=	"update career SET  career_title='$pagename',career_content='$pagedesc',career_status='$this->status',upd_date='$this->date' where career_id='$page_id'";
				
		$res		= 	$this->db ->setQuery($qry);		 	
		//print $sql;exit;
		return "Food type added successfully";
	
		
	}	
	
  //------------------------------End-------------------------------------	
	
}

?>
