
<?php 
	//include "db_config.php";

	class Helper
{
    public $db;

    public function __construct()
    {
        $this->db = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
		mysqli_set_charset($this->db,"utf8");
		         if (mysqli_connect_errno()) {

            echo "Error: Could not connect to database.";

            exit;

        }
    }
	function select($table, $columns, $where, $order){
         
            $a = array();
            $w = "";
            foreach ($where as $key => $value) {
                $w .= " and " .$key. " = '".$value."'";
                $a[":".$key] = $value;
            }
			foreach ($order as $key => $value) {
                $orderby .= " order by " .$key. "  ".$value;
                //$a[":".$key] = $value;
            }
             $result = array();
	      // echo "select ".$columns." from ".$table." where 1=1 ". $w.$orderby;    
             $sql = mysqli_query($this->db, "select ".$columns." from ".$table." where 1=1 ". $w.$orderby);
              while ($result = mysqli_fetch_array($sql)) {
             $data[] = $result;
              }
             return $data;
}
	function selectlimit($table, $columns, $where, $start, $limit, $order){
            //print_r($where);
            $start=$start*$limit;
            $a = array();
            $w = "";
            foreach ($where as $key => $value) {
                $w .= " and " .$key. " = '$value'";
                $a[":".$key] = $value;
            }
			 $countorderby=count($order);
			 $ord=" order by ";
			foreach ($order as $key => $value) {
                $orderby .= " " .$key. "  ".$value.",";
            }
			 
			$orderby=substr($orderby, 0, -1);
			if($countorderby>0){
			$orderby=$ord.$orderby;
			}
			 
			//$orderby .="order by businessid DESC,title ASC";
             $result = array();
		  //echo "select ".$columns." from ".$table." where 1=1 ". $w.$orderby." limit ".$start.",".$limit;
              $sql = mysqli_query($this->db, "select ".$columns." from ".$table." where 1=1 ". $w.$orderby." limit ".$start.",".$limit);
              while ($result = mysqli_fetch_array($sql)) {
             $data[] = $result;
              }
             return $data;
            
         
    }
    function selectlimitstaffhotel($table, $columns, $where, $start, $limit, $order,$countrytomanage){
       
            //print_r($where);
            $start=$start*$limit;
            $a = array();
            $w = "";
            foreach ($where as $key => $value) {
                $w .= " and " .$key. " = '$value'";
                $a[":".$key] = $value;
            }
			 $countorderby=count($order);
			 $ord=" order by ";
			foreach ($order as $key => $value) {
                $orderby .= " " .$key. "  ".$value.",";
            }
			 
			$orderby=substr($orderby, 0, -1);
			if($countorderby>0){
			$orderby=$ord.$orderby;
			}
		if($countrytomanage!=0){
                    $in=" and country IN(".$countrytomanage.")";
                    $w.=$w.$in ;    
                }	 
			//$orderby .="order by businessid DESC,title ASC";
             $result = array();
		    //echo "select ".$columns." from ".$table." where 1=1 ". $w.$orderby." limit ".$start.",".$limit;
              $sql = mysqli_query($this->db, "select ".$columns." from ".$table." where 1=1 ". $w.$orderby." limit ".$start.",".$limit);
              while ($result = mysqli_fetch_array($sql)) {
             $data[] = $result;
              }
             return $data;
            
         
    }
	function countofdata($table,$where,$num_per_page){
            $a = array();
            $w = "";
			if(count($where)>0){
            foreach ($where as $key => $value) {
                $w .= " and " .$key. " = ".$value; 
                $a[":".$key] = $value;
            }
			}
             $result = array();
             $sql = mysqli_query($this->db, "select count(*) as total from ".$table." where 1=1 ". $w);
             $result = mysqli_fetch_array($sql);
			 $total=$result['total'];
			 $count=$total/$num_per_page;
	          $reminder=$total%$num_per_page;
			  if($reminder!=0){
				  $count=$count+1;
			  }
			  if($total>$num_per_page){		  
			  return $count;
		  
			  }
             //return $result['total'];
         
    }
    function countofdatastaffhotel($table,$where,$num_per_page,$order,$countrytomanage){
         
            $a = array();
            $w = "";
			if(count($where)>0){
            foreach ($where as $key => $value) {
                $w .= " and " .$key. " = ".$value; 
                $a[":".$key] = $value;
            }
			}
             if($countrytomanage!=0){
                    $in=" and country IN(".$countrytomanage.")";
                    $w.=$w.$in ;    
                }
             $result = array();
             echo "select count(*) as total from ".$table." where 1=1 ". $w;
             $sql = mysqli_query($this->db, "select count(*) as total from ".$table." where 1=1 ". $w);
             $result = mysqli_fetch_array($sql);
			 $total=$result['total'];
			 $count=$total/$num_per_page;
	          $reminder=$total%$num_per_page;
			  if($reminder!=0){
				  $count=$count+1;
			  }
			  if($total>$num_per_page){		  
			  return $count;
		  
			  }
             //return $result['total'];
         
    }
	function countofsearch($table,$where,$num_per_page){
            $a = array();
            $w = "";
			if(count($where)>0){
           foreach ($where as $key => $value) {
                $w .= $key. " like '%$value%'";
                $a[":".$key] = $value;
            }
			}
             $result = array();			  
             $sql = mysqli_query($this->db, "select count(*) as total from ".$table." where 1=1 and ". $w);
             $result = mysqli_fetch_array($sql);
			 $total=$result['total'];
			 $count=$total/$num_per_page;
	          $reminder=$total%$num_per_page;
			  if($reminder!=0){
				  $count=$count+1;
			  }
			  if($total>$num_per_page){		  
			  return $count;
		  
			  }
             //return $result['total'];
         
    }
	function countoflikedata($table,$where,$num_per_page){
            $a = array();
            $w = "";
			if(count($where)>0){
            foreach ($where as $key => $value) {
                $w .= " and " .$key. " like '%$value%'";				
                $a[":".$key] = $value;
            }
			//echo $w;
			}
             $result = array();
             $sql = mysqli_query($this->db, "select count(*) as total from ".$table." where 1=1 ". $w);
             $result = mysqli_fetch_array($sql);
			// echo "select count(*) as total from ".$table." where 1=1 ". $w;
			 $total=$result['total'];
			 $count=$total/$num_per_page;
	          $reminder=$total%$num_per_page;
			  if($reminder!=0){
				  $count=$count+1;
			  }
			  if($total>$num_per_page){		  
			  return $count;
		  
			  }
             //return $result['total'];
         
    }
    function countofhotelsearch($table,$val,$num_per_page){
            $a = array();
            $w = "";
			if(count($where)>0){
            foreach ($where as $key => $value) {
                $w .= " and " .$key. " like '%$value%'";				
                $a[":".$key] = $value;
            }
			//echo $w;
			}
             $result = array();
             $sql = mysqli_query($this->db, "select count(*) as total from ".$table." where id like '%$val%' or hotelname like '%$val%'");
             $result = mysqli_fetch_array($sql);
			// echo "select count(*) as total from ".$table." where 1=1 ". $w;
			 $total=$result['total'];
			 $count=$total/$num_per_page;
	          $reminder=$total%$num_per_page;
			  if($reminder!=0){
				  $count=$count+1;
			  }
			  if($total>$num_per_page){		  
			  return $count;
		  
			  }
             //return $result['total'];
         
    }
    function countofhotelsearchstaffhotel($table,$val,$num_per_page,$avaialbalecountry){
            $a = array();
            $w = "";
			if(count($where)>0){
            foreach ($where as $key => $value) {
                $w .= " and " .$key. " like '%$value%'";				
                $a[":".$key] = $value;
            }
            $in=" and country IN(".$avaialbalecountry.")";
			//echo $w;
			}
             $result = array();
             $sql = mysqli_query($this->db, "select count(*) as total from ".$table." where id like '%$val%' or hotelname like '%$val%'".$in);
             $result = mysqli_fetch_array($sql);
			// echo "select count(*) as total from ".$table." where 1=1 ". $w;
			 $total=$result['total'];
			 $count=$total/$num_per_page;
	          $reminder=$total%$num_per_page;
			  if($reminder!=0){
				  $count=$count+1;
			  }
			  if($total>$num_per_page){		  
			  return $count;
		  
			  }
             //return $result['total'];
         
    }
   function update($table, $columnsArray, $where, $requiredColumnsArray){ 
        //$this->verifyRequiredParams($columnsArray, $requiredColumnsArray);
		  //$msg=$this->existdata($columnsArray,$dataexist,$table); 		   
           $msg=$this->verifyRequiredParams($columnsArray,$requiredColumnsArray); 
			 if(count($msg[''])>0){
				 return $msg;
			 }
			 else {
            $a = array();
            $w = "";
            $c = "";
            foreach ($where as $key => $value) {
                $w .= " and " .$key. " = ".$value;
                $a[$key] = $value;
            }
            foreach ($columnsArray as $key => $value) {
				//if($value!=""){
                $c .= $key. " = '".$this->escape_string($value)."', ";
                $a[$key] = $value;
				//}
            }
             $c = rtrim($c,", ");
			 //echo "UPDATE $table SET $c WHERE 1=1 ".$w;	 
			 $sql = mysqli_query($this->db, "UPDATE $table SET $c WHERE 1=1 ".$w); 	
			 $response["message"] = "Item Updated Successfully";
			 return $response; 	
			 }
			 
    }
	/********Image Upload*************/

 public function image_upload($file,$dir_name) {

	if(trim($file['name'])!=""){
				$uploaddir = "../images/".$dir_name."/";
				$target_folder = "../images/".$dir_name."/thumbnails/";	
				$small_file_name = trim($file['name']);
				$small_file_len = strlen($small_file_name);
				$small_file_ext=strtolower(substr($small_file_name,-4)); 
				if($small_file_ext=="jpeg"){
					$small_file_ext=".jpeg";
				}
				$small_uploadfile = $uploaddir. $file['name'];
				if($small_file_len>4 and ($small_file_ext==".doc" or $small_file_ext=="docx" or $small_file_ext==".pdf" or $small_file_ext==".jpg" or $small_file_ext==".gif" or $small_file_ext==".png" or $small_file_ext==".jpeg")){
					$uniqname = uniqid(rand()).$small_file_ext;
					$uploadfile = $uploaddir.$uniqname;
					$name_file=$file['name'];
					if (move_uploaded_file($file['tmp_name'], $uploadfile)) { 
						$file_name = $uniqname;
					}else{
						$frm_server_side_error .= "frm_image_filename1";
						$frm_error_number = 10;  					}
					copy($uploaddir.$uniqname, $target_folder.$uniqname);
					$thumbnail=$target_folder.$uniqname;
					list($sourceWidth, $sourceHeight) = getimagesize($uploaddir.$uniqname);
		            $targetWidth = 150;  

		            $targetHeight = 150;  
					$sourceRatio = $sourceWidth / $sourceHeight;
					$targetRatio = $targetWidth / $targetHeight;
					if ( $sourceRatio < $targetRatio ) {
    				$scale = $sourceWidth / $targetWidth;
					} else {
   					$scale = $sourceHeight / $targetHeight;
					}
					$resizeWidth = (int)($sourceWidth / $scale);
					$resizeHeight = (int)($sourceHeight / $scale);
					 $thumb = imagecreatetruecolor($resizeWidth, $resizeHeight);
					if($small_file_ext==".png"){
						$source = imagecreatefrompng($thumbnail);
					}

					elseif($small_file_ext==".gif"){
						$source = imagecreatefromgif($thumbnail);
					}
					else {
						$source = imagecreatefromjpeg($thumbnail);
					}
		            imagecopyresized($thumb, $source, 0, 0, 0, 0, $resizeWidth, $resizeHeight, $sourceWidth, $sourceHeight);
		            imagejpeg($thumb, $thumbnail, 100);

				}



			}

			return $file_name ;

	}

 /************End Image Upload********/	
  function delete($table, $where){
	   
        if(count($where)<=0){
            $response["status"] = "warning";
            $response["message"] = "Delete Failed: At least one condition is required";
        }else{
                $a = array();
                $w = "";
                foreach ($where as $key => $value) {
                    $w .= " and " .$key. " = ".$value;
                    $a[$key] = $value;
                }
				//echo "DELETE FROM $table WHERE 1=1 ".$w;
				 $sql = mysqli_query($this->db, "DELETE FROM $table WHERE 1=1 ".$w);
				 $response["message"] = "Item Deleted Successfully";
				return $response;
				
				
                
            
        }
       
    }
	function insert_form($names,$elements,$values,$content_id,$table,$mode){
		 
		$i=0;
		if($mode=="edit"){
			//echo "delete from ".$table." where formid='$content_id'";
	    $sql_delete=mysqli_query($this->db,"delete from ".$table." where formid='$content_id'");
		}
		foreach($names as $name){ 
		if($name!="" && $elements[$i]!=""){
		$sql_insert=mysqli_query($this->db,"insert into ".$table." (formid,name,element,value) values ('$content_id','$name','".$elements[$i]."','".$values[$i]."')");
		}
		$i=$i+1;
	   }
		
	}
	 function insert($table, $columnsArray,$requiredColumnsArray,$dataexist) {
		 
             $msg=$this->verifyRequiredParams($columnsArray, $requiredColumnsArray);
			 if(count($msg)>0){
				  
				 return $msg;
			 }
			 else {
			 $msg=$this->existdata($columnsArray,$dataexist,$table); 
			 if(count($msg[''])>0){
				 return $msg;
			 }
			 else {
            $a = array();
            $c = "";
            $v = "";
			
			 
            foreach ($columnsArray as $key => $value) {
                $c .= $key. ", ";
                $v .= "'".$value."'". ", ";
                $a[$key] = $value;
            }
            $c = rtrim($c,', ');
            $v = rtrim($v,', ');
	     // echo "INSERT INTO $table($c) VALUES($v)";
	     //echo "<br/>";
			 
            $sql = mysqli_query($this->db, "INSERT INTO $table($c) VALUES($v)");
			 $id=mysqli_insert_id($this->db);
			 $response['id']=$id;
            $response["message"] = "Item added Successfully";
			return $response;
			 }
			 }
    }
    
