<?php
ob_start();
//ob_start("ob_gzhandler");

/*
		Filename:		travel.class.php
		Owner:			Sreenath P.
		Date:			17-11-2008
		Description:	File for news management
PROCEDURES IN FILE
NAME				AUTHOR				CREATION DATE               

MODIFICATION HISTORY
NAME			AUTHOR			MODIFICATION DATE		Details							APPROVER

PROCEDURE/ FUNCTION DESCRIPTIONS
procedure name:
    TABLES:			crb_news_events. 
	COMPONENTS:$rows	= $this ->db ->readValues($sql);
					return $rows;    PARAMETERS: 
    EXTERNAL IMPACT: 
*/
include_once "generalnew.class.php";
include_once "Database.class.php";
require_once 'General.class.php';
require_once 'PHPMailer.class.php';
//include_once "cakesCart.class.php";
//require_once 'generalnew.class.php';

class dubbauser
{

	 //friend function cakesCart::cakesCartGet();
	 private $general;
	function __construct()
	{
	
			date_default_timezone_set("Asia/Kolkata");
			$this->now		= date("Y-m-d");
			$this->date		= date("Y-m-d H:i:s");
			$this->general	= new General();
			$this->db		= new database();
			$this->mail1		= new PHPMailer();
			$this->generalObj		= new generalnew();
			//$this->cakesCartObj		= new cakesCart();
			if(!$this->db->dbConnect())
			die("Error Connection".$this->db->ErrorInfo);
	}
		
	function __destruct()
	{
			@$this->db->dbClose();
	}
	
	function getAllcategories($user_id)
	{
		$sql="select menu.*,menu_cat.category from menu left join menu_cat on menu.cat_id=menu_cat.cat_id where menu.user_id='$user_id' and menu.status!='Deleted' group by menu.cat_id order by menu_cat.category asc";
		//echo $sql;exit;
		$rows	= $this->db->readValues($sql);
		//print_r($rows);
		return $rows;
	}
	function getAllcategoriesnew($user_id)
	{
		$sql="select menu.*,menu_cat.category from menu left join menu_cat on menu.cat_id=menu_cat.cat_id where menu.user_id='$user_id' and menu.status!='Deleted' order by menu_cat.category asc";
		//echo $sql;exit;
		$rows	= $this->db->readValues($sql);
		//print_r($rows);
		return $rows;
	}
	function getAllcategoriesOnly($user_id)
	{
		$sql="select menu_cat.cat_id,menu_cat.category from menu left join menu_cat on menu.cat_id=menu_cat.cat_id where menu.user_id='$user_id' and menu.status!='Deleted' group by menu.cat_id order by menu_cat.category asc";
		//echo $sql;exit;
		$rows	= $this->db->readValues($sql);
		//print_r($rows);
		return $rows;
	}
	function getAllcategoriesByCategory($cat_id)
	{
		$sql="select * from menu left join menu_cat on menu.cat_id=menu_cat.cat_id where menu_cat.cat_id='$cat_id' and menu.status!='Deleted' group by menu.cat_id order by menu_cat.category asc";
		//echo $sql;exit;
		$rows	= $this->db->readValues($sql);
		//print_r($rows);
		return $rows;
	}
	function getAllitems($user_id)
	{
		$sql="select * from menu left join menu_cat on menu.cat_id=menu_cat.cat_id where menu.user_id='$user_id' and menu.status!='Deleted' order by menu_cat.category asc";
		$rows	= $this->db->readValues($sql);
		//print_r($rows);
		return $rows;
	}
	function getAllitems1($user_id,$cat_id)
	{
		$sql="select * from menu left join menu_cat on menu.cat_id=menu_cat.cat_id where menu.user_id='$user_id' and menu.cat_id='$cat_id' and menu.status!='Deleted' order by menu_cat.category asc";
		//echo $sql;exit;
		$rows	= $this->db->readValues($sql);
		//print_r($rows);exit;
		return $rows;
	}
	function getCategory($user_id)
	{
		$sql="select * from menu_cat where user_id='$user_id'";
		$rows	= $this->db->readValues($sql);
		//print_r($rows);
		return $rows;
	}

	function getCategoryById($userid)
	{
		$sql="select * from menu_cat where user_id='$userid'";
		$rows	= $this->db->readValues($sql);
		//print_r($rows);
		return $rows;
	}
	function shopCart($shop_id,$item_id,$user_id,$count1)
	{
		
		$sql="select * from shop_cart where shop_id='$shop_id' and item_id='$item_id'";
		//echo $sql;exit;
		$row	= $this->db->readValue($sql);
		//print_r($row);
		
		if($row)
		{
		//echo "s";exit;
			$count=$row['count'];
			$count+=$count1;
			$sql1="update shop_cart set count='$count' where shop_id='$shop_id' and item_id='$item_id'";
			$res1	= $this->db->setQuery($sql1);
		}
		else
		{
		//echo "f";exit;
			$sql2="insert into shop_cart(shop_id,item_id,count) values('$shop_id','$item_id','$count1')";
			//echo $sql2;exit;
			$res2	= $this->db->setQuery($sql2);
		}
		
		$sql3="select * from shop_cart left join menu on shop_cart.item_id=menu.item_id where shop_cart.shop_id='$shop_id' and menu.user_id='$user_id'";
		$rows	= $this->db->readValues($sql3);
		return $rows;
	}
	function shopCartMain($shop_id,$user_id)
	{
		$sql3="select * from shop_cart left join menu on shop_cart.item_id=menu.item_id where shop_cart.shop_id='$shop_id' and menu.user_id='$user_id'";
		$rows	= $this->db->readValues($sql3);
		return $rows;
	}
	function shopCartMinus($shop_id,$item_id,$user_id)
	{
		$sql="select * from shop_cart where shop_id='$shop_id' and item_id='$item_id'";
		$row	= $this->db->readValue($sql);
		
		if($row)
		{
			/*$cnt=$row['count'];
			$cnt--;
			if($cnt<=0)
			{*/
				$sql1="delete from shop_cart where shop_id='$shop_id' and item_id='$item_id'";
				$res1	= $this->db->setQuery($sql1);
			/*}
			else
			{
				$sql2="update shop_cart set count='$cnt' where shop_id='$shop_id' and item_id='$item_id'";
				$res2	= $this->db->setQuery($sql2);
			}*/
		}
		$sql3="select * from shop_cart  left join menu on shop_cart.item_id=menu.item_id where shop_cart.shop_id='$shop_id' and menu.user_id='$user_id'";
		$row3	= $this->db->readValues($sql3);
		
		return $row3;
	}
	
	function getAllrestaurants($txt_search='')
	{
		$sql="select * from user where 1=1 and type='Hotel' and status='Active'";
		
		if($txt_search!="")
		{
			$sql.=" and (name like '%$txt_search%' or pin like '%$txt_search%' or city like '%$txt_search%')";
		}
		
		$sql.=" order by user_id asc ";
		
		
			
		$res	= $this->db ->readValues($sql);	
		return $res;
	}
	
	function getAllrestaurantlist($txt_search='',$food_type='',$food='',$sortValue='',$search_type='',$Offset='',$RowsPerPage='')
	{
		if(isset($_SESSION['state_id']))
		$state_id=$_SESSION['state_id'];
		else
		$state_id=13;
		
		$txt_search=mysql_real_escape_string($txt_search);
	//exit;
		$sql="select distinct user.user_id,user.name,user.image,user.address,user.address2,user.pin,user.city,user.state,user.country,user.description,user.delivery_distance,user.delivery_fee,user.delivery,user.discount,user.list_type,user.menu_url, 
		case when user.list_type='Online Ordering' then 1 when user.rest_type='Directory' then 2 end as restaurantOrder,
		case when user.rest_type='Premium' then 1 when user.rest_type='Deluxe' then 2 when user.rest_type='Economy' then 3 end as restaurantOrder from user left join rest_foodtypes on user.user_id=rest_foodtypes.user_id left join rest_includes on user.user_id=rest_includes.user_id left join rest_categories on rest_includes.rest_category_id=rest_categories.rest_category_id left join delivery_areas on delivery_areas.user_id=user.user_id left join rest_delivery_areas on delivery_areas.delivery_area_id=rest_delivery_areas.delivery_area_id  left join districts on user.district=districts.district_id ";
		
		if($food!="")
		{
			$sql.=" left join menu on user.user_id=menu.user_id ";
		}
		
		
		$sql.=" where 1=1 and user.type='Hotel' and user.status='Active' and (rest_categories.rest_category='Restaurant' or rest_categories.rest_category='Book A Table' or rest_categories.rest_category='Corporate') ";
		
		if($search_type!="")
		{
			$search_type=urldecode($search_type);
			
			if($search_type=='Online Ordering')
			{
				$sql.=" and user.list_type='Online Ordering'";
			}
			else if($search_type=='Directory')
			{
				//$sql.=" and user.list_type='Directory'";
			}
			else if($search_type=='Corporate')
			{
				$sql.=" and rest_categories.rest_category='Corporate'";
			}
			else if($search_type=='Book A Table')
			{
				$sql.=" and rest_categories.rest_category='Book A Table'";
			}
		}
		/*else
		{
			$sql.=" and user.list_type='Online Ordering'";
		}*/
		
		if($txt_search!="")
		{
			$sql.=" and (user.name like '%$txt_search%' or user.pin like '%$txt_search%' or user.city like '%$txt_search%' or  rest_delivery_areas.delivery_area like '%$txt_search%' or districts.district like '%$txt_search%')";
		}
		if($food_type!='')
		{
			$sql.=" and rest_foodtypes.food_id='$food_type' ";
		}
		if($food!='')
		{
			$sql.=" and menu.item_name like '%$food%' ";
		}
		
		$sql.=" and user.state='$state_id'";
		
		if($sortValue!='')
		{
			if($sortValue=='Type')
			{
				$sql.=" order by restaurantOrder asc, user.user_id asc";
			}
			if($sortValue=='Delivery')
			{
				$sql.=" order by user.delivery_fee asc, user.user_id asc ";
			}
			
		}
		else
		{
			$sql.=" order by user.ranking asc";
		}
		
		if(trim($Offset)!="" && trim($RowsPerPage)!="")
			{	$sql .=	" LIMIT $Offset,$RowsPerPage";	}
		
		//echo $sql;exit;
					
		$res	= $this->db ->readValues($sql);
		
		
		return $res;
	}
	function updateRating($order_id,$value,$field)
	{
		$sql="update rest_rating set $field='$value' where order_id='$order_id'";
		$res	= $this->db->setQuery($sql);
		return "rated successfully";
	}
	function getRating($user_id)
	{
		$sql="select * from rest_rating left join  orders  on orders.order_id=rest_rating.order_id where orders.rest_id='$user_id' and rest_rating.service!='0'";
		//echo $sql;exit;
		$res	= $this->db ->readValues($sql);
		return $res;
	}
	function shopCartItemNumbers($session_id,$user_id)
	{
		$sql="select * from shop_cart left join menu on menu.item_id=shop_cart.item_id where shop_cart.shop_id='$session_id' and menu.user_id='$user_id'";
		//echo $sql;
		$res	= $this->db ->readValues($sql);
		$num=0;
		foreach($res as $key=>$values)
		{
			$num+=$values['count'];
		}
		//echo $num;
		return $num;
	}
	function recentRegistration()
	{
		$sql="select * from user where type='Hotel' and status='Active'  order by register_date desc limit 0,9";
		//echo $sql;exit;
		$res	= $this->db ->readValues($sql);
		return $res;
	}
	
	function EmailExist($email)
	{
		$sql="select * from user where type='User' and email='$email' and status!='Deleted'";
		//echo $sql;
		$res	= $this->db ->readValue($sql);
		return $res;
	} 
	function MobileExist($mobile)
	{
		$sql="select * from user where type='User' and mobile='$mobile' and status!='Deleted'";
		$res	= $this->db ->readValue($sql);
		return $res;
	} 
	function urlExists($url)
	{
		$sql="select * from user where type='User' and mobile='$mobile' and status!='Deleted'";
		$res	= $this->db ->readValue($sql);
		return $res;
	} 
	
