Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.04 KB | None | 0 0
  1. <?php
  2. /**
  3. * Example Shortcode
  4. */
  5.  
  6. add_shortcode( 'crb_table_view', 'crb_shortcode_crb_table_view' );
  7. function crb_shortcode_crb_table_view( $atts, $content ) {
  8. global $wpdb;
  9.  
  10. $page = max(get_query_var('paged'), 1);
  11. $results_per_page = 12; // 2 results * 6 options
  12. $offset = ($page - 1) * $results_per_page;
  13.  
  14. $form_entry_metas = $wpdb->get_results( "
  15. SELECT
  16. SQL_CALC_FOUND_ROWS *,
  17. form_entries.id AS entry_id,
  18. form_entries.created_at,
  19. entry_meta.meta_value,
  20. form_fields.field_key
  21.  
  22. FROM `{$wpdb->prefix}frm_items` as form_entries
  23. INNER JOIN `{$wpdb->prefix}frm_item_metas` as entry_meta
  24. ON form_entries.id = entry_meta.item_id
  25. INNER JOIN `{$wpdb->prefix}frm_fields` as form_fields
  26. ON entry_meta.field_id = form_fields.id
  27.  
  28. WHERE form_entries.form_id = 6
  29. AND form_fields.field_key IN ( 'lyon_source', 'lyon_select_state', 'borrower_email', 'borrower_pri_ph', 'loan_amt_request', 'borrower_fullname' )
  30. LIMIT $offset, $results_per_page");
  31.  
  32.  
  33. $number_of_found_results = $wpdb->get_var('SELECT FOUND_ROWS()');
  34.  
  35. $results = [];
  36. foreach ( $form_entry_metas as $entry ) {
  37. $results[$entry->entry_id]['created'] = $entry->created_at;
  38. $results[$entry->entry_id]['fields'][$entry->field_key] = $entry->meta_value;
  39. }
  40.  
  41. ob_start(); ?>
  42.  
  43. <table id="crb_lyon_applications_table" class="hover order-column" data-posts-per-page="4">
  44. <thead>
  45. <tr>
  46. <th class="lyon-compact filters-row" colspan="10" >
  47. <input type="text" id="picker-start-date" class="datepicker-from" placeholder="Select Start Date">
  48. <input type="text" id="picker-end-date" class="datepicker-to" placeholder="Select End Date">
  49. <select class="filter referring_co" id="1">
  50. <option value=""><?php _e( 'Select Company Referrer', 'crb' ); ?></option>
  51. </select>
  52. <select class="filter referring_parent_co" id="0">
  53. <option value=""><?php _e( 'Select Parent Company', 'crb' ); ?></option>
  54. </select>
  55. </th>
  56. </tr>
  57.  
  58. <tr>
  59. <!--<th class="lyon-compact referring_parent_co"></th>
  60. <th class="lyon-compact referring_co"></th>-->
  61. <th class="lyon-compact"><?php _e( 'DETAIL', 'crb' ); ?></th>
  62. <th class="lyon-compact"><?php _e( 'Receive Date', 'crb' ); ?></th>
  63. <th class="lyon-compact"><?php _e( 'Source', 'crb' ); ?></th>
  64. <th class="lyon-compact"><?php _e( 'State', 'crb' ); ?></th>
  65. <th class="lyon-compact"><?php _e( 'Full Name', 'crb' ); ?></th>
  66. <th class="lyon-compact"><?php _e( 'Email', 'crb' ); ?></th>
  67. <th class="lyon-compact"><?php _e( 'Phone', 'crb' ); ?></th>
  68. <th class="lyon-compact"><?php _e( 'Loan Requested', 'crb' ); ?></th>
  69. </tr>
  70. </thead>
  71.  
  72. <tbody>
  73. <?php foreach ( $results as $id => $result ) :
  74.  
  75. $date_created = new DateTime( $result['created'] );
  76. ?>
  77. <tr>
  78. <!-- <td class="lyon-body referring_parent_co"><?php echo isset( $result['fields']['referring_parent_co'] ) ? $result['fields']['referring_parent_co'] : '' ?></td>
  79. <td class="lyon-body referring_co"><?php echo isset( $result['fields']['referring_co'] ) ? $result['fields']['referring_co'] : '' ?></td> -->
  80. <td class="lyon-body">
  81. <?php if ( $result['fields']['lyon_source'] === 'web' ) : ?>
  82. <?php if ( $result['fields']['lyon_select_state'] === 'Texas' ) : ?>
  83. <a href="/application-detail/?apptype=texas&entryid=<?php echo $id ?>">Detail</a>
  84. <?php else : ?>
  85. <a href="/aplication-detail/?apptype=other&entryid=<?php echo $id ?>">Detail</a>
  86. <?php endif ?>
  87. <?php elseif ( $result['fields']['lyon_source'] === 'xml' ) : ?>
  88. <a href="/application-detail/?apptype=xml&entryid=<?php echo $id ?>">Detail</a>
  89. <?php endif; ?>
  90. </td>
  91. <td class="lyon-body"><?php echo $date_created->format('m/d/Y h:i a'); ?></td>
  92. <td class="lyon-body"><?php echo $result['fields']['lyon_source']; ?></td>
  93. <td class="lyon-body"><?php echo $result['fields']['lyon_select_state']; ?></td>
  94. <td class="lyon-body"><?php echo $result['fields']['borrower_fullname']; ?></td>
  95. <td class="lyon-body"><a href="mailto:<?php echo $result['fields']['borrower_email']; ?>"><?php echo $result['fields']['borrower_email']; ?></a></td>
  96. <td class="lyon-body"><?php echo $result['fields']['borrower_pri_ph']; ?></td>
  97. <td class="lyon-body"><?php echo $result['fields']['loan_amt_request']; ?></td>
  98. </tr>
  99. <?php endforeach; ?>
  100. </tbody>
  101. </table>
  102.  
  103. <?php
  104.  
  105. $max_pages = ceil($number_of_found_results / $results_per_page );
  106. if ($max_pages > 1) { ?>
  107. <div class="pagination">
  108. <ul>
  109. <?php
  110. if ($page > 1) echo '<li><a href="' . get_pagenum_link($page-1) . '" class="previouspostslink"></a></li>';
  111.  
  112. for ($i=1; $i <= $max_pages; $i++) {
  113. echo '<li ' . ( $page == $i ? 'class="current_page_item"' : '' ) . '><a href="' . get_pagenum_link($i) . '">' . $i . '</a></li>';
  114. }
  115. if ($page < $max_pages) echo '<li><a href="' . get_pagenum_link($page+1) . '" class="nextpostslink"></a></li>';
  116. ?>
  117. </ul>
  118. </div>
  119. <?php
  120. }
  121.  
  122. $html = ob_get_clean();
  123.  
  124. return $html;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement