Guest User

Untitled

a guest
Oct 4th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 67.44 KB | None | 0 0
  1. <?php
  2. // Exit if accessed directly.
  3. if ( ! defined( 'ABSPATH' ) ) exit;
  4.  
  5. //short code file with appointment booking button and big calendar(full-calendar)
  6.  
  7. add_shortcode( 'APCAL', 'appointzilla_appointment_calendar_shortcode' );
  8.  
  9. function appointzilla_appointment_calendar_shortcode() {
  10.  
  11. if( get_locale() ) {
  12.  
  13. $language = get_locale();
  14.  
  15. if($language) { define('L_LANG',$language); }
  16.  
  17. }
  18.  
  19. //save appointment and email admin & client/customer
  20. if( isset($_POST['Client_Name']) && isset($_POST['Client_Email']) ) {
  21.  
  22. global $wpdb;
  23.  
  24. if( !wp_verify_nonce($_POST['wp_nonce'],'appointment_register_nonce_check') ){
  25.  
  26. print 'Sorry, your nonce did not verify.'; exit;
  27.  
  28. }
  29.  
  30. $ClientName = sanitize_text_field( $_POST['Client_Name'] );
  31.  
  32. $ClientEmail = sanitize_email( $_POST['Client_Email'] );
  33.  
  34. $ClientPhone = intval( $_POST['Client_Phone'] );
  35.  
  36. $ClientNote = sanitize_text_field( $_POST['Client_Note'] );
  37.  
  38. $AppointmentDate = date("Y-m-d", strtotime( sanitize_text_field( $_POST['AppDate'] ) ) );
  39.  
  40. $ServiceId = intval( $_POST['ServiceId'] );
  41.  
  42. $ServiceDuration = sanitize_text_field( $_POST['Service_Duration'] );
  43.  
  44. $StartTime = sanitize_text_field( $_POST['StartTime'] );
  45.  
  46.  
  47.  
  48. //calculate end time according to service duration
  49. $EndTime = date( 'h:i A' , strtotime( "+$ServiceDuration minutes" , strtotime( $StartTime ) ) );
  50.  
  51. $AppointmentKey = md5( date( "F j, Y, g:i a" ) );
  52.  
  53. $Status = __( "pending" , "appointzilla" );
  54.  
  55. $AppointmentBy = __( "user" , "appointzilla" );
  56.  
  57. $AppointmentsTable = $wpdb->prefix . "ap_appointments";
  58.  
  59. $query = $wpdb->query(
  60.  
  61. $wpdb->prepare(
  62.  
  63. "
  64. INSERT INTO $AppointmentsTable
  65.  
  66. ( id , name , email , service_id , phone , start_time , end_time , date , note , appointment_key , status , appointment_by )
  67.  
  68. VALUES ( %d , %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
  69.  
  70. ",
  71. array(
  72. null,
  73. $ClientName,
  74. $ClientEmail,
  75. $ServiceId,
  76. $ClientPhone,
  77. $StartTime,
  78. $EndTime,
  79. $AppointmentDate,
  80. $ClientNote,
  81. $AppointmentKey,
  82. $Status,
  83. $AppointmentBy
  84. )
  85. )
  86.  
  87.  
  88. );
  89.  
  90. if( $query ) {
  91.  
  92.  
  93. $BlogName = get_bloginfo();
  94.  
  95. //get service details
  96. $ServiceTable = $wpdb->prefix . "ap_services";
  97.  
  98. $ServiceData = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $ServiceTable WHERE id = %d" , $ServiceId ) , OBJECT);
  99.  
  100. $ServiceName = $ServiceData->name;
  101.  
  102.  
  103. //check notification is enabled
  104. $NotificationStatus = get_option('emailstatus');
  105. if($NotificationStatus == "on") {
  106. $Attachments = "";
  107. $AppointmentTime = $StartTime." - ".$EndTime;
  108. $AdminSubject = get_option('new_appointment_admin_subject');
  109. $AdminSubject = str_replace("[blog-name]", ucwords($BlogName), $AdminSubject);
  110. $AdminSubject = str_replace("[client-name]", ucwords($ClientName), $AdminSubject);
  111. $AdminSubject = str_replace("[client-email]", ucwords($ClientEmail), $AdminSubject);
  112. $AdminSubject = str_replace("[client-phone]", ucwords($ClientPhone), $AdminSubject);
  113. $AdminSubject = str_replace("[client-si]", ucwords($ClientNote), $AdminSubject);
  114. $AdminSubject = str_replace("[service-name]", ucwords($ServiceName), $AdminSubject);
  115. $AdminSubject = str_replace("[app-date]", $AppointmentDate, $AdminSubject);
  116. $AdminSubject = str_replace("[app-status]", ucwords($Status), $AdminSubject);
  117. $AdminSubject = str_replace("[app-time]", $AppointmentTime, $AdminSubject);
  118. $AdminSubject = str_replace("[app-key]", $AppointmentKey, $AdminSubject);
  119. $AdminSubject = str_replace("[app-note]", ucfirst($ClientNote), $AdminSubject);
  120.  
  121. $AdminBody = get_option('new_appointment_admin_body');
  122. $AdminBody = str_replace("[blog-name]", ucwords($BlogName), $AdminBody);
  123. $AdminBody = str_replace("[client-name]", ucwords($ClientName), $AdminBody);
  124. $AdminBody = str_replace("[client-email]", ucwords($ClientEmail), $AdminBody);
  125. $AdminBody = str_replace("[client-phone]", ucwords($ClientPhone), $AdminBody);
  126. $AdminBody = str_replace("[client-si]", ucwords($ClientNote), $AdminBody);
  127. $AdminBody = str_replace("[service-name]", ucwords($ServiceName), $AdminBody);
  128. $AdminBody = str_replace("[app-date]", $AppointmentDate, $AdminBody);
  129. $AdminBody = str_replace("[app-status]", ucwords($Status), $AdminBody);
  130. $AdminBody = str_replace("[app-time]", $AppointmentTime, $AdminBody);
  131. $AdminBody = str_replace("[app-key]", $AppointmentKey, $AdminBody);
  132. $AdminBody = str_replace("[app-note]", ucfirst($ClientNote), $AdminBody);
  133.  
  134.  
  135. $ClientSubject = get_option('new_appointment_client_subject');
  136. $ClientSubject = str_replace("[blog-name]", ucwords($BlogName), $ClientSubject);
  137. $ClientSubject = str_replace("[client-name]", ucwords($ClientName), $ClientSubject);
  138. $ClientSubject = str_replace("[client-email]", ucwords($ClientEmail), $ClientSubject);
  139. $ClientSubject = str_replace("[client-phone]", ucwords($ClientPhone), $ClientSubject);
  140. $ClientSubject = str_replace("[client-si]", ucwords($ClientNote), $ClientSubject);
  141. $ClientSubject = str_replace("[service-name]", ucwords($ServiceName), $ClientSubject);
  142. $ClientSubject = str_replace("[app-date]", $AppointmentDate, $ClientSubject);
  143. $ClientSubject = str_replace("[app-status]", ucwords($Status), $ClientSubject);
  144. $ClientSubject = str_replace("[app-time]", $AppointmentTime, $ClientSubject);
  145. $ClientSubject = str_replace("[app-key]", $AppointmentKey, $ClientSubject);
  146. $ClientSubject = str_replace("[app-note]", ucfirst($ClientNote), $ClientSubject);
  147.  
  148. $ClientBody = get_option('new_appointment_client_body');
  149. $ClientBody = str_replace("[blog-name]", ucwords($BlogName), $ClientBody);
  150. $ClientBody = str_replace("[client-name]", ucwords($ClientName), $ClientBody);
  151. $ClientBody = str_replace("[client-email]", ucwords($ClientEmail), $ClientBody);
  152. $ClientBody = str_replace("[client-phone]", ucwords($ClientPhone), $ClientBody);
  153. $ClientBody = str_replace("[client-si]", ucwords($ClientNote), $ClientBody);
  154. $ClientBody = str_replace("[service-name]", ucwords($ServiceName), $ClientBody);
  155. $ClientBody = str_replace("[app-date]", $AppointmentDate, $ClientBody);
  156. $ClientBody = str_replace("[app-status]", ucwords($Status), $ClientBody);
  157. $ClientBody = str_replace("[app-time]", $AppointmentTime, $ClientBody);
  158. $ClientBody = str_replace("[app-key]", $AppointmentKey, $ClientBody);
  159. $ClientBody = str_replace("[app-note]", ucfirst($ClientNote), $ClientBody);
  160.  
  161. //check email type
  162. $EmailType = get_option('emailtype');
  163. $EmailDetails = unserialize(get_option( 'emaildetails'));
  164. //wp-email
  165. if($EmailType == "wpmail") {
  166. $AdminEmail = $EmailDetails['wpemail'];
  167. $Headers[] = "From: Admin <".$AdminEmail.">";
  168. //send wp email to client
  169. wp_mail( $ClientEmail, $ClientSubject, $ClientBody, $Headers, $Attachments);
  170. //send wp email to admin
  171. wp_mail( $AdminEmail, $AdminSubject, $AdminBody, $Headers, $Attachments);
  172. }
  173.  
  174. //php-email
  175. if($EmailType == "phpmail") {
  176. $AdminEmail = $EmailDetails['phpemail'];
  177. $Headers[] = "From: Admin <".$AdminEmail.">";
  178. ///send php email to client
  179. mail($ClientEmail, $ClientSubject, $ClientBody, $Headers);
  180. //send php email to admin
  181. mail( $AdminEmail, $AdminSubject, $AdminBody, $Headers);
  182. }
  183.  
  184. //wp-email
  185. if($EmailType == "smtp") {
  186. require_once('menu-pages/notification/Email.php');
  187. $AdminEmail = $EmailDetails['smtpemail'];
  188. $HostName = $EmailDetails['hostname'];
  189. $PortNo = $EmailDetails['portno'];
  190. $SMTPEmail = $EmailDetails['smtpemail'];
  191. $Password = $EmailDetails['password'];
  192. $Headers[] = "From: Admin <".$AdminEmail.">";
  193. $Email = new SendEmail();
  194. //send smtp email to client
  195. $Email->NotifyClient($HostName, $PortNo, $SMTPEmail, $Password, $AdminEmail, $ClientEmail, $ClientSubject, $ClientBody, $BlogName);
  196. //send smtp email to admin
  197. $Email->NotifyAdmin($HostName, $PortNo, $SMTPEmail, $Password, $AdminEmail, $AdminSubject, $AdminBody, $BlogName);
  198. }
  199. } //end of notification enable check if
  200. } // end og SQL if
  201. } //end of isset ?>
  202.  
  203. <script type='text/javascript'>
  204. jQuery(document).ready(function() {
  205. jQuery('#calendar').fullCalendar({
  206. header: {
  207. left: 'prev,next today',
  208. center: 'title',
  209. right: 'month,agendaWeek,agendaDay'
  210. },
  211. titleFormat: {
  212. month: ' MMMM yyyy', // September 2009
  213. week: "MMM d[ yyyy]{ '&#8212;'[ MMM] d yyyy}", // Sep 7 - 13 2009
  214. day: 'dddd, MMM d, yyyy' // Tuesday, Sep 8, 2009
  215. },
  216. editable: false,
  217. weekends: true,
  218. timeFormat: 'h:mm{-h:mmtt }',
  219. axisFormat: 'h:mm{-h:mmtt }',
  220. <?php $AllCalendarSettings = unserialize(get_option('apcal_calendar_settings')); ?>
  221. firstDay: <?php if($AllCalendarSettings['calendar_start_day'] != '') echo $AllCalendarSettings['calendar_start_day']; else echo "1"; ?>,
  222. slotMinutes: <?php if($AllCalendarSettings['calendar_slot_time'] != '') echo $AllCalendarSettings['calendar_slot_time']; else echo "15"; ?>,
  223. defaultView: '<?php if($AllCalendarSettings['calendar_view'] != '') echo $AllCalendarSettings['calendar_view']; else echo "month"; ?>',
  224. minTime: <?php if($AllCalendarSettings['day_start_time'] != '') echo date("G", strtotime($AllCalendarSettings['day_start_time'])); else echo "8"; ?>,
  225.  
  226. maxTime: <?php if($AllCalendarSettings['day_end_time'] != '') echo date("G", strtotime($AllCalendarSettings['day_end_time'])); else echo "20"; ?>,
  227. 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"); ?>" ],
  228. 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"); ?>"],
  229. 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"); ?>"],
  230. dayNamesShort: ["<?php _e("Sun", "appointzilla"); ?>","<?php _e("Mon", "appointzilla"); ?>", "<?php _e("Tue", "appointzilla"); ?>", "<?php _e("Wed", "appointzilla"); ?>", "<?php _e("Thus", "appointzilla"); ?>", "<?php _e("Fri", "appointzilla"); ?>", "<?php _e("Sat", "appointzilla"); ?>"],
  231. buttonText: {
  232. today: "<?php _e("Today", "appointzilla"); ?>",
  233. day: "<?php _e("Day", "appointzilla"); ?>",
  234. week:"<?php _e("Week", "appointzilla"); ?>",
  235. month:"<?php _e("Month", "appointzilla"); ?>"
  236. },
  237. selectable: false,
  238. selectHelper: false,
  239. select: function(start, end, allDay) {
  240. jQuery('#AppFirstModal').show();
  241. },
  242.  
  243. events: [
  244. <?php
  245. //Loading Appointments On Calendar Start
  246. global $wpdb;
  247. $AppointmentTableName = $wpdb->prefix . "ap_appointments";
  248. $AllAppointments = $wpdb->get_results( $wpdb->prepare("select name, start_time, end_time, date FROM $AppointmentTableName where id > %d",null), OBJECT);
  249.  
  250. if($AllAppointments) {
  251. foreach($AllAppointments as $single) {
  252. $title = $single->name;
  253. $start = date("H, i", strtotime($single->start_time));
  254. $end= date("H, i", strtotime($single->end_time));
  255.  
  256. // subtract 1 from month digit coz calendar work on month 0-11
  257. $y = date ( 'Y' , strtotime( $single->date ) );
  258. $m = date ( 'n' , strtotime( $single->date ) ) - 1;
  259. $d = date ( 'd' , strtotime( $single->date ) );
  260. $date = "$y-$m-$d";
  261.  
  262. $date = str_replace("-",", ", $date); ?>
  263. {
  264. title: "<?php _e("Name: ".$title, "appointzilla"); ?>",
  265. start: new Date(<?php echo "$date, $start"; ?>),
  266. end: new Date(<?php echo "$date, $end"; ?>),
  267. allDay: false,
  268. backgroundColor : "#1FCB4A",
  269. textColor: "black",
  270. }, <?php
  271. }
  272. }
  273.  
  274.  
  275. // Loading Events On Calendar Start
  276. global $wpdb;
  277. $EventTableName = $wpdb->prefix . "ap_events";
  278. $AllEvents = $wpdb->get_results( $wpdb->prepare("select `name`, `start_time`, `end_time`, `start_date`, `end_date`, `repeat` FROM `$EventTableName` where `repeat` = %s",'N') , OBJECT );
  279.  
  280. if($AllEvents) {
  281. foreach($AllEvents as $Event) {
  282. // convert time foramt H:i:s
  283. $starttime = date("H:i", strtotime($Event->start_time));
  284. $endtime = date("H:i", strtotime($Event->end_time));
  285. // change time format according to calendar
  286. $starttime = str_replace(":",", ", $starttime);
  287. $endtime = str_replace(":", ", ", $endtime);
  288.  
  289. $startdate = $Event->start_date;
  290. // subtract 1 from $startdate month digit coz calendar work on month 0-11
  291. $y = date ( 'Y' , strtotime( $startdate ) );
  292. $m = date ( 'n' , strtotime( $startdate ) ) - 1;
  293. $d = date ( 'd' , strtotime( $startdate ) );
  294. $startdate = "$y-$m-$d";
  295. $startdate = str_replace("-",", ", $startdate); //changing date format
  296.  
  297. $enddate = $Event->end_date;
  298. // subtract 1 from $startdate month digit coz calendar work on month 0-11
  299. $y2 = date ( 'Y' , strtotime( $enddate ) );
  300. $m2 = date ( 'n' , strtotime( $enddate ) ) - 1;
  301. $d2 = date ( 'd' , strtotime( $enddate ) );
  302. $enddate = "$y2-$m2-$d2";
  303. $enddate = str_replace("-",", ", $enddate); //changing date format ?>
  304. {
  305. title: "<?php echo $Event->name; ?>",
  306. start: new Date(<?php echo "$startdate, $starttime"; ?>),
  307. end: new Date(<?php echo "$enddate, $endtime"; ?>),
  308. allDay: false,
  309. backgroundColor : "#FF7575",
  310. textColor: "black"
  311. }, <?php
  312. }
  313. }
  314.  
  315. //Loading Recurring Events On Calendar Start
  316. $AllREvents = $wpdb->get_results($wpdb->prepare("select `id`, `name`, `start_time`, `end_time`, `start_date`, `end_date`, `repeat` FROM `$EventTableName` where `repeat` != %s",'N'), OBJECT);
  317.  
  318. //dont show event on filtering
  319. if(isset($AllREvents)) {
  320. foreach($AllREvents as $Event) {
  321. //convert time foramt H:i:s
  322. $starttime = date("H:i", strtotime($Event->start_time));
  323. $endtime = date("H:i", strtotime($Event->end_time));
  324. //change time format according to calendar
  325. $starttime = str_replace(":",", ", $starttime);
  326. $endtime = str_replace(":", ", ", $endtime);
  327. $startdate = $Event->start_date;
  328. $enddate = $Event->end_date;
  329.  
  330. if($Event->repeat != 'M') {
  331. //if appointment type then calulate RTC(recutting date calulation)
  332. if($Event->repeat == 'PD')
  333. $RDC = 1;
  334. if($Event->repeat == 'D')
  335. $RDC = 1;
  336. if($Event->repeat == 'W')
  337. $RDC = 7;
  338. if($Event->repeat == 'BW')
  339. $RDC = 14;
  340.  
  341. $Alldates = array();
  342. $st_dateTS = strtotime($startdate);
  343. $ed_dateTS = strtotime($enddate);
  344. for ($currentDateTS = $st_dateTS; $currentDateTS <= $ed_dateTS; $currentDateTS += (60 * 60 * 24 * $RDC)) {
  345. $currentDateStr = date("Y-m-d",$currentDateTS);
  346. $AlldatesArr[] = $currentDateStr;
  347.  
  348. // subtract 1 from $startdate month digit coz calendar work on month 0-11
  349. $y = date ( 'Y' , strtotime( $currentDateStr ) );
  350. $m = date ( 'n' , strtotime( $currentDateStr ) ) - 1;
  351. $d = date ( 'd' , strtotime( $currentDateStr ) );
  352. $startdate = "$y-$m-$d";
  353. $startdate = str_replace("-",", ", $startdate); //changing date format
  354.  
  355. // subtract 1 from $startdate month digit coz calendar work on month 0-11
  356. $y2 = date ( 'Y' , strtotime( $currentDateStr ) );
  357. $m2 = date ( 'n' , strtotime( $currentDateStr ) ) - 1;
  358. $d2 = date ( 'd' , strtotime( $currentDateStr ) );
  359. $enddate = "$y2-$m2-$d2";
  360. //changing date format
  361. $enddate = str_replace("-",", ", $enddate); ?>
  362. {
  363. title: "<?php echo ucwords($Event->name); ?>",
  364. start: new Date(<?php echo "$startdate, $starttime"; ?>),
  365. end: new Date(<?php echo "$enddate, $endtime"; ?>),
  366. allDay: false,
  367. backgroundColor : "#FF7575",
  368. textColor: "black",
  369. }, <?php
  370. }// end of for
  371. } else {
  372. $i = 0;
  373. do {
  374. $NextDate = date("Y-m-d", strtotime("+$i months", strtotime($startdate)));
  375. // subtract 1 from $startdate month digit coz calendar work on month 0-11
  376. $y = date ( 'Y' , strtotime( $NextDate ) );
  377. $m = date ( 'n' , strtotime( $NextDate ) ) - 1;
  378. $d = date ( 'd' , strtotime( $NextDate ) );
  379. $startdate2 = "$y-$m-$d";
  380. $startdate2 = str_replace("-",", ", $startdate2); //changing date format
  381. $enddate2 = str_replace("-",", ", $startdate2); ?>
  382. {
  383. title: "<?php echo ucwords($Event->name); ?>",
  384. start: new Date(<?php echo "$startdate2, $starttime"; ?>),
  385. end: new Date(<?php echo "$enddate2, $endtime"; ?>),
  386. allDay: false,
  387. backgroundColor : "#FF7575",
  388. textColor: "black",
  389. }, <?php
  390. $i = $i+1;
  391. } while(strtotime($enddate) != strtotime($NextDate));
  392. }//end of else
  393. }//end of foreach
  394. }// end of all-events ?>
  395. {
  396. }
  397. ]
  398. });
  399.  
  400. //jQuery UI date picker on modal for
  401. //document.addnewappointment.appdate.value = jQuery.datepicker.formatDate('<?php //echo 'dd-mm-yy'; ?>', new Date());
  402. /*jQuery(function(){
  403. jQuery("#datepicker").datepicker({
  404. inline: true,
  405. minDate: 0,
  406. altField: '#alternate',
  407. firstDay: <?php //if($AllCalendarSettings['calendar_start_day'] != '') echo $AllCalendarSettings['calendar_start_day']; else echo "0"; ?>,
  408. //beforeShowDay: unavailable,
  409. onSelect: function(dateText, inst) {
  410. var dateAsString = dateText;
  411. var seleteddate = jQuery.datepicker.formatDate('<?php //echo 'dd-mm-yy'; ?>', new Date(dateAsString));
  412. var seleteddate2 = jQuery.datepicker.formatDate('dd-mm-yy', new Date(dateAsString));
  413. document.addnewappointment.appdate.value = seleteddate;
  414. },
  415. });
  416. //jQuery( "#datepicker" ).datepicker( jQuery.datepicker.regional[ "af" ] );
  417. });*/
  418.  
  419. //Modal Form Works - show frist modal
  420. jQuery('#addappointment').click(function(){
  421. var todaydate = jQuery.fullCalendar.formatDate(new Date(),'dd-MM-yyyy');
  422. jQuery('#appdate').val(todaydate);
  423. jQuery('#AppFirstModal').show();
  424. });
  425.  
  426. //hide modal
  427. jQuery('#close').click(function(){
  428. jQuery('#AppFirstModal').hide();
  429. });
  430.  
  431. //AppFirstModal Validation
  432. jQuery('#next1').click(function(){
  433. jQuery(".apcal-error").hide();
  434. if(jQuery('#service').val() == 0) {
  435. jQuery("#service").after("<span class='apcal-error'><br><strong><?php _e("Select any service.", "appointzilla"); ?></strong></span>");
  436. return false;
  437. }
  438. var ServiceId = jQuery('#service').val();
  439. var AppDate = jQuery('#appdate').val();
  440. var SecondData = "ServiceId=" + ServiceId + "&AppDate=" + AppDate;
  441. jQuery('#loading1').show(); // loading button onclick next1 at first modal
  442. jQuery('#next1').hide(); // hide next button
  443. jQuery.ajax({
  444. dataType : 'html',
  445. type: 'GET',
  446. url : location.href,
  447. cache: false,
  448. data : SecondData,
  449. complete : function() { },
  450. success: function(data) {
  451. data = jQuery(data).find('div#AppSecondModal');
  452. jQuery('#loading1').hide();
  453. jQuery('#AppFirstModal').hide();
  454. jQuery('#AppSecondModalDiv').show();
  455. jQuery('#AppSecondModalDiv').html(data);
  456. }
  457. });
  458. });
  459.  
  460. //Second Modal form validation
  461. jQuery('#booknowapp').click(function(){
  462. jQuery(".apcal-error").hide();
  463. var start_time = jQuery('input[name=start_time]:radio:checked').val();
  464. if(!start_time) {
  465. jQuery("#selecttimediv").after("<span class='apcal-error'><br><strong><?php _e("Select any time.", "appointzilla"); ?></strong></span>");
  466. return false;
  467. }
  468.  
  469. if( !jQuery('#clientname').val() ) {
  470. jQuery("#clientname").after("<span class='apcal-error'><br><strong><?php _e("Name required.", "appointzilla"); ?></strong></span>");
  471. return false;
  472. } else if(!isNaN( jQuery('#clientname').val() )) {
  473. jQuery("#clientname").after("<span class='apcal-error'><p><strong><?php _e("Invalid name.", "appointzilla"); ?></strong></p></span>");
  474. return false;
  475. }
  476.  
  477. var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  478. if( !jQuery('#clientemail').val() ) {
  479. jQuery("#clientemail").after("<span class='apcal-error'><br><strong><?php _e("Email required.", "appointzilla"); ?></strong></span>");
  480. return false;
  481. } else {
  482. if(regex.test(jQuery('#clientemail').val()) == false ) {
  483. jQuery("#clientemail").after("<span class='apcal-error'><p><strong><?php _e("Invalid Email.", "appointzilla"); ?></strong></p></span>");
  484. return false;
  485. }
  486. }
  487.  
  488. if( !jQuery('#clientphone').val() ) {
  489. jQuery("#clientphone").after("<span class='apcal-error'><br><strong><?php _e("Phone required.", "appointzilla"); ?></strong></span>");
  490. return false;
  491. } else if(isNaN( jQuery('#clientphone').val() )) {
  492. jQuery("#clientphone").after("<span class='apcal-error'><p><strong><?php _e("Invalid phone number.", "appointzilla"); ?></strong></p></span>");
  493. return false;
  494. }
  495. });
  496.  
  497. //back button show first modal
  498. jQuery('#back').click(function(){
  499. jQuery('#AppFirstModal').show();
  500. jQuery('#AppSecondModal').hide();
  501. });
  502. });
  503.  
  504.  
  505. //Modal Form Works
  506. function Backbutton() {
  507. jQuery('#AppFirstModal').show();
  508. jQuery('#AppSecondModalDiv').hide();
  509. jQuery('#next1').show();
  510. }
  511.  
  512. //validation on second modal form submissions == appointment_register_nonce_field
  513. function CheckValidation() {
  514. jQuery(".apcal-error").hide();
  515. var start_time = jQuery('input[name=start_time]:radio:checked').val();
  516. if(!start_time) {
  517. jQuery("#selecttimediv").after("<p style='width:350px; padding:2px;' class='apcal-error'><strong><?php _e("Select any time.", "appointzilla"); ?></strong></p>");
  518. return false;
  519. }
  520.  
  521. if( !jQuery('#clientname').val() ) {
  522. jQuery("#clientname").after("<span class='apcal-error'><br><strong><?php _e("Name required.", "appointzilla"); ?></strong></span>");
  523. return false;
  524. } else if(!isNaN( jQuery('#clientname').val() )) {
  525. jQuery("#clientname").after("<span class='apcal-error'><br><strong><?php _e("Invalid Name", "appointzilla"); ?></strong></span>");
  526. return false;
  527. }
  528.  
  529. var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  530. if( !jQuery('#clientemail').val() ) {
  531. jQuery("#clientemail").after("<span class='apcal-error'><br><strong><?php _e("Email required.", "appointzilla"); ?></strong></span>");
  532. return false;
  533. } else {
  534. if(regex.test(jQuery('#clientemail').val()) == false ) {
  535. jQuery("#clientemail").after("<span class='apcal-error'><br><strong><?php _e("Invalid Email", "appointzilla"); ?></strong></span>");
  536. return false;
  537. }
  538. }
  539.  
  540. if( !jQuery('#clientphone').val() ) {
  541. jQuery("#clientphone").after("<span class='apcal-error'><br><strong><?php _e("Phone required.", "appointzilla"); ?></strong></span>");
  542. return false;
  543. } else if(isNaN( jQuery('#clientphone').val() )) {
  544. jQuery("#clientphone").after("<span class='apcal-error'><br><strong><?php _e("Invalid phone number.", "appointzilla"); ?></strong></span>");
  545. return false;
  546. }
  547.  
  548. var wp_nonce = jQuery('#appointment_register_nonce_field').val();
  549.  
  550. var ServiceId = jQuery('#serviceid').val();
  551. var AppDate = jQuery('#appointmentdate').val();
  552. var ServiceDuration = jQuery('#serviceduration').val();
  553. var StartTime = jQuery('input[name=start_time]:radio:checked').val();
  554. var Client_Name = jQuery('#clientname').val();
  555. var Client_Email = jQuery('#clientemail').val();
  556. var Client_Phone = jQuery('#clientphone').val();
  557. var Client_Note = jQuery('#clientnote').val();
  558. var currenturl = jQuery(location).attr('href');
  559. var SecondData = "ServiceId=" + ServiceId + "&AppDate=" + AppDate + "&StartTime=" + StartTime + '&Client_Name=' + Client_Name +'&Client_Email=' + Client_Email +'&Client_Phone=' + Client_Phone +'&Client_Note=' + Client_Note+'&Service_Duration=' + ServiceDuration + '&wp_nonce=' + wp_nonce;
  560. var currenturl = jQuery(location).attr('href');
  561. var url = currenturl;
  562. jQuery('#loading2').show(); // loading button onclick next1 at first modal
  563. jQuery('#buttonbox').hide(); // loading button onclick book now at first modal
  564. jQuery.ajax({
  565. dataType : 'html',
  566. type: 'POST',
  567. url : url,
  568. cache: false,
  569. data : SecondData,
  570. complete : function() { },
  571. success: function() {
  572. jQuery('#AppSecondModalDiv').hide();
  573. alert("<?php _e("Thank you for scheduling appointment with us. A confirmation mail will be forward to you soon after admin approval.", "appointzilla"); ?>");
  574. var currenturl = jQuery(location).attr('href');
  575. var url = currenturl.replace("#","");
  576. window.location = url;
  577. }
  578. });
  579. }
  580. </script>
  581. <style type='text/css'>
  582. .apcal-error{
  583. color: #FF0000;
  584. }
  585. </style>
  586.  
  587. <!---Display Booking Instruction--->
  588. <?php if($AllCalendarSettings['apcal_booking_instructions']) { ?>
  589. <div id="bookinginstructions" align="center">
  590. <?php echo $AllCalendarSettings['apcal_booking_instructions']; ?>
  591. </div>
  592. <?php } ?>
  593.  
  594. <!---Schedule New New Appointment Button--->
  595. <div id="bkbtndiv" align="center" style="padding:5px;">
  596. <button name="addappointment" class="apcal_btn apcal_btn-primary apcal_btn-large" type="submit" id="addappointment">
  597. <strong></strong><i class="icon-calendar icon-white"></i>
  598. <?php if($AllCalendarSettings['booking_button_text']) {
  599. echo $AllCalendarSettings['booking_button_text'];
  600. } else {
  601. echo _e("Schedule New Appointment", "appointzilla");
  602. } ?>
  603. </strong>
  604. </button>
  605. </div>
  606.  
  607. <!---Show appointment calendar--->
  608. <div id='calendar'>
  609. <div align="right">Appointment Calendar Powered By: <a href="http://appointzilla.com/" title="Appointment Scheduling plugin for Wordpress" target="_blank">AppointZilla</a></div>
  610. <!---AppSecondModal For Schedule New Appointment--->
  611. <div id="AppSecondModalDiv" style="display:none;"></div>
  612. </div>
  613.  
  614.  
  615. <!---AppFirstModal For Schedule New Appointment--->
  616. <div id="AppFirstModal" style="display:none">
  617. <div class="apcal_modal" id="myModal" style="z-index:99999;">
  618. <form action="" method="post" name="addnewappointment" id="addnewappointment" >
  619. <div class="apcal_modal-info">
  620. <div class="apcal_alert apcal_alert-info">
  621. <div><a href="#" style="float:right; margin-right:-4px;" id="close"><i class="icon-remove"></i></a>
  622. </div>
  623. <p><strong><?php _e("Schedule New Appointment", "appointzilla"); ?></strong></p>
  624. <div><?php _e("Select Date & Service", "appointzilla"); ?></div>
  625. </div>
  626. </div>
  627.  
  628. <div class="apcal_modal-body">
  629. <div id="firdiv" style="float:left;">
  630. <div id="datepicker"></div>
  631.  
  632. <!--PHP Date-picker -->
  633. <form id="form1" name="form1" method="post" action="">
  634.  
  635. <?php
  636. require_once('calendar/tc_calendar.php');
  637.  
  638. $curr_date = date("Y-m-d", time());
  639. $datepicker2=plugins_url('calendar/', __FILE__);
  640. $myCalendar = new tc_calendar( "date1" );
  641. $myCalendar->setIcon( $datepicker2 . "images/iconCalendar.gif" );
  642. $myCalendar->setDate( date("d") , date("m") , date("Y") );
  643. $myCalendar->setPath($datepicker2);
  644. $myCalendar->setYearInterval(2035,date('Y'));
  645. $startCalendarFrom = date("Y-m-d", strtotime("-1 day", strtotime($curr_date)));
  646. $myCalendar->dateAllow($startCalendarFrom, "2035-01-01", false);
  647. $myCalendar->setOnChange( "myChanged()" );
  648. $myCalendar->writeScript();
  649. ?>
  650.  
  651. </form>
  652.  
  653. <script language="javascript">
  654. function myChanged() {
  655. var x = document.getElementById('date1').value;
  656. x = moment(x).format('DD-MM-YYYY');
  657. document.getElementById('appdate').value = x;
  658. }
  659. </script>
  660. </div>
  661.  
  662. <div id="secdiv" style="float:right;">
  663. <strong><?php _e("Your Appointment Date", "appointzilla"); ?>:</strong><br>
  664. <input name="appdate" id="appdate" type="text" readonly="" height="30px;" style="height:30px;" />
  665.  
  666. <?php
  667. global $wpdb;
  668. $ServiceTable = $wpdb->prefix . "ap_services";
  669. $AllService = $wpdb->get_results($wpdb->prepare("SELECT * FROM `$ServiceTable` WHERE `availability` = %s",'yes'), OBJECT); ?>
  670.  
  671. <br /><br />
  672. <strong><?php _e("Select Service", "appointzilla"); ?>:</strong><br />
  673. <select name="service" id="service">
  674. <option value="0"><?php _e("Select Service", "appointzilla"); ?></option>
  675. <?php foreach($AllService as $Service) { ?>
  676. <?php if($AllCalendarSettings['show_service_cost'] == 'yes') $ShowCost = 1; else $ShowCost = 0; ?>
  677. <?php if($AllCalendarSettings['show_service_duration'] == 'yes') $ShowDuration = 1; else $ShowDuration = 0; ?>
  678. <option value="<?php echo esc_attr($Service->id); ?>">
  679. <?php echo ucwords($Service->name);
  680. if($ShowDuration || $ShowCost) echo " (";
  681. if($ShowDuration) { echo $Service->duration."min"; } if($ShowDuration && $ShowCost) echo "/";
  682. if($ShowCost) { echo "$". $Service->cost; }
  683. if($ShowDuration || $ShowCost) echo ")"; ?>
  684. </option>
  685. <?php }?>
  686. </select>
  687. <br>
  688. <button name="next1" class="apcal_btn" type="button" id="next1" value="next1"><?php _e("Next", "appointzilla"); ?> <i class="icon-arrow-right"></i></button>
  689. <div id="loading1" style="display:none;"><?php _e("Loading...", "appointzilla"); ?><img src="<?php echo plugins_url()."/appointment-calendar/images/loading.gif"; ?>" /></div>
  690. </div>
  691. </div>
  692. </form>
  693. </div>
  694. </div>
  695. <!---AppSecondModal For Schedule New Appointment--->
  696.  
  697. <?php if( isset($_GET["ServiceId"]) && isset($_GET["AppDate"])) { ?>
  698. <div id="AppSecondModal">
  699. <div class="apcal_modal" id="myModal" style="z-index:99999;">
  700. <form method="post" name="appointment-form2" id="appointment-form2" action="" onsubmit="return CheckValidation()">
  701. <?php wp_nonce_field('appointment_register_nonce_check','appointment_register_nonce_field'); ?>
  702. <div class="apcal_modal-info">
  703. <div class="apcal_alert apcal_alert-info">
  704. <a href="" style="float:right; margin-right:-4px;" id="close"><i class="icon-remove"></i></a>
  705. <p><strong><?php _e("Schedule New Appointment", "appointzilla"); ?></strong></p>
  706. <div><?php _e("Select Time & Fill Out Form", "appointzilla"); ?></div>
  707. </div>
  708. </div>
  709.  
  710. <div class="apcal_modal-body">
  711. <div id="timesloatbox" class="apcal_alert apcal_alert-block" style="float:left; height:auto; width:90%;">
  712. <!---slots time calculation--->
  713. <?php
  714. // time-slots calculation
  715. global $wpdb;
  716. $ServiceId = intval( $_GET["ServiceId"] );
  717. $ServiceTableName = $wpdb->prefix . "ap_services";
  718. $ServiceData = $wpdb->get_row($wpdb->prepare("SELECT `name`, `duration` FROM `$ServiceTableName` WHERE `id` = %d",$ServiceId), OBJECT);
  719.  
  720. $ServiceDuration = $ServiceData->duration;
  721.  
  722. $AppointmentDate = date("Y-m-d", strtotime($_GET['AppDate'])); //assign selected date by user
  723. $AllCalendarSettings = unserialize(get_option('apcal_calendar_settings'));
  724. $Biz_start_time = $AllCalendarSettings['day_start_time'];
  725. $Biz_end_time = $AllCalendarSettings['day_end_time'];
  726. if(isset($AllCalendarSettings['booking_time_slot'])) {
  727. $UserDefineTimeSlot = $AllCalendarSettings['booking_time_slot'];
  728. } else {
  729. $UserDefineTimeSlot = $ServiceDuration;
  730. }
  731. $AllSlotTimesList = array();
  732. $Enable = array();
  733. $AppPreviousTimes = array();
  734. $AppNextTimes = array();
  735. $AppBetweenTimes = array();
  736. $EventPreviousTimes = array();
  737. $EventBetweenTimes = array();
  738. $DisableSlotsTimes = array();
  739. $BusinessEndCheck =array();
  740. $AllSlotTimesList_User = array();
  741. $TodaysAllDayEvent = 0;
  742.  
  743. $TimeOffTableName = $wpdb->prefix ."ap_events";
  744.  
  745. //if today is any all-day time-off then show msg no time available today
  746. $TodaysAllDayEventData = $wpdb->get_results( $wpdb->prepare("SELECT `start_time`, `end_time`, `repeat`, `start_date`, `end_date` FROM `$TimeOffTableName` WHERE date('$AppointmentDate') between `start_date` AND `end_date` AND `allday` = %s",'1'), OBJECT);
  747.  
  748. //check if appointment date in any recurring time-off date
  749. foreach($TodaysAllDayEventData as $SingleTimeOff) {
  750. // none check
  751. if($SingleTimeOff->repeat == 'N') {
  752. $TodaysAllDayEvent = 1;
  753. }
  754.  
  755. // daily check
  756. if($SingleTimeOff->repeat == 'D') {
  757. $TodaysAllDayEvent = 1;
  758. }
  759.  
  760. // weekly check
  761. if($SingleTimeOff->repeat == 'W') {
  762. $EventStartDate = $SingleTimeOff->start_date;
  763. $diff = ( strtotime($EventStartDate) - strtotime($AppointmentDate) )/60/60/24;
  764. if(($diff % 7) == 0) {
  765. $TodaysAllDayEvent = 1;
  766. }
  767. }
  768.  
  769. //bi-weekly check
  770. if($SingleTimeOff->repeat == 'BW') {
  771. $EventStartDate = $SingleTimeOff->start_date;
  772. $diff = ( strtotime($EventStartDate) - strtotime($AppointmentDate) )/60/60/24;
  773. if(($diff % 14) == 0) {
  774. $TodaysAllDayEvent = 1;
  775. }
  776. }
  777.  
  778. //monthly check
  779. if($SingleTimeOff->repeat == 'M') {
  780. // calculate all monthly dates
  781. $EventStartDate = $SingleTimeOff->start_date;
  782. $EventEndDate = $SingleTimeOff->end_date;
  783. $i = 0;
  784. do {
  785. $NextDate = date("Y-m-d", strtotime("+$i months", strtotime($EventStartDate)));
  786. $AllEventMonthlyDates[] = $NextDate;
  787. $i = $i+1;
  788. } while(strtotime($EventEndDate) != strtotime($NextDate));
  789.  
  790. //check appointment-date in $AllEventMonthlyDates
  791. if(in_array($AppointmentDate, $AllEventMonthlyDates)) {
  792. $TodaysAllDayEvent = 1;
  793. }
  794. }
  795. }//end of event fetching foreach
  796.  
  797.  
  798. if($TodaysAllDayEvent) { ?>
  799. <div class='apcal_alert apcal_alert-error'><?php _e("Sorry! No time available today.", "appointzilla"); ?></div>
  800. <a class="apcal_btn" id="back" onclick="return Backbutton()"><i class="icon-arrow-left"></i> <?php _e("Back", "appointzilla"); ?></a><?php
  801. } else {
  802. echo "<div class='apcal_alert apcal_alert-info' align='center'>". __("Available Time For", "appointzilla") ." <strong>'$ServiceData->name'</strong> ". __("On", "appointzilla"). " <strong>'".date("d-m-Y", strtotime($AppointmentDate))."'</strong></div>";
  803.  
  804. //Calculate all time slots according to today's biz hours
  805. $start = strtotime($Biz_start_time);
  806. $end = strtotime($Biz_end_time);
  807.  
  808. if($UserDefineTimeSlot) {
  809. $UserTimeSlot = $UserDefineTimeSlot;
  810. } else {
  811. $UserTimeSlot = 30;
  812. }
  813. for( $i = $start; $i < $end; $i += (60*$UserTimeSlot)) {
  814. $AllSlotTimesList_User[] = date('h:i A', $i);
  815. }
  816. // Business end check
  817. $Business_end = strtotime($Biz_end_time);
  818. $ServiceDuration_Biss= $ServiceDuration-5;
  819. $ServiceDuration_Biss = $ServiceDuration_Biss *60;
  820. $EndStartTime = $Business_end - $ServiceDuration_Biss;
  821. for( $i = $EndStartTime; $i < $Business_end; $i += (60*5)) {
  822. $BusinessEndCheck[] = date('h:i A', $i);
  823. }
  824.  
  825. // Create Business Time slot for calculation
  826. for( $i = $start; $i < $end; $i += (60*5)) {
  827. $AllSlotTimesList[] = date('h:i A', $i);
  828. }
  829.  
  830. //Fetch All today's appointments and calculate disable slots
  831. $AppointmentTableName = $wpdb->prefix . "ap_appointments";
  832. $AllAppointmentsData = $wpdb->get_results( $wpdb->prepare("SELECT `start_time`, `end_time` FROM `$AppointmentTableName` WHERE `date`= %s",$AppointmentDate) , OBJECT);
  833.  
  834. if($AllAppointmentsData) {
  835. foreach($AllAppointmentsData as $Appointment) {
  836. $AppStartTimes[] = date('h:i A', strtotime( $Appointment->start_time ) );
  837. $AppEndTimes[] = date('h:i A', strtotime( $Appointment->end_time ) );
  838.  
  839. //now calculate 5min slots between appointment's start_time & end_time
  840. $start_et = strtotime($Appointment->start_time);
  841. $end_et = strtotime($Appointment->end_time);
  842. //make 15-10=5min slot
  843. for( $i = $start_et; $i < $end_et; $i += (60*(5))) {
  844. $AppBetweenTimes[] = date('h:i A', $i);
  845. }
  846. }
  847.  
  848. //calculating Next & Previous time of booked appointments
  849. foreach($AllSlotTimesList as $single) {
  850. if(in_array($single, $AppStartTimes)) {
  851. //get next time
  852. $time = $single;
  853. $event_length = $ServiceDuration-5; // Service duration time - slot time
  854. $timestamp = strtotime("$time");
  855. $endtime = strtotime("+$event_length minutes", $timestamp);
  856. $next_time = date('h:i A', $endtime);
  857. //calculate next time
  858. $start = strtotime($single);
  859. $end = strtotime($next_time);
  860. //making 5min diffrance slot
  861. for( $i = $start; $i <= $end; $i += (60*(5))) {
  862. $AppNextTimes[] = date('h:i A', $i);
  863. }
  864.  
  865. //calculate previous time
  866. $time1 = $single;
  867. $event_length1 = $ServiceDuration-5; // 60min Service duration time - 15 slot time
  868. $timestamp1 = strtotime("$time1");
  869. $endtime1 = strtotime("-$event_length1 minutes", $timestamp1);
  870. $next_time1 = date('h:i A', $endtime1);
  871. $start1 = strtotime($next_time1);
  872. $end1 = strtotime($single);
  873. //making 5min diff slot
  874. for( $i = $start1; $i <= $end1; $i += (60*(5))) {
  875. $AppPreviousTimes[] = date('h:i A', $i);
  876. }
  877. }
  878. }//end calculating Next & Previous time of booked appointments
  879. } // end if $AllAppointmentsData
  880.  
  881. //Fetch All today's time-off and calculate disable slots
  882. $EventTableName = $wpdb->prefix."ap_events";
  883. $AllEventsData = $wpdb->get_results($wpdb->prepare("SELECT `start_time`, `end_time` FROM `$EventTableName` WHERE date('$AppointmentDate') between `start_date` AND `end_date` AND `allday` = '0' AND `repeat` != 'W' AND `repeat` != 'BW' AND `repeat` != %s",'M'), OBJECT);
  884.  
  885. if($AllEventsData)
  886. {
  887. foreach($AllEventsData as $Event)
  888. {
  889. //calculate previous time (event start time to back service-duration-5)
  890. $minustime = $ServiceDuration - 5;
  891. $start = date('h:i A', strtotime("-$minustime minutes", strtotime($Event->start_time)));
  892. $start = strtotime($start);
  893. $end = $Event->start_time;
  894. $end = strtotime($end);
  895. for( $i = $start; $i <= $end; $i += (60*(5))) //making 5min difference slot
  896. {
  897. $EventPreviousTimes[] = date('h:i A', $i);
  898. }
  899.  
  900. //calculating between time (start - end)
  901. $start_et = strtotime($Event->start_time);
  902. $end_et = strtotime($Event->end_time);
  903. for( $i = $start_et; $i < $end_et; $i += (60*(5))) //making 5min slot
  904. {
  905. $EventBetweenTimes[] = date('h:i A', $i);
  906. }
  907. }
  908. }
  909.  
  910. //Fetch All 'WEEKLY' tim-eoff and calculate disable slots
  911. $EventTableName = $wpdb->prefix . "ap_events";
  912. $AllEventsData = $wpdb->get_results($wpdb->prepare("SELECT `start_time`, `end_time`, `start_date`, `end_date` FROM `$EventTableName` WHERE date('$AppointmentDate') between `start_date` AND `end_date` AND `allday` = '0' AND `repeat` = %s",'W'), OBJECT);
  913.  
  914. if($AllEventsData) {
  915. foreach($AllEventsData as $Event) {
  916. //calculate all weekly dates between recurring_start_date - recurring_end_date
  917. $Current_Re_Start_Date = $Event->start_date;
  918. $Current_Re_End_Date = $Event->end_date;
  919. $Current_Re_Start_Date = strtotime($Current_Re_Start_Date);
  920. $Current_Re_End_Date = strtotime($Current_Re_End_Date);
  921. //make weekly dates
  922. for( $i = $Current_Re_Start_Date; $i <= $Current_Re_End_Date; $i += (60 * 60 * 24 * 7)) {
  923. $AllEventWeelylyDates[] = date('Y-m-d', $i);
  924. }
  925. if(in_array($AppointmentDate, $AllEventWeelylyDates)) {
  926. //calculate previous time (event start time to back service-duration-5)
  927. $minustime = $ServiceDuration - 5;
  928. $start = date('h:i A', strtotime("-$minustime minutes", strtotime($Event->start_time)));
  929. $start = strtotime($start);
  930. $end = $Event->start_time;
  931. $end = strtotime($end);
  932. //making 5min difference slot
  933. for( $i = $start; $i <= $end; $i += (60*(5))) {
  934. $EventPreviousTimes[] = date('h:i A', $i);
  935. }
  936.  
  937. //calculating between time (start - end)
  938. $start_et = strtotime($Event->start_time);
  939. $end_et = strtotime($Event->end_time);
  940. //making 5min slot
  941. for( $i = $start_et; $i < $end_et; $i += (60*(5))) {
  942. $EventBetweenTimes[] = date('h:i A', $i);
  943. }
  944. }
  945. unset($AllEventWeelylyDates);
  946. }
  947. }
  948.  
  949. //Fetch All 'BI-WEEKLY' time-off and calculate disable slots
  950. $EventTableName = $wpdb->prefix."ap_events";
  951. $AllEventsData = $wpdb->get_results($wpdb->prepare("SELECT `start_time`, `end_time`, `start_date`, `end_date` FROM `$EventTableName` WHERE date('$AppointmentDate') between `start_date` AND `end_date` AND `allday` = '0' AND `repeat` = %s",'BW'), OBJECT);
  952.  
  953. if($AllEventsData) {
  954. foreach($AllEventsData as $Event) {
  955. //calculate all weekly dates between recurring_start_date - recurring_end_date
  956. $Current_Re_Start_Date = $Event->start_date;
  957. $Current_Re_End_Date = $Event->end_date;
  958.  
  959. $Current_Re_Start_Date = strtotime($Current_Re_Start_Date);
  960. $Current_Re_End_Date = strtotime($Current_Re_End_Date);
  961. //make bi-weekly dates
  962. for( $i = $Current_Re_Start_Date; $i <= $Current_Re_End_Date; $i += (60 * 60 * 24 * 14)) {
  963. $AllEventBiWeelylyDates[] = date('Y-m-d', $i);
  964. }
  965. if(in_array($AppointmentDate, $AllEventBiWeelylyDates)) {
  966. //calculate previous time (event start time to back ServiceDuration-5)
  967. $minustime = $ServiceDuration - 5;
  968. $start = date('h:i A', strtotime("-$minustime minutes", strtotime($Event->start_time)));
  969. $start = strtotime($start);
  970. $end = $Event->start_time;
  971. $end = strtotime($end);
  972. //making 5min difference slot
  973. for( $i = $start; $i <= $end; $i += (60*(5))) {
  974. $EventPreviousTimes[] = date('h:i A', $i);
  975. }
  976.  
  977. //calculating between time (start - end)
  978. $start_et = strtotime($Event->start_time);
  979. $end_et = strtotime($Event->end_time);
  980. //making 5min slot
  981. for( $i = $start_et; $i < $end_et; $i += (60*(5))) {
  982. $EventBetweenTimes[] = date('h:i A', $i);
  983. }
  984. }
  985. }
  986. }
  987.  
  988. //Fetch All 'MONTHLY' timeoff and calculate disable slots
  989. $EventTableName = $wpdb->prefix."ap_events";
  990. $AllEventsData = $wpdb->get_results($wpdb->prepare("SELECT `start_time`, `end_time`, `start_date`, `end_date` FROM `$EventTableName` WHERE date('$AppointmentDate') between `start_date` AND `end_date` AND `allday` = '0' AND `repeat` = %s",'M'), OBJECT);
  991.  
  992. if($AllEventsData) {
  993. foreach($AllEventsData as $Event) {
  994. //calculate all weekly dates between recurring_start_date - recurring_end_date
  995. $Current_Re_Start_Date = $Event->start_date;
  996. $Current_Re_End_Date = $Event->end_date;
  997. $i = 0;
  998. do {
  999. $NextDate = date("Y-m-d", strtotime("+$i months", strtotime($Current_Re_Start_Date)));
  1000. $AllEventMonthlyDates[] = $NextDate;
  1001. $i = $i+1;
  1002. } while(strtotime($Current_Re_End_Date) != strtotime($NextDate));
  1003.  
  1004. if(in_array($AppointmentDate, $AllEventMonthlyDates)) {
  1005. //calculate previous time (event start time to back service-duration-5)
  1006. $minustime = $ServiceDuration - 5;
  1007. $start = date('h:i A', strtotime("-$minustime minutes", strtotime($Event->start_time)));
  1008. $start = strtotime($start);
  1009. $end = $Event->start_time;
  1010. $end = strtotime($end);
  1011. //making 5min difference slot
  1012. for( $i = $start; $i <= $end; $i += (60*(5))) {
  1013. $EventPreviousTimes[] = date('h:i A', $i);
  1014. }
  1015.  
  1016. $start_et = strtotime($Event->start_time);
  1017. $end_et = strtotime($Event->end_time);
  1018. //making 5min difference slot
  1019. for( $i = $start_et; $i < $end_et; $i += (60*(5))) {
  1020. $EventBetweenTimes[] = date('h:i A', $i);
  1021. }
  1022. }
  1023. }
  1024. }
  1025.  
  1026. $DisableSlotsTimes = array_merge($AppBetweenTimes, $AppPreviousTimes, $EventPreviousTimes, $EventBetweenTimes, $BusinessEndCheck);
  1027. unset($AppBetweenTimes);
  1028. unset($AppPreviousTimes);
  1029. unset($AppNextTimes);
  1030. unset($EventBetweenTimes);
  1031. unset($BusinessEndCheck);
  1032. // compare All Business Time slot with with DisableSlotsTimes
  1033. foreach($AllSlotTimesList as $Single) {
  1034. if(in_array($Single, $DisableSlotsTimes)) {
  1035. $Disable[] = $Single;
  1036. } else {
  1037. $Enable[] = $Single;
  1038. }
  1039. }// end foreach
  1040.  
  1041. // Show All Enable Time Slot
  1042. foreach($AllSlotTimesList_User as $Single) {
  1043. if(isset($Enable)) {
  1044. if(in_array($Single, $Enable)) { ?>
  1045. <!-- enable slots-->
  1046. <div style="width:90px; float:left; padding:1px; display:inline-block;">
  1047. <input name="start_time" id="start_time" type="radio" value="<?php echo esc_attr($Single); ?>"/>&nbsp;<?php echo $Single; ?>
  1048. </div><?php
  1049. } else { ?>
  1050. <!-- disable slots-->
  1051. <div style="width:90px; float:left; padding:1px; display:inline-block;">
  1052. <input name="start_time" id="start_time" disabled="disabled" type="radio" value="<?php echo esc_attr($Single); ?>"/>&nbsp;<del><?php echo $Single; ?></del>
  1053. </div><?php
  1054. }
  1055. }// end of enable isset
  1056. }// end foreach
  1057. unset($DisableSlotsTimes);
  1058. } // end else ?><br />
  1059. <div id="selecttimediv"><!--display select time error --></div>
  1060. </div>
  1061.  
  1062. <?php if(!$Enable && !$TodaysAllDayEvent ) { ?>
  1063. <p align=center class='apcal_alert apcal_alert-error' style='width:auto;'><strong><?php _e("Sorry! Today's all appointments has been booked.", "appointzilla"); ?></strong></p>
  1064. <a class="apcal_btn apcal_btn-primary" id="back" onclick="Backbutton()"><i class="icon-arrow-left"></i> <?php _e("Back", "appointzilla"); ?></a><?php
  1065. } else if(!$TodaysAllDayEvent && $Enable) { ?>
  1066. <input type="hidden" name="serviceid" id="serviceid" value="<?php echo esc_attr($_GET['ServiceId']); ?>" />
  1067. <input type="hidden" name="appointmentdate" id="appointmentdate" value="<?php echo esc_attr($_GET['AppDate']); ?>" />
  1068. <input type="hidden" name="serviceduration" id="serviceduration" value="<?php echo esc_attr($ServiceDuration); ?>" />
  1069. <table width="100%" id="bordercssremove">
  1070. <tr>
  1071. <td width="30%" align="left" scope="row"><strong><?php _e("Name", "appointzilla"); ?></strong></td>
  1072. <td width="5%" align="center" valign="top"><strong>:</strong></td>
  1073. <td width="65%"><input type="text" name="clientname" id="clientname" height="30px;" style="height:30px;" /></td>
  1074. </tr>
  1075. <tr>
  1076. <td align="left" scope="row"><strong><?php _e("Email", "appointzilla"); ?></strong></td>
  1077. <td align="center" valign="top"><strong>:</strong></td>
  1078. <td><input type="text" name="clientemail" id="clientemail" height="30px;" style="height:30px;" ></td>
  1079. </tr>
  1080. <tr>
  1081. <td align="left" scope="row"><strong><?php _e("Phone", "appointzilla"); ?></strong></td>
  1082. <td align="center" valign="top"><strong>:</strong></td>
  1083. <td><input name="clientphone" type="text" id="clientphone" maxlength="12" height="30px;" style="height:30px;" />
  1084. <br/>
  1085. <label><?php _e("Eg: 1234567890", "appointzilla"); ?></label></td>
  1086. </tr>
  1087. <tr>
  1088. <td align="left" valign="middle" scope="row"><strong><?php _e("Special Instruction", "appointzilla"); ?></strong></td>
  1089. <td align="center" valign="top"><strong>:</strong></td>
  1090. <td valign="top"><textarea name="clientnote" id="clientnote"></textarea></td>
  1091. </tr>
  1092. <tr id="buttonbox">
  1093. <td>&nbsp;</td>
  1094. <td>&nbsp;</td>
  1095. <td >
  1096. <a class="apcal_btn apcal_btn-alert" id="back" onclick="Backbutton()"><i class="icon-arrow-left"></i> <?php _e("Back", "appointzilla"); ?></a>
  1097. <button name="booknowapp" class="apcal_btn apcal_btn-success" type="button" id="booknowapp" onclick="CheckValidation()"><i class="icon-ok icon-white"></i> <?php _e("Book Now", "appointzilla"); ?></button>
  1098. </td>
  1099. </tr>
  1100. </table>
  1101. <div id="loading2" style="display:none; color:#1FCB4A;"><?php _e('Scheduling your appointment please wait...', 'appointzilla'); ?><img src="<?php echo plugins_url()."/appointment-calendar/images/loading.gif"; ?>" /></div>
  1102. <style type="text/css">
  1103. #bordercssremove tr td {
  1104. border-top: 0 solid #DDDDDD;
  1105. }
  1106. </style><?php
  1107. } ?>
  1108. </div>
  1109. <!--</div>-->
  1110. </form>
  1111. </div>
  1112. </div><?php
  1113. }// end of isset next1 servicId and AppDate
  1114. }//end of short code function ?>
Add Comment
Please, Sign In to add comment