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