+// Process menu editing form
+function adminProcessMenuEditForm ($type, $subMenu) {
+ // An action is done...
+ foreach (postRequestElement('sel') as $sel => $menu) {
+ $AND = "(`what` = '' OR `what` IS NULL)";
+
+ $sel = bigintval($sel);
+
+ if (!empty($subMenu)) {
+ $AND = "`action`='" . $subMenu . "'";
+ } // END - if
+
+ switch (postRequestElement('ok')) {
+ case 'edit': // Edit menu
+ // Shall we update a menu or sub menu?
+ if (!isGetRequestElementSet('sub')) {
+ // Update with 'what'=null
+ SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_%s_menu` SET `title`='%s',`action`='%s',`what`=NULL WHERE ".$AND." AND `id`=%s LIMIT 1",
+ array(
+ $type,
+ $menu,
+ postRequestElement('sel_action', $sel),
+ $sel
+ ), __FUNCTION__, __LINE__);
+ } else {
+ // Update with selected 'what'
+ SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_%s_menu` SET `title`='%s',`action`='%s',`what`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
+ array(
+ $type,
+ $menu,
+ postRequestElement('sel_action', $sel),
+ postRequestElement('sel_what', $sel),
+ $sel
+ ), __FUNCTION__, __LINE__);
+ }
+ break;
+
+ case 'delete': // Delete menu
+ SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
+ array(
+ $type,
+ $sel
+ ), __FUNCTION__, __LINE__);
+ break;
+
+ case 'status': // Change status of menus
+ SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_%s_menu` SET `visible`='%s',`locked`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
+ array(
+ $type,
+ postRequestElement('visible', $sel),
+ postRequestElement('locked', $sel),
+ $sel
+ ), __FUNCTION__, __LINE__);
+ break;
+
+ default: // Unexpected action
+ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unsupported action %s detected.", postRequestElement('ok')));
+ displayMessage('{%message,ADMIN_UNKNOWN_OKAY=' . postRequestElement('ok') . '%}');
+ break;
+ } // END - switch
+ } // END - foreach
+
+ // Load template
+ displayMessage('{--SETTINGS_SAVED--}');
+}
+
+// Handle weightning
+function doAdminProcessMenuWeightning ($type, $AND) {
+ // Are there all required (generalized) GET parameter?
+ if ((isGetRequestElementSet('act')) && (isGetRequestElementSet('tid')) && (isGetRequestElementSet('fid'))) {
+ // Init variables
+ $tid = ''; $fid = '';
+
+ // Get ids
+ if (isGetRequestElementSet('w')) {
+ // Sub menus selected
+ $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `action`='%s' AND `sort`=%s LIMIT 1",
+ array(
+ $type,
+ getRequestElement('act'),
+ bigintval(getRequestElement('tid'))
+ ), __FUNCTION__, __LINE__);
+ list($tid) = SQL_FETCHROW($result);
+ SQL_FREERESULT($result);
+ $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `action`='%s' AND `sort`=%s LIMIT 1",
+ array(
+ $type,
+ getRequestElement('act'),
+ bigintval(getRequestElement('fid'))
+ ), __FUNCTION__, __LINE__);
+ list($fid) = SQL_FETCHROW($result);
+ SQL_FREERESULT($result);
+ } else {
+ // Main menu selected
+ $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`=%s LIMIT 1",
+ array(
+ $type,
+ bigintval(getRequestElement('tid'))
+ ), __FUNCTION__, __LINE__);
+ list($tid) = SQL_FETCHROW($result);
+ SQL_FREERESULT($result);
+ $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`=%s LIMIT 1",
+ array(
+ $type,
+ bigintval(getRequestElement('fid'))
+ ), __FUNCTION__, __LINE__);
+ list($fid) = SQL_FETCHROW($result);
+ SQL_FREERESULT($result);
+ }
+
+ if ((!empty($tid)) && (!empty($fid))) {
+ // Sort menu
+ SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_%s_menu` SET `sort`=%s WHERE ".$AND." AND `id`=%s LIMIT 1",
+ array(
+ $type,
+ bigintval(getRequestElement('tid')),
+ bigintval($fid)
+ ), __FUNCTION__, __LINE__);
+ SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_%s_menu` SET `sort`=%s WHERE ".$AND." AND `id`=%s LIMIT 1",
+ array(
+ $type,
+ bigintval(getRequestElement('fid')),
+ bigintval($tid)
+ ), __FUNCTION__, __LINE__);
+ } // END - if
+ } // END - if
+}
+