[svn r14998] Fixed LDAP import of users into a course

General cleanup and security enhancements
skala
Yannick Warnier 17 years ago
parent 2095210452
commit 0b2ed5d91a
  1. 4
      main/admin/index.php
  2. 5
      main/admin/ldap_form_add_users_group.php
  3. 128
      main/admin/ldap_import_students.php
  4. 252
      main/admin/ldap_users_list.php

@ -1,4 +1,4 @@
<?php // $Id: index.php 14992 2008-04-21 20:24:31Z juliomontoya $ <?php // $Id: index.php 14998 2008-04-22 01:36:35Z yannoo $
/* /*
============================================================================== ==============================================================================
Dokeos - elearning and course management software Dokeos - elearning and course management software
@ -215,7 +215,7 @@ if(api_is_platform_admin()){
<div class="admin_section"> <div class="admin_section">
<h4><img src="../img/members.gif" border="0" style="vertical-align: middle;" alt="LDAP" />LDAP</h4> <h4><img src="../img/members.gif" border="0" style="vertical-align: middle;" alt="LDAP" />LDAP</h4>
<ul> <ul>
<!--li><a href="ldap_import_students.php"><?php echo get_lang('ImportLDAPUsersIntoCourse');?></a></li--> <li><a href="ldap_import_students.php"><?php echo get_lang('ImportLDAPUsersIntoCourse');?></a></li>
<!--li><a href="ldap_import_students_to_session.php"><?php echo get_lang('ImportLDAPUsersAndStepIntoSession');?></a></li--> <!--li><a href="ldap_import_students_to_session.php"><?php echo get_lang('ImportLDAPUsersAndStepIntoSession');?></a></li-->
<li><a href="ldap_users_list.php"><?php echo get_lang('AddLDAPUsers');?></a></li> <li><a href="ldap_users_list.php"><?php echo get_lang('AddLDAPUsers');?></a></li>
<!--li><a href="ldap_users_synchro.php"><?php echo get_lang('LDAPSynchroImportUsersAndStepsInSessions');?></a></li--> <!--li><a href="ldap_users_synchro.php"><?php echo get_lang('LDAPSynchroImportUsersAndStepsInSessions');?></a></li-->

@ -23,7 +23,7 @@
* This form is included by ldap_import_students.php * This form is included by ldap_import_students.php
*/ */
$nbre=0; $nbre=0;
echo '<form name="form" method="post" action="ldap_users_list.php">'; echo '<form name="form" method="post" action="ldap_import_students.php?annee='.Security::remove_XSS($annee).'">';
if($statut==1) if($statut==1)
{ {
echo get_lang('EmailNotifySubscription').': <input type="checkbox" name="mailling" value="1" checked="checked"><i>'.get_lang('DontUnchek').'</i>'; echo get_lang('EmailNotifySubscription').': <input type="checkbox" name="mailling" value="1" checked="checked"><i>'.get_lang('DontUnchek').'</i>';
@ -32,7 +32,8 @@ echo '<form name="form" method="post" action="ldap_users_list.php">';
{ {
echo '<input type="hidden" name="mailling" value="1">'; echo '<input type="hidden" name="mailling" value="1">';
} }
echo '<input type="hidden" name="course" value="'.Security::remove_XSS($course).'">';
echo '<input type="hidden" name="confirmed" value="yes">';
echo '<table border="0" cellspacing="0" width="100%">'; echo '<table border="0" cellspacing="0" width="100%">';
echo '<tr align="center" id="header3">' . echo '<tr align="center" id="header3">' .
'<td width="15%"><input type="button" value="'.get_lang('AllSlashNone').'" onClick="checkAll();"></td>' . '<td width="15%"><input type="button" value="'.get_lang('AllSlashNone').'" onClick="checkAll();"></td>' .

@ -22,11 +22,13 @@
// name of the language file that needs to be included // name of the language file that needs to be included
$language_file[]='admin'; $language_file[]='admin';
$language_file[]='registration'; $language_file[]='registration';
require_once('../inc/global.inc.php');
// resetting the course id // resetting the course id
$cidReset=true; $cidReset=true;
require_once('../inc/global.inc.php');
// setting the section (for the tabs) // setting the section (for the tabs)
$this_section = SECTION_PLATFORM_ADMIN; $this_section = SECTION_PLATFORM_ADMIN;
require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
require_once(api_get_path(LIBRARY_PATH).'usermanager.lib.php');
// Access restrictions // Access restrictions
api_protect_admin_script(); api_protect_admin_script();
require('../auth/ldap/authldap.php'); require('../auth/ldap/authldap.php');
@ -38,50 +40,55 @@ $tool_name = get_lang('LDAPImport');
$interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin')); $interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
$htmlHeadXtra[] = '<script language="JavaScript" type="text/javascript"> $htmlHeadXtra[] = '<script language="JavaScript" type="text/javascript">
var buttoncheck = "false"; var buttoncheck = 1;
function checkAll() { function checkAll() {
var boxes = document.form.elements[\'checkboxes[]\']; //var boxes = document.form.elements[\'checkboxes[]\'];
if (buttoncheck == "false") { var boxes = document.getElementsByName(\'checkboxes[]\');
if (buttoncheck == 0) {
for (i = 0; i < boxes.length; i++) { for (i = 0; i < boxes.length; i++) {
boxes[i].checked = true; boxes[i].checked = true;
} }
buttoncheck = "true"; buttoncheck = 1;
return "'.get_lang('None').'"; return "'.get_lang('None').'";
} }
else { else {
for (i = 0; i < boxes.length; i++) { for (i = 0; i < boxes.length; i++) {
boxes[i].checked = false; boxes[i].checked = false;
} }
buttoncheck = "false"; buttoncheck = 0;
return " '.get_lang('All').' "; return " '.get_lang('All').' ";
} }
} }
</script>'; </script>';
Display::display_header($tool_name);
$annee = $_GET['annee']; $annee = $_GET['annee'];
$composante = $_GET['composante']; $composante = $_GET['composante'];
$etape = $_GET['etape']; $etape = $_GET['etape'];
$course = $_POST['course'];
// form1 annee = 0; composante= 0 etape = 0
if ($annee == "" && $composante == "" && $etape == "") {
// form1 annee = 0; composante= 0 etape = 0
//if ($annee == "" && $composante == "" && $etape == "") {
if (empty($annee) && empty($course))
{
Display::display_header($tool_name);
echo '<div style="align:center">'; echo '<div style="align:center">';
echo '<h3><img src="../img/group.gif" alt="'.get_lang('EnterStudentsToSubscribeToCourse').'" />'.get_lang('EnterStudentsToSubscribeToCourse').'</h3>'; echo '<h3><img src="../img/group.gif" alt="'.get_lang('EnterStudentsToSubscribeToCourse').'" /> '.get_lang('EnterStudentsToSubscribeToCourse').'</h3>';
echo '<em>'.get_lang('ToDoThisYouMustEnterYearComponentAndComponentStep').'</b><br />'; echo '<em>'.get_lang('ToDoThisYouMustEnterYearComponentAndComponentStep').'</em><br />';
echo get_lang('FollowEachOfTheseStepsStepByStep').'<br />'; echo get_lang('FollowEachOfTheseStepsStepByStep').'<br />';
echo '<form method="get" action="'.api_get_self().'"><br />'; echo '<form method="get" action="'.api_get_self().'"><br />';
echo '<b>'.sprintf(get_lang('RegistrationYearExample'),date('Y'),date('Y'),date('Y')+1).' :</b> '; echo '<em>'.sprintf(get_lang('RegistrationYearExample'),date('Y'),date('Y'),date('Y')+1).' :</em> ';
echo '<input type="text" name="annee" size="4" maxlength="30" value="'.$annee_base.'"><br />'; echo '<input type="text" name="annee" size="4" maxlength="30" value="'.$annee_base.'"><br />';
echo '<input type="submit" value="'.get_lang('Submit').'">'; echo '<input type="submit" value="'.get_lang('Submit').'">';
echo '</form>'; echo '</form>';
echo '</div>'; echo '</div>';
} }
/*
elseif ($annee <> "" && $composante == "" && $etape == "") // form 2 annee != 0; composante= 0 etape = 0 elseif ($annee <> "" && $composante == "" && $etape == "") // form 2 annee != 0; composante= 0 etape = 0
{ {
Display::display_header($tool_name);
$ds = ldap_connect($ldap_host, $ldap_port) or die(get_lang('LDAPConnectionError')); $ds = ldap_connect($ldap_host, $ldap_port) or die(get_lang('LDAPConnectionError'));
ldap_set_version($ds); ldap_set_version($ds);
@ -93,7 +100,7 @@ elseif ($annee <> "" && $composante == "" && $etape == "") // form 2 annee != 0;
//$sr = @ ldap_search($ds, "o=groups,$ldap_basedn", "(&(description=etape*)(cn=*$annee))", array ('cn')); //$sr = @ ldap_search($ds, "o=groups,$ldap_basedn", "(&(description=etape*)(cn=*$annee))", array ('cn'));
//$sr = @ ldap_search($ds, "ou=$annee, ou=diploma, o=paris1, $ldap_basedn", "ou=02*", array ('description')); //$sr = @ ldap_search($ds, "ou=$annee, ou=diploma, o=paris1, $ldap_basedn", "ou=02*", array ('description'));
//$sr = @ ldap_search($ds, "ou=structures, o=paris1, $ldap_basedn", "businessCategory=pedagogy", array ('ou','description')); //$sr = @ ldap_search($ds, "ou=structures, o=paris1, $ldap_basedn", "businessCategory=pedagogy", array ('ou','description'));
$sr = ldap_search($ds, "ou=test-ou, o=test-o, $ldap_basedn", "businessCategory=education", array ('ou','description')); $sr = ldap_search($ds, $ldap_basedn, "(ou=*$annee)", array ('ou','description'));
// "ou=2006,ou=diploma,o=Paris1,dc=univ-paris1,dc=fr // "ou=2006,ou=diploma,o=Paris1,dc=univ-paris1,dc=fr
$info = ldap_get_entries($ds, $sr); $info = ldap_get_entries($ds, $sr);
@ -134,6 +141,7 @@ elseif ($annee <> "" && $composante == "" && $etape == "") // form 2 annee != 0;
elseif ($annee <> "" && $composante <> "" && $etape == "") // form3 :annee!=0composante=0etape=0 elseif ($annee <> "" && $composante <> "" && $etape == "") // form3 :annee!=0composante=0etape=0
{ {
Display::display_header($tool_name);
echo '<div style="align: center">'; echo '<div style="align: center">';
echo '<h3><img src="../img/group.gif" alt="'.get_lang('SearchResults').'" />'.get_lang('SearchResults').'</h3>'; echo '<h3><img src="../img/group.gif" alt="'.get_lang('SearchResults').'" />'.get_lang('SearchResults').'</h3>';
$ds = ldap_connect($ldap_host, $ldap_port); $ds = ldap_connect($ldap_host, $ldap_port);
@ -146,7 +154,7 @@ elseif ($annee <> "" && $composante <> "" && $etape == "") // form3 :annee!=0com
// $sr = @ ldap_search($ds, "ou=groups, $LDAPbasedn", "(&(cn=*$annee*)(cn=*$composante*))"); // $sr = @ ldap_search($ds, "ou=groups, $LDAPbasedn", "(&(cn=*$annee*)(cn=*$composante*))");
$sr = @ ldap_search($ds, "ou=$annee, ou=diploma, $ldap_basedn", "seeAlso=ou=$composante,ou=structures,$ldap_basedn", array ('ou','description')); $sr = @ ldap_search($ds, $ldap_basedn, "ou=$composante", array ('ou','description'));
//echo "Le nombre de resultats est : ".ldap_count_entries($ds,$sr)."<p>"; //echo "Le nombre de resultats est : ".ldap_count_entries($ds,$sr)."<p>";
$info = ldap_get_entries($ds, $sr); $info = ldap_get_entries($ds, $sr);
@ -203,13 +211,33 @@ elseif ($annee <> "" && $composante <> "" && $etape == "") // form3 :annee!=0com
echo '<a href="ldap_import_students.php?annee=&composante=&etape=">'.get_lang('BackToNewSearch').'</a>'; echo '<a href="ldap_import_students.php?annee=&composante=&etape=">'.get_lang('BackToNewSearch').'</a>';
echo '</div>'; echo '</div>';
} }
*/
elseif(!empty($annee) && empty($course))
{
Display::display_header($tool_name);
echo '<div style="align:center">';
echo '<img src="../img/course.gif" alt="'.get_lang('SelectCourseToImportUsersTo').'" />'.get_lang('SelectCourseToImportUsersTo').'<br />';
echo '<form method="post" action="'.api_get_self().'?annee='.Security::remove_XSS($annee).'"><br />';
echo '<select name="course">';
$courses = CourseManager::get_courses_list();
foreach($courses as $row)
{
echo '<option value="'.$row['code'].'">'.htmlentities($row['title']).'</option>';
}
echo '</select>';
echo '<input type="submit" value="'.get_lang('Submit').'">';
echo '</form>';
echo '</div>';
}
// form4 annee != 0; composante != 0 etape != 0 // form4 annee != 0; composante != 0 etape != 0
elseif ($annee <> "" && $composante <> "" && $etape <> "" && $listeok != yes) { //elseif ($annee <> "" && $composante <> "" && $etape <> "" && $listeok != 'yes') {
elseif (!empty($annee) && !empty($course) && empty($_POST['confirmed']))
{
Display::display_header($tool_name);
echo '<div style="align: center;">'; echo '<div style="align: center;">';
echo '<br />'; echo '<br />';
echo '<br />'; echo '<br />';
echo '<h3><img src="../img/group.gif" alt="'.get_lang('SelectStudents').'" />'.get_lang('SelectStudents').'</h3>'; echo '<h3><img src="../img/group.gif" alt="'.get_lang('SelectStudents').'" /> '.get_lang('SelectStudents').'</h3>';
//echo "Connection ..."; //echo "Connection ...";
$ds = ldap_connect($ldap_host, $ldap_port) or die(get_lang('LDAPConnectionError')); $ds = ldap_connect($ldap_host, $ldap_port) or die(get_lang('LDAPConnectionError'));
ldap_set_version($ds); ldap_set_version($ds);
@ -220,7 +248,8 @@ elseif ($annee <> "" && $composante <> "" && $etape <> "" && $listeok != yes) {
$res = ldap_handle_bind($ds, $r); $res = ldap_handle_bind($ds, $r);
//$sr = @ ldap_search($ds, "ou=people,$LDAPbasedn", "(|(edupersonprimaryorgunitdn=ou=$etape,ou=$annee,ou=diploma,o=Paris1,$LDAPbasedn)(edupersonprimaryorgunitdn=ou=02PEL,ou=$annee,ou=diploma,o=Paris1,$LDAPbasedn))"); //$sr = @ ldap_search($ds, "ou=people,$LDAPbasedn", "(|(edupersonprimaryorgunitdn=ou=$etape,ou=$annee,ou=diploma,o=Paris1,$LDAPbasedn)(edupersonprimaryorgunitdn=ou=02PEL,ou=$annee,ou=diploma,o=Paris1,$LDAPbasedn))");
$sr = @ ldap_search($ds, "ou=people,$ldap_basedn", "edupersonprimaryorgunitdn=ou=$etape,ou=$annee,ou=diploma,$ldap_basedn"); //echo "(ou=*$annee,ou=$composante)";
$sr = @ ldap_search($ds, $ldap_basedn, "(ou=*$annee)");
$info = ldap_get_entries($ds, $sr); $info = ldap_get_entries($ds, $sr);
@ -229,12 +258,15 @@ elseif ($annee <> "" && $composante <> "" && $etape <> "" && $listeok != yes) {
$prenom_form[] = $info[$key]["givenname"][0];//iconv("utf-8",api_get_setting('platform_charset'), $info[$key]["givenname"][0]); $prenom_form[] = $info[$key]["givenname"][0];//iconv("utf-8",api_get_setting('platform_charset'), $info[$key]["givenname"][0]);
$email_form[] = $info[$key]["mail"][0]; $email_form[] = $info[$key]["mail"][0];
// Get uid from dn // Get uid from dn
$dn_array=ldap_explode_dn($info[$key]["dn"],1); //$dn_array=ldap_explode_dn($info[$key]["dn"],1);
$username_form[] = $dn_array[0]; // uid is first key //$username_form[] = $dn_array[0]; // uid is first key
$username_form[] = $info[$key]['uid'][0];
$outab[] = $info[$key]["eduPersonPrimaryAffiliation"][0]; // Ici "student" $outab[] = $info[$key]["eduPersonPrimaryAffiliation"][0]; // Ici "student"
$val = ldap_get_values_len($ds, $entry, "userPassword"); //$val = ldap_get_values_len($ds, $entry, "userPassword");
$password_form[] = $val[0]; //$password_form[] = $val[0];
$password_form[] = $info[$key]['userPassword'][0];
} }
ldap_unbind($ds);
/*-----------------------------------------------*/ /*-----------------------------------------------*/
@ -242,9 +274,7 @@ elseif ($annee <> "" && $composante <> "" && $etape <> "" && $listeok != yes) {
reset($nom_form); reset($nom_form);
$statut=5; $statut=5;
ldap_close($ds);
include ('ldap_form_add_users_group.php'); include ('ldap_form_add_users_group.php');
ldap_unbind($ds);
} else { } else {
echo '<h4>'.get_lang('UnableToConnectTo').' '.$host.'</h4>'; echo '<h4>'.get_lang('UnableToConnectTo').' '.$host.'</h4>';
} }
@ -254,5 +284,53 @@ elseif ($annee <> "" && $composante <> "" && $etape <> "" && $listeok != yes) {
echo '</div>'; echo '</div>';
} }
elseif (!empty($annee) && !empty($course) && ($_POST['confirmed']=='yes'))
{
$id=$_POST['username_form'];
$UserList=array();
$userid_match_login = array();
foreach ($id as $user_id)
{
$tmp = ldap_add_user($user_id);
$UserList[]= $tmp;
$userid_match_login[$tmp] = $user_id;
}
if (!empty($_POST['course']))
{
foreach($UserList as $user_id)
{
CourseManager::add_user_to_course($user_id,$_POST['course']);
}
header('Location: course_information.php?code='.Security::remove_XSS($_POST['course']));
}
/*
else
{
Display :: display_header($tool_name);
if(count($userid_match_login)>0)
{
$message=get_lang('LDAPUsersAddedOrUpdated').':<br />';
foreach($userid_match_login as $user_id => $login)
{
$message .= '- '.$login.'<br />';
}
}
else
{
$message=get_lang('NoUserAdded');
}
Display :: display_normal_message($message,false);
}
*/
else
{
Display::display_header($tool_name);
$message=get_lang('NoUserAdded');
Display :: display_normal_message($message,false);
}
echo '<br /><br />';
echo '<a href="ldap_import_students.php?annee=&composante=&etape=">'.get_lang('BackToNewSearch').'</a>';
echo '<br /><br />';
}
Display::display_footer(); Display::display_footer();
?> ?>

@ -39,246 +39,6 @@ $this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script(); api_protect_admin_script();
/**
* Get the total number of users on the platform
* @see SortableTable#get_total_number_of_items()
*/
function get_ldap_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[]="(eduPersonPrimaryAffiliation=".$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, "ou=test-ou,$ldap_basedn", $str_query);
$sr = ldap_search($ds, $ldap_basedn, $str_query);
//echo "Le nombre de resultats est : ".ldap_count_entries($ds,$sr)."<p>";
$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#get_total_number_of_items()
*/
function get_number_of_users()
{
$info = get_ldap_users();
if (count($info)>0)
return $info['count'];
else
return 0;
}
/**
* Get the users to display on the current page.
* @see SortableTable#get_table_data($from)
*/
function get_user_data($from, $number_of_items, $column, $direction)
{
$users = array();
if (isset($_GET['submit']))
{
$info = get_ldap_users();
if ($info['count']>0)
{
for ($key = 0; $key < $info["count"]; $key ++)
{
$user=array();
// Get uid from dn
//YW: this might be a variation between LDAP 2 and LDAP 3, but in LDAP 3, the uid is in
//the corresponding index of the array
//$dn_array=ldap_explode_dn($info[$key]["dn"],1);
//$user[] = $dn_array[0]; // uid is first key
//$user[] = $dn_array[0]; // uid is first key
$user[] = $info[$key]['uid'][0];
$user[] = $info[$key]['uid'][0];
$user[] = iconv('utf-8', api_get_setting('platform_charset'), $info[$key]['sn'][0]);
$user[] = iconv('utf-8', api_get_setting('platform_charset'), $info[$key]['givenname'][0]);
$user[] = $info[$key]['mail'][0];
$outab[] = $info[$key]['eduPersonPrimaryAffiliation'][0]; // Ici "student"
$users[] = $user;
}
}
else
{
Display :: display_error_message(get_lang('NoUser'));
}
}
return $users;
}
/**
* Build the modify-column of the table
* @param int $user_id The user id
* @param string $url_params
* @return string Some HTML-code with modify-buttons
*/
function modify_filter($user_id,$url_params, $row)
{
$url_params_id="id[]=".$row[0];
//$url_params_id="id=".$row[0];
$result .= '<a href="ldap_users_list.php?action=add_user&amp;user_id='.$user_id.'&amp;id_session='.Security::remove_XSS($_GET['id_session']).'&amp;'.$url_params_id.'&amp;sec_token='.$_SESSION['sec_token'].'" onclick="javascript:if(!confirm('."'".addslashes(htmlentities(get_lang("ConfirmYourChoice")))."'".')) return false;"><img src="../img/add_user.gif" border="0" style="vertical-align: middle;" title="'.get_lang('AddUsers').'" alt="'.get_lang('AddUsers').'"/></a>';
return $result;
}
function addLdapUser($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);
//echo "Le nombre de resultats est : ".ldap_count_entries($ds,$sr)."<p>";
$info = ldap_get_entries($ds, $sr);
for ($key = 0; $key < $info['count']; $key ++)
{
$lastname = iconv('utf-8', api_get_setting('platform_charset'), $info[$key]['sn'][0]);
$firstname = iconv('utf-8', api_get_setting('platform_charset'), $info[$key]['givenname'][0]);
$email = $info[$key]['mail'][0];
// Get uid from dn
$dn_array=ldap_explode_dn($info[$key]['dn'],1);
$username = $dn_array[0]; // uid is first key
$outab[] = $info[$key]['edupersonprimaryaffiliation'][0]; // Ici "student"
//$val = ldap_get_values_len($ds, $entry, "userPassword");
//$val = ldap_get_values_len($ds, $info[$key], "userPassword");
//$password = $val[0];
// TODO the password, if encrypted at the source, will be encrypted twice, which makes it useless. Try to fix that.
$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];
// Pour faciliter la gestion on ajoute le code "etape-annee"
$official_code=$etape."-".$annee;
$auth_source='ldap';
// Pas de date d'expiration d'etudiant (a recuperer par rapport au shadow expire 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 = '';}
// Ajout de l'utilisateur
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 addUserToSession($UserList, $id_session)
{
// Database Table Definitions
$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);
// Une fois les utilisateurs importer dans la base des utilisateurs, on peux les affecter a<EFBFBD> la session
$result=api_sql_query("SELECT course_code FROM $tbl_session_rel_course " .
"WHERE id_session='$id_session'",__FILE__,__LINE__);
$CourseList=array();
while($row=Database::fetch_array($result))
{
$CourseList[]=$row['course_code'];
}
foreach($CourseList as $enreg_course)
{
foreach($UserList as $enreg_user)
{
api_sql_query("INSERT IGNORE INTO $tbl_session_rel_course_rel_user(id_session,course_code,id_user) VALUES('$id_session','$enreg_course','$enreg_user')",__FILE__,__LINE__);
}
$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 = api_sql_query($sql, __FILE__, __LINE__);
list($nbr_users) = Database::fetch_array($rs);
api_sql_query("UPDATE $tbl_session_rel_course SET nbr_users=$nbr_users " .
"WHERE id_session='$id_session' AND course_code='$enreg_course'",__FILE__,__LINE__);
}
foreach($UserList as $enreg_user)
{
api_sql_query("INSERT IGNORE INTO $tbl_session_rel_user(id_session, id_user) " .
"VALUES('$id_session','$enreg_user')",__FILE__,__LINE__);
}
// On mets a jour le nombre d'utilisateurs dans la session
$sql = "SELECT COUNT(id_user) as nbUsers FROM $tbl_session_rel_user WHERE id_session='$id_session'";
$rs = api_sql_query($sql, __FILE__, __LINE__);
list($nbr_users) = Database::fetch_array($rs);
api_sql_query("UPDATE $tbl_session SET nbr_users=$nbr_users WHERE id='$id_session'",__FILE__,__LINE__);
}
/** /**
============================================================================== ==============================================================================
INIT SECTION INIT SECTION
@ -295,12 +55,14 @@ if ($_GET['action'] == "login_as" && isset ($login_as_user_id))
} }
//if we already have a session id and a user... //if we already have a session id and a user...
/*
if (($_GET['action']=="add_user") && ($_GET['id_session'] == strval(intval($_GET['id_session']))) && $_GET['id_session']>0 ){ if (($_GET['action']=="add_user") && ($_GET['id_session'] == strval(intval($_GET['id_session']))) && $_GET['id_session']>0 ){
header('Location: ldap_import_students_to_session.php?id_session='.$_GET['id_session'].'&ldap_user='.$_GET['id']); header('Location: ldap_import_students_to_session.php?id_session='.$_GET['id_session'].'&ldap_user='.$_GET['id']);
} }
*/
$interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin')); $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
$tool_name = get_lang('SearchAUser'). " - LDAP"; $tool_name = get_lang('SearchLDAPUsers');
//Display :: display_header($tool_name); //cannot display now as we need to redirect //Display :: display_header($tool_name); //cannot display now as we need to redirect
//api_display_tool_title($tool_name); //api_display_tool_title($tool_name);
@ -341,12 +103,12 @@ if (isset ($_GET['action']))
$UserList=array(); $UserList=array();
$userid_match_login = array(); $userid_match_login = array();
foreach ($id as $user_id) { foreach ($id as $user_id) {
$tmp = addLdapUser($user_id); $tmp = ldap_add_user($user_id);
$UserList[]= $tmp; $UserList[]= $tmp;
$userid_match_login[$tmp] = $user_id; $userid_match_login[$tmp] = $user_id;
} }
if (isset($_GET['id_session']) && ($_GET['id_session'] == strval(intval($_GET['id_session']))) && ($_GET['id_session']>0)) { if (isset($_GET['id_session']) && ($_GET['id_session'] == strval(intval($_GET['id_session']))) && ($_GET['id_session']>0)) {
addUserToSession($UserList, $_GET['id_session']); ldap_add_user_to_session($UserList, $_GET['id_session']);
header('Location: resume_session.php?id_session='.$_GET['id_session']); header('Location: resume_session.php?id_session='.$_GET['id_session']);
} else { } else {
Display :: display_header($tool_name); Display :: display_header($tool_name);
@ -416,7 +178,7 @@ if (isset ($_POST['action']))
{ {
if($user_id != $_user['user_id']) if($user_id != $_user['user_id'])
{ {
$UserList[] = addLdapUser($user_id); $UserList[] = ldap_add_user($user_id);
} }
} }
if (isset($_GET['id_session']) && (trim($_GET['id_session'])!="")) if (isset($_GET['id_session']) && (trim($_GET['id_session'])!=""))
@ -467,7 +229,7 @@ if (isset($_GET['id_session']))
// Create a sortable table with user-data // Create a sortable table with user-data
$parameters['sec_token'] = Security::get_token(); $parameters['sec_token'] = Security::get_token();
$table = new SortableTable('users', 'get_number_of_users', 'get_user_data',2); $table = new SortableTable('users', 'ldap_get_number_of_users', 'ldap_get_user_data',2);
$table->set_additional_parameters($parameters); $table->set_additional_parameters($parameters);
$table->set_header(0, '', false); $table->set_header(0, '', false);
$table->set_header(1, get_lang('LoginName')); $table->set_header(1, get_lang('LoginName'));

Loading…
Cancel
Save