2
0

GenericList.template.php 11 KB

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