function fp_load_user

6.x db.inc fp_load_user($user_id)
4.x db.inc fp_load_user($user_id)
5.x db.inc fp_load_user($user_id)

Returns back a user object for this user_id. If the user is not found in the users table, it will return NULL. If the user_id requested is 0, the anonymous user object is returned.

5 calls to fp_load_user()
content_display_content_admin_list in modules/content/content.module
Display a list of content for the administrator
content_view_content in modules/content/content.module
Display the content specified in the GET's cid.
stats_report_access_stats in modules/stats/stats.module
This report shows recent activity in FlightPath. It can also be used to see if anyone is "online" in that they would have activity less than 5 minutes old.
system_init in modules/system/system.module
Called on every page load.
system_login_form_submit in modules/system/system.module
Submit handler for login form. If we are here, it probably means we have indeed authenticated. Just in case, we will test the form_state["passed_authentication"] value, which we expect to have been set in our validate handler.

File

includes/db.inc, line 86
This file contains mostly db shortcuts.

Code

function fp_load_user($user_id) {

  $rtn = new stdClass();

  if ($user_id == 0) {
    // Return the anonymous user.
    $rtn->id = 0;
    $rtn->name = t("Anonymous");
    $rtn->roles = array(1 => "anonymous user");
    $rtn->permissions = fp_get_permissions_for_role(1);
    return $rtn;
  }

  $res = db_query("SELECT * FROM users WHERE user_id = '?' ", $user_id);
  if (db_num_rows($res) == 0) {
    return NULL;
  }
  $cur = db_fetch_object($res);

  $rtn->id = $cur->user_id;
  $rtn->name = $cur->user_name;
  $rtn->f_name = $cur->f_name;
  $rtn->l_name = $cur->l_name;
  $rtn->email = $cur->email;
  $rtn->cwid = $cur->cwid;
  $rtn->is_student = (bool) $cur->is_student;
  $rtn->is_faculty = (bool) $cur->is_faculty;
  $rtn->roles = array();
  $rtn->permissions = array();

  // Load the user's roles and    
  $res = db_query("SELECT * FROM user_roles a,                                
                                roles c
                  WHERE a.user_id = '?'
                  AND a.rid = c.rid", $user_id);
  while ($cur = db_fetch_array($res)) {
    $rtn->roles [$cur ["rid"]] = $cur ["name"];
  }

  // Let's make sure we get the authenticated user role as well, #2.
  $rtn->roles [2] = "authenticated user";

  // Go through each role and add in the permissions for each role.
  foreach ($rtn->roles as $rid => $val) {
    $perms = fp_get_permissions_for_role($rid);
    // Merge the arrays while KEEPING the original's key.  So don't
    // use array_merge, use the + operator.
    $rtn->permissions = $rtn->permissions + $perms;
  }


  return $rtn;
}