+// Checks wether the current user is a member
+function IS_MEMBER () {
+ // By default no member
+ $ret = false;
+
+ // Fix missing 'last' array, damn stupid code :(((
+ // @TODO Try to rewrite this to one or more functions
+ if ((!isset($GLOBALS['last'])) || (!is_array($GLOBALS['last']))) $GLOBALS['last'] = array();
+
+ // is the cache entry there?
+ if (isset($GLOBALS['is_member'])) {
+ // Then return it
+ return $GLOBALS['is_member'];
+ } // END - if
+
+ // Init global 'status'
+ $GLOBALS['status'] = false;
+
+ // Fix "deleted" cookies first
+ fixDeletedCookies(array('userid', 'u_hash'));
+
+ // Are cookies set?
+ if ((isUserIdSet()) && (isSessionVariableSet('u_hash'))) {
+ // Cookies are set with values, but are they valid?
+ $result = SQL_QUERY_ESC("SELECT password, status, last_module, last_online FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
+ array(getUserId()), __FUNCTION__, __LINE__);
+ if (SQL_NUMROWS($result) == 1) {
+ // Load data from cookies
+ list($password, $GLOBALS['status'], $mod, $onl) = SQL_FETCHROW($result);
+
+ // Validate password by created the difference of it and the secret key
+ $valPass = generatePassString($password);
+
+ // Transfer last module and online time
+ if ((!empty($mod)) && (empty($GLOBALS['last']['module']))) {
+ // @TODO Try to rewrite this to one or more functions
+ $GLOBALS['last']['module'] = $mod;
+ $GLOBALS['last']['online'] = $onl;
+ } // END - if
+
+ // So did we now have valid data and an unlocked user?
+ if (($GLOBALS['status'] == 'CONFIRMED') && ($valPass == getSession('u_hash'))) {
+ // Account is confirmed and all cookie data is valid so he is definely logged in! :-)
+ $ret = true;
+ } else {
+ // Maybe got locked etc.
+ //* DEBUG: */ echo __LINE__."!!!<br />";
+ destroyUserSession();
+ }
+ } else {
+ // Cookie data is invalid!
+ //* DEBUG: */ echo __LINE__."***<br />";
+ destroyUserSession();
+ }
+
+ // Free memory
+ SQL_FREERESULT($result);
+ } else {
+ // Cookie data is invalid!
+ //* DEBUG: */ echo __LINE__."///<br />";
+ destroyUserSession();
+ }
+
+ // Cache status
+ $GLOBALS['is_member'] = $ret;
+
+ // Return status
+ return $ret;
+}
+