GenericMenu.template.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. // This contains the html for the side bar of the admin center, which is used for all admin pages.
  13. function template_generic_menu_sidebar_above()
  14. {
  15. global $context, $settings, $options, $scripturl, $txt, $modSettings;
  16. // This is the main table - we need it so we can keep the content to the right of it.
  17. // [WIP] Why is there a span id="admin_menu"? #admin_menu is also the div that wraps the drop menu system.
  18. // Is this some bonkers leftover span from 2.0 beta days? It has no content and is not listed in the CSS.
  19. echo '
  20. <div id="main_container">
  21. <div id="left_admsection"><span id="admin_menu"></span>';
  22. // What one are we rendering?
  23. $context['cur_menu_id'] = isset($context['cur_menu_id']) ? $context['cur_menu_id'] + 1 : 1;
  24. $menu_context = &$context['menu_data_' . $context['cur_menu_id']];
  25. // For every section that appears on the sidebar...
  26. $firstSection = true;
  27. foreach ($menu_context['sections'] as $section)
  28. {
  29. // Show the section header - and pump up the line spacing for readability.
  30. echo '
  31. <div class="adm_section">
  32. <div class="cat_bar">
  33. <h4 class="catbg">
  34. ', $section['title'], '
  35. </h4>
  36. </div>
  37. <ul class="smalltext left_admmenu">';
  38. // For every area of this section show a link to that area (bold if it's currently selected.)
  39. foreach ($section['areas'] as $i => $area)
  40. {
  41. // Not supposed to be printed?
  42. if (empty($area['label']))
  43. continue;
  44. echo '
  45. <li>';
  46. // Is this the current area, or just some area?
  47. if ($i == $menu_context['current_area'])
  48. {
  49. echo '
  50. <strong><a href="', isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $i, $menu_context['extra_parameters'], '">', $area['label'], '</a></strong>';
  51. if (empty($context['tabs']))
  52. $context['tabs'] = isset($area['subsections']) ? $area['subsections'] : array();
  53. }
  54. else
  55. echo '
  56. <a href="', isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $i, $menu_context['extra_parameters'], '">', $area['label'], '</a>';
  57. echo '
  58. </li>';
  59. }
  60. echo '
  61. </ul>
  62. </div>';
  63. $firstSection = false;
  64. }
  65. // This is where the actual "main content" area for the admin section starts.
  66. echo '
  67. </div>
  68. <div id="main_admsection">';
  69. // If there are any "tabs" setup, this is the place to shown them.
  70. if (!empty($context['tabs']) && empty($context['force_disable_tabs']))
  71. template_generic_menu_tabs($menu_context);
  72. }
  73. // Part of the sidebar layer - closes off the main bit.
  74. function template_generic_menu_sidebar_below()
  75. {
  76. global $context, $settings, $options;
  77. echo '
  78. </div>
  79. </div>';
  80. }
  81. // This contains the html for the side bar of the admin center, which is used for all admin pages.
  82. function template_generic_menu_dropdown_above()
  83. {
  84. global $context, $settings, $options, $scripturl, $txt, $modSettings;
  85. // Which menu are we rendering?
  86. $context['cur_menu_id'] = isset($context['cur_menu_id']) ? $context['cur_menu_id'] + 1 : 1;
  87. $menu_context = &$context['menu_data_' . $context['cur_menu_id']];
  88. echo '
  89. <div id="admin_menu">';
  90. echo '
  91. <ul class="dropmenu" id="dropdown_menu_', $context['cur_menu_id'], '">';
  92. // Main areas first.
  93. foreach ($menu_context['sections'] as $section)
  94. {
  95. echo '
  96. <li ', !empty($section['areas']) ? 'class="subsections"' : '', '><a class="', !empty($section['selected']) ? 'active ' : '', '" href="', $section['url'], $menu_context['extra_parameters'], '">', $section['title'] , '</a>
  97. <ul>';
  98. // For every area of this section show a link to that area (bold if it's currently selected.)
  99. // @todo Code for additional_items class was deprecated and has been removed. Suggest following up in Sources if required.
  100. foreach ($section['areas'] as $i => $area)
  101. {
  102. // Not supposed to be printed?
  103. if (empty($area['label']))
  104. continue;
  105. echo '
  106. <li', !empty($area['subsections']) ? ' class="subsections"' : '', '>';
  107. echo '
  108. <a ', !empty($area['selected']) ? 'class="chosen" ' : '', 'href="', (isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $i), $menu_context['extra_parameters'], '">', $area['icon'], $area['label'], '</a>';
  109. // Is this the current area, or just some area?
  110. if (!empty($area['selected']) && empty($context['tabs']))
  111. $context['tabs'] = isset($area['subsections']) ? $area['subsections'] : array();
  112. // Are there any subsections?
  113. if (!empty($area['subsections']))
  114. {
  115. echo '
  116. <ul>';
  117. foreach ($area['subsections'] as $sa => $sub)
  118. {
  119. if (!empty($sub['disabled']))
  120. continue;
  121. $url = isset($sub['url']) ? $sub['url'] : (isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $i) . ';sa=' . $sa;
  122. echo '
  123. <li ', !empty($area['subsections']) ? ' class="subsections"' : '', '>
  124. <a ', !empty($sub['selected']) ? 'class="chosen" ' : '', 'href="', $url, $menu_context['extra_parameters'], '">', $sub['label'], '</a>
  125. </li>';
  126. }
  127. echo '
  128. </ul>';
  129. }
  130. echo '
  131. </li>';
  132. }
  133. echo '
  134. </ul>
  135. </li>';
  136. }
  137. echo '
  138. </ul>
  139. </div>';
  140. // This is the main table - we need it so we can keep the content to the right of it.
  141. echo '
  142. <div id="admin_content">';
  143. // It's possible that some pages have their own tabs they wanna force...
  144. if (!empty($context['tabs']))
  145. template_generic_menu_tabs($menu_context);
  146. }
  147. // Part of the admin layer - used with admin_above to close the table started in it.
  148. function template_generic_menu_dropdown_below()
  149. {
  150. global $context, $settings, $options;
  151. echo '
  152. </div>';
  153. }
  154. // Some code for showing a tabbed view.
  155. function template_generic_menu_tabs(&$menu_context)
  156. {
  157. global $context, $settings, $options, $scripturl, $txt, $modSettings;
  158. // Handy shortcut.
  159. $tab_context = &$menu_context['tab_data'];
  160. echo '
  161. <div class="cat_bar">
  162. <h3 class="catbg">';
  163. // Exactly how many tabs do we have?
  164. foreach ($context['tabs'] as $id => $tab)
  165. {
  166. // Can this not be accessed?
  167. if (!empty($tab['disabled']))
  168. {
  169. $tab_context['tabs'][$id]['disabled'] = true;
  170. continue;
  171. }
  172. // Did this not even exist - or do we not have a label?
  173. if (!isset($tab_context['tabs'][$id]))
  174. $tab_context['tabs'][$id] = array('label' => $tab['label']);
  175. elseif (!isset($tab_context['tabs'][$id]['label']))
  176. $tab_context['tabs'][$id]['label'] = $tab['label'];
  177. // Has a custom URL defined in the main admin structure?
  178. if (isset($tab['url']) && !isset($tab_context['tabs'][$id]['url']))
  179. $tab_context['tabs'][$id]['url'] = $tab['url'];
  180. // Any additional paramaters for the url?
  181. if (isset($tab['add_params']) && !isset($tab_context['tabs'][$id]['add_params']))
  182. $tab_context['tabs'][$id]['add_params'] = $tab['add_params'];
  183. // Has it been deemed selected?
  184. if (!empty($tab['is_selected']))
  185. $tab_context['tabs'][$id]['is_selected'] = true;
  186. // Does it have its own help?
  187. if (!empty($tab['help']))
  188. $tab_context['tabs'][$id]['help'] = $tab['help'];
  189. // Is this the last one?
  190. if (!empty($tab['is_last']) && !isset($tab_context['override_last']))
  191. $tab_context['tabs'][$id]['is_last'] = true;
  192. }
  193. // Find the selected tab
  194. foreach ($tab_context['tabs'] as $sa => $tab)
  195. {
  196. if (!empty($tab['is_selected']) || (isset($menu_context['current_subsection']) && $menu_context['current_subsection'] == $sa))
  197. {
  198. $selected_tab = $tab;
  199. $tab_context['tabs'][$sa]['is_selected'] = true;
  200. }
  201. }
  202. // Show an icon and/or a help item?
  203. if (!empty($selected_tab['icon']) || !empty($tab_context['icon']) || !empty($selected_tab['help']) || !empty($tab_context['help']))
  204. {
  205. if (!empty($selected_tab['icon']) || !empty($tab_context['icon']))
  206. echo '<img src="', $settings['images_url'], '/icons/', !empty($selected_tab['icon']) ? $selected_tab['icon'] : $tab_context['icon'], '" alt="" class="icon" />';
  207. if (!empty($selected_tab['help']) || !empty($tab_context['help']))
  208. echo '<a href="', $scripturl, '?action=helpadmin;help=', !empty($selected_tab['help']) ? $selected_tab['help'] : $tab_context['help'], '" onclick="return reqOverlayDiv(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" class="icon" /></a>';
  209. echo $tab_context['title'];
  210. }
  211. else
  212. {
  213. echo '
  214. ', $tab_context['title'];
  215. }
  216. echo '
  217. </h3>
  218. </div>';
  219. // Shall we use the tabs?
  220. if (!empty($settings['use_tabs']))
  221. {
  222. echo '
  223. <p class="description">
  224. ', !empty($selected_tab['description']) ? $selected_tab['description'] : $tab_context['description'], '
  225. </p>';
  226. // The admin tabs.
  227. echo '
  228. <div id="adm_submenus">
  229. <ul class="dropmenu">';
  230. // Print out all the items in this tab.
  231. foreach ($tab_context['tabs'] as $sa => $tab)
  232. {
  233. if (!empty($tab['disabled']))
  234. continue;
  235. if (!empty($tab['is_selected']))
  236. {
  237. echo '
  238. <li>
  239. <a class="active" href="', isset($tab['url']) ? $tab['url'] : $menu_context['base_url'] . ';area=' . $menu_context['current_area'] . ';sa=' . $sa, $menu_context['extra_parameters'], isset($tab['add_params']) ? $tab['add_params'] : '', '">', $tab['label'], '</a>
  240. </li>';
  241. }
  242. else
  243. echo '
  244. <li>
  245. <a href="', isset($tab['url']) ? $tab['url'] : $menu_context['base_url'] . ';area=' . $menu_context['current_area'] . ';sa=' . $sa, $menu_context['extra_parameters'], isset($tab['add_params']) ? $tab['add_params'] : '', '">', $tab['label'], '</a>
  246. </li>';
  247. }
  248. // the end of tabs
  249. echo '
  250. </ul>
  251. </div>
  252. <br class="clear" />';
  253. }
  254. // ...if not use the old style
  255. else
  256. {
  257. echo '
  258. <p class="tabs">';
  259. // Print out all the items in this tab.
  260. foreach ($tab_context['tabs'] as $sa => $tab)
  261. {
  262. if (!empty($tab['disabled']))
  263. continue;
  264. if (!empty($tab['is_selected']))
  265. {
  266. echo '
  267. <img src="', $settings['images_url'], '/selected.png" alt="*" /> <strong><a href="', isset($tab['url']) ? $tab['url'] : $menu_context['base_url'] . ';area=' . $menu_context['current_area'] . ';sa=' . $sa, $menu_context['extra_parameters'], '">', $tab['label'], '</a></strong>';
  268. }
  269. else
  270. echo '
  271. <a href="', isset($tab['url']) ? $tab['url'] : $menu_context['base_url'] . ';area=' . $menu_context['current_area'] . ';sa=' . $sa, $menu_context['extra_parameters'], '">', $tab['label'], '</a>';
  272. if (empty($tab['is_last']))
  273. echo ' | ';
  274. }
  275. echo '
  276. </p>
  277. <p class="description">', isset($selected_tab['description']) ? $selected_tab['description'] : $tab_context['description'], '</p>';
  278. }
  279. }
  280. ?>