	function appraisal_insert($table, $columnsArray,$requiredColumnsArray,$dataexist) {
		  
            $a = array();
            $c = "";
            $v = "";
			 
			 
            foreach ($columnsArray as $key => $value) {
                $c .= $key. ", ";
                $v .= "'".$value."'". ", ";
                $a[$key] = $value;
            }
            $c = rtrim($c,', ');
            $v = rtrim($v,', ');
            $sql = mysqli_query($this->db, "INSERT INTO $table($c) VALUES($v)");
            $response["message"] = "Appraisal added Successfully";
			return $response["message"];
 			  
    }
public function slug_exist($slug,$table,$content_id,$field_id){	

        if( $content_id==""){
		 // echo "SELECT customurl from ".$table." WHERE customurl='$slug'";
        $sql = mysqli_query($this->db,"SELECT customurl from ".$table." WHERE customurl='$slug'");
        $num=mysqli_num_rows($sql);	
			  if($num>0){
				   $rand = rand(10,50);
				   $slugtext = $slug."-".$rand;
				  return $slugtext;
			  }
			  else {
				  return $slug;
			  }
		}
		else {
			//echo "SELECT customurl from ".$table." WHERE ".$field_id."<>'$content_id'";
			$sql = mysqli_query($this->db,"SELECT customurl from ".$table." WHERE ".$field_id."='$content_id'");
			$sql_result=mysqli_fetch_array($sql);
			if($sql_result['customurl']==$slug){

                return $slug;

			  }

			  else {

				  

				  return $this->generate_slug($slug,$table);

				  

			  }

			

		}

 }
  public function generate_slug($slug,$table){
	 $sql =  mysqli_query($this->db,"SELECT customurl from ".$table." WHERE customurl='$slug'");
        $num=mysqli_num_rows($sql);
			  if($num>0){
				   $rand = rand(10,50);
				   $slugtext = $slug."-".$rand;
				  return $slugtext;
			  }
			  else {
				  return $slug;
			  }

}
public function escape_string($escape){

	$escaped_variable=mysqli_real_escape_string($this->db,$escape);

	return $escaped_variable;	

}
public function verifyRequiredParams($inArray, $requiredColumns) {
	 
        $error = false;
        $errorColumns = "";
        foreach ($requiredColumns as $field) {         
            if (!isset($inArray[$field]) || strlen(trim($inArray[$field])) <= 0) {
                $error = true;
               $errorColumns .= $field . ', ';
			   
            }
			
        }
		 
        if ($error) {
            $response = array();
            $response["status"] = "error";
            echo 'Required field(s) ' . rtrim($errorColumns, ', ') . ' is missing or empty';
            $response["message"] = 'Required field(s) ' . rtrim($errorColumns, ', ') . ' is missing or empty';
	    return $response["message"];
            //echoResponse(200, $response);
			 
            exit;
        }
    }
public function existdata($inArray,$dataexist,$table) {
	 
        $error = false;
        $errorColumns = "";
        foreach ($dataexist as $field) {
		 
		   $sql_user_exist = mysqli_query($this->db, "select count(".$field.") as exist from ".$table." where ".$field."='$inArray[$field]'");
			$result_user_exist = mysqli_fetch_array($sql_user_exist);
			if ($result_user_exist['exist'] > 0) {
				$error = true;
			}  
        }
		 if ($error) {
            $response = array();
            $response["message"] = 'Already Similar data exists';
			return $response["message"];
            exit;
        }
		
    }	
 public function getfieldvalue($field,$table,$wherefield,$fieldvalue)
    {
		 
        $sql = mysqli_query($this->db, "select ".$field." from ".$table." where ".$wherefield."='$fieldvalue'");
        $result= mysqli_fetch_array($sql);
        return $result[$field];
    }
 public function datapresent($table,$wherefield,$fieldvalue) {
	  // echo "select count(*) as total from ".$table." where ".$wherefield."='$fieldvalue'";
	    $sql = mysqli_query($this->db, "select count(*) as total from ".$table." where ".$wherefield."='$fieldvalue'");
        $result= mysqli_fetch_array($sql);
        return $result['total'];
	 }
 public function expireddatapresent($table,$wherefield) {
	   //echo "select count(*) as total from ".$table." where ".$wherefield;

	    $sql = mysqli_query($this->db, "select count(*) as total from ".$table." where ".$wherefield);
        $result= mysqli_fetch_array($sql);
        return $result['total'];
	 }
public function insert_mail($table, $columnsArray,$requiredColumnsArray,$dataexist) {
		 
             $msg=$this->verifyRequiredParams($columnsArray, $requiredColumnsArray);
			 if(count($msg)>0){
				  
				 return $msg;
			 }
			 else {
			 $msg=$this->existdata($columnsArray,$dataexist,$table); 
			 if(count($msg[''])>0){
				 return $msg;
			 }
			 else {
            $a = array();
            $c = "";
            $v = "";
			   if($columnsArray['password']!=""){
				 $password=$columnsArray['password'];
				 $password=md5($password);
				 unset($columnsArray['password']);
				  $p=array("password"=>$password);
			   }
			   else {
			   $pass=rand(10000,1000000);
			   $password=md5($pass);
			   }
			   $p=array("password"=>$password);
			   $columnsArray=array_merge($columnsArray,$p);
			  
			   if($columnsArray['typeid']==""){
				$usertype="Administrator";
			   } else {
				$usertype=$this->getfieldvalue("title","tbl_user_type","typeid",$columnsArray['typeid']);
			   }
			   $message="<p>Hi ".$columnsArray['firstname']."</p>";
			   $message.="<p>New <b>".$usertype."</b> account is created with email address ".$columnsArray['email']."</p>";
			   $message.="<p>Your new password is <b>".$pass."</b></p>";
			   $message.="<p>Login to the Website and change the password</p>";
			    $from="info@cfsuae.com";
				$to = $columnsArray['email'];
				$subject = "Account created on Century Fire Technical Services";
				$headers = "From:" . $from."\r\n";
				$headers .= "Content-type: text/html\r\n"; 
			 
            foreach ($columnsArray as $key => $value) {
                $c .= $key. ", ";
                $v .= "'".$value."'". ", ";
                $a[$key] = $value;
            }
            $c = rtrim($c,', ');
            $v = rtrim($v,', ');
			//echo "INSERT INTO $table($c) VALUES($v)";
            $sql = mysqli_query($this->db, "INSERT INTO $table($c) VALUES($v)");
			
			//$this->sent_email($to,$subject,$message,$headers,"","");
            $response["message"] = "Item added Successfully";
			return $response;
			 }
			 }
    }
public function update_mail($table, $columnsArray, $where, $requiredColumnsArray){ 
         $msg=$this->verifyRequiredParams($columnsArray,$requiredColumnsArray); 
			 if(count($msg[''])>0){
				 return $msg;
			 }
			 else {
            $a = array();
            $w = "";
            $c = "";
            foreach ($where as $key => $value) {
                $w .= " and " .$key. " = ".$value;
                $a[$key] = $value;
            }
			$password=$columnsArray['password'];
			if($password!=""){
			unset($columnsArray['password']);
			   $password=md5($password);
			   $p=array("password"=>$password);
			   $message="<p>Hi ".$columnsArray['firstname']."</p>";
			   $message.="<p>Your account is Updated </p>";
			   $message.="<p>Your new password is <b>".$p."</b></p>";
			   $message.="<p>Login to the Website and change the password</p>";
			    $from="info@aafaq.ae";
				$to = $columnsArray['email'];
				$subject = "Password updated on Aafaq Finance apprisal System";
				$headers = "From:" . $from."\r\n";
				$headers .= "Content-type: text/html\r\n";
				
			}
			$columnsArray=array_merge($columnsArray,$p);
            foreach ($columnsArray as $key => $value) {
				if($value!=""){
                $c .= $key. " = '".$value."', ";
                $a[$key] = $value;
				}
            }
             $c = rtrim($c,", ");
             echo "UPDATE $table SET $c WHERE 1=1 ".$w;
			 $sql = mysqli_query($this->db, "UPDATE $table SET $c WHERE 1=1 ".$w); 
			 $this->sent_email($to,$subject,$message,$headers,"","");	
			 $response["message"] = "Item Updated Successfully";
			 return $response["message"]; 	
			 }
    }
public function sent_email($to,$subject,$message,$headers,$success,$error){ 
      if(mail($to,$subject,$message,$headers)){		  
			//return $success;
		}
		else {
			//return $error;
		} 
}
public function checkperformance($val) {
	if($val==5){
		return "Out Standing";
	}
	elseif($val==4){
		return "V Good";
	}
	elseif($val==3){
		return "Good";
	}
	elseif($val==2){
		return "Marginal";
	}
	elseif($val==1){
		return "Unsatisfactory";
	}
	else {
		return "";
	}
	
}
public function reportmember() {
	 $sql = mysqli_query($this->db, "SELECT * FROM `tbl_members` WHERE `parent_id`=0");
         while ($result = mysqli_fetch_array($sql)) {
             $data[] = $result;
              }
          return $data;
	 }		
	
 
public function report($memberid,$formid) { 
   
	    $sql = mysqli_query($this->db, "select tbl_appraisal_details.formid as id,linemng,countersignmng,title,startdate,jobtitle,appearance,punctuality,quality,computer,attention,responsibility,attitude,communication,overallassessment,managerscomment,objectives,training,apraiseecomments,appearancedetails,punctualitydetails,qualitydetails,attentiondetails,responsibilitydetails,attitudedetails,communicationdetails,computerdetails from tbl_appraisal_details join tbl_appraisalform on tbl_appraisalform.formid = tbl_appraisal_details.formid where tbl_appraisal_details.formid='$formid' and tbl_appraisal_details.memberid='$memberid'");
        $result= mysqli_fetch_array($sql);
        return $result;
	 }
public function reportsubmembers($parentid,$formid){
	 
	 $sql = mysqli_query($this->db, "SELECT * FROM `tbl_members` WHERE `parent_id`=$parentid");
         while ($result = mysqli_fetch_array($sql)) {
             $data[] = $result;
              }
			  
          foreach($data as $reportmember){
			  $appraisaldetails=$this->report($reportmember['memberid'],$formid);
			   ?>
               <div class="outertable">
			   <table border="1" cellpadding="10" cellspacing="10" class="appraisaltable" width="700px">
             <tr><td colspan="2">
              <p style="text-align:center;font-size:16px;"><b>aafaq Islamic Finance </b></p>
              <p><b>Name : </b><?php echo $reportmember['firstname']." ".$reportmember['middlename']." ".$reportmember['lastname'];?></p>
              </td></tr>
              <?php
				$formdetails=$this->select("tbl_form","*",array("formid"=>$formid),"");
				 
				foreach($formdetails as $formdetail){
$valueexist=
$this->select("tbl_appraisal","value",array("formid"=>$formid,"memberid"=>$reportmember['memberid'],"fieldid"=>$formdetail['id']
),"");
?>
				<tr><td><b><?php echo $formdetail['name'];?></b></td><td><b><?php echo $valueexist[0]['value'];?></b></td></tr>
<?php 
 }
  
				?>
              <?php
			    
$memexist=
$this->select("tbl_appraisal_mem_details","*",array("formid"=>$formid,"memberid"=>$reportmember['memberid']),"");   
 
			   ?>
                 <tr><td colspan="2"><b>Overall Assessment/Comments :</b><br/><?php echo $memexist[0]['overallassessment'];?>
                <?php
			   if($memexist[0]['parent_id']!=0){
		      $mngdetails=$this->select("tbl_members","firstname,middlename,lastname",array("memberid"=>$memexist[0]['parent_id']),"");
			   }
			   else {
				   $mngdetails=$this->select("tbl_admin","firstname,middlename,lastname",array("userid"=>$memexist[0]['userid']),"");
			   }
		 
			  ?>
              
              <p><b>Signature :</b> <?php echo $mngdetails[0]['firstname']." ".$mngdetails[0]['middlename']." ".$mngdetails[0]['lasttname'];?> </p>
               </td></tr> 
              <tr><td colspan="2"><b>Countersigning Manager’s Comments:</b><br/>
              <?php echo $memexist[0]['managerscomment'];?>
              <?php
			   if($memexist[0]['countersignmng']!=0){
		      $mngdetails=$this->select("tbl_members","firstname,middlename,lastname",array("memberid"=>$memexist[0]['countersignmng']),"");
			   }
			   else {
				   $mngdetails=$this->select("tbl_admin","firstname,middlename,lastname",array("userid"=>$memexist[0]['userid']),"");
			   }
		 
			  ?>
              
              <p><b>Signature :</b> <?php echo $mngdetails[0]['firstname']." ".$mngdetails[0]['middlename']." ".$mngdetails[0]['lasttname'];?> </p>
              </td></tr>
              <tr><td colspan="2"><b>Appraisee’s comments: </b><br/>
              <?php echo $memexist[0]['apraiseecomments'];?></td></tr>
             </table>
             </div>
			   <?php
			  $this->reportsubmembers($reportmember['memberid'],$formid);
		  }
}

public function insert_appraisal($table,$values,$mem_id,$fom_id) {
		  
            foreach($values as $key => $value){			
            $sql = mysqli_query($this->db, "INSERT INTO $table(fieldid,value,memberid,formid) VALUES('$key','$value','$mem_id','$fom_id')");
			}
            $response["message"] = "Appraisal added Successfully";
			return $response["message"];
 			  
    }
	
public function  insert_appraisal_mem_details($table,$parent_id,$memberid,$formid,$apraiseecomments,$managerscomment,$overallassessment,$countersignmng,$userid){ 	
            $sql = mysqli_query($this->db, "INSERT INTO $table(formid,memberid,parent_id,managerscomment,apraiseecomments,overallassessment,userid,countersignmng) VALUES('$formid','$memberid','$parent_id','$managerscomment','$apraiseecomments','$overallassessment','$userid','$countersignmng')");
			
		 
            $response["message"] = "Appraisal added Successfully";
			return $response["message"];
}
public function  update_appraisal_mem_details($table,$parent_id,$memberid,$formid,$apraiseecomments,$managerscomment,$overallassessment,$countersignmng,$userid){
	 
	$sql="update $table set parent_id='$parent_id'";	
	if($managerscomment!=""){
	$sql.=",managerscomment='$managerscomment'"; 	
	}
	if($apraiseecomments!=""){
	$sql.=",apraiseecomments='$apraiseecomments'"; 	
	}
	if($overallassessment!=""){
	$sql.=",overallassessment='$overallassessment'"; 	
	}
	if($countersignmng!=""){
	$sql.=",countersignmng='$countersignmng'"; 	
	}
	if($parent_id!=""){
	$sql.=",parent_id='$parent_id'"; 	
	}
	if($userid!=""){
	$sql.=",userid='$userid'"; 	
	}
	$sql.=" where memberid='$memberid' and formid='$formid'";
	
	  $sql_query = mysqli_query($this->db, $sql);		
            $response["message"] = "Updated";
			return $response["message"];
}

public function selectappraisaldetails($memberid,$formid) { 
	    $sql = mysqli_query($this->db, "select * from  tbl_appraisal where memberid='$memberid' and formid='$formid'");
        $result= mysqli_fetch_array($sql);
        return $result;
	 }
 public function multiple_image_upload($file,$dir_name) {

	 /*multiple image upload start*/

  for($i=0;$i<count($file['name']);$i++)

{

if(trim($file['name'][$i])!=""){

				$uploaddir = "images/".$dir_name."/";

				$target_folder = "images/".$dir_name."/thumbnails/";

				$small_file_name = trim($file['name'][$i]);				

				$small_file_len = strlen($small_file_name);

				$small_file_ext=strtolower(substr($small_file_name,-4)); // select last 4 characters

				$small_uploadfile = $uploaddir. $file['name'][$i];
                 if($small_file_ext=="jpeg"){
					$small_file_ext=".jpeg";
				 }
				if($small_file_len>4 and ($small_file_ext==".png" or $small_file_ext==".gif" or  $small_file_ext==".jpg" or  $small_file_ext==".jpeg")){
                
				     $unid=uniqid(rand());

				    $name_to_db[] = $unid.$small_file_ext;

					$uniqname= $unid.$small_file_ext;

					$uploadfile = $uploaddir.$uniqname;	//uncomment for local testing 

					//echo $uploadfile;

					if (move_uploaded_file($file['tmp_name'][$i], $uploadfile)) {

						$file_name = $uniqname;

						$file_name=$uploaddir.$file_name;

						chmod($file_name,0777);

						

					}

					list($sourceWidth, $sourceHeight) = getimagesize($uploaddir.$uniqname);

					

					if($sourceWidth>1000 || $sourceHeight>1000){

					$thumbnail=$uploaddir.$uniqname;

					$targetWidth =1000; // This can be a set value or a percentage of original size ($width)

		            $targetHeight = 1000; //149 This can be a set value or a percentage of original size ($height)

					$sourceRatio = $sourceWidth / $sourceHeight;

					$targetRatio = $targetWidth / $targetHeight;

					if ( $sourceRatio < $targetRatio ) {

    				$scale = $sourceWidth / $targetWidth;

					} else {

   					$scale = $sourceHeight / $targetHeight;

					}

					$resizeWidth = (int)($sourceWidth / $scale);

					$resizeHeight = (int)($sourceHeight / $scale);

		            // Load the images

					 $thumb = imagecreatetruecolor($resizeWidth, $resizeHeight);

					if($small_file_ext==".png"){

							

						$source = imagecreatefrompng($thumbnail);

					}

					elseif($small_file_ext==".gif"){

					

						$source = imagecreatefromgif($thumbnail);

					}

					else {

						$source = imagecreatefromjpeg($thumbnail);

					}

		           

		            

		            // Resize the $thumb image.

		            imagecopyresized($thumb, $source, 0, 0, 0, 0, $resizeWidth, $resizeHeight, $sourceWidth, $sourceHeight);

		            // Save the new file to the location specified by $thumbnail

		            imagejpeg($thumb, $thumbnail, 100);

						

					}

					

					list($sourceWidth, $sourceHeight) = getimagesize($uploaddir.$uniqname);

					copy($uploaddir.$uniqname, $target_folder.$uniqname);

					$thumbnail=$target_folder.$uniqname;

					//list($sourceWidth, $sourceHeight) = getimagesize($uploaddir.$uniqname);

		            $targetWidth = 150; // This can be a set value or a percentage of original size ($width)

		            $targetHeight = 150; //149 This can be a set value or a percentage of original size ($height)

					$sourceRatio = $sourceWidth / $sourceHeight;

					$targetRatio = $targetWidth / $targetHeight;

					if ( $sourceRatio < $targetRatio ) {

    				$scale = $sourceWidth / $targetWidth;

					} else {

   					$scale = $sourceHeight / $targetHeight;

					}

					$resizeWidth = (int)($sourceWidth / $scale);

					$resizeHeight = (int)($sourceHeight / $scale);

		            // Load the images

					 $thumb = imagecreatetruecolor($resizeWidth, $resizeHeight);

					if($small_file_ext==".png"){

							

						$source = imagecreatefrompng($thumbnail);

					}

					elseif($small_file_ext==".gif"){

					

						$source = imagecreatefromgif($thumbnail);

					}

					else {

						$source = imagecreatefromjpeg($thumbnail);

					}

		           

		            

		            // Resize the $thumb image.

		            imagecopyresized($thumb, $source, 0, 0, 0, 0, $resizeWidth, $resizeHeight, $sourceWidth, $sourceHeight);

		            // Save the new file to the location specified by $thumbnail

		            imagejpeg($thumb, $thumbnail, 100);			

					

				}

}
}
return $name_to_db; 

 }
 public function insert_multiple_images($image,$id,$table,$field){
	 
	$sql_images=mysqli_query($this->db,"insert into ".$table." (image,".$field.") values ('$image','$id')");

}
 public function set_order($table,$a,$field_id,$key){ 
//echo "update ".$table." set int_order='$a' where ".$field_id."='$key'";
	     mysqli_query($this->db,"update ".$table." set int_order='$a' where ".$field_id."='$key'");

   }
   
