2001-11-22 06:23:56 +00:00
|
|
|
<?PHP // $Id$
|
|
|
|
|
2003-04-27 14:50:03 +00:00
|
|
|
require_once("../config.php");
|
|
|
|
require_once("lib.php");
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
require_variable($id); // user id
|
|
|
|
require_variable($course); // course id
|
|
|
|
|
|
|
|
if (! $user = get_record("user", "id", $id)) {
|
|
|
|
error("User ID was incorrect");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $course = get_record("course", "id", $course)) {
|
2002-08-08 16:02:39 +00:00
|
|
|
error("Course ID was incorrect");
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2003-01-14 14:54:45 +00:00
|
|
|
if ($user->confirmed and user_not_fully_set_up($user)) {
|
2002-09-26 07:03:22 +00:00
|
|
|
// Special case which can only occur when a new account
|
|
|
|
// has just been created by EXTERNAL authentication
|
|
|
|
// This is the only page in Moodle that has the exception
|
|
|
|
// so that users can set up their accounts
|
|
|
|
$newaccount = true;
|
|
|
|
|
2004-01-03 15:41:15 +00:00
|
|
|
if (empty($USER)) {
|
2004-01-02 14:11:21 +00:00
|
|
|
error("Sessions don't seem to be working on this server!");
|
|
|
|
}
|
|
|
|
|
2002-09-26 07:03:22 +00:00
|
|
|
} else {
|
|
|
|
$newaccount = false;
|
2003-04-27 14:50:03 +00:00
|
|
|
require_login($course->id);
|
2002-09-26 07:03:22 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-08-08 14:17:55 +00:00
|
|
|
if ($USER->id <> $user->id and !isadmin()) {
|
2001-11-22 06:23:56 +00:00
|
|
|
error("You can only edit your own information");
|
|
|
|
}
|
|
|
|
|
2002-06-10 04:33:46 +00:00
|
|
|
if (isguest()) {
|
|
|
|
error("The guest user cannot edit their profile.");
|
|
|
|
}
|
|
|
|
|
2002-08-08 14:17:55 +00:00
|
|
|
if (isguest($user->id)) {
|
|
|
|
error("Sorry, the guest user cannot be edited.");
|
|
|
|
}
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
/// If data submitted, then process and store.
|
|
|
|
|
2003-04-27 14:50:03 +00:00
|
|
|
if ($usernew = data_submitted()) {
|
2002-08-08 14:17:55 +00:00
|
|
|
$usernew->firstname = strip_tags($usernew->firstname);
|
|
|
|
$usernew->lastname = strip_tags($usernew->lastname);
|
2003-04-27 14:50:03 +00:00
|
|
|
if (isset($usernew->username)) {
|
|
|
|
$usernew->username = trim(moodle_strtolower($usernew->username));
|
|
|
|
}
|
|
|
|
|
2003-04-15 02:08:27 +00:00
|
|
|
if (empty($_FILES['imagefile'])) {
|
|
|
|
$_FILES['imagefile'] = NULL; // To avoid using uninitialised variable later
|
|
|
|
}
|
|
|
|
|
2002-11-21 10:17:08 +00:00
|
|
|
if (find_form_errors($user, $usernew, $err)) {
|
2003-01-05 06:45:20 +00:00
|
|
|
if ($filename = valid_uploaded_file($_FILES['imagefile'])) {
|
2002-11-20 14:52:32 +00:00
|
|
|
$usernew->picture = save_user_image($user->id, $filename);
|
|
|
|
}
|
|
|
|
|
2002-08-08 14:17:55 +00:00
|
|
|
$user = $usernew;
|
|
|
|
|
|
|
|
} else {
|
2003-04-27 14:50:03 +00:00
|
|
|
$timenow = time();
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-01-05 06:45:20 +00:00
|
|
|
if ($filename = valid_uploaded_file($_FILES['imagefile'])) {
|
2002-11-20 14:52:32 +00:00
|
|
|
$usernew->picture = save_user_image($user->id, $filename);
|
2001-11-22 06:23:56 +00:00
|
|
|
} else {
|
|
|
|
$usernew->picture = $user->picture;
|
|
|
|
}
|
|
|
|
|
|
|
|
$usernew->timemodified = time();
|
|
|
|
|
2002-08-08 14:17:55 +00:00
|
|
|
if (isadmin()) {
|
2003-04-28 02:43:18 +00:00
|
|
|
if (!empty($usernew->newpassword)) {
|
2002-08-08 14:17:55 +00:00
|
|
|
$usernew->password = md5($usernew->newpassword);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (isset($usernew->newpassword)) {
|
|
|
|
error("You can not change the password like that");
|
|
|
|
}
|
|
|
|
}
|
2002-09-04 05:07:17 +00:00
|
|
|
if ($usernew->url and !(substr($usernew->url, 0, 4) == "http")) {
|
|
|
|
$usernew->url = "http://".$usernew->url;
|
|
|
|
}
|
2002-06-05 03:15:30 +00:00
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
if (update_record("user", $usernew)) {
|
2002-06-05 06:10:45 +00:00
|
|
|
add_to_log($course->id, "user", "update", "view.php?id=$user->id&course=$course->id", "");
|
2002-06-05 03:15:30 +00:00
|
|
|
|
2002-08-08 14:17:55 +00:00
|
|
|
if ($user->id == $USER->id) {
|
|
|
|
// Copy data into $USER session variable
|
|
|
|
$usernew = (array)$usernew;
|
|
|
|
foreach ($usernew as $variable => $value) {
|
2003-08-30 06:19:44 +00:00
|
|
|
$USER->$variable = stripslashes($value);
|
2002-08-08 14:17:55 +00:00
|
|
|
}
|
2003-05-06 15:58:20 +00:00
|
|
|
if (isset($USER->newadminuser)) {
|
|
|
|
unset($USER->newadminuser);
|
2003-07-30 05:21:24 +00:00
|
|
|
redirect("$CFG->wwwroot/", get_string("changessaved"));
|
2003-05-06 15:58:20 +00:00
|
|
|
}
|
|
|
|
redirect("$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id", get_string("changessaved"));
|
2002-08-08 14:17:55 +00:00
|
|
|
} else {
|
2003-12-16 05:31:52 +00:00
|
|
|
redirect("$CFG->wwwroot/$CFG->admin/user.php", get_string("changessaved"));
|
2002-06-05 03:15:30 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
} else {
|
|
|
|
error("Could not update the user record ($user->id)");
|
|
|
|
}
|
2003-04-27 14:50:03 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Otherwise fill and print the form.
|
|
|
|
|
2002-09-26 07:03:22 +00:00
|
|
|
$streditmyprofile = get_string("editmyprofile");
|
|
|
|
$strparticipants = get_string("participants");
|
|
|
|
$strnewuser = get_string("newuser");
|
2002-07-11 05:30:57 +00:00
|
|
|
|
2002-09-26 07:03:22 +00:00
|
|
|
if (($user->firstname and $user->lastname) or $newaccount) {
|
|
|
|
if ($newaccount) {
|
|
|
|
$userfullname = $strnewuser;
|
|
|
|
} else {
|
2003-11-19 16:15:56 +00:00
|
|
|
$userfullname = fullname($user, isteacher($course->id));
|
2002-09-26 07:03:22 +00:00
|
|
|
}
|
2002-08-14 01:51:58 +00:00
|
|
|
if ($course->category) {
|
2003-04-27 14:50:03 +00:00
|
|
|
print_header("$course->shortname: $streditmyprofile", "$course->fullname: $streditmyprofile",
|
2002-08-14 01:51:58 +00:00
|
|
|
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A>
|
2002-09-26 07:03:22 +00:00
|
|
|
-> <A HREF=\"index.php?id=$course->id\">$strparticipants</A>
|
2002-08-14 01:51:58 +00:00
|
|
|
-> <A HREF=\"view.php?id=$user->id&course=$course->id\">$userfullname</A>
|
2002-09-26 07:03:22 +00:00
|
|
|
-> $streditmyprofile", "");
|
2002-08-14 01:51:58 +00:00
|
|
|
} else {
|
2003-05-06 15:58:20 +00:00
|
|
|
if (isset($USER->newadminuser)) {
|
|
|
|
print_header();
|
|
|
|
} else {
|
|
|
|
print_header("$course->shortname: $streditmyprofile", "$course->fullname",
|
|
|
|
"<A HREF=\"view.php?id=$user->id&course=$course->id\">$userfullname</A>
|
|
|
|
-> $streditmyprofile", "");
|
|
|
|
}
|
2002-08-14 01:51:58 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
} else {
|
2002-09-26 07:03:22 +00:00
|
|
|
$userfullname = $strnewuser;
|
2002-08-14 01:51:58 +00:00
|
|
|
$straddnewuser = get_string("addnewuser");
|
|
|
|
|
|
|
|
$stradministration = get_string("administration");
|
2003-04-27 14:50:03 +00:00
|
|
|
print_header("$course->shortname: $streditmyprofile", "$course->fullname",
|
2003-08-10 08:01:14 +00:00
|
|
|
"<a href=\"$CFG->wwwroot/$CFG->admin/\">$stradministration</a> -> ".
|
|
|
|
"<a href=\"$CFG->wwwroot/$CFG->admin/users.php\">$strusers</a> -> $straddnewuser", "");
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2002-06-05 05:37:55 +00:00
|
|
|
$teacher = strtolower($course->teacher);
|
2002-08-08 14:17:55 +00:00
|
|
|
if (!isadmin()) {
|
|
|
|
$teacheronly = "(".get_string("teacheronly", "", $teacher).")";
|
2002-12-29 17:32:32 +00:00
|
|
|
} else {
|
|
|
|
$teacheronly = "";
|
2002-08-08 14:17:55 +00:00
|
|
|
}
|
2002-06-05 05:37:55 +00:00
|
|
|
|
2002-08-14 01:51:58 +00:00
|
|
|
print_heading( get_string("userprofilefor", "", "$userfullname") );
|
2003-05-06 15:58:20 +00:00
|
|
|
|
|
|
|
if (isset($USER->newadminuser)) {
|
2003-08-07 16:01:31 +00:00
|
|
|
print_simple_box(get_string("configintroadmin"), "center", "50%");
|
2003-05-06 15:58:20 +00:00
|
|
|
echo "<br />";
|
|
|
|
}
|
|
|
|
|
2002-09-19 13:55:40 +00:00
|
|
|
print_simple_box_start("center", "", "$THEME->cellheading");
|
2002-12-29 17:32:32 +00:00
|
|
|
if (!empty($err)) {
|
2002-11-20 14:52:32 +00:00
|
|
|
echo "<CENTER>";
|
|
|
|
notify(get_string("someerrorswerefound"));
|
|
|
|
echo "</CENTER>";
|
|
|
|
}
|
2003-04-27 14:50:03 +00:00
|
|
|
include("edit.html");
|
2001-11-22 06:23:56 +00:00
|
|
|
print_simple_box_end();
|
|
|
|
|
2003-05-06 15:58:20 +00:00
|
|
|
if (!isset($USER->newadminuser)) {
|
|
|
|
print_footer($course);
|
|
|
|
}
|
|
|
|
|
|
|
|
exit;
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// FUNCTIONS ////////////////////
|
|
|
|
|
|
|
|
function find_form_errors(&$user, &$usernew, &$err) {
|
|
|
|
|
2002-08-08 14:17:55 +00:00
|
|
|
if (isadmin()) {
|
2002-08-08 15:51:23 +00:00
|
|
|
if (empty($usernew->username)) {
|
2002-08-08 14:17:55 +00:00
|
|
|
$err["username"] = get_string("missingusername");
|
|
|
|
|
2002-08-08 15:51:23 +00:00
|
|
|
} else if (record_exists("user", "username", $usernew->username) and $user->username == "changeme") {
|
|
|
|
$err["username"] = get_string("usernameexists");
|
|
|
|
|
|
|
|
} else {
|
2003-03-15 08:26:00 +00:00
|
|
|
$string = eregi_replace("[^(-\.[:alnum:])]", "", $usernew->username);
|
2003-03-15 09:15:44 +00:00
|
|
|
if (strcmp($usernew->username, $string))
|
2002-08-08 15:51:23 +00:00
|
|
|
$err["username"] = get_string("alphanumerical");
|
|
|
|
}
|
|
|
|
|
2003-09-22 14:01:45 +00:00
|
|
|
if (empty($usernew->newpassword) and empty($user->password) and is_internal_auth() )
|
2002-08-08 14:17:55 +00:00
|
|
|
$err["newpassword"] = get_string("missingpassword");
|
2002-09-05 02:17:33 +00:00
|
|
|
|
2002-09-05 17:31:08 +00:00
|
|
|
if (($usernew->newpassword == "admin") or ($user->password == md5("admin") and empty($usernew->newpassword)) ) {
|
2002-09-05 02:17:33 +00:00
|
|
|
$err["newpassword"] = get_string("unsafepassword");
|
2002-09-05 17:31:08 +00:00
|
|
|
}
|
2002-08-08 14:17:55 +00:00
|
|
|
}
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
if (empty($usernew->email))
|
2002-07-11 05:30:57 +00:00
|
|
|
$err["email"] = get_string("missingemail");
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-08-08 14:17:55 +00:00
|
|
|
if (empty($usernew->description))
|
|
|
|
$err["description"] = get_string("missingdescription");
|
|
|
|
|
2002-06-05 05:37:55 +00:00
|
|
|
if (empty($usernew->city))
|
2002-07-11 05:30:57 +00:00
|
|
|
$err["city"] = get_string("missingcity");
|
2002-06-05 05:37:55 +00:00
|
|
|
|
2002-08-06 09:36:42 +00:00
|
|
|
if (empty($usernew->firstname))
|
|
|
|
$err["firstname"] = get_string("missingfirstname");
|
|
|
|
|
|
|
|
if (empty($usernew->lastname))
|
|
|
|
$err["lastname"] = get_string("missinglastname");
|
|
|
|
|
2002-06-05 05:37:55 +00:00
|
|
|
if (empty($usernew->country))
|
2002-07-11 05:30:57 +00:00
|
|
|
$err["country"] = get_string("missingcountry");
|
2002-06-05 05:37:55 +00:00
|
|
|
|
2002-08-08 14:17:55 +00:00
|
|
|
if (! validate_email($usernew->email))
|
2002-07-11 05:30:57 +00:00
|
|
|
$err["email"] = get_string("invalidemail");
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
else if ($otheruser = get_record("user", "email", $usernew->email)) {
|
|
|
|
if ($otheruser->id <> $user->id) {
|
2002-07-11 05:30:57 +00:00
|
|
|
$err["email"] = get_string("emailexists");
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$user->email = $usernew->email;
|
|
|
|
|
|
|
|
return count($err);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|