<?php
include('includes/session.php');
include('includes/config.php');
date_default_timezone_set('Asia/Kolkata');
if(isset($_POST['submit']))
{
if(! get_magic_quotes_gpc())
{
$uid=$_SESSION['id'];	
$title=strtoupper($_POST['title']);
$department=strtoupper($_POST['department']);
$start=($_POST['start']);
//$end=($_POST['end']);
$hall=strtoupper($_POST['hall']);
$session =strtoupper($_POST['session']);
}
else
{
$uid=$_SESSION['id'];	
$title=strtoupper($_POST['title']);
$department=strtoupper($_POST['department']);
$start=($_POST['start']);
//$end=($_POST['end']);
$hall=strtoupper($_POST['hall']);
$session = ($_POST['session']);
			 }
$date=date("d/m/Y");
$start_date_timestamp = strtotime($start);
//$end_date_timestamp = strtotime($end);
$new_start = date('Y-m-d H:i:s', $start_date_timestamp);   	
//$new_end = date('Y-m-d H:i:s', $end_date_timestamp);
	
$query1= "SELECT * from users WHERE id='$uid'";
$result= mysqli_query($conn,$query1);
while($row = mysqli_fetch_array($result))
{
	$uname= $row['fullName'];
	$uemail= $row['userEmail'];
}
	
$query2 = "SELECT * FROM `eventbooking`";
$result2 = mysqli_query($conn, $query2) or die(mysqli_error($conn));
while($row2 = mysqli_fetch_array($result2))
{
	$dbstart= $row2['Start'];
	//$dbend= $row2['End'];
	$dbhall= $row2['Hall'];
	$dbsession= $row2['session'];
	
	}
	
	if($session=="FULLDAY") 
	{
		if( $new_start == $dbstart && $dbhall == $hall  && ($dbsession == "AFTERNOON" || $dbsession == "FORENOON" || $dbsession == "FULLDAY")) 
		{
		echo"<script>alert('Event Booked Already. Try Some other date.');</script>";
		}
		else {
	
   
//Insert Query of SQL
$query="INSERT INTO eventbooking ". "(ebNo,title,Department,Start,session,Hall,userId,userName,userEmail,Date)". " values('1','$title','$department','$new_start','$session','$hall','$uid','$uname','$uemail','$date')";
if (mysqli_query($conn , $query)) 
{
    $last_id = mysqli_insert_id($conn);
    $in="EB-" . $last_id;
	$sql1="UPDATE eventbooking SET ebNo='$in' WHERE id='$last_id'";
	$retval=mysqli_query($conn, $sql1);
	echo"<script>alert('Hall Booking is Successful. Thank You !');</script>";

}
	else
	{
		echo"<script>alert('Error Try after Sometime or Contact Admin');</script>";
	}
}
	}
	
	if($session=="FORENOON") 
	{
		if( $new_start == $dbstart && $dbhall == $hall  && ($dbsession == "FULLDAY" || $dbsession == "FORENOON")) 
		{
		echo"<script>alert('Event Booked Already. Try Some other date.');</script>";
		}
		else {
	
   
//Insert Query of SQL
$query="INSERT INTO eventbooking ". "(ebNo,title,Department,Start,session,Hall,userId,userName,userEmail,Date)". " values('1','$title','$department','$new_start','$session','$hall','$uid','$uname','$uemail','$date')";
if (mysqli_query($conn , $query)) 
{
    $last_id = mysqli_insert_id($conn);
    $in="EB-" . $last_id;
	$sql1="UPDATE eventbooking SET ebNo='$in' WHERE id='$last_id'";
	$retval=mysqli_query($conn, $sql1);
	echo"<script>alert('Hall Booking is Successful. Thank You !');</script>";

}
	else{
		echo"<script>alert('Error Try after Sometime or Contact Admin');</script>";
	}
}
	}
	
	if($session=="AFTERNOON") 
	{
		if( $new_start == $dbstart && $dbhall == $hall  && ($dbsession == "FULLDAY" || $dbsession == "AFTERNOON")) 
		{
		echo"<script>alert('Event Booked Already. Try Some other date.');</script>";
		}
		else {
	
   
//Insert Query of SQL
$query="INSERT INTO eventbooking ". "(ebNo,title,Department,Start,session,Hall,userId,userName,userEmail,Date)". " values('1','$title','$department','$new_start','$session','$hall','$uid','$uname','$uemail','$date')";
if (mysqli_query($conn , $query)) 
{
    $last_id = mysqli_insert_id($conn);
    $in="EB-" . $last_id;
	$sql1="UPDATE eventbooking SET ebNo='$in' WHERE id='$last_id'";
	$retval=mysqli_query($conn, $sql1);
	echo"<script>alert('Hall Booking is Successful. Thank You !');</script>";

}
	else{
		echo"<script>alert('Error Try after Sometime or Contact Admin');</script>";
	}
}
	}
}
?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="Dashboard">
    <meta name="keyword" content="Dashboard, Bootstrap, Admin, Template, Theme, Responsive, Fluid, Retina">

    <title>AVIT | User Register Complaint</title>

    <!-- Bootstrap core CSS -->
    <link href="assets/css/bootstrap.css" rel="stylesheet">
    <link href="assets/css/style.css" rel="stylesheet">
    <link href="assets/css/nav.css" rel="stylesheet">
    <!--external css-->
    <link href="assets/font-awesome/css/font-awesome.css" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" href="assets/js/bootstrap-datepicker/css/datepicker.css" />
    <link rel="stylesheet" type="text/css" href="assets/js/bootstrap-daterangepicker/daterangepicker.css" />
    <link href="assets/css/style.css" rel="stylesheet">
    <link href="assets/css/style-responsive.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
    	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/locale/nl.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
    <style>
		label{
			font-weight: bold;
		}
		input{
			text-transform: uppercase;
		}
	#tabledesign {
