<?php session_start(); ob_start(); ?>

<?php  include 'header.php'; ?>

<?php

if(empty($_SESSION['LOGINID']) && empty($_SESSION['LOGINNM']) ){

	header("Location:index.php");
}


include("user.php");

date_default_timezone_set('Asia/Dhaka');
                    $date_c = date('Y-m-d H:i:s', time());

$c_date=date("Y-m-d");
$c_time=date("H:i:s");
$sub=1;

 if (isset($_POST['submit'])) {
									 $sub = $_POST['sub'];
									 
									$temp_booking_id = $_POST['temp_booking_id'];
									$date = $_POST['date'];
								    $time = $_POST['time'];
									$status = $_POST['status'];
									if($sub==2){
										$mid = $_POST['mid'];
									    
										$sqlupdate = "UPDATE `pr_meetings` SET `date` = '$date', `time` = '$time', `status` = '$status',`updated_at` = '$date_c', `temp_id` = '$temp_booking_id' WHERE `pr_meetings`.`id` = '$mid' ";
										$sqlupdate = mysqli_query($connection, $sqlupdate); 
										$sqlUpdate = "INSERT INTO `activity_log` (`id`, `user`, `activity`, `time`, `temp_id`) VALUES (NULL, '$ad_id', 'update pr meeting date time from edit meeting page', '$date_c','$temp_booking_id')";

									}
									
									if($sub==1){
										
										$sqlinsert = "INSERT INTO `pr_meetings` (`id`, `temp_id`, `date`, `time`, `status`, `added_by`, `added_at`, `updated_at`) VALUES (NULL, '$temp_booking_id', '$date', '$time', '$status', '$ad_id', '$date_c', '$date_c') ";
											   
                                        $sqlinsert = mysqli_query($connection, $sqlinsert); 
									
$sqlUpdate = "INSERT INTO `activity_log` (`id`, `user`, `activity`, `time`, `temp_id`) VALUES (NULL, '$ad_id', 'added pr meeting from add meeting page', '$date_c','$temp_booking_id')";
$sqlUpdate = mysqli_query($connection, $sqlUpdate); 



                                    header("Location:pr_meeting.php?temp_id=".$temp_booking_id);

									}
					
					
					
									  
}


 if (isset($_GET['temp_id'])) {
	 $temp_id=intval($_GET['temp_id']); if($temp_booking_id!=""){$temp_id=$temp_booking_id;}
	 $result = mysqli_query($connection, "SELECT * FROM `pr_meetings` where temp_id='$temp_id' ");
	 $meeting_info = mysqli_fetch_object($result);
	 $mid=$meeting_info->id; 
	 $c_date=$meeting_info->date; 
	 $c_time=$meeting_info->time; 
	 $status=$meeting_info->status; 
	 
	 $result = mysqli_query($connection, "SELECT * FROM `bookings` where id='$temp_id' ");
	 $booking_info = mysqli_fetch_object($result);
	 $booking_id=$booking_info->booking_id; 
	 $name=$booking_info->name; 
	 $sub=2;
	 
 }
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>PR Meeting Schedule</title>
    <!-- ================= Favicon ================== -->
    <!-- Standard -->
    <link rel="shortcut icon" href="http://placehold.it/64.png/000/fff">
    <!-- Retina iPad Touch Icon-->
    <link rel="apple-touch-icon" sizes="144x144" href="http://placehold.it/144.png/000/fff">
    <!-- Retina iPhone Touch Icon-->
    <link rel="apple-touch-icon" sizes="114x114" href="http://placehold.it/114.png/000/fff">
    <!-- Standard iPad Touch Icon-->
    <link rel="apple-touch-icon" sizes="72x72" href="http://placehold.it/72.png/000/fff">
    <!-- Standard iPhone Touch Icon-->
    <link rel="apple-touch-icon" sizes="57x57" href="http://placehold.it/57.png/000/fff">
    <!-- Styles -->
     <link href="assets/css/lib/data-table/buttons.bootstrap.min.css" rel="stylesheet" />
    <link href="assets/css/lib/font-awesome.min.css" rel="stylesheet">
    <link href="assets/css/lib/themify-icons.css" rel="stylesheet">
    <link href="assets/css/lib/owl.carousel.min.css" rel="stylesheet" />
    <link href="assets/css/lib/owl.theme.default.min.css" rel="stylesheet" />
    <link href="assets/css/lib/weather-icons.css" rel="stylesheet" />
    <link href="assets/css/lib/menubar/sidebar.css" rel="stylesheet">
    <link href="assets/css/lib/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/lib/unix.css" rel="stylesheet">
    <link href="assets/css/style.css" rel="stylesheet">
	   <link href="assets/css/lib/select2/select2.min.css" rel="stylesheet">
</head>

