function user_edit_user_form_submit
Search API
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 2222
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] = fp_trim($val);
}
}
$user_id = intval($values ["user_id"]);
$faculty_cwid = $values ["faculty_cwid"];
$dept_code = fp_trim(@$values ['department']);
// 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);
watchdog("user_edit", "Setting role for user @$user_id", array("@user_id" => $user_id, "@rid" => $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);
watchdog("user_edit", "Delete faculty user with cwid @$faculty_cwid", array("@faculty_cwid" => $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);
watchdog("user_edit", "Updating faculty user with cwid @faculty_cwid with new password.", array("@faculty_cwid" => $faculty_cwid));
unset($values ["new_password"]);
}
// 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' ", trim(strtolower($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_code = ?,
major_code_csv = ?
WHERE cwid = ? ", $values ["college"], $dept_code,
$values ["major_code_csv"], $faculty_cwid);
watchdog("user_edit", "Updating faculty user with various other values: @other", array("@other" => ppm($values, TRUE)));
}
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"]), trim(strtolower($values ["email"])), $values ["new_faculty_cwid"],
$values ["f_name"], $values ["l_name"], $values ["is_disabled"]);
db_query("INSERT INTO faculty (cwid, college, department_code, major_code_csv)
VALUES (?, ?, ?, ?)
", $values ["new_faculty_cwid"], $values ["college"], $dept_code, $values ["major_code_csv"]);
unset($values ['new_password']);
watchdog("user_edit", "Create new faculty user with various values: @other", array("@other" => ppm($values, TRUE)));
fp_add_message(t("User created successfully."));
fp_goto("admin/users/edit-user", "faculty_cwid=" . $values ["new_faculty_cwid"]);
}
// Do we have any phone lines listed (from the core Engagements module) that this user should be notified of when they
// receive a txt message? If so, save that information in the user_settings table.
if (isset($values ['receive_notifications_from_numbers'])) {
// Delete existing settings values...
db_query("DELETE FROM user_settings WHERE user_id = ? AND name LIKE ?", array($user_id, 'notify_sms_receipt__%'));
if (is_array($values ['receive_notifications_from_numbers'])) {
foreach ($values ['receive_notifications_from_numbers'] as $num) {
user_set_setting($user_id, "notify_sms_receipt__" . $num, $num);
}
}
}
fp_add_message(t("User updated successfully."));
}