Guest User

Untitled

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