pending-list.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <div class="booked-settings-wrap wrap"><?php
  2. $calendars = get_terms('booked_custom_calendars','orderby=slug&hide_empty=0');
  3. $booked_none_assigned = true;
  4. $default_calendar_id = false;
  5. if (!empty($calendars)):
  6. if (!current_user_can('manage_booked_options')):
  7. $booked_current_user = wp_get_current_user();
  8. $calendars = booked_filter_agent_calendars($booked_current_user,$calendars);
  9. if (empty($calendars)):
  10. $booked_none_assigned = true;
  11. else:
  12. $first_calendar = array_slice($calendars, 0, 1);
  13. $default_calendar_id = array_shift($first_calendar)->term_id;
  14. $booked_none_assigned = false;
  15. endif;
  16. else:
  17. $booked_none_assigned = false;
  18. endif;
  19. endif;
  20. if (!current_user_can('manage_booked_options') && $booked_none_assigned):
  21. echo '<div style="text-align:center;">';
  22. echo '<br><br><h3>'.esc_html__('There are no calendars assigned to you.','booked').'</h3>';
  23. echo '<p>'.esc_html__('Get in touch with the Administration of this site to get a calendar assigned to you.','booked').'</p>';
  24. echo '</div>';
  25. else:
  26. ?><div class="topSavingState savingState"><i class="booked-icon booked-icon-spinner-clock booked-icon-spin"></i>&nbsp;&nbsp;<?php esc_html_e('Updating, please wait...','booked'); ?></div>
  27. <div class="booked-settings-title"><?php esc_html_e('Pending Appointments','booked'); ?></div>
  28. <div class="booked-pending-cap bookedClearFix">
  29. <button class="delete-past button"><?php esc_html_e('Delete Passed Appointments','booked'); ?></button>
  30. <button style="float:right; margin-left:10px;" class="approve-all button button-primary"><?php esc_html_e('Approve All','booked'); ?></button>
  31. <button style="float:right;" class="delete-all button"><?php esc_html_e('Delete All','booked'); ?></button>
  32. </div><?php
  33. echo '<div class="booked-pending-appt-list">';
  34. $time_format = get_option('time_format');
  35. $date_format = get_option('date_format');
  36. $pending_statuses = apply_filters( 'booked_admin_pending_post_status',array('draft') );
  37. if (empty($calendars) && !current_user_can('manage_booked_options')):
  38. $args = false;
  39. elseif(current_user_can('manage_booked_options')):
  40. $args = array(
  41. 'post_type' => 'booked_appointments',
  42. 'posts_per_page' => -1,
  43. 'post_status' => $pending_statuses,
  44. 'meta_key' => '_appointment_timestamp',
  45. 'orderby' => 'meta_value_num',
  46. 'order' => 'ASC'
  47. );
  48. else:
  49. $calendar_ids = array();
  50. if (!empty($calendars)):
  51. foreach($calendars as $cal):
  52. $calendar_ids[] = $cal->term_id;
  53. endforeach;
  54. endif;
  55. $args = array(
  56. 'post_type' => 'booked_appointments',
  57. 'posts_per_page' => -1,
  58. 'post_status' => $pending_statuses,
  59. 'meta_key' => '_appointment_timestamp',
  60. 'orderby' => 'meta_value_num',
  61. 'order' => 'ASC'
  62. );
  63. if (!empty($calendar_ids)):
  64. $args['tax_query'] = array(
  65. array(
  66. 'taxonomy' => 'booked_custom_calendars',
  67. 'field' => 'term_id',
  68. 'terms' => $calendar_ids,
  69. )
  70. );
  71. endif;
  72. endif;
  73. $appointments_array = array();
  74. if ($args):
  75. $bookedAppointments = new WP_Query($args);
  76. if($bookedAppointments->have_posts()):
  77. while ($bookedAppointments->have_posts()):
  78. $bookedAppointments->the_post();
  79. global $post;
  80. $calendars = array();
  81. $calendar_terms = get_the_terms($post->ID,'booked_custom_calendars');
  82. if (!empty($calendar_terms)):
  83. $calendar_name = $calendar_terms[0]->name;
  84. $calendar_id = $calendar_terms[0]->term_id;
  85. else:
  86. $calendar_name = false;
  87. $calendar_id = false;
  88. endif;
  89. $guest_name = get_post_meta($post->ID, '_appointment_guest_name',true);
  90. $guest_surname = get_post_meta($post->ID, '_appointment_guest_surname',true);
  91. $guest_email = get_post_meta($post->ID, '_appointment_guest_email',true);
  92. $timestamp = get_post_meta($post->ID, '_appointment_timestamp',true);
  93. $timeslot = get_post_meta($post->ID, '_appointment_timeslot',true);
  94. $ts_title = get_post_meta($post->ID, '_appointment_title',true);
  95. $day = date_i18n('d',$timestamp);
  96. $appointments_array[$post->ID]['post_id'] = $post->ID;
  97. $appointments_array[$post->ID]['timestamp'] = $timestamp;
  98. $appointments_array[$post->ID]['timeslot'] = $timeslot;
  99. $appointments_array[$post->ID]['title'] = $ts_title;
  100. $appointments_array[$post->ID]['status'] = $post->post_status;
  101. $appointments_array[$post->ID]['calendar'] = $calendar_name;
  102. $appointments_array[$post->ID]['calendar_id'] = $calendar_id;
  103. if (!$guest_name):
  104. $user_id = get_post_meta($post->ID, '_appointment_user',true);
  105. $appointments_array[$post->ID]['user'] = $user_id;
  106. else:
  107. $appointments_array[$post->ID]['guest_name'] = $guest_name;
  108. $appointments_array[$post->ID]['guest_surname'] = $guest_surname;
  109. $appointments_array[$post->ID]['guest_email'] = $guest_email;
  110. endif;
  111. endwhile;
  112. $appointments_array = apply_filters('booked_appointments_array', $appointments_array);
  113. endif;
  114. endif;
  115. /*
  116. Let's loop through the pending appointments
  117. */
  118. if (!empty($appointments_array)):
  119. foreach($appointments_array as $appt):
  120. $date_display = date_i18n($date_format,$appt['timestamp']);
  121. $day_name = date_i18n('l',$appt['timestamp']);
  122. $timeslots = explode('-',$appt['timeslot']);
  123. $time_start = date_i18n($time_format,strtotime($timeslots[0]));
  124. $time_end = date_i18n($time_format,strtotime($timeslots[1]));
  125. $title = $appt['title'];
  126. $date_to_compare = strtotime(date_i18n('Y-m-d',$appt['timestamp']).' '.date_i18n('H:i:s',strtotime($timeslots[0])));
  127. $late_date = current_time('timestamp');
  128. if ($timeslots[0] == '0000' && $timeslots[1] == '2400'):
  129. $timeslotText = esc_html__('All day','booked');
  130. else :
  131. $timeslotText = $time_start.'&ndash;'.$time_end;
  132. endif;
  133. $pending_statuses = apply_filters('booked_admin_pending_post_status',array('draft'));
  134. $status = (in_array($appt['status'],$pending_statuses) ? 'pending' : 'approved');
  135. echo '<div class="pending-appt bookedClearFix'.($late_date > $date_to_compare ? ' passed' : '').'" data-appt-id="'.$appt['post_id'].'">';
  136. if (!isset($appt['guest_name'])):
  137. $user_info = get_userdata($appt['user']);
  138. if (isset($user_info->ID)):
  139. if ($user_info->user_firstname):
  140. $user_display = '<a href="#" class="user" data-user-id="'.$appt['user'].'">'.$user_info->user_firstname.($user_info->user_lastname ? ' '.$user_info->user_lastname : '').'</a>';
  141. elseif ($user_info->display_name):
  142. $user_display = '<a href="#" class="user" data-user-id="'.$appt['user'].'">'.$user_info->display_name.'</a>';
  143. else :
  144. $user_display = '<a href="#" class="user" data-user-id="'.$appt['user'].'">'.$user_info->user_login.'</a>';
  145. endif;
  146. else :
  147. $user_display = esc_html__('(this user no longer exists)','booked');
  148. endif;
  149. else :
  150. $user_display = '<a href="#" class="user" data-user-id="0">'.$appt['guest_name'].' '.$appt['guest_surname'].'</a>';
  151. endif;
  152. if (current_user_can('manage_booked_options') && $appt['calendar']):
  153. $term_meta = get_option( "taxonomy_".$appt['calendar_id'] );
  154. if ( isset( $term_meta['notifications_user_id'] ) && $term_meta['notifications_user_id'] ):
  155. $calendar_owner_email = $term_meta['notifications_user_id'];
  156. $calendar_owner = get_user_by('email',$calendar_owner_email);
  157. $calendar_owner_name = booked_get_name($calendar_owner->ID);
  158. else:
  159. $calendar_owner_name = false;
  160. endif;
  161. else:
  162. $calendar_owner_name = false;
  163. endif;
  164. echo '<span class="appt-block" data-appt-id="'.$appt['post_id'].'">';
  165. echo '<button data-appt-id="'.$appt['post_id'].'" class="approve button button-primary">'.esc_html__('Approve','booked').'</button>';
  166. echo '<button class="delete button">'.esc_html__('Delete','booked').'</button>';
  167. echo $user_display;
  168. echo '<br>';
  169. if ($late_date > $date_to_compare): echo '<span class="late-appt">' . esc_html__('This appointment has passed.','booked') . '</span><br>'; endif;
  170. if ($calendar_owner_name): echo '<i class="booked-icon booked-icon-user"></i>&nbsp;&nbsp;'.sprintf(esc_html__('Assigned to %s','booked'),$calendar_owner_name).'<br>'; endif;
  171. if ($appt['calendar']): echo '<i class="booked-icon booked-icon-calendar"></i>&nbsp;&nbsp;<strong>'.$appt['calendar'].'</strong>: '; endif;
  172. echo $day_name.', '.$date_display;
  173. echo '<br><i class="booked-icon booked-icon-clock"></i>&nbsp;&nbsp;'.($title ? '<strong>'.$title.':</strong>&nbsp;&nbsp;' : '').$timeslotText;
  174. echo '</span>';
  175. echo '</div>';
  176. endforeach;
  177. endif;
  178. echo '<div class="pending-appt'.(!empty($appointments_array) ? ' no-pending-message' : '').'">';
  179. echo '<p style="text-align:center; margin:3em 0 2em">'.esc_html__('There are no pending appointments.','booked').'</p>';
  180. echo '</div>';
  181. echo '</div>';
  182. endif;
  183. ?>
  184. </div>