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