+// 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
+ sqlQueryEscaped("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'
+ sqlQueryEscaped("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
+ sqlQueryEscaped("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
+ sqlQueryEscaped("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 = sqlQueryEscaped("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) = sqlFetchRow($result);
+ sqlFreeResult($result);
+ $result = sqlQueryEscaped("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) = sqlFetchRow($result);
+ sqlFreeResult($result);
+ } else {
+ // Main menu selected
+ $result = sqlQueryEscaped("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) = sqlFetchRow($result);
+ sqlFreeResult($result);
+ $result = sqlQueryEscaped("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) = sqlFetchRow($result);
+ sqlFreeResult($result);
+ }
+
+ if ((!empty($tid)) && (!empty($fid))) {
+ // Sort menu
+ sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_%s_menu` SET `sort`=%s WHERE ".$AND." AND `id`=%s LIMIT 1",
+ array(
+ $type,
+ bigintval(getRequestElement('tid')),
+ bigintval($fid)
+ ), __FUNCTION__, __LINE__);
+ sqlQueryEscaped("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
+}
+
+// Function to register first admin
+function registerFirstAdmin () {
+ // Make sure that no admin is registered
+ assert(!isAdminRegistered());
+
+ // Admin is not registered so we have to inform the user
+ if ((isFormSent('add_first_admin')) && ((!isPostRequestElementSet('admin_login')) || (!isPostRequestElementSet('admin_password1')) || (strlen(postRequestElement('admin_password1')) < getConfig('minium_admin_pass_length')) || (!isPostRequestElementSet('admin_password2')) || (strlen(postRequestElement('admin_password2')) < getConfig('minium_admin_pass_length')) || (postRequestElement('admin_password1') != postRequestElement('admin_password2')))) {
+ setPostRequestElement('add_first_admin', '***');
+ } // END - if
+
+ // Clear error message
+ $errorMessage = '';
+ $ret = 'init';
+
+ // Is form for first admin sent?
+ if ((isFormSent('add_first_admin')) && (postRequestElement('add_first_admin') != '***')) {
+ // Hash the password with the old function because we are here in install mode
+ $hashedPass = md5(postRequestElement('admin_password1'));
+
+ // Kill maybe existing session variables
+ destroyAdminSession();
+
+ // Do registration
+ $ret = addAdminAccount(postRequestElement('admin_login'), $hashedPass, getWebmaster(), 'allow');
+
+ // Check if registration wents fine
+ switch ($ret) {
+ case 'done':
+ // Change ADMIN_REGISTERED entry
+ $done = changeDataInLocalConfigurationFile('ADMIN-SETUP', "setConfigEntry('ADMIN_REGISTERED', '", "');", 'Y', 0);
+
+ // Was it successfull?
+ if ($done === TRUE) {
+ // Registering is done
+ redirectToUrl('modules.php?module=admin&register=done');
+ } else {
+ // Registration incomplete
+ $errorMessage = '{--ADMIN_CANNOT_COMPLETE--}';
+
+ // Set this to have our error message displayed
+ setPostRequestElement('add_first_admin', '***');
+ }
+ break;
+
+ case 'failed': // Registration has failed
+ $errorMessage = '{--ADMIN_REGISTER_FAILED--}';
+
+ // Set this to have our error message displayed
+ setPostRequestElement('add_first_admin', '***');
+ break;
+
+ case 'already': // Admin does already exists!
+ $errorMessage = '{--ADMIN_LOGIN_ALREADY_REG--}';
+
+ // Set this to have our error message displayed
+ setPostRequestElement('add_first_admin', '***');
+ break;
+
+ default:
+ // Any other kind will be logged
+ $errorMessage = sprintf("Unknown return code %s from ifAdminLoginDataIsValid().", $ret);
+ logDebugMessage(__FUNCTION__, __LINE__, $errorMessage);
+
+ // Set this to have our error message displayed
+ setPostRequestElement('add_first_admin', '***');
+ break;
+ } // END - switch
+ } // END - if
+
+ // Whas that action okay?
+ if ($ret != 'done') {
+ // Init login name
+ $content['admin_login'] = '';
+ if (isPostRequestElementSet('admin_login')) {
+ $content['admin_login'] = postRequestElement('admin_login');
+ } // END - if
+
+ // Init array elements
+ $content['login_message'] = '';
+ $content['password1_message'] = '';
+ $content['password2_message'] = '';
+ $content['error_message'] = '';
+
+ // Yet-another notice-fix
+ if ((isFormSent('add_first_admin')) && (postRequestElement('add_first_admin') == '***')) {
+ // Init variables
+ $loginMessage = '';
+ $password1Message = '';
+ $password2Message = '';
+
+ // No login entered?
+ if (empty($content['admin_login'])) {
+ $loginMessage = '{--ADMIN_NO_LOGIN--}';
+ } // END - if
+
+ // An error comes back from registration?
+ if ((!empty($ret)) && ($ret != 'init')) {
+ $loginMessage = $errorMessage;
+ } // END - if
+
+ // No password 1 entered or to short?
+ if (!isPostRequestElementSet('admin_password1')) {
+ $password1Message = '{--ADMIN_NO_PASSWORD1--}';
+ } elseif (!isStrongPassword(postRequestElement('admin_password1'))) {
+ $password1Message = '{--ADMIN_WEAK_PASSWORD1--}';
+ }
+
+ // No password 2 entered or to short?
+ if (!isPostRequestElementSet('admin_password2')) {
+ $password2Message = '{--ADMIN_NO_PASSWORD2--}';
+ } elseif (!isStrongPassword(postRequestElement('admin_password2'))) {
+ $password2Message = '{--ADMIN_WEAK_PASSWORD2--}';
+ }
+
+ // Both didn't match?
+ if (postRequestElement('admin_password1') != postRequestElement('admin_password2')) {
+ // No match
+ if (empty($password1Message)) $password1Message = '{--ADMIN_PASSWORD1_MISMATCH--}';
+ if (empty($password2Message)) $password2Message = '{--ADMIN_PASSWORD2_MISMATCH--}';
+ } // END - if
+
+ // Output error messages
+ $content['login_message'] = loadTemplate('admin_login_msg', TRUE, $loginMessage);
+ $content['password1_message'] = loadTemplate('admin_login_msg', TRUE, $password1Message);
+ $content['password2_message'] = loadTemplate('admin_login_msg', TRUE, $password2Message);
+ $content['error_message'] = loadTemplate('admin_login_msg', TRUE, $errorMessage);
+ } // END - if
+
+ // Output message in seperate template
+ displayMessage('{--ADMIN_ACCOUNT_NOT_REGISTERED_YET--}');
+
+ // Load register template
+ loadTemplate('admin_reg_form', FALSE, $content);
+ } // END - if
+}
+