	function EmailExistUpdate($email,$session_id)
	{
		$sql="select * from user where type='User' and email='$email' and user_id!='$session_id' and status!='Deleted'";
		//echo $sql;
		$res	= $this->db ->readValue($sql);
		return $res;
	} 
	function MobileExistUpdate($mobile,$session_id)
	{
		$sql="select * from user where type='User' and mobile='$mobile' and user_id!='$session_id' and status!='Deleted'";
		$res	= $this->db ->readValue($sql);
		return $res;
	} 
	function addUser($POST)
	{
		$name=addslashes($POST['name']);
		$email=addslashes($POST['email']);
		$mobile=addslashes($POST['mobile']);
		$password=addslashes($POST['password']);
		$rep_password=addslashes($POST['rep_password']);
		$gender=addslashes($POST['gender']);
		$dob=addslashes($POST['dob']);
		$phone=addslashes($POST['phone']);
		$address=addslashes($POST['address']);
		$address2=addslashes($POST['address2']);
		$address3=addslashes($POST['address3']);
		$city=addslashes($POST['city']);
		$country=addslashes($POST['country']);
		$state=addslashes($POST['state']);
		$district=addslashes($POST['district']);
		$pin=addslashes($POST['pin']);
		
		if(isset($POST['newsletter']))
		{
			$newsletter=addslashes($POST['newsletter']);
			$new='Subscriber';
		}
		else
		{
			$new='Unsubscriber';
		}
		$randomNumber=$this->randomNumber();
		
		$message="YOUR SIX DIGIT CONFIRMATION CODE IS '$randomNumber'.PLEASE ENTER SAME IN YOUR YUMMYBAY REGISTRATION PAGE AND CLICK CONFIRM FOR VERIFYING CONTACT NUMBER";
		//echo $messgae;
		
		if(isset($POST['terms']))
		$terms=addslashes($POST['terms']);
		
		
		$reg_date=$this->date;
		list($d,$m,$y)=explode("/",$dob);
			$dob1=$y."-".$m."-".$d;
		
		$sql="insert into user(name,email,gender,password,mobile,phone,dob,address,address2,address3,pin,rest_contacts,city,state,district,country,description,delivery_area,register_date,list_type,type,status,newsletter,verification,menu_url) values('$name','$email','$gender','$password','$mobile','$phone','$dob1','$address','$address2','$address3','$pin','','$city','$state','$district','$country','','','$reg_date','Online Ordering','User','Active','$new','','')";
		//echo $sql;exit;
		$res	= $this->db->setQuery($sql);
		
		$sql1="select max(user_id) as id from user";
		$res1	= $this->db ->readValue($sql1);
		$id=$res1['id'];
		
		if($res)
		{
			//echo 'success';exit;
			$_SESSION['yummyuserID']=$id;
			$_SESSION['yummyuserNAME']=$name;
			$_SESSION['yummytype']='User';
			$_SESSION['yummyemail']=$email;
			
			$IPtrackinguser=$this->IPtrackinguser();
		}
		//echo 'failure';exit;
		//$sendSms=$this->sendSms($message,$mobile);
		
		$sendSignupMail=$this->sendSignupMail($POST,$randomNumber);
		
		
		return "User registered successfully";
	}
	function sendSignupMail($POST,$randomNumber)
	{
	    $name=addslashes($POST['name']);
		$email=addslashes($POST['email']);
		$mobile=addslashes($POST['mobile']);
		$password=addslashes($POST['password']);
		$rep_password=addslashes($POST['rep_password']);
		$gender=addslashes($POST['gender']);
		$dob=addslashes($POST['dob']);
		
		
		$phone=addslashes($POST['phone']);
		$address=addslashes($POST['address']);
		$address2=addslashes($POST['address2']);
		$address3=addslashes($POST['address3']);
		$city=addslashes($POST['city']);
		$country=addslashes($POST['country']);
		$getcountry=$this->generalObj->getGeneralById('country_database',array('country_id'=>$country));
		$country_name=$getcountry['country_name'];
		$state=addslashes($POST['state']);
		$getstate=$this->generalObj->getGeneralById('states',array('state_id'=>$state));
		$state_name=$getstate['states'];
		$district=addslashes($POST['district']);
		$getdistrict=$this->generalObj->getGeneralById('districts',array('district_id'=>$district));
		$district_name=$getdistrict['district'];
		$pin=addslashes($POST['pin']);
		
	  	$mail1=	new PHPMailer();
		$mail1->IsHTML(true); 
	    $mail1->Host = '208.109.217.153';	
		$mail1->AddAddress("$email");	
		$mail1->From="info@yummybay.com";
		$mail1->FromName = "yummybay";
		$mail1->Subject = "Profile details from yummybay: ";
		/*$msg1= "<table width='101%' border='0'>
  <tr>
    <td colspan='6'><strong>Dear $name,<br/> Your profile created successfully in www.yummybay.com</strong></td>
  </tr>
  <tr>
    <td colspan='6'>&nbsp;</td>
  </tr>
  <tr>
    <td width='46%' ><strong>Username</strong></td>
    <td width='26%' ><strong>$email</strong></td>
    <td width='16%' ><strong>Password</strong></td>
	<td width='12%' ><strong>$password</strong></td>
  </tr>
  <tr>
    <td colspan='6'>&nbsp;</td>
  </tr>
  <tr>
    <td width='46%' ><strong>Mobile</strong></td>
    <td width='26%'><strong>$mobile</strong></td>
    <td width='16%' ><strong>Verification code</strong></td>
	<td width='12%' ><strong>$randomNumber</strong></td>
  </tr>
  <tr>
    <td colspan='6'>&nbsp;</td>
  </tr>
  <tr>
    <td width='46%' ><strong>Gender</strong></td>
    <td width='26%'><strong>$gender</strong></td>
    <td width='16%' ><strong>DOB</strong></td>
	<td width='12%' ><strong>$dob</strong></td>
  </tr>
  <tr>
    <td colspan='6'>&nbsp;</td>
  </tr>
  <tr>
    <td width='46%' ><strong>Phone</strong></td>
    <td width='26%'><strong>$phone</strong></td>
    <td width='16%' ><strong>Flat / House No</strong></td>
	<td width='12%' ><strong>$address</strong></td>
  </tr>
  <tr>
    <td colspan='6'>&nbsp;</td>
  </tr>
  <tr>
    <td width='46%' ><strong>Flat / House Name</strong></td>
    <td width='26%'><strong>$address2</strong></td>
    <td width='16%' ><strong>Location</strong></td>
	<td width='12%' ><strong>$address3</strong></td>
  </tr>
  <tr>
    <td colspan='6'>&nbsp;</td>
  </tr>
  <tr>
    <td width='46%' ><strong>City</strong></td>
    <td width='26%'><strong>$city</strong></td>
    <td width='16%' ><strong>Country</strong></td>
	<td width='12%' ><strong>$country_name</strong></td>
  </tr>
  <tr>
    <td colspan='6'>&nbsp;</td>
  </tr>
  <tr>
    <td width='46%' ><strong>State</strong></td>
    <td width='26%'><strong>$state_name</strong></td>
    <td width='16%' ><strong>District</strong></td>
	<td width='12%' ><strong>$district_name</strong></td>
  </tr>
  <tr>
    <td colspan='6'>&nbsp;</td>
  </tr>
  <tr>
    <td width='46%' ><strong>PIN Code</strong></td>
    <td width='26%'><strong>$pin</strong></td>
    <td width='16%' ><strong>&nbsp;</strong></td>
	<td width='12%' ><strong>&nbsp;</strong></td>
  </tr>
  ";*/
  
  
  
  $msg1='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>email_letter2_html</title>
<style type="text/css" media="screen">
body {
         margin: 0;
         padding: 0;
         background-color: #FFFFFF;
		 font-family: Arial;
		 color:#333333;
		 
      }
	   a {
         font-family: Arial;
         font-size: 13px;
         font-weight: normal;
         color: #f03e60;
      }

      p {
         font-family: Arial;
         font-size: 11px;
         font-weight: normal;
         color: #df143d;
		 margin:0px;
		 padding:5px 0 0 0;
      }
	  h3{
	  color:#999999;
	  }
</style>
</head>

<body>
<table  width="636"border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="background-image:url(image/bg.jpg); background-repeat:repeat-y;">
  <tr>
    <td><table width="580" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td height="111" colspan="3"><div align="center"><img src="http://yummybay.com/images/f1-img/l2ogo.jpg" width="582" height="111" /></div></td>
      </tr>
      <tr>
        <td style="background-image:url(http://yummybay.com/images/f1-img/r1ainb1ow.jpg); padding:0 0 0 10px;; margin:0px; height:155px; color:#FF0000;" colspan="3">Dear <span style="color:#333333;">'.$name.'</span>
          <h3 align="center">Welcome to Yummybay</h3>          <div align="center"></div></td>
      </tr>
      
      <tr>
        <td height="20" colspan="3"><div align="center" style="font-size:13px; color:#999999;">
          <p>Your profile created successfully in www.yummybay.com</p>
        </div></td>
      </tr>
      
      <tr>
        <td height="20" colspan="3">&nbsp;</td>
      </tr>
      <tr>
        <td width="256" height="20"><div align="right" style="font-size:13px;" ><strong>Name</strong></div> </td>
        <td width="19" height="20" align="right"><strong>:</strong> </td>
        <td width="307" height="20"><div align="left" style="font-size:13px;color:#999999;" ><strong>'.$name.'</strong></div></td>
      </tr>
      <tr>
        <td width="256" height="20"><div align="right" style="font-size:13px;" ><strong>User Name</strong></div> </td>
        <td width="19" height="20" align="right"><strong>:</strong> </td>
        <td width="307" height="20"><div align="left" style="font-size:13px;color:#999999;" ><strong>'.$email.'</strong></div></td>
      </tr>
       <tr>
        <td width="256" height="20"><div align="right" style="font-size:13px;" ><strong>Password</strong></div> </td>
        <td width="19" height="20" align="right"><strong>:</strong> </td>
        <td width="307" height="20"><div align="left" style="font-size:13px;color:#999999;" ><strong>'.$password.'</strong></div></td>
      </tr>
      <tr>
        <td width="256" height="20"><div align="right" style="font-size:13px;" ><strong>Mobile</strong></div> </td>
        <td width="19" height="20" align="right"><strong>:</strong> </td>
        <td width="307" height="20"><div align="left" style="font-size:13px;color:#999999;" ><strong>'.$mobile.'</strong></div></td>
      </tr>
      <tr>
        <td width="256" height="20"><div align="right" style="font-size:13px;" ><strong>Verification code</strong></div> </td>
        <td width="19" height="20" align="right"><strong>:</strong> </td>
        <td width="307" height="20"><div align="left" style="font-size:13px;color:#999999;" ><strong>'.$randomNumber.'</strong></div></td>
      </tr>
      <tr>
        <td width="256" height="20"><div align="right" style="font-size:13px;" ><strong>Gender</strong></div> </td>
        <td width="19" height="20" align="right"><strong>:</strong> </td>
        <td width="307" height="20"><div align="left" style="font-size:13px;color:#999999;" ><strong>'.$gender.'</strong></div></td>
      </tr>
      <tr>
        <td width="256" height="20"><div align="right" style="font-size:13px;" ><strong>DOB</strong></div> </td>
        <td width="19" height="20" align="right"><strong>:</strong> </td>
        <td width="307" height="20"><div align="left" style="font-size:13px;color:#999999;" ><strong>'.$dob.'</strong></div></td>
      </tr>
      <tr>
        <td width="256" height="20"><div align="right" style="font-size:13px;" ><strong>Phone</strong></div> </td>
        <td width="19" height="20" align="right"><strong>:</strong> </td>
        <td width="307" height="20"><div align="left" style="font-size:13px;color:#999999;" ><strong>'.$phone.'</strong></div></td>
      </tr>
      <tr>
        <td width="256" height="20"><div align="right" style="font-size:13px;" ><strong>Flat / House No</strong></div> </td>
        <td width="19" height="20" align="right"><strong>:</strong> </td>
        <td width="307" height="20"><div align="left" style="font-size:13px;color:#999999;" ><strong>'.$address.'</strong></div></td>
      </tr>
      <tr>
        <td width="256" height="20"><div align="right" style="font-size:13px;" ><strong>Flat / House Name</strong></div> </td>
        <td width="19" height="20" align="right"><strong>:</strong> </td>
        <td width="307" height="20"><div align="left" style="font-size:13px;color:#999999;" ><strong>'.$address2.'</strong></div></td>
      </tr>
      <tr>
        <td width="256" height="20"><div align="right" style="font-size:13px;" ><strong>Location</strong></div> </td>
        <td width="19" height="20" align="right"><strong>:</strong> </td>
        <td width="307" height="20"><div align="left" style="font-size:13px;color:#999999;" ><strong>'.$address3.'</strong></div></td>
      </tr>
       <tr>
        <td width="256" height="20"><div align="right" style="font-size:13px;" ><strong>City</strong></div> </td>
        <td width="19" height="20" align="right"><strong>:</strong> </td>
        <td width="307" height="20"><div align="left" style="font-size:13px;color:#999999;" ><strong>'.$city.'</strong></div></td>
      </tr>
       <tr>
        <td width="256" height="20"><div align="right" style="font-size:13px;" ><strong>Country</strong></div> </td>
        <td width="19" height="20" align="right"><strong>:</strong> </td>
        <td width="307" height="20"><div align="left" style="font-size:13px;color:#999999;" ><strong>'.$country_name.'</strong></div></td>
      </tr>
       <tr>
        <td width="256" height="20"><div align="right" style="font-size:13px;" ><strong>State</strong></div> </td>
        <td width="19" height="20" align="right"><strong>:</strong> </td>
        <td width="307" height="20"><div align="left" style="font-size:13px;color:#999999;" ><strong>'.$state_name.'</strong></div></td>
      </tr>
       <tr>
        <td width="256" height="20"><div align="right" style="font-size:13px;" ><strong>District</strong></div> </td>
        <td width="19" height="20" align="right"><strong>:</strong> </td>
        <td width="307" height="20"><div align="left" style="font-size:13px;color:#999999;" ><strong>'.$district_name.'</strong></div></td>
      </tr>
       <tr>
        <td width="256" height="20"><div align="right" style="font-size:13px;" ><strong>PIN Code</strong></div> </td>
        <td width="19" height="20" align="right"><strong>:</strong> </td>
        <td width="307" height="20"><div align="left" style="font-size:13px;color:#999999;" ><strong>'.$pin.'</strong></div></td>
      </tr>
       
      
      
     
      <tr>
        <td colspan="3">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="3"><div align="center" style="font-size:13px;">
          <p><br />
            If you need any assistance feel free to  contact at yummybay.com.</p>
        </div></td>
      </tr>
      <tr>
        <td colspan="3">&nbsp;</td>
      </tr>
      
      <tr>
    <td align="left" bgcolor="#f4f3f3" colspan="3" ><h3 style="font-size:15px; color:#f03e60; padding:5px 0 5px 10px; margin:0px;">Follow Us</h3></td>
  </tr>
      <tr>
        <td colspan="3">&nbsp;</td>
      </tr>
      <tr >
        <td colspan="3"><table width="580" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="38">&nbsp;</td>
            <td width="107"><a href="http://www.facebook.com/Yummybay" target="_blank"><img src="http://yummybay.com/images/f1-img/f1ace_b1ook.jpg" width="107" height="28" border="0" /></a></td>
            <td width="26">&nbsp;</td>
            <td width="107"><a href="http://twitter.com/yummybay" target="_blank"><img src="http://yummybay.com/images/f1-img/t1witter.jpg" width="107" height="28" border="0" /></a></td>
            <td width="11">&nbsp;</td>
            <td width="117"><a href="http://blog.yummybay.com/" target="_blank"><img src="http://yummybay.com/images/f1-img/b1log.jpg" width="107" height="28" border="0" /></a></td>
            <td width="20">&nbsp;</td>
            <td width="111"><a href="http://www.youtube.com/watch?v=o5IQatKqH2Q" target="_blank"><img src="http://yummybay.com/images/f1-img/y1ou_t1ube.jpg" width="107" height="28" border="0" /></a></td>
            <td width="43">&nbsp;</td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td style="border-bottom:dotted; color:#efefef;" colspan="3">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="3">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="3"><table width="580" border="0" cellspacing="0" cellpadding="0" style="background-color:#f4f3f3;">
          <tr>
            <td width="33%" bgcolor="#f4f3f3" style="color:#8b8989; padding:10px 0 0 10px; font-size:13px;">Contact Our CEO</td>
            <td width="33%" bgcolor="#f4f3f3" style="color:#8b8989; padding:10px 0 0 0; font-size:13px;">Marketing Division</td>
            <td width="33%" bgcolor="#f4f3f3" style="color:#8b8989; padding:10px 0 0 0; font-size:13px;">Business Devolopment</td>
          </tr>
          <tr>
            <td bgcolor="#f4f3f3" ><a href="mailto:ceo@yummybay.com" style="font-size:12px; padding:10px 10px 10px 10px;">ceo@yummybay.com</a></td>
            <td bgcolor="#f4f3f3" ><div align="left"><a href="mailto:marketing@yummybay.com" style="font-size:12px; padding:10px 10px 10px 0;">marketing@yummybay.com</a></div></td>
            <td bgcolor="#f4f3f3" ><div align="left"><a href="mailto:business@yummybay.com" style="font-size:12px; padding:10px 10px 10px 0;">business@yummybay.com</a></div></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td style="font-size:12px; padding:5px 0 10px 0;" bgcolor="#ffffff" colspan="3" ><div align="center" >
          <p>Yummybay.com is a division of AMICITIA FOOD  MART PVT LTD - Registered COCHIN.  Registered Office: AMICITIA FOOD MART PVT LTD,PALATHINKAL BLDG,KOCHAPILLY ROAD,NH  47,PALARIVATTOM BYPASS,ERNAKULAM-682025. This communication contains  information which is confidential and may also be privileged. It is for the  exclusive use of the intended recipient(s). If you are not the intended  recipient(s) please note that any distribution, copying or use of this  communication or the information in it is strictly prohibited. Any views or  opinions expressed in the communication are solely those of the author. If you  have received this communication in error please notify us by e-mail or by  telephone and then delete the communication and any copies of it.<br />
              <br />
            Telephone calls may be monitored or recorded.</p>
        </div></td>
      </tr>
      <tr>
        <td colspan="3">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
</table>

</body>
</html>
';
	
  

		$mail1->Body=$msg1;
		//echo $msg1;exit;
	    $send =  $mail1->Send();
	   	if($send)
	   	{
	   		//echo "Mail sent";
	   	}
	   	else
	   	{
	   		//echo "Mail not sent";
	   	}
		return "";

	}
	function sendSms($message,$mobile)
	{
		
		$username="yummybay";
		$password="619276";
		$sender="YUMMYBAY";
		$domain="alertbox.in";
		$method="POST";
	
	
		//echo $message;exit;
		$username=urlencode($username);
		$password=urlencode($password);
		$sender=urlencode($sender);
		$message=urlencode($message);
		$priority=2;
       
		
		$opts = array(
		  'http'=>array(
			'method'=>"$method",
			'content' => "username=$username&password=$password&sender=$sender&to=$mobile&message=$message&priority=$priority",
			'header'=>"Accept-language: en\r\n" .
					  "Cookie: foo=bar\r\n"
		  )
		);
	
		$context = stream_context_create($opts);
		
		$fp = @fopen("http://$domain/pushsms.php", "r", false, $context);
		$response = @stream_get_contents($fp);
		//echo "$response";
		//exit;
		fpassthru($fp);
		fclose($fp);
	}
	function randomNumber()
	{
		srand ((double) microtime() * 10000000);
		$input = array ("A", "B", "C", "D", "E","F","G","H","I","J","K","L","M","N","O","P","Q",
		"R","S","T","U","V","W","X","Y","Z");
		$rand_index = array_rand($input,6);
		$value=$input[$rand_index[5]].$input[$rand_index[4]].$input[$rand_index[3]].$input[$rand_index[2]].$input[$rand_index[1]].$input[$rand_index[0]];
		return $value;
	}
	function updateUser($POST,$session_id)
	{
		$name=addslashes($POST['name']);
		$email=addslashes($POST['email']);
		$mobile=addslashes($POST['mobile']);
		
		$gender=addslashes($POST['gender']);
		$dob=addslashes($POST['dob']);
		$phone=addslashes($POST['phone']);
		$address=addslashes($POST['address']);
		$address2=addslashes($POST['address2']);
		$address3=addslashes($POST['address3']);
		$city=addslashes($POST['city']);
		$country=addslashes($POST['country']);
		$state=addslashes($POST['state']);
		$district=addslashes($POST['district']);
		$pin=addslashes($POST['pin']);
		
		$reg_date=$this->date;
		list($d,$m,$y)=explode("/",$dob);
			$dob1=$y."-".$m."-".$d;
			
		$sql="update user set name='$name',email='$email',gender='$gender',mobile='$mobile',phone='$phone',dob='$dob1',address='$address',address2='$address2',address3='$address3',pin='$pin',city='$city',state='$state',district='$district',country='$country',last_update='$reg_date' where user_id='$session_id'";
		//echo $sql;exit;
		$res	= $this->db->setQuery($sql);
		return "Account updated successfully";
	}
	function userLogin($POST)
	{
		$email=addslashes($POST['email']);
		$password=addslashes($POST['password']);
		
		$sql="select * from user where email='$email' and password='$password' and type='User' and status='Active'";
		//echo $sql;exit;
		$res	= $this->db ->readValue($sql);
		if($res)
		{
			$_SESSION['yummyuserID']=$res['user_id'];
			$_SESSION['yummyuserNAME']=$res['name'];
			$_SESSION['yummytype']='User';
			$_SESSION['yummyemail']=$res['email'];
			
			$IPtrackinguser=$this->IPtrackinguser();
		}
		return $res;
	}
	function IPtrackinguser()
	{
		$date=$this->date;
		$ip=$_SERVER['REMOTE_ADDR'];
		$user_id=$_SESSION['yummyuserID'];
		
		$sql="insert into ip_tracker(ip_address,start_time,end_time,user_id) values('$ip','$date','0000-00-00 00:00:00','$user_id')";
		$res			= 	$this->db->setQuery($sql);
		$getInsertId=$this->db->getInsertId();
		$_SESSION['ip_tracker_id_user']=$getInsertId;
		
		return "";
	}
	function updateIPendtimeuser()
	{
		$date=$this->date;
		$ip_tracker_id_user=$_SESSION['ip_tracker_id_user'];
		$sql="update ip_tracker set end_time='$date' where ip_tracker_id='$ip_tracker_id_user'";
		$res			= 	$this->db->setQuery($sql);
		return "";
	}
	
	function insertOrder($POST,$cakeMessage,$txnID='')
	{
	
		if($txnID!="")
		{
			$txnID=$txnID;
		}
		else
		{
			$txnID=0;
		}
		$discount=0;
		$tax=0;
		$msg=0;
		
		$voucher_code=addslashes($POST['voucher_code']);
		
		$chkVoucherCode=$this->chkVoucherCode($voucher_code);
		
		if($chkVoucherCode)
		{
			$chkVoucherCodeTime=$this->chkVoucherCodeTime($voucher_code);
			if($chkVoucherCodeTime)
			{
				$discount=$chkVoucherCodeTime['discount'];
				$msg=1;
			}
			else
			{
				$msg=0;
			}
		}
		else
		{
			$msg=0;
		}
		//echo $msg;exit;
		
		$delivery_time=addslashes($POST['delivery_time']);
		$order_type=addslashes($POST['order_type']);
		
		//$message=addslashes($POST['message']);
		
		$mobile=addslashes($POST['mobile']);
		$address=addslashes($POST['address']);
		$address2=addslashes($POST['address2']);
		$address3=addslashes($POST['address3']);
		$city=addslashes($POST['city']);
		$country=addslashes($POST['country']);
		$state=addslashes($POST['state']);
		$district=addslashes($POST['district']);
		$pin=addslashes($POST['pin']);
		$payment=addslashes($POST['payment']);
		if($payment=='Cash')
		{
			$paid='Not paid';
		}
		else if($payment=='Card')
		{
			$paid='Paid';
		}
		
		$rest_id=$_SESSION['rest_id'];
		$user_id=$_SESSION['yummyuserID'];
		$shop_id=$_SESSION['shop_id'];
		
		$price=$this->price($shop_id,$rest_id,$order_type,$discount,$msg);
		
		$tot=$this->total($shop_id,$rest_id);
		
		$getDiscount=$this->discountCalc($rest_id,$tot,$order_type,$discount,$msg);
		
		if($msg==1)
		{
			if(($tot-$price)>$chkVoucherCodeTime['max_amount'])
			{
				$price=$tot-$chkVoucherCodeTime['max_amount'];
				$getDiscount=($chkVoucherCodeTime['max_amount']/$tot)*100;
				$getDiscount=round($getDiscount,1);
			}
		}
		
		//echo $getDiscount;
		//$price=$pricearray[0];
		//$discount=$pricearray[1];
		
		/*$dateOrer=date('y-m-d');
		list($y,$m,$d)=explode($dateOrer,"-");
		$orderID=*/
		
		$points=$this->points($shop_id,$rest_id);
		$date=$this->now;
		$time=$this->date;
		$time1=explode(" ",$time);
		$time2=$time1[1];
		
		$sql="insert into orders(user_id,rest_id,price,discount,servicetax,points,order_date,order_time,order_delivery,order_message,order_mobile,delivery_time,order_address,order_address2,order_address3,order_pin,order_city,order_state,order_country,order_type,order_payment,status_order,transaction_id) values('$user_id','$rest_id','$price','$getDiscount','$tax','$points','$date','$time2','Permanent','$cakeMessage','$mobile','$delivery_time','$address','$address2','$address3','$pin','$city','$state','$country','$order_type','$payment','Ordered','$txnID')";
		//echo $sql;exit;
		$res	= $this->db->setQuery($sql);
		
		$sql1="select max(order_id) as order_id from orders";
		//echo $sql1;exit;
		$res1	= $this->db ->readValue($sql1);
		
		$order_id=$res1['order_id'];
		
		
		if(isset($POST['favourite']))
		{
			if($POST['favourite']==1)
			{
				$OrderaddTofavourite=$this->OrderaddTofavourite($order_id);
			}
		}
		
		$sql2="select * from shop_cart left join menu on shop_cart.item_id=menu.item_id where shop_cart.shop_id='$shop_id' and menu.user_id='$rest_id'";
		
		//echo $sql2;exit;
		$res2	= $this->db ->readValues($sql2);
		
		//exit;
		
		if($res2)
		{
			$insertOrderDetails=$this->insertOrderDetails($order_id);
		}
		
		$_SESSION['order_id']=$order_id;
				
		$cakesCart=$this->cakesCartGet();
		
		if($cakesCart)
		{
			$insertCakesOrderDetails=$this->insertCakesOrderDetails($order_id,$cakesCart);
		}
		
		
		$message="ORDER ID ".$_SESSION['order_id'];
		
		if($res2)
		{
			$message.=" ITEMS ";
			foreach($res2 as $key=>$values)
			{
				$message.=trim($values['item_name'])." ";
				//$message.=trim($values['item_desc'])." ";
				$message.=trim($values['count'])." ";
				
			}
		}
		if($cakesCart)
		{
			$message.=" CAKES ";
			foreach($cakesCart as $keyCakes=>$valuesCakes)
			{
				$message.=trim($valuesCakes['cake_name'])." ";
				//$message.=trim($values['item_desc'])." ";
				$message.=trim($valuesCakes['count'])." ";
				
				if($valuesCakes['message']!="")
				$message.=" MESSAGE '".trim($valuesCakes['message'])."' ";
				
			}
		}
		
		
		$message.="PRICE ".trim($price)." ";
		$message.="MOBILE ".trim($mobile)." ";
		$message.="ADDRESS ".trim($address)." ".trim($address2)." ".trim($address3)." ".trim($city)." ".trim($pin)." ";
		
		$message.="ORDER TYPE ".trim($order_type)." ";
		$message.="DELIVERY TIME ".trim($delivery_time)." ";
		$message.="PAYMENT ".trim($paid);
		
		$mobile=$this->RestMobile();
		//echo $mobile;exit;
		
		
		$sendSms=$this->sendSms($message,$mobile);
		
		$sendSmsnew=$this->sendSms('New order received, please check the orders','9567760907');
		
		
		$order_id=$_SESSION['order_id'];
		$sendMailtoRstaurant=$this->sendMailtoRstaurant($order_id);
		$sendMailtoUser=$this->sendMailtoUser($order_id);
		
		return "Your order is successfull";
	}
	function SendOrderSms($order_id,$mobilenumber)
	{
		$sql="select * from orders where order_id='$order_id'";
		$res	=$this->db->readValue($sql);
		
		$sql1="select * from order_details where order_id='$order_id'";
		$res1	=$this->db->readValues($sql1);
		
		if($res['order_payment']=='Cash')
		{
			$paid='Not paid';
		}
		else if($res['order_payment']=='Card')
		{
			$paid='Paid';
		}
		
		$getOrderedCakedetails=$this->CakeOrderDetails($order_id);
		
		$message="ORDER ID ".trim($order_id);
		
		if($res1)
		{
			$message.=" ITEMS ";
		}
		
		foreach($res1 as $key=>$values1)
		{
			$message.=trim($values1['order_item_name'])." ";
			//$message.=trim($values1['order_item_desc'])." ";
			$message.=trim($values1['count'])." ";
		}
		
		if(count($getOrderedCakedetails)>0)
		{
			$message.=" CAKES ";
		}
		
		foreach($getOrderedCakedetails as $keyCakes=>$valuesCakes)
		{
			$message.=trim($valuesCakes['order_cake_name'])." ";
			//$message.=trim($valuesCakes['order_item_desc'])." ";
			$message.=trim($valuesCakes['order_count'])." ";
		}
		
		$message.="PRICE ".trim($res['price'])." ";
		$message.="MOBILE ".trim($res['order_mobile'])." ";
		$message.="ADDRESS ".trim($res['order_address'])." ".trim($res['order_address2'])." ".trim($res['order_address3'])." ".trim($res['order_city'])." ".trim($res['order_pin'])." ";
		
		$message.="ORDER TYPE ".trim($res['order_type'])." ";
		$message.="DELIVERY TIME ".trim($res['delivery_time'])." ";
		$message.="PAYMENT ".trim($paid);
		
		$sendSms=$this->sendSms($message,$mobilenumber);
		
		return "Message sent successfully";
		
	}
	function sendMailtoUser($order_id)
	{
	    $sql	  = "select * from order_details left join menu on order_details.item_id=menu.item_id where order_details.order_id='$order_id'";
		$res	  = $this->db ->readValues($sql);
		
		$CakeOrderDetails=$this->CakeOrderDetails($order_id);
		
	    $qry	  = "select orders.* from orders left join user on orders.user_id=user.user_id where orders.order_id='$order_id'";
		$res1	  = $this->db ->readValue($qry);
		
			$order_id	=$res1['order_id'];
			$user_id	=$res1['user_id'];
			$rest_id	=$res1['rest_id'];
			$order_date =$res1['order_date'];
			$order_time = $res1['order_time'];
			//$order_mobile =$values['order_mobile'];
			$delivery_time=$res1['delivery_time'];
			//$order_delivery=$values['order_delivery'];
			$order_mobno=$res1['order_mobile'];
			$discount=$res1['discount'];
			$price=$res1['price'];
		
		$getUserDetails=$this->generalObj->getGeneralById('user',array('user_id'=>$user_id));
		$user_name	= $getUserDetails['name'];
		$user_email	= $getUserDetails['email'];
		$mobno		= $getUserDetails['mobile'];
		
		$getRestaurantDetails=$this->generalObj->getGeneralById('user',array('user_id'=>$rest_id));
		$res_name	= $getRestaurantDetails['name'];
		$res_email	= $getRestaurantDetails['email'];
		$res_mobno	= $getRestaurantDetails['mobile'];
		
	  	$mail1=	new PHPMailer();
		$mail1->IsHTML(true); 
	    $mail1->Host = '208.109.217.153';	
		$mail1->AddAddress("$user_email");	
		$mail1->From="info@yummybay.com";
		$mail1->FromName = "yummybay";
		$mail1->Subject = "Order details from yummybay: ";
		


$msg1='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>email_letter2_html</title>
<style type="text/css" media="screen">
body {
         margin: 0;
         padding: 0;
         background-color: #FFFFFF;
		 font-family: Arial;
		 color:#333333;
		 
      }
	   a {
         font-family: Arial;
         font-size: 13px;
         font-weight: normal;
         color: #f03e60;
      }

      p {
         font-family: Arial;
         font-size: 11px;
         font-weight: normal;
         color: #df143d;
		 margin:0px;
		 padding:5px 0 0 0;
      }
	  h3{
	  color:#999999;
	  }
</style>
</head>

<body>
<table  width="636"border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="background-image:url(image/bg.jpg); background-repeat:repeat-y;">
  <tr>
    <td><table width="580" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td height="111" colspan="2"><div align="center"><img src="http://yummybay.com/images/f1-img/l2ogo.jpg" width="582" height="111" /></div></td>
      </tr>
      <tr>
        <td style="background-image:url(http://yummybay.com/images/f1-img/r1ainb1ow.jpg); padding:0 0 0 10px;; margin:0px; height:155px; color:#FF0000;" colspan="2">Dear <span style="color:#333333;">'.$user_name.'</span>
          <h3 align="center">Welcome to Yummybay</h3>          <div align="center"></div></td>
      </tr>
      
      <tr>
        <td height="20" colspan="2"><div align="center" style="font-size:13px; color:#999999;">
          <p>Order details from yummybay.com</p>
        </div></td>
      </tr>
      
      <tr>
        <td width="273"  height="20" style="font-size:13px; color:#999999;" valign="top">
        
        <table width="100%">
        <tr>
        <td colspan="2"><b>Order Details</b>        </td>
        
        
        
        
        
        </tr>
        
        
        <tr>
        <td width="38%">Order ID        </td>
        <td width="62%"><strong>'.$order_id.'</strong> </td>
        
       
        
        </tr>
        
        <tr>
        <td width="38%">Order Date        </td>
        <td width="62%"><strong>'.$order_date.'</strong> </td>
        
       
        
        </tr>
        
        <tr>
        <td width="38%">Order Time        </td>
        <td width="62%"><strong>'.$order_time.'</strong> </td>
        
       
        
        </tr>
        
        <tr>
        <td width="38%">Order Mobile No.        </td>
        <td width="62%"><strong>'.$order_mobno.'</strong> </td>
        
       
        
        </tr>
        
        
        <tr>
        <td colspan="2">&nbsp;      </td>
        
        
        
        
        
        </tr>
        
        
        <tr>
        <td colspan="2"><b>User Details</b>        </td>
        
        
        
        
        
        </tr>
        
        
        <tr>
        <td width="38%">Name</td>
        <td width="62%"><strong>'.$user_name.'</strong> </td>
        
       
        
        </tr>
        
        <tr>
        <td width="38%">Email</td>
        <td width="62%"><strong>'.$user_email.'</strong> </td>
        
       
        
        </tr>
        
        <tr>
        <td width="38%">Mobile No.</td>
        <td width="62%"><strong>'.$mobno.'</strong> </td>
        
       
        
        </tr>
        
        <tr>
        <td colspan="2">&nbsp;      </td>
        
        
        
        
        
        </tr>
        </table>
        
        </td>
        
        <td width="309"  height="20" style="font-size:13px; color:#999999;" valign="top">
        
        <table width="100%">
        <tr>
        <td colspan="4"><b>Item Details</b>        </td>
        
        
        
        
        
        </tr>
        
        
        <tr>
        <td width="33%"><strong>Name</strong></td>
        <td width="32%"><strong>Desc</strong> </td>
        <td width="14%"><strong>Count</strong> </td>
        <td width="21%"><strong>Price</strong> </td>
        
        
        
        </tr>
		';
		$tot=0;
	foreach($res as $key=>$values)
	{$tot+=$values['count']*$values['price'];
		$msg1.='
        
         <tr>
        <td width="33%">'.stripslashes($values['item_name']).'</td>
        <td width="32%">'.stripslashes($values['item_desc']).'        </td>
        <td width="14%">'.$values['count'].'        </td>
        <td width="21%">'.$values['price'].'        </td>
        
        
        
        </tr>';
		}
		
		foreach($CakeOrderDetails as $keyCakes=>$valuesCakes)
	{$tot+=$valuesCakes['order_count']*$valuesCakes['order_cake_price'];
		$msg1.='
        
         <tr>
        <td width="33%">'.stripslashes($valuesCakes['order_cake_name']).'</td>
        <td width="32%">&nbsp;        </td>
        <td width="14%">'.$valuesCakes['order_count'].'        </td>
        <td width="21%">'.$valuesCakes['order_cake_price'].'        </td>
        
        
        
        </tr>';
		}
		
		$msg1.='
        
         <tr>
        <td width="33%">Total</td>
        <td width="32%">&nbsp;        </td>
        <td width="14%">&nbsp;        </td>
        <td width="21%">'.$tot.'        </td>
        
        
        
        </tr>
        
        <tr>
        <td width="33%">Discount</td>
        <td width="32%">&nbsp;        </td>
        <td width="14%">&nbsp;        </td>
        <td width="21%">'.$discount.' %        </td>
        
        
        
        </tr>
        
        <tr>
        <td width="33%">Sub Total</td>
        <td width="32%">&nbsp;        </td>
        <td width="14%">&nbsp;        </td>
        <td width="21%"><strong>'.$price.'</strong> </td>
        
        
        
        </tr>
        
        
        
        </table>
        
        </td>
      </tr>
      <tr>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="2"><div align="center" style="font-size:13px;">
          <p><br />
            If you need any assistance feel free to  contact at yummybay.com.</p>
        </div></td>
      </tr>
      <tr>
        <td colspan="2">&nbsp;</td>
      </tr>
      
      <tr>
    <td align="left" bgcolor="#f4f3f3"  colspan="2"><h3 style="font-size:15px; color:#f03e60; padding:5px 0 5px 10px; margin:0px;">Follow Us</h3></td>
  </tr>
      <tr>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr >
        <td colspan="2"><table width="580" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="38">&nbsp;</td>
            <td width="107"><a href="http://www.facebook.com/Yummybay" target="_blank"><img src="http://yummybay.com/images/f1-img/f1ace_b1ook.jpg" width="107" height="28" border="0" /></a></td>
            <td width="26">&nbsp;</td>
            <td width="107"><a href="http://twitter.com/yummybay" target="_blank"><img src="http://yummybay.com/images/f1-img/t1witter.jpg" width="107" height="28" border="0" /></a></td>
            <td width="11">&nbsp;</td>
            <td width="117"><a href="http://blog.yummybay.com/" target="_blank"><img src="http://yummybay.com/images/f1-img/b1log.jpg" width="107" height="28" border="0" /></a></td>
            <td width="20">&nbsp;</td>
            <td width="111"><a href="http://www.youtube.com/watch?v=o5IQatKqH2Q" target="_blank"><img src="http://yummybay.com/images/f1-img/y1ou_t1ube.jpg" width="107" height="28" border="0" /></a></td>
            <td width="43">&nbsp;</td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td style="border-bottom:dotted; color:#efefef;" colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="2"><table width="580" border="0" cellspacing="0" cellpadding="0" style="background-color:#f4f3f3;">
          <tr>
            <td width="33%" bgcolor="#f4f3f3" style="color:#8b8989; padding:10px 0 0 10px; font-size:13px;">Contact Our CEO</td>
            <td width="33%" bgcolor="#f4f3f3" style="color:#8b8989; padding:10px 0 0 0; font-size:13px;">Marketing Division</td>
            <td width="33%" bgcolor="#f4f3f3" style="color:#8b8989; padding:10px 0 0 0; font-size:13px;">Business Devolopment</td>
          </tr>
          <tr>
            <td bgcolor="#f4f3f3" ><a href="mailto:ceo@yummybay.com" style="font-size:12px; padding:10px 10px 10px 10px;">ceo@yummybay.com</a></td>
            <td bgcolor="#f4f3f3" ><div align="left"><a href="mailto:marketing@yummybay.com" style="font-size:12px; padding:10px 10px 10px 0;">marketing@yummybay.com</a></div></td>
            <td bgcolor="#f4f3f3" ><div align="left"><a href="mailto:business@yummybay.com" style="font-size:12px; padding:10px 10px 10px 0;">business@yummybay.com</a></div></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td style="font-size:12px; padding:5px 0 10px 0;" bgcolor="#ffffff"  colspan="2"><div align="center" >
          <p>Yummybay.com is a division of AMICITIA FOOD  MART PVT  LTD - Registered COCHIN.  Registered Office: AMICITIA FOOD MART PVT LTD,PALATHINKAL BLDG,KOCHAPILLY ROAD,NH  47,PALARIVATTOM BYPASS,ERNAKULAM-682025. This communication contains  information which is confidential and may also be privileged. It is for the  exclusive use of the intended recipient(s). If you are not the intended  recipient(s) please note that any distribution, copying or use of this  communication or the information in it is strictly prohibited. Any views or  opinions expressed in the communication are solely those of the author. If you  have received this communication in error please notify us by e-mail or by  telephone and then delete the communication and any copies of it.<br />
              <br />
            Telephone calls may be monitored or recorded.</p>
        </div></td>
      </tr>
      <tr>
        <td colspan="2">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
</table>

</body>
</html>
';

		$mail1->Body=$msg1;
		//echo $msg1;exit;
	    $send =  $mail1->Send();
	   	if($send)
	   	{
	   		//echo "Mail sent";
	   	}
	   	else
	   	{
	   		//echo "Mail not sent";
	   	}
		return "";

	}
	function sendMailtoRstaurant($order_id)
	{
	    $sql	  = "select * from order_details left join menu on order_details.item_id=menu.item_id where order_details.order_id='$order_id'";
		$res	  = $this->db ->readValues($sql);
		
		$CakeOrderDetails=$this->CakeOrderDetails($order_id);
		
	    $qry	  = "select orders.* from orders left join user on orders.user_id=user.user_id where orders.order_id='$order_id'";
		$res1	  = $this->db ->readValue($qry);
		
			$order_id	=$res1['order_id'];
			$user_id	=$res1['user_id'];
			$rest_id	=$res1['rest_id'];
			$order_date =$res1['order_date'];
			$order_time = $res1['order_time'];
			$order_mobno =$res1['order_mobile'];
			$order_type =$res1['order_type'];
			$discount=$res1['discount'];
			$price=$res1['price'];
			$deliverytime=$res1['delivery_time'];
		
		$getUserDetails=$this->generalObj->getGeneralById('user',array('user_id'=>$user_id));
		$user_name	= $getUserDetails['name'];
		$user_email	= $getUserDetails['email'];
		$mobno		= $getUserDetails['mobile'];
		$address	= $getUserDetails['address'];
		$address2	= $getUserDetails['address2'];
		$address3	= $getUserDetails['address3'];
		
		$getRestaurantDetails=$this->generalObj->getGeneralById('user',array('user_id'=>$rest_id));
		$res_name	= $getRestaurantDetails['name'];
		$res_email	= $getRestaurantDetails['email'];
		$res_mobno	= $getRestaurantDetails['mobile'];
		
	  	$mail1=	new PHPMailer();
		$mail1->IsHTML(true); 
	    $mail1->Host = '208.109.217.153';	
		$mail1->AddAddress("$res_email");	
		$mail1->From="info@yummybay.com";
		$mail1->FromName = "yummybay";
		$mail1->Subject = "Order details from yummybay: ";
		
		$msg3='';
		
		

		$msg2='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>email_letter2_html</title>
<style type="text/css" media="screen">
body {
         margin: 0;
         padding: 0;
         background-color: #FFFFFF;
		 font-family: Arial;
		 color:#333333;
		 
      }
	   a {
         font-family: Arial;
         font-size: 13px;
         font-weight: normal;
         color: #f03e60;
      }

      p {
         font-family: Arial;
         font-size: 11px;
         font-weight: normal;
         color: #df143d;
		 margin:0px;
		 padding:5px 0 0 0;
      }
	  h3{
	  color:#999999;
	  }
</style>
</head>

<body>
<table  width="636"border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="background-image:url(image/bg.jpg); background-repeat:repeat-y;">
  <tr>
    <td><table width="580" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td height="111" colspan="2"><div align="center"><img src="http://yummybay.com/images/f1-img/l2ogo.jpg" width="582" height="111" /></div></td>
      </tr>
      <tr>
        <td style="background-image:url(http://yummybay.com/images/f1-img/r1ainb1ow.jpg); padding:0 0 0 10px;; margin:0px; height:155px; color:#FF0000;" colspan="2">Dear <span style="color:#333333;">'.$res_name.'</span>
          <h3 align="center">Welcome to Yummybay</h3>          <div align="center"></div></td>
      </tr>
      
      <tr>
        <td height="20" colspan="2"><div align="center" style="font-size:13px; color:#999999;">
          <p>Order details from yummybay.com</p>
        </div></td>
      </tr>
      
      <tr>
        <td width="273"  height="20" style="font-size:13px; color:#999999;" valign="top">
        
        <table width="100%">
        <tr>
        <td colspan="2"><b>Order Details</b>        </td>
        
        
        
        
        
        </tr>
        
        
        <tr>
        <td width="38%">Order ID        </td>
        <td width="62%"><strong>'.$order_id.'</strong> </td>
        
       
        
        </tr>
        
        <tr>
        <td width="38%">Order Date        </td>
        <td width="62%"><strong>'.$order_date.'</strong> </td>
        
       
        
        </tr>
        
        <tr>
        <td width="38%">Order Time        </td>
        <td width="62%"><strong>'.$order_time.'</strong> </td>
        
       
        
        </tr>
        
        <tr>
        <td width="38%">Order Mobile No.        </td>
        <td width="62%"><strong>'.$order_mobno.'</strong> </td>
        </tr>
        
        <tr>
        <td colspan="2"><b>Delivery Details</b></td>
        </tr>
        <tr>
          <td>Delivery Time</td>
          <td><strong>'.$deliverytime.'</strong></td>
        </tr>
        <tr>
          <td>Address</td>
          <td><strong>'.$address.'</strong></td>
        </tr>
        <tr>
          <td>Location</td>
          <td><strong>'.$address2.'</strong><strong>'.$address3.'</strong></td>
        </tr>
        <tr>
        <td width="38%">&nbsp;</td>
        <td width="62%">&nbsp;</td>
        </tr>
        <tr>
        <td colspan="2">&nbsp;      </td>
        
        
        
        
        
        </tr>
        
        
        <tr>
        <td colspan="2"><b>User Details</b>        </td>
        
        
        
        
        
        </tr>
        
        
        <tr>
        <td width="38%">Name</td>
        <td width="62%"><strong>'.$user_name.'</strong> </td>
        
       
        
        </tr>
        
        <tr>
        <td width="38%">Email</td>
        <td width="62%"><strong>'.$user_email.'</strong> </td>
        
       
        
        </tr>
        
        <tr>
        <td width="38%">Mobile No.</td>
        <td width="62%"><strong>'.$mobno.'</strong> </td>
        
       
        
        </tr>
        
        <tr>
        <td colspan="2">&nbsp;      </td>
        
        
        
        
        
        </tr>
        
        
        <tr>
        <td colspan="2"><b>Restaurant Details</b>        </td>
        
        
        
        
        
        </tr>
        
        
        <tr>
        <td width="38%">Name</td>
        <td width="62%"><strong>'.$res_name.'</strong> </td>
        
       
        
        </tr>
        
        <tr>
        <td width="38%">Email</td>
        <td width="62%"><strong>'.$res_email.'</strong> </td>
        
       
        
        </tr>
        
        <tr>
        <td width="38%">Mobile No.</td>
        <td width="62%"><strong>'.$res_mobno.'</strong> </td>
        
       
        
        </tr>
        
       
        
        
        
        </table>
        
        </td>
        
        <td width="309"  height="20" style="font-size:13px; color:#999999;" valign="top">
        
        <table width="100%">
        <tr>
        <td colspan="4"><b>Item Details</b>        </td>
        
        
        
        
        
        </tr>
        
        
        <tr>
        <td width="33%"><strong>Name</strong></td>
        <td width="32%"><strong>Desc</strong> </td>
        <td width="14%"><strong>Count</strong> </td>
        <td width="21%"><strong>Price</strong> </td>
        
        
        
        </tr>
		';
		$tot=0;
	foreach($res as $key=>$values)
	{$tot+=$values['count']*$values['price'];
		$msg2.='
        
         <tr>
        <td width="33%">'.stripslashes($values['item_name']).'</td>
        <td width="32%">'.stripslashes($values['item_desc']).'        </td>
        <td width="14%">'.$values['count'].'        </td>
        <td width="21%">'.$values['price'].'        </td>
        
        
        
        </tr>';
		}
		
		foreach($CakeOrderDetails as $keyCakes=>$valuesCakes)
	{$tot+=$valuesCakes['order_count']*$valuesCakes['order_cake_price'];
		$msg2.='
        
         <tr>
        <td width="33%">'.stripslashes($valuesCakes['order_cake_name']).'</td>
        <td width="32%">&nbsp;        </td>
        <td width="14%">'.$valuesCakes['order_count'].'        </td>
        <td width="21%">'.$valuesCakes['order_cake_price'].'        </td>
        
        
        
        </tr>';
		}
		
		
		
		$msg2.='
        
         <tr>
        <td width="33%">Total</td>
        <td width="32%">&nbsp;        </td>
        <td width="14%">&nbsp;        </td>
        <td width="21%">'.$tot.'        </td>
        
        
        
        </tr>
        
        <tr>
        <td width="33%">Discount</td>
        <td width="32%">&nbsp;        </td>
        <td width="14%">&nbsp;        </td>
        <td width="21%">'.$discount.' %        </td>
        
        
        
        </tr>
        
        <tr>
        <td width="33%">Sub Total</td>
        <td width="32%">&nbsp;        </td>
        <td width="14%">&nbsp;        </td>
        <td width="21%"><strong>'.$price.'</strong> </td>
        
        
        
        </tr>
        
        
        
        </table>
        
        </td>
      </tr>
      <tr>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="2"><div align="center" style="font-size:13px;">
          <p><br />
            If you need any assistance feel free to  contact at yummybay.com.</p>
        </div></td>
      </tr>
      <tr>
        <td colspan="2">&nbsp;</td>
      </tr>
      
      <tr>
    <td align="left" bgcolor="#f4f3f3"  colspan="2"><h3 style="font-size:15px; color:#f03e60; padding:5px 0 5px 10px; margin:0px;">Follow Us</h3></td>
  </tr>
      <tr>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr >
        <td colspan="2"><table width="580" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="38">&nbsp;</td>
            <td width="107"><a href="http://www.facebook.com/Yummybay" target="_blank"><img src="http://yummybay.com/images/f1-img/f1ace_b1ook.jpg" width="107" height="28" border="0" /></a></td>
            <td width="26">&nbsp;</td>
            <td width="107"><a href="http://twitter.com/yummybay" target="_blank"><img src="http://yummybay.com/images/f1-img/t1witter.jpg" width="107" height="28" border="0" /></a></td>
            <td width="11">&nbsp;</td>
            <td width="117"><a href="http://blog.yummybay.com/" target="_blank"><img src="http://yummybay.com/images/f1-img/b1log.jpg" width="107" height="28" border="0" /></a></td>
            <td width="20">&nbsp;</td>
            <td width="111"><a href="http://www.youtube.com/watch?v=o5IQatKqH2Q" target="_blank"><img src="http://yummybay.com/images/f1-img/y1ou_t1ube.jpg" width="107" height="28" border="0" /></a></td>
            <td width="43">&nbsp;</td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td style="border-bottom:dotted; color:#efefef;" colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="2"><table width="580" border="0" cellspacing="0" cellpadding="0" style="background-color:#f4f3f3;">
          <tr>
            <td width="33%" bgcolor="#f4f3f3" style="color:#8b8989; padding:10px 0 0 10px; font-size:13px;">Contact Our CEO</td>
            <td width="33%" bgcolor="#f4f3f3" style="color:#8b8989; padding:10px 0 0 0; font-size:13px;">Marketing Division</td>
            <td width="33%" bgcolor="#f4f3f3" style="color:#8b8989; padding:10px 0 0 0; font-size:13px;">Business Devolopment</td>
          </tr>
          <tr>
            <td bgcolor="#f4f3f3" ><a href="mailto:ceo@yummybay.com" style="font-size:12px; padding:10px 10px 10px 10px;">ceo@yummybay.com</a></td>
            <td bgcolor="#f4f3f3" ><div align="left"><a href="mailto:marketing@yummybay.com" style="font-size:12px; padding:10px 10px 10px 0;">marketing@yummybay.com</a></div></td>
            <td bgcolor="#f4f3f3" ><div align="left"><a href="mailto:business@yummybay.com" style="font-size:12px; padding:10px 10px 10px 0;">business@yummybay.com</a></div></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td style="font-size:12px; padding:5px 0 10px 0;" bgcolor="#ffffff"  colspan="2"><div align="center" >
          <p>Yummybay.com is a division of AMICITIA FOOD  MART PVT  LTD - Registered COCHIN.  Registered Office: AMICITIA FOOD MART PVT LTD,PALATHINKAL BLDG,KOCHAPILLY ROAD,NH  47,PALARIVATTOM BYPASS,ERNAKULAM-682025. This communication contains  information which is confidential and may also be privileged. It is for the  exclusive use of the intended recipient(s). If you are not the intended  recipient(s) please note that any distribution, copying or use of this  communication or the information in it is strictly prohibited. Any views or  opinions expressed in the communication are solely those of the author. If you  have received this communication in error please notify us by e-mail or by  telephone and then delete the communication and any copies of it.<br />
              <br />
            Telephone calls may be monitored or recorded.</p>
        </div></td>
      </tr>
      <tr>
        <td colspan="2">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
</table>

</body>
</html>
';







		$mail1->Body=$msg2;
		//echo $msg2;exit;
	    $send =  $mail1->Send();
		
	   	if($send)
	   	{
	   		//echo "Mail sent";
	   	}
	   	else
	   	{
	   		//echo "Mail not sent";
	   	}
		return "";
	
	}
	function RestMobile()
	{
		$order_id=$_SESSION['order_id'];
		$sql="select * from orders left join user on orders.rest_id=user.user_id where orders.order_id='$order_id' ";
		//echo $mobile;exit;
		$res	= $this->db ->readValue($sql);
		$mobile=$res['mobile'];
		return $mobile;
	}
	
