/** * Create or update user settings for the active Phorum user. * * This function can be used to store arbitrairy settings for the active * Phorum user in the database. The main goal for this function is to store * user settings which are not available as a Phorum user table field in * the database. These are settings which do not really belong to the Phorum * core, but which are for example used for remembering some kind of state * in a user interface (templates). Since each user interface might require * different settings, a dynamic settings storage like this is required. * * If you are writing modules that need to store data for a user, then please * do not use this function. Instead, use custom profile fields. The data * that is stored using this function can be best looked at as if it were * session data. * * @param array $settings * An array of setting name => value pairs to store as user * settings in the database. */ function phorum_api_user_save_settings($settings) { global $PHORUM; // Get the active user's user_id. if (empty($PHORUM['user']['user_id'])) { return; } $user_id = $PHORUM['user']['user_id']; // The settings data must always be an array. if (empty($PHORUM['user']['settings_data'])) { $PHORUM['user']['settings_data'] = array(); } // Merge the setting with the existing settings. if (is_array($settings)) { foreach ($settings as $name => $value) { if ($value === NULL) { unset($PHORUM['user']['settings_data'][$name]); } else { $PHORUM['user']['settings_data'][$name] = $value; } } } // Save the settings in the database. phorum_db_user_save(array('user_id' => $user_id, 'settings_data' => $PHORUM['user']['settings_data'])); // If user caching is enabled, we remove the user from the cache. if (!empty($GLOBALS['PHORUM']['cache_users'])) { phorum_cache_remove('user', $user_id); } }
/** * This function quickly updates real columns without any further checks * it just stores the data as fast as possible * */ function phorum_user_save_simple($user) { if ( empty( $user["user_id"] ) ) return false; // clear the cache only if we are not just updating the activity if(isset($GLOBALS['PHORUM']['cache_users']) && $GLOBALS['PHORUM']['cache_users']) { if(!(count($user) == 3 && isset($user['date_last_active']))) phorum_cache_remove('user',$user['user_id']); } $ret = phorum_db_user_save( $user ); return $ret; }
/** * Add a user. * * @param array $userdata * An array containing the fields to insert into the user table. * This array should contain at least a "username" field. See * phorum_db_user_save() for some more info on the other data * in this array. * * @return integer $user_id * The user_id that was assigned to the new user. */ function phorum_db_user_add($userdata) { $PHORUM = $GLOBALS['PHORUM']; // We need at least the username for the user. if (!isset($userdata['username'])) { trigger_error('phorum_db_user_add: Missing field in userdata: username', E_USER_ERROR); } $username = phorum_db_interact(DB_RETURN_QUOTED, $userdata['username']); // We can set the user_id. If not, then we'll create a new user_id. if (isset($userdata['user_id'])) { $user_id = (int) $userdata['user_id']; $fields = 'user_id, username, signature, moderator_data, settings_data'; $values = "{$user_id}, '{$username}', '', '', ''"; } else { $fields = 'username, signature, moderator_data, settings_data'; $values = "'{$username}', '', '', ''"; } // Insert a bare bone user in the database. $user_id = phorum_db_interact(DB_RETURN_NEWID, "INSERT INTO {$PHORUM['user_table']}\n ({$fields})\n VALUES ({$values})", NULL, DB_MASTERQUERY); // Set the rest of the data using the phorum_db_user_save() function. $userdata['user_id'] = $user_id; phorum_db_user_save($userdata); return $user_id; }
} else { $user=phorum_user_get($user_id); if($user["active"]==PHORUM_USER_PENDING_BOTH){ $userdata["active"]=PHORUM_USER_PENDING_EMAIL; } else { $userdata["active"]=PHORUM_USER_ACTIVE; // send reg approved message $maildata["mailsubject"]=$PHORUM["DATA"]["LANG"]["RegApprovedSubject"]; $maildata["mailmessage"]=wordwrap($PHORUM["DATA"]["LANG"]["RegApprovedEmailBody"], 72); phorum_email_user(array($user["email"]), $maildata); } } $userdata["user_id"]=$user_id; phorum_db_user_save($userdata); } } if(empty($users)){ $PHORUM["DATA"]["MESSAGE"] = $PHORUM["DATA"]["LANG"]["NoUnapprovedUsers"]; } else { // get a fresh list to update any changes $users=phorum_db_user_get_unapproved(); $PHORUM["DATA"]["USERS"]=$users; $PHORUM["DATA"]["ACTION"]=phorum_get_url( PHORUM_CONTROLCENTER_ACTION_URL ); $PHORUM["DATA"]["FORUM_ID"]=$PHORUM["forum_id"];