|
@@ -1,304 +1,231 @@
|
|
|
-<?php
|
|
|
-
|
|
|
-==============================================================================
|
|
|
- Dokeos - elearning and course management software
|
|
|
-
|
|
|
- Copyright (c) 2004 Dokeos SPRL
|
|
|
- Copyright (c) 2003 Ghent University (UGent)
|
|
|
- Copyright (c) 2001 Universite catholique de Louvain (UCL)
|
|
|
- Copyright (c) Universite Jean Monnet de Saint Etienne
|
|
|
- Copyright (c) Roan Embrechts (Vrije Universiteit Brussel)
|
|
|
-
|
|
|
- For a full list of contributors, see "credits.txt".
|
|
|
- The full license can be read in "license.txt".
|
|
|
-
|
|
|
- This program is free software; you can redistribute it and/or
|
|
|
- modify it under the terms of the GNU General Public License
|
|
|
- as published by the Free Software Foundation; either version 2
|
|
|
- of the License, or (at your option) any later version.
|
|
|
-
|
|
|
- See the GNU General Public License for more details.
|
|
|
-
|
|
|
- Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
|
|
|
- Mail: info@dokeos.com
|
|
|
-==============================================================================
|
|
|
-*/
|
|
|
+<?php
|
|
|
+
|
|
|
|
|
|
-=======================================================================
|
|
|
-* LDAP module functions
|
|
|
+* LDAP module functions
|
|
|
*
|
|
|
-* If the application uses LDAP, these functions are used
|
|
|
-* for logging in, searching user info, adding this info
|
|
|
-* to the Dokeos database...
|
|
|
-=======================================================================
|
|
|
- - function ldap_authentication_check()
|
|
|
- - function ldap_find_user_info()
|
|
|
- - function ldap_login()
|
|
|
- - function ldap_put_user_info_locally()
|
|
|
- - ldap_set_version()
|
|
|
-
|
|
|
- known bugs
|
|
|
- ----------
|
|
|
- - (fixed 18 june 2003) code has been internationalized
|
|
|
- - (fixed 07/05/2003) fixed some non-relative urls or includes
|
|
|
- - (fixed 28/04/2003) we now use global config.inc variables instead of local ones
|
|
|
- - (fixed 22/04/2003) the last name of a user was restricted to the first part
|
|
|
- - (fixed 11/04/2003) the user was never registered as a course manager
|
|
|
-
|
|
|
- version history
|
|
|
- ---------------
|
|
|
- 3.2 - updated to allow for specific term search for teachers identification
|
|
|
- 3.1 - updated code to use database settings, to respect coding conventions as much as possible (camel-case removed) and to allow for non-anonymous login
|
|
|
- 3.0 - updated to use ldap_var.inc.php instead of ldap_var.inc (deprecated)
|
|
|
- (November 2003)
|
|
|
- 2.9 - further changes for new login procedure
|
|
|
- - (busy) translating french functions to english
|
|
|
- (October 2003)
|
|
|
- 2.8 - adapted for new Claroline login procedure
|
|
|
- - ldap package now becomes a standard, in auth/ldap
|
|
|
- 2.7 - uses more standard LDAP field names: mail, sn, givenname
|
|
|
- instead of mail, preferredsn, preferredgivenname
|
|
|
- there are still
|
|
|
- - code cleanup
|
|
|
- - fixed bug: dc = xx, dc = yy was configured for UGent
|
|
|
- and put literally in the code, this is now a variable
|
|
|
- in configuration.php ($LDAPbasedn)
|
|
|
-
|
|
|
- with thanks to
|
|
|
- - Stefan De Wannemacker (Ghent University)
|
|
|
- - Universite Jean Monet (J Dubois / Michel Courbon)
|
|
|
- - Michel Panckoucke for reporting and fixing a bug
|
|
|
- - Patrick Cool: fixing security hole
|
|
|
-
|
|
|
- * @author Roan Embrechts
|
|
|
- * @version 3.0
|
|
|
- * @package dokeos.auth.ldap
|
|
|
-=======================================================================
|
|
|
+* If the application uses LDAP, these functions are used
|
|
|
+* for logging in, searching user info, adding this info
|
|
|
+* to the Chamilo database...
|
|
|
+ - function ldap_authentication_check()
|
|
|
+ - function ldap_find_user_info()
|
|
|
+ - function ldap_login()
|
|
|
+ - function ldap_put_user_info_locally()
|
|
|
+ - ldap_set_version()
|
|
|
+
|
|
|
+ known bugs
|
|
|
+ ----------
|
|
|
+ - (fixed 18 june 2003) code has been internationalized
|
|
|
+ - (fixed 07/05/2003) fixed some non-relative urls or includes
|
|
|
+ - (fixed 28/04/2003) we now use global config.inc variables instead of local ones
|
|
|
+ - (fixed 22/04/2003) the last name of a user was restricted to the first part
|
|
|
+ - (fixed 11/04/2003) the user was never registered as a course manager
|
|
|
+
|
|
|
+ version history
|
|
|
+ ---------------
|
|
|
+ This historial has been discontinued. Please use the Mercurial logs for more
|
|
|
+ 3.2 - updated to allow for specific term search for teachers identification
|
|
|
+ 3.1 - updated code to use database settings, to respect coding conventions as much as possible (camel-case removed) and to allow for non-anonymous login
|
|
|
+ 3.0 - updated to use ldap_var.inc.php instead of ldap_var.inc (deprecated)
|
|
|
+ (November 2003)
|
|
|
+ 2.9 - further changes for new login procedure
|
|
|
+ - (busy) translating french functions to english
|
|
|
+ (October 2003)
|
|
|
+ 2.8 - adapted for new Claroline login procedure
|
|
|
+ - ldap package now becomes a standard, in auth/ldap
|
|
|
+ 2.7 - uses more standard LDAP field names: mail, sn, givenname
|
|
|
+ instead of mail, preferredsn, preferredgivenname
|
|
|
+ there are still
|
|
|
+ - code cleanup
|
|
|
+ - fixed bug: dc = xx, dc = yy was configured for UGent
|
|
|
+ and put literally in the code, this is now a variable
|
|
|
+ in configuration.php ($LDAPbasedn)
|
|
|
+
|
|
|
+ with thanks to
|
|
|
+ - Stefan De Wannemacker (Ghent University)
|
|
|
+ - Universite Jean Monet (J Dubois / Michel Courbon)
|
|
|
+ - Michel Panckoucke for reporting and fixing a bug
|
|
|
+ - Patrick Cool: fixing security hole
|
|
|
+
|
|
|
+ * @author Roan Embrechts
|
|
|
+ * @version 3.0
|
|
|
+ * @package chamilo.auth.ldap
|
|
|
*/
|
|
|
|
|
|
require('ldap_var.inc.php');
|
|
|
|
|
|
|
|
|
-===============================================================
|
|
|
- function
|
|
|
- CHECK LOGIN & PASSWORD WITH LDAP
|
|
|
-* @return true when login & password both OK, false otherwise
|
|
|
-===============================================================
|
|
|
-* @author Roan Embrechts (based on code from Universit� Jean Monet)
|
|
|
-*/
|
|
|
-
|
|
|
-
|
|
|
-function ldap_login($login, $password)
|
|
|
-{
|
|
|
-
|
|
|
- $res = ldap_authentication_check($login, $password);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if ($res==1)
|
|
|
- {
|
|
|
-
|
|
|
- if (isset($log)) unset($log); if (isset($uid)) unset($uid);
|
|
|
- $loginLdapSucces = false;
|
|
|
- }
|
|
|
- if ($res==-1)
|
|
|
- {
|
|
|
-
|
|
|
- $login_ldap_success = false;
|
|
|
- }
|
|
|
- if ($res==0)
|
|
|
- {
|
|
|
-
|
|
|
- $login_ldap_success = true;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- $result = $login_ldap_success;
|
|
|
- return $result;
|
|
|
-}
|
|
|
+ * Check login and password with LDAP
|
|
|
+ * @return true when login & password both OK, false otherwise
|
|
|
+ * @author Roan Embrechts (based on code from Universit� Jean Monet)
|
|
|
+ */
|
|
|
|
|
|
+function ldap_login($login, $password) {
|
|
|
+
|
|
|
+ $res = ldap_authentication_check($login, $password);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if ($res==1) {
|
|
|
+
|
|
|
+ if (isset($log)) unset($log); if (isset($uid)) unset($uid);
|
|
|
+ $loginLdapSucces = false;
|
|
|
+ }
|
|
|
+ if ($res==-1) {
|
|
|
+
|
|
|
+ $login_ldap_success = false;
|
|
|
+ }
|
|
|
+ if ($res==0) {
|
|
|
+
|
|
|
+ $login_ldap_success = true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $result = $login_ldap_success;
|
|
|
+ return $result;
|
|
|
+}
|
|
|
|
|
|
|
|
|
-===============================================================
|
|
|
- function
|
|
|
- FIND USER INFO IN LDAP
|
|
|
-* @return an array with positions "firstname", "name", "email", "employeenumber"
|
|
|
-===============================================================
|
|
|
-* @author Stefan De Wannemacker
|
|
|
-* @author Roan Embrechts
|
|
|
-*/
|
|
|
-function ldap_find_user_info ($login)
|
|
|
-{
|
|
|
-
|
|
|
- global $ldap_host, $ldap_port, $ldap_basedn, $ldap_rdn, $ldap_pass, $ldap_search_dn;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $ldap_connect = ldap_connect( $ldap_host, $ldap_port);
|
|
|
- ldap_set_version($ldap_connect);
|
|
|
- if ($ldap_connect) {
|
|
|
-
|
|
|
-
|
|
|
- $ldap_bind = false;
|
|
|
- $ldap_bind_res = ldap_handle_bind($ldap_connect,$ldap_bind);
|
|
|
- if ($ldap_bind_res)
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if(!empty($ldap_search_dn))
|
|
|
- {
|
|
|
- $sr=ldap_search($ldap_connect, $ldap_search_dn, "uid=$login");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- $sr=ldap_search($ldap_connect, $ldap_basedn, "uid=$login");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $info = ldap_get_entries($ldap_connect, $sr);
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- ldap_close($ldap_connect);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- $result["firstname"] = $info[0]["givenname"][0];
|
|
|
- $result["name"] = $info[0]["sn"][0];
|
|
|
- $result["email"] = $info[0]["mail"][0];
|
|
|
- $tutor_field = api_get_setting('ldap_filled_tutor_field');
|
|
|
- $result[$tutor_field] = $info[0][$tutor_field];
|
|
|
-
|
|
|
- return $result;
|
|
|
+ * Find user info in LDAP
|
|
|
+ * @return array Array with indexes: "firstname", "name", "email", "employeenumber"
|
|
|
+ * @author Stefan De Wannemacker
|
|
|
+ * @author Roan Embrechts
|
|
|
+ */
|
|
|
+function ldap_find_user_info ($login) {
|
|
|
+
|
|
|
+ global $ldap_host, $ldap_port, $ldap_basedn, $ldap_rdn, $ldap_pass, $ldap_search_dn;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $ldap_connect = ldap_connect( $ldap_host, $ldap_port);
|
|
|
+ ldap_set_version($ldap_connect);
|
|
|
+ if ($ldap_connect) {
|
|
|
+
|
|
|
+
|
|
|
+ $ldap_bind = false;
|
|
|
+ $ldap_bind_res = ldap_handle_bind($ldap_connect,$ldap_bind);
|
|
|
+ if ($ldap_bind_res) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if(!empty($ldap_search_dn)) {
|
|
|
+ $sr=ldap_search($ldap_connect, $ldap_search_dn, "uid=$login");
|
|
|
+ } else {
|
|
|
+ $sr=ldap_search($ldap_connect, $ldap_basedn, "uid=$login");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $info = ldap_get_entries($ldap_connect, $sr);
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ ldap_close($ldap_connect);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ $result["firstname"] = $info[0]["givenname"][0];
|
|
|
+ $result["name"] = $info[0]["sn"][0];
|
|
|
+ $result["email"] = $info[0]["mail"][0];
|
|
|
+ $tutor_field = api_get_setting('ldap_filled_tutor_field');
|
|
|
+ $result[$tutor_field] = $info[0][$tutor_field];
|
|
|
+
|
|
|
+ return $result;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-* This function uses the data from ldap_find_user_info()
|
|
|
-* to add the userdata to Dokeos
|
|
|
-*
|
|
|
-* "firstname", "name", "email", "isEmployee"
|
|
|
-===============================================================
|
|
|
-* @author Roan Embrechts
|
|
|
+* This function uses the data from ldap_find_user_info()
|
|
|
+* to add the userdata to Chamilo
|
|
|
+* "firstname", "name", "email", "isEmployee"
|
|
|
+* @author Roan Embrechts
|
|
|
*/
|
|
|
-function ldap_put_user_info_locally($login, $info_array)
|
|
|
-{
|
|
|
-
|
|
|
- global $ldap_pass_placeholder;
|
|
|
- global $submitRegistration, $submit, $uname, $email,
|
|
|
- $nom, $prenom, $password, $password1, $status;
|
|
|
- global $platformLanguage;
|
|
|
- global $loginFailed, $uidReset, $_user;
|
|
|
-
|
|
|
-
|
|
|
- 1. set the necessary variables
|
|
|
- ------------------------------------------------------------ */
|
|
|
-
|
|
|
- $uname = $login;
|
|
|
- $email = $info_array["email"];
|
|
|
- $nom = $info_array["name"];
|
|
|
- $prenom = $info_array["firstname"];
|
|
|
- $password = $ldap_pass_placeholder;
|
|
|
- $password1 = $ldap_pass_placeholder;
|
|
|
- $official_code = '';
|
|
|
-
|
|
|
- define ("STUDENT",5);
|
|
|
- define ("COURSEMANAGER",1);
|
|
|
-
|
|
|
- $tutor_field = api_get_setting('ldap_filled_tutor_field');
|
|
|
- $tutor_value = api_get_setting('ldap_filled_tutor_field_value');
|
|
|
- if(empty($tutor_field))
|
|
|
- {
|
|
|
- $status = STUDENT;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if(empty($tutor_value))
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
- if(!empty($info_array[$tutor_field]))
|
|
|
- {
|
|
|
- $status = COURSEMANAGER;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- $status = STUDENT;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- if (is_array($info_array[$tutor_field]) && in_array($tutor_value,$info_array[$tutor_field]))
|
|
|
- {
|
|
|
- $status = COURSEMANAGER;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- $status = STUDENT;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- 2. add info to Dokeos
|
|
|
- ------------------------------------------------------------ */
|
|
|
-
|
|
|
- require_once(api_get_path(LIBRARY_PATH).'usermanager.lib.php');
|
|
|
- $_userId = UserManager::create_user($prenom, $nom, $status,
|
|
|
- $email, $uname, $password, $official_code,
|
|
|
- 'english','', '', 'ldap');
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- 3. register session
|
|
|
- ------------------------------------------------------------ */
|
|
|
-
|
|
|
- $uData['user_id'] = $_userId;
|
|
|
- $uData['username'] = $uname;
|
|
|
- $uData['auth_source'] = "ldap";
|
|
|
-
|
|
|
- $loginFailed = false;
|
|
|
- $uidReset = true;
|
|
|
- $_user['user_id'] = $uData['user_id'];
|
|
|
- api_session_register('_uid');
|
|
|
+function ldap_put_user_info_locally($login, $info_array) {
|
|
|
+
|
|
|
+ global $ldap_pass_placeholder;
|
|
|
+ global $submitRegistration, $submit, $uname, $email,
|
|
|
+ $nom, $prenom, $password, $password1, $status;
|
|
|
+ global $platformLanguage;
|
|
|
+ global $loginFailed, $uidReset, $_user;
|
|
|
+
|
|
|
+
|
|
|
+ 1. set the necessary variables
|
|
|
+ ------------------------------------------------------------ */
|
|
|
+ $uname = $login;
|
|
|
+ $email = $info_array["email"];
|
|
|
+ $nom = $info_array["name"];
|
|
|
+ $prenom = $info_array["firstname"];
|
|
|
+ $password = $ldap_pass_placeholder;
|
|
|
+ $password1 = $ldap_pass_placeholder;
|
|
|
+ $official_code = '';
|
|
|
+
|
|
|
+ define ("STUDENT",5);
|
|
|
+ define ("COURSEMANAGER",1);
|
|
|
+
|
|
|
+ $tutor_field = api_get_setting('ldap_filled_tutor_field');
|
|
|
+ $tutor_value = api_get_setting('ldap_filled_tutor_field_value');
|
|
|
+ if(empty($tutor_field)) {
|
|
|
+ $status = STUDENT;
|
|
|
+ } else {
|
|
|
+ if(empty($tutor_value)) {
|
|
|
+
|
|
|
+
|
|
|
+ if(!empty($info_array[$tutor_field])) {
|
|
|
+ $status = COURSEMANAGER;
|
|
|
+ } else {
|
|
|
+ $status = STUDENT;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if (is_array($info_array[$tutor_field]) && in_array($tutor_value,$info_array[$tutor_field])) {
|
|
|
+ $status = COURSEMANAGER;
|
|
|
+ } else {
|
|
|
+ $status = STUDENT;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 2. add info to Chamilo
|
|
|
+ ------------------------------------------------------------ */
|
|
|
+
|
|
|
+ require_once(api_get_path(LIBRARY_PATH).'usermanager.lib.php');
|
|
|
+ $_userId = UserManager::create_user($prenom, $nom, $status,
|
|
|
+ $email, $uname, $password, $official_code,
|
|
|
+ 'english','', '', 'ldap');
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 3. register session
|
|
|
+ ------------------------------------------------------------ */
|
|
|
+
|
|
|
+ $uData['user_id'] = $_userId;
|
|
|
+ $uData['username'] = $uname;
|
|
|
+ $uData['auth_source'] = "ldap";
|
|
|
+
|
|
|
+ $loginFailed = false;
|
|
|
+ $uidReset = true;
|
|
|
+ $_user['user_id'] = $uData['user_id'];
|
|
|
+ api_session_register('_uid');
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
-===========================================================
|
|
|
- The code of UGent uses these functions to authenticate.
|
|
|
- * function AuthVerifEnseignant ($uname, $passwd)
|
|
|
- * function AuthVerifEtudiant ($uname, $passwd)
|
|
|
- * function Authentif ($uname, $passwd)
|
|
|
-===========================================================
|
|
|
- To Do
|
|
|
- * translate the comments and code to english
|
|
|
- * let these functions use the variables in config.inc instead of ldap_var.inc
|
|
|
+* The code of UGent uses these functions to authenticate.
|
|
|
+* function AuthVerifEnseignant ($uname, $passwd)
|
|
|
+* function AuthVerifEtudiant ($uname, $passwd)
|
|
|
+* function Authentif ($uname, $passwd)
|
|
|
+* @todo translate the comments and code to english
|
|
|
+* @todo let these functions use the variables in config.inc instead of ldap_var.inc
|
|
|
*/
|
|
|
|
|
|
|
|
@@ -312,249 +239,215 @@ function ldap_put_user_info_locally($login, $info_array)
|
|
|
|
|
|
|
|
|
|
|
|
-function ldap_authentication_check ($uname, $passwd)
|
|
|
-{
|
|
|
-
|
|
|
- global $ldap_host, $ldap_port, $ldap_basedn, $ldap_host2, $ldap_port2,$ldap_rdn,$ldap_pass;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $ds=ldap_connect($ldap_host,$ldap_port);
|
|
|
- ldap_set_version($ds);
|
|
|
-
|
|
|
- $test_bind = false;
|
|
|
- $test_bind_res = ldap_handle_bind($ds,$test_bind);
|
|
|
-
|
|
|
- if($test_bind_res===false){
|
|
|
- $ds=ldap_connect($ldap_host2,$ldap_port2);
|
|
|
- ldap_set_version($ds);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
- if ($ds!==false) {
|
|
|
-
|
|
|
- $filter="(uid=$uname)";
|
|
|
-
|
|
|
-
|
|
|
- $result=false;
|
|
|
- $ldap_bind_res = ldap_handle_bind($ds,$result);
|
|
|
-
|
|
|
-
|
|
|
- $sr=ldap_search($ds,$ldap_basedn,$filter);
|
|
|
-
|
|
|
- $info = ldap_get_entries($ds, $sr);
|
|
|
- $dn=($info[0]["dn"]);
|
|
|
-
|
|
|
-
|
|
|
- ldap_close($ds);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if ($dn==""){
|
|
|
- return (-1);
|
|
|
- }
|
|
|
-
|
|
|
- if ($passwd=="") {
|
|
|
- return(1);
|
|
|
- }
|
|
|
-
|
|
|
- $ds=ldap_connect($ldap_host,$ldap_port);
|
|
|
- ldap_set_version($ds);
|
|
|
- if(!$test_bind){
|
|
|
- $ds=ldap_connect($ldap_host2,$ldap_port2);
|
|
|
- ldap_set_version($ds);
|
|
|
- }
|
|
|
-
|
|
|
- if (@ldap_bind( $ds, $dn , $passwd) === false) {
|
|
|
- return (1);
|
|
|
- }
|
|
|
-
|
|
|
- else
|
|
|
- {
|
|
|
- return (0);
|
|
|
- }
|
|
|
+function ldap_authentication_check ($uname, $passwd) {
|
|
|
+
|
|
|
+ global $ldap_host, $ldap_port, $ldap_basedn, $ldap_host2, $ldap_port2,$ldap_rdn,$ldap_pass;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $ds=ldap_connect($ldap_host,$ldap_port);
|
|
|
+ ldap_set_version($ds);
|
|
|
+
|
|
|
+ $test_bind = false;
|
|
|
+ $test_bind_res = ldap_handle_bind($ds,$test_bind);
|
|
|
+
|
|
|
+ if ($test_bind_res===false) {
|
|
|
+ $ds=ldap_connect($ldap_host2,$ldap_port2);
|
|
|
+ ldap_set_version($ds);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ if ($ds!==false) {
|
|
|
+
|
|
|
+ $filter="(uid=$uname)";
|
|
|
+
|
|
|
+
|
|
|
+ $result=false;
|
|
|
+ $ldap_bind_res = ldap_handle_bind($ds,$result);
|
|
|
+
|
|
|
+
|
|
|
+ $sr=ldap_search($ds,$ldap_basedn,$filter);
|
|
|
+
|
|
|
+ $info = ldap_get_entries($ds, $sr);
|
|
|
+ $dn=($info[0]["dn"]);
|
|
|
+
|
|
|
+
|
|
|
+ ldap_close($ds);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if ($dn=="") {
|
|
|
+ return (-1);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($passwd=="") {
|
|
|
+ return(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ $ds=ldap_connect($ldap_host,$ldap_port);
|
|
|
+ ldap_set_version($ds);
|
|
|
+ if (!$test_bind) {
|
|
|
+ $ds=ldap_connect($ldap_host2,$ldap_port2);
|
|
|
+ ldap_set_version($ds);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (@ldap_bind( $ds, $dn , $passwd) === false) {
|
|
|
+ return (1);
|
|
|
+ } else {
|
|
|
+ return (0);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
* Set the protocol version with version from config file (enables LDAP version 3)
|
|
|
- * @param resource The LDAP connexion resource, passed by reference.
|
|
|
- * @return void
|
|
|
+ * @param resource The LDAP connexion resource, passed by reference.
|
|
|
+ * @return void
|
|
|
*/
|
|
|
-function ldap_set_version(&$resource)
|
|
|
-{
|
|
|
-
|
|
|
- global $ldap_version;
|
|
|
- if($ldap_version>2)
|
|
|
- {
|
|
|
- if(ldap_set_option($resource, LDAP_OPT_PROTOCOL_VERSION, 3))
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
+function ldap_set_version(&$resource) {
|
|
|
+
|
|
|
+ global $ldap_version;
|
|
|
+ if ($ldap_version>2) {
|
|
|
+ if (ldap_set_option($resource, LDAP_OPT_PROTOCOL_VERSION, 3)) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
* Handle bind (whether authenticated or not)
|
|
|
- * @param resource The LDAP handler to which we are connecting (by reference)
|
|
|
- * @param resource The LDAP bind handler we will be modifying
|
|
|
- * @return boolean Status of the bind assignment. True for success, false for failure.
|
|
|
+ * @param resource The LDAP handler to which we are connecting (by reference)
|
|
|
+ * @param resource The LDAP bind handler we will be modifying
|
|
|
+ * @return boolean Status of the bind assignment. True for success, false for failure.
|
|
|
*/
|
|
|
-function ldap_handle_bind(&$ldap_handler,&$ldap_bind)
|
|
|
-{
|
|
|
-
|
|
|
- global $ldap_rdn,$ldap_pass;
|
|
|
- if(!empty($ldap_rdn) and !empty($ldap_pass))
|
|
|
- {
|
|
|
-
|
|
|
- $ldap_bind = ldap_bind($ldap_handler,$ldap_rdn,$ldap_pass);
|
|
|
- if(!$ldap_bind)
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
- $ldap_bind = ldap_bind($ldap_handler);
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- $ldap_bind = ldap_bind($ldap_handler);
|
|
|
- }
|
|
|
- if(!$ldap_bind)
|
|
|
- {
|
|
|
- return false;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- return true;
|
|
|
- }
|
|
|
+function ldap_handle_bind(&$ldap_handler,&$ldap_bind) {
|
|
|
+
|
|
|
+ global $ldap_rdn,$ldap_pass;
|
|
|
+ if (!empty($ldap_rdn) and !empty($ldap_pass)) {
|
|
|
+
|
|
|
+ $ldap_bind = ldap_bind($ldap_handler,$ldap_rdn,$ldap_pass);
|
|
|
+ if (!$ldap_bind) {
|
|
|
+
|
|
|
+
|
|
|
+ $ldap_bind = ldap_bind($ldap_handler);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ $ldap_bind = ldap_bind($ldap_handler);
|
|
|
+ }
|
|
|
+ if (!$ldap_bind) {
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
* Get the total number of users on the platform
|
|
|
* @see SortableTable
|
|
|
- * @author Mustapha Alouani
|
|
|
+ * @author Mustapha Alouani
|
|
|
*/
|
|
|
-function ldap_get_users()
|
|
|
-{
|
|
|
-
|
|
|
- global $ldap_basedn, $ldap_host, $ldap_port, $ldap_rdn, $ldap_pass;
|
|
|
-
|
|
|
- $keyword_firstname = trim(Database::escape_string($_GET['keyword_firstname']));
|
|
|
- $keyword_lastname = trim(Database::escape_string($_GET['keyword_lastname']));
|
|
|
- $keyword_username = trim(Database::escape_string($_GET['keyword_username']));
|
|
|
- $keyword_type = Database::escape_string($_GET['keyword_type']);
|
|
|
-
|
|
|
- $ldap_query=array();
|
|
|
-
|
|
|
- if ($keyword_username != "") {
|
|
|
- $ldap_query[]="(uid=".$keyword_username."*)";
|
|
|
- } else if ($keyword_lastname!=""){
|
|
|
- $ldap_query[]="(sn=".$keyword_lastname."*)";
|
|
|
- if ($keyword_firstname!="") {
|
|
|
- $ldap_query[]="(givenName=".$keyword_firstname."*)";
|
|
|
- }
|
|
|
- }
|
|
|
- if ($keyword_type !="" && $keyword_type !="all") {
|
|
|
- $ldap_query[]="(employeeType=".$keyword_type.")";
|
|
|
- }
|
|
|
-
|
|
|
- if (count($ldap_query)>1){
|
|
|
- $str_query.="(& ";
|
|
|
- foreach ($ldap_query as $query){
|
|
|
- $str_query.=" $query";
|
|
|
- }
|
|
|
- $str_query.=" )";
|
|
|
- } else {
|
|
|
- $str_query=$ldap_query[0];
|
|
|
- }
|
|
|
-
|
|
|
- $ds = ldap_connect($ldap_host, $ldap_port);
|
|
|
- ldap_set_version($ds);
|
|
|
- if ($ds && count($ldap_query)>0) {
|
|
|
- $r = false;
|
|
|
- $res = ldap_handle_bind($ds, $r);
|
|
|
-
|
|
|
- $sr = ldap_search($ds, $ldap_basedn, $str_query);
|
|
|
-
|
|
|
- $info = ldap_get_entries($ds, $sr);
|
|
|
- return $info;
|
|
|
-
|
|
|
- } else {
|
|
|
- if (count($ldap_query)!=0)
|
|
|
- Display :: display_error_message(get_lang('LDAPConnectionError'));
|
|
|
- return array();
|
|
|
- }
|
|
|
+function ldap_get_users() {
|
|
|
+
|
|
|
+ global $ldap_basedn, $ldap_host, $ldap_port, $ldap_rdn, $ldap_pass;
|
|
|
+
|
|
|
+ $keyword_firstname = trim(Database::escape_string($_GET['keyword_firstname']));
|
|
|
+ $keyword_lastname = trim(Database::escape_string($_GET['keyword_lastname']));
|
|
|
+ $keyword_username = trim(Database::escape_string($_GET['keyword_username']));
|
|
|
+ $keyword_type = Database::escape_string($_GET['keyword_type']);
|
|
|
+
|
|
|
+ $ldap_query=array();
|
|
|
+
|
|
|
+ if ($keyword_username != "") {
|
|
|
+ $ldap_query[]="(uid=".$keyword_username."*)";
|
|
|
+ } else if ($keyword_lastname!=""){
|
|
|
+ $ldap_query[]="(sn=".$keyword_lastname."*)";
|
|
|
+ if ($keyword_firstname!="") {
|
|
|
+ $ldap_query[]="(givenName=".$keyword_firstname."*)";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($keyword_type !="" && $keyword_type !="all") {
|
|
|
+ $ldap_query[]="(employeeType=".$keyword_type.")";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (count($ldap_query)>1){
|
|
|
+ $str_query.="(& ";
|
|
|
+ foreach ($ldap_query as $query){
|
|
|
+ $str_query.=" $query";
|
|
|
+ }
|
|
|
+ $str_query.=" )";
|
|
|
+ } else {
|
|
|
+ $str_query=$ldap_query[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ $ds = ldap_connect($ldap_host, $ldap_port);
|
|
|
+ ldap_set_version($ds);
|
|
|
+ if ($ds && count($ldap_query)>0) {
|
|
|
+ $r = false;
|
|
|
+ $res = ldap_handle_bind($ds, $r);
|
|
|
+
|
|
|
+ $sr = ldap_search($ds, $ldap_basedn, $str_query);
|
|
|
+
|
|
|
+ $info = ldap_get_entries($ds, $sr);
|
|
|
+ return $info;
|
|
|
+
|
|
|
+ } else {
|
|
|
+ if (count($ldap_query)!=0)
|
|
|
+ Display :: display_error_message(get_lang('LDAPConnectionError'));
|
|
|
+ return array();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
|
|
|
* Get the total number of users on the platform
|
|
|
* @see SortableTable
|
|
|
- * @author Mustapha Alouani
|
|
|
+ * @author Mustapha Alouani
|
|
|
*/
|
|
|
-function ldap_get_number_of_users()
|
|
|
-{
|
|
|
-
|
|
|
- $info = ldap_get_users();
|
|
|
- if (count($info)>0)
|
|
|
- return $info['count'];
|
|
|
- else
|
|
|
- return 0;
|
|
|
-
|
|
|
+function ldap_get_number_of_users() {
|
|
|
+ $info = ldap_get_users();
|
|
|
+ if (count($info)>0) {
|
|
|
+ return $info['count'];
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
* Get the users to display on the current page.
|
|
|
* @see SortableTable
|
|
|
- * @author Mustapha Alouani
|
|
|
+ * @author Mustapha Alouani
|
|
|
*/
|
|
|
-function ldap_get_user_data($from, $number_of_items, $column, $direction)
|
|
|
-{
|
|
|
- $users = array();
|
|
|
- $is_western_name_order = api_is_western_name_order();
|
|
|
- if (isset($_GET['submit']))
|
|
|
- {
|
|
|
- $info = ldap_get_users();
|
|
|
- if ($info['count']>0)
|
|
|
- {
|
|
|
- for ($key = 0; $key < $info["count"]; $key ++)
|
|
|
- {
|
|
|
- $user=array();
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $user[] = $info[$key]['uid'][0];
|
|
|
- $user[] = $info[$key]['uid'][0];
|
|
|
- if ($is_western_name_order)
|
|
|
- {
|
|
|
- $user[] = api_convert_encoding($info[$key]['givenname'][0], api_get_system_encoding(), 'UTF-8');
|
|
|
- $user[] = api_convert_encoding($info[$key]['sn'][0], api_get_system_encoding(), 'UTF-8');
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- $user[] = api_convert_encoding($info[$key]['sn'][0], api_get_system_encoding(), 'UTF-8');
|
|
|
- $user[] = api_convert_encoding($info[$key]['givenname'][0], api_get_system_encoding(), 'UTF-8');
|
|
|
- }
|
|
|
- $user[] = $info[$key]['mail'][0];
|
|
|
- $outab[] = $info[$key]['eduPersonPrimaryAffiliation'][0];
|
|
|
- $users[] = $user;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- Display :: display_error_message(get_lang('NoUser'));
|
|
|
- }
|
|
|
- }
|
|
|
- return $users;
|
|
|
+function ldap_get_user_data($from, $number_of_items, $column, $direction) {
|
|
|
+ $users = array();
|
|
|
+ $is_western_name_order = api_is_western_name_order();
|
|
|
+ if (isset($_GET['submit'])) {
|
|
|
+ $info = ldap_get_users();
|
|
|
+ if ($info['count']>0) {
|
|
|
+ for ($key = 0; $key < $info["count"]; $key ++) {
|
|
|
+ $user=array();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $user[] = $info[$key]['uid'][0];
|
|
|
+ $user[] = $info[$key]['uid'][0];
|
|
|
+ if ($is_western_name_order) {
|
|
|
+ $user[] = api_convert_encoding($info[$key]['givenname'][0], api_get_system_encoding(), 'UTF-8');
|
|
|
+ $user[] = api_convert_encoding($info[$key]['sn'][0], api_get_system_encoding(), 'UTF-8');
|
|
|
+ } else {
|
|
|
+ $user[] = api_convert_encoding($info[$key]['sn'][0], api_get_system_encoding(), 'UTF-8');
|
|
|
+ $user[] = api_convert_encoding($info[$key]['givenname'][0], api_get_system_encoding(), 'UTF-8');
|
|
|
+ }
|
|
|
+ $user[] = $info[$key]['mail'][0];
|
|
|
+ $outab[] = $info[$key]['eduPersonPrimaryAffiliation'][0];
|
|
|
+ $users[] = $user;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Display :: display_error_message(get_lang('NoUser'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $users;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -562,139 +455,134 @@ function ldap_get_user_data($from, $number_of_items, $column, $direction)
|
|
|
* @param int $user_id The user id
|
|
|
* @param string $url_params
|
|
|
* @return string Some HTML-code with modify-buttons
|
|
|
- * @author Mustapha Alouani
|
|
|
+ * @author Mustapha Alouani
|
|
|
*/
|
|
|
-function modify_filter($user_id,$url_params, $row)
|
|
|
-{
|
|
|
- $url_params_id="id[]=".$row[0];
|
|
|
-
|
|
|
- $result .= '<a href="ldap_users_list.php?action=add_user&user_id='.$user_id.'&id_session='.Security::remove_XSS($_GET['id_session']).'&'.$url_params_id.'&sec_token='.$_SESSION['sec_token'].'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, api_get_system_encoding()))."'".')) return false;">'.Display::return_icon('add_user.gif', get_lang('AddUsers')).'</a>';
|
|
|
- return $result;
|
|
|
+function modify_filter($user_id,$url_params, $row) {
|
|
|
+ $url_params_id="id[]=".$row[0];
|
|
|
+
|
|
|
+ $result .= '<a href="ldap_users_list.php?action=add_user&user_id='.$user_id.'&id_session='.Security::remove_XSS($_GET['id_session']).'&'.$url_params_id.'&sec_token='.$_SESSION['sec_token'].'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, api_get_system_encoding()))."'".')) return false;">'.Display::return_icon('add_user.gif', get_lang('AddUsers')).'</a>';
|
|
|
+ return $result;
|
|
|
}
|
|
|
|
|
|
|
|
|
- * Adds a user to the Dokeos database or updates its data
|
|
|
- * @param string username (and uid inside LDAP)
|
|
|
- * @author Mustapha Alouani
|
|
|
+ * Adds a user to the Chamilo database or updates its data
|
|
|
+ * @param string username (and uid inside LDAP)
|
|
|
+ * @author Mustapha Alouani
|
|
|
*/
|
|
|
-function ldap_add_user($login)
|
|
|
-{
|
|
|
- global $ldap_basedn, $ldap_host, $ldap_port, $ldap_rdn, $ldap_pass;
|
|
|
-
|
|
|
- $ds = ldap_connect($ldap_host, $ldap_port);
|
|
|
- ldap_set_version($ds);
|
|
|
- if ($ds)
|
|
|
- {
|
|
|
- $str_query="(uid=".$login.")";
|
|
|
- $r = false;
|
|
|
- $res = ldap_handle_bind($ds, $r);
|
|
|
- $sr = ldap_search($ds, $ldap_basedn, $str_query);
|
|
|
-
|
|
|
- $info = ldap_get_entries($ds, $sr);
|
|
|
-
|
|
|
- for ($key = 0; $key < $info['count']; $key ++)
|
|
|
- {
|
|
|
- $lastname = api_convert_encoding($info[$key]['sn'][0], api_get_system_encoding(), 'UTF-8');
|
|
|
- $firstname = api_convert_encoding($info[$key]['givenname'][0], api_get_system_encoding(), 'UTF-8');
|
|
|
- $email = $info[$key]['mail'][0];
|
|
|
-
|
|
|
- $dn_array=ldap_explode_dn($info[$key]['dn'],1);
|
|
|
- $username = $dn_array[0];
|
|
|
- $outab[] = $info[$key]['edupersonprimaryaffiliation'][0];
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $password = $info[$key]['userPassword'][0];
|
|
|
- $structure=$info[$key]['edupersonprimaryorgunitdn'][0];
|
|
|
- $array_structure=explode(",", $structure);
|
|
|
- $array_val=explode("=", $array_structure[0]);
|
|
|
- $etape=$array_val[1];
|
|
|
- $array_val=explode("=", $array_structure[1]);
|
|
|
- $annee=$array_val[1];
|
|
|
-
|
|
|
- $official_code=$etape."-".$annee;
|
|
|
- $auth_source='ldap';
|
|
|
-
|
|
|
- $expiration_date='0000-00-00 00:00:00';
|
|
|
- $active=1;
|
|
|
- if(empty($status)){$status = 5;}
|
|
|
- if(empty($phone)){$phone = '';}
|
|
|
- if(empty($picture_uri)){$picture_uri = '';}
|
|
|
-
|
|
|
- if (UserManager::is_username_available($username))
|
|
|
- {
|
|
|
- $user_id = UserManager::create_user($firstname,$lastname,$status,$email,$username,$password,$official_code,api_get_setting('platformLanguage'),$phone,$picture_uri,$auth_source,$expiration_date,$active);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- $user = UserManager::get_user_info($username);
|
|
|
- $user_id=$user['user_id'];
|
|
|
- UserManager::update_user($user_id, $firstname, $lastname, $username, null, null, $email, $status, $official_code, $phone, $picture_uri, $expiration_date, $active);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- Display :: display_error_message(get_lang('LDAPConnectionError'));
|
|
|
- }
|
|
|
- return $user_id;;
|
|
|
+function ldap_add_user($login) {
|
|
|
+ global $ldap_basedn, $ldap_host, $ldap_port, $ldap_rdn, $ldap_pass;
|
|
|
+ $ds = ldap_connect($ldap_host, $ldap_port);
|
|
|
+ ldap_set_version($ds);
|
|
|
+ if ($ds) {
|
|
|
+ $str_query="(uid=".$login.")";
|
|
|
+ $r = false;
|
|
|
+ $res = ldap_handle_bind($ds, $r);
|
|
|
+ $sr = ldap_search($ds, $ldap_basedn, $str_query);
|
|
|
+
|
|
|
+ $info = ldap_get_entries($ds, $sr);
|
|
|
+
|
|
|
+ for ($key = 0; $key < $info['count']; $key ++) {
|
|
|
+ $lastname = api_convert_encoding($info[$key]['sn'][0], api_get_system_encoding(), 'UTF-8');
|
|
|
+ $firstname = api_convert_encoding($info[$key]['givenname'][0], api_get_system_encoding(), 'UTF-8');
|
|
|
+ $email = $info[$key]['mail'][0];
|
|
|
+
|
|
|
+ $dn_array=ldap_explode_dn($info[$key]['dn'],1);
|
|
|
+ $username = $dn_array[0];
|
|
|
+ $outab[] = $info[$key]['edupersonprimaryaffiliation'][0];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $password = $info[$key]['userPassword'][0];
|
|
|
+ $structure=$info[$key]['edupersonprimaryorgunitdn'][0];
|
|
|
+ $array_structure=explode(",", $structure);
|
|
|
+ $array_val=explode("=", $array_structure[0]);
|
|
|
+ $etape=$array_val[1];
|
|
|
+ $array_val=explode("=", $array_structure[1]);
|
|
|
+ $annee=$array_val[1];
|
|
|
+
|
|
|
+ $official_code=$etape."-".$annee;
|
|
|
+ $auth_source='ldap';
|
|
|
+
|
|
|
+ $expiration_date='0000-00-00 00:00:00';
|
|
|
+ $active=1;
|
|
|
+ if(empty($status)){$status = 5;}
|
|
|
+ if(empty($phone)){$phone = '';}
|
|
|
+ if(empty($picture_uri)){$picture_uri = '';}
|
|
|
+
|
|
|
+ if (UserManager::is_username_available($username)) {
|
|
|
+ $user_id = UserManager::create_user($firstname,$lastname,$status,$email,$username,$password,$official_code,api_get_setting('platformLanguage'),$phone,$picture_uri,$auth_source,$expiration_date,$active);
|
|
|
+ } else {
|
|
|
+ $user = UserManager::get_user_info($username);
|
|
|
+ $user_id=$user['user_id'];
|
|
|
+ UserManager::update_user($user_id, $firstname, $lastname, $username, null, null, $email, $status, $official_code, $phone, $picture_uri, $expiration_date, $active);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ Display :: display_error_message(get_lang('LDAPConnectionError'));
|
|
|
+ }
|
|
|
+ return $user_id;;
|
|
|
}
|
|
|
|
|
|
|
|
|
* Adds a list of users to one session
|
|
|
- * @param array Array of user ids
|
|
|
- * @param string Course code
|
|
|
- * @return void
|
|
|
+ * @param array Array of user ids
|
|
|
+ * @param string Course code
|
|
|
+ * @return void
|
|
|
*/
|
|
|
-function ldap_add_user_to_session($UserList, $id_session)
|
|
|
-{
|
|
|
-
|
|
|
-
|
|
|
- $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
|
|
|
- $tbl_session_rel_class = Database::get_main_table(TABLE_MAIN_SESSION_CLASS);
|
|
|
- $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
|
|
|
- $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
|
|
|
- $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
|
|
|
- $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
|
|
|
- $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
|
|
|
- $tbl_class = Database::get_main_table(TABLE_MAIN_CLASS);
|
|
|
- $tbl_class_user = Database::get_main_table(TABLE_MAIN_CLASS_USER);
|
|
|
-
|
|
|
- $id_session = (int) $id_session;
|
|
|
-
|
|
|
- $result=Database::query("SELECT course_code FROM $tbl_session_rel_course " .
|
|
|
- "WHERE id_session='$id_session'");
|
|
|
- $CourseList=array();
|
|
|
- while($row=Database::fetch_array($result))
|
|
|
- {
|
|
|
- $CourseList[]=$row['course_code'];
|
|
|
- }
|
|
|
- foreach($CourseList as $enreg_course)
|
|
|
- {
|
|
|
- foreach($UserList as $enreg_user)
|
|
|
- {
|
|
|
- $enreg_user = (int) $enreg_user;
|
|
|
- Database::query("INSERT IGNORE INTO $tbl_session_rel_course_rel_user(id_session,course_code,id_user) VALUES('$id_session','$enreg_course','$enreg_user')");
|
|
|
- }
|
|
|
- $sql = "SELECT COUNT(id_user) as nbUsers FROM $tbl_session_rel_course_rel_user " .
|
|
|
- "WHERE id_session='$id_session' AND course_code='$enreg_course'";
|
|
|
- $rs = Database::query($sql);
|
|
|
- list($nbr_users) = Database::fetch_array($rs);
|
|
|
- Database::query("UPDATE $tbl_session_rel_course SET nbr_users=$nbr_users " .
|
|
|
- "WHERE id_session='$id_session' AND course_code='$enreg_course'");
|
|
|
- }
|
|
|
- foreach($UserList as $enreg_user)
|
|
|
- {
|
|
|
- $enreg_user = (int) $enreg_user;
|
|
|
- Database::query("INSERT IGNORE INTO $tbl_session_rel_user(id_session, id_user) " .
|
|
|
- "VALUES('$id_session','$enreg_user')");
|
|
|
- }
|
|
|
-
|
|
|
- $sql = "SELECT COUNT(id_user) as nbUsers FROM $tbl_session_rel_user WHERE id_session='$id_session' AND relation_type<>".SESSION_RELATION_TYPE_RRHH." ";
|
|
|
- $rs = Database::query($sql);
|
|
|
- list($nbr_users) = Database::fetch_array($rs);
|
|
|
- Database::query("UPDATE $tbl_session SET nbr_users=$nbr_users WHERE id='$id_session'");
|
|
|
+function ldap_add_user_to_session($UserList, $id_session) {
|
|
|
+
|
|
|
+
|
|
|
+ $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
|
|
|
+ $tbl_session_rel_class = Database::get_main_table(TABLE_MAIN_SESSION_CLASS);
|
|
|
+ $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
|
|
|
+ $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
|
|
|
+ $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
|
|
|
+ $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
|
|
|
+ $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
|
|
|
+ $tbl_class = Database::get_main_table(TABLE_MAIN_CLASS);
|
|
|
+ $tbl_class_user = Database::get_main_table(TABLE_MAIN_CLASS_USER);
|
|
|
+
|
|
|
+ $id_session = (int) $id_session;
|
|
|
+
|
|
|
+ $result=Database::query("SELECT course_code FROM $tbl_session_rel_course " .
|
|
|
+ "WHERE id_session='$id_session'");
|
|
|
+ $CourseList=array();
|
|
|
+ while ($row=Database::fetch_array($result)) {
|
|
|
+ $CourseList[]=$row['course_code'];
|
|
|
+ }
|
|
|
+ foreach ($CourseList as $enreg_course) {
|
|
|
+ foreach ($UserList as $enreg_user) {
|
|
|
+ $enreg_user = (int) $enreg_user;
|
|
|
+ Database::query("INSERT IGNORE ".
|
|
|
+ " INTO $tbl_session_rel_course_rel_user ".
|
|
|
+ "(id_session,course_code,id_user) VALUES ".
|
|
|
+ "('$id_session','$enreg_course','$enreg_user')");
|
|
|
+ }
|
|
|
+ $sql = "SELECT COUNT(id_user) as nbUsers ".
|
|
|
+ " FROM $tbl_session_rel_course_rel_user " .
|
|
|
+ " WHERE id_session='$id_session' ".
|
|
|
+ " AND course_code='$enreg_course'";
|
|
|
+ $rs = Database::query($sql);
|
|
|
+ list($nbr_users) = Database::fetch_array($rs);
|
|
|
+ Database::query("UPDATE $tbl_session_rel_course ".
|
|
|
+ " SET nbr_users=$nbr_users " .
|
|
|
+ " WHERE id_session='$id_session' ".
|
|
|
+ " AND course_code='$enreg_course'");
|
|
|
+ }
|
|
|
+ foreach ($UserList as $enreg_user) {
|
|
|
+ $enreg_user = (int) $enreg_user;
|
|
|
+ Database::query("INSERT IGNORE INTO $tbl_session_rel_user ".
|
|
|
+ " (id_session, id_user) " .
|
|
|
+ " VALUES('$id_session','$enreg_user')");
|
|
|
+ }
|
|
|
+
|
|
|
+ $sql = "SELECT COUNT(id_user) as nbUsers FROM $tbl_session_rel_user ".
|
|
|
+ " WHERE id_session='$id_session' ".
|
|
|
+ " AND relation_type<>".SESSION_RELATION_TYPE_RRHH." ";
|
|
|
+ $rs = Database::query($sql);
|
|
|
+ list($nbr_users) = Database::fetch_array($rs);
|
|
|
+ Database::query("UPDATE $tbl_session SET nbr_users=$nbr_users ".
|
|
|
+ " WHERE id='$id_session'");
|
|
|
}
|
|
|
-?>
|