	function insertOrderDetails($order_id)
	{
		$rest_id=$_SESSION['rest_id'];
		$shop_id=$_SESSION['shop_id'];
		$sql="select * from shop_cart left join menu on shop_cart.item_id=menu.item_id where shop_cart.shop_id='$shop_id' and menu.user_id='$rest_id'";
		
		$res	= $this->db ->readValues($sql);
		
		foreach($res as $key=>$values)
		{
			$item_id=$values['item_id'];
			$count=$values['count'];
			$price=$values['price'];
			$item_name=$values['item_name'];
			$item_desc=$values['item_desc'];
			
			$sql1="insert into order_details(order_id,item_id,count,order_item_price,order_item_name,order_item_desc) values('$order_id','$item_id','$count','$price','$item_name','$item_desc')";
			
			$res1	= $this->db->setQuery($sql1);
		}
		
		return "Order details inserted successfully";
	}
	function insertCakesOrderDetails($order_id,$cakesCart)
	{
		$rest_id=$_SESSION['rest_id'];
		$shop_id=$_SESSION['shop_id'];
		
		foreach($cakesCart as $key=>$values)
		{
			$rest_cake_id=$values['rest_cake_id'];
			$order_count=$values['count'];
			$order_cake_price=$values['cake_price'];
			$order_cake_name=$values['cake_name'];
			$order_cake_message=$values['message'];
			
			$sql="insert into cake_order_details(order_id,rest_cake_id,order_count,order_cake_price,order_cake_name,order_cake_message) values('$order_id','$rest_cake_id','$order_count','$order_cake_price','$order_cake_name','$order_cake_message')";
			$res	= $this->db->setQuery($sql);
		}
		
		return "Cake Order details inserted successfully";
		
		
	}
	
