· 9 years ago · Apr 29, 2017, 01:54 PM
1<?php // shoet code file for mobile
2add_shortcode( 'APCAL_MOBILE', 'appointment_calendar_mobile_shortcode' );
3function appointment_calendar_mobile_shortcode() {
4 //ob_start();
5 $DateFormat = get_option('apcal_date_format');
6 if($DateFormat == '') $DateFormat = "d-m-Y";
7 $TimeFormat = get_option('apcal_time_format');
8 if($TimeFormat == '') $TimeFormat = "h:i";
9 $AllCalendarSettings = unserialize(get_option('apcal_calendar_settings'));
10 $small_calendar_type = $AllCalendarSettings['small_calendar_type'];
11 if($AllCalendarSettings['calendar_start_day'] != '') {
12 $CalStartDay = $AllCalendarSettings['calendar_start_day'];
13 } else {
14 $CalStartDay = 1;
15 } ?>
16
17 <!---load bootstrap css--->
18 <script type='text/javascript'>
19 jQuery(document).ready(function() {
20 // Modal Form Works - show first modal
21 jQuery('#addappointment').click(function(){
22 jQuery('#addappointment').hide();
23 jQuery('#bkbtndiv').hide();
24 jQuery('#AppForthModal').hide();
25 jQuery('#AppFirstModal').show();
26 });
27
28 //hide modal
29 jQuery('#close').click(function(){
30 jQuery('#AppFirstModal').hide();
31 });
32 <?php if($DateFormat == 'd-m-Y') $DPFormat = 'dd MM yy';
33 if($DateFormat == 'm-d-Y') $DPFormat = 'MM dd yy';
34 if($DateFormat == 'Y-m-d') $DPFormat = 'dd MM yy'; //coz yy-mm-dd not parsing in a correct date
35
36 if($small_calendar_type == "jquery") { ?>
37 //jQuery UI date picker on modal for
38 document.addnewappointment.appdate.value = jQuery.datepicker.formatDate('<?php echo $DPFormat; ?>', new Date());
39 jQuery(function(){
40 jQuery("#datepicker").datepicker({
41 inline: true,
42 minDate: 0,
43 altField: '#alternate',
44 firstDay: <?php if($AllCalendarSettings['calendar_start_day'] != '') echo $AllCalendarSettings['calendar_start_day']; else echo "0"; ?>,
45 //beforeShowDay: unavailable,
46 onSelect: function(dateText, inst) {
47 var dateAsString = dateText;
48 var seleteddate = jQuery.datepicker.formatDate('<?php echo $DPFormat; ?>', new Date(dateAsString));
49 var seleteddate2 = jQuery.datepicker.formatDate('dd-mm-yy', new Date(dateAsString));
50 document.addnewappointment.appdate.value = seleteddate;
51 document.addnewappointment.appdate2.value = seleteddate2;
52 },
53 });
54 //jQuery( "#datepicker" ).datepicker( jQuery.datepicker.regional[ "af" ] );
55 });
56 <?php } ?>
57
58 //AppFirstModal Validation
59 jQuery('#next1').click(function(){
60 jQuery(".error").hide();
61 if(jQuery('#service').val() == 0) {
62 jQuery("#service").after("<span class='error'><br><strong><?php _e('Select Any Service.', 'appointzilla'); ?></strong><br></span>");
63 return false;
64 }
65 });
66
67 });
68
69
70 // Modal Form Works
71 function loadseconmodal() {
72 var ServiceId = jQuery('#servicelist').val();
73 var AppDate = jQuery('#appdate2').val();
74 var StaffId = jQuery('#stafflist').val();
75 var SecondData = "ServiceId=" + ServiceId + "&AppDate=" + AppDate + "&StaffId=" + StaffId;
76 jQuery('#loading1').show(); // loading button onclick next1 at first modal
77 jQuery('#next1').hide(); //hide next button
78 jQuery.ajax({
79 dataType : 'html',
80 type: 'GET',
81 url : location.href,
82 cache: false,
83 data : SecondData,
84 complete : function() { },
85 success: function(data) {
86 data = jQuery(data).find('div#AppSecondModalData');
87 jQuery('#loading1').hide();
88 jQuery('#AppFirstModal').hide();
89 jQuery('#AppSecondModal').show();
90 jQuery('#AppSecondModal').html(data);
91 }
92 });
93 }
94
95 //load first modal on click back1
96 function loadfirstmodal() {
97 jQuery('#AppSecondModal').hide()
98 jQuery('#AppFirstModal').show();
99 jQuery('#next1').show();
100 }
101
102 //load second modal on back2 click
103 function LoadSecondModal2() {
104 jQuery('#AppThirdModal').hide();
105 jQuery('#buttondiv').show();
106 jQuery('#AppSecondModal').show();
107 }
108
109 //on new user button click
110 function NewUserBtn() {
111 jQuery('#new-user-div').show();
112 jQuery('#existing-user-div').hide();
113 jQuery('#check-email-result-div').hide();
114 }
115
116 //on existing user button click
117 function ExistingUserBtn() {
118 jQuery('#new-user-div').hide();
119 jQuery('#existing-user-div').show();
120 jQuery('#check-email-div-form').show();
121 }
122
123 //load third modal on-click next2
124 function loadthirdmodal() {
125 //validation on second modal form
126 jQuery('.error').hide();
127 var ServiceId = jQuery('#ServiceId').val();
128 var AppDate = jQuery('#AppDate').val();
129 var StaffId = jQuery('#StaffId').val();
130 var Start_Time = jQuery('input[name=start_time]:radio:checked').val();
131 if(!Start_Time) {
132 jQuery("#time_slot_box").after("<span class='error'><strong><?php _e('Select any time.', 'appointzilla'); ?></strong></span>");
133 return false;
134 }
135 var ThirdData = "ServiceId=" + ServiceId + "&AppDate=" + AppDate + "&StaffId=" + StaffId + "&StartTime=" + Start_Time ;
136 jQuery('#buttondiv').hide();
137 jQuery('#loading').show();
138 jQuery.ajax({
139 dataType : 'html',
140 type: 'GET',
141 url : location.href,
142 cache: false,
143 data : ThirdData,
144 complete : function() { },
145 success: function(data) {
146 data = jQuery(data).find('div#AppThirdModalData');
147 jQuery('#loading').hide();
148 jQuery('#AppSecondModal').hide();
149 jQuery('#AppThirdModal').show();
150 //jQuery('#formbtndiv').show();
151 jQuery('#AppThirdModal').html(data);
152 }
153 });
154 }
155
156 //load forth final modal for confirm appointment
157 function CheckValidation(UserType) {
158
159 jQuery(".error").hide();
160 var ServiceId = jQuery('#ServiceId').val();
161 var AppDate = jQuery('#AppDate').val();
162 var StaffId = jQuery('#StaffId').val();
163 var StartTime = jQuery('#StartTime').val();
164
165 /**
166 * new user booking case
167 */
168 if(UserType == "NewUser") {
169 <?php if($AllCalendarSettings['apcal_user_registration'] == "yes"){ ?>
170 var ClientUserName = jQuery("#client-username").val();
171 var ClientPassword = jQuery("#client-password").val();
172 var ClientConfirmPassword = jQuery("#client-confirm-password").val();
173 <?php } ?>
174 var ClientEmail = jQuery("#client-email").val();
175 var ClientFirstName = jQuery("#client-first-name").val();
176 var ClientLastName = jQuery("#client-last-name").val();
177 var ClientPhone = jQuery("#client-phone").val();
178 var ClientSi = jQuery("#client-si").val();
179
180 <?php if($AllCalendarSettings['apcal_user_registration'] == "yes"){ ?>
181 //client username
182 if (ClientUserName == "") {
183 jQuery("#client-username").after("<span class='error'> <br><strong><?php _e('Userame required.', 'appointzilla'); ?></strong></span>");
184 return false;
185 } else {
186 if(ClientUserName.length < 6) {
187 jQuery("#client-username").after("<span class='error'> <br><strong><?php _e('Choose a strong username.', 'appointzilla'); ?></strong></span>");
188 return false;
189 }
190 var Res = isNaN(ClientUserName);
191 if(Res == false) {
192 jQuery("#client-username").after("<span class='error'> <br><strong><?php _e('Invalid username.', 'appointzilla'); ?></strong></span>");
193 return false;
194 }
195 }
196
197 //client password
198 if (ClientPassword == "") {
199 jQuery("#client-password").after("<span class='error'> <br><strong><?php _e('Password required.', 'appointzilla'); ?></strong></span>");
200 return false;
201 } else {
202 if(ClientPassword.length < 6) {
203 jQuery("#client-password").after("<span class='error'> <br><strong><?php _e('Choose a strong password.', 'appointzilla'); ?></strong></span>");
204 return false;
205 }
206 }
207
208 //client confirm password
209 if (ClientConfirmPassword == "") {
210 jQuery("#client-confirm-password").after("<span class='error'> <br><strong><?php _e('Confirm password required.', 'appointzilla'); ?></strong></span>");
211 return false;
212 } else {
213 if(ClientConfirmPassword != ClientPassword) {
214 jQuery("#client-confirm-password").after("<span class='error'> <br><strong><?php _e('Confirm password do not match', 'appointzilla'); ?></strong></span>");
215 return false;
216 }
217 }
218 <?php } ?>
219
220 //client email
221 var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
222 if (ClientEmail == "") {
223 jQuery("#client-email").after("<span class='error'> <br><strong><?php _e('Email required.', 'appointzilla'); ?></strong></span>");
224 return false;
225 } else {
226 if(regex.test(ClientEmail) == false ) {
227 jQuery("#client-email").after("<span class='error'> <br><strong><?php _e('Invalid email.', 'appointzilla'); ?></strong></span>");
228 return false;
229 }
230 }
231
232 //client first name
233 if (ClientFirstName == "") {
234 jQuery("#client-first-name").after("<span class='error'> <br><strong><?php _e('First name required.', 'appointzilla'); ?></strong></span>");
235 return false;
236 } else {
237 var Res = isNaN(ClientFirstName);
238 if(Res == false) {
239 jQuery("#client-first-name").after("<span class='error'> <br><strong><?php _e('Invalid first name.', 'appointzilla'); ?></strong></span>");
240 return false;
241 }
242 var NameRegx = /^[a-zA-Z0-9- ]*$/;
243 if(NameRegx.test(ClientFirstName) == false) {
244 jQuery("#client-first-name").after("<span class='error'> <br><strong><?php _e('No special characters allowed.', 'appointzilla'); ?></strong></span>");
245 return false;
246 }
247 }
248
249 //client last name
250 if (ClientLastName == "") {
251 jQuery("#client-last-name").after("<span class='error'> <br><strong><?php _e('Last name required.', 'appointzilla'); ?></strong></span>");
252 return false;
253 } else {
254 var Res = isNaN(ClientLastName);
255 if(Res == false) {
256 jQuery("#client-last-name").after("<span class='error'> <br><strong><?php _e('Invalid last name.', 'appointzilla'); ?></strong></span>");
257 return false;
258 }
259 var NameRegx = /^[a-zA-Z0-9- ]*$/;
260 if(NameRegx.test(ClientLastName) == false) {
261 jQuery("#client-last-name").after("<span class='error'> <br><strong><?php _e('No special characters allowed.', 'appointzilla'); ?></strong></span>");
262 return false;
263 }
264 }
265
266 //client phone
267 if (ClientPhone == "") {
268 jQuery("#client-phone").after("<span class='error'> <br><strong><?php _e("Phone required. <br>Only Numbers 1234567890.", "appointzilla"); ?></strong></span>");
269 return false;
270 } else {
271 var ClientPhoneRes = isNaN(ClientPhone);
272 if(ClientPhoneRes == true) {
273 jQuery("#client-phone").after("<span class='error'> <br><strong><?php _e("Invalid phone. <br>Numbers only: 1234567890.", "appointzilla"); ?></strong></span>");
274 return false;
275 }
276 }
277
278 var PostData1 = "Action=BookAppointment"+ "&ServiceId=" + ServiceId + "&AppDate=" + AppDate + "&StaffId=" + StaffId + "&StartTime=" + StartTime;
279 <?php if($AllCalendarSettings['apcal_user_registration'] == "yes"){ ?>
280 var PostData2 = "&UserType=" + UserType + "&ClientUserName="+ ClientUserName + "&ClientPassword=" +ClientPassword + "&ClientEmail=" + ClientEmail;
281 <?php } else { ?>
282 var PostData2 = "&UserType=" + UserType + "&ClientEmail=" + ClientEmail;
283 <?php } ?>
284 var PostData3 = "&ClientFirstName=" + ClientFirstName + "&ClientLastName=" + ClientLastName + "&ClientPhone=" + ClientPhone + "&ClientNote=" + ClientSi;
285 var PostData = PostData1 + PostData2 + PostData3;
286
287 jQuery('#new-user-form-btn-div').hide();
288 jQuery('#new-user-form-loading-img').show();
289 }
290
291 /**
292 * existing user booking case
293 */
294 if(UserType == "ExUser") {
295 var ClientEmail = jQuery("#ex-client-email").val();
296 var ClientFirstName = jQuery("#ex-client-first-name").val();
297 var ClientLastName = jQuery("#ex-client-last-name").val();
298 var ClientPhone = jQuery("#ex-client-phone").val();
299 var ClientSi = jQuery("#ex-client-si").val();
300
301 //client email
302 var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
303 if (ClientEmail == "") {
304 jQuery("#ex-client-email").after("<span class='error'> <br><strong><?php _e('Email required.', 'appointzilla'); ?></strong></span>");
305 return false;
306 } else {
307 if(regex.test(ClientEmail) == false ) {
308 jQuery("#ex-client-email").after("<span class='error'> <br><strong><?php _e('Invalid email.', 'appointzilla'); ?></strong></span>");
309 return false;
310 }
311 }
312
313 //client first name
314 if (ClientFirstName == "") {
315 jQuery("#ex-client-first-name").after("<span class='error'> <br><strong><?php _e('First name required.', 'appointzilla'); ?></strong></span>");
316 return false;
317 } else {
318 var Res = isNaN(ClientFirstName);
319 if(Res == false) {
320 jQuery("#ex-client-first-name").after("<span class='error'> <br><strong><?php _e('Invalid first name.', 'appointzilla'); ?></strong></span>");
321 return false;
322 }
323 var NameRegx = /^[a-zA-Z0-9- ]*$/;
324 if(NameRegx.test(ClientFirstName) == false) {
325 jQuery("#ex-client-first-name").after("<span class='error'> <br><strong><?php _e('No special characters allowed.', 'appointzilla'); ?></strong></span>");
326 return false;
327 }
328 }
329
330 //client last name
331 if (ClientLastName == "") {
332 jQuery("#ex-client-last-name").after("<span class='error'> <br><strong><?php _e('Last name required.', 'appointzilla'); ?></strong></span>");
333 return false;
334 } else {
335 var Res = isNaN(ClientLastName);
336 if(Res == false) {
337 jQuery("#ex-client-last-name").after("<span class='error'> <br><strong><?php _e('Invalid last name.', 'appointzilla'); ?></strong></span>");
338 return false;
339 }
340 var NameRegx = /^[a-zA-Z0-9- ]*$/;
341 if(NameRegx.test(ClientLastName) == false) {
342 jQuery("#ex-client-last-name").after("<span class='error'> <br><strong><?php _e('No special characters allowed.', 'appointzilla'); ?></strong></span>");
343 return false;
344 }
345 }
346
347 //client phone
348 if (ClientPhone == "") {
349 jQuery("#ex-client-phone").after("<span class='error'> <br><strong><?php _e("Phone required. <br>Only Numbers 1234567890.", "appointzilla"); ?></strong></span>");
350 return false;
351 } else {
352 var ClientPhoneRes = isNaN(ClientPhone);
353 if(ClientPhoneRes == true) {
354 jQuery("#ex-client-phone").after("<span class='error'> <br><strong><?php _e("Invalid phone. <br>Numbers only: 1234567890.", "appointzilla"); ?></strong></span>");
355 return false;
356 }
357 }
358
359 var PostData1 = "Action=BookAppointment"+ "&ServiceId=" + ServiceId + "&AppDate=" + AppDate + "&StaffId=" + StaffId + "&StartTime=" + StartTime;
360 var PostData2 = "&UserType=" + UserType + "&ClientEmail=" + ClientEmail;
361 var PostData3 = "&ClientFirstName=" + ClientFirstName + "&ClientLastName=" + ClientLastName + "&ClientPhone=" + ClientPhone + "&ClientNote=" + ClientSi;
362 var PostData = PostData1 + PostData2 + PostData3;
363 jQuery('#ex-user-form-btn-div').hide();
364 jQuery('#ex-user-form-loading-img').show();
365 }
366
367 jQuery.ajax({
368 dataType : 'html',
369 type: 'POST',
370 url : location.href,
371 cache: false,
372 data : PostData,
373 complete : function() { },
374 success: function(data) {
375 data = jQuery(data).find('div#AppForthModalData');
376 jQuery("#new-user-form-loading-img").hide();
377 jQuery("#check-email-div-form").hide();
378 jQuery("#AppThirdModal").hide();
379 jQuery("#AppForthModalFinal").show();
380 jQuery("#AppForthModalFinal").html(data);
381 }
382 });
383 }
384
385 //check existing user
386 function CheckExistingUser() {
387 jQuery(".error").hide();
388 var ClientEmail = jQuery("#check-client-email").val();
389 //client email
390 var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
391 if (ClientEmail == "") {
392 jQuery("#check-client-email").after("<span class='error'> <br><strong><?php _e('Email required.', 'appointzilla'); ?></strong></span>");
393 return false;
394 } else {
395 if(regex.test(ClientEmail) == false ) {
396 jQuery("#check-client-email").after("<span class='error'> <br><strong><?php _e('Invalid email.', 'appointzilla'); ?></strong></span>");
397 return false;
398 }
399 }
400
401 var PostData = "Action=CheckExistingUser" + "&ClientEmail=" + ClientEmail;
402 jQuery("#existing-user-form-btn").hide();
403 jQuery("#existing-user-loading-img").show();
404 jQuery.ajax({
405 dataType : 'html',
406 type: 'POST',
407 url : location.href,
408 cache: false,
409 data : PostData,
410 complete : function() { },
411 success: function(Data) {
412 Data = jQuery(Data).find('div#check-email-result');
413 jQuery("#existing-user-loading-img").hide();
414 jQuery("#check-user").hide();
415 jQuery('#check-email-div-form').hide();
416 jQuery("#check-email-result-div").show();
417 jQuery("#check-email-result-div").html(Data);
418 }
419 });
420
421 }
422
423 function CloseModelform() {
424 jQuery('#AppForthModalFinal').hide();
425 jQuery('#AppSecondModalData').hide();
426 jQuery('#AppThirdModalData').hide();
427 location.href = location.href;
428 }
429
430 function highlightsradio(timeslotspanid) {
431 jQuery('span').removeClass('selected');
432 var spanid = "#" + timeslotspanid;
433 jQuery(spanid).addClass("selected");
434 }
435
436 // failed appointment
437 function failedappointment() {
438 var appid = jQuery('#appid').val();
439 var Datastring = "appstatus=cancel" + "&appid="+ appid;
440 var currenturl = jQuery(location).attr('href');
441 var url = currenturl;
442 jQuery.ajax({
443 dataType : 'html',
444 type: 'POST',
445 url : url,
446 cache: false,
447 data : Datastring,
448 complete : function() { },
449 success: function(data) {
450 jQuery('#AppForthModalFinal').hide();
451 jQuery('#AppSecondModalData').hide();
452 jQuery('#AppThirdModalData').hide();
453 var currenturl = jQuery(location).attr('href');
454 currenturl=currenturl.replace('failed=failed&appointId='+appid, '');
455 location.href = currenturl;
456 }
457 });
458 }
459
460 function CancelAppointment() {
461 var appid = jQuery('#appid').val();
462 var DataString = "appstatus=cancel" + "&appid="+ appid;
463 jQuery("#paybuttondiv").hide();
464 jQuery("#pay-canceling-img").show();
465 jQuery.ajax({
466 dataType : 'html',
467 type: 'POST',
468 url : location.href,
469 cache: false,
470 data : DataString,
471 complete : function() { },
472 success: function() {
473 jQuery('#AppForthModalFinal').hide();
474 jQuery('#AppSecondModalData').hide();
475 jQuery('#AppThirdModalData').hide();
476 window.location.reload();
477 }
478 });
479 }
480
481 //apply coupon code
482 function ApplyCoupon() {
483 var CouponCode = jQuery("#coupon-code").val();
484 if(CouponCode == "") {
485 alert("<?php _e("Enter any coupon code.", "appointzilla"); ?>");
486 jQuery("#coupon-code").focus();
487 return false;
488 } else {
489 var PostData = "Action=apply-coupon" + "&CouponCode=" + CouponCode;
490 jQuery("#loading-img").show();
491 jQuery.ajax({
492 dataType : 'html',
493 type: 'POST',
494 url : location.href,
495 cache: false,
496 data : PostData,
497 complete : function() { },
498 success: function(ReturnedData) {
499 ReturnedData = jQuery(ReturnedData).find("div#coupon-result");
500 jQuery("#loading-img").hide();
501 jQuery("#apply-coupon-div").hide();
502 jQuery("#show-coupon-result").html(ReturnedData);
503 jQuery("#show-coupon-result").show();
504 var CouponCodeValue = jQuery("#coupon-code-div").text();
505 var DicountRateValue = jQuery("#discount-rate-div").text();
506 //alert(CouponCodeValue + DicountRateValue);
507 jQuery("input[name=custom]").val(CouponCodeValue);
508 jQuery("input[name=discount_rate]").val(DicountRateValue);
509 }
510 });
511 }
512 }
513
514 //try another coupon code
515 function TryAgain() {
516 jQuery("#apply-coupon-div").show();
517 jQuery("#show-coupon-result").hide();
518 }
519
520 //try again booking
521 function TryAgainBooking() {
522 jQuery("#check-email-result-div").hide();
523 jQuery("#check-user").show();
524 jQuery('#check-email-div-form').show();
525 jQuery("#existing-user-form-btn").show();
526 }
527
528 //cancel appointment
529 function Canceling() {
530 jQuery("#ex-user-form-btn-div").hide();
531 jQuery("#ex-canceling-img").show();
532 location.reload();
533 }
534
535 // on paypal pay button click
536 function PayWithPaypal(){
537 jQuery('#show-redirecting-msg').show();
538 jQuery('#paybuttondiv').hide();
539 }
540 </script>
541
542 <style type='text/css'>
543 .selected {
544 outline:1px solid #FF0000; /* Firefox, Opera, Chrome, IE8+ */
545 background-color:#FFFF99;
546 }
547 .error{
548 color: #FF0000;
549 }
550 /*first modal- 2nd div confilicts css*/
551 .entry form {
552 text-align: left;
553 }
554 </style>
555
556 <!---Display Booking Instruction--->
557 <?php if($AllCalendarSettings['apcal_booking_instructions']) { ?>
558 <div id="bookinginstructions" align="center">
559 <?php echo $AllCalendarSettings['apcal_booking_instructions']; ?>
560 </div>
561 <?php } ?>
562
563 <!--- Schedule An Appointment Button--->
564 <div id=bkbtndiv align="center" style="padding:10px;">
565 <button name="addappointment" class="apcal_btn apcal_btn-large apcal_btn-primary" type="submit" id="addappointment">
566 <i class="icon-calendar icon-white"></i> <strong>
567 <?php $AllCalendarSettings = unserialize(get_option('apcal_calendar_settings'));
568 if(isset($AllCalendarSettings['booking_button_text'])) {
569 echo $AllCalendarSettings['booking_button_text'];
570 } else {
571 _e('Schedule New Appointment', 'appointzilla');
572 } ?>
573 </strong>
574 </button>
575 <!---Show powered By--->
576 <div style="text-align: center; font-size: xx-small;"><br>Appointment Calendar Premium Powered By: <a href="http://appointzilla.com/" title="Online Appointment Scheduling Plugin For WordPress" target="_blank">AppointZilla</a></div>
577 </div>
578
579 <!---AppFirstModal For Schedule New Appointment--->
580 <div id="AppFirstModal" style="float:right; display:none; width:100%; height:auto; padding-bottom:5px;">
581 <div id="apcal_myModal" style="z-index:10000;">
582 <form action="" method="post" name="addnewappointment" id="addnewappointment">
583 <div>
584 <div class="apcal_alert apcal_alert-info">
585 <p><strong><?php _e('Schedule New Appointment', 'appointzilla'); ?></strong></p>
586 <div><?php _e('Step 1. Select Time & Service', 'appointzilla'); ?></div>
587 </div>
588 </div>
589
590 <div>
591 <div class="col-md-6" id="firdiv" style="border: 0px solid red; display: inline-block;">
592 <!--JS Datepicker -->
593 <?php if($small_calendar_type == "jquery") { ?>
594 <div id="datepicker"></div>
595 <?php } ?>
596
597 <!--PHP Datepicker-->
598 <?php
599 if($DateFormat == 'd-m-Y') $CalFormat = 'DD-MM-YYYY';
600 if($DateFormat == 'm-d-Y') $CalFormat = 'MM-DD-YYYY';
601 if($DateFormat == 'Y-m-d') $CalFormat = 'YYYY-MM-DD'; //coz yy-mm-dd not
602
603 if(get_locale()) {
604 $language = get_locale();
605 if($language) { define('L_LANG',$language); }
606 }
607
608 //disable closed business days on small datepicker
609 global $wpdb;
610 $ClosedDays = array();
611 $StartDate = date("Y-m-d");
612 $StartDate = date('Y-m-d',strtotime($StartDate . "+1 days"));
613 $EndDate = "2035-01-01";
614 /*$BusinessHoursTable = $wpdb->prefix . "ap_business_hours";
615 $ClosedBusinessDays = $wpdb->get_results("SELECT * FROM `$BusinessHoursTable` WHERE `close` LIKE 'yes'");
616 if(count($ClosedBusinessDays)) {
617 foreach($ClosedBusinessDays as $ClosedBusinessDay) {
618 $ClosedDays[] = ucfirst(substr($ClosedBusinessDay->day, 0, 3));
619 }
620 }*/
621 require_once( plugin_dir_path( __FILE__ ) . 'calendar/tc_calendar.php');
622 $curr_date = date("Y-m-d", time());
623 $DatePicker2 = plugins_url('calendar/', __FILE__);
624 $myCalendar = new tc_calendar("date1");
625 foreach($ClosedDays as $Day) {
626 $myCalendar->disabledDay("$Day");
627 }
628 $myCalendar->startDate($CalStartDay);
629 $myCalendar->setIcon($DatePicker2."images/iconCalendar.gif");
630 $myCalendar->setDate(date("d", strtotime($StartDate)), date("m", strtotime($StartDate)), date("Y", strtotime($StartDate)));
631 $myCalendar->setPath($DatePicker2);
632 $myCalendar->setYearInterval(2035,date('Y'));
633 $StartCalendarFrom = date("Y-m-d", strtotime("0 day", strtotime($StartDate)));
634 $myCalendar->dateAllow($StartCalendarFrom, $EndDate, false);
635 $myCalendar->setOnChange("myChanged()");
636
637 if($small_calendar_type == "php") {
638 $myCalendar->writeScript();
639 }
640 ?>
641
642 <script language="javascript">
643 function myChanged() {
644 var x = document.getElementById('date1').value;
645 var x2 = document.getElementById('date1').value;
646 x = moment(x).format('<?php echo $CalFormat; ?>');
647 x2 = moment(x2).format('DD-MM-YYYY');
648 document.getElementById('appdate').value = x;
649 document.getElementById('appdate2').value = x2;
650 }
651 </script>
652 </div>
653
654 <div class="col-md-6" id="secdiv" style="border: 0px solid red; display: inline-block; vertical-align: top; padding: 5px;">
655 <!--float:right; margin-right:5%; width:40%;-->
656 <strong><?php _e('Your Appointment Date:', 'appointzilla'); ?> </strong><br>
657 <input name="appdate" id="appdate" type="text" readonly="" style="height:30px; width:100%; padding-left: 15px;" value="<?php echo date($DateFormat, strtotime($StartDate)); ?>" /><br>
658 <input name="appdate2" id="appdate2" type="hidden" readonly="" style="height:30px; width:100%" value="<?php echo date("Y-m-d", strtotime($StartDate)); ?>" />
659 <?php global $wpdb;
660
661 $CategoryTable = $wpdb->prefix."ap_service_category";
662 $FindCategorySQL = "SELECT * FROM `$CategoryTable` order by `name` ASC";
663 $Allcategory = $wpdb->get_results($FindCategorySQL, OBJECT); ?>
664
665 <style type="text/css"> .mycss { font-weight:bold; } </style>
666 <strong><?php _e('Select Service:', 'appointzilla'); ?></strong><br>
667 <select name="servicelist" id="servicelist">
668 <option value="0"><?php _e('Select Service', 'appointzilla'); ?></option>
669 <?php
670 $cal_admin_currency_id = get_option('cal_admin_currency');
671 if($cal_admin_currency_id) {
672 $CurrencyTableName = $wpdb->prefix . "ap_currency";
673 $cal_admin_currency = $wpdb->get_row("SELECT `symbol` FROM `$CurrencyTableName` WHERE `id` = '$cal_admin_currency_id'");
674 $cal_admin_currency = $cal_admin_currency->symbol;
675 } else {
676 $cal_admin_currency = "$";
677 }
678
679 if($AllCalendarSettings['show_service_cost'] == 'yes') $ShowCost = 1; else $ShowCost = 0;
680 if($AllCalendarSettings['show_service_duration'] == 'yes') $ShowDuration = 1; else $ShowDuration = 0;
681 $ServiceTable = $wpdb->prefix."ap_services";
682 foreach($Allcategory as $Category) {
683 echo "<option value='$Category->id' disabled class='mycss'>".ucwords($Category->name)."</option>";
684
685 $FindServiceSql = "SELECT * FROM `$ServiceTable` WHERE `availability` = 'yes' and `category_id` = '$Category->id' order by `name` ASC";
686 $AllServices = $wpdb->get_results($FindServiceSql, OBJECT);
687 if(count($AllServices)) {
688 foreach($AllServices as $Service) { ?>
689 <option value="<?php echo $Service->id?>">
690 <?php echo ucwords($Service->name);
691 if($ShowDuration || $ShowCost) {
692 echo " (";
693 }
694 if($ShowDuration) {
695 echo $Service->duration."min";
696 }
697 if($ShowDuration && $ShowCost && $Service->cost) {
698 echo "/";
699 }
700 if($ShowCost && $Service->cost) {
701 echo $cal_admin_currency. $Service->cost;
702 }
703 if($ShowDuration || $ShowCost) {
704 echo ")";
705 } ?>
706 </option><?php
707 }
708 } else {
709 echo "<option disabled> ".ucwords(__('No service in this category', 'appointzilla'))."</option>";
710 }
711 } ?>
712 </select>
713 <br>
714 <script type="text/javascript">
715 //load staff according to service - start
716 jQuery('#servicelist').change(function(){
717
718 var ServiceId = jQuery("select#servicelist").val();
719 if(ServiceId > 0) {
720 jQuery('#loading-staff').show();
721 jQuery('#staff').hide();
722 var FirstData = "ServiceId=" + ServiceId;
723 jQuery.ajax({
724 dataType : 'html',
725 type: 'GET',
726 url : location.href,
727 data : FirstData,
728 complete : function() { },
729 success: function(data) {
730 data=jQuery(data).find('div#stfflistdiv');
731 jQuery('#staff').show();
732 jQuery('#loading-staff').hide();
733 jQuery('#staff').html(data);
734 }
735 });
736 } else {
737 jQuery('#staff').hide();
738 }
739 });
740 </script>
741 <div id="loading-staff" style="display:none;"><?php _e('Loading Staff...', 'appointzilla'); ?><img src="<?php echo plugins_url('images/loading.gif', __FILE__); ?>" /></div>
742 <div id="staff"></div>
743 </div><!--#secdiv-->
744 </div><!--#modal-body-->
745 </form>
746 </div>
747 </div>
748 <!---AppSecondModal For Schedule New Appointment--->
749
750 <!---AppSecondModal For Schedule New Appointment--->
751 <div id="AppSecondModal" style="display:none;"></div>
752 <!---AppSecondModal For Schedule New Appointment End--->
753
754 <!---AppThirdModal For Schedule New Appointment--->
755 <div id="AppThirdModal" style="display:none;"></div>
756 <!---AppThirdModal For Schedule New Appointment End--->
757 <div id="AppForthModalFinal" style="display:none;">
758
759 </div>
760 <!---AppThirdModal For Schedule New Appointment End--->
761
762 <!--date-picker js -->
763 <script src="<?php echo plugins_url('/menu-pages/datepicker-assets/js/jquery.ui.datepicker.js', __FILE__); ?>" type="text/javascript"></script>
764
765 <!---Loading staff ajax return code--->
766 <?php if(isset($_GET['ServiceId'])) { ?>
767 <!---load bootstrap css--->
768 <link rel='stylesheet' type='text/css' href='<?php echo plugins_url('/bootstrap-assets/css/bootstrap.css', __FILE__); ?>' />
769
770 <div id="stfflistdiv">
771 <?php
772 $ServiceID = $_GET['ServiceId'];
773 if($ServiceID) {
774 $ServiceTable = $wpdb->prefix . "ap_services";
775 $StaffTable = $wpdb->prefix . "ap_staff";
776 $AllStaffIdList = $wpdb->get_row("SELECT `staff_id` FROM `$ServiceTable` WHERE `id` = '$ServiceID'", OBJECT);
777 $AllStaffIdList = unserialize($AllStaffIdList->staff_id);
778 if(count($AllStaffIdList) > 1) {
779 ?>
780 <strong><?php _e('Select Staff:', 'appointzilla'); ?></strong><br>
781 <select name='stafflist' id='stafflist' style="width:100%">
782 <?php //get all staff id list by service id
783
784 if(count($AllStaffIdList)) {
785 foreach($AllStaffIdList as $StaffId) {
786 $StaffDetails = $wpdb->get_row("SELECT `id`, `name` FROM `$StaffTable` WHERE `id` = '$StaffId'", OBJECT);
787 echo "<option value='".$StaffDetails->id."'> ".ucwords($StaffDetails->name)."</option>";
788 }
789 } else {
790 echo "<option value='1'>".__("No Staff Assigned")."</option>";
791 }
792 ?>
793 </select>
794 <br>
795 <?php
796 } else { // end of count > 1
797 if(count($AllStaffIdList)) {
798 foreach($AllStaffIdList as $StaffId) {
799 $StaffDetails = $wpdb->get_row("SELECT `id`, `name` FROM `$StaffTable` WHERE `id` = '$StaffId'", OBJECT);
800 echo "<input type='hidden' name='stafflist' id='stafflist' value='$StaffDetails->id'>";
801 }
802 }
803 } // end of count > 1 else
804 ?>
805 <button type="button" class="apcal_btn" id="next1" name="next1" onclick="loadseconmodal()"><?php _e('Next', 'appointzilla'); ?> <i class="icon-arrow-right"></i></button>
806 <div id="loading1" style="display:none;"><?php _e('Loading...', 'appointzilla'); ?><img src="<?php echo plugins_url("images/loading.gif", __FILE__); ?>" /></div>
807 <?php } //end of service id if ?>
808 </div><?php
809 } ?>
810
811
812 <!---loading second modal form ajax return code--->
813 <?php require_once('shortcode-time-slot-calculation-mobile.php'); ?>
814 <!---loading second modal form ajax return code--->
815
816
817 <!---loading third modal form ajax return code--->
818 <?php if( isset($_GET['StartTime']) && isset($_GET['StaffId']) ) { ?>
819 <div id="AppThirdModalData">
820 <div id="AppThirdModal" style="z-index:10000;">
821 <input name="ServiceId" id="ServiceId" type="hidden" value="<?php if(isset($_GET['ServiceId'])) { echo $_GET['ServiceId']; } ?>" />
822 <input name="StaffId" id="StaffId" type="hidden" value="<?php if(isset($_GET['StaffId'])) { echo $_GET['StaffId']; } ?>" />
823 <input name="AppDate" id="AppDate" type="hidden" value="<?php if(isset($_GET['AppDate'])) { echo $_GET['AppDate']; } ?>" />
824 <input name="StartTime" id="StartTime" type="hidden" value="<?php if(isset($_GET['StartTime'])) { echo $_GET['StartTime']; } ?>" />
825 <input name="EndTime" id="EndTime" type="hidden" value="<?php if(isset($_GET['EndTime'])) { echo $_GET['EndTime']; } ?>" />
826 <input name="RecurringType" id="RecurringType" type="hidden" value="<?php if(isset($_GET['RecurringType'])) { echo $_GET['RecurringType']; } ?>" />
827 <input name="RecurringStartDate" id="RecurringStartDate" type="hidden" value="<?php if(isset($_GET['recurring_start_date'])) { echo $_GET['recurring_start_date']; } ?>" />
828 <input name="RecurringEndDate" id="RecurringEndDate" type="hidden" value="<?php if(isset($_GET['recurring_end_date'])) { echo $_GET['recurring_end_date']; } ?>" />
829
830 <div>
831 <div class="apcal_alert apcal_alert-info">
832 <p><strong><?php _e('Schedule New Appointment', 'appointzilla'); ?></strong></p>
833 <?php _e('Step 3. Complete Your Booking', 'appointzilla'); ?>
834 </div>
835 </div>
836
837 <div class="apcal_modal-body" style="max-height: 100%;">
838 <?php if($AllCalendarSettings['apcal_user_registration'] == "yes") { ?>
839 <!--check user div-->
840 <div id="check-user">
841 <table width="100%" class="table">
842 <tr>
843 <td colspan="3">
844 <button id="new-user" name="new-user" class="apcal_btn apcal_btn-info" onclick="return NewUserBtn();"><i class="icon-user icon-white"></i> <?php _e("New User", "appointzilla"); ?></button>
845 <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>
846 <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>
847 </td>
848 </tr>
849 </table>
850 </div>
851
852 <!--new user div-->
853 <div id="new-user-div" style="display: none;">
854 <table width="100%" class="table">
855 <tr>
856 <th scope="row"><?php _e('Username', 'appointzilla'); ?></th>
857 <td><strong>:</strong></td>
858 <td><input name="client-username" type="text" id="client-username" style="height:30px;" /></td>
859 </tr>
860 <tr>
861 <th scope="row"><?php _e('Password', 'appointzilla'); ?></th>
862 <td><strong>:</strong></td>
863 <td><input name="client-password" type="password" id="client-password" style="height:30px;" /></td>
864 </tr>
865 <tr>
866 <th scope="row"><?php _e('Confirm Password', 'appointzilla'); ?></th>
867 <td><strong>:</strong></td>
868 <td><input name="client-confirm-password" type="password" id="client-confirm-password" style="height:30px;" /></td>
869 </tr>
870 <tr>
871 <th scope="row"><?php _e('Email', 'appointzilla'); ?></th>
872 <td><strong>:</strong></td>
873 <td><input name="client-email" type="text" id="client-email" style="height:30px;" /></td>
874 </tr>
875 <tr>
876 <th scope="row"><?php _e('First Name', 'appointzilla'); ?></th>
877 <td><strong>:</strong></td>
878 <td><input name="client-first-name" type="text" id="client-first-name" style="height:30px;" /></td>
879 </tr>
880 <tr>
881 <th scope="row"><?php _e('Last Name', 'appointzilla'); ?></th>
882 <td><strong>:</strong></td>
883 <td><input name="client-last-name" type="text" id="client-last-name" style="height:30px;" /></td>
884 </tr>
885 <tr>
886 <th scope="row"><?php _e('Phone', 'appointzilla'); ?></th>
887 <td><strong>:</strong></td>
888 <td><input name="client-phone" type="text" id="client-phone" style="height:30px;" maxlength="14"/></td>
889 </tr>
890 <tr>
891 <th scope="row"><?php _e('Special Instruction', 'appointzilla'); ?></th>
892 <td><strong>:</strong></td>
893 <td><textarea name="client-si" id="client-si"></textarea></td>
894 </tr>
895 <tr>
896 <td> </td>
897 <td> </td>
898 <td>
899 <div id="new-user-form-btn-div">
900 <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>
901 </div>
902 <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>
903 </td>
904 </tr>
905 </table>
906 </div>
907
908 <!--existing user div-->
909 <div id="existing-user-div" style="display: none;">
910
911 <!--div for display existing user search details-->
912 <div id="check-email-div-form" style="display: none;">
913 <table width="100%" class="table">
914 <tr>
915 <th scope="row"><?php _e('Email', 'appointzilla'); ?></th>
916 <td><strong>:</strong></td>
917 <td><input name="check-client-email" type="text" id="check-client-email" style="height:30px;" /></td>
918 </tr>
919 <tr>
920 <td> </td>
921 <td> </td>
922 <td>
923 <div id="existing-user-form-btn">
924 <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>
925 </div>
926 <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>
927 </td>
928 </tr>
929 </table>
930 </div>
931
932 <!--div for display existing user search details-->
933 <div id="check-email-result-div" style="display: none;">
934 </div>
935 </div>
936 <?php } else { // end of if registration enable?>
937 <!--user registration not enable-->
938 <div id="no-user-registration">
939 <table width="100%" class="table">
940 <tr>
941 <th scope="row"><?php _e('Email', 'appointzilla'); ?></th>
942 <td><strong>:</strong></td>
943 <td><input name="client-email" type="text" id="client-email" style="height:30px;" /></td>
944 </tr>
945 <tr>
946 <th scope="row"><?php _e('First Name', 'appointzilla'); ?></th>
947 <td><strong>:</strong></td>
948 <td><input name="client-first-name" type="text" id="client-first-name" style="height:30px;" /></td>
949 </tr>
950 <tr>
951 <th scope="row"><?php _e('Last Name', 'appointzilla'); ?></th>
952 <td><strong>:</strong></td>
953 <td><input name="client-last-name" type="text" id="client-last-name" style="height:30px;" /></td>
954 </tr>
955 <tr>
956 <th scope="row"><?php _e('Phone', 'appointzilla'); ?></th>
957 <td><strong>:</strong></td>
958 <td><input name="client-phone" type="text" id="client-phone" style="height:30px;" maxlength="14"/></td>
959 </tr>
960 <tr>
961 <th scope="row"><?php _e('Special Instruction', 'appointzilla'); ?></th>
962 <td><strong>:</strong></td>
963 <td><textarea name="client-si" id="client-si"></textarea></td>
964 </tr>
965 <tr>
966 <td> </td>
967 <td> </td>
968 <td>
969 <div id="new-user-form-btn-div">
970 <button type="button" class="apcal_btn" id="back2" name="back2" onclick="LoadSecondModal2()"><i class="icon-arrow-left"></i> <?php _e('Back', 'appointzilla'); ?></button>
971 <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>
972 </div>
973 <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>
974 </td>
975 </tr>
976 </table>
977 </div>
978 <?php } ?>
979 </div><!--end modal-body-->
980 </div>
981 </div><?php
982 } ?>
983
984
985 <!---saving appointments--->
986 <?php if( isset($_POST['Action'])) {
987 $Action = $_POST['Action'];
988 $UserType = $_POST['UserType'];
989 if($Action == "BookAppointment") {
990 //print_r($_POST); die;
991 $ServiceId = $_POST['ServiceId'];
992 $StaffId = $_POST['StaffId'];
993 $AppDateNo = $_POST['AppDate'];
994
995 $ClientEmail = $_POST['ClientEmail'];
996 $ClientFirstName = sanitize_text_field($_POST['ClientFirstName']);
997 $ClientLastName = sanitize_text_field($_POST['ClientLastName']);
998 $ClientName = $ClientFirstName ." ". $ClientLastName;
999 $ClientPhone = $_POST['ClientPhone'];
1000 $ClientNote = $_POST['ClientNote'];
1001 $AppointmentKey = md5(date("F j, Y, g:i a"));
1002 $AppDate = date("Y-m-d", strtotime($AppDateNo));
1003 $StartTime = $_POST['StartTime'];
1004
1005 //check user registration yes/no
1006 if($AllCalendarSettings['apcal_user_registration'] == "yes"){
1007 if($UserType == "NewUser") {
1008 $ClientUserName = $_POST['ClientUserName'];
1009 $ClientPassword = $_POST['ClientPassword'];
1010
1011 //create new user profile as subscriber
1012 echo $UserId = username_exists( $ClientUserName );
1013 if ( !$UserId and email_exists($ClientEmail) == false ) {
1014 $UserId = wp_create_user( $ClientUserName, $ClientPassword, $ClientEmail );
1015 if($UserId){
1016 add_user_meta( $UserId, 'first_name', $ClientFirstName);
1017 add_user_meta( $UserId, 'last_name', $ClientLastName);
1018 add_user_meta( $UserId, 'client_phone', $ClientPhone);
1019 add_user_meta( $UserId, 'client_note', $ClientNote);
1020 }
1021 } else {
1022 _e("User already exists", "appointzilla");
1023 }
1024 }
1025
1026 if($UserType == "ExUser") {
1027 //update existing user profile as subscriber
1028 echo $UserId = email_exists($ClientEmail);
1029 if($UserId){
1030 update_user_meta( $UserId, 'first_name', $ClientFirstName);
1031 update_user_meta( $UserId, 'last_name', $ClientLastName);
1032 update_user_meta( $UserId, 'client_phone', $ClientPhone);
1033 update_user_meta( $UserId, 'client_note', $ClientNote);
1034 } else {
1035 _e("User already exists", "appointzilla");
1036 }
1037 }
1038 } // end of check user registration
1039
1040 //fetch service detail calculation EndTime and Service name
1041 $ServiceTableName = $wpdb->prefix . "ap_services";
1042 $ServiceName = $wpdb->get_row("SELECT * FROM `$ServiceTableName` WHERE `id` = '$ServiceId' ");
1043 $ServiceDuration = $ServiceName->duration;
1044
1045 $StartTimeTimestamp = strtotime($StartTime);
1046 //calculate end time according to service duration
1047 $CalculateTime = strtotime("+$ServiceDuration minutes", $StartTimeTimestamp);
1048 $EndTime = date('h:i A', $CalculateTime );
1049
1050 if(isset($AllCalendarSettings['apcal_new_appointment_status'])) {
1051 $Status = $AllCalendarSettings['apcal_new_appointment_status'];
1052 } else {
1053 $Status = "pending";
1054 }
1055 $AppointmentBy = "user";
1056 $Recurring = "no";
1057 $RecurringType = "none";
1058 $RecurringStartDate = $AppDate;
1059 $RecurringEndDate = $AppDate;
1060 $PaymentStatus = "unpaid";
1061
1062 global $wpdb;
1063 $AppointmentsTable = $wpdb->prefix ."ap_appointments";
1064 $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');";
1065
1066 if($wpdb->query($CreateAppointments)) {
1067 $LastAppointmentId = $wpdb->insert_id; ?>
1068 <div id="AppForthModalData">
1069 <?php global $wpdb;
1070 $ClientTable = $wpdb->prefix."ap_clients";
1071 $ExistClientDetails = $wpdb->get_row("SELECT * FROM `$ClientTable` WHERE `email` = '$ClientEmail' ");
1072 if(count($ExistClientDetails)) {
1073 // update exiting client deatils
1074 $ExistClientId = $ExistClientDetails->id;
1075 $update_client = "UPDATE `$ClientTable` SET `name` = '$ClientName', `email` = '$ClientEmail', `phone` = '$ClientPhone', `note` = '$ClientNote' WHERE `id` = '$ExistClientId' ;";
1076 if($wpdb->query($update_client)) {
1077 $LastClientId = $ExistClientId;
1078 } else {
1079 // if now data filed modified then
1080 $LastClientId = $ExistClientId;
1081 }
1082 } else {
1083 // insert new client deatils
1084 $InsertClient = "INSERT INTO `$ClientTable` (`id` ,`name` ,`email` ,`phone` ,`note`) VALUES ('NULL', '$ClientName', '$ClientEmail', '$ClientPhone', '$ClientNote');";
1085 if($wpdb->query($InsertClient)) {
1086 $LastClientId = $wpdb->insert_id;
1087 }
1088 } ?>
1089
1090 <div id="AppForthModal" style="z-index:10000;">
1091 <div class="apcal_modal-info">
1092 <div style="float:right; margin-top:5px; margin-right:10px;"></div>
1093 <div class="apcal_alert apcal_alert-info">
1094 <p><?php _e('Thank You. Your appointment has been scheduled.', 'appointzilla'); ?></p>
1095 </div>
1096
1097 <div class="apcal_modal-body">
1098 <style>
1099 .table th, .table td {
1100 padding: 4px;;
1101 }
1102 </style>
1103 <strong><?php _e('Your Appointment Details', 'appointzilla'); ?></strong>
1104 <input type="hidden" id="appid" name="appid" value="<?php echo $LastAppointmentId; ?>" />
1105 <table width="100%" class="table">
1106 <tr>
1107 <th width="26%" scope="row"><?php _e('Name', 'appointzilla'); ?></th>
1108 <td width="1%"><strong>:</strong></td>
1109 <td width="73%"><?php echo ucwords($ClientName); ?></td>
1110 </tr>
1111 <tr>
1112 <th width="26%" scope="row"><?php _e('Email', 'appointzilla'); ?></th>
1113 <td width="1%"><strong>:</strong></td>
1114 <td width="73%"><?php echo $ClientEmail; ?></td>
1115 </tr>
1116 <tr>
1117 <th width="26%" scope="row"><?php _e('Phone', 'appointzilla'); ?></th>
1118 <td width="1%"><strong>:</strong></td>
1119 <td width="73%"><?php echo $ClientPhone; ?></td>
1120 </tr>
1121 <tr>
1122 <th width="26%" scope="row"><?php _e('Service', 'appointzilla'); ?></th>
1123 <td width="1%"><strong>:</strong></td>
1124 <td width="73%"><?php echo ucwords($ServiceName->name); ?></td>
1125 </tr>
1126 <tr>
1127 <th width="26%" scope="row"><?php _e('Staff', 'appointzilla'); ?></th>
1128 <td width="1%"><strong>:</strong></td>
1129 <td width="73%">
1130 <?php $StaffTableName = $wpdb->prefix . "ap_staff";
1131 $StaffName = $wpdb->get_row("SELECT `name` FROM `$StaffTableName` WHERE `id` = '$StaffId' ");
1132 echo ucwords($StaffName->name); ?>
1133 </td>
1134 </tr>
1135 <tr>
1136 <th width="26%" scope="row"><?php _e('Date', 'appointzilla'); ?></th>
1137 <td width="1%"><strong>:</strong></td>
1138 <td width="73%"><?php echo date($DateFormat, strtotime($AppDate)); ?></td>
1139 </tr>
1140 <tr>
1141 <?php if($TimeFormat == "h:i") $InfoTimeFormat = "h:i A"; else $InfoTimeFormat = "H:i"; ?>
1142 <th width="26%" scope="row"><?php _e('Time', 'appointzilla'); ?></th>
1143 <td width="1%"><strong>:</strong></td>
1144 <td width="73%"><?php echo date($InfoTimeFormat, strtotime($StartTime))." - ".date($InfoTimeFormat, strtotime($EndTime)); ?></td>
1145 </tr>
1146 <tr>
1147 <th width="26%" scope="row"><?php _e('Status', 'appointzilla'); ?></th>
1148 <td width="1%"><strong>:</strong></td>
1149 <td width="73%"><?php echo _e(ucfirst($Status),'appointzilla'); ?></td>
1150 </tr>
1151 <?php
1152 //get service details for payment purpose & also check payment settings
1153 global $wpdb;
1154 $ServiceTableName = $wpdb->prefix . 'ap_services';
1155 $ServiceDetails = $wpdb->get_row("SELECT * FROM `$ServiceTableName` WHERE `id` = '$ServiceId'");
1156 $AcceptPayment = $ServiceDetails->accept_payment;
1157 $PaymentType = $ServiceDetails->payment_type;
1158 $ap_payment_email = get_option('ap_payment_email');
1159 $ap_payment_gateway_status = get_option('ap_payment_gateway_status');
1160 if($AcceptPayment == "yes" && $PaymentType == "full" && $ap_payment_email && $ap_payment_gateway_status == "yes") {
1161 ?>
1162 <tr>
1163 <th width="26%" scope="row"><?php _e('Coupon Code', 'appointzilla'); ?></th>
1164 <td width="1%"><strong>:</strong></td>
1165 <td width="73%">
1166 <div id="apply-coupon-div">
1167 <input type="text" id="coupon-code" name="coupon-code" maxlength="15" style="width: 120px;">
1168 <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>
1169 </div>
1170
1171 <div id="loading-img" style="display:none;"><?php _e('Applying...', 'appointzilla'); ?><img src="<?php echo plugins_url("images/loading.gif", __FILE__); ?>" /></div>
1172 <div id="show-coupon-result" style="display:none;"></div>
1173 </td>
1174 </tr>
1175 <?php } ?>
1176 <tr>
1177 <td colspan="3">
1178 <?php $Check1 = 0; $Check2 = 0; $Check3 = 0;
1179 /**
1180 * Paypal Payment Process
1181 **/
1182 //get service details for payment purpose
1183 global $wpdb;
1184 $ServiceTableName = $wpdb->prefix . 'ap_services';
1185 $ServiceDetails = $wpdb->get_row("SELECT * FROM `$ServiceTableName` WHERE `id` = '$ServiceId'");
1186
1187 //get currency code
1188 $CurrencyId = get_option('cal_admin_currency');
1189 if($CurrencyId != '') {
1190 $CurrencyTableName = $wpdb->prefix."ap_currency";
1191 $CurrencyDetails = $wpdb->get_row("SELECT `code` FROM `$CurrencyTableName` WHERE `id` = '$CurrencyId'");
1192 $CurrencyCode = $CurrencyDetails->code;
1193 } else {
1194 $CurrencyCode = 'USD';
1195 }
1196
1197 $Protocol = stripos($_SERVER['SERVER_PROTOCOL'],'https') === true ? 'https://' : 'http://';
1198 $SuccessCurrentUrl = $Protocol.$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
1199 $FailedCurrentUrl = $SuccessCurrentUrl."?&failed=failed&appointId=".$LastAppointmentId;
1200
1201 //check payment is 'yes'
1202 if($ap_payment_gateway_status == 'yes') {
1203
1204 //check service is paid
1205 if($ServiceDetails->accept_payment == 'yes') {
1206 //check payment type
1207 if($ServiceDetails->payment_type == 'percentage') {
1208 $PayCost = $ServiceDetails->cost;
1209 $percentage = $ServiceDetails->percentage_ammount;
1210 $PayCost = ($PayCost * $percentage) /100;
1211 } else {
1212 $PayCost = $ServiceDetails->cost;
1213 }
1214
1215 $ApPaymentEmail = get_option('ap_payment_email');
1216 if($ApPaymentEmail) {
1217 // default discount value
1218 $DiscountRate = 0;
1219
1220 // Include the paypal library
1221 require_once ('menu-pages/paypal-api/Scientechpaypal.php');
1222 $ScientechPaypal = new Scientechpaypal();
1223 $ScientechPaypal->TakePayment($ApPaymentEmail, $CurrencyCode, $SuccessCurrentUrl, $FailedCurrentUrl, $ServiceDetails->name, $PayCost, $LastAppointmentId, $DiscountRate);
1224 } else {
1225 $Check3 = 1; ?>
1226 <!--<button type="submit" class="apcal_btn apcal_btn-primary" onclick="CloseModelform()" style="margin-left:80%"><i class="icon-ok icon-white"></i> <?php /*_e('Done', 'appointzilla'); */?></button>--><?php
1227 }
1228 } else {
1229 $Check2 = 1;
1230 ?><!--<button type="button" class="apcal_btn apcal_btn-primary" onclick="CloseModelform()" ><i class="icon-ok icon-white"></i> --><?php /*_e('Done', 'appointzilla'); */?></button>
1231 <?php
1232 }
1233 } else {
1234 $Check1 = 1;
1235 }
1236
1237 // send notification if any of check == 1
1238 if($Check1 || $Check2 || $Check3) { ?>
1239 <button type="submit" class="apcal_btn apcal_btn" onclick="CloseModelform()" style="margin-left:80%"><i class="icon-ok"></i> <?php _e('Done', 'appointzilla'); ?></button>
1240 <?php $BlogName = get_bloginfo('name');
1241 if($LastAppointmentId && $LastClientId) {
1242 $AppId = $LastAppointmentId;
1243 $ServiceId = $ServiceId;
1244 $StaffId = $StaffId;
1245 $ClientId = $LastClientId;
1246 //include notification class
1247 require_once('menu-pages/notification-class.php');
1248 $Notification = new Notification();
1249 $Notification->notifyadmin($Status, $AppId, $ServiceId, $StaffId, $ClientId, $BlogName, $DateFormat, $TimeFormat);
1250 $Notification->notifyclient($Status, $AppId, $ServiceId, $StaffId, $ClientId, $BlogName, $DateFormat, $TimeFormat);
1251 if(get_option('staff_notification_status') == 'on') {
1252 $Notification->notifystaff($Status, $AppId, $ServiceId, $StaffId, $ClientId, $BlogName, $DateFormat, $TimeFormat);
1253 }
1254 }
1255 }
1256
1257 //if status is approved then sync appointment
1258 if($Status == 'approved') {
1259
1260 //add service name with event title($name)
1261 //$ServiceTable = $wpdb->prefix . "ap_services";
1262 //$ServiceData = $wpdb->get_row("SELECT * FROM `$ServiceTable` WHERE `id` = '$ServiceId'");
1263 //$name = $name."(".$ServiceData->name.")";
1264
1265 /***
1266 * admin appointment sync
1267 */
1268 $CalData = get_option('google_caelndar_settings_details');
1269 if($CalData['google_calendar_client_id'] != '' && $CalData['google_calendar_secret_key'] != '') {
1270 $StartTime = date("H:i", strtotime($StartTime));
1271 $EndTime = date("H:i", strtotime($EndTime));
1272 $AppDate = date("Y-m-d", strtotime($AppDate));
1273 $ClientNote = strip_tags($ClientNote);
1274
1275 $ClientId = $CalData['google_calendar_client_id'];
1276 $ClientSecretId = $CalData['google_calendar_secret_key'];
1277 $RedirectUri = $CalData['google_calendar_redirect_uri'];
1278 require_once('menu-pages/google-appointment-sync-class.php');
1279
1280 //global $wpdb;
1281 $AppointmentSyncTableName = $wpdb->prefix . "ap_appointment_sync";
1282 // insert this appointment event on calendar
1283 $GoogleAppointmentSync = new GoogleAppointmentSync($ClientId, $ClientSecretId, $RedirectUri);
1284 $tag = "Appointment with: ";
1285 $OAuth = $GoogleAppointmentSync->NormalSync($ClientName, $AppDate, $StartTime, $EndTime, $ClientNote, $tag);
1286 //insert appintment sync details
1287 $OAuth = serialize($OAuth);
1288 $wpdb->query("INSERT INTO `$AppointmentSyncTableName` ( `id` , `app_id` , `app_sync_details` ) VALUES ( NULL , '$AppId', '$OAuth' );");
1289 } // end of google calendar setting
1290
1291 /***
1292 * staff appointment sync
1293 */
1294 $StaffAppointmentSyncSettings = unserialize(get_option("staff_google_calendar_sync_settings_".$StaffId));
1295 if($StaffAppointmentSyncSettings['StaffGoogleCalendarClientId'] != "" && $StaffAppointmentSyncSettings['StaffGoogleCalendarSecret']) {
1296 $StaffGoogleEmail = $StaffAppointmentSyncSettings['StaffGoogleEmail'];
1297 $StaffGoogleCalendarClientId = $StaffAppointmentSyncSettings['StaffGoogleCalendarClientId'];
1298 $StaffGoogleCalendarSecret = $StaffAppointmentSyncSettings['StaffGoogleCalendarSecret'];
1299 $StaffGoogleCalendarRedirectUris = $StaffAppointmentSyncSettings['StaffGoogleCalendarRedirectUris'];
1300 require_once('menu-pages/google-staff-appointment-sync-class.php');
1301
1302 // add this staff appointment event on his google calendar
1303 $StaffGoogleAppointmentSync = new StaffGoogleAppointmentSync($StaffGoogleCalendarClientId, $StaffGoogleCalendarSecret, $StaffGoogleCalendarRedirectUris);
1304 $Tag = __("Appointment with: ", "appointzilla");
1305 $StaffOAuth = $StaffGoogleAppointmentSync->NormalStaffAppointmentSync($StaffId, $ClientName, $AppDate, $StartTime, $EndTime, $ClientNote, $Tag);
1306
1307 //insert staff appointment sync details
1308 global $wpdb;
1309 $StaffAppointmentSyncTable = $wpdb->prefix . "ap_staff_appointment_sync";
1310 $StaffOAuth = serialize($StaffOAuth);
1311 $wpdb->query("INSERT INTO `$StaffAppointmentSyncTable` ( `id` , `app_id` , `staff_sync_details` ) VALUES ( NULL , '$AppId', '$StaffOAuth' )");
1312 }//end of staff appointment sync
1313
1314 //unset payment post variables
1315 unset($_POST['address_status']); unset($_POST['payer_id']);
1316
1317 } // end of sync appointment is approved
1318 ?>
1319 <div id="loading-staff" style="display:none;">
1320 <?php _e('Loading Staff...', 'appointzilla'); ?><img src="<?php echo plugins_url('images/loading.gif', __FILE__); ?>" />
1321 </div>
1322 </td>
1323 </tr>
1324 </table>
1325 </div>
1326 </div>
1327 </div>
1328 <?php
1329 } //query if
1330 } //if action
1331} // saving appointment if
1332
1333 // Payment success
1334 if( isset($_POST['address_status']) && isset($_POST['payer_id']) ) {
1335 global $wpdb;
1336 $AppointmentTableName = $wpdb->prefix . "ap_appointments";
1337 $PaymentTableName = $wpdb->prefix . 'ap_payment_transaction';
1338 $ClientTableName = $wpdb->prefix . 'ap_clients';
1339 $CouponsCodesTable = $wpdb->prefix ."apcal_pre_coupons_codes";
1340 $PaymentDetails = serialize($_POST);
1341 $appId = $_POST['item_number'];
1342
1343 //get client id by appointment id
1344 $ClientEmail = $wpdb->get_row("SELECT `email` FROM `$AppointmentTableName` WHERE `id` = '$appId'");
1345 $FetchClientEmail = $wpdb->get_row("SELECT `id` FROM `$ClientTableName` WHERE `email` = '$ClientEmail->email'");
1346 $clientId = $FetchClientEmail->id;
1347
1348 $ammount = $_POST['mc_gross'];
1349 $date = $_POST['payment_date'];
1350 $status = $_POST['address_status'];
1351 $txn_id = $_POST['txn_id'];
1352 $gateway = 'paypal';
1353
1354 $wpdb->query("INSERT INTO `$PaymentTableName` (`id`, `app_id`, `client_id`, `ammount`, `date`, `status`, `txn_id`, `gateway`, `other_fields`) VALUES (NULL, '$appId', '$clientId', '$ammount', '$date', '$status', '$txn_id', '$gateway', '$PaymentDetails');");
1355 $AppointmentId = $_POST['item_number'];
1356 $AppointmentRow = $wpdb->get_row("SELECT * FROM `$AppointmentTableName` WHERE `id` = '$AppointmentId'");
1357 if($AppointmentRow) {
1358 $name = $AppointmentRow->name;
1359 $ServiceId = $AppointmentRow->service_id;
1360 $StaffId = $AppointmentRow->staff_id;
1361 $StartTime = $AppointmentRow->start_time;
1362 $EndTime = $AppointmentRow->end_time;
1363 $Client_name = $AppointmentRow->name;
1364 $Client_Email = $AppointmentRow->email;
1365 $Client_Phone = $AppointmentRow->phone;
1366 $Client_Note = $AppointmentRow->note;
1367 $AppDate = $AppointmentRow->date;
1368 $Status = 'approved';
1369 $AppointmentKey = $AppointmentRow->appointment_key;
1370
1371 //update appointment status n payment status
1372 $PaymentStatus = $_POST['payment_status'];
1373 $AppointmentRow = $wpdb->query("UPDATE `$AppointmentTableName` SET `status` = '$Status', `payment_status` = 'paid' WHERE `id` = '$AppointmentId' ");
1374
1375 $BlogName = get_bloginfo();
1376 if($AppointmentId && $clientId) {
1377 $AppId = $AppointmentId;
1378 $ServiceId = $ServiceId;
1379 $StaffId = $StaffId;
1380 $ClientId = $clientId;
1381 //include notification class
1382 require_once('menu-pages/notification-class.php');
1383 $Notification = new Notification();
1384 $Notification->notifyadmin('approved', $AppId, $ServiceId, $StaffId, $ClientId, $BlogName, $DateFormat, $TimeFormat);
1385 $Notification->notifyclient('approved', $AppId, $ServiceId, $StaffId, $ClientId, $BlogName, $DateFormat, $TimeFormat);
1386 if(get_option('staff_notification_status') == 'on') {
1387 $Notification->notifystaff('approved', $AppId, $ServiceId, $StaffId, $ClientId, $BlogName, $DateFormat, $TimeFormat);
1388 }
1389 }
1390
1391 //if status is approved then sync appointment
1392 if($Status == 'approved') {
1393
1394 /***
1395 * admin appointment sync
1396 */
1397 $CalData = get_option('google_caelndar_settings_details');
1398 if($CalData['google_calendar_client_id'] != '' && $CalData['google_calendar_secret_key'] != '') {
1399 $start_time = date("H:i", strtotime($StartTime));
1400 $end_time = date("H:i", strtotime($EndTime));
1401 $appointmentdate = date("Y-m-d", strtotime($AppDate));
1402 $note = strip_tags($Client_Note);
1403
1404 $ClientId = $CalData['google_calendar_client_id'];
1405 $ClientSecretId = $CalData['google_calendar_secret_key'];
1406 $RedirectUri = $CalData['google_calendar_redirect_uri'];
1407 require_once('menu-pages/google-appointment-sync-class.php');
1408
1409 //global $wpdb;
1410 $AppointmentSyncTableName = $wpdb->prefix . "ap_appointment_sync";
1411 // insert this appointment event on calendar
1412 $GoogleAppointmentSync = new GoogleAppointmentSync($ClientId, $ClientSecretId, $RedirectUri);
1413 $tag = "Appointment with: ";
1414 $OAuth = $GoogleAppointmentSync->NormalSync($name, $appointmentdate, $start_time, $end_time, $note, $tag);
1415 //insert appointment sync details
1416 $OAuth = serialize($OAuth);
1417 $wpdb->query("INSERT INTO `$AppointmentSyncTableName` ( `id` , `app_id` , `app_sync_details` ) VALUES ( NULL , '$AppointmentId', '$OAuth' );");
1418 } // end of google calendar setting
1419
1420 /***
1421 * staff appointment sync
1422 */
1423 $StaffAppointmentSyncSettings = unserialize(get_option("staff_google_calendar_sync_settings_".$StaffId));
1424 if($StaffAppointmentSyncSettings['StaffGoogleCalendarClientId'] != "" && $StaffAppointmentSyncSettings['StaffGoogleCalendarSecret']) {
1425 $StaffGoogleEmail = $StaffAppointmentSyncSettings['StaffGoogleEmail'];
1426 $StaffGoogleCalendarClientId = $StaffAppointmentSyncSettings['StaffGoogleCalendarClientId'];
1427 $StaffGoogleCalendarSecret = $StaffAppointmentSyncSettings['StaffGoogleCalendarSecret'];
1428 $StaffGoogleCalendarRedirectUris = $StaffAppointmentSyncSettings['StaffGoogleCalendarRedirectUris'];
1429 require_once('menu-pages/google-staff-appointment-sync-class.php');
1430
1431 // add this staff appointment event on his google calendar
1432 $StaffGoogleAppointmentSync = new StaffGoogleAppointmentSync($StaffGoogleCalendarClientId, $StaffGoogleCalendarSecret, $StaffGoogleCalendarRedirectUris);
1433 $Tag = __("Appointment with: ", "appointzilla");
1434 $StaffOAuth = $StaffGoogleAppointmentSync->NormalStaffAppointmentSync($StaffId, $ClientName, $AppDate, $StartTime, $EndTime, $ClientNote, $Tag);
1435
1436 //insert staff appointment sync details
1437 global $wpdb;
1438 $StaffAppointmentSyncTable = $wpdb->prefix . "ap_staff_appointment_sync";
1439 $StaffOAuth = serialize($StaffOAuth);
1440 $wpdb->query("INSERT INTO `$StaffAppointmentSyncTable` ( `id` , `app_id` , `staff_sync_details` ) VALUES ( NULL , '$AppId', '$StaffOAuth' )");
1441 }//end of staff appointment sync
1442
1443 //unset payment post variables
1444 unset($_POST['address_status']); unset($_POST['payer_id']);
1445 } // end of appointment is approved ?>
1446 <div id="AppForthModal" style="z-index:10000;">
1447 <div class="apcal_modal-info">
1448 <div class="apcal_alert apcal_alert-info">
1449 <h4 ><?php _e('Payment Successfully Processed', 'appointzilla'); ?></h4>
1450 </div>
1451 <div>
1452 <div class="apcal_alert apcal_alert-success">
1453 <strong><?php _e('Payment received and your appointment has been confirmed.', 'appointzilla'); ?></strong><br />
1454 <strong><?php _e('Thank you for scheduling appointment with us.', 'appointzilla'); ?></strong>
1455 <?php
1456 //if payment confirmed(done) then increment coupon used count value
1457 if($status == "confirmed") {
1458 $PaymentDetails = unserialize($PaymentDetails);
1459 if(isset($PaymentDetails['custom'])) {
1460 $CouponCode = $PaymentDetails['custom'];
1461 //check coupon exist or not
1462 $CouponsData = $wpdb->get_row("SELECT * FROM `$CouponsCodesTable` WHERE `coupon_code` LIKE '$CouponCode'");
1463 if(count($CouponsData)) {
1464 //increment total used count
1465 $CouponId = $CouponsData->id;
1466 $UsedCount = $CouponsData->used_count + 1;
1467 $wpdb->query("UPDATE `$CouponsCodesTable` SET `used_count` = '$UsedCount' WHERE `id` = '$CouponId' ");
1468 }
1469 }
1470 }
1471 ?>
1472 </div>
1473 <button type='button' onclick='CloseModelform()' name='close' id='close' value='Done' class='apcal_btn'><i class="icon-ok"></i> <?php _e('Done', 'appointzilla'); ?></button>
1474 </div>
1475 </div>
1476 </div><?php
1477 } // end of AppointmentRow
1478 } // end of Payment success
1479
1480 // Payment process faild
1481 if( isset($_GET['failed']) && isset($_GET['appointId'])) { ?>
1482 <div id="AppForthModal" style="z-index:10000;">
1483 <div style="padding-bottom:20px;">
1484 <input type="hidden" name="appid" id="appid" value="<?php echo $_GET['appointId']; ?>" />
1485 <div class="apcal_alert apcal_alert-info">
1486 <h4><?php _e('Payment Failed', 'appointzilla'); ?></h4>
1487 </div>
1488 <div style=" margin-left:20px; padding-right:20px;">
1489 <div class="apcal_alert apcal_alert-error">
1490 <?php _e('Sorry! Appointment Booking was not successful.', 'appointzilla'); ?>
1491 </div>
1492 <button type='button' onclick='failedappointment()' name='close' id='close' value='close' class='apcal_btn'><i class="icon-repeat"></i> <?php _e('Try Again', 'appointzilla'); ?> </button>
1493 </div>
1494 </div>
1495 </div><?php
1496 }
1497
1498 // cancel appointment
1499 if(isset($_POST['appid']) && isset($_POST['appstatus']) ) {
1500 $AppId = $_POST['appid'];
1501 global $wpdb;
1502 $AppointmentTable = $wpdb->prefix."ap_appointments";
1503 $wpdb->query("UPDATE `$AppointmentTable` SET `status` = 'cancelled' WHERE `id` = '$AppId' ;");
1504 }
1505
1506 //applying coupon code
1507 if(isset($_POST['Action']) == "apply-coupon") {
1508 if(isset($_POST['CouponCode'])) {
1509 $CouponCode = strtolower($_POST['CouponCode']);
1510 } else {
1511 $CouponCode = "";
1512 }
1513 if($CouponCode){
1514 global $wpdb;
1515 $Discount = 0;
1516 $CouponsCodesTable = $wpdb->prefix . "apcal_pre_coupons_codes";
1517 //Search Coupon
1518 $CouponDetails = $wpdb->get_row("SELECT * FROM `$CouponsCodesTable` WHERE `coupon_code` LIKE '$CouponCode'");
1519 if(count($CouponDetails)) {
1520 //check coupon expire
1521 $DateTodayTs = strtotime(date("Y-m-d"));
1522 $ExpireDateTs = strtotime(date("Y-m-d", strtotime($CouponDetails->expire)));
1523 $TotalUses = $CouponDetails->total_uses;
1524 $UsedCount = $CouponDetails->used_count;
1525 $Discount = $CouponDetails->discount;
1526 if($DateTodayTs > $ExpireDateTs) {
1527 //coupon expired
1528 ?><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
1529
1530 } else if($UsedCount >= $TotalUses) {
1531 //ckeck used count
1532
1533 ?><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
1534
1535 } else {
1536 //coupon valid and appied
1537 ?><div id="coupon-result">
1538 <div id="coupon-code-div" style="display: none;"><?php echo $CouponCode; ?></div>
1539 <div id="discount-rate-div" style="display: none;"><?php echo $Discount; ?></div>
1540 <?php echo strtoupper("<strong>$CouponCode</strong> "); _e("coupon code applied.", "appointzilla"); ?> <a id="try-another" onclick="return TryAgain();"><?php _e("Change", "appointzilla"); ?></a>
1541 </div><?php
1542 }
1543 } else {
1544 ?>
1545 <div id="coupon-result">
1546 <div id="discount-rate-div" style="display: none;"><?php echo $Discount; ?></div>
1547 <?php echo strtoupper("<strong>$CouponCode</strong> "); _e("coupon code is invalid.", "appointzilla"); ?>
1548 <a id="try-another" onclick="return TryAgain();"><?php _e("Try Another", "appointzilla"); ?></a>
1549 </div>
1550 <?php
1551 }
1552 }
1553 }
1554
1555 //check existing user
1556 if(isset($_POST['Action'])) {
1557 $Action = $_POST['Action'];
1558 if($Action == "CheckExistingUser") {
1559 ?><div id="check-email-result"><?php
1560 $ClientEmail = $_POST['ClientEmail'];
1561 $ClientId = email_exists( $ClientEmail );
1562 if( $ClientId = email_exists( $ClientEmail )) {
1563 //fetch user details
1564 $ClientDetails = get_userdata( $ClientId );
1565 //print_r($ClientDetails);
1566 $FirstName = "";
1567 $LastName = "";
1568 $Phone = "";
1569 $ClientNote = "";
1570 $UserMetaData = get_user_meta( $ClientId );
1571 if(count($UserMetaData)) {
1572 if(isset($UserMetaData['first_name'][0])) {
1573 $FirstName = ucwords($UserMetaData['first_name'][0]);
1574 }
1575 if(isset($UserMetaData['last_name'][0])) {
1576 $LastName = ucwords($UserMetaData['last_name'][0]);
1577 }
1578 if(isset($UserMetaData['client_phone'][0])) {
1579 $Phone = $UserMetaData['client_phone'][0];
1580 }
1581 if(isset($UserMetaData['client_note'][0])) {
1582 $ClientNote = ucfirst($UserMetaData['client_note'][0]);
1583 }
1584 }
1585 ?>
1586 <input type="hidden" id="client-id" name="client-id" value="<?php echo $ClientId; ?>">
1587 <table width="100%" class="table">
1588 <tr>
1589 <th scope="row"><?php _e('Email', 'appointzilla'); ?></th>
1590 <td><strong>:</strong></td>
1591 <td><input name="ex-client-email" type="text" id="ex-client-email" style="height:30px;" value="<?php echo $ClientEmail; ?>" readonly="" /></td>
1592 </tr>
1593 <tr>
1594 <th scope="row"><?php _e('First Name', 'appointzilla'); ?></th>
1595 <td><strong>:</strong></td>
1596 <td><input name="ex-client-first-name" type="text" id="ex-client-first-name" style="height:30px;" value="<?php echo $FirstName; ?>"/></td>
1597 </tr>
1598 <tr>
1599 <th scope="row"><?php _e('Last Name', 'appointzilla'); ?></th>
1600 <td><strong>:</strong></td>
1601 <td><input name="ex-client-last-name" type="text" id="ex-client-last-name" style="height:30px;" value="<?php echo $LastName; ?>" /></td>
1602 </tr>
1603 <tr>
1604 <th scope="row"><?php _e('Phone', 'appointzilla'); ?></th>
1605 <td><strong>:</strong></td>
1606 <td><input name="ex-client-phone" type="text" id="ex-client-phone" style="height:30px;" value="<?php echo $Phone; ?>" maxlength="14"/></td>
1607 </tr>
1608 <tr>
1609 <th scope="row"><?php _e('Special Instruction', 'appointzilla'); ?></th>
1610 <td><strong>:</strong></td>
1611 <td><textarea name="ex-client-si" id="ex-client-si"><?php echo $ClientNote; ?></textarea></td>
1612 </tr>
1613 <tr>
1614 <td> </td>
1615 <td> </td>
1616 <td>
1617 <div id="ex-user-form-btn-div">
1618 <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>
1619 <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>
1620 </div>
1621 <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>
1622 <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>
1623 </td>
1624 </tr>
1625 </table>
1626 <?php
1627 } else { ?>
1628 <table width="100%" class="table">
1629 <tr>
1630 <td colspan="3">
1631 <?php _e("Sorry! No record found.","appointzilla"); ?>
1632 <button type="button" onclick="return TryAgainBooking();" class="apcal_btn apcal_btn-danger"><i class="fa fa-mail-reply"></i> Try Again</button>
1633 </td>
1634 </tr>
1635 </table>
1636 <?php
1637 }
1638 ?></div><?php
1639 }
1640 }
1641 /*$output_string = ob_get_contents();
1642 ob_end_clean();
1643 return $output_string;*/
1644}//end of short code function
1645?>