diff --git a/admin/auth.php b/admin/auth.php
index a11e2b731da..39b7469e3df 100644
--- a/admin/auth.php
+++ b/admin/auth.php
@@ -23,11 +23,27 @@
$config = (array)$config;
validate_form($config, $err);
+ // extract and sanitize the auth key explicitly
+ $modules = get_list_of_plugins("auth");
+ if (in_array($config['auth'], $modules)) {
+ $auth = $config['auth'];
+ } else {
+ notify("Error defining the authentication method");
+ }
+
if (count($err) == 0) {
print_header();
foreach ($config as $name => $value) {
- if (! set_config($name, $value)) {
- notify("Problem saving config $name as $value");
+ if (preg_match('/^pluginconfig_(.+?)$/', $name, $matches)) {
+ $plugin = "auth/$auth";
+ $name = $matches[1];
+ if (! set_config($name, $value, $plugin)) {
+ notify("Problem saving config $name as $value for plugin $plugin");
+ }
+ } else { // normal handling for
+ if (! set_config($name, $value)) {
+ notify("Problem saving config $name as $value");
+ }
}
}
redirect("auth.php?sesskey=$USER->sesskey", get_string("changessaved"), 1);
@@ -198,5 +214,30 @@ function validate_form(&$form, &$err) {
return;
}
+//
+// Good enough for most auth plugins
+// but some may want a custom one if they are offering
+// other options
+// Note: pluginconfig_ fields have special handling.
+function print_auth_lock_options ($auth, $user_fields, $helptext='', $refreshopts, $updateopts) {
+ echo '
| ';
+ print_heading(get_string('auth_fieldlocks', 'auth'));
+ echo ' | |
';
+
+ $lockoptions = array ('unlocked' => get_string('auth_unlocked', 'auth'),
+ 'unlockedifempty' => get_string('auth_unlockedifempty', 'auth'),
+ 'locked' => get_string('auth_locked', 'auth'));
+
+ $pluginconfig = get_config("auth/$auth");
+
+ foreach ($user_fields as $field) {
+ echo '| ';
+ echo get_string($field);
+ echo ' | ';
+ choose_from_menu($lockoptions, "pluginconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, "");
+ echo " | $helptext |
";
+ $helptext = ' ';
+ }
+}
?>
diff --git a/auth/email/config.html b/auth/email/config.html
index 660e38b7020..f686f3a9529 100644
--- a/auth/email/config.html
+++ b/auth/email/config.html
@@ -1,2 +1,4 @@
+
+
\ No newline at end of file
diff --git a/auth/fc/config.html b/auth/fc/config.html
index 90e7e9f11be..11682c9f5b6 100644
--- a/auth/fc/config.html
+++ b/auth/fc/config.html
@@ -166,3 +166,4 @@
+
diff --git a/auth/imap/config.html b/auth/imap/config.html
index 5766b132992..40619cb4993 100644
--- a/auth/imap/config.html
+++ b/auth/imap/config.html
@@ -57,3 +57,4 @@
+
\ No newline at end of file
diff --git a/auth/manual/config.html b/auth/manual/config.html
index 111a2494b01..7288eb46f89 100644
--- a/auth/manual/config.html
+++ b/auth/manual/config.html
@@ -8,4 +8,4 @@
-
+
diff --git a/auth/nntp/config.html b/auth/nntp/config.html
index 8fcf207e15f..f8216d086b7 100644
--- a/auth/nntp/config.html
+++ b/auth/nntp/config.html
@@ -40,3 +40,4 @@
+
\ No newline at end of file
diff --git a/auth/none/config.html b/auth/none/config.html
index 660e38b7020..e3056dbba4b 100644
--- a/auth/none/config.html
+++ b/auth/none/config.html
@@ -1,2 +1,3 @@
+
\ No newline at end of file
diff --git a/auth/pam/config.html b/auth/pam/config.html
index ea85dec7bc0..fa9c94a07a5 100644
--- a/auth/pam/config.html
+++ b/auth/pam/config.html
@@ -6,4 +6,5 @@
-
\ No newline at end of file
+
+
\ No newline at end of file
diff --git a/auth/pop3/config.html b/auth/pop3/config.html
index 6eb389656d3..d35962cd291 100644
--- a/auth/pop3/config.html
+++ b/auth/pop3/config.html
@@ -71,3 +71,5 @@
+
+
\ No newline at end of file
diff --git a/lib/moodlelib.php b/lib/moodlelib.php
index 53fbd974f97..a8f8856b80f 100644
--- a/lib/moodlelib.php
+++ b/lib/moodlelib.php
@@ -387,29 +387,104 @@ function optional_variable(&$var, $default=0) {
*
* Set a key/value pair in both this session's {@link $CFG} global variable
* and in the 'config' database table for future sessions.
+ *
+ * Can also be used to update keys for plugin-scoped configs in config_plugin table.
+ * In that case it doesn't affect $CFG.
*
* @param string $name the key to set
* @param string $value the value to set
+ * @param string $plugin (optional) the plugin scope
* @uses $CFG
* @return bool
*/
-function set_config($name, $value) {
+function set_config($name, $value, $plugin=NULL) {
/// No need for get_config because they are usually always available in $CFG
global $CFG;
-
- $CFG->$name = $value; // So it's defined for this invocation at least
-
- if (get_field('config', 'name', 'name', $name)) {
- return set_field('config', 'value', $value, 'name', $name);
- } else {
- $config->name = $name;
- $config->value = $value;
- return insert_record('config', $config);
+ if (empty($plugin)) {
+ $CFG->$name = $value; // So it's defined for this invocation at least
+
+ if (get_field('config', 'name', 'name', $name)) {
+ return set_field('config', 'value', $value, 'name', $name);
+ } else {
+ $config->name = $name;
+ $config->value = $value;
+ return insert_record('config', $config);
+ }
+ } else { // plugin scope
+ if ($id = get_field('config_plugins', 'id', 'name', $name, 'plugin', $plugin)) {
+ return set_field('config_plugins', 'value', $value, 'id', $id);
+ } else {
+ $config->plugin = $plugin;
+ $config->name = $name;
+ $config->value = $value;
+ return insert_record('config_plugins', $config);
+ }
}
}
+/**
+ * Get configuration values from the global config table
+ * or the config_plugins table.
+ *
+ * If called with no parameters it will do the right thing
+ * generating $CFG safely from the database without overwriting
+ * existing values.
+ *
+ * @param string $plugin
+ * @param string $name
+ * @uses $CFG
+ * @return hash-like object or single value
+ *
+ */
+function get_config($plugin=NULL, $name=NULL) {
+
+ global $CFG;
+
+ if (!empty($name)) { // the user is asking for a specific value
+ if (!empty($plugin)) {
+ return get_record('config_plugins', 'plugin' , $plugin, 'name', $name);
+ } else {
+ return get_record('config', 'name', $name);
+ }
+ }
+
+ // the user is after a recordset
+ if (!empty($plugin)) {
+ if ($configs=get_records('config_plugins', 'plugin', $plugin, '', 'name,value')) {
+ $configs = (array)$configs;
+ $localcfg = array();
+ foreach ($configs as $config) {
+ $localcfg[$config->name] = $config->value;
+ }
+ return (object)$localcfg;
+ } else {
+ return false;
+ }
+ } else {
+ // this was originally in setup.php
+ if ($configs = get_records('config')) {
+ $localcfg = (array)$CFG;
+ foreach ($configs as $config) {
+ if (!isset($localcfg[$config->name])) {
+ $localcfg[$config->name] = $config->value;
+ } else {
+ if ($localcfg[$config->name] != $config->value ) {
+ // complain if the DB has a different
+ // value than config.php does
+ error_log("\$CFG->{$config->name} in config.php ({$localcfg[$config->name]}) overrides database setting ({$config->value})");
+ }
+ }
+ }
+
+ $localcfg = (object)$localcfg;
+ }
+ return $localcfg;
+ }
+}
+
+
/**
* Refresh current $USER session global variable with all their current preferences.
* @uses $USER
diff --git a/lib/setup.php b/lib/setup.php
index af22b7702d4..a00571e3017 100644
--- a/lib/setup.php
+++ b/lib/setup.php
@@ -147,21 +147,7 @@ global $THEME;
/// Load up any configuration from the config table
-
- if ($configs = get_records('config')) {
- $CFG = (array)$CFG;
- foreach ($configs as $config) {
- if (!isset($CFG[$config->name])) {
- $CFG[$config->name] = $config->value;
- } else {
- error_log("\$CFG->$config->name in config.php overrides database setting");
- }
- }
-
- $CFG = (object)$CFG;
- unset($configs);
- unset($config);
- }
+ $CFG = get_config();
/// Turn on SQL logging if required
if (!empty($CFG->logsql)) {
diff --git a/lib/weblib.php b/lib/weblib.php
index 867ae1330e0..70ae052b24f 100644
--- a/lib/weblib.php
+++ b/lib/weblib.php
@@ -2900,6 +2900,10 @@ function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $v
}
if ($usehtmleditor) {
+
+ // cleanup bad html that may have made it to the db
+ $value = clean_text($value);
+
if (!empty($courseid) and isteacher($courseid)) {
echo ($scriptcount < 1) ? ''."\n" : '';
} else {
diff --git a/user/edit.php b/user/edit.php
index 1d6f72c8bd9..a00c31d6811 100644
--- a/user/edit.php
+++ b/user/edit.php
@@ -126,11 +126,13 @@
// override locked values
if (!isadmin()) {
$fields = get_user_fieldnames();
+ $authconfig = get_config( 'auth/' . $user->auth );
foreach ($fields as $field) {
- $configvariable = 'auth_user_'.$field.'_editlock';
- if (!empty($CFG->$configvariable)) {
- if (isset($usernew->$field) && $user->$field !== $usernew->$field) {
- $usernew->$field = $user->$field;
+ $configvariable = 'field_lock_' . $field;
+ if ( $authconfig->{$configvariable} === 'locked'
+ || ($authconfig->{$configvariable} === 'unlockedifempty' && !empty($user->$field)) ) {
+ if (!empty( $user->$field)) {
+ $usernew->$field = $user->$field;
}
}
}
@@ -323,9 +325,11 @@
echo '