+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret=' . intval($ret));
+ return $ret;
+}
+
+// Fetch user data for given user id
+function fetchUserData ($userid, $column = 'userid') {
+ // If we should look for userid secure&set it here
+ if (substr($column, -2, 2) == 'id') {
+ // Secure userid
+ $userid = bigintval($userid);
+
+ // Set it here
+ setCurrentUserId($userid);
+
+ // Don't look for invalid userids...
+ if (!isValidUserId($userid)) {
+ // Invalid, so abort here
+ debug_report_bug(__FUNCTION__, __LINE__, 'User id ' . $userid . ' is invalid.');
+ } elseif (isUserDataValid()) {
+ // Use cache, so it is fine
+ return true;
+ }
+ } elseif (isUserDataValid()) {
+ // Use cache, so it is fine
+ return true;
+ }
+
+ // By default none was found
+ $found = false;
+
+ // Extra statements
+ $ADD = '';
+ if (isExtensionInstalledAndNewer('user', '0.3.5')) $ADD = ', UNIX_TIMESTAMP(`lock_timestamp`) AS `lock_timestamp`';
+
+ // Query for the user
+ $result = SQL_QUERY_ESC("SELECT *".$ADD." 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_raw']);
+
+ // 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 () {
+ // No admin in installation phase!
+ if ((isInstallationPhase()) || (!isAdminRegistered())) {
+ return false;
+ } // END - if
+
+ // Init variables
+ $ret = false;
+ $adminId = '0';
+ $passCookie = '';
+ $valPass = '';
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $adminId);
+
+ // If admin login is not given take current from cookies...
+ if ((isSessionVariableSet('admin_id')) && (isSessionVariableSet('admin_md5'))) {
+ // Get admin login and password from session/cookies
+ $adminId = getSession('admin_id');
+ $passCookie = getSession('admin_md5');
+ } // END - if
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $adminId.'/'.$passCookie);
+
+ // Abort if admin id is zero
+ if ($adminId == '0') {
+ return false;
+ } // END - if
+
+ // Do we have cache?
+ if (!isset($GLOBALS[__FUNCTION__][$adminId])) {
+ // Init it with failed
+ $GLOBALS[__FUNCTION__][$adminId] = false;
+
+ // Search in array for entry
+ if (isset($GLOBALS['admin_hash'])) {
+ // Use cached string
+ $valPass = $GLOBALS['admin_hash'];
+ } elseif ((!empty($passCookie)) && (isAdminHashSet($adminId) === true) && (!empty($adminId))) {
+ // Login data is valid or not?
+ $valPass = encodeHashForCookie(getAdminHash($adminId));
+
+ // Cache it away
+ $GLOBALS['admin_hash'] = $valPass;
+
+ // Count cache hits
+ incrementStatsEntry('cache_hits');
+ } elseif ((!empty($adminId)) && ((!isExtensionActive('cache')) || (isAdminHashSet($adminId) === false))) {
+ // Get admin hash and hash it
+ $valPass = encodeHashForCookie(getAdminHash($adminId));
+
+ // Cache it away
+ $GLOBALS['admin_hash'] = $valPass;
+ }
+
+ if (!empty($valPass)) {
+ // Check if password is valid
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '(' . $valPass . '==' . $passCookie . ')='.intval($valPass == $passCookie));
+ $GLOBALS[__FUNCTION__][$adminId] = (($GLOBALS['admin_hash'] == $passCookie) || ((strlen($GLOBALS['admin_hash']) == 32) && ($GLOBALS['admin_hash'] == md5($passCookie))) || (($GLOBALS['admin_hash'] == '*FAILED*') && (!isExtensionActive('cache'))));
+ } // END - if
+ } // END - if
+
+ // Return result of comparision
+ return $GLOBALS[__FUNCTION__][$adminId];
+}
+
+// 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` ASC',
+ __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` ASC',
+ __FUNCTION__, __LINE__);
+ break;
+
+ default: // Invalid!
+ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Invalid mode %s detected.", $mode));
+ break;
+ }
+
+ // Some entries are found?
+ if (!SQL_HASZERONUMS($result)) {
+ $OUT = '';
+ while ($content = SQL_FETCHARRAY($result)) {
+ $OUT .= ' <option value="' . $content['value'] . '"';
+ if (postRequestParameter('max_mails') == $content['value']) $OUT .= ' selected="selected"';
+ $OUT .= '>' . $content['value'] . ' {--PER_DAY--}';
+ if (!empty($content['comment'])) $OUT .= '(' . $content['comment'] . ')';
+ $OUT .= '</option>';
+ }
+
+ // Load template
+ $OUT = loadTemplate(($mode . '_receive_table'), true, $OUT);
+ } else {
+ // Maybe the admin has to setup some maximum values?
+ debug_report_bug(__FUNCTION__, __LINE__, '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 '%%%s%%' OR `email` LIKE '%%%s%%' LIMIT 1",
+ array($email, str_replace('.', '{DOT}', $email)), __FUNCTION__, __LINE__);
+
+ // Is the email there?
+ $ret = (SQL_NUMROWS($result) == 1);
+
+ // Free the result
+ SQL_FREERESULT($result);
+
+ // Return result