1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 
<?php
/**
 * Simple Machines Forum (SMF)
 *
 * @package SMF
 * @author Simple Machines http://www.simplemachines.org
 * @copyright 2019 Simple Machines and individual contributors
 * @license http://www.simplemachines.org/about/smf/license.php BSD
 *
 * @version 2.1 RC1
 */

/**
 * This contains the HTML for the menu bar at the top of the admin center.
 */
function template_generic_menu_dropdown_above()
{
    global $context, $txt;

    // Which menu are we rendering?
    $context['cur_menu_id'] = isset($context['cur_menu_id']) ? $context['cur_menu_id'] + 1 : 1;
    $menu_context = &$context['menu_data_' . $context['cur_menu_id']];

    // Load the menu
    // Add mobile menu as well
    echo '
    <a class="menu_icon mobile_generic_menu_', $context['cur_menu_id'], '"></a>
    <div id="genericmenu">
        <div id="mobile_generic_menu_', $context['cur_menu_id'], '" class="popup_container">
            <div class="popup_window description">
                <div class="popup_heading">
                    ', $txt['mobile_user_menu'], '
                    <a href="javascript:void(0);" class="main_icons hide_popup"></a>
                </div>
                ', template_generic_menu($menu_context), '
                </div>
        </div>
    </div>
    <script>
        $( ".mobile_generic_menu_', $context['cur_menu_id'], '" ).click(function() {
            $( "#mobile_generic_menu_', $context['cur_menu_id'], '" ).show();
            });
        $( ".hide_popup" ).click(function() {
            $( "#mobile_generic_menu_', $context['cur_menu_id'], '" ).hide();
        });
    </script>';

    // This is the main table - we need it so we can keep the content to the right of it.
    echo '
                <div id="admin_content">';

    // It's possible that some pages have their own tabs they wanna force...
//  if (!empty($context['tabs']))
    template_generic_menu_tabs($menu_context);
}

/**
 * Part of the admin layer - used with generic_menu_dropdown_above to close the admin content div.
 */
function template_generic_menu_dropdown_below()
{
    echo '
                </div><!-- #admin_content -->';
}

function template_generic_menu(&$menu_context)
{
    global $context;

    echo '
                <div class="generic_menu">
                    <ul class="dropmenu dropdown_menu_', $context['cur_menu_id'], '">';

    // Main areas first.
    foreach ($menu_context['sections'] as $section)
    {
        echo '
                        <li ', !empty($section['areas']) ? 'class="subsections"' : '', '><a class="', !empty($section['selected']) ? 'active ' : '', '" href="', $section['url'], $menu_context['extra_parameters'], '">', $section['title'], !empty($section['amt']) ? ' <span class="amt">' . $section['amt'] . '</span>' : '', '</a>
                            <ul>';

        // For every area of this section show a link to that area (bold if it's currently selected.)
        // @todo Code for additional_items class was deprecated and has been removed. Suggest following up in Sources if required.
        foreach ($section['areas'] as $i => $area)
        {
            // Not supposed to be printed?
            if (empty($area['label']))
                continue;

            echo '
                                <li', !empty($area['subsections']) ? ' class="subsections"' : '', '>
                                    <a class="', $area['icon_class'], !empty($area['selected']) ? ' chosen ' : '', '" href="', (isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $i), $menu_context['extra_parameters'], '">', $area['icon'], $area['label'], !empty($area['amt']) ? ' <span class="amt">' . $area['amt'] . '</span>' : '', '</a>';

            // Is this the current area, or just some area?
            if (!empty($area['selected']) && empty($context['tabs']))
                $context['tabs'] = isset($area['subsections']) ? $area['subsections'] : array();

            // Are there any subsections?
            if (!empty($area['subsections']))
            {
                echo '
                                    <ul>';

                foreach ($area['subsections'] as $sa => $sub)
                {
                    if (!empty($sub['disabled']))
                        continue;

                    $url = isset($sub['url']) ? $sub['url'] : (isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $i) . ';sa=' . $sa;

                    echo '
                                        <li>
                                            <a ', !empty($sub['selected']) ? 'class="chosen" ' : '', ' href="', $url, $menu_context['extra_parameters'], '">', $sub['label'], !empty($sub['amt']) ? ' <span class="amt">' . $sub['amt'] . '</span>' : '', '</a>
                                        </li>';
                }

                echo '
                                    </ul>';
            }

            echo '
                                </li>';
        }
        echo '
                            </ul>
                        </li>';
    }

    echo '
                    </ul><!-- .dropmenu -->
                </div><!-- .generic_menu -->';
}

/**
 * The code for displaying the menu
 *
 * @param array $menu_context An array of menu context data
 */
function template_generic_menu_tabs(&$menu_context)
{
    global $context, $settings, $scripturl, $txt;

    // Handy shortcut.
    $tab_context = &$menu_context['tab_data'];

    if (!empty($tab_context['title']))
    {
        echo '
                    <div class="cat_bar">', (function_exists('template_admin_quick_search') ? '
                        <form action="' . $scripturl . '?action=admin;area=search" method="post" accept-charset="' . $context['character_set'] . '">' : ''), '
                            <h3 class="catbg">';

        // The function is in Admin.template.php, but since this template is used elsewhere too better check if the function is available
        if (function_exists('template_admin_quick_search'))
            template_admin_quick_search();

        // Exactly how many tabs do we have?
        if (!empty($context['tabs']))
        {
            foreach ($context['tabs'] as $id => $tab)
            {
                // Can this not be accessed?
                if (!empty($tab['disabled']))
                {
                    $tab_context['tabs'][$id]['disabled'] = true;
                    continue;
                }

                // Did this not even exist - or do we not have a label?
                if (!isset($tab_context['tabs'][$id]))
                    $tab_context['tabs'][$id] = array('label' => $tab['label']);
                elseif (!isset($tab_context['tabs'][$id]['label']))
                    $tab_context['tabs'][$id]['label'] = $tab['label'];

                // Has a custom URL defined in the main admin structure?
                if (isset($tab['url']) && !isset($tab_context['tabs'][$id]['url']))
                    $tab_context['tabs'][$id]['url'] = $tab['url'];

                // Any additional parameters for the url?
                if (isset($tab['add_params']) && !isset($tab_context['tabs'][$id]['add_params']))
                    $tab_context['tabs'][$id]['add_params'] = $tab['add_params'];

                // Has it been deemed selected?
                if (!empty($tab['is_selected']))
                    $tab_context['tabs'][$id]['is_selected'] = true;

                // Does it have its own help?
                if (!empty($tab['help']))
                    $tab_context['tabs'][$id]['help'] = $tab['help'];

                // Is this the last one?
                if (!empty($tab['is_last']) && !isset($tab_context['override_last']))
                    $tab_context['tabs'][$id]['is_last'] = true;
            }

            // Find the selected tab
            foreach ($tab_context['tabs'] as $sa => $tab)
            {
                if (!empty($tab['is_selected']) || (isset($menu_context['current_subsection']) && $menu_context['current_subsection'] == $sa))
                {
                    $selected_tab = $tab;
                    $tab_context['tabs'][$sa]['is_selected'] = true;
                }
            }
        }

        // Show an icon and/or a help item?
        if (!empty($selected_tab['icon_class']) || !empty($tab_context['icon_class']) || !empty($selected_tab['icon']) || !empty($tab_context['icon']) || !empty($selected_tab['help']) || !empty($tab_context['help']))
        {
            if (!empty($selected_tab['icon_class']) || !empty($tab_context['icon_class']))
                echo '
                                <span class="', !empty($selected_tab['icon_class']) ? $selected_tab['icon_class'] : $tab_context['icon_class'], ' icon"></span>';
            elseif (!empty($selected_tab['icon']) || !empty($tab_context['icon']))
                echo '
                                <img src="', $settings['images_url'], '/icons/', !empty($selected_tab['icon']) ? $selected_tab['icon'] : $tab_context['icon'], '" alt="" class="icon">';

            if (!empty($selected_tab['help']) || !empty($tab_context['help']))
                echo '
                                <a href="', $scripturl, '?action=helpadmin;help=', !empty($selected_tab['help']) ? $selected_tab['help'] : $tab_context['help'], '" onclick="return reqOverlayDiv(this.href);" class="help"><span class="main_icons help" title="', $txt['help'], '"></span></a>';

            echo $tab_context['title'];
        }
        else
            echo '
                                ', $tab_context['title'];

        echo '
                            </h3>', (function_exists('template_admin_quick_search') ? '
                        </form>' : ''), '
                    </div><!-- .cat_bar -->';
    }

    // Shall we use the tabs? Yes, it's the only known way!
    if (!empty($selected_tab['description']) || !empty($tab_context['description']))
        echo '
                    <p class="information">
                        ', !empty($selected_tab['description']) ? $selected_tab['description'] : $tab_context['description'], '
                    </p>';

    // Print out all the items in this tab (if any).
    if (!empty($context['tabs']))
    {
        // The admin tabs.
        echo '
                    <div id="adm_submenus">
                        <ul class="dropmenu">';

        foreach ($tab_context['tabs'] as $sa => $tab)
        {
            if (!empty($tab['disabled']))
                continue;

            if (!empty($tab['is_selected']))
                echo '
                            <li>
                                <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>
                            </li>';
            else
                echo '
                            <li>
                                <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>
                            </li>';
        }

        // The end of tabs
        echo '
                        </ul>
                    </div><!-- #adm_submenus -->';
    }
}

?>