2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 08/31/2003 *
4 * =================== Last change: 11/23/2004 *
6 * -------------------------------------------------------------------- *
7 * File : admin-inc.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Administrative related functions *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Fuer die Administration benoetigte Funktionen *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2012 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
43 // Register an administrator account
44 function addAdminAccount ($adminLogin, $passHash, $adminEmail) {
45 // Login does already exist
49 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `login`='%s' LIMIT 1",
50 array($adminLogin), __FUNCTION__, __LINE__);
52 // Is the entry there?
53 if (SQL_HASZERONUMS($result)) {
54 // Ok, let's create the admin login
55 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins` (`login`, `password`, `email`) VALUES ('%s', '%s', '%s')",
60 ), __FUNCTION__, __LINE__);
67 SQL_FREERESULT($result);
73 // This function will be executed when the admin is not logged in and has submitted his login data
74 function ifAdminLoginDataIsValid ($adminLogin, $adminPassword) {
75 // First of all, no admin login is found, so the admin hash is null
79 // Get admin id from login
80 $adminId = getAdminId($adminLogin);
82 // Continue only with found admin ids
84 // Then we need to lookup the login name by getting the admin hash
85 $adminHash = getAdminHash($adminId);
87 // If this is fine, we can continue
88 if ($adminHash != '-1') {
89 // Get admin id and set it as current
90 setCurrentAdminId($adminId);
92 // Now, we need to encode the password in the same way the one is encoded in database
93 $testHash = generateHash($adminPassword, $adminHash);
95 // If they both match, the login data is valid
96 if ($testHash == $adminHash) {
106 // Prepare data array
109 'login' => $adminLogin,
110 'plain_pass' => $adminPassword,
111 'pass_hash' => $adminHash
114 // Run a special filter
115 runFilterChain('do_admin_login_' . $ret, $data);
121 // Only be executed on cookie checking
122 function ifAdminCookiesAreValid ($adminLogin, $passHash) {
123 // First of all, no admin login is found
126 // Then we need to lookup the login name by getting the admin hash
127 $adminHash = getAdminHash($adminLogin);
129 // If this is fine, we can continue
130 if ($adminHash != '-1') {
131 // Now, we need to encode the password in the same way the one is encoded in database
132 $testHash = encodeHashForCookie($adminHash);
133 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminLogin=' . $adminLogin . ',passHash='.$passHash.',adminHash='.$adminHash.',testHash='.$testHash);
135 // If they both match, the login data is valid
136 if ($testHash != $passHash) {
137 // Passwords don't match
139 } elseif (!isAdmin()) {
140 // Is not valid session
149 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret='.$ret);
153 // Do an admin action
154 function doAdminAction () {
155 // Determine correct 'what' value
156 $what = determineWhat();
159 $action = getActionFromModuleWhat(getModule(), $what);
161 // Load welcome template
162 if (isExtensionActive('admins')) {
163 // @TODO This and the next getCurrentAdminId() call might be moved into the templates?
164 $content['welcome'] = loadTemplate('admin_welcome_admins', TRUE, getCurrentAdminId());
166 $content['welcome'] = loadTemplate('admin_welcome', TRUE, getCurrentAdminId());
169 // Load header, footer, render menu
170 $content['header'] = loadTemplate('admin_header' , TRUE, $content);
171 $content['footer'] = loadTemplate('admin_footer' , TRUE, $content);
172 $content['menu'] = addAdminMenu($action, $what);
174 // Load main template
175 loadTemplate('admin_main', FALSE, $content);
177 // Check if action/what pair is valid
178 $result_action = SQL_QUERY_ESC("SELECT
181 `{?_MYSQL_PREFIX?}_admin_menu`
186 `what`='%s' AND `what` != 'welcome'
189 `what`='' OR `what` IS NULL
200 ), __FUNCTION__, __LINE__);
202 // Is there an entry?
203 if (SQL_NUMROWS($result_action) == 1) {
204 // Is valid but does the inlcude file exists?
205 $inc = sprintf("inc/modules/admin/action-%s.php", $action);
206 if ((isIncludeReadable($inc)) && (isMenuActionValid('admin', $action, $what)) && ($GLOBALS['acl_allow'] === TRUE)) {
207 // Ok, we finally load the admin action module
209 } elseif ($GLOBALS['acl_allow'] === FALSE) {
211 loadTemplate('admin_menu_failed', FALSE, '{%message,ADMIN_ACCESS_DENIED=' . $what . '%}');
213 // Include file not found :-(
214 loadTemplate('admin_menu_failed', FALSE, '{%message,ADMIN_ACTION_404=' . $action . '%}');
217 // Invalid action/what pair found
218 loadTemplate('admin_menu_failed', FALSE, '{%message,ADMIN_ACTION_INVALID=' . $action . '/' . $what . '%}');
222 SQL_FREERESULT($result_action);
225 loadTemplate('admin_main_footer', FALSE, $content);
229 * Checks whether current admin is allowed to access given action/what
230 * combination (only one is allowed to be null!).
232 function isAdminAllowedAccessMenu ($action, $what = NULL) {
234 if (!isset($GLOBALS[__FUNCTION__][$action][$what])) {
235 // ACL is always 'allow' when no ext-admins is installed
236 // @TODO This can be rewritten into a filter
237 $GLOBALS[__FUNCTION__][$action][$what] = ((!isExtensionInstalledAndNewer('admins', '0.2.0')) || ((isExtensionActive('admins')) && (isAdminsAllowedByAcl($action, $what))));
240 // Return the cached value
241 return $GLOBALS[__FUNCTION__][$action][$what];
244 // Adds an admin menu
245 function addAdminMenu ($action, $what) {
251 $GLOBALS['menu']['description'] = array();
252 $GLOBALS['menu']['title'] = array();
255 $result_main = SQL_QUERY("SELECT
256 `action` AS `main_action`,
257 `title` AS `main_title`,
258 `descr` AS `main_descr`
260 `{?_MYSQL_PREFIX?}_admin_menu`
262 (`what`='' OR `what` IS NULL)
265 `id` DESC", __FUNCTION__, __LINE__);
267 // Are there entries?
268 if (!SQL_HASZERONUMS($result_main)) {
269 $OUT .= '<ul class="admin_menu_main">';
271 // Load all 'action' menus
272 while ($mainContent = SQL_FETCHARRAY($result_main)) {
274 $inc = sprintf("inc/modules/admin/action-%s.php", $mainContent['main_action']);
276 // Is the current admin allowed to access this 'action' menu?
277 if (isAdminAllowedAccessMenu($mainContent['main_action'])) {
278 if ($SUB === FALSE) {
279 // Insert compiled menu title and description
280 $GLOBALS['menu']['title'][$mainContent['main_action']] = $mainContent['main_title'];
281 $GLOBALS['menu']['description'][$mainContent['main_action']] = $mainContent['main_descr'];
283 $OUT .= '<li class="admin_menu"' . addJavaScriptMenuContent('admin', $mainContent['main_action'], $action, $what) . '>
284 <div class="nobr"><strong>·</strong> ';
286 // Is the file readable?
287 if (isIncludeReadable($inc)) {
288 if (($mainContent['main_action'] == $action) && (empty($what))) {
291 $OUT .= '[<a href="{%url=modules.php?module=admin&action=' . $mainContent['main_action'] . '%}">';
294 $OUT .= '<span class="bad" style="cursor:help" title="{%message,ADMIN_MENU_ACTION_404_TITLE=' . $mainContent['main_action'] . '%}">';
297 $OUT .= $mainContent['main_title'];
299 // Is the file readable?
300 if (isIncludeReadable($inc)) {
301 if (($mainContent['main_action'] == $action) && (empty($what))) {
314 $OUT .= addAdminSubMenu($mainContent, $action, $what);
322 SQL_FREERESULT($result_main);
329 // Add admin sub menu
330 function addAdminSubMenu ($mainContent, $action, $what) {
334 // Check for menu entries
335 $result_what = SQL_QUERY_ESC("SELECT
336 `what` AS `sub_what`,
337 `title` AS `sub_title`,
338 `descr` AS `sub_descr`
340 `{?_MYSQL_PREFIX?}_admin_menu`
348 array($mainContent['main_action']), __FUNCTION__, __LINE__);
350 // Remember the count for later checks
351 setAdminMenuHasEntries($mainContent['main_action'], ((!SQL_HASZERONUMS($result_what)) && (($action == $mainContent['main_action']) || (isAdminMenuJavascriptEnabled()))));
353 // Start li-tag for sub menu content
354 $OUT .= '<li class="admin_menu_sub" id="action_menu_' . $mainContent['main_action'] . '"' . addStyleMenuContent('admin', $mainContent['main_action'], $action) . '>';
356 // Are there entries?
357 if (ifAdminMenuHasEntries($mainContent['main_action'])) {
358 // Sub menu has been called
361 // Are there entries?
362 if (!SQL_HASZERONUMS($result_what)) {
364 $OUT .= '<ul class="admin_menu_sub">';
367 while ($subContent = SQL_FETCHARRAY($result_what)) {
369 $inc = sprintf("inc/modules/admin/what-%s.php", $subContent['sub_what']);
371 // Is the current admin allowed to access this 'what' menu?
372 if (isAdminAllowedAccessMenu(NULL, $subContent['sub_what'])) {
373 // Insert compiled title and description
374 $GLOBALS['menu']['title'][$subContent['sub_what']] = $subContent['sub_title'];
375 $GLOBALS['menu']['description'][$subContent['sub_what']] = $subContent['sub_descr'];
376 $OUT .= '<li class="admin_menu">
377 <div class="nobr"><strong>--></strong> ';
379 // Is the file readable?
380 if (isIncludeReadable($inc)) {
381 if ($what == $subContent['sub_what']) {
384 $OUT .= '[<a href="{%url=modules.php?module=admin&what=' . $subContent['sub_what'] . '%}">';
387 $OUT .= '<span class="bad" style="cursor:help" title="{%message,ADMIN_MENU_WHAT_404_TITLE=' . $subContent['sub_what'] . '%}">';
390 $OUT .= $subContent['sub_title'];
392 // Is the file readable?
393 if (isIncludeReadable($inc)) {
394 if ($what == $subContent['sub_what']) {
407 // Finish HTML output
412 SQL_FREERESULT($result_what);
422 // Create an admin selection box form
423 function addAdminSelectionBox ($adminId = NULL, $special = '') {
424 // Default is email as "special column"
425 $ADD = ',`email` AS `special`';
427 // Is a special column given?
428 if (!empty($special)) {
429 // Additional column for SQL query
430 $ADD = ',`' . $special . '` AS `special`';
434 $result = SQL_QUERY('SELECT
439 `{?_MYSQL_PREFIX?}_admins`
441 `login` ASC', __FUNCTION__, __LINE__);
447 while ($content = SQL_FETCHARRAY($result)) {
449 $content['default'] = '';
451 // Is the id the same?
452 if ($content['id'] == $adminId) {
453 // Set this as default
454 $content['default'] = ' selected="selected"';
458 $OUT .= loadTemplate('select_admins_option', TRUE, $content);
462 SQL_FREERESULT($result);
464 // Add form to content
465 $content['form_selection'] = $OUT;
468 loadTemplate('select_admins_box', FALSE, $content);
471 // Create a member selection box
472 function addMemberSelectionBox ($userid = NULL, $add_all = FALSE, $return = FALSE, $none = FALSE, $field = 'userid', $whereStatement = " WHERE `surname` NOT LIKE '{?tester_user_surname_prefix?}%'") {
473 // Output selection form with all confirmed user accounts listed
474 $result = SQL_QUERY('SELECT
479 `{?_MYSQL_PREFIX?}_user_data`
480 ' . $whereStatement . '
482 `userid` ASC', __FUNCTION__, __LINE__);
487 // USe this only for adding points (e.g. adding refs really makes no sence ;-) )
488 if ($add_all === TRUE) {
489 $OUT = ' <option value="all">{--ALL_MEMBERS--}</option>';
490 } elseif ($none === TRUE) {
491 $OUT = ' <option value="0">{--SELECT_NONE--}</option>';
495 while ($content = SQL_FETCHARRAY($result)) {
496 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . intval($userid) . '/' . $content['userid']);
497 $OUT .= '<option value="' . bigintval($content['userid']) . '"';
498 if (bigintval($userid, FALSE, FALSE) === bigintval($content['userid'])) {
499 $OUT .= ' selected="selected"';
501 $OUT .= '>' . $content['surname'] . ' ' . $content['family'] . ' (' . bigintval($content['userid']) . ')</option>';
505 SQL_FREERESULT($result);
507 if ($return === FALSE) {
508 // Remeber options in constant
509 $content['form_selection'] = $OUT;
510 $content['what'] = '{%pipe,getWhat%}';
513 loadTemplate('admin_form_selection_box', FALSE, $content);
515 // Return content in selection frame
516 return '<select class="form_select" name="' . handleFieldWithBraces($field) . '" size="1">' . $OUT . '</select>';
520 // Create a menu selection box for given menu system
521 // @TODO Try to rewrite this to adminAddMenuSelectionBox()
523 function adminMenuSelectionBox_DEPRECATED ($mode, $default = '', $defid = '') {
524 $what = "`what` != '' AND `what` IS NOT NULL";
525 if ($mode == 'action') $what = "(`what`='' OR `what` IS NULL) AND `action` != 'login'";
527 $result = SQL_QUERY_ESC("SELECT `%s` AS `menu`, `title` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$what." ORDER BY `sort` ASC",
528 array($mode), __FUNCTION__, __LINE__);
529 if (!SQL_HASZERONUMS($result)) {
530 // Load menu as selection
531 $OUT = '<select name="' . $mode . '_menu';
532 if ((!empty($defid)) || ($defid == '0')) $OUT .= '[' . $defid . ']';
533 $OUT .= '" size="1" class="form_select">
534 <option value="">{--SELECT_NONE--}</option>';
536 while ($content = SQL_FETCHARRAY($result)) {
537 $OUT .= '<option value="' . $content['menu'] . '"';
538 if ((!empty($default)) && ($default == $content['menu'])) {
539 $OUT .= ' selected="selected"';
541 $OUT .= '>' . $content['title'] . '</option>';
545 SQL_FREERESULT($result);
547 // Add closing select-tag
551 $OUT = '{--ADMIN_PROBLEM_NO_MENU--}';
558 // Wrapper for $_POST and adminSaveSettings
559 function adminSaveSettingsFromPostData ($tableName = '_config', $whereStatement = '`config`=0', $translateComma = array(), $alwaysAdd = FALSE, $displayMessage = TRUE) {
561 $postData = postRequestArray();
563 // Call the lower function
564 adminSaveSettings($postData, $tableName, $whereStatement, $translateComma, $alwaysAdd, $displayMessage);
567 // Save settings to the database
568 function adminSaveSettings (&$postData, $tableName = '_config', $whereStatement = '`config`=0', $translateComma = array(), $alwaysAdd = FALSE, $displayMessage = TRUE) {
569 // Prepare all arrays, variables
570 $tableData = array();
573 // Now, walk through all entries and prepare them for saving
574 //* BUG: */ reportBug(__FUNCTION__, __LINE__, '<pre>'.print_r(postRequestArray(), TRUE).'</pre>');
575 foreach ($postData as $id => $val) {
576 // Process only formular field but not submit buttons ;)
577 if ($id =='save_config') {
582 // Do not save the ok value
583 convertSelectionsToEpocheTime($postData, $tableData, $id, $skip);
585 // Shall we process this id? It muss not be empty, of course
586 if (($skip === FALSE) && (!empty($id)) && ((!isset($GLOBALS['skip_config'][$id]))) || ($tableName != '_config')) {
587 // Translate the value? (comma to dot!)
588 if ((is_array($translateComma)) && (in_array($id, $translateComma))) {
589 // Then do it here... :)
590 $val = convertCommaToDot($val);
593 // Test value on float
594 $test = (float) $val;
597 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'test=' . $test . ',val=' . $val . ',id=' . $id);
599 // Shall we add numbers or strings?
600 if ('' . $val . '' == '' . $test . '') {
602 array_push($tableData, sprintf("`%s`=%s", $id, $test));
603 } elseif (is_null($val)) {
605 array_push($tableData, sprintf("`%s`=NULL", $id));
608 array_push($tableData, sprintf("`%s`='%s'", $id, trim($val)));
611 // Do not add a config entry twice
612 $GLOBALS['skip_config'][$id] = TRUE;
614 // Update current configuration
615 setConfigEntry($id, $val);
619 // Check if entry does exist
621 if ($alwaysAdd === FALSE) {
622 if (!empty($whereStatement)) {
623 $result = SQL_QUERY("SELECT * FROM `{?_MYSQL_PREFIX?}" . $tableName . "` WHERE " . $whereStatement . " LIMIT 1", __FUNCTION__, __LINE__);
625 $result = SQL_QUERY("SELECT * FROM `{?_MYSQL_PREFIX?}" . $tableName . "` LIMIT 1", __FUNCTION__, __LINE__);
629 if (SQL_NUMROWS($result) == 1) {
630 // "Implode" all data to single string
631 $updatedData = implode(', ', $tableData);
633 // Generate SQL string
634 $sql = sprintf("UPDATE `{?_MYSQL_PREFIX?}%s` SET %s WHERE %s LIMIT 1",
640 // Add Line (does only work with AUTO_INCREMENT!
641 $keys = array(); $values = array();
642 foreach ($tableData as $entry) {
644 $line = explode('=', $entry);
645 array_push($keys , $line[0]);
646 array_push($values, $line[1]);
649 // Add both in one line
650 $keys = implode('`, `', $keys);
651 $values = implode(', ' , $values);
653 // Generate SQL string
654 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}%s` (%s) VALUES (%s)",
662 SQL_FREERESULT($result);
664 // Simply run generated SQL string
665 SQL_QUERY($sql, __FUNCTION__, __LINE__);
667 // Remember affected rows
668 $affected = SQL_AFFECTEDROWS();
671 rebuildCache('config', 'config');
673 // Settings saved, so display message?
674 if ($displayMessage === TRUE) {
676 displayMessage('{--SETTINGS_SAVED--}');
679 // Return affected rows
683 // Generate a selection box
684 function adminAddMenuSelectionBox ($menu, $type, $name, $default = '') {
685 // Open the requested menu directory
686 $menuArray = getArrayFromDirectory(sprintf("inc/modules/%s/", $menu), $type . '-', FALSE, FALSE);
688 // Init the selection box
689 $OUT = '<select name="' . $name . '" class="form_select" size="1"><option value="">{--ADMIN_IS_TOP_MENU--}</option>';
691 // Walk through all files
692 foreach ($menuArray as $file) {
693 // Is this a PHP script?
694 if ((!isDirectory($file)) && (isInString('' . $type . '-', $file)) && (isInString('.php', $file))) {
695 // Then test if the file is readable
696 $test = sprintf("inc/modules/%s/%s", $menu, $file);
698 // Is the file there?
699 if (isIncludeReadable($test)) {
700 // Extract the value for what=xxx
701 $part = substr($file, (strlen($type) + 1));
702 $part = substr($part, 0, -4);
704 // Is that part different from the overview?
705 if ($part != 'welcome') {
706 $OUT .= '<option value="' . $part . '"';
707 if ($part == $default) {
708 $OUT .= ' selected="selected"';
710 $OUT .= '>' . $part . '</option>';
716 // Close selection box
723 // Creates a user-profile link for the admin. This function can also be used for many other purposes
724 function generateUserProfileLink ($userid, $title = '', $what = '') {
726 if (!isset($GLOBALS[__FUNCTION__][$userid][$title . '_' . $what])) {
727 // Is title empty and valid userid?
728 if (($title == '') && (isValidUserId($userid))) {
729 // Set userid as title
731 } elseif (!isValidUserId($userid)) {
732 // User id zero is invalid
733 return '<strong>' . convertNullToZero($userid) . '</strong>';
738 // Then get it to 'list_user'
742 if (($title == '0') && ($what == 'list_refs')) {
743 // Return title again
745 } elseif (!empty($title)) {
746 // Not empty, so skip next one
747 } elseif (isExtensionActive('nickname')) {
749 $nick = getNickname($userid);
751 // Is it not empty, use it as title else the userid
753 $title = $nick . '(' . $userid . ')';
760 $GLOBALS[__FUNCTION__][$userid][$title . '_' . $what] = '[<a href="{%url=modules.php?module=admin&what=' . $what . '&userid=' . $userid . '%}" title="{--ADMIN_USER_PROFILE_TITLE--}">' . $title . '</a>]';
764 return $GLOBALS[__FUNCTION__][$userid][$title . '_' . $what];
767 // Check "logical-area-mode"
768 function adminGetMenuMode () {
769 // Set the default menu mode as the mode for all admins
772 // If ext-sql_patches is up-to-date enough, use the configuration
773 if (isExtensionInstalledAndNewer('sql_patches', '0.3.2')) {
774 $mode = getAdminMenu();
781 $adminId = getCurrentAdminId();
783 // Check individual settings of current admin
784 if (isset($GLOBALS['cache_array']['admin']['la_mode'][$adminId])) {
786 $adminMode = $GLOBALS['cache_array']['admin']['la_mode'][$adminId];
787 incrementStatsEntry('cache_hits');
788 } elseif (isExtensionInstalledAndNewer('admins', '0.6.7')) {
789 // Load from database when version of 'admins' is enough
790 $result = SQL_QUERY_ESC("SELECT `la_mode` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `id`=%s LIMIT 1",
791 array($adminId), __FUNCTION__, __LINE__);
793 // Is there an entry?
794 if (SQL_NUMROWS($result) == 1) {
796 list($adminMode) = SQL_FETCHROW($result);
800 SQL_FREERESULT($result);
803 // Check what the admin wants and set it when it's not the default mode
804 if ($adminMode != 'global') {
808 // Return admin-menu's mode
812 // Change activation status
813 function adminChangeActivationStatus ($IDs, $table, $row, $idRow = 'id') {
815 if ((is_array($IDs)) && (count($IDs) > 0)) {
816 // "Walk" all through and count them
817 foreach ($IDs as $id => $selected) {
818 // Secure the id number
819 $id = bigintval($id);
821 // Should always be set... ;-)
822 if (!empty($selected)) {
823 // Determine new status
824 $result = SQL_QUERY_ESC("SELECT %s FROM `{?_MYSQL_PREFIX?}_%s` WHERE %s=%s LIMIT 1",
830 ), __FUNCTION__, __LINE__);
833 if (SQL_NUMROWS($result) == 1) {
835 list($currStatus) = SQL_FETCHROW($result);
837 // And switch it N<->Y
838 $newStatus = convertBooleanToYesNo(!($currStatus == 'Y'));
840 // Change this status
841 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_%s` SET %s='%s' WHERE %s=%s LIMIT 1",
848 ), __FUNCTION__, __LINE__);
850 // Count up affected rows
851 $count += SQL_AFFECTEDROWS();
855 SQL_FREERESULT($result);
860 displayMessage(sprintf(getMessage('ADMIN_STATUS_CHANGED'), $count, count($IDs)));
863 displayMessage('{--ADMIN_NOTHING_SELECTED_CHANGE--}');
867 // Build a special template list
868 // @TODO cacheFiles is not yet supported
869 function adminListBuilder ($listType, $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUserId = array('userid'), $content = array()) {
870 // Call inner (general) function
871 doGenericListBuilder('admin', $listType, $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUserId, $content);
874 // Change status of "build" list
875 function adminBuilderStatusHandler ($mode, $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $statusArray, $rawUserId = array('userid'), $cacheFiles = array()) {
876 // $tableName must be an array
877 if ((!is_array($tableName)) || (count($tableName) != 1)) {
878 // No tableName specified
879 reportBug(__FUNCTION__, __LINE__, 'tableName is not given. Please fix your XML,tableName[]=' . gettype($tableName) . '!=array: userIdColumn=' . $userIdColumn);
880 } elseif (!is_array($idColumn)) {
881 // $idColumn is no array
882 reportBug(__FUNCTION__, __LINE__, 'idColumn[]=' . gettype($idColumn) . '!=array: userIdColumn=' . $userIdColumn);
883 } elseif ((!is_array($userIdColumn)) || (count($userIdColumn) != 1)) {
884 // $tableName is no array
885 reportBug(__FUNCTION__, __LINE__, 'userIdColumn[]=' . gettype($userIdColumn) . '!=array: userIdColumn=' . $userIdColumn);
888 // "Walk" through all entries
889 foreach (postRequestElement($idColumn[0]) as $id => $sel) {
890 // Construct SQL query
891 $sql = sprintf("UPDATE `{?_MYSQL_PREFIX?}_%s` SET", SQL_ESCAPE($tableName[0]));
893 // Load data of entry
894 $result = SQL_QUERY_ESC("SELECT * FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`=%s LIMIT 1",
899 ), __FUNCTION__, __LINE__);
902 $content = SQL_FETCHARRAY($result);
905 SQL_FREERESULT($result);
907 // Add all status entries (e.g. status column last_updated or so)
908 $newStatus = 'UNKNOWN';
909 $oldStatus = 'UNKNOWN';
910 $statusColumn = 'unknown';
911 foreach ($statusArray as $column => $statusInfo) {
912 // Does the entry exist?
913 if ((isset($content[$column])) && (isset($statusInfo[$content[$column]]))) {
914 // Add these entries for update
915 $sql .= sprintf(" `%s`='%s',", SQL_ESCAPE($column), SQL_ESCAPE($statusInfo[$content[$column]]));
918 if ($statusColumn == 'unknown') {
919 // Always (!!!) change status column first!
920 $oldStatus = $content[$column];
921 $newStatus = $statusInfo[$oldStatus];
922 $statusColumn = $column;
924 } elseif (isset($content[$column])) {
926 reportBug(__FUNCTION__, __LINE__, ':UNFINISHED: id=' . $id . ',column=' . $column . '[' . gettype($statusInfo) . '] = ' . $content[$column]);
930 // Add other columns as well
931 foreach (postRequestArray() as $key => $entries) {
933 logDebugMessage(__FUNCTION__, __LINE__, 'Found entry: ' . $key);
935 // Skip id, raw userid and 'do_$mode'
936 if (!in_array($key, array($idColumn[0], $rawUserId[0], ('do_' . $mode)))) {
937 // Are there brackets () at the end?
938 if (substr($entries[$id], -2, 2) == '()') {
939 // Direct SQL command found
940 $sql .= sprintf(" `%s`=%s,", SQL_ESCAPE($key), SQL_ESCAPE($entries[$id]));
943 $sql .= sprintf(" `%s`='%s',", SQL_ESCAPE($key), SQL_ESCAPE($entries[$id]));
946 $content[$key] = $entries[$id];
950 logDebugMessage(__FUNCTION__, __LINE__, 'Skipped: ' . $key);
954 // Finish SQL statement
955 $sql = substr($sql, 0, -1) . sprintf(" WHERE `%s`=%s AND `%s`='%s' LIMIT 1",
963 SQL_QUERY($sql, __FUNCTION__, __LINE__);
965 // Send "build mails" out
966 sendGenericBuildMails($mode, $tableName, $content, $id, $statusInfo[$content[$column]], $userIdColumn);
970 // Delete rows by given id numbers
971 function adminDeleteEntriesConfirm ($tableName, $columns = array(), $filterFunctions = array(), $extraValues = array(), $deleteNow = array(FALSE), $idColumn = array('id'), $userIdColumn = array('userid'), $rawUserId = array('userid'), $cacheFiles = array(), $content = array()) {
972 // $tableName must be an array
973 if ((!is_array($tableName)) || (count($tableName) != 1)) {
974 // No tableName specified
975 reportBug(__FUNCTION__, __LINE__, 'tableName is not given. Please fix your XML,tableName[]=' . gettype($tableName) . '!=array: userIdColumn=' . $userIdColumn);
976 } elseif (!is_array($idColumn)) {
977 // $idColumn is no array
978 reportBug(__FUNCTION__, __LINE__, 'idColumn[]=' . gettype($idColumn) . '!=array: userIdColumn=' . $userIdColumn);
979 } elseif (!is_array($userIdColumn)) {
980 // $userIdColumn is no array
981 reportBug(__FUNCTION__, __LINE__, 'userIdColumn[]=' . gettype($userIdColumn) . '!=array: userIdColumn=' . $userIdColumn);
982 } elseif (!is_array($deleteNow)) {
983 // $deleteNow is no array
984 reportBug(__FUNCTION__, __LINE__, 'deleteNow[]=' . gettype($deleteNow) . '!=array: userIdColumn=' . $userIdColumn);
987 // Shall we delete here or list for deletion?
988 if ($deleteNow[0] === TRUE) {
989 // Call generic function
990 $affected = doGenericDeleteEntriesConfirm($tableName, $columns, $filterFunctions, $extraValues, $deleteNow, $idColumn, $userIdColumn, $rawUserId, $cacheFiles);
993 if ($affected == countPostSelection($idColumn[0])) {
995 displayMessage('{--ADMIN_ALL_ENTRIES_REMOVED--}');
997 // Some are still there :(
998 displayMessage(sprintf(getMessage('ADMIN_SOME_ENTRIES_NOT_DELETED'), SQL_AFFECTEDROWS(), countPostSelection($idColumn[0])));
1001 // List for deletion confirmation
1002 adminListBuilder('delete', $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUserId, $content);
1006 // Edit rows by given id numbers
1007 function adminEditEntriesConfirm ($tableName, $columns = array(), $filterFunctions = array(), $extraValues = array(), $timeColumns = array(), $editNow = array(FALSE), $idColumn = array('id'), $userIdColumn = array('userid'), $rawUserId = array('userid'), $cacheFiles = array(), $content = array()) {
1008 // $tableName must be an array
1009 if ((!is_array($tableName)) || (count($tableName) != 1)) {
1010 // No tableName specified
1011 reportBug(__FUNCTION__, __LINE__, 'tableName is not given. Please fix your XML,tableName[]=' . gettype($tableName) . '!=array: userIdColumn=' . $userIdColumn);
1012 } elseif (!is_array($idColumn)) {
1013 // $idColumn is no array
1014 reportBug(__FUNCTION__, __LINE__, 'idColumn[]=' . gettype($idColumn) . '!=array: userIdColumn=' . $userIdColumn);
1015 } elseif (!is_array($userIdColumn)) {
1016 // $userIdColumn is no array
1017 reportBug(__FUNCTION__, __LINE__, 'userIdColumn[]=' . gettype($userIdColumn) . '!=array: userIdColumn=' . $userIdColumn);
1018 } elseif (!is_array($editNow)) {
1019 // $editNow is no array
1020 reportBug(__FUNCTION__, __LINE__, 'editNow[]=' . gettype($editNow) . '!=array: userIdColumn=' . $userIdColumn);
1023 // Shall we change here or list for editing?
1024 if ($editNow[0] === TRUE) {
1025 // Call generic change method
1026 $affected = doGenericEditEntriesConfirm($tableName, $columns, $filterFunctions, $extraValues, $timeColumns, $editNow, $idColumn, $userIdColumn, $rawUserId, $cacheFiles);
1029 if ($affected == countPostSelection($idColumn[0])) {
1031 displayMessage('{--ADMIN_ALL_ENTRIES_EDITED--}');
1033 // Some are still there :(
1034 displayMessage(sprintf(getMessage('ADMIN_SOME_ENTRIES_NOT_EDITED'), $affected, countPostSelection($idColumn[0])));
1038 adminListBuilder('edit', $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUserId, $content);
1042 // Un-/lock rows by given id numbers
1043 // @TODO rawUserId/content is not yet supported
1044 function adminLockEntriesConfirm ($tableName, $columns = array(), $filterFunctions = array(), $extraValues = array(), $statusArray = array(), $lockNow = array(FALSE), $idColumn = array('id'), $userIdColumn = array('userid')) {
1045 // $tableName must be an array
1046 if ((!is_array($tableName)) || (count($tableName) != 1)) {
1047 // No tableName specified
1048 reportBug(__FUNCTION__, __LINE__, 'tableName is not given. Please fix your XML,tableName[]=' . gettype($tableName) . '!=array: userIdColumn=' . $userIdColumn);
1049 } elseif (!is_array($idColumn)) {
1050 // $idColumn is no array
1051 reportBug(__FUNCTION__, __LINE__, 'idColumn[]=' . gettype($idColumn) . '!=array: userIdColumn=' . $userIdColumn);
1052 } elseif (!is_array($lockNow)) {
1053 // $lockNow is no array
1054 reportBug(__FUNCTION__, __LINE__, 'lockNow[]=' . gettype($lockNow) . '!=array: userIdColumn=' . $userIdColumn);
1057 // Shall we un-/lock here or list for locking?
1058 if ($lockNow[0] === TRUE) {
1060 adminBuilderStatusHandler('lock', $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $statusArray);
1063 adminListBuilder('lock', $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn);
1067 // Undelete rows by given id numbers
1068 // @TODO rawUserId/cacheFiles/content is not yet supported
1069 function adminUndeleteEntriesConfirm ($tableName, $columns = array(), $filterFunctions = array(), $extraValues = array(), $statusArray = array(), $undeleteNow = array(FALSE), $idColumn = array('id'), $userIdColumn = array('userid')) {
1070 // $tableName must be an array
1071 if ((!is_array($tableName)) || (count($tableName) != 1)) {
1072 // No tableName specified
1073 reportBug(__FUNCTION__, __LINE__, 'tableName is not given. Please fix your XML,tableName[]=' . gettype($tableName) . '!=array: userIdColumn=' . $userIdColumn);
1074 } elseif (!is_array($idColumn)) {
1075 // $idColumn is no array
1076 reportBug(__FUNCTION__, __LINE__, 'idColumn[]=' . gettype($idColumn) . '!=array: userIdColumn=' . $userIdColumn);
1077 } elseif (!is_array($undeleteNow)) {
1078 // $undeleteNow is no array
1079 reportBug(__FUNCTION__, __LINE__, 'undeleteNow[]=' . gettype($undeleteNow) . '!=array: userIdColumn=' . $userIdColumn);
1082 // Shall we un-/lock here or list for locking?
1083 if ($undeleteNow[0] === TRUE) {
1085 adminBuilderStatusHandler('undelete', $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $statusArray);
1088 adminListBuilder('undelete', $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn);
1092 // Adds a given entry to the database
1093 function adminAddEntries ($tableName, $columns = array(), $filterFunctions = array(), $extraValues = array(), $timeColumns = array(), $columnIndex = NULL) {
1094 // Is the userid set?
1095 if (!isPostRequestElementSet('userid')) {
1096 // Then set NULL here
1097 setPostRequestElement('userid', NULL);
1100 // Call inner function
1101 doGenericAddEntries($tableName, $columns, $filterFunctions, $extraValues, $timeColumns, $columnIndex);
1103 // Entry has been added?
1104 if ((!SQL_HASZEROAFFECTED()) && ($GLOBALS['__XML_PARSE_RESULT'] === TRUE)) {
1105 // Display success message
1106 displayMessage('{--ADMIN_ENTRY_ADDED--}');
1108 // Display failed message
1109 displayMessage('{--ADMIN_ENTRY_NOT_ADDED--}');
1113 // Checks proxy settins by fetching check-updates3.php from mxchange.org
1114 function adminTestProxySettings ($settingsArray) {
1115 // Set temporary the new settings
1116 mergeConfig($settingsArray);
1118 // Now get the test URL
1119 $content = sendGetRequest('check-updates3.php');
1121 // Is the first line with "200 OK"?
1122 $valid = isInString('200 OK', $content[0]);
1128 // Sends out a link to the given email adress so the admin can reset his/her password
1129 function sendAdminPasswordResetLink ($email) {
1133 //Â Look up administator login
1134 $result = SQL_QUERY_ESC("SELECT `id`, `login`, `password` FROM `{?_MYSQL_PREFIX?}_admins` WHERE '%s' REGEXP `email` LIMIT 1",
1135 array($email), __FUNCTION__, __LINE__);
1137 // Is there an account?
1138 if (SQL_HASZERONUMS($result)) {
1140 return '{--ADMIN_NO_LOGIN_WITH_EMAIL--}';
1144 $content = SQL_FETCHARRAY($result);
1147 SQL_FREERESULT($result);
1149 // Generate hash for reset link
1150 $content['hash'] = generateHash(getUrl() . getEncryptSeparator() . $content['id'] . getEncryptSeparator() . $content['login'] . getEncryptSeparator() . $content['password'], substr($content['password'], getSaltLength()));
1153 unset($content['id']);
1154 unset($content['password']);
1157 $mailText = loadEmailTemplate('admin_reset_password', $content);
1160 sendEmail($email, '{--ADMIN_RESET_PASSWORD_LINK_SUBJECT--}', $mailText);
1163 return '{--ADMIN_RESET_PASSWORD_LINK_SENT--}';
1166 // Validate hash and login for password reset
1167 function adminResetValidateHashLogin ($hash, $login) {
1168 // By default nothing validates... ;)
1171 // Then try to find that user
1172 $result = SQL_QUERY_ESC("SELECT `id`, `password`, `email` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `login`='%s' LIMIT 1",
1173 array($login), __FUNCTION__, __LINE__);
1175 // Is an account here?
1176 if (SQL_NUMROWS($result) == 1) {
1178 $content = SQL_FETCHARRAY($result);
1180 // Generate hash again
1181 $hashFromData = generateHash(getUrl() . getEncryptSeparator() . $content['id'] . getEncryptSeparator() . $login . getEncryptSeparator() . $content['password'], substr($content['password'], getSaltLength()));
1184 $valid = ($hash == $hashFromData);
1188 SQL_FREERESULT($result);
1194 // Reset the password for the login. Do NOT call this function without calling above function first!
1195 function doResetAdminPassword ($login, $password) {
1196 // Generate hash (we already check for ext-sql_patches in generateHash())
1197 $passHash = generateHash($password);
1199 // Prepare fake POST data
1201 'login' => array(getAdminId($login) => $login),
1202 'password' => array(getAdminId($login) => $passHash),
1206 $message = adminsChangeAdminAccount($postData, '', FALSE);
1209 runFilterChain('post_form_reset_pass', array('login' => $login, 'hash' => $passHash, 'message' => $message));
1212 return '{--ADMIN_PASSWORD_RESET_DONE--}';
1215 // Solves a task by given id number
1216 function adminSolveTask ($id) {
1217 // Update the task data
1218 adminUpdateTaskData($id, 'status', 'SOLVED');
1221 // Marks a given task as deleted
1222 function adminDeleteTask ($id) {
1223 // Update the task data
1224 adminUpdateTaskData($id, 'status', 'DELETED');
1227 // Function to update task data
1228 function adminUpdateTaskData ($id, $row, $data) {
1229 // Should be admin and valid id
1231 // Not an admin so redirect better
1232 reportBug(__FUNCTION__, __LINE__, 'id=' . $id . ',row=' . $row . ',data=' . $data . ' - isAdmin()=false');
1233 } elseif ($id <= 0) {
1234 // Initiate backtrace
1235 reportBug(__FUNCTION__, __LINE__, sprintf("id is invalid: %s. row=%s, data=%s",
1243 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_task_system` SET `%s`='%s' WHERE `id`=%s LIMIT 1",
1248 ), __FUNCTION__, __LINE__);
1251 // Checks whether if the admin menu has entries
1252 function ifAdminMenuHasEntries ($action) {
1255 // Is the entry set?
1256 isset($GLOBALS['admin_menu_has_entries'][$action])
1258 // And do we have a menu for this action?
1259 $GLOBALS['admin_menu_has_entries'][$action] === TRUE
1261 // Login has always a menu
1267 // Setter for 'admin_menu_has_entries'
1268 function setAdminMenuHasEntries ($action, $hasEntries) {
1269 $GLOBALS['admin_menu_has_entries'][$action] = (bool) $hasEntries;
1272 // Creates a link to the user's admin-profile
1273 function adminCreateUserLink ($userid) {
1274 // Is the userid set correctly?
1275 if (isValidUserId($userid)) {
1276 // Create a link to that profile
1277 return '{%url=modules.php?module=admin&what=list_user&userid=' . bigintval($userid) . '%}';
1280 // Return a link to the user list
1281 return '{%url=modules.php?module=admin&what=list_user%}';
1284 // Generate a "link" for the given admin id (admin_id)
1285 function generateAdminLink ($adminId) {
1286 // No assigned admin is default
1287 $adminLink = '{--ADMIN_NO_ADMIN_ASSIGNED--}';
1289 // Zero? = Not assigned
1290 if (isValidUserId($adminId)) {
1291 // Load admin's login
1292 $login = getAdminLogin($adminId);
1294 // Is the login valid?
1295 if ($login != '***') {
1296 // Is the extension there?
1297 if (isExtensionActive('admins')) {
1299 $adminLink = '<a href="' . generateEmailLink(getAdminEmail($adminId), 'admins') . '" title="{--ADMIN_CONTACT_LINK_TITLE--}">' . $login . '</a>';
1301 // Extension not found
1302 $adminLink = '{%message,ADMIN_TASK_ROW_EXTENSION_NOT_INSTALLED=admins%}';
1306 $adminLink = '<div class="bad">{%message,ADMIN_ID_404=' . $adminId . '%}</div>';
1314 // Verifies if the current admin has confirmed to alter expert settings
1317 // 'failed' = Something goes wrong (default)
1318 // 'agreed' = Has verified and and confirmed it to see them
1319 // 'forbidden' = Has not the proper right to alter them
1320 // 'update' = Need to update extension 'admins'
1321 // 'ask' = A form was send to the admin
1322 function doVerifyExpertSettings () {
1323 // Default return status is failed
1326 // Is the extension installed and recent?
1327 if (isExtensionInstalledAndNewer('admins', '0.7.3')) {
1328 // Okay, load the status
1329 $expertSettings = getAminsExpertSettings();
1332 if ($expertSettings == 'Y') {
1333 // Okay, does he want to see them?
1334 if (isAdminsExpertWarningEnabled()) {
1337 // Is the element set, then we need to change the admin
1338 if (isPostRequestElementSet('expert_settings')) {
1339 // Get it and prepare final post data array
1340 $postData['login'][getCurrentAdminId()] = getCurrentAdminLogin();
1341 $postData['expert_warning'][getCurrentAdminId()] = 'N';
1343 // Change it in the admin
1344 adminsChangeAdminAccount($postData, 'expert_warning');
1351 loadTemplate('admin_expert_settings_form');
1362 if ((isFormSent()) && (isPostRequestElementSet('expert_settings'))) {
1364 unsetPostRequestElement('ok');
1365 unsetPostRequestElement('expert_settings');
1369 $return = 'forbidden';
1372 // Out-dated extension or not installed
1376 // Output message for other status than ask/agreed
1377 if (($return != 'ask') && ($return != 'agreed')) {
1379 displayMessage('{--ADMIN_EXPERT_SETTINGS_STATUS_' . strtoupper($return) . '--}');
1386 // Generate link to unconfirmed mails for admin
1387 function generateUnconfirmedAdminLink ($id, $unconfirmed, $type = 'bid') {
1389 $OUT = $unconfirmed;
1391 // Is there unconfirmed mails?
1392 if ($unconfirmed > 0) {
1393 // Add link to list_unconfirmed what-file
1394 $OUT = '<a href="{%url=modules.php?module=admin&what=list_unconfirmed&' . $type . '=' . $id . '%}">{%pipe,translateComma=' . $unconfirmed . '%}</a>';
1401 // Generates a navigation row for listing emails
1402 function addEmailNavigation ($numPages, $offset, $show_form, $colspan, $return=false) {
1403 // Don't do anything if $numPages is 1
1404 if ($numPages == 1) {
1405 // Abort here with empty content
1410 if ($show_form === FALSE) {
1415 for ($page = 1; $page <= $numPages; $page++) {
1416 // Is the page currently selected or shall we generate a link to it?
1417 if (($page == getRequestElement('page')) || ((!isGetRequestElementSet('page')) && ($page == 1))) {
1418 // Is currently selected, so only highlight it
1419 $NAV .= '<strong>-';
1421 // Open anchor tag and add base URL
1422 $NAV .= '<a href="{%url=modules.php?module=admin&what=' . getWhat() . '&page=' . $page . '&offset=' . $offset;
1424 // Add userid when we shall show all mails from a single member
1425 if ((isGetRequestElementSet('userid')) && (isValidUserId(getRequestElement('userid')))) $NAV .= '&userid=' . bigintval(getRequestElement('userid'));
1427 // Close open anchor tag
1431 if (($page == getRequestElement('page')) || ((!isGetRequestElementSet('page')) && ($page == 1))) {
1432 // Is currently selected, so only highlight it
1433 $NAV .= '-</strong>';
1439 // Add separator if we have not yet reached total pages
1440 if ($page < $numPages) {
1446 // Define constants only once
1447 $content['nav'] = $NAV;
1448 $content['span'] = $colspan;
1449 $content['top'] = $TOP;
1451 // Load navigation template
1452 $OUT = loadTemplate('admin_email_nav_row', TRUE, $content);
1454 if ($return === TRUE) {
1455 // Return generated HTML-Code
1463 // Process menu editing form
1464 function adminProcessMenuEditForm ($type, $subMenu) {
1465 // An action is done...
1466 foreach (postRequestElement('sel') as $sel => $menu) {
1467 $AND = "(`what` = '' OR `what` IS NULL)";
1469 $sel = bigintval($sel);
1471 if (!empty($subMenu)) {
1472 $AND = "`action`='" . $subMenu . "'";
1475 switch (postRequestElement('ok')) {
1476 case 'edit': // Edit menu
1477 // Shall we update a menu or sub menu?
1478 if (!isGetRequestElementSet('sub')) {
1479 // Update with 'what'=null
1480 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_%s_menu` SET `title`='%s',`action`='%s',`what`=NULL WHERE ".$AND." AND `id`=%s LIMIT 1",
1484 postRequestElement('sel_action', $sel),
1486 ), __FUNCTION__, __LINE__);
1488 // Update with selected 'what'
1489 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_%s_menu` SET `title`='%s',`action`='%s',`what`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
1493 postRequestElement('sel_action', $sel),
1494 postRequestElement('sel_what', $sel),
1496 ), __FUNCTION__, __LINE__);
1500 case 'delete': // Delete menu
1501 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
1505 ), __FUNCTION__, __LINE__);
1508 case 'status': // Change status of menus
1509 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_%s_menu` SET `visible`='%s',`locked`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
1512 postRequestElement('visible', $sel),
1513 postRequestElement('locked', $sel),
1515 ), __FUNCTION__, __LINE__);
1518 default: // Unexpected action
1519 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unsupported action %s detected.", postRequestElement('ok')));
1520 displayMessage('{%message,ADMIN_UNKNOWN_OKAY=' . postRequestElement('ok') . '%}');
1526 displayMessage('{--SETTINGS_SAVED--}');
1529 // Handle weightning
1530 function doAdminProcessMenuWeightning ($type, $AND) {
1531 // Are there all required (generalized) GET parameter?
1532 if ((isGetRequestElementSet('act')) && (isGetRequestElementSet('tid')) && (isGetRequestElementSet('fid'))) {
1534 $tid = ''; $fid = '';
1537 if (isGetRequestElementSet('w')) {
1538 // Sub menus selected
1539 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `action`='%s' AND `sort`=%s LIMIT 1",
1542 getRequestElement('act'),
1543 bigintval(getRequestElement('tid'))
1544 ), __FUNCTION__, __LINE__);
1545 list($tid) = SQL_FETCHROW($result);
1546 SQL_FREERESULT($result);
1547 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `action`='%s' AND `sort`=%s LIMIT 1",
1550 getRequestElement('act'),
1551 bigintval(getRequestElement('fid'))
1552 ), __FUNCTION__, __LINE__);
1553 list($fid) = SQL_FETCHROW($result);
1554 SQL_FREERESULT($result);
1556 // Main menu selected
1557 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`=%s LIMIT 1",
1560 bigintval(getRequestElement('tid'))
1561 ), __FUNCTION__, __LINE__);
1562 list($tid) = SQL_FETCHROW($result);
1563 SQL_FREERESULT($result);
1564 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`=%s LIMIT 1",
1567 bigintval(getRequestElement('fid'))
1568 ), __FUNCTION__, __LINE__);
1569 list($fid) = SQL_FETCHROW($result);
1570 SQL_FREERESULT($result);
1573 if ((!empty($tid)) && (!empty($fid))) {
1575 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_%s_menu` SET `sort`=%s WHERE ".$AND." AND `id`=%s LIMIT 1",
1578 bigintval(getRequestElement('tid')),
1580 ), __FUNCTION__, __LINE__);
1581 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_%s_menu` SET `sort`=%s WHERE ".$AND." AND `id`=%s LIMIT 1",
1584 bigintval(getRequestElement('fid')),
1586 ), __FUNCTION__, __LINE__);