<!DOCTYPE html>
<html lang="en-US">
<?php 
include('common/header.php');
$errMsg = '';
$succMsg = '';
if(isset($_POST['register_from']) && $_POST['register_from'] == 'listener'){
	$dateD = date('Y-m-d H:i:s');
	$email = $_POST['email'];
	
	$validateEmailQ = "SELECT * FROM tbl_user WHERE email = '$email' AND status = 1";
	$userList = $conn->execute($validateEmailQ,'select');
	if(isset($userList->id) && $userList->id > 0){
		$errMsg = "Email address already exist.";	
	}else{
		$userInsertQ = "INSERT INTO `tbl_user` (`name`, `email`, `emirates`, `nationality`, `type`, `mobile_no`, `where_did_hear`, `status`, `created`) VALUES ('".$_POST['name']."', '".$_POST['email']."', '".$_POST['emirate']."', '".$_POST['nationality']."', '1', '971".$_POST['contact1'].$_POST['contact']."', '".$_POST['where_did_hear']."', '1', '$dateD')";
		$userId = $conn->execute($userInsertQ,'insert');
		$restNameArr = $_POST['cat_val'];
		foreach($restNameArr as $key => $value){
			if($value != ''){
				$validateRestQ = "SELECT * FROM tbl_restaurant WHERE name = '$value' AND status = 1";
				$restaurantData = $conn->execute($validateRestQ,'select');
				
				$catId = $key;
				if(isset($restaurantData->id) && $restaurantData->id > 0){
					$restId = $restaurantData->id;
				}else{
					$insertQuery = "INSERT INTO `tbl_restaurant` (`name`, `created`,`added_by`, `status`) VALUES ('$value', '".$dateD."','".$userId."', '1')";
					$restId = $conn->execute($insertQuery,'insert');
				}
				$nominateQuery =  "INSERT INTO `tbl_nominate` (`category_id`, `restaurant_id`, `user_id`, `status`, `created`) VALUES ('$catId', '$restId', '$userId', '1', '$dateD')";
				$nominateId = $conn->execute($nominateQuery,'insert');
			}
		}
	$succMsg = "Thank You for your nomination. We will get in touch with you shortly.";		
	}
		
		
				
	
}

if(isset($_POST['register_from']) && $_POST['register_from'] == 'owner'){
	
	$dateD = date('Y-m-d H:i:s');
	$email = $_POST['email'];
	
	$validateEmailQ = "SELECT * FROM tbl_user WHERE email = '$email' AND status = 1";
	$userList = $conn->execute($validateEmailQ,'select');
	if(isset($userList->id) && $userList->id > 0){
		$errMsg = "Email address already exist.";	
	}else{
		$userInsertQ = "INSERT INTO `tbl_user` (`name`, `email`, `designation`, `address`, `type`, `mobile_no`, `where_did_hear`, `status`, `created`) VALUES ('".$_POST['name']."', '".$_POST['email']."', '".$_POST['designation']."', '".$_POST['address']."', '2', '".$_POST['contact']."', '".$_POST['where_did_hear']."', '1', '$dateD')";
		$userId = $conn->execute($userInsertQ,'insert');
		
		$restNameArr = $_POST['rest_name'];
		foreach($restNameArr as $key => $value){
			
			if($value != ''){
				$validateRestQ = "SELECT * FROM tbl_restaurant WHERE name = '$value' AND status = 1";
				$restaurantData = $conn->execute($validateRestQ,'select');
				
				$catId = $_POST['category'][$key];
				if(isset($restaurantData->id) && $restaurantData->id > 0){
					$restId = $restaurantData->id;
				}else{
					$insertQuery = "INSERT INTO `tbl_restaurant` (`name`, `created`,`added_by`, `status`) VALUES ('$value', '".$dateD."','".$userId."', '1')";
					$restId = $conn->execute($insertQuery,'insert');
				}
				$nominateQuery =  "INSERT INTO `tbl_nominate` (`category_id`, `restaurant_id`, `user_id`, `status`, `created`) VALUES ('$catId', '$restId', '$userId', '1', '$dateD')";
				$nominateId = $conn->execute($nominateQuery,'insert');
			}
		}
				
	$succMsg = "Thank You for your nomination. We will get in touch with you shortly.";	
	}
		
}

$catList = $conn->execute('SELECT * FROM tbl_category WHERE 1=1 AND status = 1');
$restaurantList = $conn->execute('SELECT name,id FROM tbl_restaurant WHERE 1=1 AND status = 1');
?>
<style>
input::-webkit-calendar-picker-indicator {
 background-color: inherit;
}
.result-disp {
	position: absolute;
	width: 100%;
	max-width: 870px;
	cursor: pointer;
	overflow-y: auto;
	max-height: 400px;
	box-sizing: border-box;
	z-index: 1001;
}
.link-class:hover {
	background-color: #fff;
}
.link-class {
	margin-left: 0 !important;
}
.text-muted {
	color: #fff !important;
}
</style>
<script>

$(document).ready(function(){
	$.ajaxSetup({ cache: false });
 
 $(".emailid").blur(function(){
    var email_id  = $(this).val();
	$.ajax({
		type:"POST",
		url : "<?php echo SITE_URL?>validate-email.php",
		data : "email_id="+email_id,
		async: false,
		success : function(response) {
			if(response != ''){
			alert(response);
			$(this).focus();
			return false;
			}
		},error: function() {
		}
	});
}); 

});
function validateQty(event) {
	  var key = window.event ? event.keyCode : event.which;
	  if (event.keyCode == 8 || event.keyCode == 46 || event.keyCode == 37 || event.keyCode == 39) {
		return true;
	  } else if (key < 48 || key > 57) {
		return false;
	  } else return true;
	}
</script>

<div class="container-wrapper">
  <div class="page-bg" align="center" style=" background-image: url(images/bg-pizza.jpg); " ></div>
  <div id="container">
    <div class="page-title-wrapper">
      <div class="page-title-outher">
        <div class="page-title-inner">
          <h1 class="page-title">NOMINATE YOUR FAVORITE RESTAURANT</h1>
          <div class="clear"></div>
        </div>
        <div class="clear"></div>
      </div>
    </div>
    <div class="clear"></div>
    <div class="page-wrapper">
      <div class="offer-menu-wrapper">
        <?php if(isset($succMsg) && $succMsg != ''){ ?>
        <div class="alert alert-success"> <strong>Success!</strong> <?php echo $succMsg;?> </div>
        <?php }?>
        <?php if(isset($errMsg) && $errMsg != ''){ ?>
        <div class="alert alert-danger"> <strong>Error!</strong> <?php echo $errMsg;?> </div>
        <?php }?>
        <script>
