]> git.mjollnir.org Git - moodle.git/commitdiff
Fields set as locked are now disabled using the forms class rather than
authorikawhero <ikawhero>
Fri, 5 Jan 2007 06:57:30 +0000 (06:57 +0000)
committerikawhero <ikawhero>
Fri, 5 Jan 2007 06:57:30 +0000 (06:57 +0000)
javascript.

user/edit.php
user/edit_form.php

index 49ed2c0209272046c2897a8ba6eabc9032ee1427..87fe800fd9542e4a0c459c48b79284deeea1c6ab 100644 (file)
@@ -76,7 +76,7 @@
     }
 
 
-    $userform = new user_edit_form('edit.php', compact('user','course'));
+    $userform = new user_edit_form('edit.php', compact('user','course','authplugin'));
     $userform->set_upload_manager(new upload_manager('imagefile',false,false,null,false,0,true,true));
 
 /// If data submitted, then process and store.
 
     $userform->display();
 
-    if (!has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {      /// Lock all the locked fields using Javascript
-        $fields = get_user_fieldnames();
-
-        echo '<script type="text/javascript">'."\n";
-        echo '<!--'."\n";
-
-        foreach ($fields as $field) {
-            $configvariable = 'field_lock_' . $field;
-            if (isset($authplugin->config->{$configvariable})) {
-                if ( $authplugin->config->{$configvariable} === 'locked'
-                    or ($authplugin->config->{$configvariable} === 'unlockedifempty' and !empty($user->$field))) {
-                   echo "eval('getElementById('editform').$field.disabled=true');\n";
-                }
-            }
-        }
-
-        echo '-->'."\n";
-        echo '</script>'."\n";
-    }
-
-
     if (!isset($USER->newadminuser)) {
         print_footer($course);
     } else {
index e17963597f76dc1927f90a41579572314fffe65b..fd158dae45247da927be79c4896b44a3872272af 100644 (file)
@@ -9,10 +9,11 @@ class user_edit_form extends moodleform {
     function definition () {
         global $USER, $CFG;
 
-        $mform    =& $this->_form;
-        $renderer =& $mform->defaultRenderer();
-        $user     = $this->_customdata['user'];
-        $course   = $this->_customdata['course'];
+        $mform      =& $this->_form;
+        $renderer   =& $mform->defaultRenderer();
+        $user       = $this->_customdata['user'];
+        $course     = $this->_customdata['course'];
+        $authplugin = $this->_customdata['authplugin'];
 
         $systemcontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
         $userupdate    = has_capability('moodle/user:update', $systemcontext);
@@ -290,6 +291,19 @@ class user_edit_form extends moodleform {
         /// override the defaults with the user settings
         $this->set_defaults($user);
 
+
+        /// disable fields that are locked by auth plugins
+        if ($userupdate) {
+            $fields = get_user_fieldnames();
+
+            foreach ($fields as $field) {
+                $configvariable = 'field_lock_' . $field;
+                if (isset($authplugin->config->{$configvariable})) {
+                    $mform->disabledIf($field, ( $authplugin->config->{$configvariable} === 'locked' or ($authplugin->config->{$configvariable} === 'unlockedifempty' and !empty($user->$field))), true);
+                }
+            }
+        }
+
         
         /// Next the customisable categories
         if ($categories = get_records_select('user_info_category', '1', 'sortorder ASC')) {
@@ -310,7 +324,6 @@ class user_edit_form extends moodleform {
             } /// End of $categories foreach
         } /// End of $categories if
 
-
         $this->add_action_buttons(false, get_string('updatemyprofile'));
 
     } /// End of function