eventsmanager

custom template my-past-bookings.php

Aug 27th, 2020 (edited)
50
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php do_action('em_template_my_bookings_header'); ?>
  2. <?php
  3. global $wpdb, $current_user, $EM_Notices, $EM_Person;
  4. if( is_user_logged_in() ):
  5. $EM_Person = new EM_Person( get_current_user_id() );
  6. $EM_Bookings = $EM_Person->get_bookings();
  7. $bookings_count = count($EM_Bookings->bookings);
  8. if($bookings_count > 0){
  9. //Get events here in one query to speed things up
  10. $event_ids = array();
  11. foreach($EM_Bookings as $EM_Booking){
  12. $event_ids[] = $EM_Booking->event_id;
  13. }
  14. }
  15. $limit = ( !empty($_GET['limit']) ) ? $_GET['limit'] : 20;//Default limit
  16. $page = ( !empty($_GET['pno']) ) ? $_GET['pno']:1;
  17. $offset = ( $page > 1 ) ? ($page-1)*$limit : 0;
  18. echo $EM_Notices;
  19. ?>
  20. <div class='em-my-bookings'>
  21. <?php if ( $bookings_count >= $limit ) : ?>
  22. <div class='tablenav'>
  23. <?php
  24. if ( $bookings_count >= $limit ) {
  25. $link = em_add_get_params($_SERVER['REQUEST_URI'], array('pno'=>'%PAGE%'), false); //don't html encode, so em_paginate does its thing
  26. $bookings_nav = em_paginate( $link, $bookings_count, $limit, $page);
  27. echo $bookings_nav;
  28. }
  29. ?>
  30. <div class="clear"></div>
  31. </div>
  32. <?php endif; ?>
  33. <div class="clear"></div>
  34. <?php if( $bookings_count > 0 ): ?>
  35. <div class='table-wrap'>
  36. <table id='dbem-bookings-table' class='widefat post fixed'>
  37. <thead>
  38. <tr>
  39. <th class='manage-column' scope='col'><?php _e('Event', 'dbem'); ?></th>
  40. <th class='manage-column' scope='col'><?php _e('Date', 'dbem'); ?></th>
  41. <th class='manage-column' scope='col'><?php _e('Spaces', 'dbem'); ?></th>
  42. <th class='manage-column' scope='col'><?php _e('Status', 'dbem'); ?></th>
  43. <th class='manage-column' scope='col'>&nbsp;</th>
  44. </tr>
  45. </thead>
  46. <tbody>
  47. <?php
  48. $rowno = 0;
  49. $event_count = 0;
  50. $nonce = wp_create_nonce('booking_cancel');
  51. foreach ($EM_Bookings as $EM_Booking) {
  52. /* @var $EM_Booking EM_Booking */
  53. $EM_Event = $EM_Booking->get_event();
  54. $todays_date = date("Y-m-d");
  55. $today = strtotime($todays_date);
  56.  
  57. if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) && ($EM_Event->start <= $today) ) {
  58. $rowno++;
  59. ?>
  60. <tr>
  61. <td><?php echo $EM_Event->output("#_EVENTLINK"); ?></td>
  62. <td><?php echo date_i18n( get_option('dbem_date_format'), $EM_Event->start ); ?></td>
  63. <td><?php echo $EM_Booking->get_spaces() ?></td>
  64. <td>
  65. <?php echo $EM_Booking->get_status(); ?>
  66. </td>
  67.  
  68. <td>
  69. <?php
  70. /*
  71. $cancel_link = '';
  72. if( !in_array($EM_Booking->status, array(2,3)) && get_option('dbem_bookings_user_cancellation') && $EM_Event->get_bookings()->has_open_time() ){
  73. $cancel_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'booking_cancel', 'booking_id'=>$EM_Booking->booking_id, '_wpnonce'=>$nonce));
  74. $cancel_link = '<a class="em-bookings-cancel" href="'.$cancel_url.'" onclick="if( !confirm(EM.booking_warning_cancel) ){ return false; }">'.__('Cancel','dbem').'</a>';
  75. }
  76. echo apply_filters('em_my_bookings_booking_actions', $cancel_link, $EM_Booking);
  77. */
  78. ?>
  79. </td>
  80.  
  81. <td>
  82. <a href="#" target="_blank" class="new-window">Print
  83. <div class="ticket" style="display:none">
  84. <table border="0">
  85. <tr>
  86. <td><strong><span>Name: </span></strong><?php echo $EM_Event->output("#_EVENTNAME"); ?></td>
  87. </tr>
  88. <tr>
  89. <td><strong><span>Date/Time: </span></strong><?php echo $EM_Event->output("#_EVENTDATES").' '.$EM_Event->output("#_EVENTTIMES"); ?></td>
  90. </tr>
  91. <tr><td></td></tr>
  92. <tr><td></td></tr>
  93. <tr>
  94. <td><h4>Personal Details</h4></td>
  95. </tr>
  96. <tr>
  97. <td><strong><span>Name: </span><?php echo $EM_Booking->get_person()->get_name(); ?></td>
  98. </tr>
  99. <tr>
  100. <td><strong><span>Email: </span><?php echo $EM_Booking->get_person()->user_email; ?></td>
  101. </tr>
  102. <tr>
  103. <td><strong><span>Address: </span><?php echo wp_kses_data(get_metadata('user', $EM_Booking->get_person()->ID, 'dbem_address', true)); ?></td>
  104. </tr>
  105. <tr>
  106. <td><strong><span>Address 2: </span><?php echo wp_kses_data(get_metadata('user', $EM_Booking->get_person()->ID, 'dbem_address_2', true)); ?></td>
  107. </tr>
  108. <tr>
  109. <td><strong><span>City: </span><?php echo wp_kses_data(get_metadata('user', $EM_Booking->get_person()->ID, 'dbem_city', true)); ?></td>
  110. </tr>
  111. <tr>
  112. <td><strong><span>State: </span><?php echo wp_kses_data(get_metadata('user', $EM_Booking->get_person()->ID, 'dbem_state', true)); ?></td>
  113. </tr>
  114. <tr>
  115. <td><strong><span>Zip/Post Code: </span><?php echo wp_kses_data(get_metadata('user', $EM_Booking->get_person()->ID, 'dbem_zip', true)); ?></td>
  116. </tr>
  117. <tr>
  118. <td><strong><span>Country: </span><?php echo wp_kses_data(get_metadata('user', $EM_Booking->get_person()->ID, 'dbem_country', true)); ?></td>
  119. </tr>
  120. <tr><td></td></tr>
  121. <tr><td></td></tr>
  122. <tr>
  123. <td><h4>Booking Details</h4></td>
  124. </tr>
  125. <tr>
  126. <td>
  127. <?php if ( is_array($EM_Booking->booking_meta['booking']) ){ ?>
  128. <?php foreach( $EM_Booking->booking_meta['booking'] as $key => $value) { ?>
  129. <span><strong><?php echo $key; ?></strong></span>
  130. <?php //print_r($value); ?>
  131. <?php if ( is_array($value) ){ ?>
  132. <?php foreach( $value as $key1 => $value1) { ?>
  133. <label><?php echo $value1; ?></label>
  134. <?php } ?>
  135. <?php }else{ ?>
  136. <label><?php echo $value; ?></label>
  137. <?php } ?>
  138. <br/>
  139. <?php } ?>
  140. <?php } ?>
  141. </td>
  142. </tr>
  143. </table>
  144. </div></a>
  145. </td>
  146. </tr>
  147. <?php
  148. }
  149. do_action('em_my_bookings_booking_loop',$EM_Booking);
  150. $event_count++;
  151. }
  152. ?>
  153. </tbody>
  154. </table>
  155. </div>
  156. <?php else: ?>
  157. <?php _e('You do not have any bookings.', 'dbem'); ?>
  158. <?php endif; ?>
  159. <?php if( !empty($bookings_nav) && $EM_Bookings >= $limit ) : ?>
  160. <div class='tablenav'>
  161. <?php echo $bookings_nav; ?>
  162. <div class="clear"></div>
  163. </div>
  164. <?php endif; ?>
  165. </div>
  166. <?php else: ?>
  167. <p><?php echo sprintf(__('Please <a href="%s">Log In</a> to view your bookings.','dbem'),site_url('wp-login.php?redirect_to=' . urlencode(get_permalink()), 'login'))?></p>
  168. <?php endif; ?>
  169. <?php do_action('em_template_my_bookings_footer', $EM_Bookings); ?>
  170.  
  171.  
  172.  
  173.  
  174. <script>
  175. jQuery(function ($) {
  176.  
  177. $('a.new-window').click(function () {
  178. var btn = $(this),
  179. ticket = btn.find('.ticket').html(),
  180. recipe = window.open('','PrintWindow','width=600,height=600'),
  181. html = '<html><head><title>Print Your Ticket</title></head><body><div id="myprintticket">' + ticket + '</div></body></html>';
  182. recipe.document.open();
  183. recipe.document.write(html);
  184. recipe.document.close();
  185. return false;
  186. });
  187.  
  188. });
  189. </script>
RAW Paste Data