<?php
//mysql_connect("localhost","root","") or die("Error1:".mysql_error());
//mysql_select_db("buda_hotel_dbms") or die("Error2:".mysql_error());
class house_class{

     public  $dbcon;
     public  $host="localhost";
     public  $dbname="aiderste_house_rent";
     public  $user="aiderste_aiderstech";
     public  $pwd="Aid@2022_2023";

                                      //FUNCTION FOR DATABASE CONNECTION GOES HERE
 
function __construct(){
	
		   $this->dbcon = new PDO("mysql:dbname=$this->dbname;host=$this->host",$this->user,$this->pwd);
          
}




 ////////////////////////STRICT_ALL_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ZERO_DATE,NO_ZERO_IN_DATE,NO_AUTO_CREATE_USER////
 /////////////////FUNCTION RETRIEVING SHOP SPECIFIC ITEM/////////
function getMyAllInquiry($receiverid){
	try{
		$ownerH=$this->dbcon->prepare("select * from inquirysms where receiverid=:rid  order by postDate DESC");
	   // $ownerH->bindParam(":id",$house_no);
	    //$ownerH->bindParam(":Id",$roomid); 
	    $ownerH->bindParam(":rid",$receiverid); 
	   // $ownerH->bindParam(":sid",$receiverid);   
	    $ownerH->execute(); 
		  
		return $ownerH;

	}
	catch(PDOException $xc){
		$xc->getMessage();
	}
}
////////////////////////GET ITEM FROM THIS HOUSE///////////////////////
////////////////////////////   DATE OF DEPART///////////////////
function deleteThisMyHouseRoom($house_no,$room_no){
	
     
     

	 $data=array($house_no,$room_no);
       try{
	
	      $Qr=$this->dbcon->prepare("delete from rooms where house_no=? and roomid=?");
	     
	     $Qr->execute($data);
	      
	      if ($Qr->rowCount()>0) {
////////////
	        $Qr2=$this->dbcon->prepare("delete from roomimages where house_no=? and roomid=?");
	     
	        $Qr2->execute($data);
	      
	      if ($Qr2->rowCount()>0) {
	           return $Qr2;//= //$Re="Oops your network is low to upload data!..";
	           } 
	           else
	         {
                return $Qr=$Qr2->ErrorInfo();
	           }
	        

	           //= //$Re="Oops your network is low to upload data!..";
	           } 
	           else
	         {
                return $Qr=$Qr->ErrorInfo();
	           }
	       } 

         

 
      catch(PDOException $ex){
	  $ex->getMessage();
}
} 

//////////////////////// ITEM DETAIL VALIDATIO NEND//////////////

////////////////////////////   DATE OF DEPART///////////////////
function updateHouseRoomStatusSetFree($house_no,$room_no){
	
      $status="Free";
     

	 $data=array($status,$house_no,$room_no);
       try{
	
	      $Qr=$this->dbcon->prepare("update rooms set status=? where house_no=? and roomid=?");
	     
	     $Qr->execute($data);
	      
	      if ($Qr->rowCount()>0) {
	           return $Qr;//= //$Re="Oops your network is low to upload data!..";
	           } 
	           else
	         {
                return $Qr;//=$Qr->ErrorInfo();
	           }
	       } 

         

 
      catch(PDOException $ex){
	  $ex->getMessage();
}
} 

//////////////////////// ITEM DETAIL VALIDATIO NEND//////////////
////////////////////////////   DATE OF DEPART///////////////////
function updateHouseRoom($category,$rcost,$currency,$cduration,$description,$house_no,$room_no){
	
      
     

	 $data=array($category,$rcost,$currency,$cduration,$description,$house_no,$room_no);
       try{
	
	      $Qr=$this->dbcon->prepare("update rooms set category=?,cost=?,currency=?,contract_duration=?,finishingdisc=? where house_no=? and roomid=?");
	     
	     $Qr->execute($data);
	      
	      if ($Qr->rowCount()>0) {
	           return $Qr;//= //$Re="Oops your network is low to upload data!..";
	           } 
	           else
	         {
                return $Qr=$Qr->ErrorInfo();
	           }
	       } 

         

 
      catch(PDOException $ex){
	  $ex->getMessage();
}
} 

//////////////////////// ITEM DETAIL VALIDATIO NEND//////////////


	           /////////////////////
	           //////////////////ADD ROUTE FUNCTION GOES HERE
	           ///////////////////////                   


function addHouseRoom($house_no,$room_no,$category,$rcost,$currency,$cduration,$description,$imgdescription,$fn,$tmp_name){
	
      
     $site="../houseroomimages/".$fn;
     $status="Busy";

	 $data=array($house_no,$room_no,$category,$rcost,$currency,$cduration,$status,$description);
       try{
	
	      $Qr=$this->dbcon->prepare("insert into rooms(	house_no,roomid,category,cost,currency,contract_duration,status,finishingdisc) values(?,?,?,?,?,?,?,?)");
	     
	     $Qr->execute($data);
	      
	      if ($Qr->rowCount()>0) {
	       	 $data2=array($house_no,$room_no,$imgdescription,$site);
	       	  $Qr2=$this->dbcon->prepare("insert into roomimages(house_no,roomid,imgdesc,directory) values(?,?,?,?)");
	     
	          $Qr2->execute($data2);
	          if($Qr2->rowCount()>0)
	            {

                  move_uploaded_file($tmp_name,$site);

           
                  return $Qr;//="The image is successfully uploaded!..";
	             }
	            else
	           {
	 	        return $Qr= $Qr->ErrorInfo(); //$Re="Oops your network is low to upload data!..";
	           } 
	       } 

        }

 
      catch(PDOException $ex){
	  $ex->getMessage();
}
} 
//////////////////////// ITEM DETAIL VALIDATIO NEND//////////////

function vedate($edate) {
	 
	
		if($edate!=""){
			return 	$edate;
		} 
		 else{
		 	return false;
		 }
}  


function eedate($edate) {
	 if($edate=="")
	               {

	 	return $edate="Starting date required!..";
	               }
	 
	 else         {
		          	return;
		          }
	           } 

//////////////////////// ITEM DETAIL VALIDATIO NEND//////////////

function vsdate($sdate) {
	 
	
		if($sdate!=""){
			return 	$sdate;
		} 
		 else{
		 	return false;
		 }
}  


function esdate($sdate) {
	 if($sdate=="")
	               {

	 	return $sdate="Starting date required!..";
	               }
	 
	 else         {
		          	return;
		          }
	           } 

function vLDate($expireD) {
	 
	
		if($expireD!=""){
			return 	$expireD;
		} 
		 else{
		 	return false;
		 }
}  


function eLDate($expireD) {
	 if($expireD=="")
	               {

	 	return $expireD="Contract lasting required!..";
	               }
	 
	 else         {
		          	return;
		          }
	           } 