	function price($shop_id,$rest_id,$order_type,$VoucherCodeDiscount,$msg)
	{
		$getRestaurantbyId=$this->generalObj->getGeneralById('user',array('user_id'=>$rest_id));
		$discount=$getRestaurantbyId['discount'];
		//echo $discount;exit;
		$tax	=$getRestaurantbyId['servicetax'];
		$delivery_fee=$getRestaurantbyId['delivery_fee'];
		
		$getRestPromotions=$this->generalObj->getGeneralById('rest_promotions',array('user_id'=>$rest_id));
		
		//$adminDiscount=$this->adminDiscount();
		
		//$discount1=$discount+$adminDiscount;
		
		
		
		$tot=$this->total($shop_id,$rest_id);
		
		$getDiscount=$this->discountCalc($rest_id,$tot,$order_type,$VoucherCodeDiscount,$msg);
		
		
		
		//echo $getDiscount;exit;
		
		if($order_type=='Delivery')
		{
			$subtotal=$tot+$delivery_fee;
		}
		else
		{
			$subtotal=$tot;
		}
		
		$subtotaldscnt=($subtotal*(100-$getDiscount))/100;
		$taxsubtotalcnt=$subtotaldscnt+($subtotaldscnt*$tax)/100;
		//$retValue=array($subtotaldscnt,$discount)
		
		return $taxsubtotalcnt;
	}
	function discountCalc($rest_id,$tot,$order_type,$VoucherCodeDiscount,$msg)
	{
	
		$getRestaurantbyId=$this->generalObj->getGeneralById('user',array('user_id'=>$rest_id));
		$discount=$getRestaurantbyId['discount'];
		$tax	 =$getRestaurantbyId['servicetax'];
		$getRestPromotions=$this->generalObj->getGeneralById('rest_promotions',array('user_id'=>$rest_id));
		
		if($getRestPromotions)
		{
			if(($getRestPromotions['promot3']!="")&&($getRestPromotions['promot3_rs']!=""))
			{
				//$fndPercent=($getRestPromotions['promot3']/$subtothead)*100;
				if($tot>=$getRestPromotions['promot3_rs'])
				{
					if($getRestPromotions['promot3']>$discount)
					{
						$discount=$getRestPromotions['promot3'];
						
					}
					
				}
			}
			
			if($order_type=='Collection')
			{
			
			
				if(($getRestPromotions['promot2']!="")&&($getRestPromotions['promot2_rs']!=""))
				{
					if($tot>=$getRestPromotions['promot2_rs'])
					{
						if($getRestPromotions['promot2']>$discount)
						{
							$discount=$getRestPromotions['promot2'];
							
						}
					}
				}
			}
		}
		
		if($msg==1)
		{
			if($VoucherCodeDiscount>$discount)
			{
				$discount=$VoucherCodeDiscount;
			}
		}
		//echo $discount;exit;
		return $discount;
	}
	function total($shop_id,$rest_id)
	{
		$orderDetails=$this->shopCartMain($shop_id,$rest_id);
		$tot=0;
		foreach($orderDetails as $key=>$values)
		{
			$tot+=($values['count']*$values['price']);
		}
		
		$cakesCart=$this->cakesCartGet();
		
		foreach($cakesCart as $keyCakes=>$valuesCakes)
		{
			$tot+=($valuesCakes['count']*$valuesCakes['cake_price']);
		}
		
		return $tot;
	}
	function points($shop_id,$rest_id)
	{
		$tot=$this->total($shop_id,$rest_id);
		$points=$tot/10;
		$pts=round($points);
		return $pts;
	}
	function adminDiscount()
	{
		$sql="select discount from user where type='SuperAdmin' and user_id='1'";
		$res	= $this->db ->readValue($sql);
		$discount=$res['discount'];
		return $discount;
	}
	function successOrderDetails($order_id)
	{
		$sql="select * from order_details left join menu on order_details.item_id=menu.item_id where order_details.order_id='$order_id'";
		//echo $sql; exit;
		$res	= $this->db ->readValues($sql);
		return $res;
	}
	function getOrderAndRestaurant($order_id)
	{
		$sql="select * from orders left join user on orders.rest_id=user.user_id where orders.order_id='$order_id'";
		//echo $sql;exit;
		$res	= $this->db->readValue($sql);
		return $res;
	}
	function getAllUserOrders($user_id)
	{
		$sql="select orders.*,user.name from orders left join user on orders.rest_id=user.user_id where orders.user_id='$user_id' and orders.status_order!='Cancelled' order by orders.order_id desc";
		//echo $sql;
		
		$res	= $this->db->readValues($sql);
		//exit;
		//echo count($res);exit;
		return $res;
	}
	function chkLogin($session_id,$POST)
	{
		$password=addslashes($POST['password']);
		$new_password=addslashes($POST['new_password']);
		$confirm_password=addslashes($POST['confirm_password']);
		$sql="select * from user where user_id='$session_id' and password='$password'";
		$res	= $this->db->readValue($sql);
		if($res)
		{
			$sql1="update user set password='$new_password' where user_id='$session_id'";
			$res1	= $this->db->setQuery($sql1);
			return "Password changed successfully";
		}
		else
		{
			return "Old password is incorrect";
		}
	}
	function ForgotPassword($POST)
	{
		$email=addslashes($POST['email']);
		$sql="select * from user where email='$email' and type='User' and status='Active'";
		$res	= $this->db->readValue($sql);
		if($res)
		{
			return $res;
		}
		else
		{
			return "";
		}
	}
	function insertReview($POST)
	{
		$order_id=addslashes($POST['order_id']);
		$review=addslashes($POST['review']);
		$date=$this->date;
		list($date1,$time)=explode(" ",$date);
		$sql="insert into customer_review(order_id,review,date,time,status) values('$order_id','$review','$date1','$time','Active')";
		$res	= $this->db->setQuery($sql);
		return "Review posted successfully";
						
	}
	function addTofavourite($user_id,$rest_id)
	{
		$sql="insert into favourite_reataurants(user_id,rest_id) values('$user_id','$rest_id')";
		$res	= $this->db->setQuery($sql);
		return "Restaurant added to favourite";
	}
	function getFavourite($user_id,$rest_id)
	{
		$sql="select * from favourite_reataurants where user_id='$user_id' and rest_id='$rest_id'";
		$res	= $this->db->readValue($sql);
		return $res;
	}
	function RemoveFromfavourite($user_id,$rest_id)
	{
		$sql="delete from favourite_reataurants where user_id='$user_id' and rest_id='$rest_id'";
		$res	= $this->db->setQuery($sql);
		return "Restaurant removed from favourite";
	}
	function MobileVerification($session_id,$POST)
	{
		$mobile=addslashes($POST['mobile']);
		$sql="select verification from user where user_id='$session_id' and verification='$mobile'";
		$res	= $this->db->readValue($sql);
		if($res)
		{//echo "1";exit;
			$sql1="update user set verification='' where user_id='$session_id'";
			$res1	= $this->db->setQuery($sql1);
			return 'success';
		}
		else
		{
			//echo "2";exit;
			return 'failure';
		}
		//exit;
	}
	function chkMobile($user_id)
	{
		$sql="select verification from user where user_id='$user_id'";
		$res	= $this->db->readValue($sql);
		return $res;
	}
	function getUserById($user_id)
	{
		$sql="select * from user where user_id='$user_id'";
		//exit;
		$res	=$this->db->readValue($sql);
		//print_r($res);exit;
		return $res;
	}
	function RestaurantInArea($district)
	{
		$sql="select * from user where district='$district' and type='Hotel' and status='Active' limit 0,4";
		$res	=$this->db->readValues($sql);
		//print_r($res);exit;
		return $res;
	}
	function getAllFavouriteRestaurant()
	{
		$user_id=$_SESSION['yummyuserID'];
		$sql="select * from favourite_reataurants left join user on favourite_reataurants.rest_id=user.user_id where favourite_reataurants.user_id='$user_id' and user.status='Active'";
		$res	=$this->db->readValues($sql);
		//print_r($res);exit;
		return $res;
	}
	function OrderaddTofavourite($order_id)
	{
		$user_id=$_SESSION['yummyuserID'];
		$sql="delete from favourite_order where user_id='$user_id' and order_id='$order_id'";
		$res	= $this->db->setQuery($sql);
		$sql1="insert into favourite_order(user_id,order_id) values('$user_id','$order_id')";
		$res1	= $this->db->setQuery($sql1);
		return "Order added to favourite";
	}
	function getAllFavouriteOrders()
	{
		$user_id=$_SESSION['yummyuserID'];
		$sql="select * from favourite_order left join orders on favourite_order.order_id=orders.order_id left join user on user.user_id=orders.rest_id where favourite_order.user_id='$user_id'";
		$res	=$this->db->readValues($sql);
		return $res;
	}
	function AddToCart($order_id)
	{
		$shop_id=$_SESSION['shop_id'];
		$orderDetails=$this->successOrderDetails($order_id);
		
		foreach($orderDetails as $key=>$values)
		{
			$item_id=$values['item_id'];
			$count=$values['count'];
			$sql="insert into shop_cart(shop_id,item_id,count) values('$shop_id','$item_id','$count')";
			//echo $sql;
			$res	= $this->db->setQuery($sql);
		}
		return "Order added to cart";
	}
	function deleteOrderFavourite($order_id)
	{
		$user_id=$_SESSION['yummyuserID'];
		$sql="delete from favourite_order where user_id='$user_id' and order_id='$order_id'";
		//echo $sql;exit;
		$res	= $this->db->setQuery($sql);
		return "Order removed from favourite";
	}
	function rateService($value,$order_id)
	{
		$sql="select * from rest_rating where order_id='$order_id'";
		$res	=$this->db->readValue($sql);
		if($res)
		{
			$sql1="update rest_rating set service='$value' where order_id='$order_id'";
			$res1	= $this->db->setQuery($sql1);
		}
		else
		{
			$sql2="insert into rest_rating(order_id,service) values('$order_id','$value')";
			$res2	= $this->db->setQuery($sql2);
		}
		return "Service rated successfully";
	}
	function rateQuality($value,$order_id)
	{
		$sql="select * from rest_rating where order_id='$order_id'";
		$res	=$this->db->readValue($sql);
		if($res)
		{
			$sql1="update rest_rating set quality='$value' where order_id='$order_id'";
			$res1	= $this->db->setQuery($sql1);
		}
		else
		{
			$sql2="insert into rest_rating(order_id,quality) values('$order_id','$value')";
			$res2	= $this->db->setQuery($sql2);
		}
		return "Quality rated successfully";
	}
	function rateDelivery($value,$order_id)
	{
		$sql="select * from rest_rating where order_id='$order_id'";
		$res	=$this->db->readValue($sql);
		if($res)
		{
			$sql1="update rest_rating set deliveryTime ='$value' where order_id='$order_id'";
			$res1	= $this->db->setQuery($sql1);
		}
		else
		{
			$sql2="insert into rest_rating(order_id,deliveryTime) values('$order_id','$value')";
			$res2	= $this->db->setQuery($sql2);
		}
		return "Delivery rated successfully";
	}
	
	function OrderRating($order_id)
	{
		$sql="select * from rest_rating where order_id='$order_id'";
		//echo $sql;exit;
		$res	=$this->db->readValue($sql);
		return $res;
	}
	function serviceRating2($service)
	{
		switch ($service) 
							{
								case 1:
									$imagedelivery="cr-1.jpg";
									break;
								case 1.1:
									$imagedelivery="cr-1.jpg";
									break;
								case 1.2:
									$imagedelivery="cr-1.jpg";
									break;
								case 1.3:
									$imagedelivery="cr-1pt5.jpg";
									break;
								case 1.4:
									$imagedelivery="cr-1pt5.jpg";
									break;
								case 1.5:
									$imagedelivery="cr-1pt5.jpg";
									break;
								case 1.6:
									$imagedelivery="cr-1pt5.jpg";
									break;
								case 1.7:
									$imagedelivery="cr-1pt5.jpg";
									break;
								case 1.8:
									$imagedelivery="cr-2.jpg";
									break;
								case 1.9:
									$imagedelivery="cr-2.jpg";
									break;
								case 2:
									$imagedelivery="cr-2.jpg";
									break;
								case 2.1:
									$imagedelivery="cr-2.jpg";
									break;
								case 2.2:
									$imagedelivery="cr-2.jpg";
									break;
								case 2.3:
									$imagedelivery="cr-2pt5.jpg";
									break;
								case 2.4:
									$imagedelivery="cr-2pt5.jpg";
									break;
								case 2.5:
									$imagedelivery="cr-2pt5.jpg";
									break;
								case 2.6:
									$imagedelivery="cr-2pt5.jpg";
									break;
								case 2.7:
									$imagedelivery="cr-2pt5.jpg";
									break;
								case 2.8:
									$imagedelivery="cr-3.jpg";
									break;
								case 2.9:
									$imagedelivery="cr-3.jpg";
									break;
								case 3:
									$imagedelivery="cr-3.jpg";
									break;
								case 3.1:
									$imagedelivery="cr-3.jpg";
									break;
								case 3.2:
									$imagedelivery="cr-3.jpg";
									break;
								case 3.3:
									$imagedelivery="cr-3pt5.jpg";
									break;
								case 3.4:
									$imagedelivery="cr-3pt5.jpg";
									break;
								case 3.5:
									$imagedelivery="cr-3pt5.jpg";
									break;
								case 3.6:
									$imagedelivery="cr-3pt5.jpg";
									break;
								case 3.7:
									$imagedelivery="cr-3pt5.jpg";
									break;
								case 3.8:
									$imagedelivery="cr-4.jpg";
									break;
								case 3.9:
									$imagedelivery="cr-4.jpg";
									break;
								case 4:
									$imagedelivery="cr-4.jpg";
									break;
								case 4.1:
									$imagedelivery="cr-4.jpg";
									break;
								case 4.2:
									$imagedelivery="cr-4.jpg";
									break;
								case 4.3:
									$imagedelivery="cr-4pt5.jpg";
									break;
								case 4.4:
									$imagedelivery="cr-4pt5.jpg";
									break;
								case 4.5:
									$imagedelivery="cr-4pt5.jpg";
									break;
								case 4.6:
									$imagedelivery="cr-4pt5.jpg";
									break;
								case 4.7:
									$imagedelivery="cr-4pt5.jpg";
									break;
								case 4.8:
									$imagedelivery="cr-5.jpg";
									break;
								case 4.9:
									$imagedelivery="cr-5.jpg";
									break;
								case 5:
									$imagedelivery="cr-5.jpg";
									break;
								case 5.1:
									$imagedelivery="cr-5.jpg";
									break;
								case 5.2:
									$imagedelivery="cr-5.jpg";
									break;
								case 5.3:
									$imagedelivery="cr-5pt5.jpg";
									break;
								case 5.4:
									$imagedelivery="cr-5pt5.jpg";
									break;
								case 5.5:
									$imagedelivery="cr-5pt5.jpg";
									break;
								case 5.6:
									$imagedelivery="cr-5pt5.jpg";
									break;
								case 5.7:
									$imagedelivery="cr-5pt5.jpg";
									break;
								case 5.8:
									$imagedelivery="cr-6.jpg";
									break;
								case 5.9:
									$imagedelivery="cr-6.jpg";
									break;
								case 6:
									$imagedelivery="cr-6.jpg";
									break;
							}
		return $imagedelivery;
	}
	function qualityRating2($quality)
	{
		switch ($quality) 
							{
								case 1:
									$imagedelivery="cr-1.jpg";
									break;
								case 1.1:
									$imagedelivery="cr-1.jpg";
									break;
								case 1.2:
									$imagedelivery="cr-1.jpg";
									break;
								case 1.3:
									$imagedelivery="cr-1pt5.jpg";
									break;
								case 1.4:
									$imagedelivery="cr-1pt5.jpg";
									break;
								case 1.5:
									$imagedelivery="cr-1pt5.jpg";
									break;
								case 1.6:
									$imagedelivery="cr-1pt5.jpg";
									break;
								case 1.7:
									$imagedelivery="cr-1pt5.jpg";
									break;
								case 1.8:
									$imagedelivery="cr-2.jpg";
									break;
								case 1.9:
									$imagedelivery="cr-2.jpg";
									break;
								case 2:
									$imagedelivery="cr-2.jpg";
									break;
								case 2.1:
									$imagedelivery="cr-2.jpg";
									break;
								case 2.2:
									$imagedelivery="cr-2.jpg";
									break;
								case 2.3:
									$imagedelivery="cr-2pt5.jpg";
									break;
								case 2.4:
									$imagedelivery="cr-2pt5.jpg";
									break;
								case 2.5:
									$imagedelivery="cr-2pt5.jpg";
									break;
								case 2.6:
									$imagedelivery="cr-2pt5.jpg";
									break;
								case 2.7:
									$imagedelivery="cr-2pt5.jpg";
									break;
								case 2.8:
									$imagedelivery="cr-3.jpg";
									break;
								case 2.9:
									$imagedelivery="cr-3.jpg";
									break;
								case 3:
									$imagedelivery="cr-3.jpg";
									break;
								case 3.1:
									$imagedelivery="cr-3.jpg";
									break;
								case 3.2:
									$imagedelivery="cr-3.jpg";
									break;
								case 3.3:
									$imagedelivery="cr-3pt5.jpg";
									break;
								case 3.4:
									$imagedelivery="cr-3pt5.jpg";
									break;
								case 3.5:
									$imagedelivery="cr-3pt5.jpg";
									break;
								case 3.6:
									$imagedelivery="cr-3pt5.jpg";
									break;
								case 3.7:
									$imagedelivery="cr-3pt5.jpg";
									break;
								case 3.8:
									$imagedelivery="cr-4.jpg";
									break;
								case 3.9:
									$imagedelivery="cr-4.jpg";
									break;
								case 4:
									$imagedelivery="cr-4.jpg";
									break;
								case 4.1:
									$imagedelivery="cr-4.jpg";
									break;
								case 4.2:
									$imagedelivery="cr-4.jpg";
									break;
								case 4.3:
									$imagedelivery="cr-4pt5.jpg";
									break;
								case 4.4:
									$imagedelivery="cr-4pt5.jpg";
									break;
								case 4.5:
									$imagedelivery="cr-4pt5.jpg";
									break;
								case 4.6:
									$imagedelivery="cr-4pt5.jpg";
									break;
								case 4.7:
									$imagedelivery="cr-4pt5.jpg";
									break;
								case 4.8:
									$imagedelivery="cr-5.jpg";
									break;
								case 4.9:
									$imagedelivery="cr-5.jpg";
									break;
								case 5:
									$imagedelivery="cr-5.jpg";
									break;
								case 5.1:
									$imagedelivery="cr-5.jpg";
									break;
								case 5.2:
									$imagedelivery="cr-5.jpg";
									break;
								case 5.3:
									$imagedelivery="cr-5pt5.jpg";
									break;
								case 5.4:
									$imagedelivery="cr-5pt5.jpg";
									break;
								case 5.5:
									$imagedelivery="cr-5pt5.jpg";
									break;
								case 5.6:
									$imagedelivery="cr-5pt5.jpg";
									break;
								case 5.7:
									$imagedelivery="cr-5pt5.jpg";
									break;
								case 5.8:
									$imagedelivery="cr-6.jpg";
									break;
								case 5.9:
									$imagedelivery="cr-6.jpg";
									break;
								case 6:
									$imagedelivery="cr-6.jpg";
									break;
							}
		return $imagedelivery;
	}
	function deliveryRating2($delivery)
	{
		switch ($delivery) 
							{
								case 1:
									$imagedelivery="cr-1.jpg";
									break;
								case 1.1:
									$imagedelivery="cr-1.jpg";
									break;
								case 1.2:
									$imagedelivery="cr-1.jpg";
									break;
								case 1.3:
									$imagedelivery="cr-1pt5.jpg";
									break;
								case 1.4:
									$imagedelivery="cr-1pt5.jpg";
									break;
								case 1.5:
									$imagedelivery="cr-1pt5.jpg";
									break;
								case 1.6:
									$imagedelivery="cr-1pt5.jpg";
									break;
								case 1.7:
									$imagedelivery="cr-1pt5.jpg";
									break;
								case 1.8:
									$imagedelivery="cr-2.jpg";
									break;
								case 1.9:
									$imagedelivery="cr-2.jpg";
									break;
								case 2:
									$imagedelivery="cr-2.jpg";
									break;
								case 2.1:
									$imagedelivery="cr-2.jpg";
									break;
								case 2.2:
									$imagedelivery="cr-2.jpg";
									break;
								case 2.3:
									$imagedelivery="cr-2pt5.jpg";
									break;
								case 2.4:
									$imagedelivery="cr-2pt5.jpg";
									break;
								case 2.5:
									$imagedelivery="cr-2pt5.jpg";
									break;
								case 2.6:
									$imagedelivery="cr-2pt5.jpg";
									break;
								case 2.7:
									$imagedelivery="cr-2pt5.jpg";
									break;
								case 2.8:
									$imagedelivery="cr-3.jpg";
									break;
								case 2.9:
									$imagedelivery="cr-3.jpg";
									break;
								case 3:
									$imagedelivery="cr-3.jpg";
									break;
								case 3.1:
									$imagedelivery="cr-3.jpg";
									break;
								case 3.2:
									$imagedelivery="cr-3.jpg";
									break;
								case 3.3:
									$imagedelivery="cr-3pt5.jpg";
									break;
								case 3.4:
									$imagedelivery="cr-3pt5.jpg";
									break;
								case 3.5:
									$imagedelivery="cr-3pt5.jpg";
									break;
								case 3.6:
									$imagedelivery="cr-3pt5.jpg";
									break;
								case 3.7:
									$imagedelivery="cr-3pt5.jpg";
									break;
								case 3.8:
									$imagedelivery="cr-4.jpg";
									break;
								case 3.9:
									$imagedelivery="cr-4.jpg";
									break;
								case 4:
									$imagedelivery="cr-4.jpg";
									break;
								case 4.1:
									$imagedelivery="cr-4.jpg";
									break;
								case 4.2:
									$imagedelivery="cr-4.jpg";
									break;
								case 4.3:
									$imagedelivery="cr-4pt5.jpg";
									break;
								case 4.4:
									$imagedelivery="cr-4pt5.jpg";
									break;
								case 4.5:
									$imagedelivery="cr-4pt5.jpg";
									break;
								case 4.6:
									$imagedelivery="cr-4pt5.jpg";
									break;
								case 4.7:
									$imagedelivery="cr-4pt5.jpg";
									break;
								case 4.8:
									$imagedelivery="cr-5.jpg";
									break;
								case 4.9:
									$imagedelivery="cr-5.jpg";
									break;
								case 5:
									$imagedelivery="cr-5.jpg";
									break;
								case 5.1:
									$imagedelivery="cr-5.jpg";
									break;
								case 5.2:
									$imagedelivery="cr-5.jpg";
									break;
								case 5.3:
									$imagedelivery="cr-5pt5.jpg";
									break;
								case 5.4:
									$imagedelivery="cr-5pt5.jpg";
									break;
								case 5.5:
									$imagedelivery="cr-5pt5.jpg";
									break;
								case 5.6:
									$imagedelivery="cr-5pt5.jpg";
									break;
								case 5.7:
									$imagedelivery="cr-5pt5.jpg";
									break;
								case 5.8:
									$imagedelivery="cr-6.jpg";
									break;
								case 5.9:
									$imagedelivery="cr-6.jpg";
									break;
								case 6:
									$imagedelivery="cr-6.jpg";
									break;
							}
		return $imagedelivery;
	}
	function getAllRestaurantCategory($user_id)
	{
		$sql="select * from rest_categories left join rest_includes on rest_categories.rest_category_id=rest_includes.rest_category_id where rest_includes.user_id='$user_id'";
		//echo $sql;exit;
		$res	=$this->db->readValues($sql);
		return $res;
	}
	function CancelGeneral($table,$primary=array())
	{
		$sql="update $table set status_order='Cancelled'";
		
		if(!empty($primary))
		{
			$primary1=array_keys($primary);
			$primary2=$primary1[0];
			$primary3=$primary[$primary2];
			$sql.=" where $primary2='$primary3' ";
			//echo $sql;exit;
			$res	= $this->db ->setQuery($sql);
		}
		
		return "Deleted successfully";
	}
	function AddCorporate($POST,$service)
	{
		$name=addslashes($POST['name']);
		$email=addslashes($POST['email']);
		$mobile=addslashes($POST['mobile']);
		$phone=addslashes($POST['phone']);
		$date=addslashes($POST['date']);
		$hour=addslashes($POST['hour']);
		$min=addslashes($POST['min']);
		
		$end_date=addslashes($POST['end_date']);
		$end_hour=addslashes($POST['end_hour']);
		$end_min=addslashes($POST['end_min']);
	
		$seats=addslashes($POST['seats']);
		$cuisine=addslashes($POST['cuisine']);
		$budget=addslashes($POST['budget']);
		$city=addslashes($POST['city']);
		$locality=addslashes($POST['locality']);
		
		$getDistrictbyId=$this->generalObj->getGeneralById('districts',array('district_id'=>$locality));
		
		$district=$getDistrictbyId['district'];
		
		$occassion=addslashes($POST['occassion']);
		$instruction=addslashes($POST['instruction']);
		
		list($d,$m,$y)=explode("/",$date);
			$dob1=$y."-".$m."-".$d;
			
		list($end_d,$end_m,$end_y)=explode("/",$end_date);
			$end_dob1=$end_y."-".$end_m."-".$end_d;
			
		$time=$hour.":".$min;
		
		$end_time=$end_hour.":".$end_min;
		
		$start_date=$dob1." ".$time;
		$end_date=$end_dob1." ".$time;
		
		$sql="insert into book_table(name,mobile,phone,email_id,date,time,start_date,end_date,total_seats,cuisine,service,budget,city,locality,occasion,instructions,type) values('$name','$mobile','$phone','$email','$dob1','$time','$start_date','$end_date','$seats','$cuisine','$service','$budget','$city','$district','$occassion','$instruction','corporate')";
		
		//echo $sql;exit;
		$res	= $this->db ->setQuery($sql);
		$sendSmsnew=$this->sendSms('New corporate booking received, please check corporate booking','9037045600');
		return "Corporate request sent successfully";
	}
	function AddCaters($POST)
	{
		$name=addslashes($POST['name']);
		$email=addslashes($POST['email']);
		$mobile=addslashes($POST['mobile']);
		$phone=addslashes($POST['phone']);
		$date=addslashes($POST['date']);
		
		$cuisine=addslashes($POST['cuisine']);
		$district=addslashes($POST['district']);
		$location=addslashes($POST['location']);
		$occassion=addslashes($POST['occassion']);
		$instruction=addslashes($POST['instruction']);
		
		if(isset($POST['enquiry']))
		{
			$enquiry=addslashes($POST['enquiry']);
		}
		else
		{
			$enquiry=0;
		}
		$user_id=addslashes($POST['user_id']);
		
		list($d,$m,$y)=explode("/",$date);
			$dob1=$y."-".$m."-".$d;
		$sql="insert into book_table(user_id,name,mobile,phone,email_id,date,time,total_seats,cuisine,service,budget,locality,district,occasion,instructions,type,enquiry,status) values('$user_id','$name','$mobile','$phone','$email','$dob1','00:00:00','0','$cuisine','','','$location','$district','$occassion','$instruction','caters','$enquiry','Inactive')";
		//$sql;exit;
		
		$res	= $this->db ->setQuery($sql);
		return "Cater request sent successfully";
	}
	function AddBookaTable($POST,$restmobile)
	{
		$user_id=addslashes($POST['user_id']);
		
		$name=addslashes($POST['name']);
		$email=addslashes($POST['email']);
		$mobile=addslashes($POST['mobile']);
		$phone=addslashes($POST['phone']);
		$date=addslashes($POST['date']);
		$hour=addslashes($POST['hour']);
		$min=addslashes($POST['min']);
		$seats=addslashes($POST['seats']);
		$cuisine=addslashes($POST['cuisine']);
		$city=addslashes($POST['city']);
		$locality=addslashes($POST['locality']);
		$occassion=addslashes($POST['occassion']);
		$instruction=addslashes($POST['instruction']);
		
		list($d,$m,$y)=explode("/",$date);
			$dob1=$y."-".$m."-".$d;
			
		$time=$hour.":".$min;
		
		$sql="insert into book_table(user_id,name,mobile,phone,email_id,date,time,total_seats,cuisine,service,budget,city,locality,occasion,instructions,type) values('$user_id','$name','$mobile','$phone','$email','$dob1','$time','$seats','$cuisine','','','$city','$locality','$occassion','$instruction','bookatable')";
		//echo $sql;exit;
		$res	= $this->db ->setQuery($sql);
		
		$message=trim($name).' Booked a table in your restaurant:';
		$message.='Mobile '.trim($mobile);
		$message.='Time '.trim($time);
		$sendSms=$this->sendSms($message,$restmobile);
		$sendSmsnew=$this->sendSms('New booking received, please check Book A Table','9037045600');
		return "Table booked successfully";
	}
	function AddFeedback($POST)
	{
			$name=addslashes($POST['name']);
		$email=addslashes($POST['email']);
		$phone=addslashes($POST['phone']);
		
		$instruction=addslashes($POST['instruction']);
		
		$date=$this->date;
		
		$sql="insert into feedback(name,email,phone,feedback,date) values('$name','$email','$phone','$instruction','$date')";
		//echo $sql;exit;
		$res	= $this->db ->setQuery($sql);
		return "Feedback sent successfully";
	}
	
