============================================================================================================================
Modification Name: Header Links Control Advanced

Version: 2.0

Author: GuldantheWarlock (GuldantheWarlock@xmbgarage.com)

Last Updated: March 29, 2010

Modification Description:
This modification will allow you to specify sub-links for your header links through the admin panel.
This modification will display all sub-links in a JavaScript drop down menu under the specified link.
This modification also includes the features for Header Link Controls Advanced:
 - This modification will provide controls for the number of header links per line via Admin Panel -> Header Links.
 - This modification will will provide on/off controls for the link images in Admin Panel -> Header Links.
 - This modification will allow you to enter a separator for the links in Admin Panel -> Header Links.

Supported Version: XMB 1.9.5 SP1

Notes: This modification uses some code from Header Links Control Advanced by Adam Clarke (http://www.xmbservices.com/) and myself.
           This modification is released under the GPL License v3. A copy is provided with this software package.

Please backup your files before installing this modification.
Neither XMBGarage nor the author can be held responsible if your board stops functioning properly due to you installing this modification.
============================================================================================================================
=========================================================================================================================
IF YOU HAVE HEADER LINKS CONTROL ADVANCED V1.0 OR ANY OTHER HEADER LINK CONTROL HACK, YOU WILL NEED TO REMOVE IT FIRST!
=========================================================================================================================
=======
Step 1:
=======

Upload the file 'install.php' from the 'Contents' folder to your forum directory and run install.php by directing your browser to it.

Example: http://www.domain.ext/forum/install.php

NOTE: MAKE SURE YOU DO THIS STEP BEFORE EDITING ANYTHING ELSE, OR IT MAY RESULT IN ERRORS!

============================================================================================================================
=======
Step 2:
=======
=======================
Edit File: lang/English.lang.php
=======================
========================
Add To End Of File Above  ?>
========================

// Header Links Control Advanced Mod Begin
$lang['linkimages'] = "Show Header Link Images:";
$lang['linkdivider'] = "Link Divider:";
$lang['headerlinks'] = "Header Links Per Line:";
$lang['textlinkopts'] = "Header Link Options:";
$lang['textheaderlinks'] = "Header Links";
$lang['textnewlink'] = "New Link Text";
$lang['textnewlinkhref'] = "New Link Location";
$lang['textnewsublink'] = "New Sub-Link Text";
$lang['textnewsubhref'] = "New Sub-Link Location";
$lang['textnewlinkimg'] = "New Link Image";
$lang['textnewsubimg'] = "New Sub-Link Image";
$lang['textnewwin'] = "New Window?";
$lang['textviewlevel'] = "Select Who Can View";
$lang['textheaderlinksupdate'] = "Header Links Successfully Updated!";
$lang['linkoptshelp'] = "You may add/edit your header and sub-links here. For the link text, you may either add text, or a variable name/lang var.";
$lang['hldelconfirm'] = 'Warning!\n\nYou have selected a top level header link for deletion. If you delete a header link, all sub links connected to it will be deleted.\n\nAre you sure you want to continue?';
// Header Links Control Advanced Mod End

============================================================================================================================
=======
Step 3:
=======
=================
Edit File: header.php
=================
==========
Find Code:
==========

,'forums'

================
Replace Code With:
================

,'forums','headerlinks'

==========
Find Code:
==========

// Search-link
if ($SETTINGS['searchstatus'] == "on") {
    $links[] = "<img src=\"$imgdir/search.gif\" alt=\"$lang[altsearch]\" border=\"0\" /> <a href=\"misc.php?action=search\"><font class=\"navtd\">$lang[textsearch]</font></a>";
}

// Faq-link
if ($SETTINGS['faqstatus'] == "on") {
    $links[] = "<img src=\"$imgdir/faq.gif\" alt=\"$lang[altfaq]\" border=\"0\" /> <a href=\"faq.php\"><font class=\"navtd\">$lang[textfaq]</font></a>";
}

// Memberlist-link
if ($SETTINGS['memliststatus'] == "on") {
    $links[] = "<img src=\"$imgdir/members_list.gif\" alt=\"$lang[altmemberlist]\" border=\"0\" /> <a href=\"misc.php?action=list\"><font class=\"navtd\">$lang[textmemberlist]</font></a>";
}

// Today's posts-link
if ($SETTINGS['todaysposts'] == "on") {
    $links[] = "<img src=\"$imgdir/todays_posts.gif\" alt=\"$lang[alttodayposts]\" border=\"0\" /> <a href=\"today.php\"><font class=\"navtd\">$lang[navtodaysposts]</font></a>";
}

// Stats-link
if ($SETTINGS['stats'] == "on") {
    $links[] = "<img src=\"$imgdir/stats.gif\" alt=\"$lang[altstats]\" border=\"0\" /> <a href=\"stats.php\"><font class=\"navtd\">$lang[navstats]</font></a>";
}

// 'Forum Rules'-link
if ($SETTINGS['bbrules'] == "on") {
    $links[] = "<img src=\"$imgdir/bbrules.gif\" alt=\"$lang[altrules]\" border=\"0\" /> <a href=\"faq.php?page=forumrules\"><font class=\"navtd\">$lang[textbbrules]</font></a>";
}

$links = implode(' &nbsp; ', $links);

// Show all plugins
$pluglinks = array();
foreach ($plugname as $plugnum => $item) {
    if (!empty($plugurl[$plugnum]) && !empty($plugname[$plugnum])) {
        if (trim($plugimg[$plugnum]) != '') {
            $img = '<img src="'.$plugimg[$plugnum].'" border="0" /> ';
        } else {
            $img = '';
        }

        if ($plugadmin[$plugnum] != true || X_ADMIN) {
            $pluglinks[] = " &nbsp; $img<a href=\"$plugurl[$plugnum]\"><font class=\"navtd\">$plugname[$plugnum]</font></a>";
        }
    }
}

if (count($pluglinks) == 0) {
    $pluglink = '';
} else {
    $pluglink = implode(' &nbsp; ', $pluglinks);
}

================
Replace Code With:
================

// Header Links Control Advanced Mod Begin
$links = compileHeaderLinks();
$pluglink = compilePlugLinks();
$linkdisplay = compileLinkDisplay($links, $pluglink, $SETTINGS['linkimages'], $SETTINGS['linkdivider']);
// Header Links Control Advanced Mod End

============================================================================================================================
=======
Step 4:
=======
==============
Edit File: cp.php:
==============
==========
Find Code:
==========

if ($action == "rename") {

===============
Add Code Above:
===============

// Header Links Control Advanced Mod Begin
if ($action == 'headerlinks') {
    if (isset($_POST['linksubmit'])) {
        $query = $db->query("SELECT lid FROM $table_headerlinks WHERE type='link'");
        while($link = $db->fetch_array($query)) {
            $displayorder = "displayorder$link[lid]";
            $displayorder = "${$displayorder}";
            $text = "link$link[lid]";
            $text = "${$text}";
            $href = "href$link[lid]";
            $href = "${$href}";
            $img = "img$link[lid]";
            $img = "${$img}";
            $newwin = "newwin$link[lid]";
            $newwin = "${$newwin}";
            $viewlvl = "view_level$link[lid]";
            $viewlvl = "${$viewlvl}";
            $delete = "delete$link[lid]";
            $delete = "${$delete}";
            $status = "status$link[lid]";
            $status = "${$status}";

            if ($delete != '') {
                $db->query("DELETE FROM $table_headerlinks WHERE lid='$delete'");
                $db->query("DELETE FROM $table_headerlinks WHERE type='sub' AND lup='$delete'");
            } else {
                $text = addslashes($text);
                $newwin = ((int) $newwin == 1) ? 1 : 0;
                $db->query("UPDATE $table_headerlinks SET displayorder='".(int) $displayorder."', link='$text', href='$href', img='$img', new_win='$newwin', view_level='$viewlvl', status='$status' WHERE lid='$link[lid]'");
            }
        }
        $db->free_result($query);

        $query = $db->query("SELECT lid FROM $table_headerlinks WHERE type='sub'");
        while($sub = $db->fetch_array($query)) {
            $displayorder = "displayorder$sub[lid]";
            $displayorder = "${$displayorder}";
            $link = "link$sub[lid]";
            $link = "${$link}";
            $href = "href$sub[lid]";
            $href = "${$href}";
            $img = "img$sub[lid]";
            $img = "${$img}";
            $newwin = "newwin$sub[lid]";
            $newwin = "${$newwin}";
            $viewlvl = "view_level$sub[lid]";
            $viewlvl = "${$viewlvl}";
            $delete = "delete$sub[lid]";
            $delete = "${$delete}";
            $status = "status$sub[lid]";
            $status = "${$status}";
            $moveto = "moveto$sub[lid]";
            $moveto = "${$moveto}";

            if (isset($delete) && $delete != '') {
                $db->query("DELETE FROM $table_headerlinks WHERE lid='$delete'");
            } else {
                $link = addslashes($link);
                $newwin = (isset($newwin) && ((int) $newwin == 1)) ? 1 : 0;
                $db->query("UPDATE $table_headerlinks SET displayorder='".(int) $displayorder."', link='$link', href='$href', img='$img', new_win='$newwin', view_level='$viewlvl', status='$status', lup='".(int) $moveto."' WHERE lid='$sub[lid]'");
            }
        }
        $db->free_result($query);

        if ($newlinkname != $lang['textnewlink'] && $newlinkname != '' && $newlinkhref != $lang['textnewlinkhref'] && $newlinkhref != '') {
            $newlinkname = addslashes($newlinkname);
            $newlinkimg  = ($newlinkimg != $lang['textnewlinkimg']) ? $newlinkimg : '';
            $newwin = (isset($newlinkwin) && ((int) $newlinkwin == 1)) ? 1 : 0;
            $newviewlvl  = ($new_view_level != '') ? $new_view_level : 'guest';
            $db->query("INSERT INTO $table_headerlinks (lid, type, href, link, img, new_win, view_level, lup, status, displayorder) VALUES ('', 'link', '$newlinkhref', '$newlinkname', '$newlinkimg', '$newwin', '$newviewlvl', '0', '$newlinkstatus', '$newlinkorder')");
        }

        if ($newsubname != $lang['textnewsublink'] && $newsubname != '' && $newsubhref != $lang['textnewsubhref'] && $newsubhref != '') {
            $newsubname = addslashes($newsubname);
            $newsubimg  = ($newsubimg != $lang['textnewsubimg']) ? $newsubimg : '';
            $newsubwin  = ((int) $newsubwin == 1) ? 1 : 0;
            $newsubvlvl = ($new_sub_view_level != '') ? $new_sub_view_level : 'guest';
            $db->query("INSERT INTO $table_headerlinks (lid, type, href, link, img, new_win, view_level, lup, status, displayorder) VALUES ('', 'sub', '$newsubhref', '$newsubname', '$newsubimg', '$newsubwin', '$newsubvlvl', '$newsublup', '$newsubstatus', '$newsuborder')");
        }

        // Update Settings table last...
        $linkimagesnew  = ($linkimagesnew == 'on') ? 'on' : 'off';
        $headerlinksnew = (int) $headerlinksnew;

        $db->query("UPDATE $table_settings SET linkimages='$linkimagesnew', linkdivider='$linkdividernew', headerlinks='$headerlinksnew'");

        echo "<tr bgcolor=\"$altbg2\" class=\"tablerow\"><td align=\"center\">$lang[textheaderlinksupdate]</td></tr>";
        redirect('./cp.php?action=headerlinks', 2);
    } else {
        $links = array();
        $subs = array();
        $linklist = array();
        $headerlinks = array();
        $i = 0;
        $query = $db->query("SELECT * FROM $table_headerlinks ORDER BY lup ASC, displayorder ASC");
        while($link = $db->fetch_array($query)) {
            if ($link['type'] == 'link') {
                $links[$i]['lid'] = $link['lid'];
                $links[$i]['href'] = $link['href'];
                $links[$i]['link'] = htmlspecialchars($link['link']);
                $links[$i]['img'] = $link['img'];
                $links[$i]['new_win'] = (int) $link['new_win'];
                $links[$i]['view_level'] = $link['view_level'];
                $links[$i]['displayorder'] = $link['displayorder'];
                $links[$i]['status'] = $link['status'];
                $links[$i]['lup'] = $link['lup'];
                $linklist[$i]['lid'] = $link['lid'];
                $linklist[$i]['link'] = htmlspecialchars($link['link']);
                $headerlinks[$i] = $link['lid'];
            } elseif ($link['type'] == 'sub') {
                $id = (empty($link['lup'])) ? 0 : $link['lup'];
                $subs["$id"][$i]['lid'] = $link['lid'];
                $subs["$id"][$i]['href'] = $link['href'];
                $subs["$id"][$i]['link'] = htmlspecialchars($link['link']);
                $subs["$id"][$i]['img'] = $link['img'];
                $subs["$id"][$i]['new_win'] = (int) $link['new_win'];
                $subs["$id"][$i]['view_level'] = $link['view_level'];
                $subs["$id"][$i]['displayorder'] = $link['displayorder'];
                $subs["$id"][$i]['status'] = $link['status'];
                $subs["$id"][$i]['lup'] = $link['lup'];
            }
            $i++;
        }

        $linkImgOn = $linkImgOff = '';
        if ($SETTINGS['linkimages'] == 'on') {
            $linkImgOn = $selHTML;
        } else {
            $linkImgOff = $selHTML;
        }

        ?>
        <script language="JavaScript">
        var headerLinkIDs = new Array(<?php echo implode(', ', $headerlinks)?>);
        var hlDelConfirm  = '<?php echo $lang['hldelconfirm']?>';
        </script>

        <tr bgcolor="<?php echo $altbg2?>">
        <td>
        <form method="post" action="cp.php?action=headerlinks" onSubmit="return checkHLForm(hlDelConfirm);">
        <table cellspacing="0" cellpadding="0" border="0" width="90%" align="center">
        <tr>
        <td bgcolor="<?php echo $bordercolor?>">
        <table border="0" cellspacing="<?php echo $borderwidth?>" cellpadding="<?php echo $tablespace?>" width="100%">
        <tr>
        <td colspan="2" class="category"><font color="<?php echo $cattext?>"><strong><?php echo $lang['textlinkopts']?></strong></font></td>
        </tr>
        <tr class="tablerow">
        <td bgcolor="<?php echo $altbg1?>"><?php echo $lang['linkimages']?></td>
        <td bgcolor="<?php echo $altbg2?>">
        <select name="linkimagesnew">
        <option value="on" <?php echo $linkImgOn?>><?php echo $lang['texton']?></option>
        <option value="off" <?php echo $linkImgOff?>><?php echo $lang['textoff']?></option>
        </select>
        </td>
        </tr>
        <tr class="tablerow">
        <td bgcolor="<?php echo $altbg1?>"><?php echo $lang['linkdivider']?></td>
        <td bgcolor="<?php echo $altbg2?>"><input type="text" name="linkdividernew" size="4" value="<?php echo $SETTINGS['linkdivider']?>" /></td>
        </tr>
        <tr class="tablerow">
        <td bgcolor="<?php echo $altbg1?>"><?php echo $lang['headerlinks']?></td>
        <td bgcolor="<?php echo $altbg2?>"><input type="text" name="headerlinksnew" size="4" value="<?php echo $SETTINGS['headerlinks']?>" /></td>
        </tr>
        <tr bgcolor="<?php echo $altbg1?>" class="tablerow">
        <td colspan="2">&nbsp;</td>
        </tr>
        <tr bgcolor="<?php echo $altbg1?>" class="tablerow">
        <td colspan="2" align="center"><?php echo $lang['linkoptshelp']?></td>
        </tr>
        <?php

        foreach($links as $link) {
            $on = $off = '';
            switch($link['status']) {
                case 'on':
                    $on = $selHTML;
                    break;

                default:
                    $off = $selHTML;
                    break;
            }

            $adminSel = $staffSel = $memberSel = $guestSel = '';
            switch($link['view_level']) {
                case 'admin':
                    $adminSel = $selHTML;
                    break;

                case 'staff':
                    $staffSel = $selHTML;
                    break;

                case 'member':
                    $memberSel = $selHTML;
                    break;

                case 'guest':
                    $guestSel = $selHTML;
                    break;
            }

            $newWin = ($link['new_win'] == 1) ? 'checked="checked"' : '';
            ?>
            <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
            <td colspan="2" class="smalltxt"><input type="checkbox" name="delete<?php echo $link['lid']?>" value="<?php echo $link['lid']?>" />
            &nbsp;<input type="text" name="link<?php echo $link['lid']?>" value="<?php echo stripslashes($link['link'])?>" />
            &nbsp;<input type="text" name="href<?php echo $link['lid']?>" value="<?php echo $link['href']?>" />
            &nbsp;<input type="text" name="img<?php echo $link['lid']?>" value="<?php echo $link['img']?>" />
            &nbsp; <?php echo $lang['textorder']?> <input type="text" name="displayorder<?php echo $link['lid']?>" size="2" value="<?php echo $link['displayorder']?>" />
            &nbsp; <select name="status<?php echo $link['lid']?>">
            <option value="on" <?php echo $on?>><?php echo $lang['texton']?></option><option value="off" <?php echo $off?>><?php echo $lang['textoff']?></option></select>
            <select name="view_level<?php echo $link['lid']?>">
            <option value=""><?php echo $lang['textviewlevel']?></option>
            <option value="admin" <?php echo $adminSel?>><?php echo $lang['textpermission2']?></option>
            <option value="staff" <?php echo $staffSel?>><?php echo $lang['textpermission3']?></option>
            <option value="member" <?php echo $memberSel?>><?php echo $lang['textmembers']?></option>
            <option value="guest" <?php echo $guestSel?>><?php echo $lang['textguests']?></option>
            </select>
            &nbsp; <input type="checkbox" name="newwin<?php echo $link['lid']?>" value="1" <?php echo $newWin?> /> <?php echo $lang['textnewwin']?>
            </td>
            </tr>
            <?php
            if (array_key_exists("$link[lid]", $subs)) {
                foreach($subs[$link['lid']] as $sub) {
                    $on = $off = '';
                    switch($sub['status']) {
                        case 'on':
                            $on = $selHTML;
                            break;

                        default:
                            $off = $selHTML;
                            break;
                    }

                    $adminSel = $staffSel = $memberSel = $guestSel = '';
                    switch($sub['view_level']) {
                        case 'admin':
                            $adminSel = $selHTML;
                            break;

                        case 'staff':
                            $staffSel = $selHTML;
                            break;

                        case 'member':
                            $memberSel = $selHTML;
                            break;

                        case 'guest':
                            $guestSel = $selHTML;
                            break;
                    }

                    $newSubWin = ($sub['new_win'] == 1) ? 'checked="checked"' : '';
                    ?>
                    <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
                    <td colspan="2" class="smalltxt"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="checkbox" name="delete<?php echo $sub['lid']?>" value="<?php echo $sub['lid']?>" />
                    &nbsp;<input type="text" name="link<?php echo $sub['lid']?>" value="<?php echo stripslashes($sub['link'])?>" />
                    &nbsp;<input type="text" name="href<?php echo $sub['lid']?>" value="<?php echo $sub['href']?>" />
                    &nbsp;<input type="text" name="img<?php echo $sub['lid']?>" value="<?php echo $sub['img']?>" />
                    &nbsp; <?php echo $lang['textorder']?> <input type="text" name="displayorder<?php echo $sub['lid']?>" size="2" value="<?php echo $sub['displayorder']?>" />
                    &nbsp; <select name="status<?php echo $sub['lid']?>">
                    <option value="on" <?php echo $on?>><?php echo $lang['texton']?></option><option value="off" <?php echo $off?>><?php echo $lang['textoff']?></option></select>
                    <select name="view_level<?php echo $sub['lid']?>">
                    <option value=""><?php echo $lang['textviewlevel']?></option>
                    <option value="admin" <?php echo $adminSel?>><?php echo $lang['textpermission2']?></option>
                    <option value="staff" <?php echo $staffSel?>><?php echo $lang['textpermission3']?></option>
                    <option value="member" <?php echo $memberSel?>><?php echo $lang['textmembers']?></option>
                    <option value="guest" <?php echo $guestSel?>><?php echo $lang['textguests']?></option>
                    </select>
                    &nbsp; <select name="moveto<?php echo $sub['lid']?>">
                    <?php
                    foreach($linklist as $movelink) {
                        if ($movelink['lid'] == $link['lid']) {
                            echo '<option value="'.$movelink['lid'].'" selected="selected">'.stripslashes($movelink['link']).'</option>';
                        } else {
                            echo '<option value="'.$movelink['lid'].'">'.stripslashes($movelink['link']).'</option>';
                        }
                    }
                    ?>
                    </select>
                    &nbsp; <input type="checkbox" name="newwin<?php echo $sub['lid']?>" value="1" <?php echo $newSubWin?> /> <?php echo $lang['textnewwin']?>
                    </td>
                    </tr>
                    <?php
                }
            }
        }
        ?>
        <tr bgcolor="<?php echo $altbg1?>" class="tablerow">
        <td colspan="2">&nbsp;</td>
        </tr>
        <tr bgcolor="<?php echo $altbg1?>" class="tablerow">
        <td colspan="2" class="smalltxt"><input type="text" name="newlinkname" value="<?php echo $lang['textnewlink']?>" onfocus="if (this.value == '<?php echo $lang['textnewlink']?>') {this.value='';}" />
        &nbsp; <input type="text" name="newlinkhref" value="<?php echo $lang['textnewlinkhref']?>" onfocus="if (this.value == '<?php echo $lang['textnewlinkhref']?>') {this.value='';}" />
        &nbsp; <input type="text" name="newlinkimg" value="<?php echo $lang['textnewlinkimg']?>" onfocus="if (this.value == '<?php echo $lang['textnewlinkimg']?>') { this.value = '';}" />
        &nbsp; <?php echo $lang['textorder']?> <input type="text" name="newlinkorder" size="2" />
        &nbsp; <select name="newlinkstatus"><option value="on"><?php echo $lang['texton']?></option><option value="off"><?php echo $lang['textoff']?></option></select>
        &nbsp; <select name="new_view_level">
               <option value=""><?php echo $lang['textviewlevel']?></option>
               <option value="admin" <?php echo $adminSel?>><?php echo $lang['textpermission2']?></option>
               <option value="staff" <?php echo $staffSel?>><?php echo $lang['textpermission3']?></option>
               <option value="member" <?php echo $memberSel?>><?php echo $lang['textmembers']?></option>
               <option value="guest" <?php echo $guestSel?>><?php echo $lang['textguests']?></option>
               </select>
        &nbsp; <input type="checkbox" name="newlinkwin" value="1" /> <?php echo $lang['textnewwin']?>
        </td>
        </tr>
        <tr bgcolor="<?php echo $altbg1?>" class="tablerow">
        <td colspan="2" class="smalltxt"><input type="text" name="newsubname" value="<?php echo $lang['textnewsublink']?>" onfocus="if (this.value == '<?php echo $lang['textnewsublink']?>') {this.value='';}" />
        &nbsp; <input type="text" name="newsubhref" value="<?php echo $lang['textnewsubhref']?>" onfocus="if (this.value == '<?php echo $lang['textnewsubhref']?>') {this.value='';}" />
        &nbsp; <input type="text" name="newsubimg" value="<?php echo $lang['textnewsubimg']?>" onfocus="if (this.value == '<?php echo $lang['textnewsubimg']?>') { this.value = ''; }" />
        &nbsp; <?php echo $lang['textorder']?> <input type="text" name="newsuborder" size="2" />
        &nbsp; <select name="newsubstatus"><option value="on"><?php echo $lang['texton']?></option><option value="off"><?php echo $lang['textoff']?></option></select>
        &nbsp; <select name="newsublup">

        <?php
        foreach ($linklist as $link) {
            echo '<option value="'.$link['lid'].'">'.stripslashes($link['link']).'</option>';
        }
        ?>

        </select>
        &nbsp; <select name="new_sub_view_level">
               <option value=""><?php echo $lang['textviewlevel']?></option>
               <option value="admin" <?php echo $adminSel?>><?php echo $lang['textpermission2']?></option>
               <option value="staff" <?php echo $staffSel?>><?php echo $lang['textpermission3']?></option>
               <option value="member" <?php echo $memberSel?>><?php echo $lang['textmembers']?></option>
               <option value="guest" <?php echo $guestSel?>><?php echo $lang['textguests']?></option>
               </select>
        &nbsp; <input type="checkbox" name="newsubwin" value="1" /> <?php echo $lang['textnewwin']?>
        </td>
        </tr>
        <tr>
        <td colspan="2" bgcolor="<?php echo $altbg2?>" class="tablerow" align="center"><input type="submit" name="linksubmit" value="<?php echo $lang['textsubmitchanges']?>" class="submit" /></td>
        </tr>
        </table>
        </td>
        </tr>
        </table>
        </form>
        </td>
        </tr>
        <?php
    }
}
// Header Links Control Advanced Mod End

============================================================================================================================
=======
Step 5:
=======
==================
Edit File: functions.php
==================
==========
Find Code:
==========

function iso8601_date($year=0, $month=0, $day=0) {

===============
Add Code Above:
===============

// Header Links Control Advanced Mod Begin
function compileHeaderLinks() {
    global $db, $table_headerlinks, $imgdir, $lang, $SETTINGS, $THEME;

    $links = array();
    $subs = array();
    $subDivs = array();
    $i = 0;

    $query = $db->query("SELECT lid, href, link, img, new_win, view_level FROM $table_headerlinks WHERE type='link' AND status='on' ORDER BY displayorder ASC");
    $subquery = $db->query("SELECT lid, href, link, img, new_win, view_level, lup FROM $table_headerlinks WHERE type='sub' AND status='on' ORDER BY displayorder ASC");
    while($sub = $db->fetch_array($subquery)) {
        $subs["$sub[lup]"][$i]['href'] = $sub['href'];
        $subs["$sub[lup]"][$i]['link'] = $sub['link'];
        $subs["$sub[lup]"][$i]['img'] = $sub['img'];
        $subs["$sub[lup]"][$i]['view_level'] = $sub['view_level'];
        $subs["$sub[lup]"][$i]['new_win'] = (int) $sub['new_win'];
        $i++;
    }
    $db->free_result($subquery);

    // Uncomment this block of code if the Portal is installed
    /*
    // Portal-link
    if ($SETTINGS['portalstatus'] == 'on') {
        if (false === strpos($GLOBALS['url'], 'portal.php') || false !== strpos($GLOBALS['url'], 'cp_portal.php')) {
            $links[] = '<img src="'.$THEME['imgdir'].'/portal.gif" alt="'.$lang['portalnav'].'" title="'.$lang['portalnav'].'" border="0" /> <a href="portal.php"><font class="navtd">'.$lang['portalnav'].'</font></a>';
        } else {
            $links[] = '<img src="'.$THEME['imgdir'].'/portal.gif" alt="'.$lang['portalindexnav'].'" title="'.$lang['portalindexnav'].'" border="0" /> <a href="index.php?forums"><font class="navtd">'.$lang['portalindexnav'].'</font></a>';
        }
    }
    */

    while($link = $db->fetch_array($query)) {
        $img = ($link['img'] != '') ? '<img src="'.$imgdir.'/'.$link['img'].'" alt="'.$link['link'].'" border="0" />&nbsp;' : '';
        $target = ($link['new_win'] == 1) ? 'target="_blank" ' : '';
        $href = (strpos($link['href'], 'http:') === false && strpos($link['href'], 'ftp:') === false && strpos($link['href'], 'https:') === false && strpos($link['href'], '#') === false && strpos($link['href'], './') === false && strpos($link['href'], '../') === false) ? ROOT.stripslashes($link['href']) : stripslashes($link['href']);
        $text = stripslashes($link['link']);

        if (ord(substr($text, 0, 1)) == 36) {
            // Assume it's a lang var and eval...
            eval('$text = "'.$text.'";');
        }

        $class = (array_key_exists("$link[lid]", $subs)) ? 'class="header-link-'.$link['lid'].'" ' : '';

        $canView = getLinkViewPermissions($link['view_level']);
        if ($canView) {
            // Do NOT remove the class name from the links. That is so the javascript can find the headerlinks!
            $links[] = $img.'<a href="'.$href.'" '.$target.$class.'><font class="navtd">'.$text.'</font></a>';
        }

        if (array_key_exists("$link[lid]", $subs)) {
            $subDiv = array();
            $subDiv[] = '<div id="sub-links-'.$link['lid'].'" class="headermenu" style="width:150px;display: none;">';
            foreach($subs[$link['lid']] as $sub) {
                $img = ($sub['img'] != '') ? '<img src="'.$imgdir.'/'.$sub['img'].'" alt="'.$sub['link'].'" border="0" />&nbsp;' : '';
                $target = ($sub['new_win'] == 1) ? 'target="_blank" ' : '';
                $href = (strpos($sub['href'], 'http:') === false && strpos($sub['href'], 'ftp:') === false && strpos($sub['href'], 'https:') === false && strpos($sub['href'], '#') === false && strpos($sub['href'], './') === false && strpos($sub['href'], '../') === false) ? ROOT.stripslashes($sub['href']) : stripslashes($sub['href']);
                $text = stripslashes($sub['link']);

                if (ord(substr($text, 0, 1)) == 36) {
                    eval('$text = "'.$text.'";');
                }

                $canView = getLinkViewPermissions($sub['view_level']);

                if ($canView) {
                    $subDiv[] = '<a href="'.$href.'" '.$target.'>'.$img.$text.'</a>';
                }
            }
            $subDiv[] = '</div>';
            $subDiv = implode("\n", $subDiv);
            $subDivs[] = $subDiv;
        }
    }

    // Check if bbrules are on, and add in that link.
    if ($SETTINGS['bbrules'] == 'on') {
        $links[] = "<img src=\"$imgdir/bbrules.gif\" alt=\"$lang[altrules]\" border=\"0\" /> <a href=\"faq.php?page=forumrules\"><font class=\"navtd\">$lang[textbbrules]</font></a>";
    }

    $subDivs = implode("\n", $subDivs);
    $links[] = $subDivs;

    return $links;
}

function compilePlugLinks() {
    global $plugname, $plugurl, $plugadmin, $plugimg, $SETTINGS;

    if (!isset($plugname)) {
        $plugname = array();
    }

    $pluglinks = array();

    for($i=0;$i<count($plugname);$i++) {
        if (!empty($plugname[$i]) && !empty($plugurl[$i])) {
            $img = (trim($plugimg[$i]) != '') ? '<img src="'.$plugimg[$i].'" border="0" />&nbsp;' : '';

            if ($plugadmin[$i] !== true || X_ADMIN) {
                $pluglinks[] = '<a href="'.$plugurl[$i].'"><font class="navtd">'.$img.$plugname[$i].'</font></a>';
            }
        }
    }
    return $pluglinks;
}

function compileLinkDisplay($links, $pluglinks, $imgStatus, $divider) {
    $linkcount = $GLOBALS['SETTINGS']['headerlinks'];
    $linkdisplay = '';
    $divide = '';
    $count = 0;

    $linkDivs = array_pop($links);

    $links = $links + $pluglinks; // Do not use array_merge() here!
    foreach($links as $num => $link) {
        if ($count == $linkcount) {
            $divide = '<br />';
            $count  = 0;
        }
        $linkdisplay .= $divide . $link;
        $divide = ' '.$divider.' ';
        $count++;
    }

    if ($imgStatus == 'off') {
        $linkdisplay = preg_replace('/<img(.*?) \/>/mi', '', $linkdisplay);
        $linkDivs    = preg_replace('/<img(.*?) \/>/mi', '', $linkDivs);
    }
    return $linkdisplay."\n".$linkDivs;
}

function getLinkViewPermissions($level) {
    switch($level) {
        case 'admin':
            return X_ADMIN;
            break;
        case 'staff':
            return X_STAFF;
            break;
        case 'member':
            return X_MEMBER;
            break;
        case 'guest':
            return true;
            break;
    }
}
// Header Links Control Advanced Mod End

============================================================================================================================
=======
Step 6:
=======
===========================
Edit File: include/admin.user.inc.php
===========================
==========
Find Code:
==========

    &raquo;&nbsp;<a href="cp2.php?action=smilies"><?php echo $lang['smilies']?></a><br />

===============
Add Code Above:
===============

    <!-- Header Links Control Advanced Mod Begin -->
    &raquo;&nbsp;<a href="cp.php?action=headerlinks"><?php echo $lang['textheaderlinks']?></a><br />
    <!-- Header Links Control Advanced Mod End -->

============================================================================================================================
=======
Step 7:
=======
===============================
Go To Administration Panel --> Templates
===============================
=================
Edit Template: header
=================
==========
Find Code:
==========

<script language="JavaScript" type="text/javascript" src="./include/header.js"></script>

===============
Add Code Below:
===============

<script language="JavaScript" type="text/javascript" src="./include/headerlinks.js"></script>

=====
Find:
=====

$links   $pluglink

=============
Replace With:
=============

$linkdisplay

============================================================================================================================
=======
Step 8:
=======
===============================
Go To Administration Panel --> Templates
===============================
=====================
Edit Template: index_ticker
=====================
==========
Find Code:
=========

window.onload = tickerstart;

================
Replace Code With:
================

registerLoadFunc(tickerstart);

============================================================================================================================
=======
Step 9:
=======
===============================
Go To Administration Panel --> Templates
===============================
=========================
Edit Template: functions_bbcode
=========================
==========
Find Code:
==========

window.onload = loadEls;

============
Replace With:
============

registerLoadFunc(loadEls);

============================================================================================================================
========
Step 10:
========
================================
Go To Administration Panel --> Templates
================================
===============
Edit Template: css
===============
==========
Find Code:
==========

.header2 {
    background-color: $altbg1;
    font-family: Verdana;
    font-size: 11px;
    font-weight: bold;
    table-layout: fixed;
}

===============
Add Code Below:
===============

div.headermenu {
    position: absolute;
    background-color: $header;
    border-bottom-width: 0;
    border: 1px solid $bordercolor;
    border-bottom: none;
    font: normal 12px $font;
    z-index:100;
}

.headermenu a {
    width: 100%;
    display: block;
    border-bottom: 1px solid $bordercolor;
    color: $headertext;
    font-size: 11px;
    padding: 1px 0;
    text-decoration: none;
    text-indent: 3px;
}

.headermenu a:hover {
    background-color: $altbg1;
    text-decoration: none;
}

============================================================================================================================
========
Step 11:
========

Upload headerlinks.js from the 'Contents' folder to your forum's 'include' directory

============================================================================================================================
Enjoy!