function checkCheckBoxListener(){
	if (document.getElementById("agree1").checked == false) 
	{
		alert ('Please agree our terms and conditions	!');
		return false;
	} else {    
		return true;
	}
	
}
function checkCheckBoxOwner(){
	if (document.getElementById("agree2").checked == false) 
	{
		alert ('Please agree our terms and conditions	!');
		return false;
	} else {    
		return true;
	}
	
}
</script>
        <ul id="filters" class="single-offer-category-filter option-set" data-option-key="filter" >
          <li class="filter-cat" style="margin-left:40px;"><a class="selected"  href="#filter" data-option-value=".cat1"><img src="images/menu-icon1.png" style="margin-right:10px;vertical-align:middle;">I am a Listener</a></li>
          <li class="filter-cat" style="margin-left:20px;"><a  href="#filter" data-option-value=".cat2"><img src="images/menu-icon.png" style="margin-right:10px;vertical-align:middle; ">I am a Restaurant Owner</a></li>
        </ul>
        <div class="offer-menu-items" style="position:relative; overflow:hidden; width:100%; height:auto !important;  ">
          <div class="single-offer-category-item isotope-item cat1">
            <div class="single-offer-item">
              <div class="single-offer-details">
                <form role="form" method="post" name="reused_form_listener" id="reused_form_listener" style="margin-top:15px;" onSubmit="return checkCheckBoxListener();">
                  <div class="row">
                    <div class="col-sm-6 col-md-6 form-group">
                      <label for="name"> Name <span class="red">*</span> </label>
                      <input type="text" class="form-control" required id="name" placeholder="Enter your name" name="name" maxlength="50">
                    </div>
                    <div class="col-sm-6 col-md-6 form-group">
                      <label for="contact"> Mobile Number <span class="red">*</span> </label>
                      <div class="form-item" id="edit-mobile_number-wrapper col-md-12"> <span class="fld_left_contact">
                        <div class="col-md-1 col-sm-2" style="margin-right:0.15%; padding-left:0px; padding-right:0px; width:11%; font-family:'Montserrat', sans-serif;">+971</div>
                        <select name="contact1" id="contact1" class="form-control1 col-md-2 col-sm-3 col-xs-12 " style="margin-right:4%; padding:0px;">
                          <option value="50">50</option>
                          <option value="52">52</option>
                          <option value="55">55</option>
                          <option value="56">56</option>
                          <option value="58">58</option>
                        </select>
                        <!--<input type="text" name="contact1" id="contact1" value="50/55"
                               onblur="if(this.value == ''){ this.value = '50/55'; }" onfocus="if(this.value == '50/55'){ this.value = ''; }"
                               style="  color: rgb(102, 102, 102); width:33px; "  maxlength="2" onKeyPress="return onlyNumbers(event)" />-->&nbsp;
                        <input type="text" onKeyPress="return validateQty(event);"  maxlength="7" name="contact" id="edit-mobile_number" placeholder="Enter your mobile number" required class="form-control1 form-text col-md-8 col-sm-6 col-xs-12 ">
                        </span> </div>
                    </div>
                  </div>
                  <div class="row">
                    <div class="col-sm-6 form-group">
                      <label for="email"> Email Address <span class="red">*</span> </label>
                      <input type="email" class="form-control emailid" id="email1" name="email" placeholder="Enter your  valid email address" required maxlength="50">
                    </div>
                    <div class="col-sm-6 form-group">
                      <label for="emirate"> Emirate <span class="red">*</span> </label>
                      <select class="form-control" name="emirate" id="emirate">
                        <option value="Abu Dhabi">Abu Dhabi</option>
                        <option value="Dubai" >Dubai</option>
                        <option value="Sharjah">Sharjah</option>
                        <option value="Ajman">Ajman</option>
                        <option value="Fujairah" >Fujairah</option>
                        <option value="Ras Al Khaimah">Ras Al Khaimah</option>
                        <option value="Umm Al Quwain">Umm Al Quwain </option>
                      </select>
                    </div>
                  </div>
                  <div class="row">
                    <div class="col-sm-6 form-group">
                      <label for="nationality"> Nationality <span class="red">*</span> </label>
                      <select class="form-control" id="nationality" name="nationality">
                        <?php foreach($countryArray as $country){ ?>
                        <option value="<?php echo $country;?>" <?php if($userDetail->nationality == $country){ echo 'selected="selected"';}?> ><?php echo $country;?></option>
                        <?php } ?>
                      </select>
                    </div>
                    <div class="col-sm-6 form-group">
                      <label for="where_did_hear"> Where did you hear about us? <span class="red">*</span> </label>
                      <select class="form-control" name="where_did_hear" id="where_did_hear">
                        <option value="Radio">Radio</option>
                        <option value="Website">Website </option>
                        <option value="Social Media">Social Media </option>
                        <option value="Google Search">Google Search </option>
                        <option value="SMS">SMS </option>
                        <option value="WhatsApp">WhatsApp </option>
                        <option value="From a Friend">From a Friend </option>
                        <option value="Others">Others </option>
                      </select>
                    </div>
                  </div>
                  <div class="row">
                    <div class="col-sm-6 col-md-6 col-xs-6 form-group">
                      <label for="name">Category <span class="red">*</span> </label>
                      <ul>
                        <?php foreach($catList as $cat){?>
                        <div class="Header--wrapper">
                          <div class="Header--start-small">
                            <li style=" font-weight:bold; margin-left:30px;font-family: 'Montserrat', sans-serif;"><?php echo $cat->name?></li>
                          </div>
                          <div class="Arrow"></div>
                        </div>
                        <?php } ?>
                      </ul>
                    </div>
                    <div class="col-sm-6 col-md-6 col-xs-6 form-group rest">
                      <label for="name "> Restaurant Name </label>
                      <?php foreach($catList as $cat){?>
                      <input type="text" class="form-control" autocomplete="off" list="cat_val_list_2" id="cat_val<?php echo $cat->id?>" name="cat_val[<?php echo $cat->id?>]" maxlength="50" placeholder="Enter restaurant name" style="margin-bottom:6px;">
                      <?php } ?>
                    </div>
                  </div>
                  <div class="row">
                    <div class="col-sm-8 col-md-8 col-xs-8 form-group" style="text-transform:none;  color:#000; font-size:12px; font-weight:600;font-family: 'Montserrat', sans-serif;">
                      <input type="checkbox" name="agree" required id="agree1"  />
                      <span class="red">*</span> I have read and agree to the <a href="#" style="text-decoration:underline;font-family: 'Montserrat', sans-serif; ">Terms and Conditions</a> </div>
                    <div class="col-sm-4 col-md-4 col-xs-4 form-group rest">
                      <input type="hidden" name="register_from" value="listener" id="register_from" />
                      <button type="submit" class="btn btn-lg btn-success btn-block" id="btnContactUs">REGISTER </button>
                    </div>
                  </div>
                </form>
              </div>
              <div class="clear"></div>
            </div>
          </div>
          <div class="single-offer-category-item isotope-item cat2">
            <div class="single-offer-item" style=" position:relative;">
              <div class="single-offer-details">
                <div class="single-offer-title">
                  <div>
                    <form role="form" method="post" id="reused_form_owner" name="reused_form_owner" style="margin-top:15px;" onSubmit="return checkCheckBoxOwner();">
                      <div class="row ">
                        <div class="col-sm-6 form-group">
                          <label for="category"> Category <span class="red">*</span> </label>
                          <select class="form-control" name="category[]">
                            <?php foreach($catList as $cat){?>
                            <option value="<?php echo $cat->id?>"><?php echo $cat->name?></option>
                            <?php } ?>
                          </select>
                        </div>
                        <div class="col-sm-6 form-group container1" >
                          <label> Restaurant Name<span class="red">*</span> </label>
                          <input class="form-control" required list="cat_val_list_2" placeholder="Enter restaurant name" maxlength="50" name="rest_name[]" >
                        </div>
                      </div>
                      <div class="contents2"> </div>
                      <span>&nbsp;</span> <span style="float:right;"><a href="javascript:void(0);" class="add2" style="font-size:12px; color:#333; text-transform:capitalize; font-weight:bold; font-family: 'Montserrat', sans-serif !important;" ><span style="margin-right:5px; vertical-align:middle; float:left; "><img src="images/add.png"></span>Nominate More</a></span> 
                      <script>
            $(document).ready(function() {
                $(".add2").click(function() {
                    var data = '<div class="row"><div class="col-sm-6 form-group"><label for="email"> Category <span class="red">*</span></label><select class="form-control" name="category[]"><option value="1">Best Biryani</option><option value="2">Best Chinese</option><option value="3">Best Kababs</option><option value="4">Best Fine Dining Indian Restaurant</option><option value="5">Best Thali</option><option value="6">Best Dessert</option><option value="7">Best Arabic Food</option><option value="8">Best Coffee</option><option value="9">Best Chat</option></select></div><div class="col-sm-6 form-group"><label for="email"> Restaurant Name <span class="red">*</span> </label> <span class="rem2" ><a href="javascript:void(0);" ><img src="images/Close.png" style="float:right; margin-right:3px;"></a></span><input class=" form-control" maxlength="50" placeholder="Enter restaurant name" name="rest_name[]" list="cat_val_list_2"></div></div>';
					$(".contents2").append(data);
                });
            });

$('.contents2').on('click', '.rem2', function() {
  $(this).parent("div").parent("div").remove();
});
</script>
                      <div class="row">
                        <div class="col-sm-6 col-md-6 form-group">
                          <label for="name">Name <span class="red">*</span> </label>
                          <input type="text" class="form-control" required id="name" placeholder="Enter your name" name="name" maxlength="50">
                        </div>
                        <div class="col-sm-6 form-group">
                          <label for="contact"> Contact Number <span class="red">*</span> </label>
                          <input type="text" class="form-control" required id="contact" placeholder="Enter your contact number" name="contact" maxlength="50">
                        </div>
                      </div>
                      <div class="row">
                        <div class="col-sm-6 col-md-6 form-group">
                          <label for="email"> Email ID <span class="red">*</span> </label>
                          <input type="email" class="form-control emailid" required id="email" placeholder="Enter your valid email address" name="email" maxlength="50">
                        </div>
                        <div class="col-sm-6 col-md-6 form-group">
                          <label for="designation"> Designation <span class="red">*</span> </label>
                          <select id="designation" name="designation" class="form-control">
                            <option value="Owner">Owner </option>
                            <option value="Manager">Manager </option>
                          </select>
                        </div>
                      </div>
                      <div class="row">
                        <div class="col-sm-6 form-group">
                          <label for="address"> Office Address <span class="red">*</span> </label>
                          <input type="text" class="form-control" id="address" name="address" placeholder="Enter your office address" required maxlength="50">
                        </div>
                        <div class="col-sm-6 form-group">
                          <label for="where_did_hear"> Where did you hear about us? <span class="red">*</span> </label>
                          <select name="where_did_hear" id="where_did_hear" class="form-control">
                            <option value="Radio">Radio</option>
                            <option value="Website">Website </option>
                            <option value="Social Media">Social Media </option>
                            <option value="Google Search">Google Search </option>
                            <option value="SMS">SMS </option>
                            <option value="WhatsApp">WhatsApp </option>
                            <option value="From a Friend">From a Friend </option>
                            <option value="Others">Others </option>
                          </select>
                        </div>
                      </div>
                      
                      <div class="row">
                        <div class="col-sm-8 form-group" style="text-transform:none;  color:#000; font-size:12px; font-weight:600;font-family: 'Montserrat', sans-serif;">
                         <input type="checkbox" name="agree" required id="agree2"  />
                          <span class="red">*</span> I have read and agree to the <a href="#" style="text-decoration:underline;font-family: 'Montserrat', sans-serif; ">Terms and Conditions</a>
                        </div>
                        <div class="col-sm-4 form-group" >
                          <input type="hidden" name="register_from" value="owner" id="register_from" />
                          <button type="submit" class="btn btn-lg btn-success btn-block" id="btnContactUs">REGISTER </button>
                        </div>
                      </div>
                      
                    </form>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<datalist id="cat_val_list_2">
  <?php  foreach($restaurantList as $restaurant){?>
  <option value="<?php echo $restaurant->name?>"><?php echo $restaurant->name?></option>
  <?php } ?>
</datalist>
<?php include 'common/footer.php';?>
<script type="text/javascript">
function hideSuggestions(id){
	$("#result"+id).html('');
}


</script>