]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-8096 - rewritten standard edit form and other fixes; new custom profile fields...
authorskodak <skodak>
Thu, 25 Jan 2007 18:02:48 +0000 (18:02 +0000)
committerskodak <skodak>
Thu, 25 Jan 2007 18:02:48 +0000 (18:02 +0000)
user/edit.php
user/edit_form.php
user/edit_form_common.php
user/editadvanced.php
user/editadvanced_form.php

index a045809810ad382e30186b82880ce29d1abb2dbc..5b6e69dbb5076a45207961b31ee1fe02c2220612 100644 (file)
 <?php // $Id$
 
-    require_once("../config.php");
-    require_once("$CFG->libdir/gdlib.php");
-    require_once("$CFG->dirroot/user/edit_form.php");
+    require_once('../config.php');
+    require_once($CFG->libdir.'/gdlib.php');
+    require_once($CFG->dirroot.'/user/edit_form.php');
+    require_once($CFG->dirroot.'/user/profile/lib.php');
 
-    $id     = optional_param('id',     0,      PARAM_INT);   // user id
     $course = optional_param('course', SITEID, PARAM_INT);   // course id (defaults to Site)
 
-    if (empty($id)) {         // See your own profile by default
-        require_login();
-        $id = $USER->id;
+    if (!$course = get_record('course', 'id', $course)) {
+        error('Course ID was incorrect');
     }
 
-    httpsrequired(); // HTTPS is potentially required in this page
+    require_login($course->id);
 
-    if (! $user = get_record("user", "id", $id)) {
-        error("User ID was incorrect");
-    }
-
-    if (! $course = get_record("course", "id", $course)) {
-        error("Course ID was incorrect");
+    if (isguest()) { //TODO: add proper capability to edit own profile and change password too
+        print_error('guestnoeditprofile');
     }
 
-    if ($user->confirmed and user_not_fully_set_up($user)) {
-        // 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;
-
-        if (empty($USER->id)) {
-            error("Sessions don't seem to be working on this server!");
-        }
-
-    } else {
-        $newaccount  = false;
-        require_login($course->id);
+    if (!$user = get_record('user', 'id', $USER->id)) {
+        error('User ID was incorrect');
     }
 
     // remote users cannot be edited
     if (is_mnet_remote_user($user)) {
-        redirect($CFG->wwwroot . "/user/view.php?id=$id&course={$course->id}");
+        redirect($CFG->wwwroot . "/user/view.php?course={$course->id}");
     }
 
-    if ($USER->id <> $user->id) {    // Current user editing someone else's profile
-        if (has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) { // Current user can update user profiles
-            if ($mainadmin = get_admin()) {
-                if ($user->id == $mainadmin->id) {  // Can't edit primary admin
-                    print_error('adminprimarynoedit');
-                }
-            }
-        } else {
-            print_error('onlyeditown');
+    //load preferences
+    if (!empty($user->id) and $preferences = get_user_preferences(null, null, $user->id)) {
+        foreach($preferences as $name=>$value) {
+            $user->{'preference_'.$name} = $value;
         }
     }
+    //TODO: Load the custom profile fields
 
-    if (isguest()) {
-        print_error('guestnoeditprofile');
-    }
-
-    if (isguest($user->id)) {
-        print_error('guestnoeditprofileother');
-    }
-
-
-    // load the relevant auth libraries
-    if (!empty($user->auth)) {
-        $auth = $user->auth;
-        // TODO: spit dummy if $auth doesn't exist
-        if (! exists_auth_plugin($auth)) {
-            trigger_error("Can't find auth module '$auth', default to internal.");
-            $auth = "manual";
-        }
-        $authplugin = get_auth_plugin($auth);
-    } else {
-        $authplugin = get_auth_plugin($CFG->auth);
-    }
-
-
-    $userform = new user_edit_form(null, compact('user','course','authplugin'));
+    //create form
+    $userform = new user_edit_form();
     $userform->set_data($user);
 
-/// If data submitted, then process and store.
     if ($usernew = $userform->get_data()) {
+        add_to_log($course->id, 'user', 'update', "view.php?id=$user->id&course=$course->id", '');
 
-        $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
-        // if userid = x and name = changeme then we are adding 1
-        // else we are editting one
-        $dummyuser = get_record('user','id', $id);
-
-        if ($dummyuser->username == 'changeme') {                                            // check for add user
-            require_capability('moodle/user:create', $context);
-        } else {
-            if ($USER->id <> $usernew->id and !has_capability('moodle/user:update', $context)) { // check for edit
-                print_error('onlyeditown');
-            }
-        }
-
-        if (isset($usernew->password)) {
-            unset($usernew->password);
-        }
-
-        if ($CFG->allowusermailcharset) {
-            $usernew->mailcharset = clean_param($usernew->mailcharset, PARAM_CLEAN);
-            if (!empty($usernew->mailcharset)) {
-                set_user_preference('mailcharset', $usernew->mailcharset, $user->id);
-            } else {
-                 unset_user_preference('mailcharset', $user->id);
-            }
-        } else {
-            unset_user_preference('mailcharset', $user->id);
-        }
-
-        foreach ($usernew as $key => $data) {
-            $usernew->$key = addslashes(clean_text(stripslashes(trim($usernew->$key)), FORMAT_MOODLE));
-        }
-
-        if (isset($usernew->username)) {
-            $usernew->username = moodle_strtolower($usernew->username);
-        }
-
-        if (!empty($_FILES) and !(empty($CFG->disableuserimages) or has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM, SITEID)))) {
-            error('Users can not update profile images!');
-        }
-
-        // override locked values
-        if (!has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
-            $fields = get_user_fieldnames();
-            foreach ($fields as $field) {
-                $configvariable = 'field_lock_' . $field;
-                if ( empty($authplugin->config->{$configvariable}) ) {
-                    continue; //no locking set
-                }
-                if ( $authplugin->config->{$configvariable} === 'locked'
-                     or ($authplugin->config->{$configvariable} === 'unlockedifempty' and !empty($user->$field))) {
-                    if (!empty( $user->$field)) {
-                        $usernew->$field = addslashes($user->$field);
-                    }
-                }
-            }
-            unset($fields);
-            unset($field);
-            unset($configvariable);
-        }
-
-        if (!$usernew->picture = save_profile_image($user->id, $userform->_upload_manager, 'users')) {
-            if (!empty($usernew->deletepicture)) {
-                set_field('user', 'picture', 0, 'id', $user->id);  /// Delete picture
-                $usernew->picture = 0;
-            } else {
-                $usernew->picture = $user->picture;
-            }
-        }
-
-        $timenow = time();
+        $authplugin = get_auth_plugin($user->auth);
 
         $usernew->timemodified = time();
 
-        if (has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
-            if (!empty($usernew->newpassword)) {
-                $usernew->password = hash_internal_user_password($usernew->newpassword);
-                // update external passwords
-                // TODO: this was using $user->auth possibly overriding $authplugin above. Can we guarantee $user->auth being something valid?
-                if ($authplugin->can_change_password()) {
-                    if (method_exists($authplugin, 'user_update_password')){
-                        if (!$authplugin->user_update_password($user->username, $usernew->newpassword)){
-                            error('Failed to update password on external auth: ' . $user->auth .
-                                    '. See the server logs for more details.');
-                        }
-                    } else {
-                        error('Your external authentication module is misconfigued!');
-                    }
-                }
-            }
-            // store forcepasswordchange in user's preferences
-            if (!empty($usernew->forcepasswordchange)){
-                set_user_preference('auth_forcepasswordchange', 1, $user->id);
-            } else {
-                unset_user_preference('auth_forcepasswordchange', $user->id);
-            }
-        } else {
-            if (isset($usernew->newpassword)) {
-                error("You can not change the password like that");
-            }
-        }
-
-        $userold = get_record('user','id',$usernew->id);
-        if (update_record("user", $usernew)) {
-            if (method_exists($authplugin, "user_update")){
+        if (update_record('user', $usernew)) {
+            if (method_exists($authplugin, 'user_update')){
                 // pass a true $userold here
-                if (! $authplugin->user_update($userold, $usernew)) {
+                if (! $authplugin->user_update($user, $userform->get_data(false))) {
                     // auth update failed, rollback for moodle
-                    update_record("user", $userold);
-                    error('Failed to update user data on external auth: '.$user->auth.
+                    update_record('user', addslashes_object($user));
+                    error('Failed to update user data on external auth: '.$usernew->auth.
                             '. See the server logs for more details.');
                 }
             };
+        } else {
+            error('Error updating user record');
+        }
 
-            if ($userold->email != $usernew->email) {
-                set_bounce_count($usernew,true);
-                set_send_count($usernew,true);
-            }
-
-            /// Update forum track preference.
-            if (($usernew->trackforums != $userold->trackforums) && !$usernew->trackforums) {
-                require_once($CFG->dirroot.'/mod/forum/lib.php');
-                forum_tp_delete_read_records($usernew->id);
+        //update preferences
+        $ua = (array)$usernew;
+        foreach($ua as $key=>$value) {
+            if (strpos($key, 'preference_') === 0) {
+                $name = substr($key, strlen('preference_'));
+                set_user_preference($name, $value, $usernew->id);
             }
+        }
 
-            /// Update the custom user fields
-            if ($categories = get_records_select('user_info_category', '', 'sortorder ASC')) {
-                foreach ($categories as $category) {
-
-                    if ($fields = get_records_select('user_info_field', "categoryid=$category->id", 'sortorder ASC')) {
-                        foreach ($fields as $field) {
-
-                            require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
-                            $newfield = 'profile_field_'.$field->datatype;
-                            $formfield = new $newfield($field->id,$user->id);
-                            if (isset($usernew->{$formfield->fieldname})) {
-                                $formfield->save_data($usernew->{$formfield->fieldname});
-                            }
-
-                            unset($formfield);
-
-                        }
-                    } /// End of $fields if
-                } /// End of $categories foreach
-            } /// End of $categories if
-
-
-
-            add_to_log($course->id, "user", "update", "view.php?id=$user->id&course=$course->id", "");
-
-            if ($user->id == $USER->id) {
-                // Copy data into $USER session variable
-                $usernew = (array)$usernew;
-                foreach ($usernew as $variable => $value) {
-                    $USER->$variable = stripslashes($value);
-                }
-                if (isset($USER->newadminuser)) {
-                    unset($USER->newadminuser);
-                    // redirect to admin/ to continue with installation
-                    redirect("$CFG->wwwroot/$CFG->admin/");
-                }
-                if (!empty($SESSION->wantsurl)) {  // User may have been forced to edit account, so let's
-                    // send them to where they wanted to go originally
-                    $wantsurl = $SESSION->wantsurl;
-                    $SESSION->wantsurl = '';       // In case unset doesn't work as expected
-                    unset($SESSION->wantsurl);
-                    redirect($wantsurl);
-                } else {
-                    redirect("$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id");
-                }
-            } else {
-                redirect("$CFG->wwwroot/$CFG->admin/user.php");
+        if (!empty($CFG->gdversion) and empty($CFG->disableuserimages)) {
+             //update user picture
+            if ($usernew->deletepicture) {
+                //TODO - delete the files
+                set_field('user', 'picture', 0, 'id', $usernew->id);
+            } else if ($usernew->picture = save_profile_image($usernew->id, $userform->get_um(), 'users')) {
+                set_field('user', 'picture', 1, 'id', $usernew->id);
             }
-        } else {
-            error("Could not update the user record ($user->id)");
         }
-    }
-
-
-/// Otherwise fill and print the form.
 
-    $streditmyprofile = get_string("editmyprofile");
-    $strparticipants = get_string("participants");
-    $strnewuser = get_string("newuser");
-
-    if (over_bounce_threshold($user) && empty($err['email'])) {
-        $err['email'] = get_string('toomanybounces');
-    }
-
-    if (($user->firstname and $user->lastname) or $newaccount) {
-        if ($newaccount) {
-            $userfullname = $strnewuser;
-        } else {
-            $userfullname = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
-        }
-        if ($course->id != SITEID) {
-            print_header("$course->shortname: $streditmyprofile", "$course->fullname: $streditmyprofile",
-                        "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>
-                        -> <a href=\"index.php?id=$course->id\">$strparticipants</a>
-                        -> <a href=\"view.php?id=$user->id&amp;course=$course->id\">$userfullname</a>
-                        -> $streditmyprofile", "");
-        } else {
-            if (isset($USER->newadminuser)) {
-                print_header();
-            } else {
-                print_header("$course->shortname: $streditmyprofile", "$course->fullname",
-                             "<a href=\"view.php?id=$user->id&amp;course=$course->id\">$userfullname</a>
-                              -> $streditmyprofile", "");
-            }
+        // update mail bounces
+        if ($user->email !== $usernew->email) {
+            set_bounce_count($usernew,true);
+            set_send_count($usernew,true);
         }
-    } else {
-        $userfullname = $strnewuser;
-        $straddnewuser = get_string("addnewuser");
 
-        $stradministration = get_string("administration");
-        print_header("$course->shortname: $streditmyprofile", "$course->fullname",
-                     "<a href=\"$CFG->wwwroot/$CFG->admin/\">$stradministration</a> -> $straddnewuser", "");
-    }
+        /// Update forum track preference.
+        if (($usernew->trackforums != $user->trackforums) and !$usernew->trackforums) {
+            require_once($CFG->dirroot.'/mod/forum/lib.php');
+            forum_tp_delete_read_records($usernew->id);
+        }
 
+        //TODO: Save the custom profile fields
 
-    if (isset($USER->newadminuser)) {
-        print_simple_box(get_string('configintroadmin', 'admin'), 'center', '50%');
-        echo '<br />';
-    } else {
-        /// Print tabs at top
-        /// This same call is made in:
-        ///     /user/view.php
-        ///     /user/edit.php
-        ///     /course/user.php
-        $showroles = 1;
-        $currenttab = 'editprofile';
-        include('tabs.php');
+        redirect("$CFG->wwwroot/user/view.php?id=$USER->id&course=$course->id");
     }
 
-    if (!empty($err)) {
-        echo "<center>";
-        notify(get_string("someerrorswerefound"));
-        echo "</center>";
-    }
 
-    $teacher = $course->teacher;
-    if (!has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
-        $teacheronly = '('.get_string('teacheronly', '', $teacher).')';
+/// Display page header
+    $streditmyprofile = get_string('editmyprofile');
+    $strparticipants  = get_string('participants');
+    $userfullname     = fullname($user, true);
+    if ($course->id != SITEID) {
+        print_header("$course->shortname: $streditmyprofile", "$course->fullname: $streditmyprofile",
+                     "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>
+                      -> <a href=\"index.php?id=$course->id\">$strparticipants</a>
+                      -> <a href=\"view.php?id=$user->id&amp;course=$course->id\">$userfullname</a>
+                      -> $streditmyprofile", "");
     } else {
-        $teacheronly = '';
+        print_header("$course->shortname: $streditmyprofile", "$course->fullname",
+                     "<a href=\"view.php?id=$user->id&amp;course=$course->id\">$userfullname</a>
+                      -> $streditmyprofile", "");
     }
+    /// Print tabs at the top
+    $showroles = 1;
+    $currenttab = 'editprofile';
+    require('tabs.php');
 
+/// Finally display THE form
     $userform->display();
 
-    if (!isset($USER->newadminuser)) {
-        print_footer($course);
-    } else {
-        print_footer();
-    }
+/// and proper footer
+    print_footer($course);
 
 ?>
index 5e27db44b919f0c7af15f8f6c1acbd306a33f84a..5f7b79ece7f198f2c37cf99fc7a5a7ae4c7298e7 100644 (file)
 <?php //$Id$
 
-include_once("$CFG->dirroot/lib/formslib.php");
-require_once("$CFG->dirroot/user/profile/lib.php");
+require_once($CFG->dirroot.'/lib/formslib.php');
 
 class user_edit_form extends moodleform {
 
     // Define the form
     function definition () {
-        global $USER, $CFG;
-
-        $mform      =& $this->_form;
-        $renderer   =& $mform->defaultRenderer();
-        $user       = $this->_customdata['user'];
-        $course     = $this->_customdata['course'];
-        $authplugin = $this->_customdata['authplugin'];
+        global $USER, $CFG, $COURSE;
 
-        $systemcontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
-        $userupdate    = has_capability('moodle/user:update', $systemcontext);
+        $mform =& $this->_form;
+        $this->set_upload_manager(new upload_manager('imagefile', false, false, null, false, 0, true, true, false));
         $strrequired = get_string('required');
 
-        $this->set_upload_manager(new upload_manager('imagefile',false,false,null,false,0,true,true));
-
         /// Add some extra hidden fields
         $mform->addElement('hidden', 'id');
-        $mform->addElement('hidden', 'course', $course->id);
-
+        $mform->addElement('hidden', 'course', $COURSE->id);
 
         /// Print the required moodle fields first
         $mform->addElement('header', 'moodle', $strrequired);
 
-        if ($userupdate) {
-            $theadmin = get_admin(); // returns false during install
-            $adminself = (!empty($theadmin) and ($theadmin->id == $USER->id) and ($USER->id == $user->id));
-            $userauth = get_auth_plugin($user->auth);
-
-            if ($adminself or $userauth->is_internal()) {
-                $mform->addElement('text', 'username', get_string('username'), 'size="20"');
-                $mform->setType('username', PARAM_MULTILANG);
-                $mform->setDefault('username', '');
-                $mform->addRule('username', $strrequired, 'required', null, 'client');
-            } else {
-                $mform->addElement('hidden', 'username');
-            }
-
-            $modules = get_list_of_plugins("auth");
-            $auth_options = array();
-            foreach ($modules as $module) {
-                $auth_options[$module] = get_string("auth_$module"."title", "auth");
-            }
-            if (!$adminself) {    /// Main admin is ALWAYS default manual
-                $mform->addElement('select', 'auth', get_string('chooseauthmethod','auth'),$auth_options);
-                $mform->setType('auth', PARAM_ALPHANUM);
-                $mform->addRule('auth', $strrequired, 'required', null, 'client');
-                $mform->setHelpButton('auth', array('authchange', get_string('chooseauthmethod','auth')));
-            }
-
-            if ($adminself or $userauth->can_change_password()) {
-                $newpasswordgrp = array();
-                $newpasswordgrp[] = &MoodleQuickForm::createElement('text', 'newpassword', '', 'size="20"');
-                $newpasswordgrp[] = &MoodleQuickForm::createElement('static', 'newpasswordtext', '', '('.get_string('leavetokeep').')');
-                $mform->addGroup($newpasswordgrp, 'newpasswordgrp', get_string('newpassword'),' ',false);
-                $mform->setType('newpassword', PARAM_RAW);
-
-                if (!$adminself and $userauth->can_change_password()) {
-                    if (get_user_preferences('auth_forcepasswordchange', NULL, $user->id)) {
-                        $checked = ' checked="checked" ';
-                    } else {
-                        $checked = '';
-                    }
-                    $forcepasswordgrp = array();
-                    $forcepasswordgrp[] = &MoodleQuickForm::createElement('checkbox', 'forcepasswordchange', '');
-                    $forcepasswordgrp[] = &MoodleQuickForm::createElement('static', 'forcepasswordtext', '', '('.get_string('forcepasswordchangehelp').')');
-                    $mform->addGroup($forcepasswordgrp, 'forcepasswordgrp', get_string('forcepasswordchange'));
-                    $mform->setDefault('forcepasswordchange',$checked);
-                }
-            }
-            $mform->addElement('static','username_break', '','<hr />');
+        require('edit_form_common.php');
 
+        /// extra settigs
+        $mform->addRule('description', $strrequired, 'required', null, 'client');
+        if (!empty($CFG->gdversion) and !empty($CFG->disableuserimages)) {
+            $mform->removeElement('deletepicture');
+            $mform->removeElement('imagefile');
+            $mform->removeElement('imagealt');
         }
 
+        $this->add_action_buttons(false, get_string('updatemyprofile'));
+    }
 
-        $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
-        $mform->setType('firstname', PARAM_NOTAGS);
-        $mform->addRule('firstname', $strrequired, 'required', null, 'client');
-
-        $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"');
-        $mform->setType('lastname', PARAM_NOTAGS);
-        $mform->addRule('lastname', $strrequired, 'required', null, 'client');
-
-        $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"');
-        $mform->setType('email', PARAM_MULTILANG);
-        $mform->addRule('email', $strrequired, 'required', null, 'client');
-
-        $choices = array();
-        $choices["0"] = get_string("emaildisplayno");
-        $choices["1"] = get_string("emaildisplayyes");
-        $choices["2"] = get_string("emaildisplaycourse");
-        $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
-        $mform->setType('maildisplay', PARAM_INT);
+    function definition_after_data() {
+        global $USER, $CFG;
 
-        $choices = array();
-        $choices["0"] = get_string("emailenable");
-        $choices["1"] = get_string("emaildisable");
-        $mform->addElement('select', 'emailstop', get_string('emailactive'), $choices);
-        $mform->setType('emailstop', PARAM_INT);
+        $mform =& $this->_form;
+        $userid = $mform->getElementValue('id');
 
-        $choices = array();
-        $choices["0"] = get_string("textformat");
-        $choices["1"] = get_string("htmlformat");
-        $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
-        $mform->setType('mailformat', PARAM_INT);
-        $mform->setAdvanced('mailformat');
+        if ($user = get_record('user', 'id', $userid)) {
 
-        if (!empty($CFG->unicodedb) && !empty($CFG->allowusermailcharset)) {
-            $mailcharset = get_user_preferences('mailcharset', '0', $user->id);
-            $choices = array();
-            $charsets = get_list_of_charsets();
-            if (!empty($CFG->sitemailcharset)) {
-                $choices["0"] = get_string('site').' ('.$CFG->sitemailcharset.')';
+        // print picture
+        if (!empty($CFG->gdversion)) {
+            $image_el = $mform->getElement('currentpicture');
+            if ($user and $user->picture) {
+                $image_el->setValue(print_user_picture($user->id, SITEID, $user->picture, 64, true, false, '', true));
             } else {
-                $choices["0"] = get_string('site').' ('.current_charset().')';
-            }
-            $choices = array_merge($choices, $charsets);
-            $mform->addElement('select', 'mailcharset', get_string('emailcharset'), $choices);
-            $mform->setType('mailcharset', PARAM_CLEAN);
-            $mform->setDefault('mailcharset', $mailcharset);
-            $mform->setAdvanced('mailcharset');
-        }
-
-
-        $choices = array();
-        $choices['0'] = get_string('emaildigestoff');
-        $choices['1'] = get_string('emaildigestcomplete');
-        $choices['2'] = get_string('emaildigestsubjects');
-        $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
-        $mform->setType('maildigest', PARAM_INT);
-        $mform->setDefault('maildigest', 0);
-        $mform->setAdvanced('maildigest');
-
-        $choices = array();
-        $choices["1"] = get_string("autosubscribeyes");
-        $choices["0"] = get_string("autosubscribeno");
-        $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
-        $mform->setType('autosubscribe', PARAM_INT);
-        $mform->setDefault('autosubscribe', 0);
-        $mform->setAdvanced('autosubscribe');
-
-        if (!empty($CFG->forum_trackreadposts)) {
-            $choices = array();
-            $choices["0"] = get_string("trackforumsno");
-            $choices["1"] = get_string("trackforumsyes");
-            $mform->addElement('select', 'trackforums', get_string('trackforums'), $choices);
-            $mform->setType('trackforums', PARAM_INT);
-            $mform->setDefault('trackforums', 0);
-        }
-        $mform->setAdvanced('trackforums');
-
-        if ($CFG->htmleditor) {
-            $choices = array();
-            $choices["0"] = get_string("texteditor");
-            $choices["1"] = get_string("htmleditor");
-            $mform->addElement('select', 'htmleditor', get_string('textediting'), $choices);
-            $mform->setType('htmleditor', PARAM_INT);
-            $mform->setDefault('htmleditor', 1);
-        }
-        $mform->setAdvanced('htmleditor');
-
-        $choices = array();
-        $choices["0"] = get_string("ajaxno");
-        $choices["1"] = get_string("ajaxyes");
-        $mform->addElement('select', 'ajax', get_string('ajaxuse'), $choices);
-        $mform->setType('ajax', PARAM_INT);
-        $mform->setDefault('ajax', 1);
-        if (empty($CFG->enableajax)) {
-            $mform->hardFreeze('ajax');
-        }
-        $mform->setAdvanced('ajax');
-
-        $mform->addElement('text', 'city', get_string('city'), 'maxlength="100" size="25"');
-        $mform->setType('city', PARAM_MULTILANG);
-        $mform->addRule('city', $strrequired, 'required', null, 'client');
-
-
-        $choices = get_list_of_countries();
-        $choices= array(''=>get_string('selectacountry').'...') + $choices;
-        $mform->addElement('select', 'country', get_string('selectacountry'), $choices);
-        $mform->setType('country', PARAM_ALPHA);
-        $mform->addRule('country', $strrequired, 'required', null, 'client');
-        if (!empty($CFG->country)) {
-            $mform->setDefault('country', $CFG->country);
-        }
-
-        $choices = get_list_of_timezones();
-        $choices['99'] = get_string('serverlocaltime');
-        if ($CFG->forcetimezone != 99) {
-            $mform->addElement('static', 'forcedtimezone', get_string('timezone'), $choices[$CFG->forcetimezone]);
-        } else {
-            $mform->addElement('select', 'timezone', get_string('timezone'), $choices);
-            $mform->setType('timezone', PARAM_PATH);
-            $mform->setDefault('timezone', '99');
-        }
-
-        $choices = array();
-        if ($choices = get_list_of_languages()) {
-            $mform->addElement('select', 'lang', get_string('preferredlanguage'), $choices);
-            $mform->setType('lang', PARAM_FILE);
-            $mform->setDefault('lang', $CFG->lang);
-        }
-
-        if (!empty($CFG->allowuserthemes)) {
-            $choices = array();
-            $choices[''] = get_string('default');
-            $choices += get_list_of_themes();
-            $mform->addElement('select', 'theme', get_string('preferredtheme'), $choices);
-            $mform->setType('theme', PARAM_ALPHANUM);
-            $mform->setAdvanced('theme');
-        }
-
-        $mform->addElement('htmleditor', 'description', get_string('userdescription'));
-        $mform->setType('description', PARAM_MULTILANG);
-        $mform->setHelpButton('description', array('text', get_string('helptext')));
-        if (!$userupdate) {
-            $mform->addRule('description', $strrequired, 'required', null, 'client');
-        }
-
-        $choices = array();
-        $choices["0"] = get_string("screenreaderno");
-        $choices["1"] = get_string("screenreaderyes");
-        $mform->addElement('select', 'screenreader', get_string('screenreaderuse'), $choices);
-        $mform->setType('screenreader', PARAM_INT);
-        $mform->setDefault('screenreader', 0);
-        $mform->setAdvanced('screenreader');
-
-        $maxbytes = get_max_upload_file_size($CFG->maxbytes, $course->maxbytes);
-        if (!empty($CFG->gdversion) and $maxbytes and (empty($CFG->disableuserimages) or $userupdate)) {
-
-            $mform->addElement('header', 'moodle_picture', get_string('pictureof', '', fullname($user)));
-
-            $mform->addElement('static', 'currentpicture', get_string('currentpicture'),print_user_picture($user->id, $course->id, $user->picture, false, true, false));
-            if ($user->picture) {
-                $mform->addElement('checkbox', 'deletepicture', get_string('delete'));
-                $mform->setDefault('deletepicture',false);
+                $image_el->setValue(get_string('none'));
             }
-            $mform->addElement('file', 'imagefile', get_string('newpicture'));
-            $mform->setHelpButton('imagefile', array('picture', get_string('helppicture')));
-
-            $mform->addElement('text', 'imagealt', get_string('imagealt'), 'maxlength="100" size="30"');
-            $mform->setType('imagealt', PARAM_MULTILANG);
-
-        }
-
-
-        /// Moodle optional fields
-        $mform->addElement('header', 'moodle_optional', get_string('optional', 'form'));
-        $mform->setAdvanced('moodle_optional');
-
-        $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"');
-        $mform->setType('url', PARAM_URL);
-
-        $mform->addElement('text', 'icq', get_string('icqnumber'), 'maxlength="15" size="25"');
-        $mform->setType('icq', PARAM_CLEAN);
-
-        $mform->addElement('text', 'skype', get_string('skypeid'), 'maxlength="50" size="25"');
-        $mform->setType('skype', PARAM_CLEAN);
-
-        $mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="50" size="25"');
-        $mform->setType('aim', PARAM_CLEAN);
-
-        $mform->addElement('text', 'yahoo', get_string('yahooid'), 'maxlength="50" size="25"');
-        $mform->setType('yahoo', PARAM_CLEAN);
-
-        $mform->addElement('text', 'msn', get_string('msnid'), 'maxlength="50" size="25"');
-        $mform->setType('msn', PARAM_CLEAN);
-
-        $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="64" size="25"');
-        $mform->setType('idnumber', PARAM_MULTILANG);
-        if (!$userupdate) {
-            $mform->hardFreeze('idnumber');
-        }
-
-        if ($userupdate) {
-            $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"');
-            $mform->setType('institution', PARAM_MULTILANG);
-
-            $mform->addElement('text', 'department', get_string('department'), 'maxlength="30" size="25"');
-            $mform->setType('department', PARAM_MULTILANG);
-        }
-
-        $mform->addElement('text', 'phone1', get_string('phone'), 'maxlength="20" size="25"');
-        $mform->setType('phone1', PARAM_CLEAN);
-        if (!$userupdate) {
-            $mform->hardFreeze('phone1');
-        }
-
-        $mform->addElement('text', 'phone2', get_string('phone'), 'maxlength="20" size="25"');
-        $mform->setType('phone2', PARAM_CLEAN);
-        if (!$userupdate) {
-            $mform->hardFreeze('phone2');
         }
 
-        $mform->addElement('text', 'address', get_string('address'), 'maxlength="70" size="25"');
-        $mform->setType('address', PARAM_MULTILANG);
-        if (!$userupdate) {
-            $mform->hardFreeze('address');
-        }
-
-        /// disable fields that are locked by auth plugins
-        $fields = get_user_fieldnames();
-        $freezefields = array();
-        foreach ($fields as $field) {
-            $configvariable = 'field_lock_' . $field;
-            if (isset($authplugin->config->{$configvariable}) and
-                 ( $authplugin->config->{$configvariable} === 'locked' or
-                   ( $authplugin->config->{$configvariable} === 'unlockedifempty' and !empty($user->$field)) ) ) {
-                $freezefields[] = $field;
+            /// disable fields that are locked by auth plugins
+            $fields = get_user_fieldnames();
+            $freezefields = array();
+            $authplugin = get_auth_plugin($user->auth);
+            foreach ($fields as $field) {
+                if (!$mform->elementExists($field)) {
+                    continue;
+                }
+                $configvariable = 'field_lock_' . $field;
+                if (isset($authplugin->config->{$configvariable})) {
+                    if ($authplugin->config->{$configvariable} === 'locked') {
+                        $freezefields[] = $field;
+                    } else if ($authplugin->config->{$configvariable} === 'unlockedifempty' and $user->$field != '') {
+                        $freezefields[] = $field;
+                    }
+                }
             }
+            $mform->hardFreeze($freezefields);
         }
-        $mform->hardFreeze($freezefields);
-
-        /// Next the customisable profile fields
-        profile_print_custom_fields($mform, $user->id);
-
-        
-        $this->add_action_buttons(false, get_string('updatemyprofile'));
-
-    } /// End of function
+        /// TODO: add locking
 
-    function definition_after_data () {
-        /// nothing yet
     }
 
-
-/// perform some moodle validation
     function validation ($usernew) {
         global $CFG;
 
         $usernew = (object)$usernew;
-        $user    = $this->_customdata['user'];
+        $user    = get_record('user', 'id', $usernew->id);
         $err     = array();
 
-        if (has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
-            if (empty($usernew->username)) { /// We should never get this
-                //$err["username"] = get_string("missingusername");
-                $err["username"] = 'testing';
-            } else if (record_exists("user", "username", $usernew->username, 'mnethostid', $CFG->mnet_localhost_id) and $user->username == "changeme") {
-                $err["username"] = get_string("usernameexists");
-            } else {
-                if (empty($CFG->extendedusernamechars)) {
-                    $string = eregi_replace("[^(-\.[:alnum:])]", "", $usernew->username);
-                    if (strcmp($usernew->username, $string)) {
-                        $err["username"] = get_string("alphanumerical");
-                    }
-                }
-            }
-
-            // TODO: is_internal_auth() - what, the global auth? the user auth?
-            if (empty($usernew->newpassword) and empty($user->password) and is_internal_auth()) {
-                $err["newpassword"] = get_string("missingpassword");
-            }
-            if (($usernew->newpassword == "admin") or ($user->password == md5("admin") and empty($usernew->newpassword)) ) {
-                $err["newpassword"] = get_string("unsafepassword");
-            }
-        }
-
-
-        if (! validate_email($usernew->email)) {
-            $err["email"] = get_string("invalidemail");
-        } else if ($otheruser = get_record("user", "email", $usernew->email)) {
-            if ($otheruser->id <> $user->id) {
-                $err["email"] = get_string("emailexists");
-            }
+        // validate email
+        if (!validate_email($usernew->email)) {
+            $err['email'] = get_string('invalidemail');
+        } else if (($usernew->email !== $user->email) and record_exists('user', 'email', $usernew->email, 'mnethostid', $CFG->mnet_localhost_id)) {
+            $err['email'] = get_string('emailexists');
         }
-        if (empty($err["email"]) and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
-            if ($error = email_is_not_allowed($usernew->email)) {
-                $err["email"] = $error;
-            }
+        
+        if ($usernew->email === $user->email and over_bounce_threshold($user)) {
+            $err['email'] = get_string('toomanybounces');
         }
 
-        /// And now we validate the custom data fields
-
-        if ($categories = get_records_select('user_info_category', '', 'sortorder ASC')) {
-            foreach ($categories as $category) {
-
-                if ($fields = get_records_select('user_info_field', "categoryid=$category->id", 'sortorder ASC')) {
-                    foreach ($fields as $field) {
-
-                        require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
-                        $newfield = 'profile_field_'.$field->datatype;
-                        $formfield = new $newfield($field->id,$user->id);
-
-                        if (isset($usernew->{$formfield->fieldname})) {
-
-                            $errorstr = $formfield->validate_data($usernew->{$formfield->fieldname});
-                            if (!empty($errorstr)) {
-                                $err[$formfield->fieldname] = $errorstr;
-                            }
-
-                        }
-
-                        unset($formfield);
-
-                    }
-                } /// End of $fields if
-            } /// End of $categories foreach
-        } /// End of $categories if
-
         if (count($err) == 0){
             return true;
         } else {
             return $err;
         }
     }
+
+    function get_um() {
+        return $this->_upload_manager;
+    }
 }
 
 ?>
index 23747ce2611e447d11f53b397ea99aacdbbff94e..b7bda4bc00d036966463e8b7eea9a96d92b49f59 100644 (file)
 <?php  //$Id$
 
-        $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
-        $mform->addRule('firstname', $strrequired, 'required', null, 'client');
-        $mform->setType('firstname', PARAM_NOTAGS);
-
-        $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"');
-        $mform->addRule('lastname', $strrequired, 'required', null, 'client');
-        $mform->setType('lastname', PARAM_NOTAGS);
-
-        $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"');
-        $mform->addRule('email', $strrequired, 'required', null, 'client');
-
-        $choices = array();
-        $choices['0'] = get_string('emaildisplayno');
-        $choices['1'] = get_string('emaildisplayyes');
-        $choices['2'] = get_string('emaildisplaycourse');
-        $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
-        $mform->setDefault('emaildisplay', 2);
-
-        $choices = array();
-        $choices['0'] = get_string('emailenable');
-        $choices['1'] = get_string('emaildisable');
-        $mform->addElement('select', 'emailstop', get_string('emailactive'), $choices);
-        $mform->setDefault('emailenable', 1);
-
+    if (!defined('MOODLE_INTERNAL')) {
+        die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
+    }
+
+    $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
+    $mform->addRule('firstname', $strrequired, 'required', null, 'client');
+    $mform->setType('firstname', PARAM_NOTAGS);
+
+    $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"');
+    $mform->addRule('lastname', $strrequired, 'required', null, 'client');
+    $mform->setType('lastname', PARAM_NOTAGS);
+
+    $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"');
+    $mform->addRule('email', $strrequired, 'required', null, 'client');
+
+    $choices = array();
+    $choices['0'] = get_string('emaildisplayno');
+    $choices['1'] = get_string('emaildisplayyes');
+    $choices['2'] = get_string('emaildisplaycourse');
+    $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
+    $mform->setDefault('emaildisplay', 2);
+
+    $choices = array();
+    $choices['0'] = get_string('emailenable');
+    $choices['1'] = get_string('emaildisable');
+    $mform->addElement('select', 'emailstop', get_string('emailactive'), $choices);
+    $mform->setDefault('emailenable', 1);
+
+    $choices = array();
+    $choices['0'] = get_string('textformat');
+    $choices['1'] = get_string('htmlformat');
+    $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
+    $mform->setDefault('mailformat', 1);
+    $mform->setAdvanced('mailformat');
+
+    if (!empty($CFG->allowusermailcharset)) {
         $choices = array();
-        $choices['0'] = get_string('textformat');
-        $choices['1'] = get_string('htmlformat');
-        $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
-        $mform->setDefault('mailformat', 1);
-        $mform->setAdvanced('mailformat');
-
-        if (!empty($CFG->allowusermailcharset)) {
-            $choices = array();
-            $charsets = get_list_of_charsets();
-            if (!empty($CFG->sitemailcharset)) {
-                $choices['0'] = get_string('site').' ('.$CFG->sitemailcharset.')';
-            } else {
-                $choices['0'] = get_string('site').' ('.current_charset().')';
-            }
-            $choices = array_merge($choices, $charsets);
-            $mform->addElement('select', 'preference_mailcharset', get_string('emailcharset'), $choices);
-            $mform->setAdvanced('preference_mailcharset');
+        $charsets = get_list_of_charsets();
+        if (!empty($CFG->sitemailcharset)) {
+            $choices['0'] = get_string('site').' ('.$CFG->sitemailcharset.')';
+        } else {
+            $choices['0'] = get_string('site').' ('.current_charset().')';
         }
-
+        $choices = array_merge($choices, $charsets);
+        $mform->addElement('select', 'preference_mailcharset', get_string('emailcharset'), $choices);
+        $mform->setAdvanced('preference_mailcharset');
+    }
+
+    $choices = array();
+    $choices['0'] = get_string('emaildigestoff');
+    $choices['1'] = get_string('emaildigestcomplete');
+    $choices['2'] = get_string('emaildigestsubjects');
+    $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
+    $mform->setDefault('maildigest', 0);
+    $mform->setAdvanced('maildigest');
+
+    $choices = array();
+    $choices['1'] = get_string('autosubscribeyes');
+    $choices['0'] = get_string('autosubscribeno');
+    $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
+    $mform->setDefault('autosubscribe', 0);
+    $mform->setAdvanced('autosubscribe');
+
+    if (!empty($CFG->forum_trackreadposts)) {
         $choices = array();
-        $choices['0'] = get_string('emaildigestoff');
-        $choices['1'] = get_string('emaildigestcomplete');
-        $choices['2'] = get_string('emaildigestsubjects');
-        $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
-        $mform->setDefault('maildigest', 0);
-        $mform->setAdvanced('maildigest');
-
+        $choices['0'] = get_string('trackforumsno');
+        $choices['1'] = get_string('trackforumsyes');
+        $mform->addElement('select', 'trackforums', get_string('trackforums'), $choices);
+        $mform->setDefault('trackforums', 0);
+        $mform->setAdvanced('trackforums');
+    }
+
+    if ($CFG->htmleditor) {
         $choices = array();
-        $choices['1'] = get_string('autosubscribeyes');
-        $choices['0'] = get_string('autosubscribeno');
-        $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
-        $mform->setDefault('autosubscribe', 0);
-        $mform->setAdvanced('autosubscribe');
-
-        if (!empty($CFG->forum_trackreadposts)) {
-            $choices = array();
-            $choices['0'] = get_string('trackforumsno');
-            $choices['1'] = get_string('trackforumsyes');
-            $mform->addElement('select', 'trackforums', get_string('trackforums'), $choices);
-            $mform->setDefault('trackforums', 0);
-            $mform->setAdvanced('trackforums');
-        }
-
-        if ($CFG->htmleditor) {
-            $choices = array();
-            $choices['0'] = get_string('texteditor');
-            $choices['1'] = get_string('htmleditor');
-            $mform->addElement('select', 'htmleditor', get_string('textediting'), $choices);
-            $mform->setDefault('htmleditor', 1);
-            $mform->setAdvanced('htmleditor');
-        }
-
-        if (empty($CFG->enableajax)) {
-            $mform->addElement('static', 'ajaxdisabled', get_string('ajaxuse'), get_string('ajaxno'));
-            $mform->setAdvanced('ajaxdisabled');
-        } else {
-            $choices = array();
-            $choices['0'] = get_string('ajaxno');
-            $choices['1'] = get_string('ajaxyes');
-            $mform->addElement('select', 'ajax', get_string('ajaxuse'), $choices);
-            $mform->setDefault('ajax', 0);
-            $mform->setAdvanced('ajax');
-        }
-
+        $choices['0'] = get_string('texteditor');
+        $choices['1'] = get_string('htmleditor');
+        $mform->addElement('select', 'htmleditor', get_string('textediting'), $choices);
+        $mform->setDefault('htmleditor', 1);
+        $mform->setAdvanced('htmleditor');
+    }
+
+    if (empty($CFG->enableajax)) {
+        $mform->addElement('static', 'ajaxdisabled', get_string('ajaxuse'), get_string('ajaxno'));
+        $mform->setAdvanced('ajaxdisabled');
+    } else {
         $choices = array();
-        $choices['0'] = get_string('screenreaderno');
-        $choices['1'] = get_string('screenreaderyes');
-        $mform->addElement('select', 'screenreader', get_string('screenreaderuse'), $choices);
-        $mform->setDefault('screenreader', 0);
-        $mform->setAdvanced('screenreader');
-
-        $mform->addElement('text', 'city', get_string('city'), 'maxlength="100" size="25"');
-        $mform->setType('city', PARAM_MULTILANG);
-        $mform->addRule('city', $strrequired, 'required', null, 'client');
-
-
-        $choices = get_list_of_countries();
-        $choices= array(''=>get_string('selectacountry').'...') + $choices;
-        $mform->addElement('select', 'country', get_string('selectacountry'), $choices);
-        $mform->addRule('country', $strrequired, 'required', null, 'client');
-        if (!empty($CFG->country)) {
-            $mform->setDefault('country', $CFG->country);
-        }
-
-        $choices = get_list_of_timezones();
-        $choices['99'] = get_string('serverlocaltime');
-        if ($CFG->forcetimezone != 99) {
-            $mform->addElement('static', 'forcedtimezone', get_string('timezone'), $choices[$CFG->forcetimezone]);
-        } else {
-            $mform->addElement('select', 'timezone', get_string('timezone'), $choices);
-            $mform->setDefault('timezone', '99');
-        }
-
+        $choices['0'] = get_string('ajaxno');
+        $choices['1'] = get_string('ajaxyes');
+        $mform->addElement('select', 'ajax', get_string('ajaxuse'), $choices);
+        $mform->setDefault('ajax', 0);
+        $mform->setAdvanced('ajax');
+    }
+
+    $choices = array();
+    $choices['0'] = get_string('screenreaderno');
+    $choices['1'] = get_string('screenreaderyes');
+    $mform->addElement('select', 'screenreader', get_string('screenreaderuse'), $choices);
+    $mform->setDefault('screenreader', 0);
+    $mform->setAdvanced('screenreader');
+
+    $mform->addElement('text', 'city', get_string('city'), 'maxlength="100" size="25"');
+    $mform->setType('city', PARAM_MULTILANG);
+    $mform->addRule('city', $strrequired, 'required', null, 'client');
+
+
+    $choices = get_list_of_countries();
+    $choices= array(''=>get_string('selectacountry').'...') + $choices;
+    $mform->addElement('select', 'country', get_string('selectacountry'), $choices);
+    $mform->addRule('country', $strrequired, 'required', null, 'client');
+    if (!empty($CFG->country)) {
+        $mform->setDefault('country', $CFG->country);
+    }
+
+    $choices = get_list_of_timezones();
+    $choices['99'] = get_string('serverlocaltime');
+    if ($CFG->forcetimezone != 99) {
+        $mform->addElement('static', 'forcedtimezone', get_string('timezone'), $choices[$CFG->forcetimezone]);
+    } else {
+        $mform->addElement('select', 'timezone', get_string('timezone'), $choices);
+        $mform->setDefault('timezone', '99');
+    }
+
+    $choices = array();
+    if ($choices = get_list_of_languages()) {
+        $mform->addElement('select', 'lang', get_string('preferredlanguage'), $choices);
+        $mform->setDefault('lang', $CFG->lang);
+    }
+
+    if (!empty($CFG->allowuserthemes)) {
         $choices = array();
-        if ($choices = get_list_of_languages()) {
-            $mform->addElement('select', 'lang', get_string('preferredlanguage'), $choices);
-            $mform->setDefault('lang', $CFG->lang);
-        }
+        $choices[''] = get_string('default');
+        $choices += get_list_of_themes();
+        $mform->addElement('select', 'theme', get_string('preferredtheme'), $choices);
+        $mform->setAdvanced('theme');
+    }
 
-        if (!empty($CFG->allowuserthemes)) {
-            $choices = array();
-            $choices[''] = get_string('default');
-            $choices += get_list_of_themes();
-            $mform->addElement('select', 'theme', get_string('preferredtheme'), $choices);
-            $mform->setAdvanced('theme');
-        }
-
-        $mform->addElement('htmleditor', 'description', get_string('userdescription'));
-        $mform->setType('description', PARAM_CLEAN);
-        $mform->setHelpButton('description', array('text', get_string('helptext')));
-        //TODO: set as 'required' in normal edit form
+    $mform->addElement('htmleditor', 'description', get_string('userdescription'));
+    $mform->setType('description', PARAM_CLEAN);
+    $mform->setHelpButton('description', array('text', get_string('helptext')));
 
-        if (!empty($CFG->gdversion)) {
-            $mform->addElement('header', 'moodle_picture', get_string('pictureof'));//TODO: Accessibility fix fieldset legend
+    if (!empty($CFG->gdversion)) {
+        $mform->addElement('header', 'moodle_picture', get_string('pictureof'));//TODO: Accessibility fix fieldset legend
 
-            $mform->addElement('static', 'currentpicture', get_string('currentpicture'));
-            //TODO: set current picture as default value
+        $mform->addElement('static', 'currentpicture', get_string('currentpicture'));
 
-            $mform->addElement('checkbox', 'deletepicture', get_string('delete'));
-            $mform->setDefault('deletepicture',false);
-            //TODO: remove when picture not present or user->id==0
+        $mform->addElement('checkbox', 'deletepicture', get_string('delete'));
+        $mform->setDefault('deletepicture',false);
 
-            $mform->addElement('file', 'imagefile', get_string('newpicture'));
-            $mform->setHelpButton('imagefile', array('picture', get_string('helppicture')));
+        $mform->addElement('file', 'imagefile', get_string('newpicture'));
+        $mform->setHelpButton('imagefile', array('picture', get_string('helppicture')));
 
-            $mform->addElement('text', 'imagealt', get_string('imagealt'), 'maxlength="100" size="30"');
-            $mform->setType('imagealt', PARAM_MULTILANG);
+        $mform->addElement('text', 'imagealt', get_string('imagealt'), 'maxlength="100" size="30"');
+        $mform->setType('imagealt', PARAM_MULTILANG);
 
-        }
-        //TODO: remove if empty($CFG->disableuserimages) in normal edit form
+    }
 
-        /// Moodle optional fields
-        /// TODO: freeze what's needed
-        $mform->addElement('header', 'moodle_optional', get_string('optional', 'form'));
-        $mform->setAdvanced('moodle_optional');
+    /// Moodle optional fields
+    $mform->addElement('header', 'moodle_optional', get_string('optional', 'form'));
+    $mform->setAdvanced('moodle_optional');
 
-        $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"');
-        $mform->setType('url', PARAM_URL);
+    $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"');
+    $mform->setType('url', PARAM_URL);
 
-        $mform->addElement('text', 'icq', get_string('icqnumber'), 'maxlength="15" size="25"');
-        $mform->setType('icq', PARAM_CLEAN);
+    $mform->addElement('text', 'icq', get_string('icqnumber'), 'maxlength="15" size="25"');
+    $mform->setType('icq', PARAM_CLEAN);
 
-        $mform->addElement('text', 'skype', get_string('skypeid'), 'maxlength="50" size="25"');
-        $mform->setType('skype', PARAM_CLEAN);
+    $mform->addElement('text', 'skype', get_string('skypeid'), 'maxlength="50" size="25"');
+    $mform->setType('skype', PARAM_CLEAN);
 
-        $mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="50" size="25"');
-        $mform->setType('aim', PARAM_CLEAN);
+    $mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="50" size="25"');
+    $mform->setType('aim', PARAM_CLEAN);
 
-        $mform->addElement('text', 'yahoo', get_string('yahooid'), 'maxlength="50" size="25"');
-        $mform->setType('yahoo', PARAM_CLEAN);
+    $mform->addElement('text', 'yahoo', get_string('yahooid'), 'maxlength="50" size="25"');
+    $mform->setType('yahoo', PARAM_CLEAN);
 
-        $mform->addElement('text', 'msn', get_string('msnid'), 'maxlength="50" size="25"');
-        $mform->setType('msn', PARAM_CLEAN);
+    $mform->addElement('text', 'msn', get_string('msnid'), 'maxlength="50" size="25"');
+    $mform->setType('msn', PARAM_CLEAN);
 
-        $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="64" size="25"');
-        $mform->setType('idnumber', PARAM_RAW);
+    $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="64" size="25"');
+    $mform->setType('idnumber', PARAM_RAW);
 
-        $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"');
-        $mform->setType('institution', PARAM_MULTILANG);
+    $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"');
+    $mform->setType('institution', PARAM_MULTILANG);
 
-        $mform->addElement('text', 'department', get_string('department'), 'maxlength="30" size="25"');
-        $mform->setType('department', PARAM_MULTILANG);
+    $mform->addElement('text', 'department', get_string('department'), 'maxlength="30" size="25"');
+    $mform->setType('department', PARAM_MULTILANG);
 
-        $mform->addElement('text', 'phone1', get_string('phone'), 'maxlength="20" size="25"');
-        $mform->setType('phone1', PARAM_CLEAN);
+    $mform->addElement('text', 'phone1', get_string('phone'), 'maxlength="20" size="25"');
+    $mform->setType('phone1', PARAM_CLEAN);
 
-        $mform->addElement('text', 'phone2', get_string('phone'), 'maxlength="20" size="25"');
-        $mform->setType('phone2', PARAM_CLEAN);
+    $mform->addElement('text', 'phone2', get_string('phone'), 'maxlength="20" size="25"');
+    $mform->setType('phone2', PARAM_CLEAN);
 
-        $mform->addElement('text', 'address', get_string('address'), 'maxlength="70" size="25"');
-        $mform->setType('address', PARAM_MULTILANG);
+    $mform->addElement('text', 'address', get_string('address'), 'maxlength="70" size="25"');
+    $mform->setType('address', PARAM_MULTILANG);
 
 
 ?>
\ No newline at end of file
index d83616723e13af1aeb5e0f52efe82f8fb703dd15..f6788128f243a0d327d641fc77abe4a140ff5e78 100644 (file)
@@ -4,6 +4,7 @@
     require_once($CFG->libdir.'/gdlib.php');
     require_once($CFG->libdir.'/adminlib.php');
     require_once($CFG->dirroot.'/user/editadvanced_form.php');
+    require_once($CFG->dirroot.'/user/profile/lib.php');
 
     $id     = optional_param('id', $USER->id, PARAM_INT);    // user id; -1 if creating new user
     $course = optional_param('course', SITEID, PARAM_INT);   // course id (defaults to Site)
     //TODO: Load the custom profile fields
 
     //create form
-    $userform = new user_editadvanced_form(null, $course);
+    $userform = new user_editadvanced_form();
     $userform->set_data($user);
 
     if ($usernew = $userform->get_data()) {
         add_to_log($course->id, 'user', 'update', "view.php?id=$user->id&course=$course->id", '');
 
-        $authplugin = get_auth_plugin($CFG->auth);
+        if (empty($usernew->auth)) {
+            //user editing self
+            $authplugin = get_auth_plugin($user->auth);
+            unset($usernew->auth);
+        } else {
+            $authplugin = get_auth_plugin($usernew->auth);
+        }
 
         $usernew->timemodified = time();
 
         if ($usernew->id == -1) {
             unset($usernew->id);
             $usernew->mnethostid = $CFG->mnet_localhost_id; // always local user
-            $usernew->confirmed = 1;
+            $usernew->confirmed  = 1;
             if (!$usernew->id = insert_record('user', $usernew)) {
                 error('Error creating user record');
             }
         }
 
         //update user picture
-        if ($usernew->deletepicture) {
-            //TODO - delete the files
-            set_field('user', 'picture', 0, 'id', $usernew->id);
-        } else if ($usernew->picture = save_profile_image($usernew->id, $userform->get_um(), 'users')) {
-            set_field('user', 'picture', 1, 'id', $usernew->id);
+        if (!empty($CFG->gdversion)) {
+            if ($usernew->deletepicture) {
+                //TODO - delete the files
+                set_field('user', 'picture', 0, 'id', $usernew->id);
+            } else if ($usernew->picture = save_profile_image($usernew->id, $userform->get_um(), 'users')) {
+                set_field('user', 'picture', 1, 'id', $usernew->id);
+            }
         }
 
         // update mail bounces
-        if ($user->email != $usernew->email) {
+        if ($user->email !== $usernew->email) {
             set_bounce_count($usernew,true);
             set_send_count($usernew,true);
         }
 
         /// Update forum track preference.
-        if (($usernew->trackforums != $user->trackforums) && !$usernew->trackforums) {
+        if (($usernew->trackforums != $user->trackforums) and !$usernew->trackforums) {
             require_once($CFG->dirroot.'/mod/forum/lib.php');
             forum_tp_delete_read_records($usernew->id);
         }
         echo '<br />';
     } else {
         $streditmyprofile = get_string('editmyprofile');
-        $strparticipants = get_string('participants');
-        $strnewuser = get_string('newuser');
-        $userfullname = fullname($user, true);
+        $strparticipants  = get_string('participants');
+        $strnewuser       = get_string('newuser');
+        $userfullname     = fullname($user, true);
         if ($course->id != SITEID) {
             print_header("$course->shortname: $streditmyprofile", "$course->fullname: $streditmyprofile",
                          "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>
index ad6e2c82a69e03877fec71ff4ca83383d8e484cf..6350b8b03e6808cf4822aebcb97f8154eac70a67 100644 (file)
@@ -1,22 +1,20 @@
 <?php //$Id$
 
 require_once($CFG->dirroot.'/lib/formslib.php');
-require_once($CFG->dirroot.'/user/profile/lib.php');
 
 class user_editadvanced_form extends moodleform {
 
     // Define the form
     function definition () {
-        global $USER, $CFG;
+        global $USER, $CFG, $COURSE;
 
         $mform =& $this->_form;
-        $course = $this->_customdata;
         $this->set_upload_manager(new upload_manager('imagefile', false, false, null, false, 0, true, true, false));
         $strrequired = get_string('required');
 
         /// Add some extra hidden fields
         $mform->addElement('hidden', 'id');
-        $mform->addElement('hidden', 'course', $course->id);
+        $mform->addElement('hidden', 'course', $COURSE->id);
 
         /// Print the required moodle fields first
         $mform->addElement('header', 'moodle', $strrequired);