 function selectexpired($table){
         
            $a = array();
            $w = "";
            foreach ($where as $key => $value) {
                $w .= " and " .$key. " = ".$value;
                $a[":".$key] = $value;
            }
			foreach ($order as $key => $value) {
                $orderby .= " order by " .$key. "  ".$value;
                //$a[":".$key] = $value;
            }
             $result = array();
			// echo "select ".$columns." from ".$table." where 1=1 and daystoexpire<0 order by daystoexpire DESC";
             $sql = mysqli_query($this->db, "select * from ".$table." where daystoexpire <> '' and daystoexpire<0 order by daystoexpire DESC");
              while ($result = mysqli_fetch_array($sql)) {
             $data[] = $result;
              }
             return $data;
            
         
    }
	function selectexpiredin15($table){
         
            $a = array();
            $w = "";
            foreach ($where as $key => $value) {
                $w .= " and " .$key. " = ".$value;
                $a[":".$key] = $value;
            }
			foreach ($order as $key => $value) {
                $orderby .= " order by " .$key. "  ".$value;
                //$a[":".$key] = $value;
            }
             $result = array();
			// echo "select * from ".$table." where daystoexpire <> '' and daystoexpire between 0 and 15 order by daystoexpire DESC";
             $sql = mysqli_query($this->db, "select * from ".$table." where daystoexpire <> '' and daystoexpire between 0 and 15 order by daystoexpire DESC");
              while ($result = mysqli_fetch_array($sql)) {
             $data[] = $result;
              }
             return $data;
            
         
    }
	function selectexpiredin30($table){
         
            $a = array();
            $w = "";
            foreach ($where as $key => $value) {
                $w .= " and " .$key. " = ".$value;
                $a[":".$key] = $value;
            }
			foreach ($order as $key => $value) {
                $orderby .= " order by " .$key. "  ".$value;
                //$a[":".$key] = $value;
            }
             $result = array();
			// echo "select ".$columns." from ".$table." where 1=1 and daystoexpire<0 order by daystoexpire DESC";
             $sql = mysqli_query($this->db, "select * from ".$table." where daystoexpire <> '' and daystoexpire between 15 and 30 order by daystoexpire DESC");
              while ($result = mysqli_fetch_array($sql)) {
             $data[] = $result;
              }
             return $data;
            
         
    }
	function selectexpiredin45($table){
         
            $a = array();
            $w = "";
            foreach ($where as $key => $value) {
                $w .= " and " .$key. " = ".$value;
                $a[":".$key] = $value;
            }
			foreach ($order as $key => $value) {
                $orderby .= " order by " .$key. "  ".$value;
                //$a[":".$key] = $value;
            }
             $result = array();
			// echo "select ".$columns." from ".$table." where 1=1 and daystoexpire<0 order by daystoexpire DESC";
             $sql = mysqli_query($this->db, "select * from ".$table." where daystoexpire <> '' and daystoexpire between 30 and 45 order by daystoexpire DESC");
              while ($result = mysqli_fetch_array($sql)) {
             $data[] = $result;
              }
             return $data;
            
         
    }
	