	function AddContactus($POST)
	{
		$name=addslashes($POST['name']);
		$email=addslashes($POST['email']);
		$phone=addslashes($POST['phone']);
		$department=addslashes($POST['department']);
		$comments=addslashes($POST['comments']);
		$date=$this->date;
		
		$sql="insert into contact(name,mobile,email,department,comments,date) values('$name','$phone','$email','$department','$comments','$date')";
		$res	= $this->db ->setQuery($sql);
		return "Your contact details sent successfully, yummybay admin will contact you soon";
	}
	function getReviewbyId($order_id)
	{
		$sql="select * from customer_review where order_id='$order_id' and review_status='Active'";
		//echo $sql;exit;
		$res	=$this->db->readValue($sql);
		return $res;
	}
	function getAllpremiumRestaurants()
	{
		if(isset($_SESSION['state_id']))
		$state_id=$_SESSION['state_id'];
		else
		$state_id=13;
		
		$sql="select * from user where type='Hotel' and status='Active' and rest_type='Premium' and state='$state_id' ";
		$res	=$this->db->readValues($sql);
		return $res;
	}
	function getAllReviews($user_id)
	{
	
		$sql="select customer_review.* from customer_review left join user on customer_review.rest_id=user.user_id where customer_review.rest_id='$user_id' and customer_review.review_status='Active'";
		$res	=$this->db->readValues($sql);
		return $res;
	}
	function postReview($POST,$user_id)
	{
	
		$date=$this->date;
		list($date1,$time) = explode(" ",$date);
		$yummyuser_id=$_SESSION['yummyuserID'];
		$review=addslashes($POST['review']);
		
		$sql="insert into customer_review(rest_id,user_id,review,date,time,review_status) values('$user_id','$yummyuser_id','$review','$date1','$time','Active')";
		//echo $sql;
		//exit;
		$res	= $this->db ->setQuery($sql);
		
		$sql1="select max(review_id) as review_id from customer_review";
		$res1	=$this->db->readValue($sql1);
		
		$review_id=$res1['review_id'];
		
		$message="New review received in yummybay.com";
		
		$rest=$this->generalObj->getGeneralById('user',array('user_id'=>$user_id));
		
		$mobile=$rest['mobile'];
		
		$sendsmstoRestaurant=$this->sendSms($message,$mobile);
		
		return $review_id;
	}
	
