+
+// Fetch user data for given user id
+function fetchUserData ($userid, $column='userid') {
+ // Don't look for invalid userids...
+ if ($userid < 1) {
+ // Invalid, so abort here
+ debug_report_bug('User id ' . $userid . ' is invalid.');
+ } elseif (isset($GLOBALS['user_data'][$userid])) {
+ // Use cache, so it is fine
+ return true;
+ }
+
+ // By default none was found
+ $found = false;
+
+ // Do we have userid/refid?
+ if (($column == 'userid') || ($column == 'refid')) {
+ // Then secure the id
+ $userid = bigintval($userid);
+ } // END - if
+
+ // Query for the user
+ $result = SQL_QUERY_ESC("SELECT * FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `%s`='%s' LIMIT 1",
+ array($column, $userid), __FUNCTION__, __LINE__);
+
+ // Do we have a record?
+ if (SQL_NUMROWS($result) == 1) {
+ // Load data from cookies
+ $data = SQL_FETCHARRAY($result);
+
+ // Set the userid for later use
+ setCurrentUserId($data['userid']);
+ $GLOBALS['user_data'][getCurrentUserId()] = $data;
+
+ // Rewrite 'last_failure' if found
+ if (isset($GLOBALS['user_data'][getCurrentUserId()]['last_failure'])) {
+ // Backup the raw one and zero it
+ $GLOBALS['user_data'][getCurrentUserId()]['last_failure_raw'] = $GLOBALS['user_data'][getCurrentUserId()]['last_failure'];
+ $GLOBALS['user_data'][getCurrentUserId()]['last_failure'] = 0;
+
+ // Is it not zero?
+ if ($GLOBALS['user_data'][getCurrentUserId()]['last_failure_raw'] != '0000-00-00 00:00:00') {
+ // Seperate data/time
+ $array = explode(' ', $GLOBALS['user_data'][getCurrentUserId()]['last_failure']);
+
+ // Seperate data and time again
+ $array['date'] = explode('-', $array[0]);
+ $array['time'] = explode(':', $array[1]);
+
+ // Now pass it to mktime()
+ $GLOBALS['user_data'][getCurrentUserId()]['last_failure'] = mktime(
+ $array['time'][0],
+ $array['time'][1],
+ $array['time'][2],
+ $array['date'][1],
+ $array['date'][2],
+ $array['date'][0]
+ );
+ } // END - if
+ } // END - if
+
+ // Found, but valid?
+ $found = isUserDataValid();
+ } // END - if
+
+ // Free memory
+ SQL_FREERESULT($result);
+
+ // Return result
+ return $found;
+}
+
+// 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);