	function selectleaves($fromdate,$todate,$memberid){
             $sql = mysqli_query($this->db, "select * from tbl_appliedleaves where (fromdate between '$fromdate' and '$todate') and memberid='$memberid'");
              while ($result = mysqli_fetch_array($sql)) {
             $data[] = $result;
              }
             return $data;
            
         
    }
	function selectsearch($table, $columns, $where, $start, $limit){
            $start=$start*$limit;
            $a = array();
            $w = "";
            foreach ($where as $key => $value) {
                $w .= $key. " like '%$value%'";
                $a[":".$key] = $value;
            }
			 $countorderby=count($order);
			 $ord=" order by ";
			foreach ($order as $key => $value) {
                $orderby .= " " .$key. "  ".$value.",";
            }
			 
			$orderby=substr($orderby, 0, -1);
			if($countorderby>0){
			$orderby=$ord.$orderby;
			}
			 
			//$orderby .="order by businessid DESC,title ASC";
               $result = array();
		      echo "select ".$columns." from ".$table. " where " .$w.$orderby." limit ".$start.",".$limit;
              $sql = mysqli_query($this->db, "select ".$columns." from ".$table. " where " .$w.$orderby." limit ".$start.",".$limit);
              while ($result = mysqli_fetch_array($sql)) {
             $data[] = $result;
              }
             return $data;
            
         
    }
    function selecthotelsearch($table, $columns, $val, $start, $limit){
            $start=$start*$limit;
            $a = array();
            $w = "";
            foreach ($where as $key => $value) {
                $w .= $key. " like '%$value%'";
                $a[":".$key] = $value;
            }
			 $countorderby=count($order);
			 $ord=" order by ";
			foreach ($order as $key => $value) {
                $orderby .= " " .$key. "  ".$value.",";
            }
			 
			$orderby=substr($orderby, 0, -1);
			if($countorderby>0){
			$orderby=$ord.$orderby;
			}
		if($countrytomanage!=""){
                 $andvalue=" and country='$countrytomanage'";
                }	 
			//$orderby .="order by businessid DESC,title ASC";
               $result = array();
               echo  "select ".$columns." from ".$table. " where id like '%$val%' or hotelname like '%$val%'".$andvalue.$orderby." limit ".$start.",".$limit;
               $sql = mysqli_query($this->db, "select ".$columns." from ".$table. " where id like '%$val%' or hotelname like '%$val%'".$andvalue.$orderby." limit ".$start.",".$limit);
              while ($result = mysqli_fetch_array($sql)) {
             $data[] = $result;
              }
             return $data;
            
         
    }
    function selecthotelsearchstaff($table, $columns, $val, $start, $limit,$countrytomanage){
            $start=$start*$limit;
            $a = array();
            $w = "";
            foreach ($where as $key => $value) {
                $w .= $key. " like '%$value%'";
                $a[":".$key] = $value;
            }
			 $countorderby=count($order);
			 $ord=" order by ";
			foreach ($order as $key => $value) {
                $orderby .= " " .$key. "  ".$value.",";
            }
			 
			$orderby=substr($orderby, 0, -1);
			if($countorderby>0){
			$orderby=$ord.$orderby;
			}
		if($countrytomanage!=""){
                 $andvalue=" and country IN(".$countrytomanage.")";
                }	 
			//$orderby .="order by businessid DESC,title ASC";
               $result = array();
                 
               $sql = mysqli_query($this->db, "select ".$columns." from ".$table. " where (id like '%$val%' or hotelname like '%$val%')".$andvalue.$orderby." limit ".$start.",".$limit);
              while ($result = mysqli_fetch_array($sql)) {
             $data[] = $result;
              }
             return $data;
            
         
    }
	function branchsearch($table, $columns, $where, $start, $limit,$clientid){
            $start=$start*$limit;
            $a = array();
            $w = "";
            foreach ($where as $key => $value) {
                $w .= $key. " like '%$value%'";
                $a[":".$key] = $value;
            }
			$w=$w." and clientid='$clientid'";
			 $countorderby=count($order);
			 $ord=" order by ";
			foreach ($order as $key => $value) {
                $orderby .= " " .$key. "  ".$value.",";
            }
			 
			$orderby=substr($orderby, 0, -1);
			if($countorderby>0){
			$orderby=$ord.$orderby;
			}
			 
			//$orderby .="order by businessid DESC,title ASC";
             $result = array();
		      //echo "select ".$columns." from ".$table. " where " .$w.$orderby." limit ".$start.",".$limit;
              $sql = mysqli_query($this->db, "select ".$columns." from ".$table. " where " .$w.$orderby." limit ".$start.",".$limit);
              while ($result = mysqli_fetch_array($sql)) {
             $data[] = $result;
              }
             return $data;
            
         
    }
	function projectsearch($table, $columns, $where, $start, $limit,$branchid,$searchservice){
            $start=$start*$limit;
            $a = array();
            $w = " where ";
            foreach ($where as $key => $value) {
                $w .= $key. " like '%$value%'";
                $a[":".$key] = $value;
            }
			$w=$w." and branchid='$branchid'";
			if($searchservice!=""){
				$w.=" and service='$searchservice'";
			}
			
			 $countorderby=count($order);
			 $ord=" order by ";
			foreach ($order as $key => $value) {
                $orderby .= " " .$key. "  ".$value.",";
            }
			 
			$orderby=substr($orderby, 0, -1);
			if($countorderby>0){
			$orderby=$ord.$orderby;
			}
			 
			//$orderby .="order by businessid DESC,title ASC";
             $result = array();
		   // echo "select ".$columns." from ".$table.$w.$orderby." limit ".$start.",".$limit;
              $sql = mysqli_query($this->db, "select ".$columns." from ".$table.$w.$orderby." limit ".$start.",".$limit);
              while ($result = mysqli_fetch_array($sql)) {
             $data[] = $result;
              }
             return $data;
            
         
    }
	function selectreport($table, $columns,$projectid,$startdate,$enddate){
            
             $result = array();
			  
 $sql = mysqli_query($this->db,
 "select ".$columns." from ".$table." where projectid='$projectid' and scheduledate between '$startdate' and '$enddate' order by scheduledate ASC");
              while ($result = mysqli_fetch_array($sql)) {
             $data[] = $result;
              }
             return $data;           
         
    }
	 public function tbl_project_services($serviceid,$projectid,$table){	 
	$sql_images=mysqli_query($this->db,"insert into ".$table." (serviceid,projectid) values ('$serviceid','$projectid')");
    }
	public function tbl_company_type($contractid,$companyid,$table){	 
	$sql_images=mysqli_query($this->db,"insert into ".$table." (typeid,companyid) values ('$contractid','$companyid')");
    }
	public function tbl_emergency_services($serviceid,$emergencyid,$table){	 
	$sql_images=mysqli_query($this->db,"insert into ".$table." (serviceid,emergencyid) values ('$serviceid','$emergencyid')");
    }
	
	public function check_types($table,$type_field,$typeid,$content_id){	
	//echo "select count(*) as total from ".$table." where companyid='$content_id' and ".$type_field."=".$typeid;	
	$sql_check_types=mysqli_query(
	$this->db,"select count(*) as total from ".$table." where companyid='$content_id' and ".$type_field."=".$typeid);
	$result=mysqli_fetch_array($sql_check_types);
	return $result['total'];
	}
	public function check_emg_types($table,$type_field,$typeid,$content_id){		
	$sql_check_types=mysqli_query(
	$this->db,"select count(*) as total from ".$table." where emergencyid='$content_id' and ".$type_field."=".$typeid);
	$result=mysqli_fetch_array($sql_check_types);
	return $result['total'];
	}
	public function displayservices($projectid){		
	$sql_check_types=mysqli_query(
	$this->db,"select title from tbl_services join tbl_project_services on tbl_services.serviceid=tbl_project_services.serviceid where  tbl_project_services.projectid='$projectid' group by tbl_services.serviceid");
	while ($result = mysqli_fetch_array($sql_check_types)) {
             $data[] = $result;
              }
             return $data;
	}
	
  
 function selectbetweenlimit($table, $columns, $where, $start, $limit, $order){
            $start=$start*$limit;
            $a = array();
            $w = $where;
             
			 $countorderby=count($order);
			 $ord=" order by ";
			foreach ($order as $key => $value) {
                $orderby .= " " .$key. "  ".$value.",";
            }
			 
			$orderby=substr($orderby, 0, -1);
			if($countorderby>0){
			$orderby=$ord.$orderby;
			}
			 
			//$orderby .="order by businessid DESC,title ASC";
             $result = array();
		  //echo "select ".$columns." from ".$table." where 1=1 ". $w.$orderby." limit ".$start.",".$limit;
              $sql = mysqli_query($this->db, "select ".$columns." from ".$table." where 1=1 ". $w.$orderby." limit ".$start.",".$limit);
              while ($result = mysqli_fetch_array($sql)) {
             $data[] = $result;
              }
             return $data;
            
         
    }
function hotelgroupcontact($name,$position,$functionarea,$emailid,$phone,$content_id,$table,$mode){		 
		$j=0;
		if($mode=="edit"){			
	    $sql_delete=mysqli_query($this->db,"delete from ".$table." where groupid='$content_id'");
		}
		foreach($name as $sname){ 		 
		if($position[$j]!=""){ 
		$sql_insert=mysqli_query($this->db,"insert into ".$table." (name,position,functionarea,contactemail,contactphone,groupid) values ('$sname','".$position[$j]."','".$functionarea[$j]."','".$emailid[$j]."','".$phone[$j]."','$content_id')");		 
		}
		 
		$j=$j+1;
	   }
		
	}
	public function hotelcontractors($typeid){	 
	$sql_check_types=mysqli_query(
	$this->db,"select tbl_company.companyname,tbl_company.companyid from tbl_company  join tbl_company_type on tbl_company.companyid=tbl_company_type.companyid where tbl_company_type.typeid='$typeid'");
	while ($result = mysqli_fetch_array($sql_check_types)) {
             $data[] = $result;
              }
             return $data;
	}
	
function companygroupcontact($name,$position,$functionarea,$emailid,$phone,$content_id,$table,$mode){		 
		$j=0;
		if($mode=="edit"){			
	    $sql_delete=mysqli_query($this->db,"delete from ".$table." where companyid='$content_id'");
		}
		foreach($name as $sname){ 		 
		if($position[$j]!=""){ 
		$sql_insert=mysqli_query($this->db,"insert into ".$table." (name,position,functionarea,contactemail,contactphone,companyid) values ('$sname','".$position[$j]."','".$functionarea[$j]."','".$emailid[$j]."','".$phone[$j]."','$content_id')");		 
		}
		 
		$j=$j+1;
	   }
		
	}
        
function selectjoincompany($typeid,$companyname){
          
             $result = array();
             $sqlquery="select tbl_company.companyid,companyname from tbl_company join tbl_company_type on tbl_company_type.companyid=tbl_company.companyid where tbl_company_type.typeid='$typeid' and tbl_company.companyname='$companyname'";
              //echo $sqlquery;
               
              $sql = mysqli_query($this->db, $sqlquery);
              while ($result = mysqli_fetch_array($sql)) {
             $data[] = $result;
              }
             return $data;
            
         
    }
function insertextradata($table, $columns,$value) {
		 echo "INSERT INTO $table($columns) VALUES('$value')";	 
            $sql = mysqli_query($this->db, "INSERT INTO $table($columns) VALUES('$value')");
			 $id=mysqli_insert_id($this->db);
			  
			return $id;
			  
    }	
function inserhoteldata($id,$hotelname,$statusid,$phasesid,$hoteltypeid,$categoryid,$openingdate,$stars,$rooms,$tbi,$city,$groupid,$area,$industrytype,$lastupdated,$latitude,$longitude,$landmark,$plotno,$note,$scope,$watchman,$watchmanno) {
    $image=$id.".jpg";
		  $sqlhotel="INSERT INTO tbl_hotels (id,hotelname,projectstatus,projectphase,hotel_type_group,projectcategory,openingdate,stars,rooms,tbi,city,hotelgroup,status,location,str_update,industrytype,image,latitude,longitude,nearstlandmark,plotno,notes,scope,watchman,watchmanphone) VALUES('$id','$hotelname','$statusid','$phasesid','$hoteltypeid','$categoryid','$openingdate','$stars','$rooms','$tbi','$city','$groupid',1,'$area','$industrytype','$lastupdated','$image','$latitude','$longitude','$landmark','$plotno','$note','$scope','$watchman','$watchmanno')";	 
               // echo $sqlhotel;
                //echo "<br/>";
                 $sql = mysqli_query($this->db,$sqlhotel);
		 $id=mysqli_insert_id($this->db);
		return $id;
			  
    }
    function inserhotelcompanies($hotelid,$id,$developerowner,$developercompany,$developerphone,$developeraddress,$client_rep_name,$client_rep_phone,$client_rep_email,$client_rep_visit_time,$consultant_company,$consultant_address,$consultant_phone,$consultant_pm_name,$consultant_pm_phone,$consultant_pm_email,$contracting_company,$contracting_address,$contracting_phone,$contracting_pm_name,$contracting_pm_phone,$contracting_pm_email,$interior_company,$interior_address,$interior_phone,$interior_pm_name,$interior_pm_phone,$interior_pm_email,$operator_company,$operator_address,$operator_phone,$operator_pm_name,$operator_pm_phone,$operator_pm_email,$clientposition) {
        $sqlcompanies="INSERT INTO  tbl_hotelcompanies (hotelid,hotelno,developerowner,developercompany,developerphone,developeraddress,client_rep_name,client_rep_phone,client_rep_email,client_rep_visit_time,consultant_company,consultant_address,consultant_phone,consultant_pm_name,consultant_pm_phone,consultant_pm_email,contracting_company,contracting_address,contracting_phone,contracting_pm_name,contracting_pm_phone,contracting_pm_email,interior_company,interior_address,interior_phone,interior_pm_name,interior_pm_phone,interior_pm_email,operator_company,operator_address,operator_phone,operator_pm_name,operator_pm_phone,operator_pm_email,clientposition) VALUES('$hotelid','$id','$developerowner','$developercompany','$developerphone','$developeraddress','$client_rep_name','$client_rep_phone','$client_rep_email','$client_rep_visit_time','$consultant_company','$consultant_address','$consultant_phone','$consultant_pm_name','$consultant_pm_phone','$consultant_pm_email','$contracting_company','$contracting_address','$contracting_phone','$contracting_pm_name','$contracting_pm_phone','$contracting_pm_email','$interior_company','$interior_address','$interior_phone','$interior_pm_name','$interior_pm_phone','$interior_pm_email','$operator_company','$operator_address','$operator_phone','$operator_pm_name','$operator_pm_phone','$operator_pm_email','$clientposition')";	 
           echo $sqlcompanies;
                echo "<br/>";
                 $sql = mysqli_query($this->db,$sqlcompanies);
		 $id=mysqli_insert_id($this->db);
		return $id;
			  
    }
 function inserthotelcontractors($hotelid,$companyid,$typeid) {  
            $sql = mysqli_query($this->db, "INSERT INTO tbl_hotelcontractors(hotelid,companyid,typeid) Values ('$hotelid','$companyid','$typeid')");
			 $id=mysqli_insert_id($this->db);
			  
			return $id;
			  
    }  
    
    function updatecompany($companyname,$phone,$fax,$email,$address) {  
            $sql = mysqli_query($this->db, "update tbl_company set email='$email',phone='$phone',fax='$fax',address='$address' where companyname='$companyname'");
			 $id=mysqli_insert_id($this->db);			  
			return $id;
			  
    }  
    function insertcompany($companyname,$phone,$fax,$email,$address,$typeid) {  
            $sql = mysqli_query($this->db, "insert tbl_company (companyname,email,phone,fax,address) values ('$companyname','$email','$phone','$fax','$address')");
			 $id=mysqli_insert_id($this->db);
            $sql1 = mysqli_query($this->db, "insert tbl_company_type (typeid,companyid) values ('$typeid','$id')");
			
			  
    } 
    function insertcompanytype($companyid,$typeid) {               
            $sql1 = mysqli_query($this->db, "insert tbl_company_type (typeid,companyid) values ('$typeid','$companyid')");
			
			  
    } 
     public function hotelexist($hotelid)
    {
       //echo "select count(hotels) as exist from tbl_hotelcompanies where hotelid='$hotelid'";
        $sql_user_exist = mysqli_query($this->db, "select count(hotelid) as exist from tbl_hotelcompanies where hotelid='$hotelid'");
        $result_user_exist = mysqli_fetch_array($sql_user_exist);
        if ($result_user_exist['exist'] > 0) {
            $error = "Hotel Exist Already";
            return $error;
        }
    }
    public function numberofhotels($table,$wherefield) { 
 
	    $sql = mysqli_query($this->db, "select count(*) as total from ".$table." where ".$wherefield);
        $result= mysqli_fetch_array($sql);
        return $result['total'];
	 } 
  function selectexpireusers($table, $columns, $where, $start, $limit, $order){
            //print_r($where);
            $start=$start*$limit;
            $a = array();
            $w = "";
            foreach ($where as $key => $value) {
                $w .= " and " .$key. " = '$value'";
                $a[":".$key] = $value;
            }
			 $countorderby=count($order);
			 $ord=" order by ";
			foreach ($order as $key => $value) {
                $orderby .= " " .$key. "  ".$value.",";
            }
			 
			$orderby=substr($orderby, 0, -1);
			if($countorderby>0){
			$orderby=$ord.$orderby;
			}
                if($_SESSION['userrole']==3 && $_SESSION['staffid']!=""){
                    $nd=" and salesid=".$_SESSION['staffid'];
                }
			 
			//$orderby .="order by businessid DESC,title ASC";
             $result = array();
		// echo "select ".$columns." from ".$table." where 1=1 and expirydate < CURRENT_DATE() limit ".$start.",".$limit;
              $sql = mysqli_query($this->db, "select ".$columns." from ".$table." where 1=1 and expirydate < CURRENT_DATE()".$nd." limit ".$start.",".$limit);
              while ($result = mysqli_fetch_array($sql)) {
             $data[] = $result;
              }
             return $data;
            
         
    }
    function countofexpiredata($table,$where,$num_per_page){
            $a = array();
            $w = "";
			if(count($where)>0){
            foreach ($where as $key => $value) {
                $w .= " and " .$key. " = ".$value; 
                $a[":".$key] = $value;
            }
			}
             $result = array(); 
              if($_SESSION['userrole']==3 && $_SESSION['staffid']!=""){
                    $nd=" and salesid=".$_SESSION['staffid'];
                } 
             $sql = mysqli_query($this->db, "select count(*) as total from ".$table." where 1=1".$nd." and expirydate < CURRENT_DATE()");
             $result = mysqli_fetch_array($sql);
			 $total=$result['total'];
			 $count=$total/$num_per_page;
	          $reminder=$total%$num_per_page;
			  if($reminder!=0){
				  $count=$count+1;
			  }
			  if($total>$num_per_page){		  
			  return $count;
		  
			  }
             //return $result['total'];
         
    }
    function countofexpiredatain30days($table,$where,$num_per_page){
            $a = array();
            $w = "";
			if(count($where)>0){
            foreach ($where as $key => $value) {
                $w .= " and " .$key. " = ".$value; 
                $a[":".$key] = $value;
            }
			}
             if($_SESSION['userrole']==3 && $_SESSION['staffid']!=""){
                    $nd=" and salesid=".$_SESSION['staffid'];
                }           
             $result = array();             
             $sql = mysqli_query($this->db, "select count(*) as total from ".$table." where 1=1".$nd." and expirydate BETWEEN CURRENT_DATE()AND DATE_ADD(CURRENT_DATE(), INTERVAL 30 DAY)");
             $result = mysqli_fetch_array($sql);
			 $total=$result['total'];
			 $count=$total/$num_per_page;
	          $reminder=$total%$num_per_page;
			  if($reminder!=0){
				  $count=$count+1;
			  }
			  if($total>$num_per_page){		  
			  return $count;
		  
			  }
             //return $result['total'];
         
    }
    function selectexpireusersin30days($table, $columns, $where, $start, $limit, $order){ 
            $start=$start*$limit;
            $a = array();
            $w = "";
            foreach ($where as $key => $value) {
                $w .= " and " .$key. " = '$value'";
                $a[":".$key] = $value;
            }
			 $countorderby=count($order);
			 $ord=" order by ";
			foreach ($order as $key => $value) {
                $orderby .= " " .$key. "  ".$value.",";
            }
			 
			$orderby=substr($orderby, 0, -1);
			if($countorderby>0){
			$orderby=$ord.$orderby;
			}
			 
		if($_SESSION['userrole']==3 && $_SESSION['staffid']!=""){
                    $nd=" and salesid=".$_SESSION['staffid'];
                }	 
             $result = array();
		
              $sql = mysqli_query($this->db, "select ".$columns." from ".$table." where 1=1".$nd." and expirydate BETWEEN CURRENT_DATE()AND DATE_ADD(CURRENT_DATE(), INTERVAL 30 DAY)limit ".$start.",".$limit);
              while ($result = mysqli_fetch_array($sql)) {
             $data[] = $result;
              }
             return $data;
            
         
    }
     function approveemail($userid,$table){
         $userdetails=$this->select($table,"*",array("int_user_id"=>$userid));
         $permitted_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
         $pass=substr(str_shuffle($permitted_chars), 0, 10);
	 $password=md5($pass);
         mysqli_query($this->db,"update tbl_users set password='$password' where int_user_id='$userid'");
          
         $table='<table style="background:#e6e7e8;width:700px;">';
$table.='<tr><td colspan="3" style="text-align:center;"><br/><img src=\'http://menahotelprojects.com/images/emaillogo.png\'/></td></tr>';
$table.='<tr><td colspan="3" style="text-align:center;"><h2 style="color:#a60808;"><br/>Ready To Get Started?</h2></td></tr>';
$table.='<tr><td colspan="3">';
$table.='<table style="background:#fff;width:600px;margin:50px;">';
$table.='<tr><td style="padding:20px;">';
$table.='<p>Dear '.$userdetails[0]['firstname'].' '.$userdetails[0]['lastname'].',</p>';
$table.='<p>Welcome to MENA Hotel Projects, The Region\'s Only Hotel Project Tracker</p>';
if($userdetails[0]['plan']==2) {
$table.='<p>Your MENA Trial Account has been successfully created and you have been awarded 3 hotel
projects to access from our thousands of upcoming hotel projects database.</p>';
}
 
$table.='<p>Your login credentials are:<br/>Username : '.$userdetails[0]['email'].'<br/>Password : '.$pass.'</p>';
if($userdetails[0]['plan']==2) {
$table.='<p><p>Initially your test account is created in limited status. This means you cannot experience all the features. Once you sign up for an annual contact, you will be automatically upgraded to Full Access</p>';
}
if($userdetails[0]['plan']==1) {
$table.="<p>Your account is activated and now you can experience all the features.</p>";
          }
$table.="<p style='text-align:center;'>We are excited to have you on-board and we wish you the best!</p>";
          
$table.='</td></tr>';
$table.='<tr><td style="text-align:center;"><h1 style="color:#a60808;">Work Smarter Not Harder</h1></td></tr>';
$table.='<tr><td style="text-align:center;"><p style="text-align:center;">To find more, please visit our website<br/><br/><a href="https://menahotelprojects.com"/><img src="https://menahotelprojects.com/images/linkmena.jpg"/></a></p></td></tr>';
$table.='<tr><td style="background:#fff;padding:20px;"><p><br/>With Kind Regards<br/>MENA Hotel Projects Team</p></td></tr>';
$table.='<tr><td style="border-top:1px solid #c9cbcc;padding-bottom:10px;background:#e6e7e8;"></td></tr>';
$table.='</table>';
$table.='</td></tr>';

$table.='<tr><td style="padding:10px;"><p style="font-size:11px;line-height:18px;">Clifford Landman<br/>
Sales Manager - Middle East<br/>
Phone: +971 52 441 3994<br/>
Email: <a href="mailto:clandman@menahotelprojects.com">clandman@menahotelprojects.com</a></p>
<p style="font-size:11px;line-height:18px;">Sales Manager - International<br/>
Kithan Kumar<br/>
Phone: +971 58 540 4243<br/>
Email: <a href="mailto:kkumar@menahotelprojects.com">kkumar@menahotelprojects.com</a></p>
</td>
<td><p style="font-size:11px;line-height:18px;border-left:2px solid #a60808;padding-left:10px;">MENA Hotel Projects LLC<br/>
P.O.Box 12356, Dubai - UAE<br/>
Phone: +971 4 273 9974<br/>
Email: <a href="mailto:support@menahotelprojects.com">support@menahotelprojects.com</a><br/>
Web: <a href="https://menahotelprojects.com">www.menahotelprojects.com</a></p>
</td><td><p><img src="https://menahotelprojects.com/images/logo2.png"/></p>
</td></tr>';
 $table.='</table>';
 $salemandetails= $this->select("tbl_staff","*",array("staffid"=>$userdetails[0]['salesid']));
 
                                $subject="Menahotelprojects account activated ";
                                $emailto = $userdetails[0]['email'];
				$toname = 'menahotelprojects';
				$emailfrom = 'sales@menahotelprojects.com';
				$fromname = 'menahotelprojects'; 
				$headers = 
					'Return-Path: ' . $emailfrom . "\r\n" . 
					'From: ' . $fromname . ' <' . $emailfrom . '>' . "\r\n" . 
					'X-Priority: 3' . "\r\n" . 
					'X-Mailer: PHP ' . phpversion() .  "\r\n" . 
					'Reply-To: ' . $fromname . ' <' . $userdetails[0]['email'] . '>' . "\r\n" .
					'MIME-Version: 1.0' . "\r\n" . 
					'Content-Transfer-Encoding: 8bit' . "\r\n" .  
					'Content-Type: text/html; charset=UTF-8' . "\r\n";
				$params = '-f ' . $emailfrom;
                                mail($emailto, $subject, $table, $headers, $params);
     $mailmsg2='<p>Dear '.$salemandetails[0]['firstname'].' '.$salemandetails[0]['firstname'].'</p>';
     $mailmsg2.='<p>Account created for '.$userdetails[0]['firstname'].' '.$userdetails[0]['lastname'].' is now activated</p>'; 
     $mailmsg2.='<p>Login details were forwarded to customer email</p>'; 
     $mailmsg2.='<p>Please provide all asistance what they needed</p>';
     $subject="Menahotelprojects - Account activated ";
                                $emailto = $salemandetails[0]['email'];
				$toname = 'menahotelprojects';
				$emailfrom = 'sales@menahotelprojects.com';
				$fromname = 'menahotelprojects'; 
				$headers = 
					'Return-Path: ' . $emailfrom . "\r\n" . 
					'From: ' . $fromname . ' <' . $emailfrom . '>' . "\r\n" . 
					'X-Priority: 3' . "\r\n" . 
					'X-Mailer: PHP ' . phpversion() .  "\r\n" . 
					'Reply-To: ' . $fromname . ' <' . $salemandetails[0]['email'] . '>' . "\r\n" .
					'MIME-Version: 1.0' . "\r\n" . 
					'Content-Transfer-Encoding: 8bit' . "\r\n" .  
					'Content-Type: text/html; charset=UTF-8' . "\r\n";
				$params = '-f ' . $emailfrom;
                                mail($emailto, $subject, $mailmsg2, $headers, $params);
         
     } 
     function visitedhotels($table, $columns, $where, $start, $limit, $order){
            //print_r($where);
            $start=$start*$limit;
            $a = array();
            $w = "";
            foreach ($where as $key => $value) {
                $w .= " and " .$key. " = '$value'";
                $a[":".$key] = $value;
            }
			 $countorderby=count($order);
			 $ord=" order by ";
			foreach ($order as $key => $value) {
                $orderby .= " " .$key. "  ".$value.",";
            }
			 
			$orderby=substr($orderby, 0, -1);
			if($countorderby>0){
			$orderby=$ord.$orderby;
			}
			 
			//$orderby .="order by businessid DESC,title ASC";
             $result = array();
              //echo "select ".$columns." from ".$table." where 1=1 and hotelname <>''  ". $w.$orderby." limit ".$start.",".$limit;
              $sql = mysqli_query($this->db, "select ".$columns." from ".$table." where 1=1 and hotelname <>''  ". $w.$orderby." limit ".$start.",".$limit);
              while ($result = mysqli_fetch_array($sql)) {
             $data[] = $result;
              }
             return $data;
            
         
    }
    
