'index.php','name' => get_lang('PlatformAdmin'));
$htmlHeadXtra[] = '';
$annee = $_GET['annee'];
$id_session = $_POST['id_session'];
// form1 annee = 0; composante= 0 etape = 0
//if ($annee == "" && $composante == "" && $etape == "") {
if (empty($annee) && empty($id_session))
{
Display::display_header($tool_name);
echo '
';
echo Display::return_icon('group.gif', get_lang('LDAPSelectFilterOnUsersOU')).' '.get_lang('LDAPSelectFilterOnUsersOU');
echo '';
echo '
';
}
elseif(!empty($annee) && empty($id_session))
{
Display::display_header($tool_name);
echo '';
echo Display::return_icon('course.gif', get_lang('SelectSessionToImportUsersTo')).' '.get_lang('SelectSessionToImportUsersTo').'
';
echo '';
echo '
';
}
// form4 annee != 0; composante != 0 etape != 0
//elseif ($annee <> "" && $composante <> "" && $etape <> "" && $listeok != 'yes') {
elseif (!empty($annee) && !empty($id_session) && empty($_POST['confirmed']))
{
Display::display_header($tool_name);
echo '';
echo '
';
echo '
';
echo '
'.Display::return_icon('group.gif', get_lang('SelectStudents')).' '.get_lang('SelectStudents').'
';
//echo "Connection ...";
$ds = ldap_connect($ldap_host, $ldap_port) or die(get_lang('LDAPConnectionError'));
ldap_set_version($ds);
if ($ds) {
$r = false;
$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))");
//echo "(ou=*$annee,ou=$composante)";
$sr = @ ldap_search($ds, $ldap_basedn, "(ou=*$annee)");
$info = ldap_get_entries($ds, $sr);
for ($key = 0; $key < $info["count"]; $key ++) {
$nom_form[] = $info[$key]["sn"][0];//iconv("utf-8",api_get_setting('platform_charset'), $info[$key]["sn"][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];
// Get uid from dn
//$dn_array=ldap_explode_dn($info[$key]["dn"],1);
//$username_form[] = $dn_array[0]; // uid is first key
$username_form[] = $info[$key]['uid'][0];
$outab[] = $info[$key]["eduPersonPrimaryAffiliation"][0]; // Ici "student"
//$val = ldap_get_values_len($ds, $entry, "userPassword");
//$password_form[] = $val[0];
$password_form[] = $info[$key]['userPassword'][0];
}
ldap_unbind($ds);
/*-----------------------------------------------*/
asort($nom_form);
reset($nom_form);
$statut=5;
include ('ldap_form_add_users_group.php');
} else {
echo '
'.get_lang('UnableToConnectTo').' '.$host.'
';
}
echo '
';
echo '
'.get_lang('BackToNewSearch').'';
echo '
';
echo '
';
}
elseif (!empty($annee) && !empty($id_session) && ($_POST['confirmed']=='yes'))
{
$id=$_POST['username_form'];
$UserList=array();
$userid_match_login = array();
foreach ($id as $form_index=>$user_id)
{
if(is_array($_POST['checkboxes']) && in_array($form_index,array_values($_POST['checkboxes'])))
{
$tmp = ldap_add_user($user_id);
$UserList[]= $tmp;
$userid_match_login[$tmp] = $user_id;
}
}
if (!empty($_POST['id_session']))
{
$num = 0;
$tbl_session_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
foreach($UserList as $user_id)
{
$sql = 'INSERT INTO '.$tbl_session_user.' SET
id_user="'.intval($user_id).'",
id_session = "'.intval($id_session).'"';
$res_user = api_sql_query($sql,__FILE__,__LINE__);
if($res_user != false)
{
$num++;
}
}
if($num>0)
{
$sql = 'UPDATE '.$tbl_session.' SET nbr_users = (nbr_users + '.$num.') WHERE id = '.intval($id_session);
$res = api_sql_query($sql,__FILE__,__LINE__);
}
header('Location: resume_session.php?id_session='.Security::remove_XSS($_POST['id_session']));
}
/*
else
{
Display :: display_header($tool_name);
if(count($userid_match_login)>0)
{
$message=get_lang('LDAPUsersAddedOrUpdated').':
';
foreach($userid_match_login as $user_id => $login)
{
$message .= '- '.$login.'
';
}
}
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 '
';
echo ''.get_lang('BackToNewSearch').'';
echo '
';
}
Display::display_footer();
?>