Advertisement
Guest User

ee table

a guest
Nov 28th, 2012
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.75 KB | None | 0 0
  1. <?php
  2. /*
  3. Shortcode Name: Espresso Table
  4. Author: Seth Shoultes
  5. Contact: seth@eventespresso.com
  6. Website: http://www.eventespresso.com
  7. Description: Only show events in a CATEGORY within a certain number number of days into the future and a qty. The example below only shows events in a certain category that start within 30 days from the current date.
  8. Usage Example: [ESPRESSO_TABLE max_days="30" qty="3" category_id="gracecard" order_by="state"]
  9. Custom CSS for the table display
  10. Notes: This file should be stored in your "/wp-content/uploads/espresso/templates/" folder and you should have the custom_includes.php files installed in your "/wp-content/uploads/espresso/" directory.
  11. */
  12. function espresso_display_table($atts){
  13. global $wpdb;
  14. $org_options = get_option('events_organization_settings');
  15. $event_page_id =$org_options['event_page_id'];
  16.  
  17. global $load_espresso_scripts;
  18. $load_espresso_scripts = true;//This tells the plugin to load the required scripts
  19. extract(shortcode_atts(array('event_category_id'=>'NULL','category_identifier' => 'NULL','show_expired' => 'false', 'show_secondary'=>'false','show_deleted'=>'false','show_recurrence'=>'true', 'limit' => '0', 'order_by' => 'NULL', 'max_days'=>''),$atts));
  20.  
  21. if ($category_identifier != 'NULL'){
  22. $type = 'category';
  23. }
  24.  
  25. $show_expired = $show_expired == 'false' ? " AND e.start_date >= '".date ( 'Y-m-d' )."' " : '';
  26. $show_secondary = $show_secondary == 'false' ? " AND e.event_status != 'S' " : '';
  27. $show_deleted = $show_deleted == 'false' ? " AND e.event_status != 'D' " : '';
  28. $show_recurrence = $show_recurrence == 'false' ? " AND e.recurrence_id = '0' " : '';
  29. $limit = $limit > 0 ? " LIMIT 0," . $limit . " " : '';
  30. $order_by = $order_by != 'NULL'? " ORDER BY ". $order_by ." ASC " : " ORDER BY date(start_date), id ASC ";
  31.  
  32. if ($type == 'category'){
  33. $sql = "SELECT e.* FROM " . EVENTS_CATEGORY_TABLE . " c ";
  34. $sql .= " JOIN " . EVENTS_CATEGORY_REL_TABLE . " r ON r.cat_id = c.id ";
  35. $sql .= " JOIN " . EVENTS_DETAIL_TABLE . " e ON e.id = r.event_id ";
  36. $sql .= " WHERE c.category_identifier = '" . $category_identifier . "' ";
  37. $sql .= " AND e.is_active = 'Y' ";
  38. }else{
  39. $sql = "SELECT e.* FROM " . EVENTS_DETAIL_TABLE . " e ";
  40. $sql .= " WHERE e.is_active = 'Y' ";
  41. }
  42. if ($max_days != ""){
  43. $sql .= " AND ADDDATE('".date ( 'Y-m-d' )."', INTERVAL ".$max_days." DAY) >= e.start_date AND e.start_date >= '".date ( 'Y-m-d' )."' ";
  44. }
  45. $sql .= $show_expired;
  46. $sql .= $show_secondary;
  47. $sql .= $show_deleted;
  48. $sql .= $show_recurrence;
  49. $sql .= $order_by;
  50. $sql .= $limit;
  51.  
  52.  
  53. echo espresso_get_table($sql);
  54.  
  55. }
  56. //Events Custom Table Listing - Shows the events on your page in matching table.
  57. function espresso_get_table($sql){
  58. global $wpdb, $org_options;
  59. //echo 'This page is located in ' . get_option( 'upload_path' );
  60. $event_page_id = $org_options['event_page_id'];
  61. $currency_symbol = $org_options['currency_symbol'];
  62. $events = $wpdb->get_results($sql);
  63. $category_name = $wpdb->last_result[0]->category_name;
  64. $category_desc = $wpdb->last_result[0]->category_desc;
  65. $display_desc = $wpdb->last_result[0]->display_desc;
  66. if ($display_desc == 'Y'){
  67. echo '<p>' . stripslashes_deep($category_name) . '</p>';
  68. echo '<p>' . stripslashes_deep($category_desc) . '</p>';
  69. }
  70. ?>
  71. <table class="espresso-table" width="100%">
  72.  
  73. <thead class="espresso-table-header-row">
  74. <tr>
  75. <th class="th-group"><?php _e('Course','event_espresso'); ?></th>
  76. <!--
  77. <th class="th-group"><?php //_e('Location','event_espresso'); ?></th>
  78. <th class="th-group"><?php //_e('City','event_espresso'); ?></th>
  79. <th class="th-group"><?php //_e('State','event_espresso'); ?></th>
  80. -->
  81. <th class="th-group"><?php _e('Date','event_espresso'); ?></th>
  82. <th class="th-group"><?php _e('Time','event_espresso'); ?></th>
  83. <th class="th-group"><?php _e('','event_espresso'); ?></th>
  84. </tr>
  85. </thead>
  86. <tbody>
  87.  
  88. <?php
  89.  
  90. foreach ($events as $event){
  91. $reg_limit = $event->reg_limit;
  92.  
  93.  
  94. $event_desc = wpautop($event->event_desc);
  95.  
  96. $register_button = '<a id="a_register_link-'.$event->id.'" href="'.get_option('siteurl').'/?page_id='.$event_page_id.'&regevent_action=register&event_id='.$event->id.'&name_of_event='.stripslashes_deep($event->event_name).'">Register</a>';
  97.  
  98. //Check to see how many open spots are available
  99. $open_spots = get_number_of_attendees_reg_limit($event->id, 'available_spaces') == 'Unlimited' ? 999 : get_number_of_attendees_reg_limit($event->id, 'available_spaces');
  100. //echo $open_spots;
  101.  
  102. if ( $open_spots < 1 ) { $live_button = 'Closed'; }
  103.  
  104. ?>
  105. <tr class="espresso-table-row">
  106. <td class="td-group">
  107. <?php echo $event->event_name ?>
  108. </td>
  109.  
  110. <!--
  111. <td class="td-group">
  112. <?php //echo $event->address ?>
  113. </td>
  114. <td class="td-group">
  115. <?php //echo $event->city ?>
  116. </td>
  117. <td class="td-group">
  118. <?php //echo $event->state ?>
  119. </td>
  120.  
  121. -->
  122. <td class="td-group">
  123. <?php echo event_date_display($event->start_date, $format = 'l, M d, Y') ?>
  124. </td>
  125. <td class="td-group">
  126. <?php echo espresso_event_time($event->id, 'start_time', get_option('time_format')) ?>
  127. </td>
  128.  
  129. <td class="td-group">
  130. <?php //echo $register_button ?>
  131. <?php echo do_shortcode('[ESPRESSO_CART_LINK anchor="Add to cart"]'); ?>
  132. </td>
  133. </tr>
  134. <?php } //close foreach ?>
  135. </tbody>
  136. </table>
  137.  
  138. <?php
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement