Advertisement
eventsmanager

Custom My Bookings Page

Apr 15th, 2013 (edited)
627
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.22 KB | None | 0 0
  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='<?php em_template_classes('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', 'events-manager'); ?></th>
  40. <th class='manage-column' scope='col'><?php _e('Date', 'events-manager'); ?></th>
  41. <th class='manage-column' scope='col'><?php _e('Spaces', 'events-manager'); ?></th>
  42. <th class='manage-column' scope='col'><?php _e('Status', 'events-manager'); ?></th>
  43. <?php if( get_option('dbem_bookings_rsvp') && get_option('dbem_bookings_rsvp_my_bookings') ): ?>
  44. <th class='manage-column' scope='col'><?php _e('RSVP', 'events-manager'); ?></th>
  45. <?php endif; ?>
  46. <th class='manage-column' scope='col'>&nbsp;</th>
  47. </tr>
  48. </thead>
  49. <tbody>
  50. <?php
  51. $rowno = 0;
  52. $event_count = 0;
  53. $nonce = wp_create_nonce('booking_cancel');
  54. $rsvp_nonce = wp_create_nonce('booking_rsvp');
  55. foreach ($EM_Bookings as $EM_Booking) {
  56. /* @var $EM_Booking EM_Booking */
  57. $todays_date = date("Y-m-d");
  58. $today = strtotime($todays_date);
  59. $EM_Event = $EM_Booking->get_event();
  60. if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) && ($EM_Event->start >= $today) ) {
  61. $rowno++;
  62. ?>
  63. <tr>
  64. <td><?php echo $EM_Event->output("#_EVENTLINK"); ?></td>
  65. <td><?php echo $EM_Event->start()->i18n( get_option('dbem_date_format') ); ?></td>
  66. <td><?php echo $EM_Booking->get_spaces() ?></td>
  67. <td>
  68. <?php echo $EM_Booking->get_status(); ?>
  69. </td>
  70. <?php if( get_option('dbem_bookings_rsvp') && get_option('dbem_bookings_rsvp_my_bookings') ): ?>
  71. <td>
  72. <?php echo $EM_Booking->get_rsvp_status( true ); ?>
  73. </td>
  74. <?php endif; ?>
  75. <td>
  76. <?php
  77. $cancel_links = array();
  78. $show_rsvp = get_option('dbem_bookings_rsvp') && get_option('dbem_bookings_rsvp_my_bookings_buttons');
  79. $show_cancel_rsvp = $EM_Booking->can_rsvp(0) && get_option('dbem_bookings_rsvp_sync_cancel');
  80. if( !$show_cancel_rsvp && (!in_array($EM_Booking->booking_status, array(2,3)) && $EM_Booking->can_cancel()) ){
  81. $cancel_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'booking_cancel', 'booking_id'=>$EM_Booking->booking_id, '_wpnonce'=>$nonce));
  82. $cancel_links[] = '<a class="em-bookings-cancel" href="'. esc_url($cancel_url) .'" onclick="if( !confirm(EM.booking_warning_cancel) ){ return false; }">'.__('Cancel','events-manager').'</a>';
  83. }
  84. if ( $show_rsvp ) {
  85. if( $EM_Booking->can_rsvp(1) ) {
  86. $url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'booking_rsvp_change', 'status' => 1, 'booking_id'=>$EM_Booking->booking_id, '_wpnonce'=>$rsvp_nonce));
  87. $cancel_links[] = '<a class="em-bookings-rsvp-confirm" href="'.esc_url($url).'">'. EM_Booking::get_rsvp_statuses(1)->label_action .'</a>';
  88. }
  89. if( $EM_Booking->can_rsvp(0) ) {
  90. $url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'booking_rsvp_change', 'status' => 0, 'booking_id'=>$EM_Booking->booking_id, '_wpnonce'=>$rsvp_nonce));
  91. $cancel_links[] = '<a class="em-bookings-rsvp-cancel" href="'.esc_url($url).'">'. EM_Booking::get_rsvp_statuses(0)->label_action .'</a>';
  92. }
  93. if( $EM_Booking->can_rsvp(2) ) {
  94. $url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'booking_rsvp_change', 'status' => 2, 'booking_id'=>$EM_Booking->booking_id, '_wpnonce'=>$rsvp_nonce));
  95. $cancel_links[] = '<a class="em-bookings-rsvp-maybe" href="'.esc_url($url).'">'. EM_Booking::get_rsvp_statuses(2)->label_action .'</a>';
  96. }
  97. }
  98. $action_links = apply_filters('em_my_bookings_booking_action_links', $cancel_links, $EM_Booking, $cancel_links);
  99. $action_text = '';
  100. if( !empty($action_links) ) {
  101. if (is_array($action_links) ) {
  102. ?>
  103. <button type="button" class="em-tooltip-ddm em-clickable input button-secondary" data-button-width="match" data-tooltip-class="em-my-bookings-actions-tooltip"><?php esc_html_e('Actions', 'events-manager-pro'); ?></button>
  104. <div class="em-tooltip-ddm-content em-my-bookings-actions-content">
  105. <?php foreach( $action_links as $link ): ?>
  106. <?php echo $link; ?>
  107. <?php endforeach; ?>
  108. </div>
  109. <?php
  110. } else {
  111. // if something messed up the em_my_bookings_booking_action_links filter, just output the links as text further down
  112. $action_text = $action_links;
  113. }
  114. }
  115. // if we have legacy stuff running, just output links as probably expected
  116. // @deprecated - stop using this and use em_my_bookings_booking_action_links above
  117. echo apply_filters('em_my_bookings_booking_actions', $action_text, $EM_Booking, $cancel_links);
  118. do_action( 'em_my_bookings_booking_actions_bottom', $EM_Booking );
  119. ?>
  120. </td>
  121. </tr>
  122. <?php
  123. }
  124. do_action('em_my_bookings_booking_loop',$EM_Booking);
  125. $event_count++;
  126. }
  127. ?>
  128. </tbody>
  129. </table>
  130. </div>
  131. <?php else: ?>
  132. <?php _e('You do not have any bookings.', 'events-manager'); ?>
  133. <?php endif; ?>
  134. <?php if( !empty($bookings_nav) && $bookings_count >= $limit ) : ?>
  135. <div class='tablenav'>
  136. <?php echo $bookings_nav; ?>
  137. <div class="clear"></div>
  138. </div>
  139. <?php endif; ?>
  140. </div>
  141. <?php do_action('em_template_my_bookings_footer', $EM_Bookings); ?>
  142. <?php else: ?>
  143. <p><?php echo sprintf(__('Please <a href="%s">Log In</a> to view your bookings.','events-manager'),site_url('wp-login.php?redirect_to=' . urlencode(get_permalink()), 'login'))?></p>
  144. <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement