<?php

echo "test ldapX<hr>";

if (!function_exists('ldap_connect')) {
	die('Function ldap_connect not exists!');
}

$root_dn = 'uid=se,cn=users,dc=biall,dc=pl';
$root_pw = 'kontem11';

$ldap_con = ldap_connect('ldap://macmini.biall.pl') or die("Could not connect to server. Error is: " . ldap_error($ldap_con));
ldap_set_option($ldap_con, LDAP_OPT_PROTOCOL_VERSION, 3);
$ldap_bd = ldap_bind($ldap_con, $root_dn, $root_pw) or die("Could not bind to server. Error is: " .ldap_error($ldap_con));
$personnel_base = "cn=groups,dc=biall,dc=pl";
$personnel_base = "cn=users,dc=biall,dc=pl";
// "(uid=*)"
$res = ldap_search($ldap_con, $personnel_base, "(uid=*)") or die ("Error in query");
echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">res (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';var_dump($res);echo'</pre>';
$info = ldap_get_entries($ldap_con, $res);
echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">info (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($info);echo'</pre>';

ldap_close($ldap_con);

for ($i = 0; $i < $info["count"]; $i++) {
	echo '<p>' . $info[$i]["uid"][0] . '</p>';// groups(' . impode(',', $info[$i]['objectclass']) . ')' . '</p>';
}

exit;

$ds = ldap_connect('macmini.biall.pl');
echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($ds);echo'</pre>';
if ($ds) {
    // bind with appropriate dn to give update access
    //$r = ldap_bind($ds, "cn=root, o=, c=US", "secret");
# -xLLL -h macmini.biall.pl -b "cn=groups,dc=biall,dc=pl"
$dn = "cn=groups,dc=biall,dc=pl";
$filter="";
$justthese = null;//array("ou", "sn", "givenname", "mail");

$sr = ldap_search($ds, $dn, $filter);//, $justthese);
if (!$sr) {
	echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">error: (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r(ldap_error($ds));echo'</pre>';
} else {
	echo '<p>sr ok</p>';
}
echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">sr (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';var_dump($sr);echo'</pre>';
$info = ldap_get_entries($ds, $sr);
echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">info (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($info);echo'</pre>';
/*
    // prepare data
    $info["cn"] = "John Jones";
    $info["sn"] = "Jones";
    $info["mail"] = "jonj@example.com";
    $info["objectclass"] = "person";

    // add data to directory
    $r = ldap_add($ds, "cn=groups,dc=biall,dc=pl", $info);

*/
    ldap_close($ds);
} else {
    echo "Unable to connect to LDAP server";
}


echo "test1<hr>";
include("./home/www/xx");
echo "test2<hr>";
include("./../../xx");
echo "test3<hr>";
include("/home/www/SES_USERS2/SE/xx");
echo "test4<hr>";
include("logs/../xx");
echo "test5<hr>";
fopen("logs/../xx",r);
echo "test6<hr>";
fopen("/../../xx",r);


phpinfo();



?>
