function user_edit_student_user_form

6.x user.student.inc user_edit_student_user_form()
7.x user.student.inc user_edit_student_user_form()
4.x user.module user_edit_student_user_form()
5.x user.student.inc user_edit_student_user_form()

Let the user edit a studentuser's information.

1 string reference to 'user_edit_student_user_form'
schools_form_alter in modules/schools/schools.module
Implements hook_form_alter

File

modules/user/user.student.inc, line 798
Keep track of functions dealing specifically with student user management

Code

function user_edit_student_user_form() {

  fp_add_js(fp_get_module_path("user") . "/js/user.js");

  $form = array();
  $m = 0;
  $student_cwid = @$_REQUEST ["student_cwid"]; // now getting it from argument
  $de_catalog_year = @$_REQUEST ["de_catalog_year"];
  $user_id = db_get_user_id_from_cwid($student_cwid, "student");

  $db = get_global_database_handler();

  // Figure out what the page's sub-tabs should be, and set them.
  $tab_array = array();
  $tab_array [0]["title"] = t("Edit Student");
  $tab_array [0]["active"] = TRUE;
  $tab_array [0]["on_click"] = "window.location=\"" . fp_url("admin/users/edit-student-user", "student_cwid=$student_cwid&de_catalog_year=$de_catalog_year") . "\"";

  $tab_array [1]["title"] = t("Edit Student Courses");
  $tab_array [1]["active"] = FALSE;
  $tab_array [1]["on_click"] = "window.location=\"" . fp_url("admin/users/edit-student-user/courses", "student_cwid=$student_cwid&de_catalog_year=$de_catalog_year") . "\"";

  // If there are attributes for a student, then show the tab.
  $attributes = user_get_registered_attributes();

  foreach ($attributes as $def) {
    if (@$def ['settings']['user_type'] == 'student' || @$def ['settings']['user_type'] == 'all') {
      $tab_array [2]["title"] = t("Edit User Attributes");
      $tab_array [2]["active"] = FALSE;
      $tab_array [2]["on_click"] = "window.location=\"" . fp_url("admin/users/edit-student-user/attributes", "user_id=$user_id&user_type=student&student_cwid=$student_cwid&de_catalog_year=$de_catalog_year") . "\"";
      break;
    }
  }



  fp_set_page_sub_tabs($tab_array);






  if ($student_cwid != "new") {
    $name = fp_get_student_name($student_cwid);
    fp_set_title(t("Edit Student User @name (@id)", array("@name" => $name, "@id" => $student_cwid)));
  }
  else {
    // A new student!
    fp_set_title(t("Create New Student User"));
  }

  $form ["user_id"] = array(
    "type" => "hidden",
    "value" => $user_id,
  );

  $form ["perform_action2"] = array(
    "type" => "hidden",
    "value" => "",
  );

  $form ["student_cwid"] = array(
    "type" => "hidden",
    "value" => $student_cwid,
  );


  // TODO: At the moment, only faculty can be assigned roles in FP.  However, this could change
  // one day, so I am going to leave this code in place for students, but commented out.
  /*
  $user_roles = system_get_roles_for_user($user_id);
  //fpm($user_roles);
  $default_values = array();
  foreach ($user_roles as $rid => $val) {
    $default_values[$rid] = $rid;
  }

  // Show a list of roles in the system which we may select from, and check the ones
  // all ready assigned to this user.
  
  $options = array();
      
  $res = db_query("SELECT * FROM roles ORDER BY rid");
  while ($cur = db_fetch_array($res)) {
    
    $key = $cur["rid"];
    $value = $cur["name"];

    if ($key > 2) {
      $options[$key] = $value;
    } 
      
  }  
//fpm($default_values);
  $form["roles"] = array(
    "label" => t("Check which roles this user should have."),
    "type" => "checkboxes",
    "options" => $options,
    "value" => $default_values,
  );
  */


  // Let's present the form elements to allow some basic editing of this user.

  // Only if we are making a new student...
  if ($student_cwid == "new") {
    $form ["new_student_cwid"] = array(
      "label" => t("Enter a new CWID, unique to students:"),
      "type" => "textfield",
      "size" => 20,
      "required" => TRUE,
      "description" => t("Enter an alpha-numeric ID for this student.  It may be the same
                          as a faculty member, but may not be the same as any existing
                          student.  You will not be able to edit this value, once saved."),
      "weight" => 10,
    );

    $form ["new_user_name"] = array(
      "label" => t("Enter a new username, unique to all users:"),
      "type" => "textfield",
      "size" => 20,
      "required" => TRUE,
      "description" => t("Enter a username for this user.  This is what the user will
                          use to log in.  It must be unique to all users (cannot have both
                          a faculty and a student with the same username).  You will not
                          be able to edit this value, once saved."),
      "weight" => 10,
    );


    $cur = array();
  }
  else {
    // NOT a new student.  Load their information normally.

    $res = db_query("SELECT * FROM users u, students s
                     WHERE u.cwid = '?'
                     AND u.is_student = '1'
                     AND u.cwid = s.cwid", $student_cwid);
    $cur = db_fetch_array($res);
  }

  $user_name = @$cur ["user_name"];
  if ($user_name != "") {
    $form ["mark" . $m++] = array(
      "value" => "<p><b>Username:</b> $user_name</p>",
    );
  }

  $form ["new_password"] = array(
    "label" => t("Enter a new password for this user:"),
    "type" => "textfield",
    "size" => 20,
    "required" => ($student_cwid == "new") ? TRUE : FALSE,
    "description" => t("If you enter any value here, it will change the
                        user's password in FlightPath.  If you are using a single-sign-on or similar module (CAS, SAML, LDAP, etc)
                        for external user password management, the password will be <strong>unaffected</strong> by this setting."),
    "weight" => 20,
  );

  $form ["email"] = array(
    "label" => t("Email:"),
    "type" => "textfield",
    "value" => @$cur ["email"],
    "weight" => 30,
  );

  $form ["f_name"] = array(
    "label" => t("First name:"),
    "type" => "textfield",
    "value" => @$cur ["f_name"],
    "weight" => 40,
  );

  $form ["l_name"] = array(
    "label" => t("Last name:"),
    "type" => "textfield",
    "value" => @$cur ["l_name"],
    "weight" => 50,
  );

  $form ["is_disabled"] = array(
    "label" => t("Is disabled:"),
    "type" => "textfield",
    "value" => @$cur ["is_disabled"],
    "size" => 5,
    "description" => t("Enter only 1 or 0 (number one for 'yes', or number zero for 'no').  This setting means the user will
                        be ignored by FlightPath, and they will not be able to log in or be searched for.
                        It is safer to disable a user, than delete them."),
    "weight" => 60,
  );


  // Unique to students...
  $form ["cumulative_hours"] = array(
    "label" => t("Cumulative hours:"),
    "type" => "textfield",
    "value" => @$cur ["cumulative_hours"],
    "size" => 5,
    "description" => t("How many hours has the student earned?  NOTE: If FlightPath is set to
                        calculate this, rather than read from the database, whatever you enter here
                        will be ignored, and instead this value will be calculated on the fly when
                        the student is loaded."),
    "weight" => 70,
  );

  $form ["gpa"] = array(
    "label" => t("GPA:"),
    "type" => "textfield",
    "value" => @$cur ["gpa"],
    "size" => 5,
    "description" => t("What is the student's GPA?  NOTE: If FlightPath is set to
                        calculate this, rather than read from the database, whatever you enter here
                        will be ignored, and instead this value will be calculated on the fly when
                        the student is loaded."),
    "weight" => 80,
  );

  $form ["rank_code"] = array(
    "label" => t("Rank or Classification:"),
    "type" => "textfield",
    "value" => @$cur ["rank_code"],
    "size" => 5,
    "description" => t("For example, FR, SO, JR, SR, GR for Freshman, Sophomore, Junior, Senior, and Graduate.") . "
                      <br><b>" . t("Important:") . "</b> " . t("You must enter a code from the Allowed Student Ranks field
                      on the System Settings form.  For example, FR.  If you do not do this, you will not be able to search
                      for this student in FlightPath.") . "<br>&nbsp; &nbsp; &nbsp;" . t("Current value for Allowed Student Ranks:") . " 
                      <i>" . variable_get("allowed_student_ranks", "") . "</i>",
    "weight" => 90,
  );


  $major_code_array = $db->get_student_majors_from_db($student_cwid, TRUE, FALSE, FALSE);

  $temp = "";
  foreach ($major_code_array as $details) {
    if ((string) $details ["is_editable"] == "1") {
      $temp .= "* ";
    }

    $temp .= $details ["major_code"] . "\n";
  }

  $form ["major_codes"] = array(
    "label" => t("Major code(s) and Directives:"),
    "type" => "textarea",
    "value" => $temp,
    "cols" => 40,
    "rows" => 5,
    "description" => t("Enter the student's major codes, one per line.
                          <br>Ex:
                          <br>&nbsp; &nbsp; ACCT
                          <br>&nbsp; &nbsp; MATH
                        <br>Advanced: If any of the level 3 (add-on) major codes can be 'editable' by the advisor or another
                        privileged user during normal advising, add an asterisk
                        at the beginning.  For example: <b>*</b> ACCT|_COSC.  If you are unsure what this means, do not enter an asterisk.
                        <br>
                        <br>Available directives (advanced):
                        <ul>
                          <li>LOCKED ~ level_3_class_code
                          <ul>
                            <li>
                              This will tell FlightPath not to allow a user to make any changes (except in What If mode) to this student's degrees for the specified
                              level 3 classification.  For example, to prevent additions or removals from Concentrations (CONC) for this student, you would enter:
                              <br> &nbsp; &nbsp; &nbsp; LOCKED ~ CONC
                              <br>(notice the single tilde ~ character between the LOCKED keyword and the code for the degree class).                              
                            </li> 
                          </ul>
                          </li>
                        </ul>  
                            
                            
                            "),
    "weight" => 100,
  );


  $form ["catalog_year"] = array(
    "label" => t("Catalog year:"),
    "type" => "textfield",
    "value" => @$cur ["catalog_year"],
    "size" => 10,
    "description" => t("Only the leading year is used.  For example, for the
                        catalog year 2008-2009, you would just enter 2008."),
    "weight" => 110,
  );

  $form ["is_active"] = array(
    "label" => t("Active?:"),
    "type" => "select",
    "options" => array(1 => t("Y - Active"), 0 => t("N - Inactive")),
    "hide_please_select" => TRUE,
    "value" => @$cur ["is_active"],
    "size" => 5,
    "description" => t("This setting means the student
                      will not appear in searches automatically, unless the advisor specifies to search
                      for inactive students."),
    "weight" => 120,
  );




  $form ["submit"] = array(
    "type" => "submit",
    "value" => "Submit",
    "prefix" => "<hr>",
    "weight" => 500,
  );


  if ($student_cwid != "new" && user_has_permission("delete_users")) {

    $form ["mark" . $m++] = array(
      "type" => "markup",
      "value" => "<div align='right'>
                        " . t("Delete this student?") . " <input type='button' value='X'
                        onClick='userDeleteStudent();'>
                      </div>",
      "weight" => 600,
    );
  }





  return $form;

}