	           /////////////////////////////////////////////
	           /////////////////////DELETE HOUSE CONTRACT/////////////////
	           /////////////////////////////////////////////////////

function deleteThisMyHouseRoomContract($house_no,$roomid,$contractid){
	try{
		$ownerH=$this->dbcon->prepare("delete from contract_info where house_no=:id and roomid=:rid and contractid=:cid");
	    $ownerH->bindParam(":id",$house_no);
	    $ownerH->bindParam(":rid",$roomid);
	    $ownerH->bindParam(":cid",$contractid);  
	    $ownerH->execute(); 
		  
		return $ownerH;

	}
	catch(PDOException $xc){
		$xc->getMessage();
	}
}
///////////////////////TERMINATE THIS CONTRACT///////////////////////

function updateThisMyHouseRoomContract($house_no,$roomid,$contractid){
	try{

	 $status="Terminated on(".date("Y-m-d:h:i:s").")";
	//$contractid=substr(Date("Ymdhis"),2);
 
	 $data=array($status,$house_no,$roomid,$contractid);
		  $Qr=$this->dbcon->prepare("update  contract_info set status=? where house_no=? and roomid=? and contractid=?");   
	      $Qr->execute($data); 
		  
		  if($Qr->rowCount()>0)
	      {
	      	$status="Free";
           $data2=array($status,$house_no,$roomid);
	       $Qr2=$this->dbcon->prepare("update rooms set status=? where house_no=? and  roomid=?");
	       $Qr2->execute($data2);
	   
	        if ($Qr2->rowCount()>0)
	        {
		
             return $Qr2;//="Information submitted successfully!..";
	        }
	        else
	        {
		    return  $Qr2->ErrorInfo();
	       }
	 }
	 else
	 {
	 	  return $Qr->ErrorInfo();//="Data not saved resubmit the form!..";
	 }

	}
	catch(PDOException $xc){
		$xc->getMessage();
	}
}
////////////////////////GET ITEM FROM THIS HOUSE///////////////////////
	/////////////////FUNCTION RETRIEVING SHOP SPECIFIC ITEM/////////
function getThisMyHouseRoomInquirySender($house_no ,$roomid,$receiverid){
	try{
		
       $ownerH=$this->dbcon->prepare("select * from inquirysms where house_no=:id and roomid=:Id and receiverid=:rid or senderid=:sid order by postDate ASC");
	    $ownerH->bindParam(":id",$house_no);
	    $ownerH->bindParam(":Id",$roomid); 
	    $ownerH->bindParam(":rid",$receiverid); 
	    $ownerH->bindParam(":sid",$receiverid);   
	    $ownerH->execute();

		/*$ownerH=$this->dbcon->prepare("select * from inquirysms where house_no=:id and roomid=:Id and receiverid=:rid  order by postDate DESC");
	    $ownerH->bindParam(":id",$house_no);
	    $ownerH->bindParam(":Id",$roomid); 
	    $ownerH->bindParam(":rid",$receiverid);    
	    $ownerH->execute(); */
		  
		return $ownerH;

	}
	catch(PDOException $xc){
		$xc->getMessage();
	}
}
////////////////////////GET ITEM FROM THIS HOUSE///

	/////////////////FUNCTION RETRIEVING SHOP SPECIFIC ITEM/////////
function getThisMyHouseRoomResideInquiry($house_no ,$roomid,$receiverid){
	try{
		$ownerH=$this->dbcon->prepare("select * from inquirysms where house_no=:id and roomid=:Id and receiverid=:rid or senderid=:sid order by postDate ASC");
	    $ownerH->bindParam(":id",$house_no);
	    $ownerH->bindParam(":Id",$roomid); 
	    $ownerH->bindParam(":rid",$receiverid); 
	    $ownerH->bindParam(":sid",$receiverid);   
	    $ownerH->execute(); 
		  
		return $ownerH;

	}
	catch(PDOException $xc){
		$xc->getMessage();
	}
}
////////////////////////GET ITEM FROM THIS HOUSE///////////////////////



	/////////////////FUNCTION RETRIEVING SHOP SPECIFIC ITEM/////////
function getThisMyHouseRoomResideContract($house_no ,$roomid){
	try{
		$ownerH=$this->dbcon->prepare("select * from contract_info where house_no=:id and roomid=:Id");
	    $ownerH->bindParam(":id",$house_no);
	    $ownerH->bindParam(":Id",$roomid);    
	    $ownerH->execute(); 
		  
		return $ownerH;

	}
	catch(PDOException $xc){
		$xc->getMessage();
	}
}
////////////////////////GET ITEM FROM THIS HOUSE///////////////////////

