2001-11-22 06:23:56 +00:00
|
|
|
<?PHP // $Id$
|
|
|
|
|
|
|
|
require("../config.php");
|
2002-06-05 05:37:55 +00:00
|
|
|
require("../lib/countries.php");
|
2001-11-22 06:23:56 +00:00
|
|
|
require("lib.php");
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
require_login($course->id);
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
if (match_referer() && isset($HTTP_POST_VARS)) {
|
|
|
|
|
|
|
|
$usernew = (object)$HTTP_POST_VARS;
|
|
|
|
|
2002-08-08 14:17:55 +00:00
|
|
|
$usernew->firstname = strip_tags($usernew->firstname);
|
|
|
|
$usernew->lastname = strip_tags($usernew->lastname);
|
|
|
|
|
|
|
|
if (find_form_errors($user, $usernew, $err) ) {
|
|
|
|
$user = $usernew;
|
|
|
|
|
|
|
|
} else {
|
2001-11-22 06:23:56 +00:00
|
|
|
$timenow = time();
|
|
|
|
|
2002-08-06 17:23:45 +00:00
|
|
|
if ($filename = valid_uploaded_file($imagefile)) {
|
|
|
|
$imageinfo = GetImageSize($filename);
|
2001-11-22 06:23:56 +00:00
|
|
|
$image->width = $imageinfo[0];
|
|
|
|
$image->height = $imageinfo[1];
|
|
|
|
$image->type = $imageinfo[2];
|
|
|
|
|
|
|
|
switch ($image->type) {
|
2002-08-06 17:23:45 +00:00
|
|
|
case 2: $im = ImageCreateFromJPEG($filename); break;
|
|
|
|
case 3: $im = ImageCreateFromPNG($filename); break;
|
2001-11-22 06:23:56 +00:00
|
|
|
default: error("Image must be in JPG or PNG format");
|
|
|
|
}
|
2002-06-13 11:18:52 +00:00
|
|
|
if (function_exists("ImageCreateTrueColor") and $CFG->gdversion >= 2) {
|
2001-11-22 06:23:56 +00:00
|
|
|
$im1 = ImageCreateTrueColor(100,100);
|
|
|
|
$im2 = ImageCreateTrueColor(35,35);
|
|
|
|
} else {
|
|
|
|
$im1 = ImageCreate(100,100);
|
|
|
|
$im2 = ImageCreate(35,35);
|
|
|
|
}
|
|
|
|
|
|
|
|
$cx = $image->width / 2;
|
|
|
|
$cy = $image->height / 2;
|
|
|
|
|
|
|
|
if ($image->width < $image->height) {
|
|
|
|
$half = floor($image->width / 2.0);
|
|
|
|
} else {
|
|
|
|
$half = floor($image->height / 2.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!file_exists("$CFG->dataroot/users")) {
|
2002-05-18 03:13:44 +00:00
|
|
|
if (! mkdir("$CFG->dataroot/users", 0777)) {
|
|
|
|
$badpermissions = true;
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2002-08-08 14:17:55 +00:00
|
|
|
if (!file_exists("$CFG->dataroot/users/$user->id")) {
|
|
|
|
if (! mkdir("$CFG->dataroot/users/$user->id", 0777)) {
|
2002-05-18 03:13:44 +00:00
|
|
|
$badpermissions = true;
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2002-05-18 03:13:44 +00:00
|
|
|
if ($badpermissions) {
|
|
|
|
$usernew->picture = "0";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
ImageCopyBicubic($im1, $im, 0, 0, $cx-$half, $cy-$half, 100, 100, $half*2, $half*2);
|
|
|
|
ImageCopyBicubic($im2, $im, 0, 0, $cx-$half, $cy-$half, 35, 35, $half*2, $half*2);
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-05-18 03:13:44 +00:00
|
|
|
// Draw borders over the top.
|
|
|
|
$black1 = ImageColorAllocate ($im1, 0, 0, 0);
|
|
|
|
$black2 = ImageColorAllocate ($im2, 0, 0, 0);
|
|
|
|
ImageLine ($im1, 0, 0, 0, 99, $black1);
|
|
|
|
ImageLine ($im1, 0, 99, 99, 99, $black1);
|
|
|
|
ImageLine ($im1, 99, 99, 99, 0, $black1);
|
|
|
|
ImageLine ($im1, 99, 0, 0, 0, $black1);
|
|
|
|
ImageLine ($im2, 0, 0, 0, 34, $black2);
|
|
|
|
ImageLine ($im2, 0, 34, 34, 34, $black2);
|
|
|
|
ImageLine ($im2, 34, 34, 34, 0, $black2);
|
|
|
|
ImageLine ($im2, 34, 0, 0, 0, $black2);
|
|
|
|
|
2002-08-08 14:17:55 +00:00
|
|
|
ImageJpeg($im1, "$CFG->dataroot/users/$user->id/f1.jpg", 90);
|
|
|
|
ImageJpeg($im2, "$CFG->dataroot/users/$user->id/f2.jpg", 95);
|
2002-05-18 03:13:44 +00:00
|
|
|
$usernew->picture = "1";
|
|
|
|
}
|
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()) {
|
|
|
|
if ($usernew->newpassword) {
|
|
|
|
$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) {
|
|
|
|
$USER->$variable = $value;
|
|
|
|
}
|
|
|
|
save_session("USER");
|
|
|
|
redirect("view.php?id=$user->id&course=$course->id", "Changes saved");
|
|
|
|
} else {
|
|
|
|
redirect("../admin/user.php", "Changes saved");
|
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)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Otherwise fill and print the form.
|
|
|
|
|
2002-07-11 05:30:57 +00:00
|
|
|
$editmyprofile = get_string("editmyprofile");
|
|
|
|
$participants = get_string("participants");
|
|
|
|
|
2002-08-14 01:51:58 +00:00
|
|
|
if ($user->firstname and $user->lastname) {
|
|
|
|
$userfullname = "$user->firstname $user->lastname";
|
|
|
|
if ($course->category) {
|
|
|
|
print_header("$course->fullname: $editmyprofile", "$course->fullname: $editmyprofile",
|
|
|
|
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A>
|
|
|
|
-> <A HREF=\"index.php?id=$course->id\">$participants</A>
|
|
|
|
-> <A HREF=\"view.php?id=$user->id&course=$course->id\">$userfullname</A>
|
|
|
|
-> $editmyprofile", "");
|
|
|
|
} else {
|
|
|
|
print_header("$course->fullname: $editmyprofile", "$course->fullname",
|
|
|
|
"<A HREF=\"view.php?id=$user->id&course=$course->id\">$userfullname</A>
|
|
|
|
-> $editmyprofile", "");
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
} else {
|
2002-08-14 01:51:58 +00:00
|
|
|
$userfullname = get_string("newuser");
|
|
|
|
$straddnewuser = get_string("addnewuser");
|
|
|
|
|
|
|
|
$stradministration = get_string("administration");
|
2002-08-08 16:02:39 +00:00
|
|
|
print_header("$course->fullname: $editmyprofile", "$course->fullname",
|
2002-08-14 01:51:58 +00:00
|
|
|
"<A HREF=\"$CFG->wwwroot/admin\">$stradministration</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-06-05 05:37:55 +00:00
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
print_simple_box_start("center", "", "$THEME->cellheading");
|
2002-08-14 01:51:58 +00:00
|
|
|
print_heading( get_string("userprofilefor", "", "$userfullname") );
|
2001-11-22 06:23:56 +00:00
|
|
|
include("edit.html");
|
|
|
|
print_simple_box_end();
|
|
|
|
print_footer($course);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// 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 {
|
|
|
|
$string = eregi_replace("[^([:alnum:])]", "", $user->username);
|
|
|
|
if (strcmp($user->username, $string))
|
|
|
|
$err["username"] = get_string("alphanumerical");
|
|
|
|
}
|
|
|
|
|
2002-08-08 14:17:55 +00:00
|
|
|
if (empty($usernew->newpassword) and empty($user->password))
|
|
|
|
$err["newpassword"] = get_string("missingpassword");
|
2002-09-05 02:17:33 +00:00
|
|
|
|
|
|
|
if ($usernew->newpassword == md5("admin") or $user->password == md5("admin"))
|
|
|
|
$err["newpassword"] = get_string("unsafepassword");
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|