    public function allowedcountries(){
       $sql = mysqli_query($this->db, "select tbl_country.country,tbl_country.countryid from tbl_country join tbl_hotels on tbl_hotels.country=tbl_country.countryid group by tbl_hotels.country");   
       while ($result = mysqli_fetch_array($sql)) {
             $data[] = $result;
              }
             return $data;
    
     }
     public function intemporarytable ($table,$staffid,$hotelid){
        // echo "select count(*) as total from ".$table." where 1=1 and  staffid=".$staffid." and approvalstatus=1 and hotelid='$hotelid'";
         $sql = mysqli_query($this->db, "select count(*) as total,tempid from ".$table." where 1=1 and  staffid=".$staffid." and approvalstatus=1 and hotelid='$hotelid'");
         $result = mysqli_fetch_array($sql);
	// $total=$result['total'];
         return $result;
     }
    public function updatesecondarytable ($staffid,$hotelid,$hoteltempid){
       $sql = mysqli_query($this->db, "INSERT INTO `tbl_hotelcompanies_temporary` (`id`, `hotelid`, `hotelno`, `developerowner`, `developercompany`, `developerphone`, `developeraddress`, `client_rep_name`, `client_rep_phone`, `client_rep_email`, `client_rep_visit_time`, `consultant_company`, `consultant_address`, `consultant_phone`, `consultant_pm_name`, `consultant_pm_phone`, `consultant_pm_email`, `contracting_company`, `contracting_address`, `contracting_phone`, `contracting_pm_name`, `contracting_pm_phone`, `clientposition`, `contracting_pm_email`, `interior_company`, `interior_address`, `interior_phone`, `interior_pm_name`, `interior_pm_phone`, `interior_pm_email`, `operator_company`, `operator_address`, `operator_phone`, `operator_pm_name`, `operator_pm_phone`, `operator_pm_email`,`hoteltempid`,`staffid`) select `id`, `hotelid`, `hotelno`, `developerowner`, `developercompany`, `developerphone`, `developeraddress`, `client_rep_name`, `client_rep_phone`, `client_rep_email`, `client_rep_visit_time`, `consultant_company`, `consultant_address`, `consultant_phone`, `consultant_pm_name`, `consultant_pm_phone`, `consultant_pm_email`, `contracting_company`, `contracting_address`, `contracting_phone`, `contracting_pm_name`, `contracting_pm_phone`, `clientposition`, `contracting_pm_email`, `interior_company`, `interior_address`, `interior_phone`, `interior_pm_name`, `interior_pm_phone`, `interior_pm_email`, `operator_company`, `operator_address`, `operator_phone`, `operator_pm_name`, `operator_pm_phone`, `operator_pm_email`,'$hoteltempid','$staffid' from tbl_hotelcompanies where hotelid='$hotelid'"); 
    }
    public function updateprimarytable ($staffid,$hotelid){
       $sql = mysqli_query($this->db, "INSERT INTO `tbl_hotels_temporary` (`hotelid`, `id`, `hotelname`, `address`, `email`, `phone`, `city`, `state`, `country`, `pobox`, `projectphase`, `projectstatus`, `percentage`, `stars`, `projectcategory`, `hotelcategory`, `rooms`, `tbi`, `openingdate`, `hotel_type_group`, `description`, `image`, `status`, `user_id`, `str_date`, `industrytype`, `location`, `str_update`, `latitude`, `longitude`, `hotelgroup`, `nearstlandmark`, `plotno`, `notes`, `scope`, `watchman`, `watchmanphone`, `trial`, `staffid`,  `approvalstatus`) select `hotelid`, `id`, `hotelname`, `address`, `email`, `phone`, `city`, `state`, `country`, `pobox`, `projectphase`, `projectstatus`, `percentage`, `stars`, `projectcategory`, `hotelcategory`, `rooms`, `tbi`, `openingdate`, `hotel_type_group`, `description`, `image`, `status`, `user_id`, `str_date`, `industrytype`, `location`, `str_update`, `latitude`, `longitude`, `hotelgroup`, `nearstlandmark`, `plotno`, `notes`, `scope`, `watchman`, `watchmanphone`, `trial`,'$staffid',1 from tbl_hotels where hotelid='$hotelid'"); 
       $id=mysqli_insert_id($this->db);
       $response['id']=$id;
       return $response;
       
    }
    public function listcolumn ($sql1){
          $sql = mysqli_query($this->db,$sql1);
         while ($result = mysqli_fetch_array($sql)) {
             $data[] = $result;
              }
             return $data;
     }
     