	/////////////////FUNCTION RETRIEVING SHOP SPECIFIC ITEM/////////
function getThisMyHouseRoomContract($house_no){
	try{
		$ownerH=$this->dbcon->prepare("select * from contract_info where house_no=:id");
	    $ownerH->bindParam(":id",$house_no);
	    //$ownerH->bindParam(":Id",$roomid);  
	    $ownerH->execute(); 
		  
		return $ownerH;

	}
	catch(PDOException $xc){
		$xc->getMessage();
	}
}
////////////////////////GET ITEM FROM THIS HOUSE///////////////////////

	/////////////////FUNCTION RETRIEVING SHOP SPECIFIC ITEM/////////
function getThisHouseRoom($house_no,$roomid){
	try{
		$ownerH=$this->dbcon->prepare("select * from rooms where house_no=:id and roomid=:Id");
	    $ownerH->bindParam(":id",$house_no);
	    $ownerH->bindParam(":Id",$roomid);  
	    $ownerH->execute(); 
		  
		return $ownerH;

	}
	catch(PDOException $xc){
		$xc->getMessage();
	}
}
////////////////////////GET ITEM FROM THIS HOUSE///////////////////////
 
function  getOtherHouses($ownID){
	try{
		$ownerH=$this->dbcon->prepare("select * from house_info where ownerid!=:Id");
	    $ownerH->bindParam(":Id",$ownID); 
	    $ownerH->execute(); 
		  
		return $ownerH;

	}
	catch(PDOException $xc){
		$xc->getMessage();
	}
}
////////
////////////////////////GET ITEM FROM THIS HOUSE///////////////////////
 ////////////////////////GET ITEM FROM THIS HOUSE///////////////////////
 
function  getHouses(){
	try{
		$ownerH=$this->dbcon->prepare("select * from house_info");
	    //$ownerH->bindParam(":Id",$ownID); 
	    $ownerH->execute(); 
		  
		return $ownerH;

	}
	catch(PDOException $xc){
		$xc->getMessage();
	}
}
////////
////////////////////////GET ITEM FROM THIS HOUSE///////////////////////


////////////////////////GET ITEM FROM THIS HOUSE///////////////////////
 
function getOtherHousesOut(){
	try{
		$ownerH=$this->dbcon->prepare("select * from house_info");
	    //$ownerH->bindParam(":Id",$ownID); 
	    $ownerH->execute(); 
		  
		return $ownerH;

	}
	catch(PDOException $xc){
		$xc->getMessage();
	}
}
////////
////////////////////////GET ITEM FROM THIS HOUSE///////////////////////
function getMyHouses($ownID){
	try{ 
	      
		$ownerH=$this->dbcon->prepare("select * from house_info where ownerid=:Id");
	    $ownerH->bindParam(":Id",$ownID);
	    $ownerH->execute(); 
		  
		return $ownerH;

	}
	catch(PDOException $xc){
		$xc->getMessage();
	}
}

//////////////////////////
////////////////////////GET  THIS HOUSE///////////////////////
 
function getThisMyHouses($house_no,$ownID){
	try{ 
	      
		$ownerH=$this->dbcon->prepare("select * from house_info where house_no=:Id and ownerid=:own");
	    $ownerH->bindParam(":Id",$house_no);
	    $ownerH->bindParam(":own",$ownID);
	    $ownerH->execute(); 
		  
		return $ownerH;

	}
	catch(PDOException $xc){
		$xc->getMessage();
	}
}

//////////////////////////
 
////////////////////////GET   THIS HOUSE///////////////////////
////////
////////////////////////GET  THIS HOUSE///////////////////////
 
function getThisHousesDetail($house_no){
	try{ 
	      
		$ownerH=$this->dbcon->prepare("select * from house_info where house_no=:Id");
	    $ownerH->bindParam(":Id",$house_no);
	    $ownerH->execute(); 
		  
		return $ownerH;

	}
	catch(PDOException $xc){
		$xc->getMessage();
	}
}

//////////////////////////

 
function checkIfHousesFreeWithExistRoom(){
	try{
		$status="Free";
		$ownerH=$this->dbcon->prepare("select * from rooms where  status=:free");
	    //$ownerH->bindParam(":id",$house_no);
	    $ownerH->bindParam(":free",$status);  
	    $ownerH->execute(); 
		  
		return $ownerH;

	}
	catch(PDOException $xc){
		$xc->getMessage();
	}
}
//////////////////////////                           /////////////////
////////////////////////GET ITEM FROM  P///////////////////////
 
function getHousesFreeRoom($house_no){
	try{
		$status="Free";
		$ownerH=$this->dbcon->prepare("select * from rooms where house_no=:id and status=:free");
	    $ownerH->bindParam(":id",$house_no);
	    $ownerH->bindParam(":free",$status);  
	    $ownerH->execute(); 
		  
		return $ownerH;

	}
	catch(PDOException $xc){
		$xc->getMessage();
	}
}
//////////////////////////                           /////////////////
////////////////////////GET ITEM FROM  P///////////////////////
////////
////////////////////////GET ITEM FROM THIS HOUSE///////////////////////
 
function getHousesRoom($house_no){
	try{
		$status="Free";
		$ownerH=$this->dbcon->prepare("select * from rooms where house_no=:id");
	    $ownerH->bindParam(":id",$house_no);   
	    $ownerH->execute(); 
		  
		return $ownerH;

	}
	catch(PDOException $xc){
		$xc->getMessage();
	}
}
//////////////////////////                           /////////////////

////////////////////////GET ITEM FROM THIS HOUSE///////////////////////
/* 
function getHousesRoomForContract($house_no){
	try{
		$status="Free";
		$ownerH=$this->dbcon->prepare("select * from rooms where house_no=:id and status=:status");
	    $ownerH->bindParam(":id",$house_no); 
	    $ownerH->bindParam(":status",$status); 
	    $ownerH->execute(); 
		  
		return $ownerH;

	}
	catch(PDOException $xc){
		$xc->getMessage();
	}
}
/////////////////////////*/                           /////////////////
////////////////////////GET ITEM FROM  P///////////////////////
////////////////////////GET ITEM FROM  P///////////////////////


////////////////////////GET ITEM FROM THIS HOUSE///////////////////////
 
function getHousesThisRoom($house_no,$roomid){
	try{
		$ownerH=$this->dbcon->prepare("select * from rooms where house_no=:id and roomid=:rid");
	    $ownerH->bindParam(":id",$house_no); 
	    $ownerH->bindParam(":rid",$roomid);  
	    $ownerH->execute(); 
		  
		return $ownerH;

	}
	catch(PDOException $xc){
		$xc->getMessage();
	}
}
//////////////////////////                           /////////////////
////////////////////////GET ITEM FROM  P///////////////////////
//////////////////////////
////////////////////////////////GET ITEM FROM THIS HOUSE///////////////////////
 
function getThisRoomImages($house_no,$roomid){
	try{
		$ownerH=$this->dbcon->prepare("select * from roomimages where house_no=:id and roomid=:rid");
	    $ownerH->bindParam(":id",$house_no); 
	    $ownerH->bindParam(":rid",$roomid); 
	    $ownerH->execute(); 
		  
		return $ownerH;

	}
	catch(PDOException $xc){
		$xc->getMessage();
	}
}
//////////////////////////                           /////////////////
////////////////////////GET ITEM FROM THIS HOUSE///////////////////////

////////////////////////////////GET ITEM FROM THIS HOUSE///////////////////////
 
function getMyHouseThisRoomDetail($house_no,$roomid){
	try{
		$ownerH=$this->dbcon->prepare("select * from rooms where house_no=:id and roomid=:rid");
	    $ownerH->bindParam(":id",$house_no); 
	    $ownerH->bindParam(":rid",$roomid); 
	    $ownerH->execute(); 
		  
		return $ownerH;

	}
	catch(PDOException $xc){
		$xc->getMessage();
	}
}
//////////////////////////                           /////////////////
////////////////////////GET ITEM FROM THIS HOUSE///////////////////////
 
function getHousesPImg($house_no){
	try{
		$ownerH=$this->dbcon->prepare("select * from houseimage where house_no=:id");
	    $ownerH->bindParam(":id",$house_no);  
	    $ownerH->execute(); 
		  
		return $ownerH;

	}
	catch(PDOException $xc){
		$xc->getMessage();
	}
}
//////////////////////////                           /////////////////
////////////////////////GET ITEM FROM  P///////////////////////
//////////////////////////      ///////////////////////

