<?php
function hsnet($user, $password)
{
    $db = dbconnect();
    $query_ldapuser = $db->query("SELECT wert1, wert2 FROM parameter WHERE pid='13'");
    $row_ldapuser = $query_ldapuser->fetch_array();
    #hsnet
    $ds = @ldap_connect("141.10.128.30", "389");
    ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
    ldap_set_option($ds, LDAP_OPT_NETWORK_TIMEOUT, 1);

    # bind wird benötigt, sonst werden die Umlaute bei Namen  nicht richtig angezeigt ?!!?
    $r = @ldap_bind($ds, $row_ldapuser['wert1'], $row_ldapuser['wert2']);
    if ($r)
    {
        $_ldap_dn = "ou=OUHochschulnetzwerk,dc=hsnet,dc=hs-ludwigsburg,dc=de";
        $sr = @ldap_search($ds, $_ldap_dn, "samaccountname=$user");
        $info = @ldap_get_entries($ds, $sr);
        $anzahl = ldap_count_entries($ds, $sr);

        if ($anzahl > 0)
        {
            $first = ldap_first_entry($ds, $sr);
            $distinguishedName = ldap_get_dn($ds, $first);
            if (@ldap_bind($ds, $distinguishedName, $password))
            {
                ldap_close($ds);
                return true;
            }
            else
            {
                ldap_close($ds);
                return false;
            }
        }
        else
        {
            ldap_close($ds);
            return false;
        }
    }
    else
    {
        ldap_close($ds);
        return false;
    }

}

function studnet($user, $password)
{
    $db = dbconnect();
    $query_ldapuser = $db->query("SELECT wert1, wert2 FROM parameter WHERE pid='13'");
    $row_ldapuser = $query_ldapuser->fetch_array();
    # Studnet
    $ds = ldap_connect("141.10.144.37", "389");
    ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
    ldap_set_option($ds, LDAP_OPT_NETWORK_TIMEOUT, 1);
    $r = @ldap_bind($ds, $row_ldapuser['wert1'], $row_ldapuser['wert2']);
    if ($r)
    {
        $_ldap_dn = "ou=ouStudnet,dc=studnet,dc=hs-ludwigsburg,dc=de";
        $sr = @ldap_search($ds, $_ldap_dn, "samaccountname=$user");
        $info = @ldap_get_entries($ds, $sr);
        $anzahl = ldap_count_entries($ds, $sr);
        if ($anzahl > 0)
        {
            $first = ldap_first_entry($ds, $sr);
            $distinguishedName = ldap_get_dn($ds, $first);
            if (@ldap_bind($ds, $distinguishedName, $password))
            {
                ldap_close($ds);
                return true;
            }
            else
            {
                ldap_close($ds);
                return false;
            }
        }
        else
        {
            ldap_close($ds);
            return false;
        }
    }
    else
    {
        ldap_close($ds);
        return false;
    }
}
?>