1 <?php 2 if(isset($_GET['date'])){ 3 $date = $_GET['date']; 4 } 5 6 if(isset($_POST['submit'])){ 7 $name = $_POST['name']; 8 $email = $_POST['email']; 9 $timeslot= $_POST['timeslot']; 10 $mysqli = new mysqli('localhost', 'root', '', 'bookingcalendar'); 11 $stmt = $mysqli->prepare("INSERT INTO bookings (name,timeslot, email, date) VALUES (?,?,?,?)"); 12 $stmt->bind_param('ssss', $name,$timeslot, $email, $date); 13 $stmt->execute(); 14 $msg = "<div class='alert alert-success'>Booking Successfull</div>"; 15 $stmt->close(); 16 $mysqli->close(); 17 } 18 $duration = 10; 19 $cleanup =0; 20 $start = "09.00"; 21 $end = "15:00"; 22 23 24 function timeslots($duration,$cleanup,$start,$end){ 25 $start = new DateTime($start); 26 $end = new DateTime($end); 27 $interval = new DateInterval("PT".$duration."M"); 28 $cleanupInterval = new DateInterval("PT".$cleanup."M"); 29 $slots = array(); 30 31 for ($intStart = $start; $intStart<$end; $intStart-> add($interval)->add($cleanupInterval)){ 32 $endPeriod = clone $intStart; 33 $endPeriod->add($interval); 34 if($endPeriod>$end){ 35 break; 36 } 37 $slots[] = $intStart->format("H:iA")."-".$endPeriod->format("H:iA"); 38 } 39 40 return $slots; 41 } 42 43 ?> 44 <!doctype html> 45 <html lang="en"> 46 47 <head> 48 <meta charset="UTF-8"> 49 <meta http-equiv="X-UA-Compatible" content="ie=edge"> 50 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 51 52 <title></title> 53 54 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> 55 <link rel="stylesheet" href="/css/main.css"> 56 </head> 57 58 <body> 59 <div class="container"> 60 <h1 class="text-center">Book for Date: <?php echo date('m/d/Y', strtotime($date)); ?></h1><hr> 61 <div class="row"> 62 <div class="col-md-12"> 63 <?php echo isset($msg)?$msg:"";?> 64 </div> 65 66 <?php 67 $timeslots = timeslots($duration,$cleanup,$start,$end); 68 foreach($timeslots as $ts){ 69 ?> 70 <div class = "col-md-2"> 71 <div class = "form-group"> 72 <button class="btn btn-success book"data-timeslot="<?php echo $ts;?>"><?php echo $ts; ?></boutton> 73 </div> 74 </div> 75 <?php} ?> 76 77 </div> 78 </div> 79 <div id="myModal" class="modal fade" role="dialog"> 80 <div class="modal-dialog"> 81 82 <!-- Modal content--> 83 <div class="modal-content"> 84 <div class="modal-header"> 85 <button type="button" class="close" data-dismiss="modal">×</button> 86 <h4 class="modal-title">Booking:<span id="slot"></span></h4> 87 </div> 88 <div class="modal-body"> 89 <div class"row"> 90 <div class"col-md-12"> 91 <form action = "" method ="post"> 92 <div class ="form-group"> 93 <label for "">Timeslot</label> 94 <input required type "text" readonly name = "timeslot" id= "timeslot" class ="form-control"> 95 </div> 96 <div class ="form-group"> 97 <label for "">Name</label> 98 <input required type "text" = "name" class ="form-control"> 99 </div> 100 <div class ="form-group"> 101 <label for "">Email</label> 102 <input required type "email" = "email" class ="form-control"> 103 </div> 104 <div class ="form-group pull-right"> 105 <button class = "btn-btn-primary" type ="submit" name="submit">Submit</button> 106 </div> 107 </form> 108 </div> 109 </div> 110 </div> 111 112 </div> 113 114 </div> 115 </div> 116 117 118 119 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 120 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> 121 <script> 122 $(".book").click(function()){ 123 var timeslot = $(this).attr('data-timeslot'); 124 $("#slot").html(timeslot); 125 $("#timeslot").val(timeslot); 126 $("#myModal").modal("show"); 127 } 128 </script> 129 </body> 130 </html>
{
}
66 <?php 67 $timeslots = timeslots($duration,$cleanup,$start,$end); 68 foreach($timeslots as $ts){ 69 ?> 70 <div class = "col-md-2"> 71 <div class = "form-group"> 72 <button class="btn btn-success book"data-timeslot="<?php echo $ts;?>"><?php echo $ts; ?></boutton> 73 </div> 74 </div> 75 <?php} ?>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)