function user_edit_user_form_submit

7.x user.module user_edit_user_form_submit($form, $form_state)
6.x user.module user_edit_user_form_submit($form, $form_state)
4.x user.module user_edit_user_form_submit($form, $form_state)
5.x user.module user_edit_user_form_submit($form, $form_state)

Submit handler for our edit faculty form

File

modules/user/user.module, line 1019

Code

function user_edit_user_form_submit($form, $form_state) {

  $values = $form_state ["values"];

  foreach ($values as $key => $val) {
    if (!is_array($val)) {
      $values [$key] = trim($val);
    }
  }

  $user_id = $values ["user_id"];
  $faculty_cwid = $values ["faculty_cwid"];
  // Save the roles into the database for this user.
  // Begin by deleting what's there all ready.
  db_query("DELETE FROM user_roles WHERE user_id = ? ", $user_id);

  if (is_array($values ["roles"])) {
    foreach ($values ["roles"] as $rid) {
      //fpm("inserting $rid");
      db_query("INSERT INTO user_roles (user_id, rid)
                VALUES (?, ?) ", $user_id, $rid);
    }
  }

  // Are we supposed to DELETE a faculty?
  if ($values ["perform_action2"] == "delete_faculty" && user_has_permission("delete_users")) {


    db_query("DELETE FROM faculty WHERE cwid = ? ", $faculty_cwid);
    db_query("DELETE FROM users WHERE cwid = ? AND is_faculty = '1' ", $faculty_cwid);

    fp_add_message(t("User has been deleted."));
    fp_goto("admin/users/faculty");
    return;
  }


  if ($faculty_cwid != "new") {
    // NOT a new faculty!  Insert values normally.
    // First-- was there a password given?  If so, insert that separate.
    if (trim($values ["new_password"]) != "") {
      $new_pass = user_hash_password(trim($values ["new_password"]));

      db_query("UPDATE users 
                SET password = ? 
                WHERE cwid = ? 
                AND is_faculty = '1' ", $new_pass, $faculty_cwid);
    }
    // Okay, now we can just update everything else.
    // Update users table first...
    db_query("UPDATE users
              SET email = ?,                  
                  f_name = ?,
                  l_name = ?,
                  is_disabled = ?
               WHERE cwid = ?
               AND is_faculty = '1' ", $values ["email"], $values ["f_name"], 
    $values ["l_name"], $values ["is_disabled"], 
    $faculty_cwid);

    // Now, update the faculty table entry.
    db_query("UPDATE faculty
             SET college = ?,
                 department = ?,
                 major_code_csv = ?                
             WHERE cwid = ? ", $values ["college"], $values ["department"], 
    $values ["major_code_csv"], $faculty_cwid);

  }
  else {
    // This is a NEW user!  We need to perform inserts.  Thanks to our validate handler,
    // we know all of the values we have are valid.

    if (trim($values ["l_name"]) == "") {
      // No last name?  Set to username.
      $values ['l_name'] = $values ['new_user_name'];
    }

    db_query("INSERT INTO users (user_name, password, is_faculty, email, cwid, f_name, l_name, is_disabled)
              VALUES (?, ?, '1', ?, ?, ?, ?, ?)
              ", $values ["new_user_name"], user_hash_password($values ["new_password"]), $values ["email"], $values ["new_faculty_cwid"], 
    $values ["f_name"], $values ["l_name"], $values ["is_disabled"]);
    db_query("INSERT INTO faculty (cwid, college, department, major_code_csv)
              VALUES (?, ?, ?, ?)
             ", $values ["new_faculty_cwid"], $values ["college"], $values ["department"], $values ["major_code_csv"]);

    fp_add_message(t("User created successfully."));
    fp_goto("admin/users/edit-user", "faculty_cwid=" . $values ["new_faculty_cwid"]);
  }






  fp_add_message(t("User updated successfully."));


}