GenericList.template.php 11 KB

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