GenericList.template.php 10 KB

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