	/////////////////FUNCTION RETRIEVING SHOP SPECIFIC ITEM/////////
function getThisHouse($house_no){
	try{
		$ownerH=$this->dbcon->prepare("select * from house_info where house_no=:id ");
	    $ownerH->bindParam(":id",$house_no);  
	    $ownerH->execute(); 
		  
		return $ownerH;

	}
	catch(PDOException $xc){
		$xc->getMessage();
	}
}
//////////////////////////                           /////////////////
////////////////////////GET ITEM FROM THIS SHOP///////////////////////


 ///////////// FUNCTION THAT SAVING CONTRACT ///////////////////////
	           ////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////


function addHouseRentContract($ownID,$rentorid,$roomid, $house_no, $sdate,$edate,$rcost,$currency){
	
	$status="Current";
	$contractid=substr(Date("Ymdhis"),2);
 
	 $data=array($contractid,$ownID,$rentorid,$house_no,$roomid,$sdate,$edate,$rcost,$currency,$status);
try{
	
	$Qr=$this->dbcon->prepare("insert into contract_info(
	contractid,ownerid,rentorid,house_no,roomid,startdate,enddate,cashpaid,currency,status) values(?,?,?,?,?,?,?,?,?,?)");
	$Qr->execute($data);

	 if($Qr->rowCount()>0)
	 {
	 	$status="Busy";
        $data2=array($status,$house_no,$roomid);
	    $Qr2=$this->dbcon->prepare("update rooms set status=? where house_no=? and  roomid=?");
	    $Qr2->execute($data2);
	   
	    if ($Qr2->rowCount()>0)
	      {
		
          return $Qr2;//="Information submitted successfully!..";
	      }
	      else
	      {
		   return  $Qr2->ErrorInfo();
	      }
	 }
	 else
	 {
	 	  return $Qr->ErrorInfo();//="Data not saved resubmit the form!..";
	 }

}
catch(PDOException $ex){
	$ex->getMessage();
}
} 

//////////////////////////////
                         //WARD VALIDATION
           ////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
///////////// FUNCTION THAT SAVING CONTRACT ///////////////////////
	           ////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////


function addRoomInquiryPost($house_no,$rentorid,$roomid,$contractid,$senderid,$mesage){
	 
	$smsid=substr(Date("Ymdhis"),2);
 
	 $data=array($smsid,$house_no,$rentorid,$roomid,$contractid,$senderid,$mesage);
try{
	
	$Qr=$this->dbcon->prepare("insert into inquirysms(smsid,house_no,receiverid,roomid,contractid,senderid,inquiry) values(?,?,?,?,?,?,?)");
	$Qr->execute($data);

	 if($Qr->rowCount()>0)
	 {
	 	  
		
          return $Qr;//="Information submitted successfully!..";
	  }
	 
	 else
	 {
	 	  return $Qr->ErrorInfo();//="Data not saved resubmit the form!..";
	 }

}
catch(PDOException $ex){
	$ex->getMessage();
}
} 

//////////////////////////////
                         //WARD VALIDATION
           ////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////


function updateMyHouseProfile($hnumber,$accountId,$hname,$cduration,$category,$email,$phoneno,$popularDistination,$rnumber,$distancerm,$tcondition,$hcost,$currency,$finishD,$regno,$regdate){
	
	
try{

	//$regno=substr(Date("Ymdhis"),2);
  
	 $data=array($hnumber,$accountId,$hname,$cduration,$category,$email,$phoneno,$popularDistination,$rnumber,$distancerm,$tcondition,$hcost,$currency,$finishD,$regno,$regdate);
	$Qr=$this->dbcon->prepare("update house_info set house_no=?,ownerid=?,house_title=?,cduration=?,category=?,email=?,phone_no=?,popularmark=?,rooms_no=?,distance_m_r=?,term_condition=?,cost_ifany=?,currency=?,finishdisc=? where reg_no=? and regdate=?");

	$Qr->execute($data);
	 if($Qr->rowCount()>0)
	 {
          return $Re="Information submitted successfully!..";
	 }
	 else
	 {
	 	  return $Qr=$Qr->ErrorInfo();//="Data not saved resubmit the form!..";
	 }

}
catch(PDOException $ex){
	$ex->getMessage();
}
} 

//////////////////////////////
                   



 ///////////// FUNCTION THAT SAVING HOUSE PROFILE ///////////////////////
	           ////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////


function RegisterHouse($hnumber,$ownerid,$hname,$cduration,$category,$email,$phoneno,$country,$region,$district,$ward,$street,$popularDistination,$rnumber,$distancerm,$tcondition,$hcost,$currency,$finishD){
	
	
try{

	$regno=substr(Date("Ymdhis"),2);
  
	 $data=array($hnumber,$ownerid,$regno,$hname,$cduration,$category,$email,$phoneno,$country,$region,$district,$ward,$street,$popularDistination,$rnumber,$distancerm,$tcondition,$hcost,$currency,$finishD);
	$Qr=$this->dbcon->prepare("insert into house_info(house_no,ownerid,reg_no,house_title,cduration,category,email,phone_no,country,region,district,ward,street,popularmark,rooms_no,distance_m_r,term_condition,cost_ifany,currency,finishdisc) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");

	$Qr->execute($data);
	 if($Qr->rowCount()>0)
	 {
          return $Re="Information submitted successfully!..";
	 }
	 else
	 {
	 	  return $Qr="Data not saved resubmit the form!..";
	 	 // print_r($Qr->ErrorInfo());
	 }

}
catch(PDOException $ex){
	$ex->getMessage();
}
} 

//////////////////////////////
                         //WARD VALIDATION

function vCategory($category) {
	 
	
		if(preg_match("/^[\sA-Za-z]+$/",$category)  && $category!=""){
			return 	$category;
		} 
		 else{
		 	return false;
		 }
}  


function eCategory($category) {
 
	 if($category=="")
	               {

	 	return $category="category required!..";
	               }
	
	 else if(!preg_match("/^[\sA-Za-z]+$/",$category))
	              {
		 
        return $category= "Invalid category!";
		          }
	 else         {
		          	return;
		          }
	 

}

// NUMBER OF ROOM VALIDATION

function vaccountId($accountId) {
	 
	
		if(preg_match("/^[\sA-Za-z0-9]+$/",$accountId)  && $accountId!=""){


			return 	$accountId;
		} 
		 else{
		 	return false;
		 }
}  


function eaccountId($accountId) {
	 if($accountId=="")
	               {

	 	return $accountId="Account id required!..";
	               }

   
	 else if(!preg_match("/\b\d{1,30}\b/",$accountId))
	              {
		 
        return $accountId= "Invalid account id!..";
		          }
	 else         {
		          	return;
		          }
	 

}


//////////////////////////////
// NUMBER OF ROOM VALIDATION

function vRnumber($rnumber) {
	 
	
		if(preg_match("/\b\d{1,30}\b/",$rnumber)  && $rnumber!=""){
			return 	$rnumber;
		} 
		 else{
		 	return false;
		 }
}  


function eRnumber($rnumber) {
	 if($rnumber=="")
	               {

	 	return $rnumber="Number of room required!..";
	               }

   
	 else if(!preg_match("/\b\d{1,30}\b/",$rnumber))
	              {
		 
        return $phoneno= "Invalid room number!..";
		          }
	 else         {
		          	return;
		          }
	 

}

//PHONE NUMBER VALIDATION

function vPhoneno($phoneno) {
	 
	
		if(preg_match("/\b\d{10,12}\b/",$phoneno)  && $phoneno!=""){
			return 	$phoneno;
		} 
		 else{
		 	return false;
		 }
}  


function ePhoneno($phoneno) {
	 if($phoneno=="")
	               {

	 	return $phoneno="Phone number required!..";
	               }

   
	 else if(!preg_match("/\b\d{10,12}\b/",$phoneno))
	              {
		 
        return $phoneno= "Invalid phone number!..";
		          }
	 else         {
		          	return;
		          }
	 

}


//////////////////////HOUSE DISTANCE FROM MAIN ROAD/////////////
///////////////////////////////////////////////////////////
////////////////////////////////////POST ADVERTISEMENT HERE///////////////////////////////////////////////////////////
	                                  ////////////////////////////////
 
function vDistancerm($distancerm) {
	 
	
		if(preg_match("/^[\sA-Za-z0-9]+$/",$distancerm)  && $distancerm!=""){
			return 	$distancerm;
		} 
		 else{
		 	return false;
		 }
}  


function eDistancerm($distancerm) {
	 if($distancerm=="")
	               {

	 	return $distancerm="Distance from main required!..";
	               }
	
	 else if(!preg_match("/^[\sA-Za-z0-9]+$/",$distancerm))
	              {
		 
        return $distancerm= "Distance from main road typed with error!";
		          }
	 else         {
		          	return;
		          }
	 

}

/////////////////////////////////////////////////////////////

////////////////////////////////////POST ADVERTISEMENT HERE///////////////////////////////////////////////////////////
	                                  ////////////////////////////////
 
function vcduration($cduration) {
	 
	
		if(preg_match("/^[\sA-Za-z0-9]+$/",$cduration)  && $cduration!=""){
			return 	$cduration;
		} 
		 else{
		 	return false;
		 }
}  


function ecduration($cduration) {
	 if($cduration=="")
	               {

	 	return $$cduration="Contract duration required!..";
	               }
	
	 else if(!preg_match("/^[\sA-Za-z0-9]+$/",$cduration))
	              {
		 
        return $cduration= "Contract duration typed with error!";
		          }
	 else         {
		          	return;
		          }
	 

}

/////////////////////////////////////////////////////////////
             ////////////////////////////////
	                                    //  HOUSE COST///////////////
function vHcost($hcost,$currency) {
	 
	
		if(preg_match("/^[0-9]+$/",$hcost)  && $hcost!="" && $currency!=""){
			return 	$hcost;
		} 
		 else{
		 	return false;
		 }
}  


function eHcost($hcost,$currency) {
	 if($hcost=="" || $currency=="")
	               {

	 	return $hcost="Both Price and currency are required!..";
	               }
	
	 else if(!preg_match("/^[0-9]+$/",$hcost))
	              {
		 
        return $hcost= "Cost typed with error! ";
		          }
	 else         {
		          	return;
		          }
	           }                           


//////////////////////////////////////HOUSE NUMBER/////////////////////
///////////////////////////////////////////////////////////////////////

                                      //STREET VALIDATION

function vHnumber($hnumber) {
	 
	
		if($hnumber!=""){
			return 	$hnumber;
		} 
		 else{
		 	return false;
		 }
}  


function eHnumber($hnumber) {
	 if($hnumber=="")
	               {

	 	return $hnumber="House number required!..";
	               }
	
	  
	 else         {
		          	return;
		          }
	 

}


                        /////////////////////////////////////////////////////////////
////////////////////////////////////POST ADVERTISEMENT HERE///////////////////////////////////////////////////////////
	                                  ////////////////////////////////
 
function vTcondition($tcondition) {
	 
	
		if($tcondition!=""){
			return 	$tcondition;
		} 
		 else{
		 	return false;
		 }
}  


function eTcondition($tcondition) {
	 if($tcondition=="")
	               {

	 	return $tcondition="Term and condition required!..";
	               }
	 
	 else         {
		          	return;
		          }
	 

}


////////////////////////////////////POST ADVERTISEMENT HERE///////////////////////////////////////////////////////////
	                                  ////////////////////////////////
                        /////////////////////////////////////////////////////////////
////////////////////////////////////POST ADVERTISEMENT HERE///////////////////////////////////////////////////////////
	                                  ////////////////////////////////
 
function vPopularDistination($popularDistination) {
	 
	
		if( $popularDistination!=""){
			return 	$popularDistination;
		} 
		 else{
		 	return false;
		 }
}  


function ePopularDistination($popularDistination) {
	 if($popularDistination=="")
	               {

	 	return $popularDistination="Popular destination required!..";
	               }
	
	 
	 else         {
		          	return;
		          }
	 

}


////////////////////////////////////POST ADVERTISEMENT HERE///////////////////////////////////////////////////////////
	                                  ////////////////////////////////
 
function vFinishD($finishD) {
	 
	
		if( $finishD!=""){
			return 	$finishD;
		} 
		 else{
		 	return false;
		 }
}  


function eFinishD($finishD) {
	 if($finishD=="")
	               {

	 	return $finishD="Finishing description required!..";
	               }
	 
	 else         {
		          	return;
		          }
	 

}

                                      //STREET VALIDATION

function vStreet($street) {
	 
	
		if(preg_match("/^[\sA-Za-z]+$/",$street)  && $street!=""){
			return 	$street;
		} 
		 else{
		 	return false;
		 }
}  


function eStreet($street) {
	 if($street=="")
	               {

	 	return $street="Street required!..";
	               }
	
	 else if(!preg_match("/^[\sA-Za-z]+$/",$street))
	              {
		 
        return $street= "Invalid street  name!";
		          }
	 else         {
		          	return;
		          }
	 

}


function vOwnerid($ownerid) {
	 
	
		if(preg_match("/^[A-Za-z0-9]+$/",$ownerid)  && $ownerid!=""){
			return 	$ownerid;
		} 
		 else{
		 	return false;
		 }
}  


function eOwnerid($ownerid) {
	 if($ownerid=="")
	               {

	 	return $ownerid="Ownerid required!..";
	               }
	
	 else if(!preg_match("/^[A-Za-z0-9]+$/",$ownerid))
	              {
		 
        return $ownerid= "Invalid ownerid!";
		          }
	 else         {
		          	return;
		          }
	 

}

  ///////////////////////////////////HOTEL NAME VALIDATION////////////////////////////////
                       /////////////////////////////////////
/////////////////////////////////////////////////////////////////
function vHname($hname) {
	 
	
		if(preg_match("/^[\sA-Za-z]+$/",$hname)  && $hname!=""){
			return 	$hname;
		} 
		 else{
		 	return false;
		 }
}  

      
function eHname($hname) {
	 if($hname=="")
	               {

	 	return $hname="Hotel name required!..";
	               }
	
	 else if(!preg_match("/^[\sA-Za-z]+$/",$hname))
	              {
		 
        return $hname= "House name typed with error!";
		          }
	 else         {
		          	return;
		          }
	 

}
                                //WARD VALIDATION

function vWard($ward) {
	 
	
		if(preg_match("/^[\sA-Za-z]+$/",$ward)  && $ward!=""){
			return 	$ward;
		} 
		 else{
		 	return false;
		 }
}  


function eWard($ward) {
	 if($ward=="")
	               {

	 	return $ward="Ward required!..";
	               }
	
	 else if(!preg_match("/^[\sA-Za-z]+$/",$ward))
	              {
		 
        return $ward= "Invalid ward name!";
		          }
	 else         {
		          	return;
		          }
	 

}






 







                                      //EMAIL VALIDATION

function vEmail($email) {
	 
	
		if(preg_match("/\b[(A-Za-z)][\w.]\w+@\w+\.(net|com|edu)\b/",$email)  && $email!=""){
			return 	$email;
		} 
		 else{
		 	return false;
		 }
}  


function eEmail($email) {
	 if($email=="")
	               {

	 	return $email="Email required!..";
	               }
	
	 else if(!preg_match("/\b[\(A-Za-z)][\w.]\w+@\w+\.(net|com|edu)\b/",$email))
	              {
		 
        return $email= "Invalid email address!";
		          }
	 else         {
		          	return;
		          }
	 

}                                                    


                                      //DISTRICT VALIDATION

function vDistrict($district) {
	 
	
		if(preg_match("/^[\sA-Za-z]+$/",$district)  && $district!=""){
			return 	$district;
		} 
		 else{
		 	return false;
		 }
}  


function eDistrict($district) {
	 if($district=="")
	               {

	 	return $district="District required!..";
	               }
	
	 else if(!preg_match("/^[\sA-Za-z]+$/",$district))
	              {
		 
        return $district= "Invalid district name!";
		          }
	 else         {
		          	return;
		          }
	 

}




                                      //REGION VALIDATION

function vRegion($region) {
	 
	
		if(preg_match("/^[\sA-Za-z]+$/",$region)  && $region!=""){
			return 	$region;
		} 
		 else{
		 	return false;
		 }
}  


function eRegion($region) {
	 if($region=="")
	               {

	 	return $region="Region required!..";
	               }
	
	 else if(!preg_match("/^[\sA-Za-z]+$/",$region))
	              {
		 
        return $district= "Invalid region name!";
		          }
	 else         {
		          	return;
		          }
	 

}

                                      //COUNTRY VALIDATION

function vCountry($country) {
	 
	
		if(preg_match("/^[\sA-Za-z]+$/",$country)  && $country!=""){
			return 	$country;
		} 
		 else{
		 	return false;
		 }
}  


function eCountry($country) {
	 if($country=="")
	               {

	 	return $region="Country required!..";
	               }
	
	 else if(!preg_match("/^[\sA-Za-z]+$/",$country))
	              {
		 
        return $district= "Invalid country name!";
		          }
	 else         {
		          	return;
		          }
	 

}
//IMAGE ERROR VALIDATION

                            //CHECK IF IMAGE EXIST

function vRoomImageExist($fn) {
	 
	if(file_exists("../houseroomimages/".$fn))
	{
      
      return false;
		  
    }
	else
	 {
	  return true; 
	 }

     }  



function eRoomImageExist($fn) 
 {
	 
	
if(file_exists("../houseroomimages/".$fn))
	{
      
      return  $exs= "The ".$fn." already uploaded!..";
  
    }
	 else
    {
	 return ;
    }


} 

  
///////////////////////////////////////////
////////////////////////////////////////////HOUSE IMAGE UPLOAD//////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////IMAGE TITLE//////////////////

function vimagename($itemname) {
	 
	
		if(preg_match("/^[\sA-Za-z0-9]+$/",$itemname)  && $itemname!=""){
			return 	$itemname;
		} 
		 else{
		 	return false;
		 }
}  


function eimagename($itemname) {
	 if($itemname=="")
	               {

	 	return $itemname="Image name required!..";
	               }
	
	 else if(!preg_match("/^[\sA-Za-z0-9]+$/",$itemname))
	              {
		 
        return $itemname= "Error in image name!";
		          }
	 else         {
		          	return;
		          }
	           }                           

////////////////////////////////////////////
//////////////////////////////////////////////   FUNCTION  FOR IMAGE VALIDATIO  GOES HERE //////////////////////
function vImageType($ext,$allowedtype) {
	 
	if(in_array($ext,$allowedtype))
	{
      
      return $ext;
		  
    }
	else
	 {
	  return false; 
	 }

     }  



function eImageType($ext,$allowedtype) {
	 
	if(in_array($ext,$allowedtype))
	{
      
      return;
		  
    }
	else
	 {
	  return $ex= "The extension ".$ext." is not type of an image!..";
	 }

     }  
                                      //TYPE OF IMAGE ENDS




                             //IMAGE SIZE VALIDATION

function vImageSize($size) {
	 
	if($size>=0 && $size<2000000)
	{
      
      return $size;
		  
    }
	else
	 {
	  return false; 
	 }

     }  



function eImageSize($size) 
 {
	 
	if($size>=0 && $size<2000000)
	{
      
      return;
		  
    }
	 else
    {
	 return $size= "The Height:  ".$height." and   Width: ".$width."   of image is not within range!..";
    }


} 
                                      //VALIDATION  OF IMAGE SIZE ENDS


                             //IMAGE ERROR VALIDATION

function vImageError($error) {
	 
	if($error <= 0)
	{
      
      return true;
		  
    }
	else
	 {
	  return false; 
	 }

     }  



function eImageError($error) 
 {
	 
	if($error > 0)
	{
      
      return $err="An error: ".$error." occurred while uploading file!..."; 

		  
    }
	 else
    {
	 return ;
    }


} 

//IMAGE ERROR VALIDATION

                            //CHECK IF IMAGE EXIST

function vImageExist($fn) {
	 
	if(file_exists("../houseimages/".$fn))
	{
      
      return false;
		  
    }
	else
	 {
	  return true; 
	 }

     }  



function eImageExist($fn) 
 {
	 
	
if(file_exists("../houseimages/".$fn))
	{
      
      return  $exs= "The ".$fn." already uploaded!..";
  
    }
	 else
    {
	 return ;
    }


} 


                            //CHECK IF IMAGE SELECTED

function vImageSelectF($fn) {
	 
	if($fn=="")
	{
      
      return false;
		  
    }
	else
	 {
	  return true; 
	 }

     }  



function eImageSelectF($fn) 
 {
	 
	
if($fn=="")
	{
      
      return  $exs= "Select file to upload!..";
  
    }
	 else
    {
	 return ;
    }


} 

/////////////////////////////////UPLOAD ITEM IMAGES/////////////////////

function uploadImage($house_no,$itemname,$fn,$tmp_name){
	

 

  $site="../houseimages/".$fn;
  $ext = strtolower($site);

  $info = getimagesize($tmp_name);

  if ($info['mime'] == 'image/jpeg')
  {
      
    $image = imagecreatefromjpeg($tmp_name);
  }
  elseif ($info['mime'] == 'image/gif') 
  {
    $image = imagecreatefromgif($tmp_name);
  }
  elseif ($info['mime'] == 'image/png')
  { 
    $image = imagecreatefrompng($tmp_name);
  }
 //imagejpeg($image, $site, 1);
	 
	 $data=array($house_no,$site,$itemname);
  try{
	
	$Qr=$this->dbcon->prepare("insert into houseimage(house_no,directory,title) values(?,?,?)");
	$Qr->execute($data);
	 if($Qr->rowCount()>0)
	 {

     //move_uploaded_file($tmp_name,$site);
     imagejpeg($image, $site, 1);
           
          return $Qr ;//="The image is successfully uploaded!..";
	 }
	 else
	 {
	 	  return $Qr= $Qr->ErrorInfo(); //$Re="Oops your network is low to upload data!..";
	 } 

}
catch(PDOException $ex){
	$ex->getMessage();
}
}
//////////////////////////////////////////////                               //////////////////////
///////////////////////////////////////////////////// IMAGE VALIDATION ENDS  ///////////////////

///////////////////////////ROOM ERROR CHECKING/////////////////////
//////////////////////////////////////////////////////////////////
  
   /////////////////////                                             //////////////////////
///////////////////////  FUNCTION FOR VALIDATION OF ITEM DETAIL  GOES HERE///////////////

                 //////////////////////////////////

function vRoomno($room_no) {
	 
	
		if(preg_match("/^[\sA-Za-z0-9]+$/",$room_no)  && $room_no!=""){
			return 	$room_no;
		} 
		 else{
		 	return false;
		 }
}  


function eRoomno($room_no) {
	 if($room_no=="")
	               {

	 	return $room_no="Room norequired!..";
	               }
	
	 else if(!preg_match("/^[\sA-Za-z0-9]+$/",$room_no))
	              {
		 
        return $itemname= "Error in typing room no!";
		          }
	 else         {
		          	return;
		          }
	           }                           


                    

 


                               ////////////////////////////////
	                                    //  ROUTE DIRECTION VIA POINT
function vrcost($rcost,$currency) {
	 
	
		if(preg_match("/^[0-9]+$/",$rcost)  && $rcost!="" && $currency!=""){
			return 	$rcost;
		} 
		 else{
		 	return false;
		 }
}  


function ercost($rcost,$currency) {
	 if($rcost=="" || $currency=="")
	               {

	 	return $rcost="Both cost and currency are required!..";
	               }
	
	 else if(!preg_match("/^[0-9]+$/",$rcost))
	              {
		 
        return $via= "Cost typed with error! ";
		          }
	 else         {
		          	return;
		          }
	           }                           
                               ////////////////////////////////
	                                    //  ROUTE DETAIL
function vdescription($description) {
	 
	
		if($description!=""){
			return 	$description;
		} 
		 else{
		 	return false;
		 }
}  


function edescription($description) {
	 if($description=="")
	               {

	 	return $description="Description required!..";
	               }
	 
	 else         {
		          	return;
		          }
	           }                           


                                     //  ROUTE DETAIL
function vimgdescription($imgdescription) {
	 
	
		if($imgdescription!=""){
			return 	$imgdescription;
		} 
		 else{
		 	return false;
		 }
}  


function eimgdescription($imgdescription) {
	 if($imgdescription=="")
	               {

	 	return $imgdescription="Image description required!..";
	               }
	 
	 else         {
		          	return;
		          }
	                                    




                                         // CLASS TERMINAL
}
 }
?> 