function saveOrders($sTop, $aCustom)
{
    db_res("UPDATE `TopMenu` SET `Order` = 0, `Parent` = 0");
    $sTop = trim($sTop, ' ,');
    $aTopIDs = explode(',', $sTop);
    foreach ($aTopIDs as $iOrd => $iID) {
        $iID = trim($iID, ' ,');
        $iID = (int) $iID;
        if (!$iID) {
            continue;
        }
        db_res("UPDATE `TopMenu` SET `Order` = {$iOrd}, `Type` = 'top' WHERE `ID` = {$iID}");
    }
    foreach ($aCustom as $iParent => $sCustom) {
        $iParent = (int) $iParent;
        $sCustom = trim($sCustom, ' ,');
        $aCustomIDs = explode(',', $sCustom);
        foreach ($aCustomIDs as $iOrd => $iID) {
            $iID = trim($iID, ' ,');
            $iID = (int) $iID;
            if (!$iID) {
                continue;
            }
            db_res("UPDATE `TopMenu` SET `Order` = {$iOrd}, `Type` = 'custom', `Parent`={$iParent} WHERE `ID` = {$iID}");
        }
    }
    compileMenus();
}
    compileMenus();
    header('location:' . $_SERVER['PHP_SELF']);
}
if ($_GET['ID'] && 'delete' == $_GET['action']) {
    // Process deleting
    delete_item($_GET['ID'], $res);
    compileMenus();
    header('location:' . $_SERVER['PHP_SELF']);
}
if (isset($_POST['Add'])) {
    add_or_edit_item();
    compileMenus();
}
if ('reset' == $_GET['action']) {
    reset_menu();
    compileMenus();
    header('location:' . $_SERVER['PHP_SELF']);
}
TopCodeAdmin();
ContentBlockHead("Member Menu");
// Get a list of all fields.
$query_str = "SELECT * FROM `MemberMenu` ORDER BY `MenuOrder` ASC";
$res = db_res($query_str);
if ($_GET['action'] == 'upload') {
    display_form((int) $_GET['ID']);
} else {
    echo "<p class=text><a href=\"{$_SERVER['PHP_SELF']}?action=upload\">Add new item</a></p>\n";
    echo "<p class=text><a href=\"{$_SERVER['PHP_SELF']}?action=reset\">Reset items</a></p>\n";
    display_menu($res);
}
ContentBlockFoot();