<body>

    
	
	  <?php include("sidebar.php"); ?>
	
	
    <!-- /# sidebar -->
     <?php include("top.php"); ?>
	<!-- /# topebar --> 
	
	
    <div class="content-wrap">
        <div class="main">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-8 p-r-0 title-margin-right">
                        <div class="page-header">
                            <div class="page-title">
                                <h1>Hello, <span>Welcome Here</span></h1>
                            </div>
                        </div>
                    </div>
                    <!-- /# column -->
                    <div class="col-lg-4 p-l-0 title-margin-left">
                        <div class="page-header">
                            <div class="page-title">
                                <ol class="breadcrumb text-right">
                                    <li><a href="#">Dashboard</a></li>
                                    <li class="active">Home</li>
                                </ol>
                            </div>
                        </div>
                    </div>
                    <!-- /# column -->
                </div>
                <!-- /# row -->
                <section id="main-content">
				
				
			
				
				
				
				
				
				<div class="row">
				
				        <div class="col-lg-12">
						
						<div class="panel panel-info m-t-15">
                                            <div class="panel-heading">PR Meeting Schedule</div>
                                            <div class="panel-body">
											
											<?php


	
                                  






											?>
						
                    <div class="row">
                        <div class="col-lg-12">
                            <div class="card alert">
                                <div class="card-body">
								
								 <form class="form-valide" action="pr_meeting.php?temp_id=<?php echo $temp_id; ?>" method="post">
								 
								 <div class="form-group row">
                                                <label class="col-lg-2 col-form-label" >Booking ID / Customer </label>
                                                <div class="col-lg-2">
                                                     <select class="form-control bg-ash border-none select2" data-placeholder="Select existing Booking" style="width: 100%;" name="temp_booking_id" id="temp_booking_id" onchange="noFunction();" >
            
                                              																
					
 
<option value="<?php echo $temp_id;  ?>"> <?php echo $booking_id;  ?> -  <?php echo $name;  ?>  </option>


											
												
												<?php 
												
												
												


                               
                                $sqlSelectMem = "SELECT * FROM `bookings` where booking_id!=0 ";

                                $sqlSelectMem = mysqli_query($connection, $sqlSelectMem);


                               while ($list = mysqli_fetch_object($sqlSelectMem)) {

                                    
                                   
                                    $booking_id = $list->booking_id;
									$temp_id = $list->id;
									$name = $list->name;
                                   
                                ?>
												
												
                                                       
														<option value="<?php echo $temp_id;  ?>"> <?php echo $booking_id;  ?> -  <?php echo $name;  ?>  </option>
														
							   <?php } ?>
                                                    </select>
                                                </div>
												  <div id="no_load" class="col-lg-2">
												  </div>
												
                                            </div>
											 <div class="form-group row">
											<label class="col-lg-2 col-form-label" > Date  </label>
												 <div class="col-lg-2">
												 <input name="date" type="date" value="<?php echo $c_date;  ?>" >  </div>
										    <label class="col-lg-2 col-form-label" > Time  </label>
												 <div class="col-lg-2">
												 <input name="time" type="time" value="<?php echo $c_time;  ?>" >  </div>
								   </div>
								  <div class="form-group row">
											<label class="col-lg-2 col-form-label" > Done  </label>
												 <div class="col-lg-2">
												 <input name="status" type="checkbox" <?php echo $status;  ?> value="checked" >  </div>
										         
								   </div>
							
										<input hidden name="sub" value="<?php echo $sub;  ?>">
										<input hidden name="mid" value="<?php echo $mid;  ?>">
										
										<br> <button type="submit" name="submit" class="btn btn-success">Save</button> <hr><br>
								
								
								
								
								
								
								
								</form>
								
								
								
								
								
								
                                </div>
                            </div>
                        </div>
                                  



                                   


							 </div> 
							 
							 
							 
							 
							 
							
							 
							 
							 
							 
							 </div>
							
                        </div>
				
				
                        <!-- /# column -->
                        
                    </div>
				
				
				
				
				
                    <!-- /# row -->
                   
				   
				   
				           <?php include("footer.php"); ?>
						   
						   
                </section>
            </div>
        </div>
    </div>

    <div id="search">
        <button type="button" class="close">×</button>
        <form>
            <input type="search" value="" placeholder="type keyword(s) here" />
            <button type="submit" class="btn btn-primary">Search</button>
        </form>
    </div>


    </div>
    <script src="assets/js/lib/jquery.min.js"></script>
    <!-- jquery vendor -->
    <script src="assets/js/lib/jquery.nanoscroller.min.js"></script>
    <!-- nano scroller -->
    <script src="assets/js/lib/menubar/sidebar.js"></script>
    <script src="assets/js/lib/preloader/pace.min.js"></script>
    <!-- sidebar -->
    <script src="assets/js/lib/bootstrap.min.js"></script>
    <!-- bootstrap -->
   
    <script src="assets/js/scripts.js"></script>
	
	 <script src="assets/js/lib/data-table/datatables.min.js"></script>
    <script src="assets/js/lib/data-table/buttons.dataTables.min.js"></script>
    <script src="assets/js/lib/data-table/dataTables.buttons.min.js"></script>
    <script src="assets/js/lib/data-table/buttons.flash.min.js"></script>
    <script src="assets/js/lib/data-table/jszip.min.js"></script>
    <script src="assets/js/lib/data-table/pdfmake.min.js"></script>
    <script src="assets/js/lib/data-table/vfs_fonts.js"></script>
    <script src="assets/js/lib/data-table/buttons.html5.min.js"></script>
    <script src="assets/js/lib/data-table/buttons.print.min.js"></script>
    <script src="assets/js/lib/data-table/datatables-init.js"></script>
	
	
     <script>
	 
	 function noFunction() {
  
 
  var temp_booking_id = document.getElementById("temp_booking_id").value;
  
      $.ajax({
            url: 'inc/meeting_check.php?temp_booking_id='+temp_booking_id,
			error: function (request, error) {
            console.log(arguments);
            alert(" Can't do because: " + error);
           },
            success: function (response)
            {
              //  alert(response);
              jQuery('#no_load').html(response);
            }
			
 

            
        });
} 
	
	  </script>

	
	<script>
        $(document).ready(function() {
            $('.select2').select2();
        });
    </script>

		 <script src="assets/js/lib/select2/select2.full.min.js"></script>
		 
		 
</body>

</html>