· 9 years ago · Dec 07, 2016, 07:06 AM
1<?php // short-code file with button and big calendar(full-calendar)
2add_shortcode( 'APCAL', 'appointment_calendar_shortcode' );
3function appointment_calendar_shortcode() {
4 ob_start();
5 if(get_locale()) {
6 $language = get_locale();
7 if($language) { define('L_LANG',$language); }
8 }
9
10 $AllCalendarSettings = unserialize(get_option('apcal_calendar_settings'));
11 $small_calendar_type = $AllCalendarSettings['small_calendar_type'];
12 if($AllCalendarSettings['calendar_start_day'] != '') {
13 $CalStartDay = $AllCalendarSettings['calendar_start_day'];
14 } else {
15 $CalStartDay = 1;
16 }
17
18 //disable closed business days on small datepicker
19 global $wpdb;
20 $ClosedDays = array();
21 $StartDate = date("Y-m-d");
22 $EndDate = "2035-01-01";
23
24 /*$BusinessHoursTable = $wpdb->prefix . "ap_business_hours";
25 $ClosedBusinessDays = $wpdb->get_results("SELECT * FROM `$BusinessHoursTable` WHERE `close` LIKE 'yes'");
26 if(count($ClosedBusinessDays)) {
27 foreach($ClosedBusinessDays as $ClosedBusinessDay) {
28 $ClosedDays[] = ucfirst(substr($ClosedBusinessDay->day, 0, 3));
29 }
30 }*/
31
32 require_once( plugin_dir_path( __FILE__ ) . 'calendar/tc_calendar.php');
33 $CurrentDate = date("Y-m-d", time());
34 $DatePicker2 = plugins_url('calendar/', __FILE__);
35 $myCalendar = new tc_calendar("date1");
36 foreach($ClosedDays as $Day) {
37 $myCalendar->disabledDay("$Day");
38 }
39 $myCalendar->startDate($CalStartDay);
40 $myCalendar->setIcon($DatePicker2."images/iconCalendar.gif");
41 $myCalendar->setDate(date("d", strtotime($StartDate)), date("m", strtotime($StartDate)), date("Y", strtotime($StartDate)));
42 $myCalendar->setPath($DatePicker2);
43 $myCalendar->setYearInterval(2035,date('Y'));
44 $StartCalendarFrom = date("Y-m-d", strtotime("-1 day", strtotime($StartDate)));
45 $myCalendar->dateAllow($StartCalendarFrom, $EndDate, false);
46 $myCalendar->setOnChange("myChanged()");
47
48 $DateFormat = get_option('apcal_date_format');
49 if($DateFormat == '') $DateFormat = "d-m-Y";
50 $TimeFormat = get_option('apcal_time_format');
51 if($TimeFormat == '') $TimeFormat = "h:i";
52
53 global $wpdb;
54 $AppointmentTableName = $wpdb->prefix . "ap_appointments";
55 $EventTableName = $wpdb->prefix."ap_events";
56 $StaffTable = $wpdb->prefix."ap_staff";
57
58 $current_month_first_date = date("Y-m-01");
59 $laod_recurring_from = date("Y-m-d", strtotime("-3 month", strtotime($current_month_first_date))); //only for recurring app
60
61 //fetch all normal appointments
62 $FetchAllApps_sql = "select `name`, `staff_id`, `start_time`, `end_time`, `date` FROM `$AppointmentTableName` WHERE `recurring` = 'no' AND `date` >= '$current_month_first_date' AND `status` != 'cancelled'";
63
64 //fetch all recurring appointments
65 $FetchAllRApps_sql = "select * FROM `$AppointmentTableName` WHERE `recurring` = 'yes' AND `date` >= '$current_month_first_date' AND `recurring_st_date` >= '$laod_recurring_from' AND `status` != 'cancelled'";
66
67 //fetch all normal events
68 $FetchAllEvent_sql = "select `name`, `start_time`, `end_time`, `start_date`, `end_date`, `repeat` FROM `$EventTableName` where `repeat` = 'N' AND `start_date` >= '$current_month_first_date' ";
69
70 //fetch all recurring events
71 $FetchAllREvent_sql = "select `name`, `start_time`, `end_time`, `start_date`, `end_date`, `repeat` FROM `$EventTableName` where `repeat` != 'N' AND `start_date` >= '$laod_recurring_from' ";
72
73 if($DateFormat == 'd-m-Y') $CalFormat = 'dd';
74 if($DateFormat == 'm-d-Y') $CalFormat = 'dd';
75 if($DateFormat == 'Y-m-d') $CalFormat = 'dd'; //coz yy-mm-dd not parsing in a correct date
76
77 //Set Colors: Get Business Hours and open & close days
78 $BusinessHoursTable = $wpdb->prefix . "ap_business_hours";
79 $AllBusinessHours = $wpdb->get_results("SELECT * FROM `$BusinessHoursTable`");
80
81 $TodayColor = ""; //"#FFFFCC";
82 $HeaderColor = ""; //"#E3E3E3";
83 $OpenDayColor = ""; //"#72FE95";
84 $CloseDayColor = ""; //"#FF4848";
85
86 $MonColor = $OpenDayColor;
87 $TueColor = $OpenDayColor;
88 $WedColor = $OpenDayColor;
89 $ThrColor = $OpenDayColor;
90 $FriColor = $OpenDayColor;
91 $SatColor = $OpenDayColor;
92 $SunColor = $OpenDayColor;
93 foreach($AllBusinessHours as $TodayHours) {
94 if($TodayHours->id == 1 & $TodayHours->close == 'yes') { $MonColor = $CloseDayColor; } else { $MonColor = "";}
95 if($TodayHours->id == 2 & $TodayHours->close == 'yes') { $TueColor = $CloseDayColor; } else { $TueColor = "";}
96 if($TodayHours->id == 3 & $TodayHours->close == 'yes') { $WedColor = $CloseDayColor; } else { $WedColor = "";}
97 if($TodayHours->id == 4 & $TodayHours->close == 'yes') { $ThrColor = $CloseDayColor; } else { $ThrColor = "";}
98 if($TodayHours->id == 5 & $TodayHours->close == 'yes') { $FriColor = $CloseDayColor; } else { $FriColor = "";}
99 if($TodayHours->id == 6 & $TodayHours->close == 'yes') { $SatColor = $CloseDayColor; } else { $SatColor = "";}
100 if($TodayHours->id == 7 & $TodayHours->close == 'yes') { $SunColor = $CloseDayColor; } else { $SunColor = "";}
101 } ?>
102
103 <style>
104 .fc-mon {
105 background-color: <?php echo $MonColor; ?>;
106 }
107 .fc-tue {
108 background-color: <?php echo $TueColor; ?>;
109 }
110 .fc-wed {
111 background-color: <?php echo $WedColor; ?>;
112 }
113 .fc-thu {
114 background-color: <?php echo $ThrColor; ?>;
115 }
116 .fc-fri {
117 background-color: <?php echo $FriColor; ?>;
118 }
119 .fc-sat {
120 background-color: <?php echo $SatColor; ?>;
121 }
122 .fc-sun {
123 background-color: <?php echo $SunColor; ?>;
124 }
125 .fc-today
126 {
127 background-color: <?php echo $TodayColor; ?>;
128 }
129 .fc-widget-header{
130 background-color:<?php echo $HeaderColor; ?>;
131 }
132
133 /* .fc-other-month .fc-day-number { display:none;} */
134
135 .selected {
136 outline:1px solid #FF0000; /* Firefox, Opera, Chrome, IE8+ */
137 background-color:#FFFF99;
138 }
139
140 .error{
141 color: #FF0000;
142 }
143
144 /*first modal- 2nd div conflicts css*/
145 .entry form {
146 text-align: left;
147 }
148 </style>
149
150 <script type='text/javascript'>
151 jQuery(document).ready(function() {
152 jQuery('#calendar').fullCalendar({
153 header: {
154 left: 'prev,next today',
155 center: 'title',
156 right: 'month,agendaWeek,agendaDay'
157 },
158 columnFormat: {
159 //month: 'dd/MM/yyyy',
160 //week: 'ddd dd/MM/yyyy',
161 //day: 'dddd dd/MM/yyyy'
162 },
163 titleFormat: {
164 //month: 'dd-MMM-yyyy',
165 //week: "dd-MM-yyyy [ yyyy]{ '—'[ dd]-MM-yyyy}",
166 //day: 'dddd dd-MM-yyyy'
167 },
168 editable: false,
169 weekends: true,
170 timeFormat: <?php if($TimeFormat == 'h:i') echo "'h:mmtt{-h:mmtt }'"; else echo "'H:mm{-H:mm }'"; ?>,
171 axisFormat: <?php if($TimeFormat == 'h:i') echo "'hh:mm'"; else echo "'HH:mm'"; ?>,
172 firstDay: <?php echo $CalStartDay; ?>,
173 slotMinutes: <?php if($AllCalendarSettings['calendar_slot_time'] != '') echo $AllCalendarSettings['calendar_slot_time']; else echo "15"; ?>,
174 defaultView: '<?php if($AllCalendarSettings['calendar_view'] != '') echo $AllCalendarSettings['calendar_view']; else echo "month"; ?>',
175 minTime: <?php if($AllCalendarSettings['day_start_time'] != '') echo date("G", strtotime($AllCalendarSettings['day_start_time'])); else echo "8"; ?>,
176 maxTime: <?php if($AllCalendarSettings['day_end_time'] != '') echo date("G", strtotime($AllCalendarSettings['day_end_time'])); else echo "20"; ?>,
177 monthNames: ["<?php _e("January", "appointzilla"); ?>","<?php _e("February", "appointzilla"); ?>","<?php _e("March", "appointzilla"); ?>","<?php _e("April", "appointzilla"); ?>","<?php _e("May", "appointzilla"); ?>","<?php _e("June", "appointzilla"); ?>","<?php _e("July", "appointzilla"); ?>", "<?php _e("August", "appointzilla"); ?>", "<?php _e("September", "appointzilla"); ?>", "<?php _e("October", "appointzilla"); ?>", "<?php _e("November", "appointzilla"); ?>", "<?php _e("December", "appointzilla"); ?>" ],
178 monthNamesShort: ["<?php _e("Jan", "appointzilla"); ?>","<?php _e("Feb", "appointzilla"); ?>","<?php _e("Mar", "appointzilla"); ?>","<?php _e("Apr", "appointzilla"); ?>","<?php _e("May", "appointzilla"); ?>","<?php _e("Jun", "appointzilla"); ?>","<?php _e("Jul", "appointzilla"); ?>","<?php _e("Aug", "appointzilla"); ?>","<?php _e("Sept", "appointzilla"); ?>","<?php _e("Oct", "appointzilla"); ?>","<?php _e("nov", "appointzilla"); ?>","<?php _e("Dec", "appointzilla"); ?>"],
179 dayNames: ["<?php _e("Sunday", "appointzilla"); ?>","<?php _e("Monday", "appointzilla"); ?>","<?php _e("Tuesday", "appointzilla"); ?>","<?php _e("Wednesday", "appointzilla"); ?>","<?php _e("Thursday", "appointzilla"); ?>","<?php _e("Friday", "appointzilla"); ?>","<?php _e("Saturday", "appointzilla"); ?>"],
180 dayNamesShort: ["<?php _e("Sun", "appointzilla"); ?>","<?php _e("Mon", "appointzilla"); ?>", "<?php _e("Tue", "appointzilla"); ?>", "<?php _e("Wed", "appointzilla"); ?>", "<?php _e("Thus", "appointzilla"); ?>", "<?php _e("Fri", "appointzilla"); ?>", "<?php _e("Sat", "appointzilla"); ?>"],
181 buttonText: {
182 today: "<?php _e("Today", "appointzilla"); ?>",
183 day: "<?php _e("Day", "appointzilla"); ?>",
184 week:"<?php _e("Week", "appointzilla"); ?>",
185 month:"<?php _e("Month", "appointzilla"); ?>"
186 }, <?php
187 if($DateFormat == 'd-m-Y') $DPFormat = 'dd-mm-yy';
188 if($DateFormat == 'm-d-Y') $DPFormat = 'mm-dd-yy';
189 if($DateFormat == 'Y-m-d') $DPFormat = 'yy-mm-dd'; //coz yy-mm-dd not parsing in a correct date ?>
190 selectable: true,
191 selectHelper: false,
192 select: function(start, end, allDay) {
193
194 var appdate = jQuery.datepicker.formatDate('<?php echo $DPFormat; ?>', new Date(start));
195 var appdate2 = jQuery.datepicker.formatDate('dd-mm-yy', new Date(start));
196 var check = jQuery.fullCalendar.formatDate(start,'yyyy-MM-dd');
197 var today = jQuery.fullCalendar.formatDate(new Date(),'yyyy-MM-dd');
198 if(check < today) {
199 // Its a past date
200 alert("<?php _e("Sorry! Appointment cannot be booked for past dates.", "appointzilla"); ?>");
201 } else {
202 // Its a right date
203 jQuery('#appdate').val(appdate);
204 jQuery('#appdate2').val(appdate2);
205 jQuery('#AppFirstModal').show();
206
207 // date-picker tweaks
208 var i;
209 var startdate = jQuery.datepicker.formatDate('yymm', new Date(start));
210 for(i=1; i<=31; i++) {
211 if(i < 10) i = '0' + i;
212 var nextdate = startdate + i;
213 jQuery('#date1_frame').contents().find('#' + nextdate).removeClass('today select');
214 }
215 var todaydate = jQuery.datepicker.formatDate('yymmdd', new Date());
216 jQuery('#date1_frame').contents().find('#' + todaydate).removeClass('select');
217 var cnvtdate = jQuery.datepicker.formatDate('yymmdd', new Date(start));
218 jQuery('#date1_frame').contents().find('#' + cnvtdate).addClass('today select');
219 }
220 },
221
222 events: [
223 <?php //Loading Normal Appointments On Calendar Start
224 $AllAppointments = $wpdb->get_results($FetchAllApps_sql, OBJECT);
225 if($AllAppointments) {
226 foreach($AllAppointments as $single) {
227 $start = date("H, i", strtotime($single->start_time));
228 $end = date("H, i", strtotime($single->end_time));
229
230 //get staff appointment color code
231 $StaffId = $single->staff_id;
232 $StaffData = $wpdb->get_row("SELECT `color` FROM `$StaffTable` WHERE `id` = '$StaffId'");
233 if(count($StaffData)) {
234 $StaffAppointmentColor = $StaffData->color;
235 } else {
236 $StaffAppointmentColor = "#1fcb4a";
237 }
238
239 // subtract 1 from month digit coz calendar work on month 0-11
240 $y = date ( 'Y' , strtotime( $single->date ) );
241 $m = date ( 'n' , strtotime( $single->date ) ) - 1;
242 $d = date ( 'd' , strtotime( $single->date ) );
243 $date = "$y-$m-$d";
244 $date = str_replace("-",", ", $date); ?>
245 {
246 title: "<?php _e('Booked', 'appointzilla'); ?>",
247 start: new Date(<?php echo "$date, $start"; ?>),
248 end: new Date(<?php echo "$date, $end"; ?>),
249 allDay: false,
250 backgroundColor : '<?php echo $StaffAppointmentColor; ?>',
251 textColor: 'black',
252 }, <?php
253 }
254 }
255 //Loading Appointments On Calendar End
256
257 //Loading Recurring Appointments On Calendar Start
258 $AllRecurringAppointments = $wpdb->get_results($FetchAllRApps_sql, OBJECT);
259 if($AllRecurringAppointments) {
260 foreach($AllRecurringAppointments as $single) {
261
262 //get staff appointment color code
263 $StaffId = $single->staff_id;
264 $StaffData = $wpdb->get_row("SELECT `color` FROM `$StaffTable` WHERE `id` = '$StaffId'");
265 if(count($StaffData)) {
266 $StaffAppointmentColor = $StaffData->color;
267 } else {
268 $StaffAppointmentColor = "#1fcb4a";
269 }
270
271 if($single->recurring_type != 'monthly') {
272 $start_time = date("H, i", strtotime($single->start_time));
273 $end_time= date("H, i", strtotime($single->end_time));
274 $start_date = $single->recurring_st_date;
275 $end_date = $single->recurring_ed_date;
276
277 //if appointment type then calculate RTC(recutting date calulation)
278 if($single->recurring_type == 'PD')
279 $RDC = 1;
280 if($single->recurring_type == 'daily')
281 $RDC = 1;
282 if($single->recurring_type == 'weekly')
283 $RDC = 7;
284
285 //calculate all dates
286 $Alldates = array();
287 $st_dateTS = strtotime($start_date);
288 $ed_dateTS = strtotime($end_date);
289 for ($currentDateTS = $st_dateTS; $currentDateTS <= $ed_dateTS; $currentDateTS += (60 * 60 * 24 * $RDC)) {
290 $currentDateStr = date("Y-m-d",$currentDateTS);
291 $AlldatesArr[] = $currentDateStr;
292
293 // subtract 1 from month digit coz calendar work on month 0-11
294 $y = date ( 'Y' , strtotime( $currentDateStr ) );
295 $m = date ( 'n' , strtotime( $currentDateStr ) ) - 1;
296 $d = date ( 'd' , strtotime( $currentDateStr ) );
297 $eachdate = "$y-$m-$d";
298
299 //change format
300 $eachdate = str_replace("-",", ", $eachdate); ?>
301 {
302 title: "<?php _e('Booked', 'appointzilla'); ?>",
303 start: new Date(<?php echo "$eachdate, $start_time"; ?>),
304 end: new Date(<?php echo "$eachdate, $end_time"; ?>),
305 allDay: false,
306 backgroundColor : "<?php echo $StaffAppointmentColor; ?>",
307 textColor: "",
308 }, <?php
309 }// end of date calculation for
310 } else {
311 $start_time = date("H, i", strtotime($single->start_time));
312 $end_time= date("H, i", strtotime($single->end_time));
313
314 $start_date = $single->recurring_st_date;
315 $end_date = $single->recurring_ed_date;
316
317 $i = 0;
318 do {
319 $NextDate = date("Y-m-d", strtotime("+$i months", strtotime($start_date)));
320 // subtract 1 from $startdate month digit coz calendar work on month 0-11
321 $y = date ( 'Y' , strtotime( $NextDate ) );
322 $m = date ( 'n' , strtotime( $NextDate ) ) - 1;
323 $d = date ( 'd' , strtotime( $NextDate ) );
324 $start_date2 = "$y-$m-$d";
325 $start_date2 = str_replace("-",", ", $start_date2); //changing date format
326 $end_date2 = str_replace("-",", ", $start_date2); ?>
327 {
328 title: "<?php _e('Booked', 'appointzilla'); ?>",
329 start: new Date(<?php echo "$start_date2, $start_time"; ?>),
330 end: new Date(<?php echo "$end_date2, $end_time"; ?>),
331 allDay: false,
332 backgroundColor : "<?php echo $StaffAppointmentColor; ?>",
333 textColor: "",
334 }, <?php
335 $i = $i+1;
336 } while(strtotime($end_date) != strtotime($NextDate));
337 }// end of else
338
339 } // end of fetching single appointment foreach
340 } // end of if
341 //Loading Recurring Appointments On Calendar End
342
343
344 //Loading Events On Calendar Start
345 $AllEvents = $wpdb->get_results($FetchAllEvent_sql, OBJECT);
346 if($AllEvents) {
347 foreach($AllEvents as $Event) {
348 //convert time foramt H:i:s
349 $starttime = date("H:i", strtotime($Event->start_time));
350 $endtime = date("H:i", strtotime($Event->end_time));
351 //change time format according to calendar
352 $starttime = str_replace(":",", ", $starttime);
353 $endtime = str_replace(":", ", ", $endtime);
354
355 $startdate = $Event->start_date;
356 // subtract 1 from $startdate month digit coz calendar work on month 0-11
357 $y = date ( 'Y' , strtotime( $startdate ) );
358 $m = date ( 'n' , strtotime( $startdate ) ) - 1;
359 $d = date ( 'd' , strtotime( $startdate ) );
360 $startdate = "$y-$m-$d";
361 $startdate = str_replace("-",", ", $startdate); //changing date format
362
363 $enddate = $Event->end_date;
364 // subtract 1 from $startdate month digit coz calendar work on month 0-11
365 $y2 = date ( 'Y' , strtotime( $enddate ) );
366 $m2 = date ( 'n' , strtotime( $enddate ) ) - 1;
367 $d2 = date ( 'd' , strtotime( $enddate ) );
368 $enddate = "$y2-$m2-$d2";
369 //changing date format
370 $enddate = str_replace("-",", ", $enddate); ?>
371 {
372 title: "<?php echo ucwords($Event->name); ?>",
373 start: new Date(<?php echo "$startdate, $starttime"; ?>),
374 end: new Date(<?php echo "$enddate, $endtime"; ?>),
375 allDay: false,
376 backgroundColor : "#FF7575",
377 textColor: "black",
378 }, <?php
379 }
380 }
381 //Loading Events On Calendar End
382
383 //Loading Recurring Events On Calendar Start
384 $AllREvents = $wpdb->get_results($FetchAllREvent_sql, OBJECT);
385 //don't show event on filtering
386 if($AllREvents) {
387 foreach($AllREvents as $Event) {
388 //convert time foramt H:i:s
389 $starttime = date("H:i", strtotime($Event->start_time));
390 $endtime = date("H:i", strtotime($Event->end_time));
391 //change time format according to calendar
392 $starttime = str_replace(":",", ", $starttime);
393 $endtime = str_replace(":", ", ", $endtime);
394 $startdate = $Event->start_date;
395 $enddate = $Event->end_date;
396
397 if($Event->repeat != 'M') {
398 //if event type then calculate RTC(recutting date calulation)
399 if($Event->repeat == 'PD')
400 $RDC = 1;
401 if($Event->repeat == 'D')
402 $RDC = 1;
403 if($Event->repeat == 'W')
404 $RDC = 7;
405 if($Event->repeat == 'BW')
406 $RDC = 14;
407
408 $Alldates = array();
409 $st_dateTS = strtotime($startdate);
410 $ed_dateTS = strtotime($enddate);
411 for ($currentDateTS = $st_dateTS; $currentDateTS <= $ed_dateTS; $currentDateTS += (60 * 60 * 24 * $RDC)) {
412 $currentDateStr = date("Y-m-d",$currentDateTS);
413 $AlldatesArr[] = $currentDateStr;
414
415 // subtract 1 from $startdate month digit coz calendar work on month 0-11
416 $y = date ( 'Y' , strtotime( $currentDateStr ) );
417 $m = date ( 'n' , strtotime( $currentDateStr ) ) - 1;
418 $d = date ( 'd' , strtotime( $currentDateStr ) );
419 $startdate = "$y-$m-$d";
420 $startdate = str_replace("-",", ", $startdate); //changing date format
421
422 // subtract 1 from $startdate month digit coz calendar work on month 0-11
423 $y2 = date ( 'Y' , strtotime( $currentDateStr ) );
424 $m2 = date ( 'n' , strtotime( $currentDateStr ) ) - 1;
425 $d2 = date ( 'd' , strtotime( $currentDateStr ) );
426 $enddate = "$y2-$m2-$d2";
427
428 $enddate = str_replace("-",", ", $enddate); //changing date format
429 ?>
430 {
431 title: "<?php echo ucwords($Event->name); ?>",
432 start: new Date(<?php echo "$startdate, $starttime"; ?>),
433 end: new Date(<?php echo "$enddate, $endtime"; ?>),
434 allDay: false,
435 backgroundColor : "#FF7575",
436 textColor: "black",
437 }, <?php
438 }
439 } else {
440 $i = 0;
441 do {
442 $NextDate = date("Y-m-d", strtotime("+$i months", strtotime($startdate)));
443 // subtract 1 from $startdate month digit coz calendar work on month 0-11
444 $y = date ( 'Y' , strtotime( $NextDate ) );
445 $m = date ( 'n' , strtotime( $NextDate ) ) - 1;
446 $d = date ( 'd' , strtotime( $NextDate ) );
447 $startdate2 = "$y-$m-$d";
448 $startdate2 = str_replace("-",", ", $startdate2); //changing date format
449 $enddate2 = str_replace("-",", ", $startdate2); ?>
450 {
451 title: "<?php echo ucwords($Event->name); ?>",
452 start: new Date(<?php echo "$startdate2, $starttime"; ?>),
453 end: new Date(<?php echo "$enddate2, $endtime"; ?>),
454 allDay: false,
455 backgroundColor : "#FF7575",
456 textColor: "black",
457 }, <?php
458 $i = $i+1;
459 } while(strtotime($enddate) != strtotime($NextDate));
460 }// enf of else
461 }// end of foreach
462 }// end of if check
463 //Loading Recurring Events On Calendar End
464 ?>
465 {
466 }
467 ]
468 });
469
470 //Modal Form Works
471 //show first modal
472 jQuery('#addappointment').click(function(){
473 jQuery('#AppFirstModal').show();
474 });
475 //hide modal
476 jQuery('#close').click(function(){
477 jQuery('#AppFirstModal').hide();
478 });
479
480 <?php if($DateFormat == 'd-m-Y') $DPFormat = 'dd-mm-yy';
481 if($DateFormat == 'm-d-Y') $DPFormat = 'mm-dd-yy';
482 if($DateFormat == 'Y-m-d') $DPFormat = 'yy-mm-dd'; //coz yy-mm-dd not parsing in a correct date
483
484 if($small_calendar_type == "jquery") {
485 ?>
486 //jQuery UI date picker on modal for
487 document.addnewappointment.appdate.value = jQuery.datepicker.formatDate('<?php echo $DPFormat; ?>', new Date());
488 jQuery(function(){
489 jQuery("#datepicker").datepicker({
490 inline: true,
491 minDate: 0,
492 altField: '#alternate',
493 firstDay: <?php if($AllCalendarSettings['calendar_start_day'] != '') echo $AllCalendarSettings['calendar_start_day']; else echo "0"; ?>,
494 //beforeShowDay: unavailable,
495 onSelect: function(dateText, inst) {
496 var dateAsString = dateText;
497 var seleteddate = jQuery.datepicker.formatDate('<?php echo $DPFormat; ?>', new Date(dateAsString));
498 var seleteddate2 = jQuery.datepicker.formatDate('dd-mm-yy', new Date(dateAsString));
499 document.addnewappointment.appdate.value = seleteddate;
500 document.addnewappointment.appdate2.value = seleteddate2;
501 },
502 });
503 //jQuery( "#datepicker" ).datepicker( jQuery.datepicker.regional[ "af" ] );
504 });
505 <?php } ?>
506
507 //AppFirstModal Validation
508 jQuery('#next1').click(function(){
509 jQuery(".error").hide();
510 if(jQuery('#service').val() == 0)
511 {
512 jQuery("#service").after("<span class='error'><br><strong><?php _e('Select Any Service.', 'appointzilla'); ?></strong><br></span>");
513 return false;
514 }
515 });
516
517 //back button show first modal
518 jQuery('#back').click(function(){
519 jQuery('#AppFirstModal').show();
520 jQuery('#AppSecondModal').hide();
521 });
522
523 });
524
525 //Modal Form Works
526 function LoadSecondModal() {
527 var ServiceId = jQuery('#servicelist').val();
528 var AppDate = jQuery('#appdate2').val();
529 var StaffId = jQuery('#stafflist').val();
530 var SecondData = "ServiceId=" + ServiceId + "&AppDate=" + AppDate + "&StaffId=" + StaffId;
531 jQuery('#loading1').show(); // loading button onclick next1 at first modal
532 jQuery('#next1').hide(); //hide next button
533 jQuery.ajax({
534 dataType : 'html',
535 type: 'GET',
536 url : location.href,
537 cache: false,
538 data : SecondData,
539 complete : function() { },
540 success: function(data) {
541 data = jQuery(data).find('div#AppSecondModalData');
542 jQuery('#loading1').hide();
543 jQuery('#AppFirstModal').hide();
544 jQuery('#AppSecondModal').show();
545 jQuery('#AppSecondModal').html(data);
546 }
547 });
548 }
549
550 //load first modal on click back1
551 function LoadFirstModal() {
552 jQuery('#AppSecondModal').hide()
553 jQuery('#AppFirstModal').show();
554 jQuery('#next1').show();
555 }
556
557 //load second modal on back2 click
558 function LoadSecondModal2() {
559 jQuery('#AppThirdModal').hide();
560 jQuery('#buttondiv').show();
561 jQuery('#AppSecondModal').show();
562 }
563
564 //on new user button click
565 function NewUserBtn() {
566 jQuery('#new-user-div').show();
567 jQuery('#existing-user-div').hide();
568 jQuery('#check-email-result-div').hide();
569 }
570
571 //on existing user button click
572 function ExistingUserBtn() {
573 jQuery('#new-user-div').hide();
574 jQuery('#existing-user-div').show();
575 jQuery('#check-email-div-form').show();
576 }
577
578 //load third modal on-click next2
579 function LoadThirdModal() {
580 //validation on second modal form
581 jQuery('.error').hide();
582 var ServiceId = jQuery('#ServiceId').val();
583 var AppDate = jQuery('#AppDate').val();
584 var StaffId = jQuery('#StaffId').val();
585 var Start_Time = jQuery('input[name=start_time]:radio:checked').val();
586 if(!Start_Time) {
587 jQuery("#time_slot_box").after("<span style='width:auto; margin-left:5%;' class='error'><strong><?php _e('Select any time.', 'appointzilla'); ?></strong></span>");
588 return false;
589 }
590 var ThirdData = "ServiceId=" + ServiceId + "&AppDate=" + AppDate + "&StaffId=" + StaffId + "&StartTime=" + Start_Time ;
591 jQuery('#buttondiv').hide();
592 jQuery('#loading').show();
593 jQuery.ajax({
594 dataType : 'html',
595 type: 'GET',
596 url : location.href,
597 cache: false,
598 data : ThirdData,
599 complete : function() { },
600 success: function(data) {
601 data = jQuery(data).find('div#AppThirdModalData');
602 jQuery('#loading').hide();
603 jQuery('#AppSecondModal').hide();
604 jQuery('#AppThirdModal').show();
605 jQuery('#AppThirdModal').html(data);
606 }
607 });
608 }
609
610
611 //load forth final modal for confirm appointment
612 function CheckValidation(UserType) {
613
614 jQuery('.error').hide();
615 var ServiceId = jQuery('#ServiceId').val();
616 var AppDate = jQuery('#AppDate').val();
617 var StaffId = jQuery('#StaffId').val();
618 var StartTime = jQuery('#StartTime').val();
619
620 /**
621 * new user booking case
622 */
623 if(UserType == "NewUser") {
624 <?php if($AllCalendarSettings['apcal_user_registration'] == "yes"){ ?>
625 var ClientUserName = jQuery("#client-username").val();
626 var ClientPassword = jQuery("#client-password").val();
627 var ClientConfirmPassword = jQuery("#client-confirm-password").val();
628 <?php } ?>
629 var ClientEmail = jQuery("#client-email").val();
630 var ClientFirstName = jQuery("#client-first-name").val();
631 var ClientLastName = jQuery("#client-last-name").val();
632 var ClientPhone = jQuery("#client-phone").val();
633 var ClientSi = jQuery("#client-si").val();
634
635 <?php if($AllCalendarSettings['apcal_user_registration'] == "yes"){ ?>
636 //client username
637 if (ClientUserName == "") {
638 jQuery("#client-username").after("<span class='error'> <br><strong><?php _e('Username required.', 'appointzilla'); ?></strong></span>");
639 return false;
640 } else {
641
642 if(ClientUserName.length < 6) {
643 jQuery("#client-username").after("<span class='error'> <br><strong><?php _e('Choose a strong username.', 'appointzilla'); ?></strong></span>");
644 return false;
645 }
646 var Res = isNaN(ClientUserName);
647 if(Res == false) {
648 jQuery("#client-username").after("<span class='error'> <br><strong><?php _e('Invalid username.', 'appointzilla'); ?></strong></span>");
649 return false;
650 }
651 }
652
653 //client password
654 if (ClientPassword == "") {
655 jQuery("#client-password").after("<span class='error'> <br><strong><?php _e('Password required.', 'appointzilla'); ?></strong></span>");
656 return false;
657 } else {
658
659 if(ClientPassword.length < 6) {
660 jQuery("#client-password").after("<span class='error'> <br><strong><?php _e('Choose a strong password.', 'appointzilla'); ?></strong></span>");
661 return false;
662 }
663 }
664
665 //client confirm password
666 if (ClientConfirmPassword == "") {
667 jQuery("#client-confirm-password").after("<span class='error'> <br><strong><?php _e('Confirm password required.', 'appointzilla'); ?></strong></span>");
668 return false;
669 } else {
670 if(ClientConfirmPassword != ClientPassword) {
671 jQuery("#client-confirm-password").after("<span class='error'> <br><strong><?php _e('Confirm password do not match', 'appointzilla'); ?></strong></span>");
672 return false;
673 }
674 }
675 <?php } ?>
676
677 //client email
678 var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
679 if (ClientEmail == "") {
680 jQuery("#client-email").after("<span class='error'> <br><strong><?php _e('Email required.', 'appointzilla'); ?></strong></span>");
681 return false;
682 } else {
683 if(regex.test(ClientEmail) == false ) {
684 jQuery("#client-email").after("<span class='error'> <br><strong><?php _e('Invalid email.', 'appointzilla'); ?></strong></span>");
685 return false;
686 }
687 }
688
689 //client first name
690 if (ClientFirstName == "") {
691 jQuery("#client-first-name").after("<span class='error'> <br><strong><?php _e('First name required.', 'appointzilla'); ?></strong></span>");
692 return false;
693 } else {
694 var Res = isNaN(ClientFirstName);
695 if(Res == false) {
696 jQuery("#client-first-name").after("<span class='error'> <br><strong><?php _e('Invalid first name.', 'appointzilla'); ?></strong></span>");
697 return false;
698 }
699 var NameRegx = /^[a-zA-Z0-9- ]*$/;
700 if(NameRegx.test(ClientFirstName) == false) {
701 jQuery("#client-first-name").after("<span class='error'> <br><strong><?php _e('No special characters allowed.', 'appointzilla'); ?></strong></span>");
702 return false;
703 }
704 }
705
706 //client last name
707 if (ClientLastName == "") {
708 jQuery("#client-last-name").after("<span class='error'> <br><strong><?php _e('Last name required.', 'appointzilla'); ?></strong></span>");
709 return false;
710 } else {
711 var Res = isNaN(ClientLastName);
712 if(Res == false) {
713 jQuery("#client-last-name").after("<span class='error'> <br><strong><?php _e('Invalid last name.', 'appointzilla'); ?></strong></span>");
714 return false;
715 }
716 var NameRegx = /^[a-zA-Z0-9- ]*$/;
717 if(NameRegx.test(ClientLastName) == false) {
718 jQuery("#client-last-name").after("<span class='error'> <br><strong><?php _e('No special characters allowed.', 'appointzilla'); ?></strong></span>");
719 return false;
720 }
721 }
722
723 //client phone
724 if (ClientPhone == "") {
725 jQuery("#client-phone").after("<span class='error'> <br><strong><?php _e("Phone required. <br>Only Numbers 1234567890.", "appointzilla"); ?></strong></span>");
726 return false;
727 } else {
728 var ClientPhoneRes = isNaN(ClientPhone);
729 if(ClientPhoneRes == true) {
730 jQuery("#client-phone").after("<span class='error'> <br><strong><?php _e("Invalid phone. <br>Numbers only: 1234567890.", "appointzilla"); ?></strong></span>");
731 return false;
732 }
733 }
734
735 var PostData1 = "Action=BookAppointment"+ "&ServiceId=" + ServiceId + "&AppDate=" + AppDate + "&StaffId=" + StaffId + "&StartTime=" + StartTime;
736 <?php if($AllCalendarSettings['apcal_user_registration'] == "yes"){ ?>
737 var PostData2 = "&UserType=" + UserType + "&ClientUserName="+ ClientUserName + "&ClientPassword=" +ClientPassword + "&ClientEmail=" + ClientEmail;
738 <?php } else { ?>
739 var PostData2 = "&UserType=" + UserType + "&ClientEmail=" + ClientEmail;
740 <?php } ?>
741 var PostData3 = "&ClientFirstName=" + ClientFirstName + "&ClientLastName=" + ClientLastName + "&ClientPhone=" + ClientPhone + "&ClientNote=" + ClientSi;
742 var PostData = PostData1 + PostData2 + PostData3;
743
744 jQuery('#new-user-form-btn-div').hide();
745 jQuery('#new-user-form-loading-img').show();
746 }
747
748 /**
749 * existing user booking case
750 */
751 if(UserType == "ExUser") {
752
753 var ClientEmail = jQuery("#ex-client-email").val();
754 var ClientFirstName = jQuery("#ex-client-first-name").val();
755 var ClientLastName = jQuery("#ex-client-last-name").val();
756 var ClientPhone = jQuery("#ex-client-phone").val();
757 var ClientSi = jQuery("#ex-client-si").val();
758
759 //client email
760 var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
761 if (ClientEmail == "") {
762 jQuery("#ex-client-email").after("<span class='error'> <br><strong><?php _e('Email required.', 'appointzilla'); ?></strong></span>");
763 return false;
764 } else {
765 if(regex.test(ClientEmail) == false ) {
766 jQuery("#ex-client-email").after("<span class='error'> <br><strong><?php _e('Invalid email.', 'appointzilla'); ?></strong></span>");
767 return false;
768 }
769 }
770
771 //client first name
772 if (ClientFirstName == "") {
773 jQuery("#ex-client-first-name").after("<span class='error'> <br><strong><?php _e('First name required.', 'appointzilla'); ?></strong></span>");
774 return false;
775 } else {
776 var Res = isNaN(ClientFirstName);
777 if(Res == false) {
778 jQuery("#ex-client-first-name").after("<span class='error'> <br><strong><?php _e('Invalid first name.', 'appointzilla'); ?></strong></span>");
779 return false;
780 }
781 var NameRegx = /^[a-zA-Z0-9- ]*$/;
782 if(NameRegx.test(ClientFirstName) == false) {
783 jQuery("#ex-client-first-name").after("<span class='error'> <br><strong><?php _e('No special characters allowed.', 'appointzilla'); ?></strong></span>");
784 return false;
785 }
786 }
787
788 //client last name
789 if (ClientLastName == "") {
790 jQuery("#ex-client-last-name").after("<span class='error'> <br><strong><?php _e('Last name required.', 'appointzilla'); ?></strong></span>");
791 return false;
792 } else {
793 var Res = isNaN(ClientLastName);
794 if(Res == false) {
795 jQuery("#ex-client-last-name").after("<span class='error'> <br><strong><?php _e('Invalid last name.', 'appointzilla'); ?></strong></span>");
796 return false;
797 }
798 var NameRegx = /^[a-zA-Z0-9- ]*$/;
799 if(NameRegx.test(ClientLastName) == false) {
800 jQuery("#ex-client-last-name").after("<span class='error'> <br><strong><?php _e('No special characters allowed.', 'appointzilla'); ?></strong></span>");
801 return false;
802 }
803 }
804
805 //client phone
806 if (ClientPhone == "") {
807 jQuery("#ex-client-phone").after("<span class='error'> <br><strong><?php _e("Phone required. <br>Only Numbers 1234567890.", "appointzilla"); ?></strong></span>");
808 return false;
809 } else {
810 var ClientPhoneRes = isNaN(ClientPhone);
811 if(ClientPhoneRes == true) {
812 jQuery("#ex-client-phone").after("<span class='error'> <br><strong><?php _e("Invalid phone. <br>Numbers only: 1234567890.", "appointzilla"); ?></strong></span>");
813 return false;
814 }
815 }
816
817 var PostData1 = "Action=BookAppointment"+ "&ServiceId=" + ServiceId + "&AppDate=" + AppDate + "&StaffId=" + StaffId + "&StartTime=" + StartTime;
818 var PostData2 = "&UserType=" + UserType + "&ClientEmail=" + ClientEmail;
819 var PostData3 = "&ClientFirstName=" + ClientFirstName + "&ClientLastName=" + ClientLastName + "&ClientPhone=" + ClientPhone + "&ClientNote=" + ClientSi;
820 var PostData = PostData1 + PostData2 + PostData3;
821
822 jQuery('#ex-user-form-btn-div').hide();
823 jQuery('#ex-user-form-loading-img').show();
824 }
825
826 jQuery.ajax({
827 dataType : 'html',
828 type: 'POST',
829 url : location.href,
830 cache: false,
831 data : PostData,
832 complete : function() { },
833 success: function(data) {
834 data = jQuery(data).find('div#AppForthModalData');
835 jQuery("#new-user-form-loading-img").hide();
836 jQuery("#check-email-div-form").hide();
837 jQuery("#AppThirdModal").hide();
838 jQuery("#AppForthModalFinal").show();
839 jQuery("#AppForthModalFinal").html(data);
840 }
841 });
842 }
843
844 //check existing user
845 function CheckExistingUser() {
846 jQuery(".error").hide();
847 var ClientEmail = jQuery("#check-client-email").val();
848 //client email
849 var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
850 if (ClientEmail == "") {
851 jQuery("#check-client-email").after("<span class='error'> <br><strong><?php _e('Email required.', 'appointzilla'); ?></strong></span>");
852 return false;
853 } else {
854 if(regex.test(ClientEmail) == false ) {
855 jQuery("#check-client-email").after("<span class='error'> <br><strong><?php _e('Invalid email.', 'appointzilla'); ?></strong></span>");
856 return false;
857 }
858 }
859
860 var PostData = "Action=CheckExistingUser" + "&ClientEmail=" + ClientEmail;
861 jQuery("#existing-user-form-btn").hide();
862 jQuery("#existing-user-loading-img").show();
863 jQuery.ajax({
864 dataType : 'html',
865 type: 'POST',
866 url : location.href,
867 cache: false,
868 data : PostData,
869 complete : function() { },
870 success: function(Data) {
871 Data = jQuery(Data).find('div#check-email-result');
872 jQuery("#existing-user-loading-img").hide();
873 jQuery("#check-user").hide();
874 jQuery('#check-email-div-form').hide();
875 jQuery("#check-email-result-div").show();
876 jQuery("#check-email-result-div").html(Data);
877 }
878 });
879 }
880
881 function CloseModelform() {
882 jQuery("#AppForthModalFinal").hide();
883 jQuery("#AppSecondModalData").hide();
884 jQuery("#AppThirdModalData").hide();
885 jQuery("#ex-pay-canceling-img").show();
886 location.href = location.href;
887 }
888
889 function highlightsradio(timeslotspanid) {
890 jQuery('span').removeClass('selected');
891 var spanid = "#" + timeslotspanid;
892 jQuery(spanid).addClass("selected");
893 }
894
895 // failed appointment
896 function failedappointment() {
897 var appid = jQuery('#appid').val();
898 var Datastring = "appstatus=cancel" + "&appid="+ appid;
899 jQuery.ajax({
900 dataType : 'html',
901 type: 'POST',
902 url : location.href,
903 cache: false,
904 data : Datastring,
905 complete : function() { },
906 success: function(data) {
907 jQuery('#AppForthModalFinal').hide();
908 jQuery('#AppSecondModalData').hide();
909 jQuery('#AppThirdModalData').hide();
910 var CurrentUrl = location.href;
911 CurrentUrl=CurrentUrl.replace('failed=failed&appointId='+appid, '');
912 location.href = CurrentUrl;
913 }
914 });
915 }
916
917 //cancel appointment
918 function CancelAppointment() {
919 var appid = jQuery('#appid').val();
920 var DataString = "appstatus=cancel" + "&appid="+ appid;
921 jQuery("#paybuttondiv").hide();
922 jQuery("#pay-canceling-img").show();
923 jQuery.ajax({
924 dataType : 'html',
925 type: 'POST',
926 url : location.href,
927 cache: false,
928 data : DataString,
929 complete : function() { },
930 success: function() {
931 jQuery('#AppForthModalFinal').hide();
932 jQuery('#AppSecondModalData').hide();
933 jQuery('#AppThirdModalData').hide();
934 window.location.reload();
935 }
936 });
937 }
938
939 //apply coupon code
940 function ApplyCoupon() {
941 var CouponCode = jQuery("#coupon-code").val();
942 if(CouponCode == "") {
943 alert("<?php _e("Enter any coupon code.", "appointzilla"); ?>");
944 jQuery("#coupon-code").focus();
945 return false;
946 } else {
947 var PostData = "Action=apply-coupon" + "&CouponCode=" + CouponCode;
948 jQuery("#loading-img").show();
949 jQuery.ajax({
950 dataType : 'html',
951 type: 'POST',
952 url : location.href,
953 cache: false,
954 data : PostData,
955 complete : function() { },
956 success: function(ReturnedData) {
957 ReturnedData = jQuery(ReturnedData).find("div#coupon-result");
958 jQuery("#loading-img").hide();
959 jQuery("#apply-coupon-div").hide();
960 jQuery("#show-coupon-result").html(ReturnedData);
961 jQuery("#show-coupon-result").show();
962 var CouponCodeValue = jQuery("#coupon-code-div").text();
963 var DicountRateValue = jQuery("#discount-rate-div").text();
964 jQuery("input[name=custom]").val(CouponCodeValue);
965 jQuery("input[name=discount_rate]").val(DicountRateValue);
966 }
967 });
968 }
969 }
970
971 //try another coupon code
972 function TryAgain() {
973 jQuery("#apply-coupon-div").show();
974 jQuery("#show-coupon-result").hide();
975 }
976
977 //try again booking
978 function TryAgainBooking() {
979 jQuery("#check-email-result-div").hide();
980 jQuery("#check-user").show();
981 jQuery('#check-email-div-form').show();
982 jQuery("#existing-user-form-btn").show();
983 }
984
985 //cancel appointment
986 function Canceling() {
987 jQuery("#ex-user-form-btn-div").hide();
988 jQuery("#ex-canceling-img").show();
989 location.reload();
990 }
991
992 // on paypal pay button click
993 function PayWithPaypal(){
994 jQuery('#show-redirecting-msg').show();
995 jQuery('#paybuttondiv').hide();
996 }
997 </script>
998
999 <!---Display Booking Instruction--->
1000 <?php if($AllCalendarSettings['apcal_booking_instructions']) { ?>
1001 <div id="bookinginstructions" align="center">
1002 <?php echo $AllCalendarSettings['apcal_booking_instructions']; ?>
1003 </div>
1004 <?php } ?>
1005
1006 <!---Schedule An Appointment Button--->
1007 <div id="bkbtndiv" align="center" style="padding:10px;">
1008 <button name="addappointment" class="apcal_btn apcal_btn-large apcal_btn-primary" type="submit" id="addappointment">
1009 <strong><i class="icon-calendar icon-white"></i> <?php if(isset($AllCalendarSettings['booking_button_text'])) {
1010 echo $AllCalendarSettings['booking_button_text'];
1011 } else {
1012 _e("Schedule New Appointment", 'appointzilla');
1013 } ?>
1014 </strong>
1015 </button>
1016 </button>
1017 </div>
1018
1019 <!---Show appointment calendar--->
1020 <div id='calendar'>
1021 <div style="text-align: right; font-size: small;">Appointment Calendar Premium Powered By: <a href="http://appointzilla.com/" title="Online Appointment Scheduling Plugin For WordPress" target="_blank">AppointZilla</a></div>
1022 </div>
1023
1024 <!---AppFirstModal For Schedule New Appointment--->
1025 <div id="AppFirstModal" style="display:none;">
1026 <div class="apcal_modal" id="myModal" style="z-index:10000;">
1027 <form action="" method="post" name="addnewappointment" id="addnewappointment">
1028 <div class="apcal_modal-info">
1029 <div class="apcal_alert apcal_alert-info">
1030 <a href="#bookinginstructions" style="float:right; margin-right:4px; margin-top:12px;" id="close"><i class="icon-remove"></i></a>
1031 <p><strong><?php _e('Schedule New Appointment', 'appointzilla'); ?></strong></p>
1032 <div><?php _e('Step 1. Select Date & Service', 'appointzilla'); ?></div>
1033 </div>
1034 </div>
1035
1036 <div class="apcal_modal-body">
1037 <div id="firdiv" style="float:left; height:210px; width:260px; padding-bottom:30px;">
1038 <!--JS Datepicker -->
1039 <?php if($small_calendar_type == "jquery") { ?>
1040 <div id="datepicker"></div>
1041 <?php } ?>
1042 <!--PHP Datepicker-->
1043 <?php
1044 if($DateFormat == 'd-m-Y') $CalFormat = 'DD-MM-YYYY';
1045 if($DateFormat == 'm-d-Y') $CalFormat = 'MM-DD-YYYY';
1046 if($DateFormat == 'Y-m-d') $CalFormat = 'YYYY-MM-DD'; //coz yy-mm-dd not
1047 if($small_calendar_type == "php") {
1048 $myCalendar->writeScript();
1049 }
1050 ?>
1051 <script>
1052 function myChanged() {
1053 var x = document.getElementById('date1').value;
1054 var x2 = document.getElementById('date1').value;
1055 x = moment(x).format('<?php echo $CalFormat; ?>');
1056 x2 = moment(x2).format('DD-MM-YYYY');
1057 document.getElementById('appdate').value = x;
1058 document.getElementById('appdate2').value = x2;
1059 }
1060 </script>
1061 </div>
1062
1063 <div id="secdiv" style="float:right; margin-right:5%; width:40%" >
1064 <strong><?php _e('Your Appointment Date:', 'appointzilla'); ?> </strong><br>
1065 <input name="appdate" id="appdate" type="text" readonly="" style="height:30px; width:100%; padding-left: 15px;" value="<?php echo date($DateFormat, strtotime($StartDate)); ?>" /><br>
1066 <input name="appdate2" id="appdate2" type="hidden" readonly="" style="height:30px; width:100%" value="<?php echo date("Y-m-d", strtotime($StartDate)); ?>" />
1067 <?php global $wpdb;
1068 $CategoryTable = $wpdb->prefix."ap_service_category";
1069 $FindCategorySQL ="SELECT * FROM `$CategoryTable` order by `name` ASC";
1070 $AllCategory = $wpdb->get_results($FindCategorySQL, OBJECT); ?>
1071
1072 <style type="text/css"> .mycss { font-weight:bold; } </style>
1073 <strong><?php _e('Select Service:', 'appointzilla'); ?></strong><br>
1074 <select name="servicelist" id="servicelist" style="width:100%">
1075 <option value="0"><?php _e('Select Service', 'appointzilla'); ?></option>
1076 <?php $cal_admin_currency_id = get_option('cal_admin_currency');
1077 if($cal_admin_currency_id) {
1078 $CurrencyTableName = $wpdb->prefix . "ap_currency";
1079 $cal_admin_currency = $wpdb->get_row("SELECT `symbol` FROM `$CurrencyTableName` WHERE `id` = '$cal_admin_currency_id'");
1080 $cal_admin_currency = $cal_admin_currency->symbol;
1081 } else {
1082 $cal_admin_currency = "$";
1083 }
1084
1085 if($AllCalendarSettings['show_service_cost'] == 'yes') $ShowCost = 1; else $ShowCost = 0;
1086 if($AllCalendarSettings['show_service_duration'] == 'yes') $ShowDuration = 1; else $ShowDuration = 0;
1087 $ServiceTable = $wpdb->prefix."ap_services";
1088 foreach($AllCategory as $Category) {
1089 echo "<option value='$Category->id' disabled class='mycss'>".ucwords($Category->name)."</option>";
1090 $FindServiceSQL = "SELECT * FROM `$ServiceTable` WHERE `availability` = 'yes' and `category_id` = '$Category->id' order by `name` ASC";
1091 $AllService = $wpdb->get_results($FindServiceSQL, OBJECT);
1092 if(count($AllService)) {
1093 foreach($AllService as $Service) { ?>
1094 <option value="<?php echo $Service->id; ?>">
1095 <?php echo ucwords($Service->name);
1096 if($ShowDuration || $ShowCost) echo " (";
1097 if($ShowDuration) { echo $Service->duration."min"; } if($ShowDuration && $ShowCost) echo "/";
1098 if($ShowCost) { echo $cal_admin_currency. $Service->cost; }
1099 if($ShowDuration || $ShowCost) echo ")"; ?>
1100 </option><?php
1101 }
1102 } else {
1103 echo "<option disabled> ".ucwords(__('No service in this category', 'appointzilla'))."</option>";
1104 }
1105 } ?>
1106 </select>
1107 <br>
1108 <script type="text/javascript">
1109 //load staff according to service - start
1110 jQuery('#servicelist').change(function(){
1111
1112 var ServiceId = jQuery("select#servicelist").val();
1113 if(ServiceId > 0) {
1114 jQuery('#loading-staff').show();
1115 jQuery('#staff').hide();
1116 var FirstData = "ServiceId=" + ServiceId;
1117 jQuery.ajax({
1118 dataType : 'html',
1119 type: 'GET',
1120 url : location.href,
1121 data : FirstData,
1122 complete : function() { },
1123 success: function(data) {
1124 data=jQuery(data).find('div#stfflistdiv');
1125 jQuery('#staff').show();
1126 jQuery('#loading-staff').hide();
1127 jQuery('#staff').html(data);
1128 }
1129 });
1130 } else {
1131 jQuery('#staff').hide();
1132 }
1133 });
1134 </script>
1135 <div id="loading-staff" style="display:none;"><?php _e('Loading Staff...', 'appointzilla'); ?><img src="<?php echo plugins_url('images/loading.gif', __FILE__); ?>" /></div>
1136 <div id="staff"></div>
1137 </div><!--#secdiv-->
1138 </div><!--#modal-body-->
1139 </form>
1140 </div>
1141 </div>
1142 <!---AppSecondModal For Schedule New Appointment--->
1143
1144 <!---AppSecondModal For Schedule New Appointment--->
1145 <div id="AppSecondModal" style="display:none;"></div>
1146 <!---AppSecondModal For Schedule New Appointment End--->
1147
1148 <!---AppThirdModal For Schedule New Appointment--->
1149 <div id="AppThirdModal" style="display:none;"></div>
1150 <!---AppThirdModal For Schedule New Appointment End--->
1151 <div id="AppForthModalFinal" style="display:none;">
1152
1153 </div>
1154 <!---AppThirdModal For Schedule New Appointment End--->
1155
1156 <!--date-picker js -->
1157 <script src="<?php echo plugins_url('/menu-pages/datepicker-assets/js/jquery.ui.datepicker.js', __FILE__); ?>" type="text/javascript"></script>
1158
1159 <!---Loading staff ajax return code--->
1160 <?php if(isset($_GET['ServiceId'])) { ?>
1161 <!---load bootstrap css--->
1162 <link rel='stylesheet' type='text/css' href='<?php echo plugins_url('/bootstrap-assets/css/bootstrap.css', __FILE__); ?>' />
1163 <div id="stfflistdiv">
1164 <?php
1165 $ServiceID = $_GET['ServiceId'];
1166 if($ServiceID) {
1167 $ServiceTable = $wpdb->prefix . "ap_services";
1168 $StaffTable = $wpdb->prefix . "ap_staff";
1169 $AllStaffIdList = $wpdb->get_row("SELECT `staff_id` FROM `$ServiceTable` WHERE `id` = '$ServiceID'", OBJECT);
1170 $AllStaffIdList = unserialize($AllStaffIdList->staff_id);
1171 if(count($AllStaffIdList) > 1) {
1172 ?>
1173 <strong><?php _e('Select Staff:', 'appointzilla'); ?></strong><br>
1174 <select name='stafflist' id='stafflist' style="width:100%">
1175 <?php //get all staff id list by service id
1176
1177 if(count($AllStaffIdList)) {
1178 foreach($AllStaffIdList as $StaffId) {
1179 $StaffDetails = $wpdb->get_row("SELECT `id`, `name` FROM `$StaffTable` WHERE `id` = '$StaffId'", OBJECT);
1180 echo "<option value='".$StaffDetails->id."'> ".ucwords($StaffDetails->name)."</option>";
1181 }
1182 } else {
1183 echo "<option value='1'>".__("No Staff Assigned")."</option>";
1184 }
1185 ?>
1186 </select>
1187 <br>
1188 <script>
1189 var tesr = sortSelect(document.getElementById('stafflist'));
1190
1191 function sortSelect(selElem) {
1192 var tmpAry = new Array();
1193 for (var i=0;i<selElem.options.length;i++) {
1194 tmpAry[i] = new Array();
1195 tmpAry[i][0] = selElem.options[i].text;
1196 tmpAry[i][1] = selElem.options[i].value;
1197 }
1198 tmpAry.sort();
1199 tmpAry.reverse();
1200 while (selElem.options.length > 0) {
1201 selElem.options[0] = null;
1202 }
1203 for (var i=0;i<tmpAry.length;i++) {
1204 var op = new Option(tmpAry[i][0], tmpAry[i][1]);
1205 selElem.options[i] = op;
1206 }
1207
1208 //return tmpAry;
1209 }
1210 </script>
1211 <?php
1212 } else { // end of count > 1
1213 if(count($AllStaffIdList)) {
1214 foreach($AllStaffIdList as $StaffId) {
1215 $StaffDetails = $wpdb->get_row("SELECT `id`, `name` FROM `$StaffTable` WHERE `id` = '$StaffId'", OBJECT);
1216 echo "<input type='hidden' name='stafflist' id='stafflist' value='$StaffDetails->id'>";
1217 }
1218 }
1219 } // end of count > 1 else
1220 ?>
1221 <button type="button" class="apcal_btn" id="next1" name="next1" onclick="LoadSecondModal()"><?php _e('Next', 'appointzilla'); ?> <i class="icon-arrow-right"></i></button>
1222 <div id="loading1" style="display:none;"><?php _e('Loading...', 'appointzilla'); ?><img src="<?php echo plugins_url("images/loading.gif", __FILE__); ?>" /></div>
1223 <?php } //end of service id if ?>
1224 </div><?php
1225 } ?>
1226
1227
1228 <!---loading second modal form ajax return code--->
1229 <?php require_once('shortcode-time-slot-calculation.php'); ?>
1230 <!---loading second modal form ajax return code--->
1231
1232
1233 <!---loading third modal form ajax return code--->
1234 <?php
1235 if( isset($_GET['StartTime']) && isset($_GET['StaffId']) ) { ?>
1236 <div id="AppThirdModalData">
1237 <div class="apcal_modal" id="AppThirdModal" style="z-index:10000;">
1238 <input name="ServiceId" id="ServiceId" type="hidden" value="<?php if(isset($_GET['ServiceId'])) { echo $_GET['ServiceId']; } ?>" />
1239 <input name="StaffId" id="StaffId" type="hidden" value="<?php if(isset($_GET['StaffId'])) { echo $_GET['StaffId']; } ?>" />
1240 <input name="AppDate" id="AppDate" type="hidden" value="<?php if(isset($_GET['AppDate'])) { echo $_GET['AppDate']; } ?>" />
1241 <input name="StartTime" id="StartTime" type="hidden" value="<?php if(isset($_GET['StartTime'])) { echo $_GET['StartTime']; } ?>" />
1242 <input name="EndTime" id="EndTime" type="hidden" value="<?php if(isset($_GET['EndTime'])) { echo $_GET['EndTime']; } ?>" />
1243 <input name="RecurringType" id="RecurringType" type="hidden" value="<?php if(isset($_GET['RecurringType'])) { echo $_GET['RecurringType']; } ?>" />
1244 <input name="RecurringStartDate" id="RecurringStartDate" type="hidden" value="<?php if(isset($_GET['recurring_start_date'])) { echo $_GET['recurring_start_date']; } ?>" />
1245 <input name="RecurringEndDate" id="RecurringEndDate" type="hidden" value="<?php if(isset($_GET['recurring_end_date'])) { echo $_GET['recurring_end_date']; } ?>" />
1246
1247 <div class="apcal_modal-info">
1248 <a href="" onclick="CloseModelform()" style="float:right; margin-right:40px; margin-top:21px;" id="close" ><i class="icon-remove"></i></a>
1249 <div class="apcal_alert apcal_alert-info">
1250 <p><strong><?php _e('Schedule New Appointment', 'appointzilla'); ?></strong></p>
1251 <?php _e('Step 3. Complete Your Booking', 'appointzilla'); ?>
1252 </div>
1253 </div>
1254
1255 <div class="apcal_modal-body">
1256 <?php if($AllCalendarSettings['apcal_user_registration'] == "yes") { ?>
1257 <!--check user div-->
1258 <div id="check-user">
1259 <table width="100%" class="table">
1260 <tr>
1261 <td colspan="3">
1262 <button id="new-user" name="new-user" class="apcal_btn apcal_btn-info" onclick="return NewUserBtn();"><i class="fa fa-user"></i> <?php _e("New User", "appointzilla"); ?></button>
1263 <button id="existing-user" name="existing-user" class="apcal_btn apcal_btn-info" onclick="return ExistingUserBtn();"><i class="fa fa-sign-in"></i> <?php _e("Existing User", "appointzilla"); ?></button>
1264 <button type="button" class="apcal_btn" id="back2" name="back2" onclick="LoadSecondModal2()" style="float: right;"><i class="icon-arrow-left"></i> <?php _e('Back', 'appointzilla'); ?></button>
1265 </td>
1266 </tr>
1267 </table>
1268 </div>
1269
1270 <!--new user div-->
1271 <div id="new-user-div" style="display: none;">
1272 <table width="100%" class="table">
1273 <tr>
1274 <th scope="row"><?php _e('Username', 'appointzilla'); ?></th>
1275 <td><strong>:</strong></td>
1276 <td><input name="client-username" type="text" id="client-username" style="height:30px;" /></td>
1277 </tr>
1278 <tr>
1279 <th scope="row"><?php _e('Password', 'appointzilla'); ?></th>
1280 <td><strong>:</strong></td>
1281 <td><input name="client-password" type="password" id="client-password" style="height:30px;" /></td>
1282 </tr>
1283 <tr>
1284 <th scope="row"><?php _e('Confirm Password', 'appointzilla'); ?></th>
1285 <td><strong>:</strong></td>
1286 <td><input name="client-confirm-password" type="password" id="client-confirm-password" style="height:30px;" /></td>
1287 </tr>
1288 <tr>
1289 <th scope="row"><?php _e('Email', 'appointzilla'); ?></th>
1290 <td><strong>:</strong></td>
1291 <td><input name="client-email" type="text" id="client-email" style="height:30px;" /></td>
1292 </tr>
1293 <tr>
1294 <th scope="row"><?php _e('First Name', 'appointzilla'); ?></th>
1295 <td><strong>:</strong></td>
1296 <td><input name="client-first-name" type="text" id="client-first-name" style="height:30px;" /></td>
1297 </tr>
1298 <tr>
1299 <th scope="row"><?php _e('Last Name', 'appointzilla'); ?></th>
1300 <td><strong>:</strong></td>
1301 <td><input name="client-last-name" type="text" id="client-last-name" style="height:30px;" /></td>
1302 </tr>
1303 <tr>
1304 <th scope="row"><?php _e('Phone', 'appointzilla'); ?></th>
1305 <td><strong>:</strong></td>
1306 <td><input name="client-phone" type="text" id="client-phone" style="height:30px;" maxlength="14"/></td>
1307 </tr>
1308 <tr>
1309 <th scope="row"><?php _e('Special Instruction', 'appointzilla'); ?></th>
1310 <td><strong>:</strong></td>
1311 <td><textarea name="client-si" id="client-si"></textarea></td>
1312 </tr>
1313 <tr>
1314 <td> </td>
1315 <td> </td>
1316 <td>
1317 <div id="new-user-form-btn-div">
1318 <button type="button" class="apcal_btn apcal_btn-success" id="book-now" name="book-now" onclick="return CheckValidation('NewUser')"><i class="icon-ok icon-white"></i> <?php _e('Book Now', 'appointzilla'); ?></button>
1319 </div>
1320 <div id="new-user-form-loading-img" style="display:none;"><?php _e('Scheduling appointment, please wait...', 'appointzilla'); ?><img src="<?php echo plugins_url('images/loading.gif', __FILE__); ?>" /></div>
1321 </td>
1322 </tr>
1323 </table>
1324 </div>
1325
1326 <!--existing user div-->
1327 <div id="existing-user-div" style="display: none;">
1328
1329 <!--div for display existing user search details-->
1330 <div id="check-email-div-form" style="display: none;">
1331 <table width="100%" class="table">
1332 <tr>
1333 <th scope="row"><?php _e('Email', 'appointzilla'); ?></th>
1334 <td><strong>:</strong></td>
1335 <td><input name="check-client-email" type="text" id="check-client-email" style="height:30px;" /></td>
1336 </tr>
1337 <tr>
1338 <td> </td>
1339 <td> </td>
1340 <td>
1341 <div id="existing-user-form-btn">
1342 <button type="button" class="apcal_btn apcal_btn-success" id="check-existing-user" name="check-existing-user" onclick="return CheckExistingUser();"><i class="icon-search icon-white"></i> <?php _e('Search Email', 'appointzilla'); ?></button>
1343 </div>
1344 <div id="existing-user-loading-img" style="display:none;"><?php _e('Searching, please wait...', 'appointzilla'); ?><img src="<?php echo plugins_url('images/loading.gif', __FILE__); ?>" /></div>
1345 </td>
1346 </tr>
1347 </table>
1348 </div>
1349
1350 <!--div for display existing user search details-->
1351 <div id="check-email-result-div" style="display: none;">
1352
1353 </div>
1354 </div>
1355 <?php } else { // end of if registration enable ?>
1356 <!--user registration not enable-->
1357 <div id="no-user-registration">
1358 <table width="100%" class="table">
1359 <tr>
1360 <th scope="row"><?php _e('Email', 'appointzilla'); ?></th>
1361 <td><strong>:</strong></td>
1362 <td><input name="client-email" type="text" id="client-email" style="height:30px;" /></td>
1363 </tr>
1364 <tr>
1365 <th scope="row"><?php _e('First Name', 'appointzilla'); ?></th>
1366 <td><strong>:</strong></td>
1367 <td><input name="client-first-name" type="text" id="client-first-name" style="height:30px;" /></td>
1368 </tr>
1369 <tr>
1370 <th scope="row"><?php _e('Last Name', 'appointzilla'); ?></th>
1371 <td><strong>:</strong></td>
1372 <td><input name="client-last-name" type="text" id="client-last-name" style="height:30px;" /></td>
1373 </tr>
1374 <tr>
1375 <th scope="row"><?php _e('Phone', 'appointzilla'); ?></th>
1376 <td><strong>:</strong></td>
1377 <td><input name="client-phone" type="text" id="client-phone" style="height:30px;" maxlength="14"/></td>
1378 </tr>
1379 <tr>
1380 <th scope="row"><?php _e('Special Instruction', 'appointzilla'); ?></th>
1381 <td><strong>:</strong></td>
1382 <td><textarea name="client-si" id="client-si"></textarea></td>
1383 </tr>
1384 <tr>
1385 <td> </td>
1386 <td> </td>
1387 <td>
1388 <div id="new-user-form-btn-div">
1389 <button type="button" class="apcal_btn" id="back2" name="back2" onclick="LoadSecondModal2()"><i class="icon-arrow-left"></i> <?php _e('Back', 'appointzilla'); ?></button>
1390 <button type="button" class="apcal_btn apcal_btn-success" id="book-now" name="book-now" onclick="return CheckValidation('NewUser')"><i class="icon-ok icon-white"></i> <?php _e('Book Now', 'appointzilla'); ?></button>
1391 </div>
1392 <div id="new-user-form-loading-img" style="display:none;"><?php _e('Scheduling appointment, please wait...', 'appointzilla'); ?><img src="<?php echo plugins_url('images/loading.gif', __FILE__); ?>" /></div>
1393 </td>
1394 </tr>
1395 </table>
1396 </div>
1397 <?php } ?>
1398 </div><!--end modal-body-->
1399 </div>
1400 </div><?php
1401 } ?>
1402
1403 <!---saving appointments--->
1404 <?php if( isset($_POST['Action'])) {
1405 $Action = $_POST['Action'];
1406 $UserType = $_POST['UserType'];
1407 if($Action == "BookAppointment") {
1408 //print_r($_POST); die;
1409 $ServiceId = $_POST['ServiceId'];
1410 $StaffId = $_POST['StaffId'];
1411 $AppDateNo = $_POST['AppDate'];
1412
1413 $ClientEmail = $_POST['ClientEmail'];
1414 $ClientFirstName = sanitize_text_field($_POST['ClientFirstName']);
1415 $ClientLastName = sanitize_text_field($_POST['ClientLastName']);
1416 $ClientName = $ClientFirstName ." ". $ClientLastName;
1417 $ClientPhone = $_POST['ClientPhone'];
1418 $ClientNote = $_POST['ClientNote'];
1419 $AppointmentKey = md5(date("F j, Y, g:i a"));
1420 $AppDate = date("Y-m-d", strtotime($AppDateNo));
1421 $StartTime = $_POST['StartTime'];
1422
1423 //check user registration yes/no
1424 if($AllCalendarSettings['apcal_user_registration'] == "yes"){
1425 if($UserType == "NewUser") {
1426 $ClientUserName = $_POST['ClientUserName'];
1427 $ClientPassword = $_POST['ClientPassword'];
1428
1429 //create new user profile as subscriber
1430 $UserId = username_exists( $ClientUserName );
1431 if ( !$UserId and email_exists($ClientEmail) == false ) {
1432 $UserId = wp_create_user( $ClientUserName, $ClientPassword, $ClientEmail );
1433 if($UserId) {
1434 update_user_meta( $UserId, 'first_name', $_POST['ClientFirstName']);
1435 update_user_meta( $UserId, 'last_name', $_POST['ClientLastName']);
1436 add_user_meta( $UserId, 'client_phone', $ClientPhone);
1437 add_user_meta( $UserId, 'client_note', $ClientNote);
1438 }
1439 } else {
1440 _e("User already exists", "appointzilla");
1441 }
1442 }
1443
1444 if($UserType == "ExUser") {
1445 //update existing user profile as subscriber
1446 $UserId = email_exists($ClientEmail);
1447 if($UserId) {
1448 update_user_meta( $UserId, 'first_name', $ClientFirstName);
1449 update_user_meta( $UserId, 'last_name', $ClientLastName);
1450 update_user_meta( $UserId, 'client_phone', $ClientPhone);
1451 update_user_meta( $UserId, 'client_note', $ClientNote);
1452 } else {
1453 _e("User already exists", "appointzilla");
1454 }
1455 }
1456 } // end of check user registration
1457
1458 //fetch service detail calculation EndTime and Service name
1459 $ServiceTableName = $wpdb->prefix . "ap_services";
1460 $ServiceName = $wpdb->get_row("SELECT * FROM `$ServiceTableName` WHERE `id` = '$ServiceId' ");
1461 $ServiceDuration = $ServiceName->duration;
1462
1463 $StartTimeTimestamp = strtotime($StartTime);
1464 //calculate end time according to service duration
1465 $CalculateTime = strtotime("+$ServiceDuration minutes", $StartTimeTimestamp);
1466 $EndTime = date('h:i A', $CalculateTime );
1467
1468 if(isset($AllCalendarSettings['apcal_new_appointment_status'])) {
1469 $Status = $AllCalendarSettings['apcal_new_appointment_status'];
1470 } else {
1471 $Status = "pending";
1472 }
1473 $AppointmentBy = "user";
1474 $Recurring = "no";
1475 $RecurringType = "none";
1476 $RecurringStartDate = $AppDate;
1477 $RecurringEndDate = $AppDate;
1478 $PaymentStatus = "unpaid";
1479
1480 global $wpdb;
1481 $AppointmentsTable = $wpdb->prefix ."ap_appointments";
1482 $CreateAppointments = "INSERT INTO `$AppointmentsTable` (`id` ,`name` ,`email` ,`service_id` ,`staff_id` ,`phone` ,`start_time` ,`end_time` ,`date` ,`note` , `appointment_key` ,`status` ,`recurring` ,`recurring_type` ,`recurring_st_date` ,`recurring_ed_date` ,`appointment_by`, `payment_status`) VALUES ('NULL', '$ClientName', '$ClientEmail', '$ServiceId', '$StaffId', '$ClientPhone', '$StartTime', '$EndTime', '$AppDate', '$ClientNote', '$AppointmentKey', '$Status', '$Recurring', '$RecurringType', '$RecurringStartDate', '$RecurringEndDate', '$AppointmentBy', '$PaymentStatus');";
1483 if($wpdb->query($CreateAppointments)) {
1484 $LastAppointmentId = $wpdb->insert_id;?>
1485 <div id="AppForthModalData">
1486 <?php global $wpdb;
1487 $ClientTable = $wpdb->prefix."ap_clients";
1488 $ExistClientDetails = $wpdb->get_row("SELECT * FROM `$ClientTable` WHERE `email` = '$ClientEmail' ");
1489 if(count($ExistClientDetails)) {
1490 // update exiting client deatils
1491 $ExistClientId = $ExistClientDetails->id;
1492 $update_client = "UPDATE `$ClientTable` SET `name` = '$ClientName', `email` = '$ClientEmail', `phone` = '$ClientPhone', `note` = '$ClientNote' WHERE `id` = '$ExistClientId' ;";
1493 if($wpdb->query($update_client)) {
1494 $LastClientId = $ExistClientId;
1495 } else {
1496 // if now data filed modified then
1497 $LastClientId = $ExistClientId;
1498 }
1499 } else {
1500 // insert new client deatils
1501 $InsertClient = "INSERT INTO `$ClientTable` (`id` ,`name` ,`email` ,`phone` ,`note`) VALUES ('NULL', '$ClientName', '$ClientEmail', '$ClientPhone', '$ClientNote');";
1502 if($wpdb->query($InsertClient)) {
1503 //$LastClientId = mysql_insert_id();
1504 $LastClientId = $wpdb->insert_id;
1505
1506 }
1507 } ?>
1508
1509 <div class="apcal_modal" id="AppForthModal" style="z-index:10000;">
1510 <div class="apcal_modal-info">
1511 <div style="float:right; margin-top:5px; margin-right:10px;"></div>
1512 <div class="apcal_alert apcal_alert-info">
1513 <p><?php _e('Thank You. Your appointment has been scheduled.', 'appointzilla'); ?></p>
1514 </div><!--end modal-info-->
1515
1516 <div class="apcal_modal-body">
1517 <style>
1518 .table th, .table td {
1519 padding: 4px;;
1520 }
1521 </style>
1522 <strong><?php _e('Your Appointment Details', 'appointzilla'); ?></strong>
1523 <input type="hidden" id="appid" name="appid" value="<?php echo $LastAppointmentId; ?>" />
1524 <table width="100%" class="table">
1525 <tr>
1526 <th width="26%" scope="row"><?php _e('Name', 'appointzilla'); ?></th>
1527 <td width="1%"><strong>:</strong></td>
1528 <td width="73%"><?php echo ucwords($ClientName); ?></td>
1529 </tr>
1530 <tr>
1531 <th width="26%" scope="row"><?php _e('Email', 'appointzilla'); ?></th>
1532 <td width="1%"><strong>:</strong></td>
1533 <td width="73%"><?php echo $ClientEmail; ?></td>
1534 </tr>
1535 <tr>
1536 <th width="26%" scope="row"><?php _e('Phone', 'appointzilla'); ?></th>
1537 <td width="1%"><strong>:</strong></td>
1538 <td width="73%"><?php echo $ClientPhone; ?></td>
1539 </tr>
1540 <tr>
1541 <th width="26%" scope="row"><?php _e('Service', 'appointzilla'); ?></th>
1542 <td width="1%"><strong>:</strong></td>
1543 <td width="73%"><?php echo ucwords($ServiceName->name); ?></td>
1544 </tr>
1545 <tr>
1546 <th width="26%" scope="row"><?php _e('Staff', 'appointzilla'); ?></th>
1547 <td width="1%"><strong>:</strong></td>
1548 <td width="73%">
1549 <?php $StaffTableName = $wpdb->prefix . "ap_staff";
1550 $StaffName = $wpdb->get_row("SELECT `name` FROM `$StaffTableName` WHERE `id` = '$StaffId' ");
1551 echo ucwords($StaffName->name); ?>
1552 </td>
1553 </tr>
1554 <tr>
1555 <th width="26%" scope="row"><?php _e('Date', 'appointzilla'); ?></th>
1556 <td width="1%"><strong>:</strong></td>
1557 <td width="73%"><?php echo date($DateFormat, strtotime($AppDate)); ?></td>
1558 </tr>
1559 <tr>
1560 <?php if($TimeFormat == "h:i") $InfoTimeFormat = "h:i A"; else $InfoTimeFormat = "H:i"; ?>
1561 <th width="26%" scope="row"><?php _e('Time', 'appointzilla'); ?></th>
1562 <td width="1%"><strong>:</strong></td>
1563 <td width="73%"><?php echo date($InfoTimeFormat, strtotime($StartTime))." - ".date($InfoTimeFormat, strtotime($EndTime)); ?></td>
1564 </tr>
1565 <tr>
1566 <th width="26%" scope="row"><?php _e('Status', 'appointzilla'); ?></th>
1567 <td width="1%"><strong>:</strong></td>
1568 <td width="73%"><?php echo _e(ucfirst($Status),'appointzilla'); ?></td>
1569 </tr>
1570 <?php
1571 //get service details for payment purpose & also check payment settings
1572 global $wpdb;
1573 $ServiceTableName = $wpdb->prefix . 'ap_services';
1574 $ServiceDetails = $wpdb->get_row("SELECT * FROM `$ServiceTableName` WHERE `id` = '$ServiceId'");
1575 $AcceptPayment = $ServiceDetails->accept_payment;
1576 $PaymentType = $ServiceDetails->payment_type;
1577 $ap_payment_email = get_option('ap_payment_email');
1578 $ap_payment_gateway_status = get_option('ap_payment_gateway_status');
1579 if($AcceptPayment == "yes" && $PaymentType == "full" && $ap_payment_email && $ap_payment_gateway_status == "yes") {
1580 ?>
1581 <tr>
1582 <th width="26%" scope="row"><?php _e('Coupon Code', 'appointzilla'); ?></th>
1583 <td width="1%"><strong>:</strong></td>
1584 <td width="73%">
1585 <div id="apply-coupon-div">
1586 <input type="text" id="coupon-code" name="coupon-code" maxlength="15" style="width: 120px;">
1587 <button id="apply-coupon" name="apply-coupon" class="apcal_btn apcal_btn-small apcal_btn-info" onclick="return ApplyCoupon();" style="margin-top: -10px;"><i class="icon-tags icon-white"></i> <?php _e('Apply', 'appointzilla'); ?></button>
1588 </div>
1589
1590 <div id="loading-img" style="display:none;"><?php _e('Applying...', 'appointzilla'); ?><img src="<?php echo plugins_url("images/loading.gif", __FILE__); ?>" /></div>
1591 <div id="show-coupon-result" style="display:none;"></div>
1592 </td>
1593 </tr>
1594 <?php } ?>
1595 <tr>
1596 <td colspan="3">
1597 <?php $Check1 = 0; $Check2 = 0; $Check3 = 0;
1598 /**
1599 * Paypal Payment Process
1600 **/
1601 //get service details for payment purpose
1602 global $wpdb;
1603 $ServiceTableName = $wpdb->prefix . 'ap_services';
1604 $ServiceDetails = $wpdb->get_row("SELECT * FROM `$ServiceTableName` WHERE `id` = '$ServiceId'");
1605
1606 //get currency code
1607 $CurrencyId = get_option('cal_admin_currency');
1608 if($CurrencyId != '') {
1609 $CurrencyTableName = $wpdb->prefix."ap_currency";
1610 $CurrencyDetails = $wpdb->get_row("SELECT `code` FROM `$CurrencyTableName` WHERE `id` = '$CurrencyId'");
1611 $CurrencyCode = $CurrencyDetails->code;
1612 } else {
1613 $CurrencyCode = 'USD';
1614 }
1615
1616 $Protocol = stripos($_SERVER['SERVER_PROTOCOL'],'https') === true ? 'https://' : 'http://www.';
1617 $SuccessCurrentUrl = $Protocol.$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
1618 $FailedCurrentUrl = $SuccessCurrentUrl."?&failed=failed&appointId=".$LastAppointmentId;
1619
1620 if($SuccessCurrentUrl!="")
1621 {}
1622 //check payment is 'yes'
1623 if($ap_payment_gateway_status == 'yes') {
1624
1625 //check service is paid
1626 if($ServiceDetails->accept_payment == 'yes') {
1627 //check payment type
1628 if($ServiceDetails->payment_type == 'percentage') {
1629 $PayCost = $ServiceDetails->cost;
1630 $percentage = $ServiceDetails->percentage_ammount;
1631 $PayCost = ($PayCost * $percentage) /100;
1632 } else {
1633 $PayCost = $ServiceDetails->cost;
1634 }
1635
1636 $ApPaymentEmail = get_option('ap_payment_email');
1637 if($ApPaymentEmail) {
1638 // default discount value
1639 $DiscountRate = 0;
1640
1641 // Include the paypal library
1642 require_once ('menu-pages/paypal-api/Scientechpaypal.php');
1643
1644
1645 $ScientechPaypal = new Scientechpaypal();
1646 $ScientechPaypal->TakePayment($ApPaymentEmail, $CurrencyCode, $SuccessCurrentUrl, $FailedCurrentUrl, $ServiceDetails->name, $PayCost, $LastAppointmentId, $DiscountRate);
1647 } else {
1648 $Check3 = 1;
1649 }
1650 } else {
1651 $Check2 = 1;
1652 }
1653 } else {
1654 $Check1 = 1;
1655 }
1656
1657 // send notification if any of check == 1
1658 if($Check1 || $Check2 || $Check3) { ?>
1659 <button type="submit" class="apcal_btn apcal_btn" onclick="CloseModelform()" style="margin-left:80%"><i class="icon-ok"></i> <?php _e('Done', 'appointzilla'); ?></button>
1660 <?php $BlogName = get_bloginfo('name');
1661 if($LastAppointmentId && $LastClientId) {
1662 $AppId = $LastAppointmentId;
1663 $ServiceId = $ServiceId;
1664 $StaffId = $StaffId;
1665 $ClientId = $LastClientId;
1666 //include notification class
1667 require_once('menu-pages/notification-class.php');
1668 $Notification = new Notification();
1669 $Notification->notifyadmin($Status, $AppId, $ServiceId, $StaffId, $ClientId, $BlogName, $DateFormat, $TimeFormat);
1670 $Notification->notifyclient($Status, $AppId, $ServiceId, $StaffId, $ClientId, $BlogName, $DateFormat, $TimeFormat);
1671 if(get_option('staff_notification_status') == 'on') {
1672 $Notification->notifystaff($Status, $AppId, $ServiceId, $StaffId, $ClientId, $BlogName, $DateFormat, $TimeFormat);
1673 }
1674 }
1675 }
1676
1677 //if status is approved then sync appointment
1678 if($Status == 'approved') {
1679
1680 //add service name with event title($name)
1681 //$ServiceTable = $wpdb->prefix . "ap_services";
1682 //$ServiceData = $wpdb->get_row("SELECT * FROM `$ServiceTable` WHERE `id` = '$ServiceId'");
1683 //$name = $name."(".$ServiceData->name.")";
1684
1685 /***
1686 * admin appointment sync
1687 */
1688 $CalData = get_option('google_caelndar_settings_details');
1689 if($CalData['google_calendar_client_id'] != '' && $CalData['google_calendar_secret_key'] != '') {
1690 $StartTime = date("H:i", strtotime($StartTime));
1691 $EndTime = date("H:i", strtotime($EndTime));
1692 $AppDate = date("Y-m-d", strtotime($AppDate));
1693 $ClientNote = strip_tags($ClientNote);
1694
1695 $ClientId = $CalData['google_calendar_client_id'];
1696 $ClientSecretId = $CalData['google_calendar_secret_key'];
1697 $RedirectUri = $CalData['google_calendar_redirect_uri'];
1698 require_once('menu-pages/google-appointment-sync-class.php');
1699
1700 //global $wpdb;
1701 $AppointmentSyncTableName = $wpdb->prefix . "ap_appointment_sync";
1702 // insert this appointment event on calendar
1703 $GoogleAppointmentSync = new GoogleAppointmentSync($ClientId, $ClientSecretId, $RedirectUri);
1704 $tag = "Appointment with: ";
1705 $OAuth = $GoogleAppointmentSync->NormalSync($ClientName, $AppDate, $StartTime, $EndTime, $ClientNote, $tag);
1706 //insert appintment sync details
1707 $OAuth = serialize($OAuth);
1708 $wpdb->query("INSERT INTO `$AppointmentSyncTableName` ( `id` , `app_id` , `app_sync_details` ) VALUES ( NULL , '$AppId', '$OAuth' )");
1709 } // end of google calendar setting
1710
1711 /***
1712 * staff appointment sync
1713 */
1714 $StaffAppointmentSyncSettings = unserialize(get_option("staff_google_calendar_sync_settings_".$StaffId));
1715 if($StaffAppointmentSyncSettings['StaffGoogleCalendarClientId'] != "" && $StaffAppointmentSyncSettings['StaffGoogleCalendarSecret']) {
1716 $StaffGoogleEmail = $StaffAppointmentSyncSettings['StaffGoogleEmail'];
1717 $StaffGoogleCalendarClientId = $StaffAppointmentSyncSettings['StaffGoogleCalendarClientId'];
1718 $StaffGoogleCalendarSecret = $StaffAppointmentSyncSettings['StaffGoogleCalendarSecret'];
1719 $StaffGoogleCalendarRedirectUris = $StaffAppointmentSyncSettings['StaffGoogleCalendarRedirectUris'];
1720 require_once('menu-pages/google-staff-appointment-sync-class.php');
1721
1722 // add this staff appointment event on his google calendar
1723 $StaffGoogleAppointmentSync = new StaffGoogleAppointmentSync($StaffGoogleCalendarClientId, $StaffGoogleCalendarSecret, $StaffGoogleCalendarRedirectUris);
1724 $Tag = __("Appointment with: ", "appointzilla");
1725 $StaffOAuth = $StaffGoogleAppointmentSync->NormalStaffAppointmentSync($StaffId, $ClientName, $AppDate, $StartTime, $EndTime, $ClientNote, $Tag);
1726
1727 //insert staff appointment sync details
1728 global $wpdb;
1729 $StaffAppointmentSyncTable = $wpdb->prefix . "ap_staff_appointment_sync";
1730 $StaffOAuth = serialize($StaffOAuth);
1731 $wpdb->query("INSERT INTO `$StaffAppointmentSyncTable` ( `id` , `app_id` , `staff_sync_details` ) VALUES ( NULL , '$AppId', '$StaffOAuth' )");
1732 }//end of staff appointment sync
1733
1734 //unset payment post variables
1735 //unset($_POST['address_status']); unset($_POST['payer_id']);
1736
1737 } // end of sync appointment is approved
1738 ?>
1739 <div id="ex-pay-canceling-img" style="display:none;"><?php _e('Refreshing, Please wait...', 'appointzilla'); ?><img src="<?php echo plugins_url('images/loading.gif', __FILE__); ?>" /></div>
1740 <div id="loading-staff" style="display:none;">
1741 <?php _e('Loading Staff...', 'appointzilla'); ?><img src="<?php echo plugins_url('images/loading.gif', __FILE__); ?>" />
1742 </div>
1743 </td>
1744 </tr>
1745 </table>
1746 </div>
1747 </div>
1748 </div>
1749 <?php
1750 }//query if
1751 }
1752 }// saving appointment if
1753
1754
1755 // Payment success
1756 if( isset($_POST['address_status']) && isset($_POST['payer_id']) ) {
1757 global $wpdb;
1758 $AppointmentTableName = $wpdb->prefix . "ap_appointments";
1759 $PaymentTableName = $wpdb->prefix . 'ap_payment_transaction';
1760 $ClientTableName = $wpdb->prefix . 'ap_clients';
1761 $CouponsCodesTable = $wpdb->prefix ."apcal_pre_coupons_codes";
1762 //print_r($_POST);
1763 $PaymentDetails = serialize($_POST);
1764 $appId = $_POST['item_number'];
1765
1766 //get client id by appointment id
1767 $ClientEmail = $wpdb->get_row("SELECT `email` FROM `$AppointmentTableName` WHERE `id` = '$appId'");
1768 $FetchClientEmail = $wpdb->get_row("SELECT `id` FROM `$ClientTableName` WHERE `email` = '$ClientEmail->email'");
1769 $clientId = $FetchClientEmail->id;
1770
1771 $amount = $_POST['mc_gross'];
1772 $date = $_POST['payment_date'];
1773 $status = $_POST['address_status'];
1774 $txn_id = $_POST['txn_id'];
1775 $gateway = 'paypal';
1776
1777 $wpdb->query("INSERT INTO `$PaymentTableName` (`id`, `app_id`, `client_id`, `ammount`, `date`, `status`, `txn_id`, `gateway`, `other_fields`) VALUES (NULL, '$appId', '$clientId', '$amount', '$date', '$status', '$txn_id', '$gateway', '$PaymentDetails');");
1778 $AppointmentId = $_POST['item_number'];
1779 $AppointmentRow = $wpdb->get_row("SELECT * FROM `$AppointmentTableName` WHERE `id` = '$AppointmentId'");
1780 if(count($AppointmentRow)) {
1781 $name = $AppointmentRow->name;
1782 $ServiceId = $AppointmentRow->service_id;
1783 $StaffId = $AppointmentRow->staff_id;
1784 $StartTime = $AppointmentRow->start_time;
1785 $EndTime = $AppointmentRow->end_time;
1786 $Client_name = $AppointmentRow->name;
1787 $Client_Email = $AppointmentRow->email;
1788 $Client_Phone = $AppointmentRow->phone;
1789 $Client_Note = $AppointmentRow->note;
1790 $AppDate = $AppointmentRow->date;
1791 $Status = 'approved';
1792 $AppointmentKey = $AppointmentRow->appointment_key;
1793
1794 //update appointment status n payment status
1795 $PaymentStatus = $_POST['payment_status'];
1796 $AppointmentRow = $wpdb->query("UPDATE `$AppointmentTableName` SET `status` = '$Status', `payment_status` = 'paid' WHERE `id` = '$AppointmentId' ");
1797
1798 $BlogName = get_bloginfo();
1799 if($AppointmentId && $clientId) {
1800 $AppId = $AppointmentId;
1801 $ServiceId = $ServiceId;
1802 $StaffId = $StaffId;
1803 $ClientId = $clientId;
1804 //include notification class
1805 require_once('menu-pages/notification-class.php');
1806 $Notification = new Notification();
1807 $Notification->notifyadmin($Status, $AppId, $ServiceId, $StaffId, $ClientId, $BlogName, $DateFormat, $TimeFormat);
1808 $Notification->notifyclient($Status, $AppId, $ServiceId, $StaffId, $ClientId, $BlogName, $DateFormat, $TimeFormat);
1809 if(get_option('staff_notification_status') == "on") {
1810 $Notification->notifystaff($Status, $AppId, $ServiceId, $StaffId, $ClientId, $BlogName, $DateFormat, $TimeFormat);
1811 }
1812 }
1813
1814 //if status is approved then sync appointment
1815 if($Status == 'approved') {
1816
1817 //add service name with event title($name)
1818 //$ServiceTable = $wpdb->prefix . "ap_services";
1819 //$ServiceData = $wpdb->get_row("SELECT * FROM `$ServiceTable` WHERE `id` = '$ServiceId'");
1820 //$name = $name."(".$ServiceData->name.")";
1821
1822 /**
1823 * Admin appointment google sync
1824 */
1825 $CalData = get_option('google_caelndar_settings_details');
1826 if($CalData['google_calendar_client_id'] != '' && $CalData['google_calendar_secret_key'] != '') {
1827 $start_time = date("H:i", strtotime($StartTime));
1828 $end_time = date("H:i", strtotime($EndTime));
1829 $appointmentdate = date("Y-m-d", strtotime($AppDate));
1830 $note = strip_tags($Client_Note);
1831
1832 $ClientId = $CalData['google_calendar_client_id'];
1833 $ClientSecretId = $CalData['google_calendar_secret_key'];
1834 $RedirectUri = $CalData['google_calendar_redirect_uri'];
1835 require_once('menu-pages/google-appointment-sync-class.php');
1836
1837 //global $wpdb;
1838 $AppointmentSyncTableName = $wpdb->prefix . "ap_appointment_sync";
1839 // insert this appointment event on calendar
1840 $GoogleAppointmentSync = new GoogleAppointmentSync($ClientId, $ClientSecretId, $RedirectUri);
1841 $tag = "Appointment with: ";
1842 $OAuth = $GoogleAppointmentSync->NormalSync($name, $appointmentdate, $start_time, $end_time, $note, $tag);
1843 //insert appintment sync details
1844 $OAuth = serialize($OAuth);
1845 $wpdb->query("INSERT INTO `$AppointmentSyncTableName` ( `id` , `app_id` , `app_sync_details` )
1846 VALUES ( NULL , '$AppointmentId', '$OAuth' );");
1847 } // end of google calendar setting
1848
1849 /**
1850 * Staff appointment google sync
1851 */
1852 $StaffAppointmentSyncSettings = unserialize(get_option("staff_google_calendar_sync_settings_".$StaffId));
1853 if($StaffAppointmentSyncSettings['StaffGoogleCalendarClientId'] != "" && $StaffAppointmentSyncSettings['StaffGoogleCalendarSecret']) {
1854 $StaffGoogleEmail = $StaffAppointmentSyncSettings['StaffGoogleEmail'];
1855 $StaffGoogleCalendarClientId = $StaffAppointmentSyncSettings['StaffGoogleCalendarClientId'];
1856 $StaffGoogleCalendarSecret = $StaffAppointmentSyncSettings['StaffGoogleCalendarSecret'];
1857 $StaffGoogleCalendarRedirectUris = $StaffAppointmentSyncSettings['StaffGoogleCalendarRedirectUris'];
1858 require_once('menu-pages/google-staff-appointment-sync-class.php');
1859
1860 $start_time = date("H:i", strtotime($StartTime));
1861 $end_time = date("H:i", strtotime($EndTime));
1862 $appointmentdate = date("Y-m-d", strtotime($AppDate));
1863 $note = strip_tags($Client_Note);
1864 // add this staff appointment event on his google calendar
1865 $StaffGoogleAppointmentSync = new StaffGoogleAppointmentSync($StaffGoogleCalendarClientId, $StaffGoogleCalendarSecret, $StaffGoogleCalendarRedirectUris);
1866 $Tag = __("Appointment with: ", "appointzilla");
1867 $StaffOAuth = $StaffGoogleAppointmentSync->NormalStaffAppointmentSync($StaffId, $name, $appointmentdate, $start_time, $end_time, $note, $Tag);
1868
1869 //insert staff appointment sync details
1870 global $wpdb;
1871 $StaffAppointmentSyncTable = $wpdb->prefix . "ap_staff_appointment_sync";
1872 $StaffOAuth = serialize($StaffOAuth);
1873 $wpdb->query("INSERT INTO `$StaffAppointmentSyncTable` ( `id` , `app_id` , `staff_sync_details` ) VALUES ( NULL , '$AppId', '$StaffOAuth' )");
1874 }//end of staff appointment sync
1875
1876 //unset payment post variables
1877 unset($_POST['address_status']); unset($_POST['payer_id']);
1878
1879 } // end of sync appointment is approved ?>
1880 <div class="apcal_modal" id="AppForthModal" style="z-index:10000;">
1881 <div class="apcal_modal-info">
1882 <div style="float:right; margin-top:5px; margin-right:10px;">
1883 <div align="center"><a href="" onclick="CloseModelform()" id="close" ><i class="icon-remove"></i></a></div>
1884 </div>
1885 <div class="apcal_alert apcal_alert-info">
1886 <h4 ><?php _e('Payment Successfully Processed', 'appointzilla'); ?></h4>
1887 </div>
1888 <div class="apcal_modal-body">
1889 <div class="apcal_alert apcal_alert-success">
1890 <strong><?php _e('Payment received and your appointment has been confirmed.', 'appointzilla'); ?></strong><br />
1891 <strong><?php _e('Thank you for scheduling appointment with us.', 'appointzilla'); ?></strong>
1892 <?php
1893 //if payment confirmed(done) then increment coupon used count value
1894 if($status == "confirmed") {
1895 $PaymentDetails = unserialize($PaymentDetails);
1896 if(isset($PaymentDetails['custom'])) {
1897 $CouponCode = $PaymentDetails['custom'];
1898 //check coupon exist or not
1899 $CouponsData = $wpdb->get_row("SELECT * FROM `$CouponsCodesTable` WHERE `coupon_code` LIKE '$CouponCode'");
1900 if(count($CouponsData)) {
1901 //increment total used count
1902 $CouponId = $CouponsData->id;
1903 $UsedCount = $CouponsData->used_count + 1;
1904 $wpdb->query("UPDATE `$CouponsCodesTable` SET `used_count` = '$UsedCount' WHERE `id` = '$CouponId' ");
1905 }
1906 }
1907 }
1908 ?>
1909 </div>
1910 <button type='button' onclick='CloseModelform()' name='close' id='close' value='Done' class='apcal_btn'><i class="icon-ok"></i> <?php _e('Done', 'appointzilla'); ?></button>
1911 </div>
1912 <div>
1913 </div>
1914 </div>
1915 <?php
1916 } // end of AppointmentRow
1917 } // end of Payment success
1918
1919 // Payment process failed
1920 if( isset($_GET['failed']) && isset($_GET['appointId'])) { ?>
1921 <div class="apcal_modal" id="AppForthModal" style="z-index:10000;">
1922 <div class="apcal_modal-info" style="padding-bottom:20px;">
1923 <div style="float:right; margin-top:5px; margin-right:10px;">
1924 <a href="#" onclick="CloseModelformfailed()" id="close" ><i class="icon-remove"></i></a>
1925 </div>
1926 <input type="hidden" name="appid" id="appid" value="<?php echo $_GET['appointId']; ?>" />
1927 <div class="apcal_alert apcal_alert-info">
1928 <h4><?php _e('Payment Failed', 'appointzilla'); ?></h4>
1929 </div>
1930 <div style=" margin-left:20px; padding-right:20px;">
1931 <div class="apcal_alert apcal_alert-error">
1932 <?php _e('Sorry! Appointment booking was not successful.', 'appointzilla'); ?>
1933 </div>
1934 <button type='button' onclick='return failedappointment();' name='close' id='close' value='close' class='apcal_btn'><i class="icon-repeat"></i> <?php _e('Try Again', 'appointzilla'); ?></button>
1935 </div>
1936 </div>
1937 </div><?php
1938 }
1939
1940 // cancel appointment
1941 if(isset($_POST['appid']) && isset($_POST['appstatus']) ) {
1942 $appid = $_POST['appid'];
1943 global $wpdb;
1944 $apptabname = $wpdb->prefix."ap_appointments";
1945 $wpdb->query("UPDATE `$apptabname` SET `status` = 'cancelled' WHERE `id` = '$appid' ;");
1946 }
1947
1948 //applying coupon code
1949 if(isset($_POST['Action'])) {
1950 $Action = $_POST['Action'];
1951 if($Action == "apply-coupon") {
1952 if(isset($_POST['CouponCode'])) {
1953 $CouponCode = strtolower($_POST['CouponCode']);
1954 } else {
1955 $CouponCode = "";
1956 }
1957 if($CouponCode){
1958 global $wpdb;
1959 $Discount = 0;
1960 $CouponsCodesTable = $wpdb->prefix . "apcal_pre_coupons_codes";
1961 //Search Coupon
1962 $CouponDetails = $wpdb->get_row("SELECT * FROM `$CouponsCodesTable` WHERE `coupon_code` LIKE '$CouponCode'");
1963 if(count($CouponDetails)) {
1964 //check coupon expire
1965 $DateTodayTs = strtotime(date("Y-m-d"));
1966 $ExpireDateTs = strtotime(date("Y-m-d", strtotime($CouponDetails->expire)));
1967 $TotalUses = $CouponDetails->total_uses;
1968 $UsedCount = $CouponDetails->used_count;
1969 $Discount = $CouponDetails->discount;
1970 if($DateTodayTs > $ExpireDateTs) {
1971 //coupon expired
1972 ?><div id="coupon-result"><div id="discount-rate-div" style="display: none;"><?php echo $Discount = 0; ?></div><?php echo strtoupper("<strong>$CouponCode</strong> "); _e("coupon code expired.", "appointzilla"); ?> <a id="try-another" onclick="return TryAgain();"><?php _e("Try Another", "appointzilla"); ?></a></div><?php
1973 } else if($UsedCount >= $TotalUses) {
1974 //ckeck used count
1975 ?><div id="coupon-result"><div id="discount-rate-div" style="display: none;"><?php echo $Discount = 0; ?></div><?php echo strtoupper("<strong>$CouponCode</strong> "); _e("coupon code expired.", "appointzilla"); ?> <a id="try-another" onclick="return TryAgain();"><?php _e("Try Another", "appointzilla"); ?></a></div><?php
1976 } else {
1977 //coupon valid and appied
1978 ?><div id="coupon-result">
1979 <div id="coupon-code-div" style="display: none;"><?php echo $CouponCode; ?></div>
1980 <div id="discount-rate-div" style="display: none;"><?php echo $Discount; ?></div>
1981 <?php echo strtoupper("<strong>$CouponCode</strong> "); _e("coupon code applied.", "appointzilla"); ?> <a id="try-another" onclick="return TryAgain();"><?php _e("Change", "appointzilla"); ?></a>
1982 </div><?php
1983 }
1984 } else {
1985 ?>
1986 <div id="coupon-result">
1987 <div id="discount-rate-div" style="display: none;"><?php echo $Discount; ?></div>
1988 <?php echo strtoupper("<strong>$CouponCode</strong> "); _e("coupon code is invalid.", "appointzilla"); ?>
1989 <a id="try-another" onclick="return TryAgain();"><?php _e("Try Another", "appointzilla"); ?></a>
1990 </div>
1991 <?php
1992 }
1993 }
1994 }//end of if action
1995 }
1996
1997 //check existing user
1998 if(isset($_POST['Action'])) {
1999 $Action = $_POST['Action'];
2000 if($Action == "CheckExistingUser") {
2001 ?><div id="check-email-result"><?php
2002 $ClientEmail = $_POST['ClientEmail'];
2003 $ClientId = email_exists( $ClientEmail );
2004 if( $ClientId = email_exists( $ClientEmail )) {
2005 //fetch user details
2006 $ClientDetails = get_userdata( $ClientId );
2007 //print_r($ClientDetails);
2008 $FirstName = "";
2009 $LastName = "";
2010 $Phone = "";
2011 $ClientNote = "";
2012 $UserMetaData = get_user_meta( $ClientId );
2013 if(count($UserMetaData)) {
2014 if(isset($UserMetaData['first_name'][0])) {
2015 $FirstName = ucwords($UserMetaData['first_name'][0]);
2016 }
2017 if(isset($UserMetaData['last_name'][0])) {
2018 $LastName = ucwords($UserMetaData['last_name'][0]);
2019 }
2020 if(isset($UserMetaData['client_phone'][0])) {
2021 $Phone = $UserMetaData['client_phone'][0];
2022 }
2023 if(isset($UserMetaData['client_note'][0])) {
2024 $ClientNote = ucfirst($UserMetaData['client_note'][0]);
2025 }
2026 }
2027 ?>
2028 <input type="hidden" id="client-id" name="client-id" value="<?php echo $ClientId; ?>">
2029 <table width="100%" class="table">
2030 <tr>
2031 <th scope="row"><?php _e('Email', 'appointzilla'); ?></th>
2032 <td><strong>:</strong></td>
2033 <td><input name="ex-client-email" type="text" id="ex-client-email" style="height:30px;" value="<?php echo $ClientEmail; ?>" readonly="" /></td>
2034 </tr>
2035 <tr>
2036 <th scope="row"><?php _e('First Name', 'appointzilla'); ?></th>
2037 <td><strong>:</strong></td>
2038 <td><input name="ex-client-first-name" type="text" id="ex-client-first-name" style="height:30px;" value="<?php echo $FirstName; ?>"/></td>
2039 </tr>
2040 <tr>
2041 <th scope="row"><?php _e('Last Name', 'appointzilla'); ?></th>
2042 <td><strong>:</strong></td>
2043 <td><input name="ex-client-last-name" type="text" id="ex-client-last-name" style="height:30px;" value="<?php echo $LastName; ?>" /></td>
2044 </tr>
2045 <tr>
2046 <th scope="row"><?php _e('Phone', 'appointzilla'); ?></th>
2047 <td><strong>:</strong></td>
2048 <td><input name="ex-client-phone" type="text" id="ex-client-phone" style="height:30px;" value="<?php echo $Phone; ?>" maxlength="14"/></td>
2049 </tr>
2050 <tr>
2051 <th scope="row"><?php _e('Special Instruction', 'appointzilla'); ?></th>
2052 <td><strong>:</strong></td>
2053 <td><textarea name="ex-client-si" id="ex-client-si"><?php echo $ClientNote; ?></textarea></td>
2054 </tr>
2055 <tr>
2056 <td> </td>
2057 <td> </td>
2058 <td>
2059 <div id="ex-user-form-btn-div">
2060 <button type="button" class="apcal_btn apcal_btn-success" id="ex-book-now" name="ex-book-now" onclick="return CheckValidation('ExUser');"><i class="icon-ok icon-white"></i> <?php _e('Book Now', 'appointzilla'); ?></button>
2061 <button type="button" class="apcal_btn apcal_btn-danger" id="ex-cancel-app" name="ex-cancel-app" onclick="return Canceling();"><i class="icon-remove icon-white"></i> <?php _e('Cancel', 'appointzilla'); ?></button>
2062 </div>
2063 <div id="ex-user-form-loading-img" style="display:none;"><?php _e('Scheduling appointment, please wait...', 'appointzilla'); ?><img src="<?php echo plugins_url('images/loading.gif', __FILE__); ?>" /></div>
2064 <div id="ex-canceling-img" style="display:none;"><?php _e('Refreshing, Please wait...', 'appointzilla'); ?><img src="<?php echo plugins_url('images/loading.gif', __FILE__); ?>" /></div>
2065 </td>
2066 </tr>
2067 </table>
2068 <?php
2069 } else { ?>
2070 <table width="100%" class="table">
2071 <tr>
2072 <td colspan="3">
2073 <?php _e("Sorry! No record found.","appointzilla"); ?>
2074 <button type="button" onclick="return TryAgainBooking();" class="apcal_btn apcal_btn-danger"><i class="fa fa-mail-reply"></i> Try Again</button>
2075 </td>
2076 </tr>
2077 </table>
2078 <?php
2079 }
2080 ?></div><?php
2081 }
2082 }
2083 $output_string = ob_get_contents();
2084 ob_end_clean();
2085 return $output_string;
2086}//end of short code function
2087?>