	function existsInFavourite($order_id)
	{
		$sql="select * from favourite_order where order_id='$order_id'";
		$res	=$this->db->readValue($sql);
		return $res;
	}
	function chkVoucherCode($vouchercode)
	{
		$sql="select * from voucher_code where voucher_code='$vouchercode'";
		$res	=$this->db->readValue($sql);
		return $res;
	}
	function chkVoucherCodeTime($vouchercode)
	{
		$date=$this->date;
		
		$sql="select * from voucher_code where voucher_code='$vouchercode' and (datefrom<='$date' and dateto>='$date')";
		
		$res	=$this->db->readValue($sql);
		return $res;
	}
	function getUserReviewCount($user_id)
	{
		$sql="select * from customer_review where user_id='$user_id' and review_status='Active'";
		$res	=$this->db->numberOfRecords($sql);
		return $res;		
	}
	function getAllcorporateRestaurant($locality)
	{
		$sql="select user.name,user.email,user.mobile from user left join rest_includes on user.user_id=rest_includes.user_id left join rest_categories on rest_includes.rest_category_id=rest_categories.rest_category_id where user.district='$locality' and user.type='Hotel' and rest_categories.rest_category='Corporate'";
		$res	=$this->db->readValues($sql);
		return $res;
	}
	function addReference($POST,$user_id)
	{
		$name='';
		$email='';
		$location='';
		$mobile='';
		$selection	=$POST['selection'];
		
		if($selection=='friend')
		{
			//$name		=$POST['name'];
			//$mobile		=$POST['mobile'];
		}
		else
		{
			$name		=$POST['restname'];
			$mobile		=$POST['mobno'];
		}
		$email		=$POST['email'];
		$location	=$POST['location'];
		$date		=$this->date;
		
		$sql="insert into refer_friend(user_id,name,email,mobile,location,type,date) values('$user_id','$name','$email','$mobile','$location','$selection','$date')";
		echo $sql;exit;
		$res	= $this->db ->setQuery($sql);
		return "Sent Successfully";
	}
	function SendEnquiry($POST)
	{
		$name=addslashes($POST['name']);
		$email=addslashes($POST['email']);
		$mobile=addslashes($POST['mobile']);
		$enquiry=addslashes($POST['enquiry']);
		$date		=$this->date;
		
		$sql="insert into advertisement_enquiry(name,email,mobile,enquiry,date) values('$name','$email','$mobile','$enquiry','$date')";
		
		$res	= $this->db ->setQuery($sql);
		return "Advertisement enquiry sent Successfully, yummybay will contact you soon";
	}
	 function getAllrefercnt()
	 {
	 	$sql="select * from refer_friend where type='friend'";
		//echo $sql;exit;
		$res	= $this->db ->readValues($sql);
		$cnt=count($res);
		return $cnt;
	 }
	 function getAllreferFriends($Offset='',$RowsPerPage='')
	 {
	 	$sql="select * from refer_friend where type='friend'";
		//echo $sql;exit;
		if(trim($Offset)!="" && trim($RowsPerPage)!="")
			{	$sql .=	" LIMIT $Offset,$RowsPerPage";	}
		$res	= $this ->db ->readValues($sql);
		return $res;
	 }
	 function cakesCartGet()
	{
		$shop_id=$_SESSION['shop_id'];
		$user_id=$_SESSION['rest_id'];
		
		$sql="select * from cake_cart left join rest_cakes on cake_cart.rest_cake_id=rest_cakes.rest_cake_id where cake_cart.shop_id='$shop_id' and rest_cakes.user_id='$user_id' ";
		
		$res	=	$this->db->readValues($sql);
		
		return $res;
	}
	function CakeOrderDetails($order_id)
	{
		$sql	  = "select * from (cake_order_details left join rest_cakes on cake_order_details.rest_cake_id=rest_cakes.rest_cake_id) left join orders on cake_order_details.order_id = orders.order_id where cake_order_details.order_id='$order_id'";
		$res	  = $this->db ->readValues($sql);
		
		return $res;
	}
	function sendComplaint($order_id)
	{
		$user_id=$_SESSION['yummyuserID'];
		$message="Complaint with the order ".trim($order_id)." user ID is ".$user_id;
		
		$Complaint=$this->sendSms($message,'9037045600');
		
		return "Your Complaint registered successfully";
	}
		function sendVoucherCode($voucher,$mobilenumber)
	{
			$message="Voucher Code-".trim($voucher)."";
			$sendSms=$this->sendSms($message,$mobilenumber);
		return "Message sent successfully";
	}
	//--------New Rating------------------------
	
	function rateServicenew($value,$order_id)
	{
		$sql="select * from rest_rating where order_id='$order_id'";
		$res	=$this->db->readValue($sql);
		if($res)
		{
			$sql1="update rest_rating set service='$value' where order_id='$order_id'";
			$res1	= $this->db->setQuery($sql1);
		}
		else
		{
			$sql2="insert into rest_rating(order_id,service) values('$order_id','$value')";
			$res2	= $this->db->setQuery($sql2);
		}
		
		//----new rating -------------------
		
		$sqluserid = mysql_query("SELECT user_id FROM orders WHERE order_id = '$order_id'");
		
		$rows = mysql_fetch_array($sqluserid);
		$ssid=$rows[user_id];
		//-----------rating calculated---------//
		$notrated='';
      
      $getRating=$this->getRating($ssid);
      
      if(!$getRating)
      $notrated='Not yet received rating';
      
      $cntRating=count($getRating);
      
      $service=0;
      $quality=0;
      $delivery=0;
      $serviceRating=0;
      $qualityRating=0;
      $deliveryRating=0;
      $serviceRating1=0;
      $qualityRating1=0;
      $deliveryRating1=0;
      $s=0;
      $d=0;
      $q=0;
      foreach($getRating as $key=>$values3)
      {
       if($values3['service']==0)
       $s++;
       
       if($values3['quality']==0)
       $q++;
       
       if($values3['deliveryTime']==0)
       $d++;
       
       $service+=$values3['service'];
       $quality+=$values3['quality'];
       $delivery+=$values3['deliveryTime'];
      }
      
      if($cntRating>0)
      {
       if($cntRating>$s)
       {
        $serviceRating=$service/($cntRating-$s);
        $serviceRating1=round($serviceRating, 1);
        $serviceRating2=$dubbauserObj->serviceRating2($serviceRating1);
       }
       
       if($cntRating>$q)
       {
        $qualityRating=$quality/($cntRating-$q);
        $qualityRating1=round($qualityRating, 1);
        $qualityRating2=$dubbauserObj->qualityRating2($qualityRating1);
       }
       
       if($cntRating>$d)
       {
        $deliveryRating=$delivery/($cntRating-$d); 
        $deliveryRating1=round($deliveryRating, 1);
        $deliveryRating2=$dubbauserObj->deliveryRating2($deliveryRating1);
        
       }         
}
//--------------------------------------------//

$ssql="update rest_searchtable set rating='$cntRating' where user_id=".$ssid;
		
		
		//---------------------------------
		
		
		return "Service rated successfully";
	}
	function rateQualitynew($value,$order_id)
	{
		$sql="select * from rest_rating where order_id='$order_id'";
		$res	=$this->db->readValue($sql);
		if($res)
		{
			$sql1="update rest_rating set quality='$value' where order_id='$order_id'";
			$res1	= $this->db->setQuery($sql1);
		}
		else
		{
			$sql2="insert into rest_rating(order_id,quality) values('$order_id','$value')";
			$res2	= $this->db->setQuery($sql2);
		}
		return "Quality rated successfully";
	}
	function rateDeliverynew($value,$order_id)
	{
		$sql="select * from rest_rating where order_id='$order_id'";
		$res	=$this->db->readValue($sql);
		if($res)
		{
			$sql1="update rest_rating set deliveryTime ='$value' where order_id='$order_id'";
			$res1	= $this->db->setQuery($sql1);
		}
		else
		{
			$sql2="insert into rest_rating(order_id,deliveryTime) values('$order_id','$value')";
			$res2	= $this->db->setQuery($sql2);
		}
		return "Delivery rated successfully";
	}
	
	//-------------------------sheeba-------------------------
function ratingpic($service)
	{
		switch ($service) 
							{
								 case 1:
        $image='<img src="images1/star-on.png" align="absmiddle" /> <img src="images1/star-off.png" align="absmiddle" /> <img src="images1/star-off.png" align="absmiddle" /> <img src="images1/star-off.png" align="absmiddle" /> <img src="images1/star-off.png" align="absmiddle" /><img src="images1/star-off.png" align="absmiddle" />';
        break;
    case 2:
        $image='<img src="images1/star-on.png" align="absmiddle" /> <img src="images1/star-on.png" align="absmiddle" /> <img src="images1/star-off.png" align="absmiddle" /> <img src="images1/star-off.png" align="absmiddle" /> <img src="images1/star-off.png" align="absmiddle" /><img src="images1/star-off.png" align="absmiddle" />';
        break;
    case 3:
        $image='<img src="images1/star-on.png" align="absmiddle" /> <img src="images1/star-on.png" align="absmiddle" /> <img src="images1/star-on.png" align="absmiddle" /><img src="images1/star-off.png" align="absmiddle" /> <img src="images1/star-off.png" align="absmiddle" /> <img src="images1/star-off.png" align="absmiddle" />';
        break;
	case 4:
        $image='<img src="images1/star-on.png" align="absmiddle" /> <img src="images1/star-on.png" align="absmiddle" /> <img src="images1/star-on.png" align="absmiddle" /> <img src="images1/star-on.png" align="absmiddle" /> <img src="images1/star-off.png" align="absmiddle" /><img src="images1/star-off.png" align="absmiddle" />';
        break;
	case 5:
        $image='<images1/star-on.png" align="absmiddle" /> <img src="images1/star-on.png" align="absmiddle" /> <img src="images1/star-on.png" align="absmiddle" /> <img src="images1/star-on.png" align="absmiddle" /> <img src="images1/star-on.png" align="absmiddle" /><img src="images1/star-off.png" align="absmiddle" />';
        break;
		}
		return $image;
	}
	//-------------------------------Sibu----------------------------------------------
		function addgmailUser($POST)
	{
		/*$name=addslashes($POST['namePerson/first']);
		$email=addslashes($POST['contact/email']);
		$country=addslashes($POST['contact/country/home']);*/
		$gender='';
	    $address='';
		$state='';
		$new='';
		$country=$this->country;
		
		if($country=='IN')
		{
			$country=105;
		}
		else
		{
			$country=000;
		}		
		
		if(isset($POST['newsletter']))
		{
			$newsletter=addslashes($POST['newsletter']);
			$new='Subscriber';
		}
		else
		{
			$new='Unsubscriber';
		}
		$randomNumber=$this->randomNumber();
		
		$message="YOUR SIX DIGIT CONFIRMATION CODE IS '$randomNumber'.PLEASE ENTER SAME IN YOUR YUMMYBAY REGISTRATION PAGE AND CLICK CONFIRM FOR VERIFYING CONTACT NUMBER";
		//echo $messgae;
		
		if(isset($POST['terms']))
		$terms=addslashes($POST['terms']);
		
		
		$reg_date=$this->date;
		list($d,$m,$y)=explode("/",$dob);
			
		
		$sql="insert into user(name,email,password,mobile,phone,address,address2,address3,pin,rest_contacts,city,country,description,delivery_area,register_date,list_type,type,status,verification,menu_url) values('$this->name','$this->email','$password','$mobile','$phone','$address','$address2','$address3','$pin','','$city','$country','','','$reg_date','Online Ordering','User','Active','','')";
		
		$res	= $this->db->setQuery($sql);
		
		$sql1="select max(user_id) as id from user";
		$res1	= $this->db ->readValue($sql1);
		$id=$res1['id'];
		
		if($res)
		{
			//echo 'success';exit;
			$_SESSION['yummyuserID']=$id;
			$_SESSION['yummyuserNAME']=$name;
			$_SESSION['yummytype']='User';
			$_SESSION['yummyemail']=$email;
			
			$IPtrackinguser=$this->IPtrackinguser();
		}
		//echo 'failure';exit;
		//$sendSms=$this->sendSms($message,$mobile);
		
		$sendSignupMail=$this->sendSignupMail($POST,$randomNumber);
		
		
		return "User registered successfully";
	}
	
	function getgmaildetails($gmail)
	{
	$sql="SELECT * FROM user WHERE email='$gmail'";
	$result=mysql_query($sql);
	while($row=mysql_fetch_array($result))
		{			
			$_SESSION['yummyuserID']=$row['user_id'];
			$_SESSION['yummyuserNAME']=$row['name'];
			$_SESSION['yummytype']='User';
			$_SESSION['yummyemail']=$row['email'];
			
			$IPtrackinguser=$this->IPtrackinguser();
		}	
	
	
	}
	
			function addyahooUser($POST)
	{
		/*$name=addslashes($POST['namePerson/first']);
		$email=addslashes($POST['contact/email']);
		$country=addslashes($POST['contact/country/home']);*/
		
	    $address='';
		$state='';
		$new='';
		if($country=='IN')
		{
			$country=105;
		}
		else
		{
			$country=000;
		}		
		$gender=$this->gender;
		$name=$this->name;
		if($gender==M)
		{
		$gender='Male';
		}
		else
		{		
		$gender='Female';
		}
		
		if(isset($POST['newsletter']))
		{
			$newsletter=addslashes($POST['newsletter']);
			$new='Subscriber';
		}
		else
		{
			$new='Unsubscriber';
		}
		$randomNumber=$this->randomNumber();
		
		$message="YOUR SIX DIGIT CONFIRMATION CODE IS '$randomNumber'.PLEASE ENTER SAME IN YOUR YUMMYBAY REGISTRATION PAGE AND CLICK CONFIRM FOR VERIFYING CONTACT NUMBER";
		//echo $messgae;
		
		if(isset($POST['terms']))
		$terms=addslashes($POST['terms']);
		
		
		$reg_date=$this->date;
		list($d,$m,$y)=explode("/",$dob);
			
		
		$sql="insert into user(name,email,gender,password,mobile,phone,address,address2,address3,pin,rest_contacts,city,country,description,delivery_area,register_date,list_type,type,status,verification,menu_url) values('$this->name','$this->email','$gender','$password','$mobile','$phone','$address','$address2','$address3','$pin','','$city','$country','','','$reg_date','Online Ordering','User','Active','','')";
		
		$res	= $this->db->setQuery($sql);
		
		$sql1="select max(user_id) as id from user";
		$res1	= $this->db ->readValue($sql1);
		$id=$res1['id'];
		
		if($res)
		{
			//echo 'success';exit;
			echo $_SESSION['yummyuserID']=$id;
			echo $_SESSION['yummyuserNAME']=$name;
			echo $_SESSION['yummytype']='User';
			echo $_SESSION['yummyemail']=$email;
						
			$IPtrackinguser=$this->IPtrackinguser();
		}
		//echo 'failure';exit;
		//$sendSms=$this->sendSms($message,$mobile);
		
		$sendSignupMail=$this->sendSignupMail($POST,$randomNumber);
		
		
		return "User registered successfully";
	}
	
	function getyahoodetails($yahoo)
	{
	$sql="SELECT * FROM user WHERE email='$yahoo'";
	$result=mysql_query($sql);
	while($row=mysql_fetch_array($result))
		{			
			$_SESSION['yummyuserID']=$row['user_id'];
			$_SESSION['yummyuserNAME']=$row['name'];
			$_SESSION['yummytype']='User';
			$_SESSION['yummyemail']=$row['email'];
			
			$IPtrackinguser=$this->IPtrackinguser();
		}	
	
	
	}
	
//---------------------------------------------------------------	
}

function redirect($page) {

  if(headers_sent()) {

    echo "<script language=\"Javascript\">window.location.href='$page';</script>";

    exit;

  } else {

    //header("Location:$page");
	echo "<script>location.href='$page'</script>";
	exit;
  }

}
ob_end_flush();
?>