Advertisement
eventsmanager

Custom templates/my-bookings.php tempalte

Nov 13th, 2014
752
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. <?php
  2. /*This is a custom my-bookings template which adds booking date*/
  3. ?>
  4. <?php do_action('em_template_my_bookings_header'); ?>
  5. <?php
  6. global $wpdb, $current_user, $EM_Notices, $EM_Person;
  7. if( is_user_logged_in() ):
  8. $EM_Person = new EM_Person( get_current_user_id() );
  9. $EM_Bookings = $EM_Person->get_bookings();
  10. $bookings_count = count($EM_Bookings->bookings);
  11. if($bookings_count > 0){
  12. //Get events here in one query to speed things up
  13. $event_ids = array();
  14. foreach($EM_Bookings as $EM_Booking){
  15. $event_ids[] = $EM_Booking->event_id;
  16. }
  17. }
  18. $limit = ( !empty($_GET['limit']) ) ? $_GET['limit'] : 20;//Default limit
  19. $page = ( !empty($_GET['pno']) ) ? $_GET['pno']:1;
  20. $offset = ( $page > 1 ) ? ($page-1)*$limit : 0;
  21. echo $EM_Notices;
  22. ?>
  23. <div class='em-my-bookings'>
  24. <?php if ( $bookings_count >= $limit ) : ?>
  25. <div class='tablenav'>
  26. <?php
  27. if ( $bookings_count >= $limit ) {
  28. $link = em_add_get_params($_SERVER['REQUEST_URI'], array('pno'=>'%PAGE%'), false); //don't html encode, so em_paginate does its thing
  29. $bookings_nav = em_paginate( $link, $bookings_count, $limit, $page);
  30. echo $bookings_nav;
  31. }
  32. ?>
  33. <div class="clear"></div>
  34. </div>
  35. <?php endif; ?>
  36. <div class="clear"></div>
  37. <?php if( $bookings_count > 0 ): ?>
  38. <div class='table-wrap'>
  39. <table id='dbem-bookings-table' class='widefat post fixed'>
  40. <thead>
  41. <tr>
  42. <th class='manage-column' scope='col'><?php _e('Event', 'dbem'); ?></th>
  43. <th class='manage-column' scope='col'><?php _e('Date', 'dbem'); ?></th>
  44. <th class='manage-column' scope='col'><?php _e('Booking Date', 'dbem'); ?></th>
  45. <th class='manage-column' scope='col'><?php _e('Spaces', 'dbem'); ?></th>
  46. <th class='manage-column' scope='col'><?php _e('Status', 'dbem'); ?></th>
  47. <th class='manage-column' scope='col'>&nbsp;</th>
  48. </tr>
  49. </thead>
  50. <tbody>
  51. <?php
  52. $rowno = 0;
  53. $event_count = 0;
  54. $nonce = wp_create_nonce('booking_cancel');
  55. foreach ($EM_Bookings as $EM_Booking) {
  56. /* @var $EM_Booking EM_Booking */
  57. $EM_Event = $EM_Booking->get_event();
  58. if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
  59. $rowno++;
  60. ?>
  61. <tr>
  62. <td><?php echo $EM_Event->output("#_EVENTLINK"); ?></td>
  63. <td><?php echo date_i18n( get_option('dbem_date_format'), $EM_Event->start ); ?></td>
  64.  
  65. <?php $sql = "SELECT * FROM ". EM_BOOKINGS_TABLE ." LEFT JOIN ". EM_META_TABLE ." ON object_id=booking_id WHERE booking_id ='$EM_Booking->id'"; ?>
  66. <?php $booking = $wpdb->get_row($sql, ARRAY_A); ?>
  67. <td><?php echo date_i18n(get_option('dbem_date_format').' '.get_option('dbem_time_format'), strtotime($booking['booking_date'])); ?></td>
  68. <td><?php echo $EM_Booking->get_spaces() ?></td>
  69. <td>
  70. <?php echo $EM_Booking->get_status(); ?>
  71. </td>
  72. <td>
  73. <?php
  74. $cancel_link = '';
  75. if( !in_array($EM_Booking->booking_status, array(2,3)) && get_option('dbem_bookings_user_cancellation') && $EM_Event->get_bookings()->has_open_time() ){
  76. $cancel_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'booking_cancel', 'booking_id'=>$EM_Booking->booking_id, '_wpnonce'=>$nonce));
  77. $cancel_link = '<a class="em-bookings-cancel" href="'.$cancel_url.'" onclick="if( !confirm(EM.booking_warning_cancel) ){ return false; }">'.__('Cancel','dbem').'</a>';
  78. }
  79. echo apply_filters('em_my_bookings_booking_actions', $cancel_link, $EM_Booking);
  80. ?>
  81. </td>
  82. </tr>
  83. <?php
  84. }
  85. do_action('em_my_bookings_booking_loop',$EM_Booking);
  86. $event_count++;
  87. }
  88. ?>
  89. </tbody>
  90. </table>
  91. </div>
  92. <?php else: ?>
  93. <?php _e('You do not have any bookings.', 'dbem'); ?>
  94. <?php endif; ?>
  95. <?php if( !empty($bookings_nav) && $bookings_count >= $limit ) : ?>
  96. <div class='tablenav'>
  97. <?php echo $bookings_nav; ?>
  98. <div class="clear"></div>
  99. </div>
  100. <?php endif; ?>
  101. </div>
  102. <?php do_action('em_template_my_bookings_footer', $EM_Bookings); ?>
  103. <?php else: ?>
  104. <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>
  105. <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement