GenericList.template.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines
  7. * @copyright 2014 Simple Machines and individual contributors
  8. * @license http://www.simplemachines.org/about/smf/license.php BSD
  9. *
  10. * @version 2.1 Alpha 1
  11. */
  12. function template_show_list($list_id = null)
  13. {
  14. global $context, $scripturl, $txt, $modSettings;
  15. // Get a shortcut to the current list.
  16. $list_id = $list_id === null ? (!empty($context['default_list']) ? $context['default_list'] : '') : $list_id;
  17. if (empty($list_id) || empty($context[$list_id]))
  18. return;
  19. $cur_list = &$context[$list_id];
  20. // These are the main tabs that is used all around the template.
  21. if (isset($cur_list['list_menu'], $cur_list['list_menu']['show_on']) && ($cur_list['list_menu']['show_on'] == 'both' || $cur_list['list_menu']['show_on'] == 'top'))
  22. template_create_list_menu($cur_list['list_menu'], 'top');
  23. if (isset($cur_list['form']))
  24. echo '
  25. <form class="generic_list_wrapper" action="', $cur_list['form']['href'], '" method="post"', empty($cur_list['form']['name']) ? '' : ' name="' . $cur_list['form']['name'] . '" id="' . $cur_list['form']['name'] . '"', ' accept-charset="', $context['character_set'], '">
  26. <div class="generic_list">';
  27. else
  28. echo '
  29. <div class="generic_list_wrapper">';
  30. // Show the title of the table (if any).
  31. if (!empty($cur_list['title']))
  32. echo '
  33. <div class="cat_bar clear_right">
  34. <h3 class="catbg">
  35. ', $cur_list['title'], '
  36. </h3>
  37. </div>';
  38. if (isset($cur_list['additional_rows']['after_title']))
  39. {
  40. echo '
  41. <div class="information flow_hidden">';
  42. template_additional_rows('after_title', $cur_list);
  43. echo '
  44. </div>';
  45. }
  46. if (isset($cur_list['additional_rows']['top_of_list']))
  47. template_additional_rows('top_of_list', $cur_list);
  48. if ((!empty($cur_list['items_per_page']) && !empty($cur_list['page_index'])) || isset($cur_list['additional_rows']['above_column_headers']))
  49. {
  50. echo '
  51. <div class="flow_auto">';
  52. // Show the page index (if this list doesn't intend to show all items).
  53. if (!empty($cur_list['items_per_page']) && !empty($cur_list['page_index']))
  54. echo '
  55. <div class="floatleft">
  56. <div class="pagesection">', $cur_list['page_index'], '</div>
  57. </div>';
  58. if (isset($cur_list['additional_rows']['above_column_headers']))
  59. template_additional_rows('above_column_headers', $cur_list);
  60. echo '
  61. </div>';
  62. }
  63. echo '
  64. <table class="table_grid" cellspacing="0"', !empty($cur_list['width']) ? ' style="width:' . $cur_list['width'] . '"' : '', '>';
  65. // Show the column headers.
  66. $header_count = count($cur_list['headers']);
  67. if (!($header_count < 2 && empty($cur_list['headers'][0]['label'])))
  68. {
  69. echo '
  70. <thead>
  71. <tr class="catbg">';
  72. // Loop through each column and add a table header.
  73. $i = 0;
  74. foreach ($cur_list['headers'] as $col_header)
  75. {
  76. $i ++;
  77. if ($i === 1)
  78. $col_header['class'] = empty($col_header['class']) ? 'first_th' : 'first_th ' . $col_header['class'];
  79. elseif ($i === $header_count)
  80. $col_header['class'] = empty($col_header['class']) ? 'last_th' : 'last_th ' . $col_header['class'];
  81. echo '
  82. <th scope="col" id="header_', $list_id, '_', $col_header['id'], '"', empty($col_header['class']) ? '' : ' class="' . $col_header['class'] . '"', empty($col_header['style']) ? '' : ' style="' . $col_header['style'] . '"', empty($col_header['colspan']) ? '' : ' colspan="' . $col_header['colspan'] . '"', '>', empty($col_header['href']) ? '' : '<a href="' . $col_header['href'] . '" rel="nofollow">', empty($col_header['label']) ? '&nbsp;' : $col_header['label'], empty($col_header['href']) ? '' : (empty($col_header['sort_image']) ? '</a>' : ' <span class="sort sort_' . $col_header['sort_image'] . '"></span></a>'), '</th>';
  83. }
  84. echo '
  85. </tr>
  86. </thead>';
  87. }
  88. echo '
  89. <tbody>';
  90. // Show a nice message informing there are no items in this list.
  91. if (empty($cur_list['rows']) && !empty($cur_list['no_items_label']))
  92. echo '
  93. <tr>
  94. <td class="windowbg" colspan="', $cur_list['num_columns'], '" align="', !empty($cur_list['no_items_align']) ? $cur_list['no_items_align'] : 'center', '"><div class="padding">', $cur_list['no_items_label'], '</div></td>
  95. </tr>';
  96. // Show the list rows.
  97. elseif (!empty($cur_list['rows']))
  98. {
  99. $alternate = false;
  100. foreach ($cur_list['rows'] as $id => $row)
  101. {
  102. echo '
  103. <tr class="windowbg', $alternate ? '2' : '', $row['class'], '"', $row['style'], ' id="list_', $list_id, '_', $id, '">';
  104. foreach ($row['data'] as $row_data)
  105. echo '
  106. <td', empty($row_data['class']) ? '' : ' class="' . $row_data['class'] . '"', empty($row_data['style']) ? '' : ' style="' . $row_data['style'] . '"', '>', $row_data['value'], '</td>';
  107. echo '
  108. </tr>';
  109. $alternate = !$alternate;
  110. }
  111. }
  112. echo '
  113. </tbody>
  114. </table>';
  115. if ((!empty($cur_list['items_per_page']) && !empty($cur_list['page_index'])) || isset($cur_list['additional_rows']['below_table_data']))
  116. {
  117. echo '
  118. <div class="flow_auto">';
  119. // Show the page index (if this list doesn't intend to show all items).
  120. if (!empty($cur_list['items_per_page']) && !empty($cur_list['page_index']))
  121. echo '
  122. <div class="floatleft">
  123. <div class="pagesection">', $cur_list['page_index'], '</div>
  124. </div>';
  125. if (isset($cur_list['additional_rows']['below_table_data']))
  126. template_additional_rows('below_table_data', $cur_list);
  127. echo '
  128. </div>';
  129. }
  130. if (isset($cur_list['additional_rows']['bottom_of_list']))
  131. template_additional_rows('bottom_of_list', $cur_list);
  132. if (isset($cur_list['form']))
  133. {
  134. foreach ($cur_list['form']['hidden_fields'] as $name => $value)
  135. echo '
  136. <input type="hidden" name="', $name, '" value="', $value, '" />';
  137. echo '
  138. </div>
  139. </form>';
  140. }
  141. else
  142. echo '
  143. </div>';
  144. // Tabs at the bottom. Usually bottom alligned.
  145. if (isset($cur_list['list_menu'], $cur_list['list_menu']['show_on']) && ($cur_list['list_menu']['show_on'] == 'both' || $cur_list['list_menu']['show_on'] == 'bottom'))
  146. template_create_list_menu($cur_list['list_menu'], 'bottom');
  147. if (isset($cur_list['javascript']))
  148. echo '
  149. <script><!-- // --><![CDATA[
  150. ', $cur_list['javascript'], '
  151. // ]]></script>';
  152. }
  153. function template_additional_rows($row_position, $cur_list)
  154. {
  155. foreach ($cur_list['additional_rows'][$row_position] as $row)
  156. echo '
  157. <div class="additional_row', empty($row['class']) ? '' : ' ' . $row['class'], '"', empty($row['style']) ? '' : ' style="' . $row['style'] . '"', '>', $row['value'], '</div>';
  158. }
  159. function template_create_list_menu($list_menu, $direction = 'top')
  160. {
  161. global $context;
  162. /**
  163. // This is use if you want your generic lists to have tabs.
  164. $cur_list['list_menu'] = array(
  165. // This is the style to use. Tabs or Buttons (Text 1 | Text 2).
  166. // By default tabs are selected if not set.
  167. // The main difference between tabs and buttons is that tabs get highlighted if selected.
  168. // If style is set to buttons and use tabs is diabled then we change the style to old styled tabs.
  169. 'style' => 'tabs',
  170. // The posisiton of the tabs/buttons. Left or Right. By default is set to left.
  171. 'position' => 'left',
  172. // This is used by the old styled menu. We *need* to know the total number of columns to span.
  173. 'columns' => 0,
  174. // This gives you the option to show tabs only at the top, bottom or both.
  175. // By default they are just shown at the top.
  176. 'show_on' => 'top',
  177. // Links. This is the core of the array. It has all the info that we need.
  178. 'links' => array(
  179. 'name' => array(
  180. // This will tell use were to go when they click it.
  181. 'href' => $scripturl . '?action=theaction',
  182. // The name that you want to appear for the link.
  183. 'label' => $txt['name'],
  184. // If we use tabs instead of buttons we highlight the current tab.
  185. // Must use conditions to determine if its selected or not.
  186. 'is_selected' => isset($_REQUEST['name']),
  187. ),
  188. ),
  189. );
  190. */
  191. // Are we using right-to-left orientation?
  192. $first = $context['right_to_left'] ? 'last' : 'first';
  193. $last = $context['right_to_left'] ? 'first' : 'last';
  194. if (!isset($list_menu['style']) || isset($list_menu['style']) && $list_menu['style'] == 'tabs')
  195. {
  196. echo '
  197. <table cellpadding="0" cellspacing="0" style="margin-', $list_menu['position'], ': 10px; width: 100%;">
  198. <tr>', $list_menu['position'] == 'right' ? '
  199. <td>&nbsp;</td>' : '', '
  200. <td align="', $list_menu['position'], '">
  201. <table cellspacing="0" cellpadding="0">
  202. <tr>
  203. <td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_', $first, '">&nbsp;</td>';
  204. foreach ($list_menu['links'] as $link)
  205. {
  206. if ($link['is_selected'])
  207. echo '
  208. <td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_active_', $first, '">&nbsp;</td>
  209. <td valign="top" class="', $direction == 'top' ? 'mirrortab' : 'maintab', '_active_back">
  210. <a href="', $link['href'], '">', $link['label'], '</a>
  211. </td>
  212. <td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_active_', $last, '">&nbsp;</td>';
  213. else
  214. echo '
  215. <td valign="top" class="', $direction == 'top' ? 'mirror' : 'main', 'tab_back">
  216. <a href="', $link['href'], '">', $link['label'], '</a>
  217. </td>';
  218. }
  219. echo '
  220. <td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_', $last, '">&nbsp;</td>
  221. </tr>
  222. </table>
  223. </td>', $list_menu['position'] == 'left' ? '
  224. <td>&nbsp;</td>' : '', '
  225. </tr>
  226. </table>';
  227. }
  228. elseif (isset($list_menu['style']) && $list_menu['style'] == 'buttons')
  229. {
  230. $links = array();
  231. foreach ($list_menu['links'] as $link)
  232. $links[] = '<a href="' . $link['href'] . '">' . $link['label'] . '</a>';
  233. echo '
  234. <table cellpadding="0" cellspacing="0" style="margin-', $list_menu['position'], ': 10px; width: 100%;">
  235. <tr>', $list_menu['position'] == 'right' ? '
  236. <td>&nbsp;</td>' : '', '
  237. <td align="', $list_menu['position'], '">
  238. <table cellspacing="0" cellpadding="0">
  239. <tr>
  240. <td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_', $first, '">&nbsp;</td>
  241. <td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_back">', implode(' &nbsp;|&nbsp; ', $links), '</td>
  242. <td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_', $last, '">&nbsp;</td>
  243. </tr>
  244. </table>
  245. </td>', $list_menu['position'] == 'left' ? '
  246. <td>&nbsp;</td>' : '', '
  247. </tr>
  248. </table>';
  249. }
  250. }
  251. ?>