From 4105cafff9192b423428ded7fa416fe496591a1a Mon Sep 17 00:00:00 2001
From: dongsheng <dongsheng>
Date: Tue, 8 Apr 2008 05:53:12 +0000
Subject: [PATCH] MDL-12531, make the new member value available to all the
 affected plugins, thanks, Robert

---
 admin/auth_config.php    | 3 ++-
 auth/cas/auth.php        | 5 +----
 auth/db/auth.php         | 5 +----
 auth/ldap/auth.php       | 5 +----
 auth/shibboleth/auth.php | 9 ++-------
 lib/authlib.php          | 7 +++++++
 6 files changed, 14 insertions(+), 20 deletions(-)

diff --git a/admin/auth_config.php b/admin/auth_config.php
index d0bc55d763..3165e5fcc5 100644
--- a/admin/auth_config.php
+++ b/admin/auth_config.php
@@ -50,7 +50,8 @@ if ($frm = data_submitted() and confirm_sesskey()) {
     $frm = get_config("auth/$auth");
 }
 
-$user_fields = array("firstname", "lastname", "email", "phone1", "phone2", "institution", "department", "address", "city", "country", "description", "idnumber", "lang");
+$user_fields = $authplugin->userfields;
+//$user_fields = array("firstname", "lastname", "email", "phone1", "phone2", "institution", "department", "address", "city", "country", "description", "idnumber", "lang");
 
 /// Get the auth title (from core or own auth lang files)
     $authtitle = $authplugin->get_title();
diff --git a/auth/cas/auth.php b/auth/cas/auth.php
index f3d05e46e4..d849227770 100644
--- a/auth/cas/auth.php
+++ b/auth/cas/auth.php
@@ -487,11 +487,8 @@ if ( !is_object($PHPCAS_CLIENT) ) {
      * @return array
      */
     function ldap_attributes () {
-        $fields = array("firstname", "lastname", "email", "phone1", "phone2",
-                        "department", "address", "city", "country", "description",
-                        "idnumber", "lang" );
         $moodleattributes = array();
-        foreach ($fields as $field) {
+        foreach ($this->userfields as $field) {
             if (!empty($this->config->{"field_map_$field"})) {
                 $moodleattributes[$field] = $this->config->{"field_map_$field"};
                 if (preg_match('/,/',$moodleattributes[$field])) {
diff --git a/auth/db/auth.php b/auth/db/auth.php
index 32f2df1e3c..334437fe7c 100644
--- a/auth/db/auth.php
+++ b/auth/db/auth.php
@@ -132,11 +132,8 @@ class auth_plugin_db extends auth_plugin_base {
      * @return array
      */
     function db_attributes() {
-        $fields = array("firstname", "lastname", "email", "phone1", "phone2",
-                        "department", "address", "city", "country", "description",
-                        "idnumber", "lang" );
         $moodleattributes = array();
-        foreach ($fields as $field) {
+        foreach ($this->userfields as $field) {
             if (!empty($this->config->{"field_map_$field"})) {
                 $moodleattributes[$field] = $this->config->{"field_map_$field"};
             }
diff --git a/auth/ldap/auth.php b/auth/ldap/auth.php
index 868d950316..cd9aab84c1 100644
--- a/auth/ldap/auth.php
+++ b/auth/ldap/auth.php
@@ -1647,11 +1647,8 @@ class auth_plugin_ldap extends auth_plugin_base {
      */
 
     function ldap_attributes () {
-        $fields = array("firstname", "lastname", "email", "phone1", "phone2",
-                        "department", "address", "city", "country", "description",
-                        "idnumber", "lang" );
         $moodleattributes = array();
-        foreach ($fields as $field) {
+        foreach ($this->userfields as $field) {
             if (!empty($this->config->{"field_map_$field"})) {
                 $moodleattributes[$field] = $this->config->{"field_map_$field"};
                 if (preg_match('/,/',$moodleattributes[$field])) {
diff --git a/auth/shibboleth/auth.php b/auth/shibboleth/auth.php
index 05c69a2b31..22d850b4ca 100644
--- a/auth/shibboleth/auth.php
+++ b/auth/shibboleth/auth.php
@@ -76,7 +76,7 @@ class auth_plugin_shibboleth extends auth_plugin_base {
 
         // Check whether we have got all the essential attributes
         if ( empty($_SERVER[$this->config->user_attribute]) ) {
-            error(get_string( 'shib_not_all_attributes_error', 'auth' , "'".$this->config->user_attribute."' ('".$_SERVER[$this->config->user_attribute]."'), '".$this->config->field_map_firstname."' ('".$_SERVER[$this->config->field_map_firstname]."'), '".$this->config->field_map_lastname."' ('".$_SERVER[$this->config->field_map_lastname]."') and '".$this->config->field_map_email."' ('".$_SERVER[$this->config->field_map_email]."')"));
+            print_error( 'shib_not_all_attributes_error', 'auth' , '', "'".$this->config->user_attribute."' ('".$_SERVER[$this->config->user_attribute]."'), '".$this->config->field_map_firstname."' ('".$_SERVER[$this->config->field_map_firstname]."'), '".$this->config->field_map_lastname."' ('".$_SERVER[$this->config->field_map_lastname]."') and '".$this->config->field_map_email."' ('".$_SERVER[$this->config->field_map_email]."')");
         }
 
         $attrmap = $this->get_attributes();
@@ -122,13 +122,8 @@ class auth_plugin_shibboleth extends auth_plugin_base {
      */
     function get_attributes() {
         $configarray = (array) $this->config;
-
-        $fields = array("firstname", "lastname", "email", "phone1", "phone2",
-                        "department", "address", "city", "country", "description",
-                        "idnumber", "lang", "guid");
-
         $moodleattributes = array();
-        foreach ($fields as $field) {
+        foreach ($this->userfields as $field) {
             if (isset($configarray["field_map_$field"])) {
                 $moodleattributes[$field] = $configarray["field_map_$field"];
             }
diff --git a/lib/authlib.php b/lib/authlib.php
index a60a661378..8996a979cf 100644
--- a/lib/authlib.php
+++ b/lib/authlib.php
@@ -57,6 +57,13 @@ class auth_plugin_base {
      * Authentication plugin type - the same as db field.
      */
     var $authtype;
+    /*
+     * The fields we can lock and update from/to external authentication backends
+     *
+     */
+    var $userfields = array("firstname", "lastname", "email", "phone1", "phone2", 
+            "institution", "department", "address", "city", "country", 
+            "description", "idnumber", "lang");
 
     /**
 
-- 
2.39.5