prefix . "ap_appointments"; $query = $wpdb->query( $wpdb->prepare( " INSERT INTO $AppointmentsTable ( id , name , email , service_id , phone , start_time , end_time , date , note , appointment_key , status , appointment_by ) VALUES ( %d , %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) ", array( null, $ClientName, $ClientEmail, $ServiceId, $ClientPhone, $StartTime, $EndTime, $AppointmentDate, $ClientNote, $AppointmentKey, $Status, $AppointmentBy ) ) ); if( $query ) { $BlogName = get_bloginfo(); //get service details $ServiceTable = $wpdb->prefix . "ap_services"; $ServiceData = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $ServiceTable WHERE id = %d" , $ServiceId ) , OBJECT); $ServiceName = $ServiceData->name; //check notification is enabled $NotificationStatus = get_option('emailstatus'); if($NotificationStatus == "on") { $Attachments = ""; $AppointmentTime = $StartTime." - ".$EndTime; $AdminSubject = get_option('new_appointment_admin_subject'); $AdminSubject = str_replace("[blog-name]", ucwords($BlogName), $AdminSubject); $AdminSubject = str_replace("[client-name]", ucwords($ClientName), $AdminSubject); $AdminSubject = str_replace("[client-email]", ucwords($ClientEmail), $AdminSubject); $AdminSubject = str_replace("[client-phone]", ucwords($ClientPhone), $AdminSubject); $AdminSubject = str_replace("[client-si]", ucwords($ClientNote), $AdminSubject); $AdminSubject = str_replace("[service-name]", ucwords($ServiceName), $AdminSubject); $AdminSubject = str_replace("[app-date]", $AppointmentDate, $AdminSubject); $AdminSubject = str_replace("[app-status]", ucwords($Status), $AdminSubject); $AdminSubject = str_replace("[app-time]", $AppointmentTime, $AdminSubject); $AdminSubject = str_replace("[app-key]", $AppointmentKey, $AdminSubject); $AdminSubject = str_replace("[app-note]", ucfirst($ClientNote), $AdminSubject); $AdminBody = get_option('new_appointment_admin_body'); $AdminBody = str_replace("[blog-name]", ucwords($BlogName), $AdminBody); $AdminBody = str_replace("[client-name]", ucwords($ClientName), $AdminBody); $AdminBody = str_replace("[client-email]", ucwords($ClientEmail), $AdminBody); $AdminBody = str_replace("[client-phone]", ucwords($ClientPhone), $AdminBody); $AdminBody = str_replace("[client-si]", ucwords($ClientNote), $AdminBody); $AdminBody = str_replace("[service-name]", ucwords($ServiceName), $AdminBody); $AdminBody = str_replace("[app-date]", $AppointmentDate, $AdminBody); $AdminBody = str_replace("[app-status]", ucwords($Status), $AdminBody); $AdminBody = str_replace("[app-time]", $AppointmentTime, $AdminBody); $AdminBody = str_replace("[app-key]", $AppointmentKey, $AdminBody); $AdminBody = str_replace("[app-note]", ucfirst($ClientNote), $AdminBody); $ClientSubject = get_option('new_appointment_client_subject'); $ClientSubject = str_replace("[blog-name]", ucwords($BlogName), $ClientSubject); $ClientSubject = str_replace("[client-name]", ucwords($ClientName), $ClientSubject); $ClientSubject = str_replace("[client-email]", ucwords($ClientEmail), $ClientSubject); $ClientSubject = str_replace("[client-phone]", ucwords($ClientPhone), $ClientSubject); $ClientSubject = str_replace("[client-si]", ucwords($ClientNote), $ClientSubject); $ClientSubject = str_replace("[service-name]", ucwords($ServiceName), $ClientSubject); $ClientSubject = str_replace("[app-date]", $AppointmentDate, $ClientSubject); $ClientSubject = str_replace("[app-status]", ucwords($Status), $ClientSubject); $ClientSubject = str_replace("[app-time]", $AppointmentTime, $ClientSubject); $ClientSubject = str_replace("[app-key]", $AppointmentKey, $ClientSubject); $ClientSubject = str_replace("[app-note]", ucfirst($ClientNote), $ClientSubject); $ClientBody = get_option('new_appointment_client_body'); $ClientBody = str_replace("[blog-name]", ucwords($BlogName), $ClientBody); $ClientBody = str_replace("[client-name]", ucwords($ClientName), $ClientBody); $ClientBody = str_replace("[client-email]", ucwords($ClientEmail), $ClientBody); $ClientBody = str_replace("[client-phone]", ucwords($ClientPhone), $ClientBody); $ClientBody = str_replace("[client-si]", ucwords($ClientNote), $ClientBody); $ClientBody = str_replace("[service-name]", ucwords($ServiceName), $ClientBody); $ClientBody = str_replace("[app-date]", $AppointmentDate, $ClientBody); $ClientBody = str_replace("[app-status]", ucwords($Status), $ClientBody); $ClientBody = str_replace("[app-time]", $AppointmentTime, $ClientBody); $ClientBody = str_replace("[app-key]", $AppointmentKey, $ClientBody); $ClientBody = str_replace("[app-note]", ucfirst($ClientNote), $ClientBody); //check email type $EmailType = get_option('emailtype'); $EmailDetails = unserialize(get_option( 'emaildetails')); //wp-email if($EmailType == "wpmail") { $AdminEmail = $EmailDetails['wpemail']; $Headers[] = "From: Admin <".$AdminEmail.">"; //send wp email to client wp_mail( $ClientEmail, $ClientSubject, $ClientBody, $Headers, $Attachments); //send wp email to admin wp_mail( $AdminEmail, $AdminSubject, $AdminBody, $Headers, $Attachments); } //php-email if($EmailType == "phpmail") { $AdminEmail = $EmailDetails['phpemail']; $Headers[] = "From: Admin <".$AdminEmail.">"; ///send php email to client mail($ClientEmail, $ClientSubject, $ClientBody, $Headers); //send php email to admin mail( $AdminEmail, $AdminSubject, $AdminBody, $Headers); } //wp-email if($EmailType == "smtp") { require_once('menu-pages/notification/Email.php'); $AdminEmail = $EmailDetails['smtpemail']; $HostName = $EmailDetails['hostname']; $PortNo = $EmailDetails['portno']; $SMTPEmail = $EmailDetails['smtpemail']; $Password = $EmailDetails['password']; $Headers[] = "From: Admin <".$AdminEmail.">"; $Email = new SendEmail(); //send smtp email to client $Email->NotifyClient($HostName, $PortNo, $SMTPEmail, $Password, $AdminEmail, $ClientEmail, $ClientSubject, $ClientBody, $BlogName); //send smtp email to admin $Email->NotifyAdmin($HostName, $PortNo, $SMTPEmail, $Password, $AdminEmail, $AdminSubject, $AdminBody, $BlogName); } } //end of notification enable check if } // end og SQL if } //end of isset ?>
Appointment Calendar Powered By: AppointZilla

prefix . "ap_services"; $ServiceData = $wpdb->get_row($wpdb->prepare("SELECT `name`, `duration` FROM `$ServiceTableName` WHERE `id` = %d",$ServiceId), OBJECT); $ServiceDuration = $ServiceData->duration; $AppointmentDate = date("Y-m-d", strtotime($_GET['AppDate'])); //assign selected date by user $AllCalendarSettings = unserialize(get_option('apcal_calendar_settings')); $Biz_start_time = $AllCalendarSettings['day_start_time']; $Biz_end_time = $AllCalendarSettings['day_end_time']; if(isset($AllCalendarSettings['booking_time_slot'])) { $UserDefineTimeSlot = $AllCalendarSettings['booking_time_slot']; } else { $UserDefineTimeSlot = $ServiceDuration; } $AllSlotTimesList = array(); $Enable = array(); $AppPreviousTimes = array(); $AppNextTimes = array(); $AppBetweenTimes = array(); $EventPreviousTimes = array(); $EventBetweenTimes = array(); $DisableSlotsTimes = array(); $BusinessEndCheck =array(); $AllSlotTimesList_User = array(); $TodaysAllDayEvent = 0; $TimeOffTableName = $wpdb->prefix ."ap_events"; //if today is any all-day time-off then show msg no time available today $TodaysAllDayEventData = $wpdb->get_results( $wpdb->prepare("SELECT `start_time`, `end_time`, `repeat`, `start_date`, `end_date` FROM `$TimeOffTableName` WHERE date('$AppointmentDate') between `start_date` AND `end_date` AND `allday` = %s",'1'), OBJECT); //check if appointment date in any recurring time-off date foreach($TodaysAllDayEventData as $SingleTimeOff) { // none check if($SingleTimeOff->repeat == 'N') { $TodaysAllDayEvent = 1; } // daily check if($SingleTimeOff->repeat == 'D') { $TodaysAllDayEvent = 1; } // weekly check if($SingleTimeOff->repeat == 'W') { $EventStartDate = $SingleTimeOff->start_date; $diff = ( strtotime($EventStartDate) - strtotime($AppointmentDate) )/60/60/24; if(($diff % 7) == 0) { $TodaysAllDayEvent = 1; } } //bi-weekly check if($SingleTimeOff->repeat == 'BW') { $EventStartDate = $SingleTimeOff->start_date; $diff = ( strtotime($EventStartDate) - strtotime($AppointmentDate) )/60/60/24; if(($diff % 14) == 0) { $TodaysAllDayEvent = 1; } } //monthly check if($SingleTimeOff->repeat == 'M') { // calculate all monthly dates $EventStartDate = $SingleTimeOff->start_date; $EventEndDate = $SingleTimeOff->end_date; $i = 0; do { $NextDate = date("Y-m-d", strtotime("+$i months", strtotime($EventStartDate))); $AllEventMonthlyDates[] = $NextDate; $i = $i+1; } while(strtotime($EventEndDate) != strtotime($NextDate)); //check appointment-date in $AllEventMonthlyDates if(in_array($AppointmentDate, $AllEventMonthlyDates)) { $TodaysAllDayEvent = 1; } } }//end of event fetching foreach if($TodaysAllDayEvent) { ?>
". __("Available Time For", "appointzilla") ." '$ServiceData->name' ". __("On", "appointzilla"). " '".date("d-m-Y", strtotime($AppointmentDate))."'
"; //Calculate all time slots according to today's biz hours $start = strtotime($Biz_start_time); $end = strtotime($Biz_end_time); if($UserDefineTimeSlot) { $UserTimeSlot = $UserDefineTimeSlot; } else { $UserTimeSlot = 30; } for( $i = $start; $i < $end; $i += (60*$UserTimeSlot)) { $AllSlotTimesList_User[] = date('h:i A', $i); } // Business end check $Business_end = strtotime($Biz_end_time); $ServiceDuration_Biss= $ServiceDuration-5; $ServiceDuration_Biss = $ServiceDuration_Biss *60; $EndStartTime = $Business_end - $ServiceDuration_Biss; for( $i = $EndStartTime; $i < $Business_end; $i += (60*5)) { $BusinessEndCheck[] = date('h:i A', $i); } // Create Business Time slot for calculation for( $i = $start; $i < $end; $i += (60*5)) { $AllSlotTimesList[] = date('h:i A', $i); } //Fetch All today's appointments and calculate disable slots $AppointmentTableName = $wpdb->prefix . "ap_appointments"; $AllAppointmentsData = $wpdb->get_results( $wpdb->prepare("SELECT `start_time`, `end_time` FROM `$AppointmentTableName` WHERE `date`= %s",$AppointmentDate) , OBJECT); if($AllAppointmentsData) { foreach($AllAppointmentsData as $Appointment) { $AppStartTimes[] = date('h:i A', strtotime( $Appointment->start_time ) ); $AppEndTimes[] = date('h:i A', strtotime( $Appointment->end_time ) ); //now calculate 5min slots between appointment's start_time & end_time $start_et = strtotime($Appointment->start_time); $end_et = strtotime($Appointment->end_time); //make 15-10=5min slot for( $i = $start_et; $i < $end_et; $i += (60*(5))) { $AppBetweenTimes[] = date('h:i A', $i); } } //calculating Next & Previous time of booked appointments foreach($AllSlotTimesList as $single) { if(in_array($single, $AppStartTimes)) { //get next time $time = $single; $event_length = $ServiceDuration-5; // Service duration time - slot time $timestamp = strtotime("$time"); $endtime = strtotime("+$event_length minutes", $timestamp); $next_time = date('h:i A', $endtime); //calculate next time $start = strtotime($single); $end = strtotime($next_time); //making 5min diffrance slot for( $i = $start; $i <= $end; $i += (60*(5))) { $AppNextTimes[] = date('h:i A', $i); } //calculate previous time $time1 = $single; $event_length1 = $ServiceDuration-5; // 60min Service duration time - 15 slot time $timestamp1 = strtotime("$time1"); $endtime1 = strtotime("-$event_length1 minutes", $timestamp1); $next_time1 = date('h:i A', $endtime1); $start1 = strtotime($next_time1); $end1 = strtotime($single); //making 5min diff slot for( $i = $start1; $i <= $end1; $i += (60*(5))) { $AppPreviousTimes[] = date('h:i A', $i); } } }//end calculating Next & Previous time of booked appointments } // end if $AllAppointmentsData //Fetch All today's time-off and calculate disable slots $EventTableName = $wpdb->prefix."ap_events"; $AllEventsData = $wpdb->get_results($wpdb->prepare("SELECT `start_time`, `end_time` FROM `$EventTableName` WHERE date('$AppointmentDate') between `start_date` AND `end_date` AND `allday` = '0' AND `repeat` != 'W' AND `repeat` != 'BW' AND `repeat` != %s",'M'), OBJECT); if($AllEventsData) { foreach($AllEventsData as $Event) { //calculate previous time (event start time to back service-duration-5) $minustime = $ServiceDuration - 5; $start = date('h:i A', strtotime("-$minustime minutes", strtotime($Event->start_time))); $start = strtotime($start); $end = $Event->start_time; $end = strtotime($end); for( $i = $start; $i <= $end; $i += (60*(5))) //making 5min difference slot { $EventPreviousTimes[] = date('h:i A', $i); } //calculating between time (start - end) $start_et = strtotime($Event->start_time); $end_et = strtotime($Event->end_time); for( $i = $start_et; $i < $end_et; $i += (60*(5))) //making 5min slot { $EventBetweenTimes[] = date('h:i A', $i); } } } //Fetch All 'WEEKLY' tim-eoff and calculate disable slots $EventTableName = $wpdb->prefix . "ap_events"; $AllEventsData = $wpdb->get_results($wpdb->prepare("SELECT `start_time`, `end_time`, `start_date`, `end_date` FROM `$EventTableName` WHERE date('$AppointmentDate') between `start_date` AND `end_date` AND `allday` = '0' AND `repeat` = %s",'W'), OBJECT); if($AllEventsData) { foreach($AllEventsData as $Event) { //calculate all weekly dates between recurring_start_date - recurring_end_date $Current_Re_Start_Date = $Event->start_date; $Current_Re_End_Date = $Event->end_date; $Current_Re_Start_Date = strtotime($Current_Re_Start_Date); $Current_Re_End_Date = strtotime($Current_Re_End_Date); //make weekly dates for( $i = $Current_Re_Start_Date; $i <= $Current_Re_End_Date; $i += (60 * 60 * 24 * 7)) { $AllEventWeelylyDates[] = date('Y-m-d', $i); } if(in_array($AppointmentDate, $AllEventWeelylyDates)) { //calculate previous time (event start time to back service-duration-5) $minustime = $ServiceDuration - 5; $start = date('h:i A', strtotime("-$minustime minutes", strtotime($Event->start_time))); $start = strtotime($start); $end = $Event->start_time; $end = strtotime($end); //making 5min difference slot for( $i = $start; $i <= $end; $i += (60*(5))) { $EventPreviousTimes[] = date('h:i A', $i); } //calculating between time (start - end) $start_et = strtotime($Event->start_time); $end_et = strtotime($Event->end_time); //making 5min slot for( $i = $start_et; $i < $end_et; $i += (60*(5))) { $EventBetweenTimes[] = date('h:i A', $i); } } unset($AllEventWeelylyDates); } } //Fetch All 'BI-WEEKLY' time-off and calculate disable slots $EventTableName = $wpdb->prefix."ap_events"; $AllEventsData = $wpdb->get_results($wpdb->prepare("SELECT `start_time`, `end_time`, `start_date`, `end_date` FROM `$EventTableName` WHERE date('$AppointmentDate') between `start_date` AND `end_date` AND `allday` = '0' AND `repeat` = %s",'BW'), OBJECT); if($AllEventsData) { foreach($AllEventsData as $Event) { //calculate all weekly dates between recurring_start_date - recurring_end_date $Current_Re_Start_Date = $Event->start_date; $Current_Re_End_Date = $Event->end_date; $Current_Re_Start_Date = strtotime($Current_Re_Start_Date); $Current_Re_End_Date = strtotime($Current_Re_End_Date); //make bi-weekly dates for( $i = $Current_Re_Start_Date; $i <= $Current_Re_End_Date; $i += (60 * 60 * 24 * 14)) { $AllEventBiWeelylyDates[] = date('Y-m-d', $i); } if(in_array($AppointmentDate, $AllEventBiWeelylyDates)) { //calculate previous time (event start time to back ServiceDuration-5) $minustime = $ServiceDuration - 5; $start = date('h:i A', strtotime("-$minustime minutes", strtotime($Event->start_time))); $start = strtotime($start); $end = $Event->start_time; $end = strtotime($end); //making 5min difference slot for( $i = $start; $i <= $end; $i += (60*(5))) { $EventPreviousTimes[] = date('h:i A', $i); } //calculating between time (start - end) $start_et = strtotime($Event->start_time); $end_et = strtotime($Event->end_time); //making 5min slot for( $i = $start_et; $i < $end_et; $i += (60*(5))) { $EventBetweenTimes[] = date('h:i A', $i); } } } } //Fetch All 'MONTHLY' timeoff and calculate disable slots $EventTableName = $wpdb->prefix."ap_events"; $AllEventsData = $wpdb->get_results($wpdb->prepare("SELECT `start_time`, `end_time`, `start_date`, `end_date` FROM `$EventTableName` WHERE date('$AppointmentDate') between `start_date` AND `end_date` AND `allday` = '0' AND `repeat` = %s",'M'), OBJECT); if($AllEventsData) { foreach($AllEventsData as $Event) { //calculate all weekly dates between recurring_start_date - recurring_end_date $Current_Re_Start_Date = $Event->start_date; $Current_Re_End_Date = $Event->end_date; $i = 0; do { $NextDate = date("Y-m-d", strtotime("+$i months", strtotime($Current_Re_Start_Date))); $AllEventMonthlyDates[] = $NextDate; $i = $i+1; } while(strtotime($Current_Re_End_Date) != strtotime($NextDate)); if(in_array($AppointmentDate, $AllEventMonthlyDates)) { //calculate previous time (event start time to back service-duration-5) $minustime = $ServiceDuration - 5; $start = date('h:i A', strtotime("-$minustime minutes", strtotime($Event->start_time))); $start = strtotime($start); $end = $Event->start_time; $end = strtotime($end); //making 5min difference slot for( $i = $start; $i <= $end; $i += (60*(5))) { $EventPreviousTimes[] = date('h:i A', $i); } $start_et = strtotime($Event->start_time); $end_et = strtotime($Event->end_time); //making 5min difference slot for( $i = $start_et; $i < $end_et; $i += (60*(5))) { $EventBetweenTimes[] = date('h:i A', $i); } } } } $DisableSlotsTimes = array_merge($AppBetweenTimes, $AppPreviousTimes, $EventPreviousTimes, $EventBetweenTimes, $BusinessEndCheck); unset($AppBetweenTimes); unset($AppPreviousTimes); unset($AppNextTimes); unset($EventBetweenTimes); unset($BusinessEndCheck); // compare All Business Time slot with with DisableSlotsTimes foreach($AllSlotTimesList as $Single) { if(in_array($Single, $DisableSlotsTimes)) { $Disable[] = $Single; } else { $Enable[] = $Single; } }// end foreach // Show All Enable Time Slot foreach($AllSlotTimesList_User as $Single) { if(isset($Enable)) { if(in_array($Single, $Enable)) { ?>
 
 

:
:
:
: