function user_edit_student_user_form

6.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.

File

modules/user/user.module, line 494

Code

function user_edit_student_user_form() {

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

  $form = array();
  $student_cwid = $_REQUEST ["student_cwid"];
  $user_id = db_get_user_id_from_cwid($student_cwid, "student");

  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 a 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."),
    );

    $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."),
    );


    $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 the LDAP module,
                        the LDAP password will be unaffected."),
  );

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

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

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

  $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."),
  );


  // 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."),
  );

  $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."),
  );

  $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>",
  );

  $form ["major_code"] = array(
    "label" => t("Major code:"),
    "type" => "textfield",
    "value" => $cur ["major_code"],
    "size" => 10,
  );

  $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."),
  );

  $form ["is_active"] = array(
    "label" => t("Is active:"),
    "type" => "textfield",
    "value" => $cur ["is_active"],
    "size" => 5,
    "description" => t("Enter only 1 or 0 (number one for 'yes', or number zero for 'no').  This setting means the student
                      will not appear in searches automatically, unless the advisor specifies to search
                      for inactive students."),
  );




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


  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>",
    );
  }

  return $form;

}