/*	font-family: 'Montserrat', sans-serif;*/
  border-collapse: collapse;
  width: 100%;
}

#tabledesign td, #tabledesign th {
  border: 1px solid #ddd;
  padding: 8px;
	font-size: 12px;
	font-weight: bold;
}

#tabledesign tr:nth-child(even){background-color: none;}

#tabledesign tr:hover {background-color: #ddd;}

#tabledesign th {
  padding-top: 12px;
  padding-bottom: 12px;
  text-align: left;
  background-color: #081F3F !important;
  color: white !important;
}
		 /*Srcoll Bar*/

	/* Scroll width */
::-webkit-scrollbar {
  width: 5px;
}

/* Track */
::-webkit-scrollbar-track {
  background: #f1f1f1; 
}
 
/* Handle */
::-webkit-scrollbar-thumb {
  background: #002147; 
}

/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
  background: #002147; 
}

/*End*/

	  </style>
	  <script>

	  </script>
	  <script>
		  var defaults = {
	calendarWeeks: true,
	showClear: true,
	showClose: true,
	allowInputToggle: true,
	useCurrent: true,
	ignoreReadonly: true,
	minDate: new Date(),
	toolbarPlacement: 'top',
	locale: 'en',
	icons: {
		time: 'fa fa-clock-o',
		date: 'fa fa-calendar',
		up: 'fa fa-angle-up',
		down: 'fa fa-angle-down',
		previous: 'fa fa-angle-left',
		next: 'fa fa-angle-right',
		today: 'fa fa-dot-circle-o',
		clear: 'fa fa-trash',
		close: 'fa fa-times'
	}
};

$(function() {
	var optionsDatetime = $.extend({}, defaults, {format:'DD-MM-YYYY HH:mm'});
	var optionsDate = $.extend({}, defaults, {format:'DD-MM-YYYY'});
	var optionsTime = $.extend({}, defaults, {format:'HH:mm'});
	
	$('.datepicker').datetimepicker(optionsDate);
	$('.timepicker').datetimepicker(optionsTime);
	$('.datetimepicker').datetimepicker(optionsDate);
	//$('.datetimepicker').datetimepicker(optionsDatetime);
});
	  </script>
	    <script type="text/javascript"> 
	 function ajaxCall() {
    $.ajax({
        url: "eventbook/ajax.php", 
        success: (function (result) {
            $("#div1").html(result);
        })
    })
};

ajaxCall(); // To output when the page loads
setInterval(ajaxCall, (1000)); 
</script>
	  
  </head>

  <body>

  <section id="container" >
     <?php include("includes/header.php");?>
      <?php include("includes/sidebar.php");?>
      <section id="main-content">
          <section class="wrapper">
          	<h3 align="center">Event Hall Booking Status</h3>
          	
          	<!-- BASIC FORM ELEMENTS -->
          	<div class="row mt">
          		<div class="col-lg-12">
                  	<div class="col-sm-12 form-panel">

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" enctype="multipart/form-data" >
<div class="row">
<div class="col-sm-12">
<div id="div1" height="300px" style="height: 470px !important; overflow: auto; "></div>
	</div>

	</div>
</div>
</form>
</div>
</div>  	
		</section>
      </section>
    <?php include("includes/footer.php");?>
  </section>

    <!-- js placed at the end of the document so the pages load faster -->
    <script src="assets/js/jquery.js"></script>
    <script src="assets/js/bootstrap.min.js"></script>
    <script class="include" type="text/javascript" src="assets/js/jquery.dcjqaccordion.2.7.js"></script>
    <script src="assets/js/jquery.scrollTo.min.js"></script>
    <script src="assets/js/jquery.nicescroll.js" type="text/javascript"></script>


    <!--common script for all pages-->
    <script src="assets/js/common-scripts.js"></script>

    <!--script for this page-->
    <script src="assets/js/jquery-ui-1.9.2.custom.min.js"></script>

	<!--custom switch-->
	<script src="assets/js/bootstrap-switch.js"></script>
	
	<!--custom tagsinput-->
	<script src="assets/js/jquery.tagsinput.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/locale/nl.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
	
	
	<script type="text/javascript" src="assets/js/bootstrap-inputmask/bootstrap-inputmask.min.js"></script>
	
	
	<script src="assets/js/form-component.js"></script>    
    
    
  <script>
      //custom select box

      $(function(){
          $('select.styled').customSelect();
      });

  </script>

  </body>
</html>