    public function approvehoteldata($tempid){ 
   $today=date('Y-m-d');
  $sqlquery="UPDATE tbl_hotels INNER JOIN tbl_hotels_temporary ON tbl_hotels.hotelid = tbl_hotels_temporary.hotelid SET 
          tbl_hotels.hotelid = tbl_hotels_temporary.hotelid,
tbl_hotels.id = tbl_hotels_temporary.id,
tbl_hotels.hotelname = tbl_hotels_temporary.hotelname,
tbl_hotels.address = tbl_hotels_temporary.address,
tbl_hotels.email = tbl_hotels_temporary.email,
tbl_hotels.phone = tbl_hotels_temporary.phone,
tbl_hotels.city = tbl_hotels_temporary.city,
tbl_hotels.state = tbl_hotels_temporary.state,
tbl_hotels.country = tbl_hotels_temporary.country,
tbl_hotels.pobox = tbl_hotels_temporary.pobox,
tbl_hotels.projectphase = tbl_hotels_temporary.projectphase,
tbl_hotels.projectstatus = tbl_hotels_temporary.projectstatus,
tbl_hotels.percentage = tbl_hotels_temporary.percentage,
tbl_hotels.stars = tbl_hotels_temporary.stars,
tbl_hotels.projectcategory = tbl_hotels_temporary.projectcategory,
tbl_hotels.hotelcategory = tbl_hotels_temporary.hotelcategory,
tbl_hotels.rooms = tbl_hotels_temporary.rooms,
tbl_hotels.tbi = tbl_hotels_temporary.tbi,
tbl_hotels.openingdate = tbl_hotels_temporary.openingdate,
tbl_hotels.hotel_type_group = tbl_hotels_temporary.hotel_type_group,
tbl_hotels.description = tbl_hotels_temporary.description,
tbl_hotels.image = tbl_hotels_temporary.image,
tbl_hotels.status = 1,
tbl_hotels.user_id = tbl_hotels_temporary.user_id,
tbl_hotels.str_date = tbl_hotels_temporary.str_date,
tbl_hotels.industrytype = tbl_hotels_temporary.industrytype,
tbl_hotels.location = tbl_hotels_temporary.location,
tbl_hotels.str_update = '$today',
tbl_hotels.latitude = tbl_hotels_temporary.latitude,
tbl_hotels.longitude = tbl_hotels_temporary.longitude,
tbl_hotels.hotelgroup = tbl_hotels_temporary.hotelgroup,
tbl_hotels.nearstlandmark = tbl_hotels_temporary.nearstlandmark,
tbl_hotels.plotno = tbl_hotels_temporary.plotno,
tbl_hotels.notes = tbl_hotels_temporary.notes,
tbl_hotels.scope = tbl_hotels_temporary.scope,
tbl_hotels.watchman = tbl_hotels_temporary.watchman,
tbl_hotels.watchmanphone = tbl_hotels_temporary.watchmanphone,
tbl_hotels.trial = tbl_hotels_temporary.trial WHERE tbl_hotels_temporary.tempid='$tempid'" ; 
 //echo $sqlquery; 
    $sql = mysqli_query($this->db,$sqlquery);
      
    }
     public function approvehotelcompanydata($tempid){ 
      $sqlquery="UPDATE tbl_hotelcompanies INNER JOIN tbl_hotelcompanies_temporary ON tbl_hotelcompanies.hotelid = tbl_hotelcompanies_temporary.hotelid SET 
         
tbl_hotelcompanies.hotelid = tbl_hotelcompanies_temporary.hotelid,
tbl_hotelcompanies.hotelno = tbl_hotelcompanies_temporary.hotelno,
tbl_hotelcompanies.developerowner = tbl_hotelcompanies_temporary.developerowner,
tbl_hotelcompanies.developercompany = tbl_hotelcompanies_temporary.developercompany,
tbl_hotelcompanies.developerphone = tbl_hotelcompanies_temporary.developerphone,
tbl_hotelcompanies.developeraddress = tbl_hotelcompanies_temporary.developeraddress,
tbl_hotelcompanies.client_rep_name = tbl_hotelcompanies_temporary.client_rep_name,
tbl_hotelcompanies.client_rep_phone = tbl_hotelcompanies_temporary.client_rep_phone,
tbl_hotelcompanies.client_rep_email = tbl_hotelcompanies_temporary.client_rep_email,
tbl_hotelcompanies.client_rep_visit_time = tbl_hotelcompanies_temporary.client_rep_visit_time,
tbl_hotelcompanies.consultant_company = tbl_hotelcompanies_temporary.consultant_company,
tbl_hotelcompanies.consultant_address = tbl_hotelcompanies_temporary.consultant_address,
tbl_hotelcompanies.consultant_phone = tbl_hotelcompanies_temporary.consultant_phone,
tbl_hotelcompanies.consultant_pm_name = tbl_hotelcompanies_temporary.consultant_pm_name,
tbl_hotelcompanies.consultant_pm_phone = tbl_hotelcompanies_temporary.consultant_pm_phone,
tbl_hotelcompanies.consultant_pm_email = tbl_hotelcompanies_temporary.consultant_pm_email,
tbl_hotelcompanies.contracting_company = tbl_hotelcompanies_temporary.contracting_company,
tbl_hotelcompanies.contracting_address = tbl_hotelcompanies_temporary.contracting_address,
tbl_hotelcompanies.contracting_phone = tbl_hotelcompanies_temporary.contracting_phone,
tbl_hotelcompanies.contracting_pm_name = tbl_hotelcompanies_temporary.contracting_pm_name,
tbl_hotelcompanies.contracting_pm_phone = tbl_hotelcompanies_temporary.contracting_pm_phone,
tbl_hotelcompanies.clientposition = tbl_hotelcompanies_temporary.clientposition,
tbl_hotelcompanies.contracting_pm_email = tbl_hotelcompanies_temporary.contracting_pm_email,
tbl_hotelcompanies.interior_company = tbl_hotelcompanies_temporary.interior_company,
tbl_hotelcompanies.interior_address = tbl_hotelcompanies_temporary.interior_address,
tbl_hotelcompanies.interior_phone = tbl_hotelcompanies_temporary.interior_phone,
tbl_hotelcompanies.interior_pm_name = tbl_hotelcompanies_temporary.interior_pm_name,
tbl_hotelcompanies.interior_pm_phone = tbl_hotelcompanies_temporary.interior_pm_phone,
tbl_hotelcompanies.interior_pm_email = tbl_hotelcompanies_temporary.interior_pm_email,
tbl_hotelcompanies.operator_company = tbl_hotelcompanies_temporary.operator_company,
tbl_hotelcompanies.operator_address = tbl_hotelcompanies_temporary.operator_address,
tbl_hotelcompanies.operator_phone = tbl_hotelcompanies_temporary.operator_phone,
tbl_hotelcompanies.operator_pm_name = tbl_hotelcompanies_temporary.operator_pm_name,
tbl_hotelcompanies.operator_pm_phone = tbl_hotelcompanies_temporary.operator_pm_phone,
tbl_hotelcompanies.operator_pm_email = tbl_hotelcompanies_temporary.operator_pm_email WHERE tbl_hotelcompanies_temporary.hoteltempid='$tempid'" ; 
     // echo $sqlquery;
    
     $sql = mysqli_query($this->db,$sqlquery);
    }
function newuserregistrationemail($staffid,$userid){
        $sql_query="select tbl_users.firstname as userfirstname,tbl_users.lastname as userlastname,tbl_users.email as emailaddress,tbl_users.mobile as mobile,tbl_users.expirydate as expirydate,tbl_users.plan as plan,tbl_staff.firstname as stafffirstname,tbl_staff.lastname as stafflastname from tbl_staff join tbl_users on tbl_staff.staffid=tbl_users.salesid where tbl_users.int_user_id='$userid'";
        $sql = mysqli_query($this->db,$sql_query);
        $result = mysqli_fetch_array($sql);
         
         $message="<p>Dear Admin</p>";
         $message.="<p>New user was created on Mena Hotel Projects</p>";
         $message.="<p>Following is the details of the user</p>";
          $message.="<p>Name: ".$result[0]['userfirstname'].$result['userlastname']."</p>";
          $message.="<p>Email: ".$result['emailaddress']."</p>";
          $message.="<p>Mobile: ".$result['mobile']."</p>";
          $message.="<p>Expiry Date: ".$result['expirydate']."</p>";
          $message.="<p>Account created by: ".$result['stafffirstname'].$result['stafflastname']."</p>";
         $message.="<p>Kindly check and activate the account</p>";
         $table='<table width="600px">';
         $table.='<tr><td style=\'text-align:center;\'><img src=\'http://menahotelprojects.com/images/logo2.png\'/></td></tr>';
         $table.='<tr><td>'.$message.'</td></tr>';
         $table.='</table>';
        
                                $subject="New user registration on Mena Hotel projects ";
                                $emailto = 'noman@rapid-supplies.com ';
				$toname = 'menahotelprojects';
				$emailfrom = 'sales@menahotelprojects.com';
				$fromname = 'menahotelprojects'; 
				$headers = 
					'Return-Path: ' . $emailfrom . "\r\n" . 
					'From: ' . $fromname . ' <' . $emailfrom . '>' . "\r\n" . 
					'X-Priority: 3' . "\r\n" . 
					'X-Mailer: PHP ' . phpversion() .  "\r\n" . 
					'Reply-To: ' . $fromname . ' <' . $userdetails[0]['email'] . '>' . "\r\n" .
					'MIME-Version: 1.0' . "\r\n" . 
					'Content-Transfer-Encoding: 8bit' . "\r\n" .  
					 'Bcc: support@menahotelprojects.com' . "\r\n" . 
					'Content-Type: text/html; charset=UTF-8' . "\r\n";
				$params = '-f ' . $emailfrom;
                                mail($emailto, $subject, $table, $headers, $params);
}
}
?>
