@@ -751,6 +349,7 @@ if (!function_exists('ldap_connect')){ // Is php4-ldap really there?
+
diff --git a/auth/ldap/lib.php b/auth/ldap/lib.php
index 73847c68ab9..f6333e143d5 100644
--- a/auth/ldap/lib.php
+++ b/auth/ldap/lib.php
@@ -372,6 +372,7 @@ function auth_sync_users ($bulk_insert_records = 1000, $do_updates=1) {
global $CFG ;
+ $pcfg = get_config('auth/ldap');
// configure a temp table
print "Configuring temp table\n";
@@ -503,11 +504,11 @@ function auth_sync_users ($bulk_insert_records = 1000, $do_updates=1) {
////
if ($do_updates) {
// narrow down what fields we need to update
- $all_keys = array_keys(get_object_vars($CFG));
+ $all_keys = array_keys(get_object_vars($pcfg));
$updatekeys = array();
foreach ($all_keys as $key) {
- if (preg_match('/^auth_user_(.+)_updatelocal$/',$key, $match)) {
- if ($CFG->{$match[0]}) { // if it has a true value
+ if (preg_match('/^field_updatelocal_(.+)$/',$key, $match)) {
+ if ($pcfg->{$match[0]}) { // if it has a true value
array_push($updatekeys, $match[1]); // the actual key name
}
}
@@ -637,6 +638,8 @@ function auth_ldap_update_user_record($username, $updatekeys=false) {
global $CFG;
+ $pcfg = get_config('auth/ldap');
+
//just in case check text case
$username = trim(moodle_strtolower($username));
@@ -663,8 +666,7 @@ function auth_ldap_update_user_record($username, $updatekeys=false) {
} else {
$value = '';
}
- if(isset($CFG->{'auth_user_' . $key. '_updatelocal'})
- && $CFG->{'auth_user_' . $key. '_updatelocal'}){
+ if (!empty($pcfg->{'field_updatelocal_' . $key})) {
if ($user->{$key} != $value) { // only update if it's changed
set_field('user', $key, $value, 'username', $username);
}
@@ -782,6 +784,8 @@ function auth_iscreator($username=0) {
function auth_user_update($olduser, $newuser) {
global $USER , $CFG;
+
+ $pcfg = get_config('auth/ldap');
$ldapconnection = auth_ldap_connect();
@@ -810,7 +814,7 @@ function auth_user_update($olduser, $newuser) {
//error_log(var_export($user_entry) . 'fpp' );
foreach ($attrmap as $key=>$ldapkeys){
- if (isset($CFG->{'auth_user_'. $key.'_updateremote'}) && $CFG->{'auth_user_'. $key.'_updateremote'}){
+ if (!empty($pcfg->{'field_updateremote_'. $key})) {
// for ldap values that could be in more than one
// ldap key, we will do our best to match
@@ -1355,10 +1359,12 @@ function auth_ldap_attributes (){
"department", "address", "city", "country", "description",
"idnumber", "lang" );
+ $pcfg = get_config('auth/ldap');
+
$moodleattributes = array();
foreach ($fields as $field) {
- if (!empty($config["auth_user_$field"])) {
- $moodleattributes[$field] = $config["auth_user_$field"];
+ if (!empty($pcfg->{"field_map_$field"})) {
+ $moodleattributes[$field] = $pcfg->{"field_map_$field"};
if (preg_match('/,/',$moodleattributes[$field])) {
$moodleattributes[$field] = explode(',', $moodleattributes[$field]); // split ?
}
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 @@
@@ -139,255 +49,7 @@ if (!isset($config->auth_user_lang_editlock)) {
-
-
:
-
-
-
-
-
-
-
-
-
-
-
-
:
-
-
-
-
-
-
-
-
-
-
-
-
:
-
-
-
-
-
-
-
-
-
-
-
-
-
1:
-
-
-
-
-
-
-
-
-
-
-
-
-
:
-
-
-
-
-
-
-
-
-
-
-
-
-
:
-
-
-
-
-
-
-
-
-
-
-
-
:
-
-
-
-
-
-
-
-
-
-
-
-
-
:
-
-
-
-
-
-
-
-
-
-
-
-
-
:
-
-
-
-
-
-
-
-
-
-
-
-
-
:
-
-
-
-
-
-
-
-
-
-
-
-
-
:
-
-
-
-
-
-
-
-
-
-
+', true, false); ?>
:
diff --git a/auth/shibboleth/lib.php b/auth/shibboleth/lib.php
index 7de729ec89c..d9a2fee02eb 100755
--- a/auth/shibboleth/lib.php
+++ b/auth/shibboleth/lib.php
@@ -65,14 +65,17 @@ function auth_shib_attributes (){
global $CFG;
$config = (array)$CFG;
+ $pcfg = get_config('auth/shibboleth');
+ $pcfg = (array) $pcfg;
+
$fields = array("firstname", "lastname", "email", "phone1", "phone2",
"department", "address", "city", "country", "description",
"idnumber", "lang", "guid");
$moodleattributes = array();
foreach ($fields as $field) {
- if ($config["auth_shib_user_$field"]) {
- $moodleattributes[$field] = $config["auth_shib_user_$field"];
+ if ($pcfg["auth_shib_user_$field"]) {
+ $moodleattributes[$field] = $pcfg["auth_shib_user_$field"];
}
}
$moodleattributes['username']=$config["shib_user_attribute"];
diff --git a/lang/en/auth.php b/lang/en/auth.php
index 79014f82bf3..9f04dd7d2cf 100644
--- a/lang/en/auth.php
+++ b/lang/en/auth.php
@@ -31,8 +31,8 @@ $string['auth_dbtable'] = 'Name of the table in the database';
$string['auth_dbtitle'] = 'Use an external database';
$string['auth_dbtype'] = 'The database type (See the ADOdb documentation for details)';
$string['auth_dbuser'] = 'Username with read access to the database';
-$string['auth_editlock'] = 'Lock value';
-$string['auth_editlock_expl'] = '
Lock value: If enabled, will prevent Moodle users and admins from editing the field directly. Use this option if you are maintaining this data in the external auth system.
Lock value: If enabled, will prevent Moodle users and admins from editing the field directly. Use this option if you are maintaining this data in the external auth system.
';
$string['auth_emaildescription'] = 'Email confirmation is the default authentication method. When the user signs up, choosing their own new username and password, a confirmation email is sent to the user\'s email address. This email contains a secure link to a page where the user can confirm their account. Future logins just check the username and password against the stored values in the Moodle database.';
$string['auth_emailtitle'] = 'Email-based authentication';
$string['auth_fccreators'] = 'List of groups whose members are allowed to create new courses. Separate multiple groups with \';\'. Names must be spelled exactly as on FirstClass server. System is case-sensitive.';
@@ -113,10 +113,10 @@ $string['auth_shib_convert_data'] = 'Data modification API';
$string['auth_shib_convert_data_description'] = 'You can use this API to further modify the data provided by Shibboleth. Read the README for further instructions.';
$string['auth_shib_instructions_help'] = 'Here you should provide custom instructions for your users to explain Shibboleth. It will be shown on the login page in the instructions section. It should include a link to a Shibboleth-protected resource that redirects users to \"$a\" so that Shibboleth users can login in Moodle. If you leave it blank, then standard instructions will be used (not Shibboleth-specific)';
$string['auth_shib_convert_data_warning'] = 'The file does not exist or is not readable by the webserver process!';
-$string['auth_updatelocal'] = 'Update local data';
-$string['auth_updatelocal_expl'] = '
Update local data: If enabled, the field will be updated (from external auth) every time the user logs in or there is a user synchronization. Fields set to update locally should be locked.
Update local: If enabled, the field will be updated (from external auth) every time the user logs in or there is a user synchronization. Fields set to update locally should be locked.
Update external: If enabled, the external auth will be updated when the user record is updated. Fields should be unlocked to allow edits.
';
$string['auth_updateremote_ldap'] = '
Note: Updating external LDAP data requires that you set binddn and bindpw to a bind-user with editing privileges to all the user records. It currently does not preserve multi-valued attributes, and will remove extra values on update.
';
$string['auth_user_create'] = 'Enable user creation';
$string['auth_user_creation'] = 'New (anonymous) users can create user accounts on the external authentication source and confirmed via email. If you enable this , remember to also configure module-specific options for user creation.';
@@ -137,5 +137,12 @@ $string['showguestlogin'] = 'You can hide or show the guest login button on the
$string['stdchangepassword'] = 'Use standard Change Password Page';
$string['stdchangepassword_expl'] = 'If the external authentication system allows password changes through Moodle, switch this to Yes. This setting overrides \'Change Password URL\'.';
$string['stdchangepassword_explldap'] = 'NOTE: It is recommended that you use LDAP over an SSL encrypted tunnel (ldaps://) if the LDAP server is remote.';
+$string['update_oncreate'] = 'On creation';
+$string['update_onlogin'] = 'On every login';
+$string['update_onupdate'] = 'On update';
+$string['update_never'] = 'Never';
+$string['unlocked'] = 'Unlocked';
+$string['unlockedifempty'] = 'Unlocked if empty';
+$string['locked'] = 'Locked';
?>
diff --git a/lib/db/mysql.php b/lib/db/mysql.php
index 68d4cda95e8..783909ad627 100644
--- a/lib/db/mysql.php
+++ b/lib/db/mysql.php
@@ -1385,6 +1385,52 @@ function main_upgrade($oldversion=0) {
COMMENT='Moodle modules and plugins configuration variables';");
}
+ if ($oldversion < 2005060200) { // migrate some config items to config_plugins table
+
+ // NOTE: this block is in both postgres AND mysql upgrade
+ // files. If you edit either, update the otherone.
+ $user_fields = array("firstname", "lastname", "email",
+ "phone1", "phone2", "department",
+ "address", "city", "country",
+ "description", "idnumber", "lang");
+ if (!empty($CFG->auth)) { // if we have no auth, just pass
+ foreach ($user_fields as $field) {
+ $suffixes = array('', '_editlock', '_updateremote', '_updatelocal');
+ foreach ($suffixes as $suffix) {
+ $key = 'auth_user_' . $field . $suffix;
+ if (isset($CFG->$key)) {
+
+ // translate keys & values
+ // to the new convention
+ // this should support upgrading
+ // even 1.5dev installs
+ $newkey = $key;
+ $newval = $CFG->$key;
+ if ($suffix === '') {
+ $newkey = 'field_map_' . $field;
+ } elseif ($suffix === '_editlock') {
+ $newkey = 'field_lock_' . $field;
+ $newval = ($newval==1) ? 'locked' : 'unlocked'; // translate 0/1 to locked/unlocked
+ } elseif ($suffix === '_updateremote') {
+ $newkey = 'field_updateremote_' . $field;
+ } elseif ($suffix === '_updatelocal') {
+ $newkey = 'field_updatelocal_' . $field;
+ $newval = ($newval==1) ? 'onlogin' : 'oncreate'; // translate 0/1 to locked/unlocked
+ }
+
+ if (!(set_config($newkey, $newval, 'auth/'.$CFG->auth)
+ && delete_records('config', 'name', $key))) {
+ notify("Error updating Auth configuration $key to {$CFG->auth} $newkey .");
+ $result = false;
+ }
+ } // end if isset key
+ } // end foreach suffix
+ } // end foreach field
+ }
+ }
+
+
+
return $result;
}
diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php
index b8b8a108672..8c9b4ae648d 100644
--- a/lib/db/postgres7.php
+++ b/lib/db/postgres7.php
@@ -1105,6 +1105,50 @@ function main_upgrade($oldversion=0) {
}
+ if ($oldversion < 2005060200) { // migrate some config items to config_plugins table
+
+ // NOTE: this block is in both postgres AND mysql upgrade
+ // files. If you edit either, update the otherone.
+ $user_fields = array("firstname", "lastname", "email",
+ "phone1", "phone2", "department",
+ "address", "city", "country",
+ "description", "idnumber", "lang");
+ if (!empty($CFG->auth)) { // if we have no auth, just pass
+ foreach ($user_fields as $field) {
+ $suffixes = array('', '_editlock', '_updateremote', '_updatelocal');
+ foreach ($suffixes as $suffix) {
+ $key = 'auth_user_' . $field . $suffix;
+ if (isset($CFG->$key)) {
+
+ // translate keys & values
+ // to the new convention
+ // this should support upgrading
+ // even 1.5dev installs
+ $newkey = $key;
+ $newval = $CFG->$key;
+ if ($suffix === '') {
+ $newkey = 'field_map_' . $field;
+ } elseif ($suffix === '_editlock') {
+ $newkey = 'field_lock_' . $field;
+ $newval = ($newval==1) ? 'locked' : 'unlocked'; // translate 0/1 to locked/unlocked
+ } elseif ($suffix === '_updateremote') {
+ $newkey = 'field_updateremote_' . $field;
+ } elseif ($suffix === '_updatelocal') {
+ $newkey = 'field_updatelocal_' . $field;
+ $newval = ($newval==1) ? 'onlogin' : 'oncreate'; // translate 0/1 to locked/unlocked
+ }
+
+ if (!(set_config($newkey, $newval, 'auth/'.$CFG->auth)
+ && delete_records('config', 'name', $key))) {
+ notify("Error updating Auth configuration $key to {$CFG->auth} $newkey .");
+ $result = false;
+ }
+ } // end if isset key
+ } // end foreach suffix
+ } // end foreach field
+ }
+ }
+
return $result;
}
diff --git a/lib/moodlelib.php b/lib/moodlelib.php
index 53fbd974f97..472021171f5 100644
--- a/lib/moodlelib.php
+++ b/lib/moodlelib.php
@@ -387,29 +387,108 @@ 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;
+ } else {
+ // preserve $CFG if DB returns nothing or error
+ return $CFG;
+ }
+
+ }
+}
+
+
/**
* 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/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 '