admin-functions.php 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326
  1. <?php
  2. function booked_new_tag($show_new_tags){
  3. if ($show_new_tags):
  4. echo '<span class="booked-new-tag">New</span>';
  5. endif;
  6. return false;
  7. }
  8. function booked_timeslots_select( $appt_id = false, $year, $month, $day = false ){
  9. if ( !$appt_id )
  10. return;
  11. // Caledar ID
  12. $calendars = get_the_terms( $appt_id, 'booked_custom_calendars' );
  13. if ( !empty($calendars) ):
  14. foreach( $calendars as $calendar ):
  15. $calendar_id = $calendar->term_id;
  16. endforeach;
  17. else:
  18. $calendar_id = false;
  19. endif;
  20. // Timeslot Information
  21. $time_format = get_option('time_format');
  22. $timeslot = get_post_meta($appt_id, '_appointment_timeslot',true);
  23. $timeslots = explode('-',$timeslot);
  24. $time_start = date_i18n($time_format,strtotime($timeslots[0]));
  25. $time_end = date_i18n($time_format,strtotime($timeslots[1]));
  26. if ($timeslots[0] == '0000' && $timeslots[1] == '2400'):
  27. $timeslotText = esc_html__('All day','booked');
  28. else :
  29. $timeslotText = $time_start.' '.esc_html__('to','booked').' '.$time_end;
  30. endif;
  31. $time_format = get_option('time_format');
  32. $full_date = $year . '-' . $month . ( $day ? '-' . $day : '' );
  33. $available_timeslots_array = booked_appointments_available( $year, $month, $day, $calendar_id, true, true );
  34. $available_timeslots_array = ( isset( $available_timeslots_array[$full_date] ) ? $available_timeslots_array[$full_date] : array() );
  35. echo '<select class="large textfield booked_appt_timeslot" name="appt_timeslot">';
  36. if ( !empty($available_timeslots_array) ):
  37. foreach( $available_timeslots_array as $_timeslot => $_available ):
  38. if ( $timeslot == $_timeslot ):
  39. $_available = '';
  40. elseif ( $_available > 0 ):
  41. $_available = ' (' . sprintf( _n( '%d Space Available', '%d Spaces Available', $_available, 'booked'), $_available ) . ')';
  42. else:
  43. $_available = ' [' . esc_html__('Full','booked') . ']';
  44. endif;
  45. $_timeslots = explode('-',$_timeslot);
  46. $_time_start = date_i18n($time_format,strtotime($_timeslots[0]));
  47. $_time_end = date_i18n($time_format,strtotime($_timeslots[1]));
  48. if ($_timeslots[0] == '0000' && $_timeslots[1] == '2400'):
  49. $_timeslotText = esc_html__('All day','booked');
  50. else :
  51. $_timeslotText = sprintf( esc_html__('%s to %s','booked'), $_time_start, $_time_end );
  52. endif;
  53. echo '<option value="' . $_timeslot . '"' . ($timeslot == $_timeslot ? ' selected="selected"' : '' ) . '>' . $_timeslotText . $_available . '</option>';
  54. endforeach;
  55. else:
  56. echo '<option value="' . $timeslot . '">' . $timeslotText . ' [' . esc_html__('Full','booked') . ']</option>';
  57. endif;
  58. echo '</select>';
  59. }
  60. function booked_parse_readme_changelog( $readme_url = false, $title = false ){
  61. $readme = ( !$readme_url ? file_get_contents( BOOKED_PLUGIN_DIR . '/readme.txt') : file_get_contents( $readme_url ) );
  62. $readme = make_clickable(esc_html($readme));
  63. $readme = preg_replace('/`(.*?)`/', '<code>\\1</code>', $readme);
  64. $readme = preg_replace( '/[\040]\*\*\NEW:\*\*/', '<strong class="new">' . esc_html__( 'New', 'booked' ) . '</strong>', $readme);
  65. $readme = preg_replace( '/[\040]\*\*\TWEAK:\*\*/', '<strong class="tweak">' . esc_html__( 'Tweak', 'booked' ) . '</strong>', $readme);
  66. $readme = preg_replace( '/[\040]\*\*\FIX:\*\*/', '<em class="fix">' . esc_html__( 'Fixed', 'booked' ) . '</em>', $readme);
  67. $readme = preg_replace( '/[\040]\*\*\NEW\*\*/', '<strong class="new">' . esc_html__( 'New', 'booked' ) . '</strong>', $readme);
  68. $readme = preg_replace( '/[\040]\*\*\TWEAK\*\*/', '<strong class="tweak">' . esc_html__( 'Tweak', 'booked' ) . '</strong>', $readme);
  69. $readme = preg_replace( '/[\040]\*\*\FIX\*\*/', '<em class="fix">' . esc_html__( 'Fixed', 'booked' ) . '</em>', $readme);
  70. $readme = preg_replace( '/\*\*(.*?)\*\*/', '<strong>\\1</strong>', $readme);
  71. $readme = preg_replace( '/\*(.*?)\*/', '<em>\\1</em>', $readme);
  72. $readme = explode( '== Changelog ==', $readme );
  73. $readme = explode( '== Upgrade Notice ==', $readme[1] );
  74. $readme = $readme[0];
  75. $whats_new_title = '<h3>' . ( $title ? esc_html( $title ) : apply_filters( 'booked_whats_new_title', esc_html__( "What's new?", "booked" ) ) ) . '</h3>';
  76. $readme = preg_replace('/= (.*?) =/', $whats_new_title, $readme);
  77. $readme = preg_replace("/\*+(.*)?/i","<ul class='booked-whatsnew-list'><li>$1</li></ul>",$readme);
  78. $readme = preg_replace("/(\<\/ul\>\n(.*)\<ul class=\'booked-whatsnew-list\'\>*)+/","",$readme);
  79. $readme = explode( $whats_new_title, $readme );
  80. $readme = $whats_new_title . $readme[1];
  81. return $readme;
  82. }
  83. function booked_render_single_timeslot_form($timeslot_intervals,$type = false){
  84. ob_start();
  85. echo '<form id="single-timeslot-form" action="" method="post">';
  86. do_action( 'booked_single_timeslot_form_start' );
  87. echo booked_render_text_field('title', esc_html__('Title (optional)','booked'));
  88. echo booked_render_time_select('startTime',$timeslot_intervals,esc_html__('Start time ...','booked'),true);
  89. echo booked_render_time_select('endTime',$timeslot_intervals,esc_html__('End time ...','booked'));
  90. booked_render_count_select('count','How many?');
  91. do_action( 'booked_single_timeslot_form_end' );
  92. echo '</form>';
  93. $html = ob_get_clean();
  94. return $html;
  95. }
  96. function booked_render_bulk_timeslot_form($timeslot_intervals,$type = false){
  97. ob_start();
  98. echo '<form id="bulk-timeslot-form" action="" method="post">';
  99. do_action( 'booked_bulk_timeslot_form_start' );
  100. echo booked_render_text_field('title', esc_html__('Title (optional)','booked'));
  101. echo booked_render_time_select('startTime',$timeslot_intervals,esc_html__('Start time ...','booked'));
  102. echo booked_render_time_select('endTime',$timeslot_intervals,esc_html__('End time ...','booked'));
  103. booked_render_time_between_select('time_between',esc_html__('Time between ...','booked'));
  104. booked_render_interval_select('interval',esc_html__('Appt Length ...','booked'));
  105. booked_render_count_select('count',esc_html__('# of Each ...','booked'));
  106. do_action( 'booked_bulk_timeslot_form_end' );
  107. echo '</form>';
  108. $html = ob_get_clean();
  109. return $html;
  110. }
  111. function booked_render_time_select($select_name,$interval,$placeholder,$single = false){
  112. $time = 0;
  113. $interval = max(1, $interval);
  114. $time_format = get_option('time_format');
  115. $html = '<select name="'.$select_name.'">';
  116. $html .= '<option value="">'.$placeholder.'</option>';
  117. if ($single): $html .= '<option value="allday">'.esc_html__('All Day','booked').'</option>'; endif;
  118. do {
  119. $time_display = booked_convertTime($time);
  120. $html .= '<option value="'.date_i18n('Hi',strtotime('2014-01-01 '.$time_display)).'">'.date_i18n($time_format,strtotime('2014-01-01 '.$time_display)).'</option>';
  121. $time = $time + $interval;
  122. } while ($time < 1440);
  123. $html .= '<option value="2400">'.date_i18n($time_format,strtotime('2014-01-01 24:00')).' ('.esc_html__('night','booked').')</option>';
  124. $html .= '</select>';
  125. return apply_filters( 'booked_time_select_field', $html );
  126. }
  127. function booked_render_text_field($field_name,$placeholder){
  128. $html = '<input type="text" name="'.$field_name.'" placeholder="'.$placeholder.'" />';
  129. return apply_filters( 'booked_text_field', $html );
  130. }
  131. function booked_render_timeslots($calendar_id = false){
  132. if ($calendar_id):
  133. $booked_defaults = get_option('booked_defaults_'.$calendar_id);
  134. else :
  135. $booked_defaults = get_option('booked_defaults');
  136. endif;
  137. $time_format = get_option('time_format');
  138. $first_day_of_week = (get_option('start_of_week') == 0 ? 7 : 1);
  139. $day_loop = array(
  140. date_i18n( 'l', strtotime('Sunday') ),
  141. date_i18n( 'l', strtotime('Monday') ),
  142. date_i18n( 'l', strtotime('Tuesday') ),
  143. date_i18n( 'l', strtotime('Wednesday') ),
  144. date_i18n( 'l', strtotime('Thursday') ),
  145. date_i18n( 'l', strtotime('Friday') ),
  146. date_i18n( 'l', strtotime('Saturday') )
  147. );
  148. // Need to use the english three-letter day names to save settings properly
  149. $day_loop_english_array = array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
  150. if ($first_day_of_week == 1):
  151. $sunday_item = array_shift($day_loop); $day_loop[] = $sunday_item;
  152. $sunday_item_array = array_shift($day_loop_english_array); $day_loop_english_array[] = $sunday_item_array;
  153. endif;
  154. ?><table class="booked-timeslots"<?php echo ($calendar_id ? ' data-calendar-id="'.$calendar_id.'"' : ''); ?>>
  155. <tr>
  156. <?php foreach($day_loop as $key => $day): ?>
  157. <td>
  158. <table>
  159. <thead>
  160. <tr>
  161. <?php
  162. echo '<th data-day="'.$day_loop_english_array[$key].'">';
  163. echo '<div>' . $day . '</div>';
  164. echo '<a href="#" class="booked-clear-timeslots button">'.esc_html__('Clear','booked').'</a>';
  165. echo '<a href="#" class="booked-add-timeslot button">'.esc_html__('Add Timeslots','booked').'</a>';
  166. echo '</th>';
  167. ?>
  168. </tr>
  169. </thead>
  170. <tbody>
  171. <tr>
  172. <td data-day="<?php echo $day_loop_english_array[$key]; ?>" class="addTimeslot"></td>
  173. </tr>
  174. <tr>
  175. <?php echo '<td class="dayTimeslots" data-day="'.$day_loop_english_array[$key].'">';
  176. if (!empty($booked_defaults[$day_loop_english_array[$key]])):
  177. ksort($booked_defaults[$day_loop_english_array[$key]]);
  178. foreach($booked_defaults[$day_loop_english_array[$key]] as $time => $count):
  179. echo booked_render_timeslot_info($time_format,$day_loop_english_array[$key],$time,$count,$calendar_id,$booked_defaults);
  180. endforeach;
  181. else :
  182. echo '<p><small>'.esc_html__('No time slots.','booked').'</small></p>';
  183. endif;
  184. echo '</td>'; ?>
  185. </tr>
  186. </tbody>
  187. </table>
  188. </td>
  189. <?php endforeach; ?>
  190. </tr>
  191. </table><?php
  192. }
  193. function booked_render_timeslot_info($time_format,$day,$time,$count,$calendar_id,$booked_defaults=array()){
  194. $title = isset($booked_defaults[$day.'-details'][$time]['title']) ? $booked_defaults[$day.'-details'][$time]['title'] : '';
  195. ob_start();
  196. echo '<span class="timeslot" data-timeslot="'.$time.'">';
  197. $time = explode('-',$time);
  198. do_action( 'booked_single_timeslot_start', $day, $time, $calendar_id );
  199. if ($time[0] == '0000' && $time[1] == '2400'):
  200. $timeslotText = '<span class="start">' . strtoupper( esc_html__( 'All day', 'booked') ) . '</span>';
  201. else :
  202. $timeslotText = '<span class="start">' . date_i18n( $time_format, strtotime( '2014-01-01 ' . $time[0] ) ) . '</span> &ndash; <span class="end">'.date_i18n($time_format,strtotime('2014-01-01 '.$time[1])).'</span>';
  203. endif;
  204. echo $timeslotText;
  205. echo '<span class="slotsBlock">';
  206. echo '<span class="changeCount minus" data-count="-1"><i class="booked-icon booked-icon-minus-circle"></i></span>';
  207. echo '<span class="count"><em>'.$count.'</em> '._n('Space Available','Spaces Available',$count,'booked').'</span>';
  208. echo '<span class="changeCount add" data-count="1"><i class="booked-icon booked-icon-plus-circle"></i></span>';
  209. echo '</span>';
  210. if ( $title ) {
  211. echo '<span class="booked_slot_title">'.esc_html($title).'</span>';
  212. }
  213. echo '<span class="delete"><i class="booked-icon booked-icon-close"></i></span>';
  214. do_action( 'booked_single_timeslot_end', $day, $time, $calendar_id );
  215. echo '</span>';
  216. return ob_get_clean();
  217. }
  218. function booked_render_interval_select($select_name,$placeholder){
  219. ob_start();
  220. echo '<select name="'.$select_name.'">'; ?>
  221. <option value="60" selected><?php esc_html_e('Every 1 hour','booked'); ?></option>
  222. <option value="90"><?php esc_html_e('Every 1 hour, 30 minutes','booked'); ?></option>
  223. <option value="120"><?php esc_html_e('Every 2 hours','booked'); ?></option>
  224. <option value="45"><?php esc_html_e('Every 45 minutes','booked'); ?></option>
  225. <option value="30"><?php esc_html_e('Every 30 minutes','booked'); ?></option>
  226. <option value="20"><?php esc_html_e('Every 20 minutes','booked'); ?></option>
  227. <option value="15"><?php esc_html_e('Every 15 minutes','booked'); ?></option>
  228. <option value="10"><?php esc_html_e('Every 10 minutes','booked'); ?></option>
  229. <option value="5"><?php esc_html_e('Every 5 minutes','booked'); ?></option>
  230. <?php echo '</select>';
  231. echo apply_filters( 'booked_interval_select_field', ob_get_clean(), $select_name );
  232. }
  233. function booked_render_time_between_select($select_name,$placeholder){
  234. ob_start();
  235. echo '<select name="'.$select_name.'">'; ?>
  236. <option value="0" selected><?php echo $placeholder; ?></option>
  237. <option value="5"><?php esc_html_e('5 minutes','booked'); ?></option>
  238. <option value="10"><?php esc_html_e('10 minutes','booked'); ?></option>
  239. <option value="15"><?php esc_html_e('15 minutes','booked'); ?></option>
  240. <option value="20"><?php esc_html_e('20 minutes','booked'); ?></option>
  241. <option value="30"><?php esc_html_e('30 minutes','booked'); ?></option>
  242. <option value="45"><?php esc_html_e('45 minutes','booked'); ?></option>
  243. <option value="60"><?php esc_html_e('1 hour','booked'); ?></option>
  244. <?php echo '</select>';
  245. echo apply_filters( 'booked_time_between_select_field', ob_get_clean(), $select_name, $placeholder );
  246. }
  247. function booked_render_count_select($select_name,$placeholder){
  248. $total_spaces = 100;
  249. $counter = 0;
  250. echo '<select name="'.$select_name.'">';
  251. do {
  252. $counter++;
  253. echo '<option value="'.$counter.'"'.($counter == 1 ? ' selected="selected"' : '').'>'.sprintf(_n('%d space available','%d spaces available',$counter,'booked'),$counter).'</option>';
  254. } while ($counter < $total_spaces);
  255. echo '</select>';
  256. }
  257. function booked_admin_set_timezone(){
  258. $timezone_seconds = (int)get_site_option('gmt_offset') * 3600;
  259. $timezone_name = timezone_name_from_abbr(null, $timezone_seconds, true);
  260. date_default_timezone_set($timezone_name);
  261. }
  262. function booked_admin_calendar($year = false,$month = false,$calendar_id = false,$size = false){
  263. $local_time = current_time('timestamp');
  264. $year = ($year ? $year : date_i18n('Y',$local_time));
  265. $month = ($month ? $month : date_i18n('m',$local_time));
  266. $today = date_i18n('j',$local_time); // Defaults to current day
  267. $last_day = date_i18n('t',strtotime($year.'-'.$month));
  268. $monthShown = date_i18n($year.'-'.$month.'-01');
  269. $currentMonth = date_i18n('Y-m-01',$local_time);
  270. $first_day_of_week = (get_option('start_of_week') == 0 ? 7 : 1); // 1 = Monday, 7 = Sunday, Get from WordPress Settings
  271. $start_timestamp = strtotime($year.'-'.$month.'-01 00:00:00');
  272. $end_timestamp = strtotime($year.'-'.$month.'-'.$last_day.' 23:59:59');
  273. $args = array(
  274. 'post_type' => 'booked_appointments',
  275. 'posts_per_page' => -1,
  276. 'post_status' => 'any',
  277. 'meta_query' => array(
  278. array(
  279. 'key' => '_appointment_timestamp',
  280. 'value' => array( $start_timestamp, $end_timestamp ),
  281. 'compare' => 'BETWEEN',
  282. )
  283. )
  284. );
  285. if ($calendar_id):
  286. $args['tax_query'] = array(
  287. array(
  288. 'taxonomy' => 'booked_custom_calendars',
  289. 'field' => 'term_id',
  290. 'terms' => $calendar_id,
  291. )
  292. );
  293. endif;
  294. $bookedAppointments = new WP_Query($args);
  295. if($bookedAppointments->have_posts()):
  296. while ($bookedAppointments->have_posts()):
  297. $bookedAppointments->the_post();
  298. global $post;
  299. $timestamp = get_post_meta($post->ID, '_appointment_timestamp',true);
  300. $day = date_i18n('j',$timestamp);
  301. $appointments_array[$day][$post->ID]['timestamp'] = $timestamp;
  302. $appointments_array[$day][$post->ID]['status'] = $post->post_status;
  303. endwhile;
  304. $appointments_array = apply_filters('booked_appointments_day_array', $appointments_array);
  305. endif;
  306. // Appointments Array
  307. // [DAY] => [POST_ID] => [TIMESTAMP/STATUS]
  308. if ($calendar_id):
  309. $calendar_name = get_term_by('id',$calendar_id,'booked_custom_calendars');
  310. $calendar_name = $calendar_name->name;
  311. else :
  312. $calendar_name = false;
  313. endif;
  314. $hide_weekends = get_option('booked_hide_weekends',false);
  315. ?><table class="booked-calendar<?php echo ($size ? ' '.$size : ''); ?>"<?php echo ($calendar_id ? ' data-calendar-id="'.$calendar_id.'"' : ''); ?> data-monthShown="<?php echo $monthShown; ?>">
  316. <thead>
  317. <tr>
  318. <th colspan="<?php if (!$hide_weekends): ?>7<?php else: ?>5<?php endif; ?>">
  319. <a href="#" data-goto="<?php echo date_i18n('Y-m-01', strtotime("-1 month", strtotime($year.'-'.$month.'-01'))); ?>" class="page-left"><i class="booked-icon booked-icon-angle-left"></i></a>
  320. <span class="calendarSavingState">
  321. <i class="booked-icon booked-icon-spinner-clock booked-icon-spin"></i>
  322. </span>
  323. <span class="monthName">
  324. <?php if ($monthShown != $currentMonth): ?>
  325. <a href="#" class="backToMonth" data-goto="<?php echo $currentMonth; ?>"><i class="booked-icon booked-icon-arrow-left"></i>&nbsp;&nbsp;&nbsp;<?php esc_html_e('Back to','booked'); ?> <?php echo date_i18n('F',strtotime($currentMonth)); ?></a>
  326. <?php endif; ?>
  327. <?php echo date_i18n("F Y", strtotime($year.'-'.$month.'-01')); ?>
  328. <?php if ($calendar_name): ?>
  329. <span class="calendarName"><i class="booked-icon booked-icon-calendar"></i>&nbsp;&nbsp;&nbsp;<?php echo $calendar_name; ?></span>
  330. <?php endif; ?>
  331. </span>
  332. <a href="#" data-goto="<?php echo date_i18n('Y-m-01', strtotime("+1 month", strtotime($year.'-'.$month.'-01'))); ?>" class="page-right"><i class="booked-icon booked-icon-angle-right"></i></a>
  333. </th>
  334. </tr>
  335. <tr class="days">
  336. <?php if ($first_day_of_week == 7 && !$hide_weekends): echo '<th>' . date_i18n( 'D', strtotime('Sunday') ) . '</th>'; endif; ?>
  337. <th><?php echo date_i18n( 'D', strtotime('Monday') ); ?></th>
  338. <th><?php echo date_i18n( 'D', strtotime('Tuesday') ); ?></th>
  339. <th><?php echo date_i18n( 'D', strtotime('Wednesday') ); ?></th>
  340. <th><?php echo date_i18n( 'D', strtotime('Thursday') ); ?></th>
  341. <th><?php echo date_i18n( 'D', strtotime('Friday') ); ?></th>
  342. <?php if (!$hide_weekends): ?><th><?php echo date_i18n( 'D', strtotime('Saturday') ); ?></th><?php endif; ?>
  343. <?php if ($first_day_of_week == 1 && !$hide_weekends): echo '<th>'. date_i18n( 'D', strtotime('Sunday') ) .'</th>'; endif; ?>
  344. </tr>
  345. </thead>
  346. <tbody><?php
  347. $today_date = date_i18n('Y',$local_time).'-'.date_i18n('m',$local_time).'-'.date_i18n('j',$local_time);
  348. $days = date_i18n("t",strtotime($year.'-'.$month.'-01')); // Days in current month
  349. $lastmonth = date_i18n("t", mktime(0,0,0,$month-1,1,$year)); // Days in previous month
  350. $start = date_i18n("N", mktime(0,0,0,$month,1,$year)); // Starting day of current month
  351. if ($first_day_of_week == 7): $start = $start + 1; endif;
  352. if ($start > 7): $start = 1; endif;
  353. $finish = $days; // Finishing day of current month
  354. $laststart = $start - 1; // Days of previous month in calander
  355. $counter = 1;
  356. $nextMonthCounter = 1;
  357. if ($calendar_id):
  358. $booked_defaults = get_option('booked_defaults_'.$calendar_id);
  359. if (!$booked_defaults):
  360. $booked_defaults = get_option('booked_defaults');
  361. endif;
  362. else :
  363. $booked_defaults = get_option('booked_defaults');
  364. endif;
  365. $booked_defaults = booked_apply_custom_timeslots_filter($booked_defaults,$calendar_id);
  366. if($start > 5){ $rows = 6; } else { $rows = 5; }
  367. for($i = 1; $i <= $rows; $i++){
  368. echo '<tr class="week">';
  369. $day_count = 0;
  370. for($x = 1; $x <= 7; $x++){
  371. $classes = array();
  372. $appointments_count = 0;
  373. if(($counter - $start) < 0){
  374. $date = (($lastmonth - $laststart) + $counter);
  375. $classes[] = 'blur';
  376. $check_month = $month - 1;
  377. } else if(($counter - $start) >= $days){
  378. $date = $nextMonthCounter;
  379. $nextMonthCounter++;
  380. $classes[] = 'blur';
  381. $check_month = $month + 1;
  382. if ($day_count == 0): break; endif;
  383. } else {
  384. $check_month = $month;
  385. $date = ($counter - $start + 1);
  386. if($today == $counter - $start + 1){
  387. if ($today_date == $year.'-'.$month.'-'.$date):
  388. $classes[] = 'today';
  389. endif;
  390. }
  391. $day_name = date('D',strtotime($year.'-'.$month.'-'.$date));
  392. $full_count = (isset($booked_defaults[$day_name]) && !empty($booked_defaults[$day_name]) ? $booked_defaults[$day_name] : false);
  393. $total_full_count = 0;
  394. if ($full_count):
  395. foreach($full_count as $full_counter){
  396. $total_full_count = $total_full_count + $full_counter;
  397. }
  398. endif;
  399. if (isset($appointments_array[$date]) && !empty($appointments_array[$date])):
  400. $appointments_count = count($appointments_array[$date]);
  401. if ($appointments_count > 0 && $appointments_count < $total_full_count): $classes[] = 'partial';
  402. elseif ($appointments_count >= $total_full_count): $classes[] = 'booked'; endif;
  403. endif;
  404. }
  405. $check_year = $year;
  406. if ($check_month == 0):
  407. $check_month = 12;
  408. $check_year = $year - 1;
  409. elseif ($check_month == 13):
  410. $check_month = 1;
  411. $check_year = $year + 1;
  412. endif;
  413. $day_of_week = date_i18n('N',strtotime($check_year.'-'.$check_month.'-'.$date));
  414. if ($hide_weekends && $day_of_week == 6 || $hide_weekends && $day_of_week == 7):
  415. $html = '';
  416. else:
  417. $day_count++;
  418. echo '<td data-date="'.$check_year.'-'.$check_month.'-'.$date.'" class="'.implode(' ',$classes).'">';
  419. echo '<span class="date'.($appointments_count > 0 ? ' tooltip' : '').'" '.($appointments_count > 0 ? ' title="'.sprintf(_n('%d Appointment','%d Appointments',$appointments_count,'booked'),$appointments_count).'"' : '').'><span class="number">'. $date . '</span></span>';
  420. echo '</td>';
  421. endif;
  422. $counter++;
  423. $class = '';
  424. }
  425. echo '</tr>';
  426. } ?>
  427. </tbody>
  428. </table><?php
  429. }
  430. function booked_admin_calendar_date_content($date,$calendar_id = false){
  431. $calendars = get_terms('booked_custom_calendars','orderby=slug&hide_empty=0');
  432. $booked_current_user = wp_get_current_user();
  433. if (!empty($calendars)):
  434. $tabbed = true;
  435. if (!current_user_can('manage_booked_options')):
  436. $calendars = booked_filter_agent_calendars($booked_current_user,$calendars);
  437. endif;
  438. else :
  439. $tabbed = false;
  440. endif;
  441. echo '<div class="booked-appt-list">';
  442. $time_format = get_option('time_format');
  443. $date_format = get_option('date_format');
  444. /*
  445. Grab all of the appointments for this day
  446. */
  447. if ($tabbed):
  448. ?><ul id="bookedAppointmentTabs" class="bookedClearFix">
  449. <?php // Show the Default calendar to admins, not booking agents
  450. $is_first_tab = true;
  451. if ( !get_option('booked_hide_default_calendar') && current_user_can('manage_booked_options') ):
  452. $calendars = get_terms('booked_custom_calendars','orderby=slug&hide_empty=0');
  453. $appointments_in_tab = booked_get_admin_appointments($date,$time_format,$date_format,'default',false,$calendars);
  454. $total_appointments = (!empty($appointments_in_tab) ? count($appointments_in_tab) : 0);
  455. ?><li<?php if (!$calendar_id): ?> class="active"<?php endif; ?>><a href="#calendar-default"><?php esc_html_e('Default Calendar','booked'); ?><?php echo ($total_appointments ? '<span>'.$total_appointments.'</span>' : ''); ?></a></li><?php
  456. $is_first_tab = false;
  457. endif;
  458. foreach($calendars as $calendar):
  459. $appointments_in_tab = booked_get_admin_appointments($date,$time_format,$date_format,$calendar->term_id);
  460. $total_appointments = (!empty($appointments_in_tab) ? count($appointments_in_tab) : 0);
  461. ?><li<?php if ( $calendar_id == $calendar->term_id || !$calendar_id && $is_first_tab ): ?> class="active"<?php endif; ?>><a href="#calendar-<?php echo $calendar->term_id; ?>"><?php echo $calendar->name; ?><?php echo ($total_appointments ? '<span>'.$total_appointments.'</span>' : ''); ?></a></li><?php
  462. $is_first_tab = false;
  463. endforeach;
  464. ?></ul><?php
  465. $tab_title = esc_html__('Appointments for','booked');
  466. $is_first_tab = true;
  467. if ( !get_option('booked_hide_default_calendar') && current_user_can('manage_booked_options') ):
  468. ?><div id="bookedCalendarAppointmentsTab-default" class="bookedAppointmentTab<?php if (!$calendar_id): ?> active<?php endif; ?>"><?php
  469. booked_admin_calendar_date_loop($date,$time_format,$date_format,false,$tab_title,$tabbed,$calendars);
  470. ?></div><?php
  471. $is_first_tab = false;
  472. endif;
  473. foreach($calendars as $calendar):
  474. ?><div id="bookedCalendarAppointmentsTab-<?php echo $calendar->term_id; ?>" class="bookedAppointmentTab<?php if ( $calendar_id == $calendar->term_id || !$calendar_id && $is_first_tab): ?> active<?php endif; ?>"><?php
  475. $display_calendar_id = $calendar->term_id;
  476. $tab_title = sprintf(esc_html__('%s Appointments for','booked'),'<strong>'.$calendar->name.'</strong>');
  477. booked_admin_calendar_date_loop($date,$time_format,$date_format,$display_calendar_id,$tab_title,$tabbed,$calendars);
  478. ?></div><?php
  479. $is_first_tab = false;
  480. endforeach;
  481. else :
  482. $tab_title = esc_html__('Appointments for','booked');
  483. booked_admin_calendar_date_loop($date,$time_format,$date_format,$calendar_id,$tab_title,false,$calendars);
  484. endif;
  485. echo '</div>';
  486. }
  487. function booked_get_admin_appointments($date,$time_format,$date_format,$calendar_id = false,$tabbed = false,$calendars = false){
  488. $year = date_i18n('Y',strtotime($date));
  489. $month = date_i18n('m',strtotime($date));
  490. $day = date_i18n('d',strtotime($date));
  491. $start_timestamp = strtotime( $year.'-'.$month.'-'.$day.' 00:00:00' );
  492. $end_timestamp = strtotime( $year.'-'.$month.'-'.$day.' 23:59:59' );
  493. $args = array(
  494. 'post_type' => 'booked_appointments',
  495. 'posts_per_page' => -1,
  496. 'post_status' => 'any',
  497. 'meta_query' => array(
  498. array(
  499. 'key' => '_appointment_timestamp',
  500. 'value' => array( $start_timestamp, $end_timestamp ),
  501. 'compare' => 'BETWEEN'
  502. )
  503. )
  504. );
  505. if ($calendar_id && $calendar_id != 'default'):
  506. $args['tax_query'] = array(
  507. array(
  508. 'taxonomy' => 'booked_custom_calendars',
  509. 'field' => 'term_id',
  510. 'terms' => $calendar_id,
  511. )
  512. );
  513. elseif (!$calendar_id && $tabbed && !empty($calendars) || $calendar_id = 'default'):
  514. $not_in_calendar = array();
  515. foreach($calendars as $calendar_term){
  516. $not_in_calendar[] = $calendar_term->term_id;
  517. }
  518. $args['tax_query'] = array(
  519. array(
  520. 'taxonomy' => 'booked_custom_calendars',
  521. 'field' => 'term_id',
  522. 'terms' => $not_in_calendar,
  523. 'include_children' => false,
  524. 'operator' => 'NOT IN'
  525. )
  526. );
  527. endif;
  528. $appointments_array = array();
  529. $bookedAppointments = new WP_Query($args);
  530. if($bookedAppointments->have_posts()):
  531. while ($bookedAppointments->have_posts()):
  532. $bookedAppointments->the_post();
  533. global $post;
  534. $timestamp = get_post_meta($post->ID, '_appointment_timestamp',true);
  535. $timeslot = get_post_meta($post->ID, '_appointment_timeslot',true);
  536. $day = date_i18n('d',$timestamp);
  537. $guest_name = get_post_meta($post->ID, '_appointment_guest_name',true);
  538. $guest_surname = get_post_meta($post->ID, '_appointment_guest_surname',true);
  539. $guest_email = get_post_meta($post->ID, '_appointment_guest_email',true);
  540. $appointments_array[$post->ID]['post_id'] = $post->ID;
  541. $appointments_array[$post->ID]['timestamp'] = $timestamp;
  542. $appointments_array[$post->ID]['timeslot'] = $timeslot;
  543. $appointments_array[$post->ID]['status'] = $post->post_status;
  544. if (!$guest_name):
  545. $user_id = get_post_meta($post->ID, '_appointment_user',true);
  546. $appointments_array[$post->ID]['user'] = $user_id;
  547. else:
  548. $appointments_array[$post->ID]['guest_name'] = $guest_name;
  549. $appointments_array[$post->ID]['guest_surname'] = $guest_surname;
  550. $appointments_array[$post->ID]['guest_email'] = $guest_email;
  551. endif;
  552. endwhile;
  553. $appointments_array = apply_filters('booked_appointments_array', $appointments_array);
  554. endif;
  555. return $appointments_array;
  556. }
  557. function booked_admin_calendar_date_loop($date,$time_format,$date_format,$calendar_id = false,$tab_title,$tabbed = false,$calendars = false){
  558. $year = date_i18n('Y',strtotime($date));
  559. $month = date_i18n('m',strtotime($date));
  560. $day = date_i18n('d',strtotime($date));
  561. $date_display = date_i18n($date_format,strtotime($date));
  562. $day_name = date('D',strtotime($date));
  563. $appointments_array = booked_get_admin_appointments($date,$time_format,$date_format,$calendar_id,$tabbed,$calendars);
  564. /*
  565. Start the list
  566. */
  567. do_action( 'booked_admin_calendar_date_loop_before_title', $date, $calendar_id );
  568. echo '<h2>'.$tab_title.' <strong>'.$date_display.'</strong></h2>';
  569. do_action( 'booked_admin_calendar_date_loop_after_title', $date, $calendar_id );
  570. /*
  571. Get today's default timeslots
  572. */
  573. if ($calendar_id):
  574. $booked_defaults = get_option('booked_defaults_'.$calendar_id);
  575. if (!$booked_defaults):
  576. $booked_defaults = get_option('booked_defaults');
  577. endif;
  578. else :
  579. $booked_defaults = get_option('booked_defaults');
  580. endif;
  581. $formatted_date = date_i18n('Ymd',strtotime($date));
  582. $booked_defaults = booked_apply_custom_timeslots_details_filter($booked_defaults,$calendar_id);
  583. if (isset($booked_defaults[$formatted_date]) && !empty($booked_defaults[$formatted_date])):
  584. $todays_defaults = (is_array($booked_defaults[$formatted_date]) ? $booked_defaults[$formatted_date] : json_decode(html_entity_decode($booked_defaults[$formatted_date]),true));
  585. $todays_defaults_details = (is_array($booked_defaults[$formatted_date.'-details']) ? $booked_defaults[$formatted_date.'-details'] : json_decode(html_entity_decode($booked_defaults[$formatted_date.'-details']),true));
  586. elseif (isset($booked_defaults[$formatted_date]) && empty($booked_defaults[$formatted_date])):
  587. $todays_defaults = false;
  588. $todays_defaults_details = false;
  589. elseif (isset($booked_defaults[$day_name]) && !empty($booked_defaults[$day_name])):
  590. $todays_defaults = $booked_defaults[$day_name];
  591. $todays_defaults_details = ( isset($booked_defaults[$day_name]) ? $booked_defaults[$day_name.'-details'] : false );
  592. else :
  593. $todays_defaults = false;
  594. $todays_defaults_details = false;
  595. endif;
  596. /*
  597. There are timeslots available, let's loop through them
  598. */
  599. if ($todays_defaults){
  600. ksort($todays_defaults);
  601. foreach($todays_defaults as $timeslot => $count):
  602. $appts_in_this_timeslot = array();
  603. /*
  604. Are there any appointments in this particular timeslot?
  605. If so, let's create an array of them.
  606. */
  607. foreach($appointments_array as $post_id => $appointment):
  608. if ($appointment['timeslot'] == $timeslot):
  609. $appts_in_this_timeslot[] = $post_id;
  610. endif;
  611. endforeach;
  612. /*
  613. Calculate the number of spots available based on total minus the appointments booked
  614. */
  615. $spots_available = $count - count($appts_in_this_timeslot);
  616. $spots_available = ($spots_available < 0 ? $spots_available = 0 : $spots_available = $spots_available);
  617. /*
  618. Display the timeslot
  619. */
  620. $timeslot_parts = explode('-',$timeslot);
  621. $current_timestamp = current_time('timestamp');
  622. $this_timeslot_timestamp = strtotime($year.'-'.$month.'-'.$day.' '.$timeslot_parts[0]);
  623. if ($current_timestamp < $this_timeslot_timestamp){
  624. $available = true;
  625. } else {
  626. $available = false;
  627. }
  628. if ($timeslot_parts[0] == '0000' && $timeslot_parts[1] == '2400'):
  629. $timeslotText = esc_html__('All day','booked');
  630. else :
  631. $timeslotText = date_i18n($time_format,strtotime($timeslot_parts[0])).' &ndash; '.date_i18n($time_format,strtotime($timeslot_parts[1]));
  632. endif;
  633. $title = '';
  634. if ( !empty( $todays_defaults_details[$timeslot] ) ) {
  635. $title = !empty($todays_defaults_details[$timeslot]['title']) ? $todays_defaults_details[$timeslot]['title'] : '';
  636. }
  637. $is_disabled = booked_is_timeslot_disabled( $date,$timeslot,$calendar_id );
  638. echo '<div class="timeslot bookedClearFix' . ( $title ? ' has-title ' : '' ) . ( $is_disabled ? ' booked-disabled' : '' ) . '">';
  639. echo '<span class="timeslot-time">';
  640. if ( $title ) {
  641. echo '<span class="timeslot-title">' . esc_html($title) . '</span><br>';
  642. }
  643. echo '<i class="booked-icon booked-icon-clock"></i>&nbsp;&nbsp;'.$timeslotText.'</span>';
  644. echo '<span class="timeslot-count">';
  645. do_action('booked_single_timeslot_in_list_start', $this_timeslot_timestamp, $timeslot, $calendar_id);
  646. echo '<span class="spots-available'.($spots_available == 0 ? ' empty' : '').'">'.$spots_available.' '._n('space','spaces',$spots_available,'booked').' '.esc_html__('available','booked').'</span>';
  647. /*
  648. Display the appointments set in this timeslot
  649. */
  650. if (!empty($appts_in_this_timeslot)):
  651. $booked_appts = count($appts_in_this_timeslot);
  652. echo '<strong>'. sprintf( esc_html( _n('%d Appointment','%d Appointments',$booked_appts,'booked') ), $booked_appts ) . ':</strong>';
  653. foreach($appts_in_this_timeslot as $appt_id):
  654. if (!isset($appointments_array[$appt_id]['guest_name'])):
  655. $user_info = get_userdata($appointments_array[$appt_id]['user']);
  656. if (isset($user_info->ID)):
  657. if ($user_info->user_firstname):
  658. $user_display = '<a href="#" class="user" data-user-id="'.$appointments_array[$appt_id]['user'].'"><i class="booked-icon booked-icon-pencil"></i>&nbsp;'.$user_info->user_firstname.($user_info->user_lastname ? ' '.$user_info->user_lastname : '').'</a>';
  659. elseif ($user_info->display_name):
  660. $user_display = '<a href="#" class="user" data-user-id="'.$appointments_array[$appt_id]['user'].'"><i class="booked-icon booked-icon-pencil"></i>&nbsp;'.$user_info->display_name.'</a>';
  661. else :
  662. $user_display = '<a href="#" class="user" data-user-id="'.$appointments_array[$appt_id]['user'].'"><i class="booked-icon booked-icon-pencil"></i>&nbsp;'.$user_info->user_login.'</a>';
  663. endif;
  664. else :
  665. $user_display = esc_html__('(this user no longer exists)','booked');
  666. endif;
  667. else :
  668. $user_display = '<a href="#" class="user" data-user-id="0"><i class="booked-icon booked-icon-pencil"></i>&nbsp;'.$appointments_array[$appt_id]['guest_name'].' '.$appointments_array[$appt_id]['guest_surname'].'</a>';
  669. endif;
  670. $status = ($appointments_array[$appt_id]['status'] !== 'publish' && $appointments_array[$appt_id]['status'] !== 'future' ? 'pending' : 'approved');
  671. echo '<span class="appt-block" data-appt-id="'.$appt_id.'">';
  672. echo $user_display;
  673. do_action('booked_admin_calendar_buttons_before', $calendar_id, $appt_id, $status);
  674. if ( apply_filters('booked_admin_show_calendar_buttons', true) ) {
  675. echo '<a href="#" class="delete"'.($calendar_id ? ' data-calendar-id="'.$calendar_id.'"' : '').'><i class="booked-icon booked-icon-close"></i></a>'.($status == 'pending' ? '<button data-appt-id="'.$appt_id.'" class="approve button button-primary">'.esc_html__('Approve','booked').'</button>' : '');
  676. }
  677. do_action('booked_admin_calendar_buttons_after', $calendar_id, $appt_id, $status);
  678. echo '</span>';
  679. unset($appointments_array[$appt_id]);
  680. endforeach;
  681. endif;
  682. do_action('booked_single_timeslot_in_list_end',$this_timeslot_timestamp,$timeslot,$calendar_id);
  683. echo '</span>';
  684. echo '<span class="timeslot-people">';
  685. echo '<button data-timeslot="'.$timeslot.'" data-title="'.esc_attr($title).'" data-date="'.$date.'"'.($calendar_id ? ' data-calendar-id="'.$calendar_id.'"' : '').' class="new-appt button button-primary"'.(!$spots_available ? ' disabled' : '').'>'.esc_html__('New Appointment','booked').'</button>';
  686. echo ( empty($appts_in_this_timeslot) ? '<button data-timeslot="'.$timeslot.'" data-title="'.esc_attr($title).'" data-date="'.$date.'"'.($calendar_id ? ' data-calendar-id="'.$calendar_id.'"' : '').' class="disable-slot button"'.(!$spots_available ? ' disabled' : '').'>' . ( $is_disabled ? esc_html__('Enable','booked') : esc_html__('Disable','booked') ) . '</button>' : '' );
  687. echo '</span>';
  688. echo '</div>';
  689. endforeach;
  690. /*
  691. Are there any additional appointments for this day that are not in the default timeslots?
  692. */
  693. if (!empty($appointments_array)):
  694. echo '<span class="additional-timeslots">';
  695. echo '<br><p>'.esc_html__('There are additional appointments booked from previously available time slots:','booked').'</p>';
  696. foreach($appointments_array as $appointment):
  697. if (!isset($appointment['guest_name'])):
  698. $user_info = get_userdata($appointment['user']);
  699. if (isset($user_info->ID)):
  700. if ($user_info->user_firstname):
  701. $user_display = '<a href="#" class="user" data-user-id="'.$appointment['user'].'">'.$user_info->user_firstname.($user_info->user_lastname ? ' '.$user_info->user_lastname : '').'</a>';
  702. elseif ($user_info->display_name):
  703. $user_display = '<a href="#" class="user" data-user-id="'.$appointment['user'].'">'.$user_info->display_name.'</a>';
  704. else :
  705. $user_display = '<a href="#" class="user" data-user-id="'.$appointment['user'].'">'.$user_info->user_login.'</a>';
  706. endif;
  707. else :
  708. $user_display = esc_html__('(this user no longer exists)','booked');
  709. endif;
  710. else :
  711. $user_display = '<a href="#" class="user" data-user-id="0">'.$appointment['guest_name'].' '.$appointment['guest_surname'].'</a>';
  712. endif;
  713. $status = ($appointment['status'] !== 'publish' && $appointment['status'] !== 'future' ? 'pending' : 'approved');
  714. $timeslot = explode('-',$appointment['timeslot']);
  715. echo '<div class="timeslot bookedClearFix" data-appt-id="'.$appointment['post_id'].'">';
  716. echo '<span class="timeslot-time">'.date_i18n($time_format,strtotime($timeslot[0])).' &ndash; '.date_i18n($time_format,strtotime($timeslot[1])).'</span>';
  717. echo '<span class="timeslot-count count-wide">';
  718. echo '<span class="appt-block appt-no-padding" data-appt-id="'.$appointment['post_id'].'">';
  719. echo $user_display;
  720. do_action('booked_admin_calendar_buttons_before', $calendar_id, $appt_id, $status);
  721. if ( apply_filters('booked_admin_show_calendar_buttons', true) ) {
  722. echo '<a href="#" class="delete"'.($calendar_id ? ' data-calendar-id="'.$calendar_id.'"' : '').'><i class="booked-icon booked-icon-close"></i></a>'.($status == 'pending' ? '<button data-appt-id="'.$appt_id.'" class="approve button button-primary">'.esc_html__('Approve','booked').'</button>' : '');
  723. }
  724. do_action('booked_admin_calendar_buttons_after', $calendar_id, $appt_id, $status);
  725. echo '</span>';
  726. echo '</span>';
  727. echo '</div>';
  728. endforeach;
  729. echo '</span>';
  730. endif;
  731. /*
  732. There are no default timeslots, however there are appointments booked.
  733. */
  734. } else if (!$todays_defaults && !empty($appointments_array)) {
  735. echo '<span class="additional-timeslots">';
  736. echo '<p>'.esc_html__('There are no appointment slots available for this day, however there are appointments booked from previously available time slots:','booked').'</p>';
  737. foreach($appointments_array as $appointment):
  738. if (!isset($appointment['guest_name'])):
  739. $user_info = get_userdata($appointment['user']);
  740. if (isset($user_info->ID)):
  741. if ($user_info->user_firstname):
  742. $user_display = '<a href="#" class="user" data-user-id="'.$appointment['user'].'">'.$user_info->user_firstname.($user_info->user_lastname ? ' '.$user_info->user_lastname : '').'</a>';
  743. elseif ($user_info->display_name):
  744. $user_display = '<a href="#" class="user" data-user-id="'.$appointment['user'].'">'.$user_info->display_name.'</a>';
  745. else :
  746. $user_display = '<a href="#" class="user" data-user-id="'.$appointment['user'].'">'.$user_info->user_login.'</a>';
  747. endif;
  748. else :
  749. $user_display = esc_html__('(this user no longer exists)','booked');
  750. endif;
  751. else :
  752. $user_display = '<a href="#" class="user" data-user-id="0">'.$appointment['guest_name'].' '.$appointment['guest_surname'].'</a>';
  753. endif;
  754. $status = ($appointment['status'] !== 'publish' && $appointment['status'] !== 'future' ? 'pending' : 'approved');
  755. $timeslot = explode('-',$appointment['timeslot']);
  756. echo '<div class="timeslot bookedClearFix" data-appt-id="'.$appointment['post_id'].'">';
  757. echo '<span class="timeslot-time">'.date_i18n($time_format,strtotime($timeslot[0])).' &ndash; '.date_i18n($time_format,strtotime($timeslot[1])).'</span>';
  758. echo '<span class="timeslot-count count-wide">';
  759. echo '<span class="appt-block appt-no-padding" data-appt-id="'.$appointment['post_id'].'">';
  760. echo $user_display;
  761. do_action('booked_admin_calendar_buttons_before', $calendar_id, $appt_id, $status);
  762. if ( apply_filters('booked_admin_show_calendar_buttons', true) ) {
  763. echo '<a href="#" class="delete"'.($calendar_id ? ' data-calendar-id="'.$calendar_id.'"' : '').'><i class="booked-icon booked-icon-close"></i></a>'.($status == 'pending' ? '<button data-appt-id="'.$appt_id.'" class="approve button button-primary">'.esc_html__('Approve','booked').'</button>' : '');
  764. }
  765. do_action('booked_admin_calendar_buttons_after', $calendar_id, $appt_id, $status);
  766. echo '</span>';
  767. echo '</span>';
  768. echo '</div>';
  769. endforeach;
  770. echo '</span>';
  771. /*
  772. There are no default timeslots and no appointments booked for this particular day.
  773. */
  774. } else {
  775. echo '<p>'.esc_html__('There are no appointment time slots available for this day.','booked').' <a href="'.get_admin_url(null,'admin.php?page=booked-settings#defaults').'">'.esc_html__('Would you like to add some?','booked').'</a></p>';
  776. }
  777. do_action( 'booked_admin_calendar_date_loop_after_loop', $date, $calendar_id );
  778. }
  779. function booked_admin_calendar_date_square($date,$calendar_id = false){
  780. $local_time = current_time('timestamp');
  781. $year = date_i18n('Y',strtotime($date));
  782. $month = date_i18n('m',strtotime($date));
  783. $this_day = date_i18n('j',strtotime($date)); // Defaults to current day
  784. $last_day = date_i18n('t',strtotime($year.'-'.$month));
  785. $monthShown = date_i18n('Y-m-d',strtotime($year.'-'.$month.'-01'));
  786. $currentMonth = date_i18n('Y-m-01',$local_time);
  787. $first_day_of_week = (get_option('start_of_week') == 0 ? 7 : 1); // 1 = Monday, 7 = Sunday, Get from WordPress Settings
  788. $start_timestamp = strtotime($year.'-'.$month.'-01 00:00:00');
  789. $end_timestamp = strtotime($year.'-'.$month.'-'.$last_day.' 23:59:59');
  790. if ($calendar_id):
  791. $booked_defaults = get_option('booked_defaults_'.$calendar_id);
  792. if (!$booked_defaults):
  793. $booked_defaults = get_option('booked_defaults');
  794. endif;
  795. else :
  796. $booked_defaults = get_option('booked_defaults');
  797. endif;
  798. $args = array(
  799. 'post_type' => 'booked_appointments',
  800. 'posts_per_page' => -1,
  801. 'meta_query' => array(
  802. array(
  803. 'key' => '_appointment_timestamp',
  804. 'value' => array( $start_timestamp, $end_timestamp ),
  805. 'compare' => 'BETWEEN',
  806. )
  807. )
  808. );
  809. if ($calendar_id):
  810. $args['tax_query'] = array(
  811. array(
  812. 'taxonomy' => 'booked_custom_calendars',
  813. 'field' => 'term_id',
  814. 'terms' => $calendar_id,
  815. )
  816. );
  817. endif;
  818. $bookedAppointments = new WP_Query($args);
  819. if($bookedAppointments->have_posts()):
  820. while ($bookedAppointments->have_posts()):
  821. $bookedAppointments->the_post();
  822. global $post;
  823. $timestamp = get_post_meta($post->ID, '_appointment_timestamp',true);
  824. $day = date_i18n('j',$timestamp);
  825. $appointments_array[$day][$post->ID]['timestamp'] = $timestamp;
  826. $appointments_array[$day][$post->ID]['status'] = $post->post_status;
  827. endwhile;
  828. $appointments_array = apply_filters('booked_appointments_day_array', $appointments_array);
  829. endif;
  830. if ( !isset($_POST['inactive']) ):
  831. $classes[] = 'active';
  832. endif;
  833. $today_date = date_i18n('Y').'-'.date_i18n('m').'-'.date_i18n('j');
  834. if ($today_date == $_POST['date']):
  835. $classes[] = 'today';
  836. endif;
  837. $day_name = date('D',strtotime($date));
  838. $full_count = (isset($booked_defaults[$day_name]) && !empty($booked_defaults[$day_name]) ? $booked_defaults[$day_name] : false);
  839. $total_full_count = 0;
  840. if ($full_count):
  841. foreach($full_count as $full_counter){
  842. $total_full_count = $total_full_count + $full_counter;
  843. }
  844. endif;
  845. if (isset($appointments_array[$this_day]) && !empty($appointments_array[$this_day])):
  846. $appointments_count = count($appointments_array[$this_day]);
  847. if ($appointments_count > 0 && $appointments_count < $total_full_count): $classes[] = 'partial';
  848. elseif ($appointments_count >= $total_full_count): $classes[] = 'booked'; endif;
  849. endif;
  850. echo '<td data-date="'.$date.'" class="'.implode(' ',$classes).'">';
  851. echo '<span class="date'.(isset($appointments_count) && $appointments_count > 0 ? ' tooltip' : '').'"'.(isset($appointments_count) && $appointments_count > 0 ? ' title="'.sprintf(_n('%d Appointment','%d Appointments',$appointments_count,'booked'),$appointments_count).'"' : '').'><span class="number">'. $this_day . '</span></span>';
  852. echo '</td>';
  853. }
  854. function booked_render_custom_fields($calendar = false){
  855. ?><form id="booked-cf-sortables-form">
  856. <ul id="booked-cf-sortables"><?php
  857. if (!$calendar):
  858. $custom_fields = json_decode(stripslashes(get_option('booked_custom_fields')),true);
  859. else:
  860. $custom_fields = json_decode(stripslashes(get_option('booked_custom_fields_'.$calendar)),true);
  861. endif;
  862. if (!empty($custom_fields)):
  863. $look_for_subs = false;
  864. foreach($custom_fields as $field):
  865. if ($look_for_subs):
  866. $field_type = explode('---',$field['name']);
  867. $field_type = $field_type[0];
  868. if ($field_type == 'single-checkbox'):
  869. ?><li class="ui-state-default"><i class="sub-handle booked-icon booked-icon-bars"></i>
  870. <input type="text" name="<?php echo $field['name']; ?>" value="<?php echo htmlentities($field['value'], ENT_QUOTES | ENT_IGNORE, "UTF-8"); ?>" placeholder="<?php esc_html_e('Enter a label for this checkbox...','booked'); ?>" />
  871. <span class="cf-delete"><i class="booked-icon booked-icon-close"></i></span>
  872. </li><?php
  873. elseif ($field_type == 'single-radio-button'):
  874. ?><li class="ui-state-default"><i class="sub-handle booked-icon booked-icon-bars"></i>
  875. <input type="text" name="<?php echo $field['name']; ?>" value="<?php echo htmlentities($field['value'], ENT_QUOTES | ENT_IGNORE, "UTF-8"); ?>" placeholder="<?php esc_html_e('Enter a label for this radio button...','booked'); ?>" />
  876. <span class="cf-delete"><i class="booked-icon booked-icon-close"></i></span>
  877. </li><?php
  878. elseif ($field_type == 'single-drop-down'):
  879. ?><li class="ui-state-default"><i class="sub-handle booked-icon booked-icon-bars"></i>
  880. <input type="text" name="<?php echo $field['name']; ?>" value="<?php echo htmlentities($field['value'], ENT_QUOTES | ENT_IGNORE, "UTF-8"); ?>" placeholder="<?php esc_html_e('Enter a label for this option...','booked'); ?>" />
  881. <span class="cf-delete"><i class="booked-icon booked-icon-close"></i></span>
  882. </li><?php
  883. elseif ($field_type == 'required'):
  884. // do nothing
  885. else :
  886. if ($look_for_subs == 'checkboxes'):
  887. ?></ul>
  888. <button class="cfButton button" data-type="single-checkbox"><i class="booked-icon booked-icon-plus"></i>&nbsp;&nbsp;<?php esc_html_e('Checkbox','booked'); ?></button>
  889. <span class="cf-delete"><i class="booked-icon booked-icon-close"></i></span>
  890. </li><?php
  891. elseif ($look_for_subs == 'radio-buttons'):
  892. ?></ul>
  893. <button class="cfButton button" data-type="single-radio-button"><i class="booked-icon booked-icon-plus"></i>&nbsp;&nbsp;<?php esc_html_e('Radio Button','booked'); ?></button>
  894. <span class="cf-delete"><i class="booked-icon booked-icon-close"></i></span>
  895. </li><?php
  896. elseif ($look_for_subs == 'dropdowns'):
  897. ?></ul>
  898. <button class="cfButton button" data-type="single-drop-down"><i class="booked-icon booked-icon-plus"></i>&nbsp;&nbsp;<?php esc_html_e('Option','booked'); ?></button>
  899. <span class="cf-delete"><i class="booked-icon booked-icon-close"></i></span>
  900. </li><?php
  901. endif;
  902. $reset_subs = apply_filters(
  903. 'booked_custom_fields_add_template_subs',
  904. $field_type,
  905. $field['name'],
  906. $field['value'],
  907. $look_for_subs
  908. );
  909. if ( $reset_subs ) {
  910. $look_for_subs = false;
  911. }
  912. endif;
  913. endif;
  914. $field_parts = explode('---',$field['name']);
  915. $field_type = $field_parts[0];
  916. $end_of_string = explode('___',$field_parts[1]);
  917. $numbers_only = $end_of_string[0];
  918. $is_required = (isset($end_of_string[1]) ? true : false);
  919. switch($field_type):
  920. case 'single-line-text-label' :
  921. ?><li class="ui-state-default"><i class="main-handle booked-icon booked-icon-bars"></i>
  922. <small><?php esc_html_e('Single Line Text','booked'); ?></small>
  923. <p><input class="cf-required-checkbox"<?php if ($is_required): echo ' checked="checked"'; endif; ?> type="checkbox" name="required---<?php echo $numbers_only; ?>" id="required---<?php echo $numbers_only; ?>"> <label for="required---<?php echo $numbers_only; ?>"><?php esc_html_e('Required Field','booked'); ?></label></p>
  924. <input type="text" name="<?php echo $field['name']; ?>" value="<?php echo htmlentities($field['value'], ENT_QUOTES | ENT_IGNORE, "UTF-8"); ?>" placeholder="<?php esc_html_e('Enter a label for this field...','booked'); ?>" />
  925. <span class="cf-delete"><i class="booked-icon booked-icon-close"></i></span>
  926. </li><?php
  927. break;
  928. case 'paragraph-text-label' :
  929. ?><li class="ui-state-default"><i class="main-handle booked-icon booked-icon-bars"></i>
  930. <small><?php esc_html_e('Paragraph Text','booked'); ?></small>
  931. <p><input class="cf-required-checkbox"<?php if ($is_required): echo ' checked="checked"'; endif; ?> type="checkbox" name="required---<?php echo $numbers_only; ?>" id="required---<?php echo $numbers_only; ?>"> <label for="required---<?php echo $numbers_only; ?>"><?php esc_html_e('Required Field','booked'); ?></label></p>
  932. <input type="text" name="<?php echo $field['name']; ?>" value="<?php echo htmlentities($field['value'], ENT_QUOTES | ENT_IGNORE, "UTF-8"); ?>" placeholder="<?php esc_html_e('Enter a label for this field...','booked'); ?>" />
  933. <span class="cf-delete"><i class="booked-icon booked-icon-close"></i></span>
  934. </li><?php
  935. break;
  936. case 'checkboxes-label' :
  937. ?><li class="ui-state-default"><i class="main-handle booked-icon booked-icon-bars"></i>
  938. <small><?php esc_html_e('Checkboxes','booked'); ?></small>
  939. <p><input class="cf-required-checkbox"<?php if ($is_required): echo ' checked="checked"'; endif; ?> type="checkbox" name="required---<?php echo $numbers_only; ?>" id="required---<?php echo $numbers_only; ?>"> <label for="required---<?php echo $numbers_only; ?>"><?php esc_html_e('Required Field','booked'); ?></label></p>
  940. <input type="text" name="<?php echo $field['name']; ?>" value="<?php echo htmlentities($field['value'], ENT_QUOTES | ENT_IGNORE, "UTF-8"); ?>" placeholder="<?php esc_html_e('Enter a label for this checkbox group...','booked'); ?>" />
  941. <ul id="booked-cf-checkboxes"><?php
  942. $look_for_subs = 'checkboxes';
  943. break;
  944. case 'radio-buttons-label' :
  945. ?><li class="ui-state-default"><i class="main-handle booked-icon booked-icon-bars"></i>
  946. <small><?php esc_html_e('Radio Buttons','booked'); ?></small>
  947. <p><input class="cf-required-checkbox"<?php if ($is_required): echo ' checked="checked"'; endif; ?> type="checkbox" name="required---<?php echo $numbers_only; ?>" id="required---<?php echo $numbers_only; ?>"> <label for="required---<?php echo $numbers_only; ?>"><?php esc_html_e('Required Field','booked'); ?></label></p>
  948. <input type="text" name="<?php echo $field['name']; ?>" value="<?php echo htmlentities($field['value'], ENT_QUOTES | ENT_IGNORE, "UTF-8"); ?>" placeholder="<?php esc_html_e('Enter a label for this radio button group...','booked'); ?>" />
  949. <ul id="booked-cf-radio-buttons"><?php
  950. $look_for_subs = 'radio-buttons';
  951. break;
  952. case 'drop-down-label' :
  953. ?><li class="ui-state-default"><i class="main-handle booked-icon booked-icon-bars"></i>
  954. <small><?php esc_html_e('Drop Down','booked'); ?></small>
  955. <p><input class="cf-required-checkbox"<?php if ($is_required): echo ' checked="checked"'; endif; ?> type="checkbox" name="required---<?php echo $numbers_only; ?>" id="required---<?php echo $numbers_only; ?>"> <label for="required---<?php echo $numbers_only; ?>"><?php esc_html_e('Required Field','booked'); ?></label></p>
  956. <input type="text" name="<?php echo $field['name']; ?>" value="<?php echo htmlentities($field['value'], ENT_QUOTES | ENT_IGNORE, "UTF-8"); ?>" placeholder="<?php esc_html_e('Enter a label for this drop-down group...','booked'); ?>" />
  957. <ul id="booked-cf-drop-down"><?php
  958. $look_for_subs = 'dropdowns';
  959. break;
  960. case 'plain-text-content' :
  961. ?><li class="ui-state-default"><i class="main-handle booked-icon booked-icon-bars"></i>
  962. <small><?php esc_html_e('Text Content','booked'); ?></small>
  963. <textarea name="<?php echo $field['name']; ?>"><?php echo htmlentities($field['value'], ENT_QUOTES | ENT_IGNORE, "UTF-8"); ?></textarea>
  964. <small class="help-text"><?php esc_html_e('HTML is allowed in this field.','booked'); ?></small>
  965. <span class="cf-delete"><i class="booked-icon booked-icon-close"></i></span>
  966. </li><?php
  967. break;
  968. default:
  969. $look_for_subs_action = apply_filters(
  970. 'booked_custom_fields_add_template_main',
  971. false, // default value to return when there is no addon plugin to hook on it
  972. $field_type,
  973. $field['name'],
  974. $field['value'],
  975. $is_required,
  976. $look_for_subs,
  977. $numbers_only
  978. );
  979. $look_for_subs = $look_for_subs_action ? $look_for_subs_action : $look_for_subs;
  980. break;
  981. endswitch;
  982. endforeach;
  983. if ($look_for_subs):
  984. do_action('booked_custom_fields_add_template_subs_end', $field_type, $look_for_subs);
  985. if ($look_for_subs == 'checkboxes'):
  986. ?></ul>
  987. <button class="cfButton button" data-type="single-checkbox"><i class="booked-icon booked-icon-plus"></i>&nbsp;&nbsp;<?php esc_html_e('Checkbox','booked'); ?></button>
  988. <span class="cf-delete"><i class="booked-icon booked-icon-close"></i></span>
  989. </li><?php
  990. elseif ($look_for_subs == 'radio-buttons'):
  991. ?></ul>
  992. <button class="cfButton button" data-type="single-radio-button"><i class="booked-icon booked-icon-plus"></i>&nbsp;&nbsp;<?php esc_html_e('Radio Button','booked'); ?></button>
  993. <span class="cf-delete"><i class="booked-icon booked-icon-close"></i></span>
  994. </li><?php
  995. elseif ($look_for_subs == 'dropdowns'):
  996. ?></ul>
  997. <button class="cfButton button" data-type="single-drop-down"><i class="booked-icon booked-icon-plus"></i>&nbsp;&nbsp;<?php esc_html_e('Option','booked'); ?></button>
  998. <span class="cf-delete"><i class="booked-icon booked-icon-close"></i></span>
  999. </li><?php
  1000. endif;
  1001. endif;
  1002. endif;
  1003. ?></ul>
  1004. </form>
  1005. <button class="cfButton button" data-type="single-line-text-label"><i class="booked-icon booked-icon-plus"></i>&nbsp;&nbsp;<?php esc_html_e('Single Line Text','booked'); ?></button>&nbsp;
  1006. <button class="cfButton button" data-type="paragraph-text-label"><i class="booked-icon booked-icon-plus"></i>&nbsp;&nbsp;<?php esc_html_e('Paragraph Text','booked'); ?></button>&nbsp;
  1007. <button class="cfButton button" data-type="checkboxes-label"><i class="booked-icon booked-icon-plus"></i>&nbsp;&nbsp;<?php esc_html_e('Checkboxes','booked'); ?></button>&nbsp;
  1008. <button class="cfButton button" data-type="radio-buttons-label"><i class="booked-icon booked-icon-plus"></i>&nbsp;&nbsp;<?php esc_html_e('Radio Buttons','booked'); ?></button>&nbsp;
  1009. <button class="cfButton button" data-type="drop-down-label"><i class="booked-icon booked-icon-plus"></i>&nbsp;&nbsp;<?php esc_html_e('Drop Down','booked'); ?></button>&nbsp;
  1010. <button class="cfButton button" data-type="plain-text-content"><i class="booked-icon booked-icon-plus"></i>&nbsp;&nbsp;<?php esc_html_e('Text Content','booked'); ?></button>
  1011. <?php do_action('booked_custom_fields_add_buttons');
  1012. }