PHP - Appointment Booking Script For Calendar
Hello. I'm trying to build a site where users can book appointments with personal trainers. I want to use the free and open source jQuery Full Calendar for the look and feel of the calendar since it looks pleasant and is responsive. <link removed>
I want each personal trainer to have their own calendar which will show the days that they're available. When a user clicks on an available day then they will see a list of time slots that they can book in 15 minute increments. So, for instance lets say a trainer named Mike is available on Mondays-Friday from 8am-5pm. If a user comes to his calendar they will see that certain days are not fully booked and they can click on a day. Then when they click on a day they can see time intervals like this: Mike's available time slots for Tuesday August 25, 2014: 8:00 am-9:00 am - Click here to book appointment! 8:15 am-9:15 am - Click here to book appointment! 2:00 pm - 3:00 pm - Click here to book appointment! The page above can be a separate page from the calendar, but it would need to be synced with the calendar to be able to fetch the times and days that he's available for appointments. Then when the user clicks on a day, he can book an appointment and after the trainer confirms via email then the user will receive an email confirmation that his appointment is scheduled. While it's still being confirmed though, that time slot would need to be no longer visible to other users, so that there wouldn't be multiple bookings for the same time slot, to avoid those conflicts. So, the application would need to fetch the data from MySQL and use that to display the available days. If a day is not available then the user will not be able to click on it in the calendar. Also, the trainers should be able to set their schedule which will get updated to MySQL, so the schedule is normally recurring but they should also be able to change certain days if they feel like they can or cannot work on that day. Also, the appointments will vary by time, so a training session can last 30 minutes, 1 hour, 3 hours, 1 hour and a half, etc. and that would need to be taken into account when the user books an appointment because if the trainer has a 1 hour gap between 2pm and 3pm, but the session is for 2 hours, they should not be able to book that time slot, since it wouldn't make any sense. What makes this complicated is that the appointment lengths can vary. Otherwise, if every appointment was 1 hour long I would be able to just create a table for appointment times and do a query to see if they're booked and only show the booked ones. How can I do it with variable time lengths? Any help would be greatly appreciated. Edited by mac_gyver, 16 August 2014 - 09:04 AM. removed link, not relevant to post Similar TutorialsHi, As a part of my university course final year project i have to create a room reservation system. I have found this http://www.phpjabbers.com/availability-booking-calendar/index.php Which looks perfect but i cant use that as i have to code it myself. Does anyone know of a guide that will help me build something similar? Thanks in advance Here's what I'm trying to do. 1. A user creates a calendar that shows which dates he's available. This calendar could showcase availability for up to a year. 2. Other users can do a search for a user that's available on a set date. For e.g. July 1st. 3. All the users available on July 1st will show up in the search results.
There is no booking for appointments involved. It simply needs to show the users available on set dates. I am wondering what's the best way to create this calendar feature? Hi, I want to check entered dates and times that a user selects against my "book-off" calendar which is a Google Calendar. The dates× from Google is in the form: 2011-04-29T23:00:00.000+02:00 The dates in my booking software (ABPro) is in the form: 2011-04-29 Times in form: 23:00:00 All I want the function to return is a number other than 0 if any of the dates/times in Google feed overlap the requested date/time entered in the booking. So I add a function and get the feed from Google: Code: [Select] function checkOverlapG($calendarID, $startdate, $starttime, $enddate, $endtime){ // Create an instance of the Calendar service using an unauthenticated //HTTP client $service = new Zend_Gdata_Calendar(); //Retrieving events in order of start time $query = $service->newEventQuery(); $query->setUser('calendarID'); // Set to $query->setVisibility('private-magicCookieValue') if using MagicCookie auth $query->setVisibility('public'); $query->setProjection('full'); $query->setOrderby('starttime'); $query->setSortOrder('ascending'); //start with first event in future //seFutureevents must be commented out when using start and end times. $query->setFutureevents('true'); $query->setSingleEvents('true'); $query->setMaxResults('200'); //Guess this could be anything, but can possibly make things slower. Default 25 events //$query->setStartMin('2006-12-01'); //$query->setStartMax('2006-12-16); // setStartMax is exclusive, will not include last date. Must add +1 day. // Retrieve the event list from the calendar server try { $eventFeed = $service->getCalendarEventFeed($query); } catch (Zend_Gdata_App_Exception $e) { echo "Error: " . $e->getMessage(); return null; } Now I want to compare the dates and times and see if any of them collide or overlap. I want to add a counter, and if any of the events overlap, I want the counter to add one number. 1. the first thing I do is check if the event feed include. any events. 2. then I add a counter 3. then I run a foreach to retrieve events one at a time 4. then I change the date and time format from Google Event to match the date and time format form the booking. 5. If fullday event from google, no time information is added, so I add this 6. COMPARE DATES AND TIMES and if overlapping events --> n++; I've not gotten this code to work. Probably I'm doing something wrong, and I'm sorry but I'm completely new to this. Getting the Google Calendar data is working fine, and so is changing the format of the dates/times to be same format as request data. After that (and before, I don't know). Code: [Select] $gCount = count($eventFeed); $n = 0; if (gCount>0){ foreach($eventFeed as $event){ foreach ($event->when as $when) { //Getting rid of extra 00's and time zone info for now $startGevent = $when->startTime; $startGevent = str_replace('.000+02:00',"",$startGevent); $endGevent = $when->endTime; $endGevent = str_replace('.000+02:00',"",$endGevent); //Splitting date and time into two variables list($startDateEvent, $startTimeEvent) = split('T',$startGevent); list($endDateEvent, $endTimeEvent) = split('T',$endGevent); //Fill in the blanks if($startTimeEvent!=0) {} else{$startTimeEvent = "00:00:00";} if($endTimeEvent!=0) {} else{$endTimeEvent = "00:00:00";} //Compare dates if($startdate == $endDateEvent){ if($starttime > $endTimeEvent OR $endtime < $startTimeEvent){} else { n++; } } if($enddate == $startDateEvent){ if($endtime < $startTimeEvent OR $starttime > $endTimeEvent){} else { n++; } } } } return $n; } Anyone have info on a simple PHP script that can display a particular month where you can insert events such as a birthday or special event? Not looking for anything too complicated or fansy. thanks Hey guys,
Ive been working on this script and I cant seem to figure out how to highlite the current date in lets say a blue color.
Any ideas please?
<!DOCTYPE html> <html> <head> <title>Simple Month Calendar</title> <script type="text/javascript"> // Author: Danny van der ven // Created: 12 aug 2014 // P.S. I'm from The Netherlands, so the names of the weeks and months are in Dutch. var Calendar = function(divId) { //Store div id this.divId = divId; // Days of week, starting on Sunday this.DaysOfWeek = [ 'Z', 'M', 'D', 'W', 'D', 'V', 'Z' ]; // Months, stating on January this.Months = ['januari', 'februari', 'maart', 'april', 'mei', 'juni', 'juli', 'augustus', 'september', 'oktober', 'november', 'december' ]; // Set the current month, year var d = new Date(); this.CurrentMonth = d.getMonth(); this.CurrentYear = d.getFullYear(); }; // Goes to next month Calendar.prototype.nextMonth = function() { if ( this.CurrentMonth == 11 ) { this.CurrentMonth = 0; this.CurrentYear = this.CurrentYear + 1; } else { this.CurrentMonth = this.CurrentMonth + 1; } this.showCurrent(); }; // Goes to previous month Calendar.prototype.previousMonth = function() { if ( this.CurrentMonth == 0 ) { this.CurrentMonth = 11; this.CurrentYear = this.CurrentYear - 1; } else { this.CurrentMonth = this.CurrentMonth - 1; } this.showCurrent(); }; // Show current month Calendar.prototype.showCurrent = function() { this.showMonth(this.CurrentYear, this.CurrentMonth); }; // Show month (year, month) Calendar.prototype.showMonth = function(y, m) { var d = new Date() // First day of the week in the selected month , firstDayOfMonth = new Date(y, m, 1).getDay() // Last day of the selected month , lastDateOfMonth = new Date(y, m+1, 0).getDate() // Last day of the previous month , lastDayOfLastMonth = m == 0 ? new Date(y-1, 11, 0).getDate() : new Date(y, m, 0).getDate(); var html = '<table>'; // Write selected month and year html += '<tr><td colspan="7">' + this.Months[m] + ' - ' + y + '</td></tr>'; // Write the header of the days of the week html += '<tr>'; for(var i=0; i < this.DaysOfWeek.length;i++) { html += '<td>' + this.DaysOfWeek[i] + '</td>'; } html += '</tr>'; // Write the days var i=1; do { var dow = new Date(y, m, i).getDay(); // If Sunday, start new row if ( dow == 0 ) { html += '<tr>'; } // If not Sunday but first day of the month // it will write the last days from the previous month else if ( i == 1 ) { html += '<tr>'; var k = lastDayOfLastMonth - firstDayOfMonth+1; for(var j=0; j < firstDayOfMonth; j++) { html += '<td class="not-current">' + k + '</td>'; k++; } } // Write the current day in the loop html += '<td>' + i + '</td>'; // If Saturday, closes the row if ( dow == 6 ) { html += '</tr>'; } // If not Saturday, but last day of the selected month // it will write the next few days from the next month else if ( i == lastDateOfMonth ) { var k=1; for(dow; dow < 6; dow++) { html += '<td class="not-current">' + k + '</td>'; k++; } } i++; }while(i <= lastDateOfMonth); // Closes table html += '</table>'; // Write HTML to the div document.getElementById(this.divId).innerHTML = html; }; // On Load of the window window.onload = function() { // Start calendar var c = new Calendar("divCalendar"); c.showCurrent(); // Bind next and previous button clicks getId('btnNext').onclick = function() { c.nextMonth(); }; getId('btnPrev').onclick = function() { c.previousMonth(); }; } // Get element by id function getId(id) { return document.getElementById(id); } </script> <style type="text/css"> td.not-current { color: #777; } </style> </head> <body> <div id="divCalendar"> </div> <button id="btnPrev" type="button">Terug</button> <button id="btnNext" type="button">Vooruit</button> </body> </html> I have an array of appointment start times throughout a day. All appointments last 30 mins. I also have a list of times that staff are available to meet these appointment times (can be in any format, array etc.) I need to ensure the appointment times are fully covered by members of staff. E.g. Code: [Select] $appointmentStart[] = "09:30"; $appointmentStart[] = "10:00"; $appointmentStart[] = "11:00"; $appointmentStart[] = "12:30"; $appointmentStart[] = "13:30"; $appointmentStart[] = "15:00"; $appointmentStart[] = "17:00"; $staffMembers[] = "09:00*12:00"; $staffMembers[] = "13:00*16:00"; $staffMembers[] = "15:00*18:00"; In the above case, no, there are not enough staff members to cover this as nobody works from 12:00 to 13:00. I only really need a yes or no. Don't worry about staff breaks, they never work more than 3 hours each at a time. Thanks in advance for any help. Hello, I found this great free php calandar script here "" by Xu and Alessandro, and I'm trying to modify the code to mark several dates(birthdays YYYY-mm-dd) from a date column in a sql database. I've played around with the _showDay() method but I can't seem to get it working.. I've also tried to create a _showBirthday() method to modify the css as well but with no luck. What I'm trying to do is loop through the database to mark the respective dates on the calendar, and have a href to display a new page with the person's name when I click the specific date. Can anyone help with this. Thanks in advance! This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=348851.0 I'm new to this blog but need serious help. I want to add a calendar to a Hotel website for the booking part, I did it once but I forgot how to do it. Here is the link to the booking file. http://regencycountryclub.com/QuickReserve.php I just want instead of having to select the day, month and year. I want to add a calendar to select the arrival date and departure date. I would really appreciate the help. Thanks Hi All I am wanting to create an online booking system. Has anyone got any suggestions on this? Adi hello, i have a booking form that allows people to book appointments from 0900 to 1800 with 30 min intervals 0900,0930,1000 etc and i was wondering if there is some php code out there that will stop people from booking an appointment at a time that is already booked. any ideas ? cheers i have installed a calendar i want to extract the available id_item that are not id_state=1(booked) i want to query all the items that are not booked the dates: $fromdate=22-03-2011; $todate=25-03-2011; Code: [Select] this is bookings.php mysql_select_db($database_international, $international); $query_RsBookingIO = sprintf("SELECT * FROM `bookings` LEFT JOIN bookings_items ON bookings.id_item = bookings_items.id WHERE dateDIFF (2011-03-22, 2011-03-25) and bookings.id_state ='1' LIMIT 0 , 30 ", GetSQLValueString($colname_RsBookingIO, "int")); $RsBookingIO = mysql_query($query_RsBookingIO, $international) or die(mysql_error()); $row_RsBookingIO = mysql_fetch_assoc($RsBookingIO); <?php do { echo $row_RsBookingIO['the_date']; ?> <?php } while ($row_RsBookingIO = mysql_fetch_assoc($RsBookingIO)); ?> now when creating the searchfunction.php <?php $data = file_get_contents('http://localhost/bookings.php?fromdate=$fromdate and todate=$todate'); $fromdate = $_GET['fromdate']; $todate = $_GET['todate']; $dates = explode(' ',$data); var_dump($data); foreach($dates as $aDate) { echo $aDate; //$aDate = '\''.$aDate.'\''; if (!in_array($aDate, $dates)) { $available = true; } } return $available; ?> //tables CREATE TABLE `bookings` ( `id` int(11) NOT NULL AUTO_INCREMENT, `id_item` int(20) NOT NULL DEFAULT '0', `the_date` date NOT NULL DEFAULT '0000-00-00', `id_state` int(11) NOT NULL DEFAULT '0', `id_booking` int(10) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `id_item` (`id_item`), KEY `id_state` (`id_state`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=12 ; -- -- Dumping data for table `bookings` -- INSERT INTO `bookings` VALUES(1, 2, '2011-03-22', 1, 0); INSERT INTO `bookings` VALUES(3, 2, '2011-03-23', 1, 0); INSERT INTO `bookings` VALUES(4, 2, '2011-03-24', 1, 0); INSERT INTO `bookings` VALUES(5, 2, '2011-03-25', 1, 0); INSERT INTO `bookings` VALUES(6, 2, '2011-03-26', 1, 0); INSERT INTO `bookings` VALUES(7, 3, '2011-03-23', 1, 0); INSERT INTO `bookings` VALUES(8, 3, '2011-03-24', 1, 0); INSERT INTO `bookings` VALUES(9, 3, '2011-03-25', 1, 0); INSERT INTO `bookings` VALUES(10, 3, '2011-03-26', 1, 0); INSERT INTO `bookings` VALUES(11, 3, '2011-03-27', 1, 0); CREATE TABLE `bookings_items` ( `id` int(11) NOT NULL AUTO_INCREMENT, `id_user` int(11) NOT NULL DEFAULT '1', `id_ref_external` int(11) NOT NULL COMMENT 'link to external db table', `desc_en` varchar(100) NOT NULL DEFAULT '', `desc_es` varchar(100) NOT NULL DEFAULT '', `list_order` int(11) NOT NULL DEFAULT '0', `state` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`id`), KEY `id_user` (`id_user`), KEY `id_ref_external` (`id_ref_external`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ; -- -- Dumping data for table `bookings_items` -- INSERT INTO `bookings_items` VALUES(1, 1, 4600, 'Suite_A', 'Suite_A', 2, 1); INSERT INTO `bookings_items` VALUES(2, 1, 4601, 'Suite_B', 'Suite_B', 2, 1); Hi all I am trying to edit a piece of code to change possible times for a booking system. This is the code I have: $count=0; for($b=$startTime;$b<$endTime;$b++){ if($count==$tempVar2){ $availability .= "</td><td align='left' valign='top'>"; } if(in_array($b,$reservedArray)){ $availability .= $b.":00 ".($b<12?"am":"pm")." - ".($b+1).":00 ".($b+1<12?"am":"pm")." - Booked.<br>"; } else { $availability .=$b.":00 ".($b<12?"am":"pm")." - ".($b+1).":15 ".($b+1<13?"am":"pm")."- <input type=\"checkbox\" value=\"".$b."\" name=\"time[]\" ><br>"; } $count++; } It gives me the following times: 09:00 am - 10:15 am 10:00 am - 11:15 am 11:00 am - 12:15 am 12:00 pm - 13:15 pm 13:00 pm - 14:15 pm 14:00 pm - 15:15 pm 15:00 pm - 16:15 pm 16:00 pm - 17:15 pm How can I change it so I can have the following times available: 10:00 am - 10:30 am 10:45 am - 11:15 am 11:30 am - 12:00 pm 12:15 pm - 12:30 pm etc... Many thanks for you help Pete. I have a problem which is why I am here. What I am trying to achieve I am creating a very very basic timetabling system online, using php and sql. I am still in the process of completing it and changing bits from here to there. Although I am fully aware that the current design / implementation needs several changes and amendments, but however it performs most of the basic functionalities from a login system to the ability to add data delete data and also reset the database and recreate. The problem I have a table called tCourse althouogh a full ERD implementation has not taken place, it is still trial and error period. The table consists of the following: - Course - Unit - Course_Code - Year (i.e. Yr1, Yr2, Yr3) - Credits (Value of the unit) - Day - Semester - Start_Time - End_Time - Room - Tutor At the moment the primary keys for the table a - Day - Start_Time - Room_ - Semester This basically prevents a particular day, a semester, a room having been booked at the same time. Which for a very basic one is ok. The only problem is though, if someone books for example: Monday >> 13:00:00 To 14:00:00 >> 205 >> Sem1 (ok) Monday >> 13:00:00 To 14:00:00 >> 205 >> Sem1 (Not ok, which is good, as it is a repeat and prevents double booking) However the problem comes he Monday >> 12:00:00 To 14:00:00 >> 205 >> Sem1 (ok) So this is allowing a booking even though that room will be busy i.e. booked between 13:00 to 14:00 So is there a way I can limit it, so if there is a room booked for that particular period it will not do it. I have done a bit of research and friend's have suggested doind several for loops and quering the database beforehand. I came here, mainly because there are a lot of experienced individuals here whom may have a simpler solution, although I can understand it won't be a one liner . I would appreciate any help, if not, it is still ok. Hello Friends,
I am trying to execute Time slot booking for an application. - When user selects a date - Each time slot can be booked by 2 users User 1 selected a date (2nd March)and selected a time slot (10:00 - 11:00 AM).
User 2 selected a date (2nd March)and selected a time slot (10:00 - 11:00 AM). Please find the script below. Your help is really appreciated. <?php include('database.php'); $fname=""; $lname=""; $email=""; $phone=""; $date=""; if(isset($_POST['fname'])){ $fname=$_POST['fname'];} if(isset($_POST['lname'])){$lname=$_POST['lname'];} if(isset($_POST['email'])){$email=$_POST['email'];} if(isset($_POST['phone'])){$phone=$_POST['phone'];} if(isset($_POST['date'])){$date=$_POST['date'];} else $date=date("m-d-Y") $result=mysqli_query($conn,"SELECT exam_time,count()from test_booking_confirm where DATEDIFF('exam_date',DATE_FORMAT('"+$date+"','%m-%d-%Y'))=0 group by exam_date,exam_time having count()>1"); $slots=array(); $i=0; if (mysqli_num_rows($result) != 0) { while($row = mysqli_fetch_assoc($result)) { $slots[$i]=$row["exam_time"]; $i++; } } ?> <!doctype html> <html> <head> <title></title> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <link rel="stylesheet" href="css/style.css" /> <link rel="stylesheet" href="css/bootstrap.min.css" /> <!-------date picker-------> <link rel="stylesheet" href="css/jquery-ui.css" /> <script src="js/jquery.js"></script> <script src="js/jquery-ui.js"></script> <script> $(document).ready(function(){ $("#datepicker").datepicker({ beforeShowDay: function(date) { var day=date.getDay(); if(day==2) { return [false]; } else { return [true]; } } }); }); </script> <script> $(document).ready(function() { $('#datepicker').datepicker(); $('#datepicker').datepicker("show"); }); </script> <script> function setToday() { var n = new Date(); y = n.getFullYear(); m = n.getMonth() + 1; d = n.getDate(); var x=m + "/" + d + "/" + y; document.getElementById("datepicker").value = x; } function datechange(vv) { document.myform.action="test_booking.php"; document.myform.submit(); } </script> </head> <body OnLoad="document.myform.fname.focus();setToday()"> <div class="container register"> <div class="row"> <div class="col-md-3 training_bk register-left"> <img src="images/ESStechlogo.png" alt=""/> <h3>Welcome</h3> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p> </div> <div class="col-md-9 register-right"> <form method="post" action="test_booking_review.php" name="myform"> <div class="tab-content" id="myTabContent"> <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab"> <h3 class="register-heading">Book your Training</h3> <div class="row register-form"> <div class="col-md-6"> <div class="form-group"> <input type="text" autofocus name="fname" required class="form-control" placeholder="First Name*" /> </div> <div class="form-group"> <input type="text" name="lname" required class="form-control" placeholder="Last Name*" /> </div> <h5>Your Preferred Slot</h5> <div class="form-group"> <!--<div id="datepicker" required name="date" ></div>--> <input type="text" id="datepicker" required name="date" placeholder="mm/dd/yyyy" class="form-control" onChange ="datechange(this.value)"> </div> </div> <div class="col-md-6"> <div class="form-group"> <input type="email" name="email" required class="form-control" placeholder="Email*" /> </div> <div class="form-group"> <input type="number" name="phone" required class="form-control" placeholder="Phone*" /> </div> <!--<div class="form-group"> <select class="form-control"> <option class="hidden" selected disabled>City</option> <option>option</option> <option>option</option> <option>option</option> </select> </div>--> <div class="form-group"> <div class="maxl"> <?php if (!in_array("08:00AM TO 09:00AM", $slots)) { ?> <label class="radio inline"> <input type="radio" name="time" value="08:00AM TO 09:00AM" checked> <span>08:00AM TO 09:00AM (Available)</span> </label> <?php } if (!in_array("09:00AM TO 10:00AM", $slots)) { ?> <label class="radio inline"> <input type="radio" name="time" value="09:00AM TO 10:00AM"> <span>09:00AM TO 10:00AM (Available)</span> </label> <?php } if (!in_array("10:00AM TO 11:00AM", $slots)) { ?> <label class="radio inline"> <input type="radio" name="time" value="10:00AM TO 11:00AM"> <span>10:00AM TO 11:00AM (Available)</span> </label> <?php } if (!in_array("11:00AM TO 12:00PM", $slots)) { ?> <label class="radio inline"> <input type="radio" name="time" value="11:00AM TO 12:00PM"> <span>11:00AM TO 12:00PM (Available)</span> </label> <?php } if (!in_array("12:00PM TO 01:00PM", $slots)) { ?> <label class="radio inline"> <input type="radio" name="time" value="12:00PM TO 01:00PM"> <span>12:00PM TO 01:00PM (Available)</span> </label> <?php } ?> </div> </div> <input type="submit" class="btnRegister" value="Continue"/> </div> </div> </div> </div> </form> </div> </div> </div> </body> Edited March 4, 2020 by Barand Added code tags
$sql="SELECT COUNT(*) as conflicts
how do I get the value of the conflicts im now very clueless Hi there Got a problem needs a solution, basically a booking system has been built (by me) and works great except for the checking availablity Basically they can do drives in a car (in any order) so I need to try all possible combinations. one idea I had was to use an array holding the availability for each slot so that it looks like slotArray=array("ABC","AC","C","A","BC","AB","ABC" ...etc) looking for drives A and B so check if slotArray[1] contains A and Slot Array 2 contains b or vice versa what i need to do is work out all the possible orders of a string ABCDE (there will be 120 of them) so I can systematically check the order anyone have a function that will do this? Hi ,
I try to change a PHP code for a booking program without succes. Now the time set is from 00.00 - 24.00hours but it must be fixed on 15.00H ( dropoff) and 11.00H (pick-up). Can someone help me please ?
Big thanks in advance !
$pickhdeftime = !empty($places[$indvrcplace]['defaulttime']) ? ((int)$places[$indvrcplace]['defaulttime'] / 3600) : ''; |