function advise_can_access_view

6.x advise.module advise_can_access_view($student_id = "")
4.x advise.module advise_can_access_view()
5.x advise.module advise_can_access_view($student_id = "")

Used by the menu to determine if the user can see the View tab for the current student.

1 call to advise_can_access_view()
advise_init in modules/advise/advise.module
Implementation of hook_init

File

modules/advise/advise.module, line 259

Code

function advise_can_access_view($student_id = "") {
  global $current_student_id, $user;

  if ($student_id == "") {
    $student_id = $current_student_id;
  }


  // must be logged in first...
  if (!user_has_permission("access_logged_in_content")) {
    return FALSE;
  }

  if ($student_id == "" || $student_id === 0) {
    return FALSE;
  }

  if ($user->id == 1) {
    return TRUE; // the admin user.
  }

  // Can the user view ANY advising session?
  if (user_has_permission("view_any_advising_session")) {
    return TRUE;
  }

  // can the user only see their own advisees, and is this student one of their advisees?
  if (user_has_permission("view_advisee_advising_session")) {
    // Is the student_id in their list of advisees?
    $advisees = advise_get_advisees();

    if (in_array($student_id, $advisees)) {
      return TRUE;
    }
  }

  // Is this user viewing THEIR OWN advising session?
  if (user_has_permission("view_own_advising_session")) {

    if ($student_id == $user->cwid && ($student_id != "" && $student_id !== 0)) {
      return TRUE;
    }
  }


  // All else fails, return FALSE  
  return FALSE;

}