foreach ($sessions as $row) {
        echo '<option value="' . $row['id'] . '">' . api_htmlentities($row['name'], ENT_COMPAT, api_get_system_encoding()) . ' (' . $row['date_start'] . ' - ' . $row['date_end'] . ')</option>';
    }
    echo '</select>';
    echo '<input type="submit" value="' . get_lang('Submit') . '">';
    echo '</form>';
    echo '</div>';
} elseif (!empty($annee) && !empty($id_session) && empty($_POST['confirmed'])) {
    Display::display_header($tool_name);
    echo '<div style="align: center;">';
    echo '<br />';
    echo '<br />';
    echo '<h3>' . Display::return_icon('group.gif', get_lang('SelectStudents')) . ' ' . get_lang('SelectStudents') . '</h3>';
    //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];
            //api_utf8_decode($info[$key]["sn"][0], api_get_system_encoding());
            $prenom_form[] = $info[$key]["givenname"][0];
            //api_utf8_decode($info[$key]["givenname"][0], api_get_system_encoding());
            $email_form[] = $info[$key]["mail"][0];
            // Get uid from dn
            //$dn_array=ldap_explode_dn($info[$key]["dn"],1);
Exemple #2
0
function syncro_users()
{
    global $ldap_basedn, $ldap_host, $ldap_port, $ldap_rdn, $ldap_pass, $ldap_search_dn;
    echo "Connecting ...";
    $ldap_connect = ldap_connect($ldap_host, $ldap_port);
    ldap_set_version($ldap_connect);
    if ($ldap_connect) {
        //echo " Connect to LDAP server successful ";
        //echo "Binding ...";
        $ldap_bind = false;
        $ldap_bind_res = ldap_handle_bind($ldap_connect, $ldap_bind);
        if ($ldap_bind_res) {
            //echo " LDAP bind successful... ";
            //echo " Searching for uid... ";
            // Search surname entry
            //OLD: $sr=ldap_search($ldapconnect,"dc=rug, dc=ac, dc=be", "uid=$login");
            //echo "<p> ldapDc = '$LDAPbasedn' </p>";
            $all_user_query = "uid=*";
            if (!empty($ldap_search_dn)) {
                $sr = ldap_search($ldap_connect, $ldap_search_dn, $all_user_query);
            } else {
                $sr = ldap_search($ldap_connect, $ldap_basedn, $all_user_query);
            }
            //echo " Number of entries returned is ".ldap_count_entries($ldapconnect,$sr);
            //echo " Getting entries ...";
            $info = ldap_get_entries($ldap_connect, $sr);
            for ($key = 0; $key < $info['count']; $key++) {
                $user_id = ldap_add_user_by_array($info[$key], false);
                if ($user_id) {
                    echo "User #{$user_id} created ";
                } else {
                    echo "User was not created ";
                }
            }
            //echo "Data for ".$info["count"]." items returned:<p>";
        } else {
            //echo "LDAP bind failed...";
        }
        //echo "Closing LDAP connection<hr>";
        ldap_close($ldap_connect);
    } else {
        //echo "<h3>Unable to connect to LDAP server</h3>";
    }
}