ajax.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. if(!class_exists('BookedFEA_Ajax')) {
  3. class BookedFEA_Ajax {
  4. public function __construct() {
  5. // Ajax Actions
  6. add_action('wp_ajax_booked_fea_delete_appt', array(&$this,'booked_fea_delete_appt'));
  7. add_action('wp_ajax_booked_fea_approve_appt', array(&$this,'booked_fea_approve_appt'));
  8. // Ajax Loaders
  9. add_action('wp_ajax_booked_fea_user_info_modal', array(&$this,'booked_fea_user_info_modal'));
  10. }
  11. // Delete an Appointment
  12. public function booked_fea_delete_appt(){
  13. if ( isset($_POST['appt_id']) ):
  14. $appt_id = esc_html( $_POST['appt_id'] );
  15. // Send an email to the user?
  16. $email_content = get_option('booked_cancellation_email_content');
  17. $email_subject = get_option('booked_cancellation_email_subject');
  18. if ($email_content && $email_subject):
  19. $token_replacements = booked_get_appointment_tokens( $appt_id );
  20. $email_content = booked_token_replacement( $email_content,$token_replacements );
  21. $email_subject = booked_token_replacement( $email_subject,$token_replacements );
  22. booked_mailer( $token_replacements['email'], $email_subject, $email_content );
  23. endif;
  24. wp_delete_post($appt_id,true);
  25. wp_die();
  26. endif;
  27. }
  28. // Approve an Appointment
  29. public function booked_fea_approve_appt(){
  30. if (isset($_POST['appt_id'])):
  31. $appt_id = esc_html( $_POST['appt_id'] );
  32. // Send an email to the user?
  33. $email_content = get_option('booked_approval_email_content');
  34. $email_subject = get_option('booked_approval_email_subject');
  35. $token_replacements = booked_get_appointment_tokens( $appt_id );
  36. if ($email_content && $email_subject):
  37. $email_content = booked_token_replacement( $email_content,$token_replacements );
  38. $email_subject = booked_token_replacement( $email_subject,$token_replacements );
  39. booked_mailer( $token_replacements['email'], $email_subject, $email_content );
  40. endif;
  41. wp_publish_post( $appt_id );
  42. wp_die();
  43. endif;
  44. }
  45. // Display the Appointment/User Info Modal
  46. public function booked_fea_user_info_modal(){
  47. if (isset($_POST['user_id'])):
  48. ob_start();
  49. echo '<div class="booked-scrollable">';
  50. echo '<p class="booked-title-bar"><small>' . __('Appointment Information','booked-frontend-agents') . '</small></p>';
  51. if (!$_POST['user_id'] && isset($_POST['appt_id'])):
  52. $guest_name = get_post_meta($_POST['appt_id'], '_appointment_guest_name',true);
  53. $guest_email = get_post_meta($_POST['appt_id'], '_appointment_guest_email',true);
  54. echo '<p class="fea-modal-title">'.__('Contact Information','booked-frontend-agents').'</p>';
  55. echo '<p><strong class="booked-left-title">'.__('Name','booked-frontend-agents').':</strong> '.$guest_name.'<br>';
  56. if ($guest_email) : echo '<strong class="booked-left-title">'.__('Email','booked-frontend-agents').':</strong> <a href="mailto:'.$guest_email.'">'.$guest_email.'</a>'; endif;
  57. echo '</p>';
  58. else :
  59. // Customer Information
  60. $user_info = get_userdata($_POST['user_id']);
  61. $display_name = booked_get_name($_POST['user_id']);
  62. $email = $user_info->user_email;
  63. $phone = get_user_meta($_POST['user_id'], 'booked_phone', true);
  64. echo '<p class="fea-modal-title">'.__('Contact Information','booked-frontend-agents').'</p>';
  65. echo '<p><strong class="booked-left-title">'.__('Name','booked-frontend-agents').':</strong> '.$display_name.'<br>';
  66. if ($email) : echo '<strong class="booked-left-title">'.__('Email','booked-frontend-agents').':</strong> <a href="mailto:'.$email.'">'.$email.'</a><br>'; endif;
  67. if ($phone) : echo '<strong class="booked-left-title">'.__('Phone','booked-frontend-agents').':</strong> <a href="tel:'.preg_replace('/[^0-9+]/', '', $phone).'">'.$phone.'</a>'; endif;
  68. echo '</p>';
  69. endif;
  70. // Appointment Information
  71. if (isset($_POST['appt_id'])):
  72. $time_format = get_option('time_format');
  73. $date_format = get_option('date_format');
  74. $appt_id = $_POST['appt_id'];
  75. $timestamp = get_post_meta($appt_id, '_appointment_timestamp',true);
  76. $timeslot = get_post_meta($appt_id, '_appointment_timeslot',true);
  77. $cf_meta_value = get_post_meta($appt_id, '_cf_meta_value',true);
  78. $date_display = date_i18n($date_format,$timestamp);
  79. $day_name = date_i18n('l',$timestamp);
  80. $timeslots = explode('-',$timeslot);
  81. $time_start = date($time_format,strtotime($timeslots[0]));
  82. $time_end = date($time_format,strtotime($timeslots[1]));
  83. if ($timeslots[0] == '0000' && $timeslots[1] == '2400'):
  84. $timeslotText = 'All day';
  85. else :
  86. $timeslotText = $time_start.' '.__('to','booked-frontend-agents').' '.$time_end;
  87. endif;
  88. $cf_meta_value = apply_filters('booked_fea_cf_metavalue',$cf_meta_value);
  89. echo '<p class="fea-modal-title fea-bordered">'.__('Appointment Information','booked-frontend-agents').'</p>';
  90. do_action('booked_before_appointment_information_admin');
  91. echo '<p><strong class="booked-left-title">'.__('Date','booked-frontend-agents').':</strong> '.$day_name.', '.$date_display.'<br>';
  92. echo '<strong class="booked-left-title">'.__('Time','booked-frontend-agents').':</strong> '.$timeslotText.'</p>';
  93. echo ($cf_meta_value ? '<div class="cf-meta-values">'.$cf_meta_value.'</div>' : '');
  94. do_action('booked_after_appointment_information_admin');
  95. endif;
  96. // Close button
  97. echo '<a href="#" class="close"><i class="booked-icon booked-icon-close"></i></a>';
  98. echo '</div>';
  99. echo ob_get_clean();
  100. wp_die();
  101. endif;
  102. }
  103. }
  104. }