914622a461b6ea7edb2b6a54fd1b1ea298295451
[mailer.git] / inc / modules / admin / admin-inc.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 08/31/2003 *
4  * ===================                          Last change: 11/23/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : admin-inc.php                                    *
8  * -------------------------------------------------------------------- *
9  * Short description : Administrative related functions                 *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Fuer die Administration benoetigte Funktionen    *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
21  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
42         die();
43 } // END - if
44
45 // Register an administrator account
46 function addAdminAccount ($adminLogin, $passHash, $adminEmail) {
47         // Login does already exist
48         $ret = 'already';
49
50         // Lookup the admin
51         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `login`='%s' LIMIT 1",
52                 array($adminLogin), __FUNCTION__, __LINE__);
53
54         // Is the entry there?
55         if (SQL_HASZERONUMS($result)) {
56                 // Ok, let's create the admin login
57                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins` (`login`, `password`, `email`) VALUES ('%s', '%s', '%s')",
58                         array(
59                                 $adminLogin,
60                                 $passHash,
61                                 $adminEmail
62                         ), __FUNCTION__, __LINE__);
63
64                 // All done
65                 $ret = 'done';
66         } // END - if
67
68         // Free memory
69         SQL_FREERESULT($result);
70
71         // Return result
72         return $ret;
73 }
74
75 // This function will be executed when the admin is not logged in and has submitted his login data
76 function ifAdminLoginDataIsValid ($adminLogin, $adminPassword) {
77         // First of all, no admin login is found
78         $ret = '404';
79
80         // Then we need to lookup the login name by getting the admin hash
81         $adminHash = getAdminHash($adminLogin);
82
83         // If this is fine, we can continue
84         if ($adminHash != '-1') {
85                 // Get admin id and set it as current
86                 setCurrentAdminId(getAdminId($adminLogin));
87
88                 // Now, we need to encode the password in the same way the one is encoded in database
89                 $testHash = generateHash($adminPassword, $adminHash);
90
91                 // If they both match, the login data is valid
92                 if ($testHash == $adminHash) {
93                         // All fine
94                         $ret = 'done';
95                 } else {
96                         // Set status
97                         $ret = 'pass';
98                 }
99         } // END - if
100
101         // Prepare data array
102         $data = array(
103                 'login'      => $adminLogin,
104                 'plain_pass' => $adminPassword,
105                 'pass_hash'  => $adminHash
106         );
107
108         // Run a special filter
109         runFilterChain('do_admin_login_' . $ret, $data);
110
111         // Return status
112         return $ret;
113 }
114
115 // Only be executed on cookie checking
116 function ifAdminCookiesAreValid ($adminLogin, $passHash) {
117         // First of all, no admin login is found
118         $ret = '404';
119
120         // Then we need to lookup the login name by getting the admin hash
121         $adminHash = getAdminHash($adminLogin);
122
123         // If this is fine, we can continue
124         if ($adminHash != '-1') {
125                 // Now, we need to encode the password in the same way the one is encoded in database
126                 $testHash = encodeHashForCookie($adminHash);
127                 //* DEBUG: */ outputHtml('adminLogin='.$adminLogin.',<br />passHash='.$passHash.',<br />adminHash='.$adminHash.',<br />testHash='.$testHash.'<br />');
128
129                 // If they both match, the login data is valid
130                 if ($testHash == $passHash) {
131                         // All fine
132                         $ret = 'done';
133                 } else {
134                         // Set status
135                         $ret = 'pass';
136                 }
137         } // END - if
138
139         // Return status
140         //* DEBUG: */ outputHtml('ret='.$ret);
141         return $ret;
142 }
143
144 // Do an admin action
145 function doAdminAction () {
146         // Get default what
147         $what = getWhat();
148
149         //* DEBUG: */ outputHtml(__LINE__.'*'.$what.'/'.getModule().'/'.getAction().'/'.getWhat().'*<br />');
150
151         // Remove any spaces from variable
152         if (empty($what)) {
153                 // Default admin action is the overview page
154                 $what = 'overview';
155         } else {
156                 // Secure it
157                 $what = secureString($what);
158         }
159
160         // Get action value
161         $action = getActionFromModuleWhat(getModule(), $what);
162
163         // Define admin login name and id number
164         $content['login'] = getSession('admin_login');
165         $content['id']    = getCurrentAdminId();
166
167         // Preload templates
168         if (isExtensionActive('admins')) {
169                 $content['welcome'] = loadTemplate('admin_welcome_admins', true, $content);
170         } else {
171                 $content['welcome'] = loadTemplate('admin_welcome', true, $content);
172         }
173         $content['footer'] = loadTemplate('admin_footer' , true, $content);
174         $content['menu']   = addAdminMenu($action, $what, true);
175
176         // Tableset header
177         loadTemplate('admin_main_header', false, $content);
178
179         // Check if action/what pair is valid
180         $result_action = SQL_QUERY_ESC("SELECT
181         `id`
182 FROM
183         `{?_MYSQL_PREFIX?}_admin_menu`
184 WHERE
185         `action`='%s' AND
186         (
187                 (
188                         `what`='%s' AND `what` != 'overview'
189                 ) OR (
190                         (
191                                 `what`='' OR `what` IS NULL
192                         ) AND (
193                                 '%s'='overview'
194                         )
195                 )
196         )
197 LIMIT 1",
198                 array(
199                         $action,
200                         $what,
201                         $what
202                 ), __FUNCTION__, __LINE__);
203
204         // Do we have an entry?
205         if (SQL_NUMROWS($result_action) == 1) {
206                 // Is valid but does the inlcude file exists?
207                 $inc = sprintf("inc/modules/admin/action-%s.php", $action);
208                 if ((isIncludeReadable($inc)) && (isMenuActionValid('admin', $action, $what)) && ($GLOBALS['acl_allow'] === true)) {
209                         // Ok, we finally load the admin action module
210                         loadInclude($inc);
211                 } elseif ($GLOBALS['acl_allow'] === false) {
212                         // Access denied
213                         loadTemplate('admin_menu_failed', false, getMaskedMessage('ADMIN_ACCESS_DENIED', $what));
214                 } else {
215                         // Include file not found! :-(
216                         loadTemplate('admin_menu_failed', false, getMaskedMessage('ADMIN_ACTION_404', $action));
217                 }
218         } else {
219                 // Invalid action/what pair found!
220                 loadTemplate('admin_menu_failed', false, getMaskedMessage('ADMIN_ACTION_INVALID', $action . '/' . $what));
221         }
222
223         // Free memory
224         SQL_FREERESULT($result_action);
225
226         // Tableset footer
227         loadTemplate('admin_main_footer', false, $content);
228 }
229
230 // Adds an admin menu
231 function addAdminMenu ($action, $what, $return=false) {
232         // Init variables
233         $SUB = false;
234         $OUT = '';
235
236         // Menu descriptions
237         $GLOBALS['menu']['description'] = array();
238         $GLOBALS['menu']['title'] = array();
239
240         // Build main menu
241         $result_main = SQL_QUERY("SELECT
242         `action`, `title`, `descr`
243 FROM
244         `{?_MYSQL_PREFIX?}_admin_menu`
245 WHERE
246         (`what`='' OR `what` IS NULL)
247 ORDER BY
248         `sort` ASC,
249         `id` DESC", __FUNCTION__, __LINE__);
250
251         // Do we have entries?
252         if (SQL_NUMROWS($result_main) > 0) {
253                 $OUT .= '<ul class="admin_menu_main">';
254                 // @TODO Rewrite this to $content = SQL_FETCHARRAY()
255                 while (list($menu, $title, $descr) = SQL_FETCHROW($result_main)) {
256                         if ((isExtensionActive('admins')) && (getExtensionVersion('admins') > '0.2.0')) {
257                                 $ACL = adminsCheckAdminAcl($menu, '');
258                         } else {
259                                 // @TODO ACL is 'allow'... hmmm
260                                 $ACL = true;
261                         }
262
263                         // Filename
264                         $inc = sprintf("inc/modules/admin/action-%s.php", $menu);
265
266                         // Is the file readable?
267                         $readable = isIncludeReadable($inc);
268
269                         if ($ACL === true) {
270                                 if ($SUB === false) {
271                                         // Insert compiled menu title and description
272                                         $GLOBALS['menu']['title'][$menu]      = $title;
273                                         $GLOBALS['menu']['description'][$menu] = $descr;
274                                 }
275                                 $OUT .= '<li class="admin_menu">
276 <div class="nobr"><strong>&middot;</strong>&nbsp;';
277
278                                 if ($readable === true) {
279                                         if (($menu == $action) && (empty($what))) {
280                                                 $OUT .= '<strong>';
281                                         } else {
282                                                 $OUT .= '[<a href="{%url=modules.php?module=admin&amp;action=' . $menu . '%}">';
283                                         }
284                                 } else {
285                                         $OUT .= '<em style="cursor:help" class="admin_note" title="{--MENU_ACTION_404--}">';
286                                 }
287
288                                 $OUT .= $title;
289
290                                 if ($readable === true) {
291                                         if (($menu == $action) && (empty($what))) {
292                                                 $OUT .= '</strong>';
293                                         } else {
294                                                 $OUT .= '</a>]';
295                                         }
296                                 } else {
297                                         $OUT .= '</em>';
298                                 }
299
300                                 $OUT .= '</div>
301 </li>';
302
303                                 // Check for menu entries
304                                 $result_what = SQL_QUERY_ESC("SELECT
305         `what`, `title`, `descr`
306 FROM
307         `{?_MYSQL_PREFIX?}_admin_menu`
308 WHERE
309         `action`='%s' AND
310         `what` != '' AND
311         `what` IS NOT NULL
312 ORDER BY
313         `sort` ASC,
314         `id` DESC",
315                                         array($menu), __FUNCTION__, __LINE__);
316
317                                 // Remember the count for later checks
318                                 setAdminMenuHasEntries($menu, ((SQL_NUMROWS($result_what) > 0) && ($action == $menu)));
319
320                                 // Do we have entries?
321                                 if ((ifAdminMenuHasEntries($menu)) && (SQL_NUMROWS($result_what) > 0)) {
322                                         $GLOBALS['menu']['description'] = array();
323                                         $GLOBALS['menu']['title'] = array(); $SUB = true;
324                                         $OUT .= '<li class="admin_menu_sub"><ul class="admin_menu_sub">';
325                                         // @TODO Rewrite this to $content = SQL_FETCHARRAY()
326                                         while (list($what_sub, $title_what, $desc_what) = SQL_FETCHROW($result_what)) {
327                                                 // Check for access level
328                                                 if ((isExtensionActive('admins')) && (getExtensionVersion('admins') > '0.2.0')) {
329                                                         $ACL = adminsCheckAdminAcl('', $what_sub);
330                                                 } else {
331                                                         // @TODO ACL is 'allow'... hmmm
332                                                         $ACL = true;
333                                                 }
334
335                                                 // Filename
336                                                 $inc = sprintf("inc/modules/admin/what-%s.php", $what_sub);
337
338                                                 // Is the file readable?
339                                                 $readable = isIncludeReadable($inc);
340
341                                                 // Access allowed?
342                                                 if ($ACL === true) {
343                                                         // Insert compiled title and description
344                                                         $GLOBALS['menu']['title'][$what_sub]      = $title_what;
345                                                         $GLOBALS['menu']['description'][$what_sub] = $desc_what;
346                                                         $OUT .= '<li class="admin_menu">
347 <div class="nobr"><strong>--&gt;</strong>&nbsp;';
348                                                         if ($readable === true) {
349                                                                 if ($what == $what_sub) {
350                                                                         $OUT .= '<strong>';
351                                                                 } else {
352                                                                         $OUT .= '[<a href="{%url=modules.php?module=admin&amp;what=' . $what_sub . '%}">';
353                                                                 }
354                                                         } else {
355                                                                 $OUT .= '<em style="cursor:help" class="admin_note" title="{--MENU_WHAT_404--}">';
356                                                         }
357
358                                                         $OUT .= $title_what;
359
360                                                         if ($readable === true) {
361                                                                 if ($what == $what_sub) {
362                                                                         $OUT .= '</strong>';
363                                                                 } else {
364                                                                         $OUT .= '</a>]';
365                                                                 }
366                                                         } else {
367                                                                 $OUT .= '</em>';
368                                                         }
369                                                         $OUT .= '</div>
370 </li>';
371                                                 } // END - if
372                                         } // END - while
373
374                                         // Free memory
375                                         SQL_FREERESULT($result_what);
376                                         $OUT .= '</ul>
377 </li>';
378                                 } // END - if
379                         } // END - if
380                 } // END - while
381
382                 // Free memory
383                 SQL_FREERESULT($result_main);
384                 $OUT .= '</ul>';
385         }
386
387         // Is there a cache instance again?
388         // Return or output content?
389         if ($return === true) {
390                 return $OUT;
391         } else {
392                 outputHtml($OUT);
393         }
394 }
395
396 // Create member selection box
397 function addMemberSelectionBox ($def=0, $add_all=false, $return=false, $none=false, $field='userid') {
398         // Output selection form with all confirmed user accounts listed
399         $result = SQL_QUERY("SELECT `userid`, `surname`, `family` FROM `{?_MYSQL_PREFIX?}_user_data` ORDER BY `userid` ASC", __FUNCTION__, __LINE__);
400
401         // Default output
402         $OUT = '';
403
404         // USe this only for adding points (e.g. adding refs really makes no sence ;-) )
405         if ($add_all === true)   $OUT = '      <option value="all">{--ALL_MEMBERS--}</option>';
406          elseif ($none === true) $OUT = '      <option value="0">{--SELECT_NONE--}</option>';
407
408         while ($content = SQL_FETCHARRAY($result)) {
409                 $OUT .= '      <option value="' . bigintval($content['userid']) . '"';
410                 if ($def == $content['userid']) $OUT .= ' selected="selected"';
411                 $OUT .= '>' . $content['surname'] . ' ' . $content['family'] . ' (' . bigintval($content['userid']) . ')</option>';
412         } // END - while
413
414         // Free memory
415         SQL_FREERESULT($result);
416
417         if ($return === false) {
418                 // Remeber options in constant
419                 $content['member_selection'] = $OUT;
420                 $content['what']             = getWhat();
421
422                 // Load template
423                 loadTemplate('admin_member_selection_box', false, $content);
424         } else {
425                 // Return content in selection frame
426                 return '<select class="admin_select" name="' . $field . '" size="1">' . $OUT . '</select>';
427         }
428 }
429
430 // Create a menu selection box for given menu system
431 // @TODO Try to rewrite this to adminAddMenuSelectionBox()
432 // @DEPRECATED
433 function adminMenuSelectionBox_DEPRECATED ($mode, $default = '', $defid = '') {
434         $what = "`what` != ''";
435         if ($mode == 'action') $what = "(`what`='' OR `what` IS NULL) AND `action` !='login'";
436
437         $result = SQL_QUERY_ESC("SELECT %s, `title` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$what." ORDER BY `sort` ASC",
438                 array($mode), __FUNCTION__, __LINE__);
439         if (SQL_NUMROWS($result) > 0) {
440                 // Load menu as selection
441                 $OUT = "<select name=\"".$mode."_menu";
442                 if ((!empty($defid)) || ($defid == '0')) $OUT .= "[".$defid."]";
443                 $OUT .= "\" size=\"1\" class=\"admin_select\">
444         <option value=\"\">{--SELECT_NONE--}</option>\n";
445                 // @TODO Try to rewrite this to $content = SQL_FETCHARRAY(). Please look some lines above for the dynamic query
446                 while (list($menu, $title) = SQL_FETCHROW($result)) {
447                         $OUT .= "  <option value=\"".$menu."\"";
448                         if ((!empty($default)) && ($default == $menu)) $OUT .= ' selected="selected"';
449                         $OUT .= ">".$title."</option>\n";
450                 } // END - while
451
452                 // Free memory
453                 SQL_FREERESULT($result);
454                 $OUT .= "</select>\n";
455         } else {
456                 // No menus???
457                 $OUT = getMessage('ADMIN_PROBLEM_NO_MENU');
458         }
459
460         // Return output
461         return $OUT;
462 }
463
464 // Wrapper for $_POST and adminSaveSettings
465 function adminSaveSettingsFromPostData ($tableName = '_config', $whereStatement = '`config`=0', $translateComma = array(), $alwaysAdd = false, $displayMessage = true) {
466         // Get the array
467         $postData = postRequestArray();
468
469         // Call the lower function
470         adminSaveSettings($postData, $tableName, $whereStatement, $translateComma, $alwaysAdd, $displayMessage);
471 }
472
473 // Save settings to the database
474 function adminSaveSettings (&$postData, $tableName = '_config', $whereStatement = '`config`=0', $translateComma = array(), $alwaysAdd = false, $displayMessage = true) {
475         // Prepare all arrays, variables
476         $tableData = array();
477         $skip = false;
478
479         // Now, walk through all entries and prepare them for saving
480         foreach ($postData as $id => $val) {
481                 // Process only formular field but not submit buttons ;)
482                 if ($id != 'ok') {
483                         // Do not save the ok value
484                         convertSelectionsToTimestamp($postData, $tableData, $id, $skip);
485
486                         // Shall we process this id? It muss not be empty, of course
487                         if (($skip === false) && (!empty($id)) && ((!isset($GLOBALS['skip_config'][$id]))) || ($tableName != '_config')) {
488                                 // Translate the value? (comma to dot!)
489                                 if ((is_array($translateComma)) && (in_array($id, $translateComma))) {
490                                         // Then do it here... :)
491                                         $val = convertCommaToDot($val);
492                                 } // END - if
493
494                                 // Shall we add numbers or strings?
495                                 $test = (float)$val;
496                                 if ('' . $val . '' == '' . $test . '') {
497                                         // Add numbers
498                                         $tableData[] = sprintf("`%s`=%s", $id, $test);
499                                 } elseif (is_null($val)) {
500                                         // Add NULL
501                                         $tableData[] = sprintf("`%s`=NULL", $id);
502                                 } else {
503                                         // Add strings
504                                         $tableData[] = sprintf("`%s`='%s'", $id, trim($val));
505                                 }
506
507                                 // Do not add a config entry twice
508                                 $GLOBALS['skip_config'][$id] = true;
509
510                                 // Update current configuration
511                                 setConfigEntry($id, $val);
512                         } // END - if
513                 } // END - if
514         } // END - foreach
515
516         // Check if entry does exist
517         $result = false;
518         if ($alwaysAdd === false) {
519                 if (!empty($whereStatement)) {
520                         $result = SQL_QUERY("SELECT * FROM `{?_MYSQL_PREFIX?}" . $tableName . "` WHERE " . $whereStatement . " LIMIT 1", __FUNCTION__, __LINE__);
521                 } else {
522                         $result = SQL_QUERY("SELECT * FROM `{?_MYSQL_PREFIX?}" . $tableName . "` LIMIT 1", __FUNCTION__, __LINE__);
523                 }
524         } // END - if
525
526         if (SQL_NUMROWS($result) == 1) {
527                 // "Implode" all data to single string
528                 $updatedData = implode(', ', $tableData);
529
530                 // Generate SQL string
531                 $sql = sprintf("UPDATE `{?_MYSQL_PREFIX?}%s` SET %s WHERE %s LIMIT 1",
532                         $tableName,
533                         $updatedData,
534                         $whereStatement
535                 );
536         } else {
537                 // Add Line (does only work with auto_increment!
538                 $keys = array(); $values = array();
539                 foreach ($tableData as $entry) {
540                         // Split up
541                         $line = explode('=', $entry);
542                         $keys[] = $line[0];
543                         $values[] = $line[1];
544                 } // END - foreach
545
546                 // Add both in one line
547                 $keys = implode('`, `', $keys);
548                 $values = implode(', ', $values);
549
550                 // Generate SQL string
551                 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}%s` (%s) VALUES (%s)",
552                         $tableName,
553                         $keys,
554                         $values
555                 );
556         }
557
558         // Free memory
559         SQL_FREERESULT($result);
560
561         // Simply run generated SQL string
562         SQL_QUERY($sql, __FUNCTION__, __LINE__);
563
564         // Remember affected rows
565         $affected = SQL_AFFECTEDROWS();
566
567         // Rebuild cache
568         rebuildCache('config', 'config');
569
570         // Settings saved, so display message?
571         if ($displayMessage === true) loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
572
573         // Return affected rows
574         return $affected;
575 }
576
577 // Generate a selection box
578 function adminAddMenuSelectionBox ($menu, $type, $name, $default = '') {
579         // Open the requested menu directory
580         $menuArray = getArrayFromDirectory(sprintf("inc/modules/%s/", $menu), '', false, false);
581
582         // Init the selection box
583         $OUT = "<select name=\"".$name."\" class=\"admin_select\" size=\"1\">
584         <option value=\"\">{--IS_TOP_MENU--}</option>\n";
585
586         // Walk through all files
587         foreach ($menuArray as $file) {
588                 // Is this a PHP script?
589                 if ((!isDirectory($file)) && (strpos($file, "".$type.'-') > -1) && (strpos($file, '.php') > 0)) {
590                         // Then test if the file is readable
591                         $test = sprintf("inc/modules/%s/%s", $menu, $file);
592
593                         // Is the file there?
594                         if (isIncludeReadable($test)) {
595                                 // Extract the value for what=xxx
596                                 $part = substr($file, (strlen($type) + 1));
597                                 $part = substr($part, 0, -4);
598
599                                 // Is that part different from the overview?
600                                 if ($part != 'overview') {
601                                         $OUT .= "       <option value=\"".$part."\"";
602                                         if ($part == $default) $OUT .= ' selected="selected"';
603                                         $OUT .= ">".$part."</option>\n";
604                                 } // END - if
605                         } // END - if
606                 } // END - if
607         } // END - foreach
608
609         // Close selection box
610         $OUT .= "</select>\n";
611
612         // Return contents
613         return $OUT;
614 }
615
616 // Creates a user-profile link for the admin. This function can also be used for many other purposes
617 function generateUserProfileLink ($userid, $title = '', $what = 'list_user') {
618         if (($title == '') && ($userid > 0)) {
619                 // Set userid as title
620                 $title = $userid;
621         } elseif ($userid == 0) {
622                 // User id zero is invalid
623                 return '<strong>' . $userid . '</strong>';
624         }
625
626         if (($title == '0') && ($what == 'list_refs')) {
627                 // Return title again
628                 return $title;
629         } elseif (isExtensionActive('nickname')) {
630                 // Get nickname
631                 $nick = getNickname($userid);
632
633                 // Is it not empty, use it as title else the userid
634                 if (!empty($nick)) $title = $nick . '(' . $userid . ')'; else $title = $userid;
635         }
636
637         // Return link
638         return '[<a href="{%url=modules.php?module=admin&amp;what=' . $what . '&amp;userid=' . $userid . '%}" title="{--ADMIN_USER_PROFILE_TITLE--}">' . $title . '</a>]';
639 }
640
641 // Check "logical-area-mode"
642 function adminGetMenuMode () {
643         // Set the default menu mode as the mode for all admins
644         $mode = getConfig('admin_menu');
645         $adminMode = $mode;
646
647         // Get admin id
648         $adminId = getCurrentAdminId();
649
650         // Check individual settings of current admin
651         if (isset($GLOBALS['cache_array']['admin']['la_mode'][$adminId])) {
652                 // Load from cache
653                 $adminMode = $GLOBALS['cache_array']['admin']['la_mode'][$adminId];
654                 incrementStatsEntry('cache_hits');
655         } elseif (isExtensionInstalledAndNewer('admins', '0.6.7')) {
656                 // Load from database when version of 'admins' is enough
657                 $result = SQL_QUERY_ESC("SELECT la_mode FROM `{?_MYSQL_PREFIX?}_admins` WHERE `id`=%s LIMIT 1",
658                         array($adminId), __FUNCTION__, __LINE__);
659
660                 // Do we have an entry?
661                 if (SQL_NUMROWS($result) == 1) {
662                         // Load data
663                         list($adminMode) = SQL_FETCHROW($result);
664                 } // END - if
665
666                 // Free memory
667                 SQL_FREERESULT($result);
668         }
669
670         // Check what the admin wants and set it when it's not the default mode
671         if ($adminMode != 'global') $mode = $adminMode;
672
673         // Return admin-menu's mode
674         return $mode;
675 }
676
677 // Change activation status
678 function adminChangeActivationStatus ($IDs, $table, $row, $idRow = 'id') {
679         $cnt = '0'; $newStatus = 'Y';
680         if ((is_array($IDs)) && (count($IDs) > 0)) {
681                 // "Walk" all through and count them
682                 foreach ($IDs as $id => $selected) {
683                         // Secure the id number
684                         $id = bigintval($id);
685
686                         // Should always be set... ;-)
687                         if (!empty($selected)) {
688                                 // Determine new status
689                                 $result = SQL_QUERY_ESC("SELECT %s FROM `{?_MYSQL_PREFIX?}_%s` WHERE %s=%s LIMIT 1",
690                                 array($row, $table, $idRow, $id), __FUNCTION__, __LINE__);
691
692                                 // Row found?
693                                 if (SQL_NUMROWS($result) == 1) {
694                                         // Load the status
695                                         list($currStatus) = SQL_FETCHROW($result);
696
697                                         // And switch it N<->Y
698                                         if ($currStatus == 'Y') $newStatus = 'N'; else $newStatus = 'Y';
699
700                                         // Change this status
701                                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_%s` SET %s='%s' WHERE %s=%s LIMIT 1",
702                                         array($table, $row, $newStatus, $idRow, $id), __FUNCTION__, __LINE__);
703
704                                         // Count up affected rows
705                                         $cnt += SQL_AFFECTEDROWS();
706                                 } // END - if
707
708                                 // Free the result
709                                 SQL_FREERESULT($result);
710                         } // END - if
711                 } // END - foreach
712
713                 // Output status
714                 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_STATUS_CHANGED'), $cnt, count($IDs)));
715         } else {
716                 // Nothing selected!
717                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NOTHING_SELECTED_CHANGE'));
718         }
719 }
720
721 // Send mails for del/edit/lock build modes
722 function sendAdminBuildMails ($mode, $table, $content, $id, $subjectPart = '') {
723         // Default subject is the subject part
724         $subject = $subjectPart;
725
726         // Is the subject part not set?
727         if (empty($subjectPart)) {
728                 // Then use it from the mode
729                 $subject = strtoupper($mode);
730         } // END - if
731
732         // Is the raw userid set?
733         if (postRequestParameter('userid_raw', $id) > 0) {
734                 // Generate subject
735                 $subjectLine = getMessage('MEMBER_'.strtoupper($subject).'_'.strtoupper($table).'_SUBJECT');
736
737                 // Load email template
738                 if (!empty($subjectPart)) {
739                         $mail = loadEmailTemplate('member_' . $mode . '_' . strtolower($subjectPart) . '_' . $table, $content);
740                 } else {
741                         $mail = loadEmailTemplate('member_' . $mode . '_' . $table, $content);
742                 }
743
744                 // Send email out
745                 sendEmail(postRequestParameter('userid_raw', $id), $subjectLine, $mail);
746         } // END - if
747
748         // Generate subject
749         $subjectLine = getMessage('ADMIN_'.strtoupper($subject).'_'.strtoupper($table).'_SUBJECT');
750
751         // Send admin notification out
752         if (!empty($subjectPart)) {
753                 sendAdminNotification($subjectLine, 'admin_' . $mode . '_' . strtolower($subjectPart) . '_' . $table, $content, postRequestParameter('userid_raw', $id));
754         } else {
755                 sendAdminNotification($subjectLine, 'admin_' . $mode . '_' . $table, $content, postRequestParameter('userid_raw', $id));
756         }
757 }
758
759 // Build a special template list
760 function adminListBuilder ($listType, $IDs, $table, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn) {
761         $OUT = ''; $SW = 2;
762
763         // "Walk" through all entries
764         foreach ($IDs as $id => $selected) {
765                 // Secure id number
766                 $id = bigintval($id);
767
768                 // Get result from a given column array and table name
769                 $result = SQL_RESULT_FROM_ARRAY($table, $columns, $idColumn, $id, __FUNCTION__, __LINE__);
770
771                 // Is there one entry?
772                 if (SQL_NUMROWS($result) == 1) {
773                         // Load all data
774                         $content = SQL_FETCHARRAY($result);
775
776                         // Filter all data
777                         foreach ($content as $key => $value) {
778                                 // Search index
779                                 $idx = array_search($key, $columns, true);
780
781                                 // Do we have a userid?
782                                 if ($key == 'userid') {
783                                         // Add it again as raw id
784                                         $content['userid'] = bigintval($value);
785                                 } // END - if
786
787                                 // Handle the call in external function
788                                 $content[$key] = handleExtraValues($filterFunctions[$idx], $value, $extraValues[$idx]);
789                         } // END - foreach
790
791                         // Add color switching
792                         $content['sw'] = $SW;
793
794                         // Then list it
795                         $OUT .= loadTemplate(sprintf("admin_%s_%s_row",
796                         $listType,
797                         $table
798                         ), true, $content
799                         );
800
801                         // Switch color
802                         $SW = 3 - $SW;
803                 } // END - if
804
805                 // Free the result
806                 SQL_FREERESULT($result);
807         } // END - foreach
808
809         // Load master template
810         loadTemplate(sprintf("admin_%s_%s",
811                 $listType,
812                 $table
813                 ), false, $OUT
814         );
815 }
816
817 // Change status of "build" list
818 function adminBuilderStatusHandler ($mode, $IDs, $table, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $statusArray) {
819         // All valid entries? (We hope so here!)
820         if ((is_array($IDs)) && (count($IDs) > 0) && (count($columns) == count($filterFunctions)) && (count($columns) == count($extraValues)) && (count($statusArray) > 0)) {
821                 // "Walk" through all entries
822                 foreach ($IDs as $id => $sel) {
823                         // Construct SQL query
824                         $sql = sprintf("UPDATE `{?_MYSQL_PREFIX?}_%s` SET", SQL_ESCAPE($table));
825
826                         // Load data of entry
827                         $result = SQL_QUERY_ESC("SELECT * FROM `{?_MYSQL_PREFIX?}_%s` WHERE %s=%s LIMIT 1",
828                                 array($table, $idColumn, $id), __FUNCTION__, __LINE__);
829
830                         // Fetch the data
831                         $content = SQL_FETCHARRAY($result);
832
833                         // Free the result
834                         SQL_FREERESULT($result);
835
836                         // Add all status entries (e.g. status column last_updated or so)
837                         $newStatus = 'UNKNOWN';
838                         $oldStatus = 'UNKNOWN';
839                         $statusColumn = 'unknown';
840                         foreach ($statusArray as $column => $statusInfo) {
841                                 // Does the entry exist?
842                                 if ((isset($content[$column])) && (isset($statusInfo[$content[$column]]))) {
843                                         // Add these entries for update
844                                         $sql .= sprintf(" %s='%s',", SQL_ESCAPE($column), SQL_ESCAPE($statusInfo[$content[$column]]));
845
846                                         // Remember status
847                                         if ($statusColumn == 'unknown') {
848                                                 // Always (!!!) change status column first!
849                                                 $oldStatus = $content[$column];
850                                                 $newStatus = $statusInfo[$oldStatus];
851                                                 $statusColumn = $column;
852                                         } // END - if
853                                 } elseif (isset($content[$column])) {
854                                         // Unfinished!
855                                         app_die(__FUNCTION__, __LINE__, ":UNFINISHED: id={$id}/{$column}[".gettype($statusInfo)."] = {$content[$column]}");
856                                 }
857                         } // END - foreach
858
859                         // Add other columns as well
860                         foreach (postRequestArray() as $key => $entries) {
861                                 // Skip id, raw userid and 'do_$mode'
862                                 if (!in_array($key, array($idColumn, 'userid_raw', ('do_'.$mode)))) {
863                                         // Are there brackets () at the end?
864                                         if (substr($entries[$id], -2, 2) == "()") {
865                                                 // Direct SQL command found
866                                                 $sql .= sprintf(" %s=%s,", SQL_ESCAPE($key), SQL_ESCAPE($entries[$id]));
867                                         } else {
868                                                 // Add regular entry
869                                                 $sql .= sprintf(" %s='%s',", SQL_ESCAPE($key), SQL_ESCAPE($entries[$id]));
870
871                                                 // Add entry
872                                                 $content[$key] = $entries[$id];
873                                         }
874                                 } // END - if
875                         } // END - foreach
876
877                         // Finish SQL statement
878                         $sql = substr($sql, 0, -1) . sprintf(" WHERE `%s`=%s AND `%s`='%s' LIMIT 1",
879                                 $idColumn,
880                                 bigintval($id),
881                                 $statusColumn,
882                                 $oldStatus
883                         );
884
885                         // Run the SQL
886                         SQL_QUERY($sql, __FUNCTION__, __LINE__);
887
888                         // Do we have an URL?
889                         if (isset($content['url'])) {
890                                 // Then add a framekiller test as well
891                                 $content['frametester'] = generateFrametesterUrl($content['url']);
892                         } // END - if
893
894                         // Send "build mails" out
895                         sendAdminBuildMails($mode, $table, $content, $id, $statusInfo[$content[$column]]);
896                 } // END - foreach
897         } // END - if
898 }
899
900 // Delete rows by given id numbers
901 function adminDeleteEntriesConfirm ($IDs, $table, $columns=array(), $filterFunctions=array(), $extraValues=array(), $deleteNow=false, $idColumn='id', $userIdColumn='userid') {
902         // All valid entries? (We hope so here!)
903         if ((is_array($IDs)) && (count($IDs) > 0) && (count($columns) == count($filterFunctions)) && (count($columns) == count($extraValues))) {
904                 // Shall we delete here or list for deletion?
905                 if ($deleteNow === true) {
906                         // The base SQL command:
907                         $sql = "DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_%s` WHERE %s IN (%s)";
908
909                         // Delete them all
910                         $idList = '';
911                         foreach ($IDs as $id => $sel) {
912                                 // Is there a userid?
913                                 if (isPostRequestParameterSet('userid_raw', $id)) {
914                                         // Load all data from that id
915                                         $result = SQL_QUERY_ESC("SELECT * FROM `{?_MYSQL_PREFIX?}_%s` WHERE %s=%s LIMIT 1",
916                                         array($table, $idColumn, $id), __FUNCTION__, __LINE__);
917
918                                         // Fetch the data
919                                         $content = SQL_FETCHARRAY($result);
920
921                                         // Free the result
922                                         SQL_FREERESULT($result);
923
924                                         // Send "build mails" out
925                                         sendAdminBuildMails('del', $table, $content, $id);
926                                 } // END - if
927
928                                 // Add id number
929                                 $idList .= $id . ',';
930                         } // END - foreach
931
932                         // Run the query
933                         SQL_QUERY($sql, array($table, $idColumn, substr($idList, 0, -1)), __FUNCTION__, __LINE__);
934
935                         // Was this fine?
936                         if (SQL_AFFECTEDROWS() == count($IDs)) {
937                                 // All deleted
938                                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_ALL_ENTRIES_REMOVED'));
939                         } else {
940                                 // Some are still there :(
941                                 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_SOME_ENTRIES_NOT_DELETED'), SQL_AFFECTEDROWS(), count($IDs)));
942                         }
943                 } else {
944                         // List for deletion confirmation
945                         adminListBuilder('del', $IDs, $table, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn);
946                 }
947         } // END - if
948 }
949
950 // Edit rows by given id numbers
951 function adminEditEntriesConfirm ($IDs, $table, $columns=array(), $filterFunctions=array(), $extraValues=array(), $editNow=false, $idColumn='id', $userIdColumn='userid') {
952         // All valid entries? (We hope so here!)
953         if ((is_array($IDs)) && (count($IDs) > 0) && (count($columns) == count($filterFunctions)) && (count($columns) == count($extraValues))) {
954                 // Shall we change here or list for editing?
955                 if ($editNow === true) {
956                         // Change them all
957                         $affected = '0';
958                         foreach ($IDs as $id => $sel) {
959                                 // Prepare content array (new values)
960                                 $content = array();
961
962                                 // Prepare SQL for this row
963                                 $sql = sprintf("UPDATE `{?_MYSQL_PREFIX?}_%s` SET",
964                                         SQL_ESCAPE($table)
965                                 );
966                                 foreach (postRequestArray() as $key => $entries) {
967                                         // Skip raw userid which is always invalid
968                                         if ($key == 'userid_raw') {
969                                                 // Continue with next field
970                                                 continue;
971                                         } // END - if
972
973                                         // Is entries an array?
974                                         if (($key != $idColumn) && (is_array($entries)) && (isset($entries[$id]))) {
975                                                 // Add this entry to content
976                                                 $content[$key] = $entries[$id];
977
978                                                 // Send data through the filter function if found
979                                                 if ((isset($filterFunctions[$key])) && (isset($extraValues[$key]))) {
980                                                         // Filter function set!
981                                                         $entries[$id] = handleExtraValues($filterFunctions[$key], $entries[$id], $extraValues[$key]);
982                                                 } // END - if
983
984                                                 // Then add this value
985                                                 $sql .= sprintf(" `%s`='%s',",
986                                                 SQL_ESCAPE($key),
987                                                 SQL_ESCAPE($entries[$id])
988                                                 );
989                                         } elseif (($key != $idColumn) && (!is_array($entries))) {
990                                                 // Add normal entries as well!
991                                                 $content[$key] =  $entries;
992                                         }
993
994                                         // Do we have an URL?
995                                         if ($key == 'url') {
996                                                 // Then add a framekiller test as well
997                                                 $content['frametester'] = generateFrametesterUrl($content[$key]);
998                                         } // END - if
999                                 } // END - foreach
1000
1001                                 // Finish SQL command
1002                                 $sql = substr($sql, 0, -1) . " WHERE `" . $idColumn . "`=" . bigintval($id) . " LIMIT 1";
1003
1004                                 // Run this query
1005                                 SQL_QUERY($sql, __FUNCTION__, __LINE__);
1006
1007                                 // Add affected rows
1008                                 $affected += SQL_AFFECTEDROWS();
1009
1010                                 // Load all data from that id
1011                                 $result = SQL_QUERY_ESC("SELECT * FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`=%s LIMIT 1",
1012                                         array($table, $idColumn, $id), __FUNCTION__, __LINE__);
1013
1014                                 // Fetch the data and merge it into $content
1015                                 $content = merge_array($content, SQL_FETCHARRAY($result));
1016
1017                                 // Free the result
1018                                 SQL_FREERESULT($result);
1019
1020                                 // Send "build mails" out
1021                                 sendAdminBuildMails('edit', $table, $content, $id);
1022                         } // END - foreach
1023
1024                         // Was this fine?
1025                         if ($affected == count($IDs)) {
1026                                 // All deleted
1027                                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_ALL_ENTRIES_EDITED'));
1028                         } else {
1029                                 // Some are still there :(
1030                                 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_SOME_ENTRIES_NOT_EDITED'), $affected, count($IDs)));
1031                         }
1032                 } else {
1033                         // List for editing
1034                         adminListBuilder('edit', $IDs, $table, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn);
1035                 }
1036         } // END - if
1037 }
1038
1039 // Un-/lock rows by given id numbers
1040 function adminLockEntriesConfirm ($IDs, $table, $columns=array(), $filterFunctions=array(), $extraValues=array(), $statusArray=array(), $lockNow=false, $idColumn='id', $userIdColumn='userid') {
1041         // All valid entries? (We hope so here!)
1042         if ((is_array($IDs)) && (count($IDs) > 0) && (count($columns) == count($filterFunctions)) && (count($columns) == count($extraValues)) && (($lockNow === false) || (count($statusArray) == 1))) {
1043                 // Shall we un-/lock here or list for locking?
1044                 if ($lockNow === true) {
1045                         // Un-/lock entries
1046                         adminBuilderStatusHandler('lock', $IDs, $table, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $statusArray);
1047                 } else {
1048                         // List for editing
1049                         adminListBuilder('lock', $IDs, $table, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn);
1050                 }
1051         } // END - if
1052 }
1053
1054 // Undelete rows by given id numbers
1055 function adminUndeleteEntriesConfirm ($IDs, $table, $columns=array(), $filterFunctions=array(), $extraValues=array(), $statusArray=array(), $undeleteNow=false, $idColumn='id', $userIdColumn='userid') {
1056         // All valid entries? (We hope so here!)
1057         if ((is_array($IDs)) && (count($IDs) > 0) && (count($columns) == count($filterFunctions)) && (count($columns) == count($extraValues)) && (($undeleteNow === false) || (count($statusArray) == 1))) {
1058                 // Shall we un-/lock here or list for locking?
1059                 if ($undeleteNow === true) {
1060                         // Undelete entries
1061                         adminBuilderStatusHandler('undelete', $IDs, $table, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $statusArray);
1062                 } else {
1063                         // List for editing
1064                         adminListBuilder('undelete', $IDs, $table, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn);
1065                 }
1066         } // END - if
1067 }
1068
1069 // Checks proxy settins by fetching check-updates3.php from www.mxchange.org
1070 function adminTestProxySettings ($settingsArray) {
1071         // Set temporary the new settings
1072         mergeConfig($settingsArray);
1073
1074         // Now get the test URL
1075         $content = sendGetRequest('check-updates3.php');
1076
1077         // Is the first line with "200 OK"?
1078         $valid = (strpos($content[0], '200 OK') !== false);
1079
1080         // Return result
1081         return $valid;
1082 }
1083
1084 // Sends out a link to the given email adress so the admin can reset his/her password
1085 function sendAdminPasswordResetLink ($email) {
1086         // Init output
1087         $OUT = '';
1088
1089         // Look up administator login
1090         $result = SQL_QUERY_ESC("SELECT `id`, `login`, `password` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `email`='%s' LIMIT 1",
1091                 array($email), __FUNCTION__, __LINE__);
1092
1093         // Is there an account?
1094         if (SQL_HASZERONUMS($result)) {
1095                 // No account found!
1096                 return getMessage('ADMIN_NO_LOGIN_WITH_EMAIL');
1097         } // END - if
1098
1099         // Load all data
1100         $content = SQL_FETCHARRAY($result);
1101
1102         // Free result
1103         SQL_FREERESULT($result);
1104
1105         // Generate hash for reset link
1106         $content['hash'] = generateHash(getConfig('URL') . ':' . $content['id'] . ':' . $content['login'] . ':' . $content['password'], substr($content['password'], 10));
1107
1108         // Remove some data
1109         unset($content['id']);
1110         unset($content['password']);
1111
1112         // Prepare email
1113         $mailText = loadEmailTemplate('admin_reset_password', $content);
1114
1115         // Send it out
1116         sendEmail($email, getMessage('ADMIN_RESET_PASS_LINK_SUBJ'), $mailText);
1117
1118         // Prepare output
1119         return getMessage('ADMIN_RESET_LINK_SENT');
1120 }
1121
1122 // Validate hash and login for password reset
1123 function adminResetValidateHashLogin ($hash, $login) {
1124         // By default nothing validates... ;)
1125         $valid = false;
1126
1127         // Then try to find that user
1128         $result = SQL_QUERY_ESC("SELECT `id`, `password`, `email` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `login`='%s' LIMIT 1",
1129                 array($login), __FUNCTION__, __LINE__);
1130
1131         // Is an account here?
1132         if (SQL_NUMROWS($result) == 1) {
1133                 // Load all data
1134                 $content = SQL_FETCHARRAY($result);
1135
1136                 // Generate hash again
1137                 $hashFromData = generateHash(getConfig('URL') . ':' . $content['id'] . ':' . $login . ':' . $content['password'], substr($content['password'], 10));
1138
1139                 // Does both match?
1140                 $valid = ($hash == $hashFromData);
1141         } // END - if
1142
1143         // Free result
1144         SQL_FREERESULT($result);
1145
1146         // Return result
1147         return $valid;
1148 }
1149
1150 // Reset the password for the login. Do NOT call this function without calling above function first!
1151 function doResetAdminPassword ($login, $password) {
1152         // Generate hash (we already check for sql_patches in generateHash())
1153         $passHash = generateHash($password);
1154
1155         // Update database
1156         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admins` SET `password`='%s' WHERE `login`='%s' LIMIT 1",
1157                 array($passHash, $login), __FUNCTION__, __LINE__);
1158
1159         // Run filters
1160         runFilterChain('post_admin_reset_pass', array('login' => $login, 'hash' => $passHash));
1161
1162         // Return output
1163         return getMessage('ADMIN_PASSWORD_RESET_DONE');
1164 }
1165
1166 // Solves a task by given id number
1167 function adminSolveTask ($id) {
1168         // Update the task data
1169         adminUpdateTaskData($id, 'status', 'SOLVED');
1170 }
1171
1172 // Marks a given task as deleted
1173 function adminDeleteTask ($id) {
1174         // Update the task data
1175         adminUpdateTaskData($id, 'status', 'DELETED');
1176 }
1177
1178 // Function to update task data
1179 function adminUpdateTaskData ($id, $row, $data) {
1180         // Should be admin!
1181         if (!isAdmin()) {
1182                 // Not an admin so redirect better
1183                 redirectToUrl('modules.php?module=index');
1184         } // END - if
1185
1186         // Is the id not set, then we need a backtrace here... :(
1187         if ($id <= 0) {
1188                 // Initiate backtrace
1189                 debug_report_bug(sprintf("id is invalid: %s. row=%s, data=%s",
1190                         $id,
1191                         $row,
1192                         $data
1193                 ));
1194         } // END - if
1195
1196         // Update the task
1197         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_task_system` SET `%s`='%s' WHERE `id`=%s LIMIT 1",
1198                 array(
1199                         $row,
1200                         $data,
1201                         bigintval($id)
1202                 ), __FUNCTION__, __LINE__);
1203 }
1204
1205 // Checks wether if the admin menu has entries
1206 function ifAdminMenuHasEntries ($action) {
1207         return (
1208                 ((
1209                         // Is the entry set?
1210                         isset($GLOBALS['admin_menu_has_entries'][$action])
1211                 ) && (
1212                         // And do we have a menu for this action?
1213                         $GLOBALS['admin_menu_has_entries'][$action] === true
1214                 )) || (
1215                         // Login has always a menu
1216                         $action == 'login'
1217                 )
1218         );
1219 }
1220
1221 // Setter for 'admin_menu_has_entries'
1222 function setAdminMenuHasEntries ($action, $hasEntries) {
1223         $GLOBALS['admin_menu_has_entries'][$action] = (bool) $hasEntries;
1224 }
1225
1226 // Creates a link to the user's admin-profile
1227 function adminCreateUserLink ($userid) {
1228         // Is the userid set correctly?
1229         if ($userid > 0) {
1230                 // Create a link to that profile
1231                 return '{%url=modules.php?module=admin&amp;what=list_user&amp;userid=' . bigintval($userid) . '%}';
1232         } // END - if
1233
1234         // Return a link to the user list
1235         return '{%url=modules.php?module=admin&amp;what=list_user%}';
1236 }
1237
1238 // Generate a "link" for the given admin id (admin_id)
1239 function generateAdminLink ($adminId) {
1240         // No assigned admin is default
1241         $adminLink = '<span class="admin_note">{--ADMIN_NO_ADMIN_ASSIGNED--}</span>';
1242
1243         // Zero? = Not assigned
1244         if (bigintval($adminId) > 0) {
1245                 // Load admin's login
1246                 $login = getAdminLogin($adminId);
1247
1248                 // Is the login valid?
1249                 if ($login != '***') {
1250                         // Is the extension there?
1251                         if (isExtensionActive('admins')) {
1252                                 // Admin found
1253                                 $adminLink = '<a href="' . generateEmailLink(getAdminEmail($adminId), 'admins') . '" title="{--ADMIN_CONTACT_LINK_TITLE--}">' . $login . '</a>';
1254                         } else {
1255                                 // Extension not found
1256                                 $adminLink = getMaskedMessage('EXTENSION_PROBLEM_NOT_INSTALLED', 'admins');
1257                         }
1258                 } else {
1259                         // Maybe deleted?
1260                         $adminLink = '<div class="admin_note">' . getMaskedMessage('ADMIN_ID_404', $adminId) . '</div>';
1261                 }
1262         } // END - if
1263
1264         // Return result
1265         return $adminLink;
1266 }
1267
1268 // Verifies if the current admin has confirmed to alter expert settings
1269 //
1270 // Return values:
1271 // 'failed'    = Something goes wrong (default)
1272 // 'agreed'    = Has verified and and confirmed it to see them
1273 // 'forbidden' = Has not the proper right to alter them
1274 // 'update'    = Need to update extension 'admins'
1275 // 'ask'       = A form was send to the admin
1276 function doVerifyExpertSettings () {
1277         // Default return status is failed
1278         $return = 'failed';
1279
1280         // Is the extension installed and recent?
1281         if (isExtensionInstalledAndNewer('admins', '0.7.3')) {
1282                 // Okay, load the status
1283                 $expertSettings = getAminsExpertSettings();
1284
1285                 // Is he allowed?
1286                 if ($expertSettings == 'Y') {
1287                         // Okay, does he want to see them?
1288                         if (getAminsExpertWarning() == 'Y') {
1289                                 // Ask for them
1290                                 if (isFormSent()) {
1291                                         // Is the element set, then we need to change the admin
1292                                         if (isPostRequestParameterSet('expert_settings')) {
1293                                                 // Get it and prepare final post data array
1294                                                 $postData['login'][getCurrentAdminId()] = getAdminLogin(getCurrentAdminId());
1295                                                 $postData['expert_warning'][getCurrentAdminId()] = 'N';
1296
1297                                                 // Change it in the admin
1298                                                 adminsChangeAdminAccount($postData, 'expert_warning');
1299
1300                                                 // Clear form
1301                                                 unsetPostRequestParameter('ok');
1302                                         } // END - if
1303
1304                                         // All fine!
1305                                         $return = 'agreed';
1306                                 } else {
1307                                         // Send form
1308                                         loadTemplate('admin_expert_settings_form');
1309
1310                                         // Asked for it
1311                                         $return = 'ask';
1312                                 }
1313                         } else {
1314                                 // Do not display
1315                                 $return = 'agreed';
1316                         }
1317                 } else {
1318                         // Forbidden
1319                         $return = 'forbidden';
1320                 }
1321         } else {
1322                 // Out-dated extension or not installed
1323                 $return = 'update';
1324         }
1325
1326         // Output message for other status than ask/agreed
1327         if (($return != 'ask') && ($return != 'agreed')) {
1328                 // Output message
1329                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_EXPERT_SETTINGS_STATUS_' . strtoupper($return)));
1330         } // END - if
1331
1332         // Return status
1333         return $return;
1334 }
1335
1336 // [EOF]
1337 ?>