+
+// This patched function will reduce many SELECT queries for the specified or current admin login
+function isAdmin ($admin = '') {
+ // Init variables
+ $ret = false; $passCookie = ''; $valPass = '';
+ //* DEBUG: */ print(__FUNCTION__.':'.$admin.'<br />');
+
+ // If admin login is not given take current from cookies...
+ if ((empty($admin)) && (isSessionVariableSet('admin_login')) && (isSessionVariableSet('admin_md5'))) {
+ // Get admin login and password from session/cookies
+ $admin = getSession('admin_login');
+ $passCookie = getSession('admin_md5');
+ } // END - if
+ //* DEBUG: */ print(__FUNCTION__.':'.$admin.'/'.$passCookie.'<br />');
+
+ // Do we have cache?
+ if (!isset($GLOBALS['is_admin'][$admin])) {
+ // Init it with failed
+ $GLOBALS['is_admin'][$admin] = false;
+
+ // Search in array for entry
+ if (isset($GLOBALS['admin_hash'])) {
+ // Use cached string
+ $valPass = $GLOBALS['admin_hash'];
+ } elseif ((!empty($passCookie)) && (isAdminHashSet($admin) === true) && (!empty($admin))) {
+ // Login data is valid or not?
+ $valPass = generatePassString(getAdminHash($admin));
+
+ // Cache it away
+ $GLOBALS['admin_hash'] = $valPass;
+
+ // Count cache hits
+ incrementStatsEntry('cache_hits');
+ } elseif ((!empty($admin)) && ((!isExtensionActive('cache'))) || (isAdminHashSet($admin) === false)) {
+ // Search for admin
+ $result = SQL_QUERY_ESC("SELECT HIGH_PRIORITY `password` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `login`='%s' LIMIT 1",
+ array($admin), __FUNCTION__, __LINE__);
+
+ // Is he admin?
+ $passDB = '';
+ if (SQL_NUMROWS($result) == 1) {
+ // Admin login was found so let's load password from DB
+ list($passDB) = SQL_FETCHROW($result);
+
+ // Temporary cache it
+ setAdminHash($admin, $passDB);
+
+ // Generate password hash
+ $valPass = generatePassString($passDB);
+ } // END - if
+
+ // Free memory
+ SQL_FREERESULT($result);
+ }
+
+ if (!empty($valPass)) {
+ // Check if password is valid
+ //* DEBUG: */ print(__FUNCTION__ . ':(' . $valPass . '==' . $passCookie . ')='.intval($valPass == $passCookie).'<br />');
+ $GLOBALS['is_admin'][$admin] = (($valPass == $passCookie) || ((strlen($valPass) == 32) && ($valPass == md5($passCookie))) || (($valPass == '*FAILED*') && (!isExtensionActive('cache'))));
+ } // END - if
+ } // END - if
+
+ // Return result of comparision
+ return $GLOBALS['is_admin'][$admin];
+}
+
+// Generates a list of "max receiveable emails per day"
+function addMaxReceiveList ($mode, $default = '', $return = false) {
+ $OUT = '';
+ $result = false;
+
+ switch ($mode) {
+ case 'guest':
+ // Guests (in the registration form) are not allowed to select 0 mails per day.
+ $result = SQL_QUERY("SELECT value, comment FROM `{?_MYSQL_PREFIX?}_max_receive` WHERE value > 0 ORDER BY value",
+ __FUNCTION__, __LINE__);
+ break;
+
+ case 'member':
+ // Members are allowed to set to zero mails per day (we will change this soon!)
+ $result = SQL_QUERY("SELECT value, comment FROM `{?_MYSQL_PREFIX?}_max_receive` ORDER BY value",
+ __FUNCTION__, __LINE__);
+ break;
+
+ default: // Invalid!
+ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Invalid mode %s detected.", $mode));
+ break;
+ }
+
+ // Some entries are found?
+ if (SQL_NUMROWS($result) > 0) {
+ $OUT = '';
+ while ($content = SQL_FETCHARRAY($result)) {
+ $OUT .= " <option value=\"".$content['value']."\"";
+ if (postRequestElement('max_mails') == $content['value']) $OUT .= ' selected="selected"';
+ $OUT .= ">".$content['value']." {--PER_DAY--}";
+ if (!empty($content['comment'])) $OUT .= " (".$content['comment'].')';
+ $OUT .= "</option>\n";
+ }
+
+ // Load template
+ $OUT = loadTemplate(($mode . '_receive_table'), true, $OUT);
+ } else {
+ // Maybe the admin has to setup some maximum values?
+ debug_report_bug('Nothing is being done here?');
+ }
+
+ // Free result
+ SQL_FREERESULT($result);
+
+ if ($return === true) {
+ // Return generated HTML code
+ return $OUT;
+ } else {
+ // Output directly (default)
+ outputHtml($OUT);
+ }
+}
+
+// Checks wether the given email address is used.
+function isEmailTaken ($email) {
+ // Query the database
+ $result = SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE email LIKE '{PER}%s{PER}' LIMIT 1",
+ array($email), __FUNCTION__, __LINE__);
+
+ // Is the email there?
+ $ret = (SQL_NUMROWS($result) == 1);
+
+ // Free the result
+ SQL_FREERESULT($result);
+
+ // Return result
+ return $ret;
+}
+
+// Validate the given menu action
+function isMenuActionValid ($mode, $action, $what, $updateEntry=false) {
+ // Is the cache entry there and we shall not update?
+ if ((isset($GLOBALS['action_valid'][$mode][$action][$what])) && ($updateEntry === false)) {
+ // Count cache hit
+ incrementStatsEntry('cache_hits');
+
+ // Then use this cache
+ return $GLOBALS['action_valid'][$mode][$action][$what];
+ } // END - if
+
+ // By default nothing is valid