function search_user()
{
    header("Pragma: no-cache");
    header("Expires: 0");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-cache, must-revalidate");
    $stringtofind = $_GET["search_user"];
    $tpl = new templates();
    $usermenu = new usersMenus();
    $ldap = new clladp();
    if ($usermenu->AsAnAdministratorGeneric == true) {
        $hash_full = $ldap->UserSearch(null, $stringtofind);
    } else {
        $us = $ldap->UserDatas($_SESSION["uid"]);
        $hash_full = $ldap->UserSearch($us["ou"], $stringtofind);
    }
    $html = "<table style='width:100%'>";
    for ($i = 0; $i < $hash_full[0]["count"]; $i++) {
        $displayname = $hash_full[0][$i]["displayname"][0];
        $mail = $hash_full[0][$i]["mail"][0];
        if (strlen($mail) > 27) {
            $mail = substr($mail, 0, 24) . '...';
        }
        $uid = $hash_full[0][$i]["uid"][0];
        $js = "RestoreMbxSelectedUser('{$uid}');";
        $html = $html . "<tr " . CellRollOver($js) . ">\n\t\t\t<td width=1%><img src='img/fw_bold.gif'></td>\n\t\t\t<td><code nowrap>{$displayname}</code></td>\n\t\t\t<td><code>{$mail}</code></td>\n\t\t</tr>\n\t\t\t\n\t\t";
    }
    $html = $html . "</table>";
    echo $html;
}
function SyncOrg($ou)
{
    $ldap = new clladp();
    $hash = $ldap->UserSearch($ou, "");
    for ($i = 0; $i < $hash["count"]; $i++) {
        $uid = $hash[$i]["uid"][0];
        write_syslog("Checking {$uid}", __FILE__);
        $obm = new obm_user($uid);
    }
}
Exemple #3
0
function local_users()
{
    $stringtofind = $_GET["browser-users"];
    $ldap = new clladp();
    $page = CurrentPageName();
    $tpl = new templates();
    if ($_SESSION["ou"] != null) {
        $ou = $_SESSION["ou"];
    }
    $hash = $ldap->UserSearch($ou, $stringtofind);
    $YahooWin = "YahooWin5";
    if (isset($_GET["YahooWin"])) {
        $YahooWin = "YahooWin{$_GET["YahooWin"]}";
    }
    $html = "\n<table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:100%'>\n<thead class='thead'>\n\t<tr>\n\t<th colspan=4>{members}</th>\n\t</tr>\n</thead>\n<tbody class='tbody'>";
    for ($i = 0; $i < $hash[0]["count"]; $i++) {
        $ligne = $hash[0][$i];
        $dn = $ligne["dn"];
        if (strpos($ligne["dn"], "dc=pureftpd,dc=organizations") > 0) {
            continue;
        }
        $uid = $ligne["uid"][0];
        if ($uid == null) {
            continue;
        }
        if ($uid == "squidinternalauth") {
            continue;
        }
        if ($array[$uid] != null) {
            continue;
        }
        if ($classtr == "oddRow") {
            $classtr = null;
        } else {
            $classtr = "oddRow";
        }
        $ct = new user($uid);
        $js = MEMBER_JS($uid, 1, 1);
        $img = imgtootltip("contact-48.png", "{view}", $js);
        $add = imgtootltip("plus-24.png", "{add}", "SelectMemberBrowser('{$uid}')");
        $html = $html . "\n\t\t\t<tr class={$classtr}>\n\t\t\t<td width=1%>{$img}</td>\n\t\t\t<td><strong style='font-size:14px'>{$ct->DisplayName}</td>\n\t\t\t<td width=1%>{$add}</td>\n\t\t\t</tr>\n\t\t\t";
    }
    $html = $html . "</tbody></table>\n\t<script>\t\n\t\tfunction SelectMemberBrowser(uid){\n\t\t\tdocument.getElementById('{$_GET["field"]}').value=uid;\n\t\t\t{$YahooWin}Hide();\n\t\t}\n\t</script>\n\t\n\t";
    echo $tpl->_ENGINE_parse_body($html);
}
function MEMBERS_SEARCH_USERS()
{
    $gid = $_GET["FindInGroup"];
    $pattern = $_GET["pattern"];
    $pattern = str_replace('*', '', $pattern);
    $styleRoll = "\n\tstyle='border:1px solid white;width:190px;float:left;margin:1px'\n\tOnMouseOver=\"this.style.backgroundColor='#F3F3DF';this.style.cursor='pointer';this.style.border='1px solid #CCCCCC'\"\n\tOnMouseOut=\"this.style.backgroundColor='transparent';this.style.cursor='auto';this.style.border='1px solid white'\"\n\t";
    //first we search the users
    $ldap = new clladp();
    $hash = $ldap->UserSearch(null, $pattern);
    //second we load users uids of the group and build the hash
    $sr = @ldap_search($ldap->ldap_connection, $ldap->suffix, "(gidnumber={$gid})", array("memberUid"));
    if (!$sr) {
        writelogs("Search members for (gidnumber={$gid}) failed", __FUNCTION__, __FILE__);
        return null;
    }
    $entry_id = ldap_first_entry($ldap->ldap_connection, $sr);
    if (!$entry_id) {
        return null;
    }
    $attrs = ldap_get_attributes($ldap->ldap_connection, $entry_id);
    if (!is_array($attrs["memberUid"])) {
        writelogs("memberUid no attrs", __FUNCTION__, __FILE__);
        return null;
    }
    $count = $attrs["memberUid"]["count"];
    while (list($num, $ligne) = each($attrs["memberUid"])) {
        $hash_members[$ligne] = true;
    }
    //now we parse the search results
    $count = 0;
    for ($i = 0; $i < $hash["count"]; $i++) {
        if ($hash_members[$hash[$i]["uid"][0]]) {
            $uid = $hash[$i]["uid"][0];
            $count = $count + 1;
            $html = $html . "<div {$styleRoll} id='mainid_{$uid}'>" . MEMBERS_SELL($uid) . "</div>";
            if ($count > 41) {
                break;
            }
        }
    }
    $tpl = new templates();
    echo $tpl->_ENGINE_parse_body($html);
}
function TOOL_SYNC_FIND_MAILBOX()
{
    $user = new user($_GET["uid"]);
    $ou = $user->ou;
    $ldap = new clladp();
    $hash = $ldap->UserSearch($ou, $_GET["sync_find_user"]);
    $html = "\n\t<div style='width:100%;height:300px;overflow:auto'>\n\t<strong style='width:12px'>{search_in_orgnization}:{$ou}</strong>\n\t<table style='width:100%'>";
    //print_r($hash);
    while (list($num, $ligne) = each($hash)) {
        $id = $ligne["uid"][0];
        $displayname = $ligne["displayname"][0];
        $mail = $ligne["mail"][0];
        if (trim($mail) == null) {
            continue;
        }
        $html = $html . "<tr " . CellRollOver() . ">\n\t\t\t<td width=1%><img src='img/fw_bold.gif'></td>\n\t\t\t<td style='font-size:11px'>{$displayname}</td>\n\t\t\t<td style='font-size:11px'>{$mail}</td>\n\t\t\t<td style='font-size:11px' width=1%><input type='button' OnClick=\"javascript:ExportMailBoxSelect2('{$id}')\" value='{select}&nbsp;&raquo;'></td>\n\t\t\t</tr>";
    }
    $tpl = new templates();
    $html = $html . "</table></div>";
    echo $tpl->_ENGINE_parse_body($html);
}
function finduser_list()
{
    $keycached = "{$_GET["finduser"]}";
    header("Pragma: no-cache");
    header("Expires: 0");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-cache, must-revalidate");
    $GLOBALS["OUTPUT_DEBUG"] = false;
    $stringtofind = trim($_GET["finduser"]);
    if ($_POST["query"] != null) {
        $stringtofind = $_POST["query"];
    }
    if (!isset($_POST["rp"])) {
        $_POST["rp"] = 15;
    }
    $users = new usersMenus();
    $sock = new sockets();
    $EnableManageUsersTroughActiveDirectory = $sock->GET_INFO("EnableManageUsersTroughActiveDirectory");
    if (!is_numeric($EnableManageUsersTroughActiveDirectory)) {
        $EnableManageUsersTroughActiveDirectory = 0;
    }
    if (preg_match("#debug:(.+)#", $stringtofind, $re)) {
        $GLOBALS["OUTPUT_DEBUG"] = true;
        $stringtofind = trim($re[1]);
    }
    if ($GLOBALS["OUTPUT_DEBUG"]) {
        echo "Want to search {$stringtofind}<br>";
    }
    $tpl = new templates();
    $usermenu = new usersMenus();
    $ldap = new clladp();
    if (!$ldap->IsKerbAuth()) {
        if ($usermenu->AsAnAdministratorGeneric == true) {
            if ($GLOBALS["OUTPUT_DEBUG"]) {
                echo "It is an administrator search in the entire tree<br>";
            }
            $hash_full = $ldap->UserSearch(null, $stringtofind, $_POST["rp"]);
        } else {
            $us = $ldap->UserDatas($_SESSION["uid"]);
            if ($GLOBALS["OUTPUT_DEBUG"]) {
                echo "It is an user search in the {$us["ou"]} tree<br>";
            }
            $hash_full = $ldap->UserSearch($us["ou"], $stringtofind, $_POST["rp"]);
        }
        $hash1 = $hash_full[0];
        $hash2 = $hash_full[1];
        if ($GLOBALS["OUTPUT_DEBUG"]) {
            echo "Search results " . count($hash1) . " users and " . count($hash2) . " contacts<br>";
        }
    } else {
        include_once dirname(__FILE__) . "/ressources/class.external.ad.inc";
        $ad = new external_ad_search();
        $hash_full = $ad->UserSearch(null, $stringtofind, $_POST["rp"]);
        $hash1 = $hash_full[0];
        $hash2 = $hash_full[1];
        if ($GLOBALS["OUTPUT_DEBUG"]) {
            echo "Search results " . count($hash1) . " users and " . count($hash2) . " contacts<br>";
        }
    }
    $hash = array();
    $count = 0;
    $data = array();
    $data['page'] = 1;
    $data['total'] = 0;
    $data['rows'] = array();
    if (is_array($hash1)) {
        if ($GLOBALS["OUTPUT_DEBUG"]) {
            echo "<strong>Search results ->HASH1</strong><br>\n";
        }
        while (list($num, $ligne) = each($hash1)) {
            if (isset($ligne["samaccountname"][0])) {
                $ligne["uid"][0] = $ligne["samaccountname"][0];
            }
            if ($ligne["uid"][0] == null) {
                if (preg_match("#^CN=(.+?),#i", $ligne["dn"], $re)) {
                    $ligne["uid"][0] = $re[1];
                    $hash[$count]["displayname"][0] = $re[1];
                }
            }
            if ($EnableManageUsersTroughActiveDirectory == 0) {
                if ($ligne["uid"][0] == null && $ligne["employeenumber"][0] == null) {
                    continue;
                }
            }
            if (strpos($ligne["dn"], "dc=pureftpd,dc=organizations") > 0) {
                continue;
            }
            $hash[$count]["displayname"][0] = trim($ligne["displayname"][0]);
            $hash[$count]["givenname"][0] = $ligne["givenname"][0];
            if ($EnableManageUsersTroughActiveDirectory == 1) {
                $hash[$count]["uid"][0] = $ligne["samaccountname"][0];
            } else {
                $hash[$count]["uid"][0] = $ligne["uid"][0];
            }
            if (substr($hash[$count]["uid"][0], strlen($hash[$count]["uid"][0]) - 1, 1) == '$') {
                continue;
            }
            $hash[$count]["employeenumber"][0] = $ligne["employeenumber"][0];
            $hash[$count]["title"][0] = $ligne["title"][0];
            $hash[$count]["uri"][0] = $ligne["uri"][0];
            $hash[$count]["mail"][0] = $ligne["mail"][0];
            $hash[$count]["phone"][0] = $ligne["telephonenumber"][0];
            $hash[$count]["sn"][0] = $ligne["sn"][0];
            $hash[$count]["dn"] = $ligne["dn"];
            $count++;
        }
    } else {
        if ($GLOBALS["OUTPUT_DEBUG"]) {
            echo "<strong>Search results ->HASH1 NOT AN ARRAY</strong><br>\n";
        }
    }
    if (is_array($hash2)) {
        if ($GLOBALS["OUTPUT_DEBUG"]) {
            echo "<strong>Search results ->HASH2</strong><br>\n";
        }
        while (list($num, $ligne) = each($hash2)) {
            if (isset($ligne["samaccountname"][0])) {
                $ligne["uid"][0] = $ligne["samaccountname"][0];
            }
            if ($ligne["uid"][0] == null && $ligne["employeenumber"][0] == null) {
                continue;
            }
            if (strpos($ligne["dn"], "dc=pureftpd,dc=organizations") > 0) {
                continue;
            }
            $hash[$count]["displayname"][0] = $ligne["displayname"][0];
            $hash[$count]["givenname"][0] = $ligne["givenname"][0];
            $hash[$count]["uid"][0] = $ligne["uid"][0];
            $hash[$count]["employeenumber"][0] = $ligne["employeenumber"][0];
            $hash[$count]["title"][0] = $ligne["title"][0];
            $hash[$count]["uri"][0] = $ligne["uri"][0];
            $hash[$count]["mail"][0] = $ligne["mail"][0];
            $hash[$count]["phone"][0] = $ligne["telephonenumber"][0];
            $hash[$count]["sn"][0] = $ligne["sn"][0];
            $hash[$count]["dn"] = $ligne["dn"];
            $count = $count + 1;
        }
    } else {
        if ($GLOBALS["OUTPUT_DEBUG"]) {
            echo "<strong>Search results ->HASH2 NOT AN ARRAY</strong><br>\n";
        }
    }
    $count = count($hash);
    $data['total'] = $count;
    if ($count == 0) {
        json_error_show("no data", 1);
    }
    if ($GLOBALS["OUTPUT_DEBUG"]) {
        echo "<strong>Search results {$count} items</strong><br>\n";
    }
    if (is_array($hash)) {
        while (list($num, $ligne) = each($hash)) {
            if ($GLOBALS["OUTPUT_DEBUG"]) {
                echo "dn:{$ligne["dn"]}<br>";
            }
            if ($GLOBALS["OUTPUT_DEBUG"]) {
                echo "uid:{$ligne["uid"][0]}<br>";
            }
            if ($GLOBALS["OUTPUT_DEBUG"]) {
                echo "employeenumber:{$ligne["employeenumber"][0]}<br>";
            }
            if ($ligne["uid"][0] == null && $ligne["employeenumber"][0] == null) {
                if ($GLOBALS["OUTPUT_DEBUG"]) {
                    echo "null twice, aborting...<br>";
                }
                continue;
            }
            if ($ligne["uid"][0] == "squidinternalauth") {
                $count = $count - 1;
                continue;
            }
            if ($GLOBALS["OUTPUT_DEBUG"]) {
                echo "edit_config_user={$ligne["uid"][0]}<br>";
            }
            $edit_config_user = MEMBER_JS($ligne["uid"][0], 1, 0, $ligne["dn"]);
            if ($usermenu->AllowAddUsers == true) {
                $uri = $edit_config_user;
            } else {
                $uri = null;
            }
            if ($usermenu->AsOrgAdmin == true) {
                $uri = $edit_config_user;
            } else {
                $uri = null;
            }
            if ($usermenu->AsArticaAdministrator == true) {
                $uri = $edit_config_user;
            } else {
                $uri = null;
            }
            $displayname = trim($ligne["displayname"][0]);
            $givenname = $ligne["givenname"][0];
            $mail = $ligne["mail"][0];
            if ($displayname == null) {
                $displayname = $ligne["uid"][0];
            }
            if ($givenname == null) {
                $givenname = '{unknown}';
            }
            if ($mail == null) {
                $mail = '{unknown}';
            }
            if ($ligne["employeenumber"][0] != null) {
                $array["employeenumber"] = $ligne["employeenumber"][0];
                $user = new contacts($_SESSION["uid"], $ligne["employeenumber"][0]);
                $array["title"] = $user->displayName;
                $uri = "javascript:Loadjs('contact.php?employeeNumber={$ligne["employeenumber"][0]}')";
            } else {
                if ($ligne["uid"][0] != null) {
                    $array["title"] = $ligne["uid"][0];
                    $user = new user($ligne["uid"][0]);
                }
            }
            if (strlen($user->jpegPhoto) > 0) {
                $array["img"] = $user->img_identity;
            } else {
                $array["img"] = "img/contact-unknown-user.png";
            }
            writelogs("identity:{$user->img_identity} ", __FUNCTION__, __FILE__);
            $array["uri"] = $uri;
            $array["mail"] = $ligne["mail"][0];
            $array["phone"] = $ligne["telephonenumber"][0];
            $array["sn"] = $ligne["sn"][0];
            if (!$ldap->EnableManageUsersTroughActiveDirectory) {
                if ($displayname == null) {
                    $displayname = "{$givenname} {$ligne["sn"][0]}";
                }
            }
            $array["displayname"] = $displayname;
            $array["givenname"] = $givenname;
            $array["JS"] = $edit_config_user;
            $array["title"] = $ligne["title"][0];
            $array["ou"] = $user->ou;
            $array["uid"] = $ligne["uid"][0];
            $data['rows'][] = finduser_format($array);
        }
    }
    echo json_encode($data);
}
function finduser()
{
    header("Pragma: no-cache");
    header("Expires: 0");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-cache, must-revalidate");
    $stringtofind = $_GET["finduser"];
    writelogs("Want to search {$stringtofind}", __FUNCTION__, __FILE__);
    $tpl = new templates();
    $usermenu = new usersMenus();
    $ldap = new clladp();
    if ($usermenu->AsAnAdministratorGeneric == true) {
        writelogs("It is an administrator search in the entire tree", __FUNCTION__, __FILE__);
        $hash_full = $ldap->UserSearch(null, $stringtofind);
    } else {
        $us = $ldap->UserDatas($_SESSION["uid"]);
        writelogs("It is an user search in the {$us["ou"]} tree", __FUNCTION__, __FILE__);
        $hash_full = $ldap->UserSearch($us["ou"], $stringtofind);
    }
    $hash1 = $hash_full[0];
    $hash2 = $hash_full[1];
    writelogs("Search results " . count($hash1) . " users and " . count($hash2) . " contacts", __FUNCTION__, __FILE__);
    $count = 0;
    if (is_array($hash1)) {
        while (list($num, $ligne) = each($hash1)) {
            if ($ligne["uid"][0] == null && $ligne["employeenumber"][0] == null) {
                continue;
            }
            $hash[$count]["displayname"][0] = $ligne["displayname"][0];
            $hash[$count]["givenname"][0] = $ligne["givenname"][0];
            $hash[$count]["uid"][0] = $ligne["uid"][0];
            $hash[$count]["employeenumber"][0] = $ligne["employeenumber"][0];
            $hash[$count]["title"][0] = $ligne["title"][0];
            $hash[$count]["uri"][0] = $ligne["uri"][0];
            $hash[$count]["mail"][0] = $ligne["mail"][0];
            $hash[$count]["phone"][0] = $ligne["telephonenumber"][0];
            $hash[$count]["sn"][0] = $ligne["sn"][0];
            $count = $count + 1;
        }
    }
    if (is_array($hash2)) {
        while (list($num, $ligne) = each($hash2)) {
            if ($ligne["uid"][0] == null && $ligne["employeenumber"][0] == null) {
                continue;
            }
            $hash[$count]["displayname"][0] = $ligne["displayname"][0];
            $hash[$count]["givenname"][0] = $ligne["givenname"][0];
            $hash[$count]["uid"][0] = $ligne["uid"][0];
            $hash[$count]["employeenumber"][0] = $ligne["employeenumber"][0];
            $hash[$count]["title"][0] = $ligne["title"][0];
            $hash[$count]["uri"][0] = $ligne["uri"][0];
            $hash[$count]["mail"][0] = $ligne["mail"][0];
            $hash[$count]["phone"][0] = $ligne["telephonenumber"][0];
            $hash[$count]["sn"][0] = $ligne["sn"][0];
            $count = $count + 1;
        }
    }
    $count = count($hash);
    writelogs("Search results {$count} items", __FUNCTION__, __FILE__);
    if (is_array($hash)) {
        while (list($num, $ligne) = each($hash)) {
            if ($ligne["uid"][0] == null && $ligne["employeenumber"][0] == null) {
                continue;
            }
            if ($ligne["uid"][0] == "squidinternalauth") {
                $count = $count - 1;
                continue;
            }
            $edit_config_user = MEMBER_JS($ligne["uid"][0], 1);
            if ($usermenu->AllowAddUsers == true) {
                $uri = $edit_config_user;
            } else {
                $uri = null;
            }
            if ($usermenu->AsOrgAdmin == true) {
                $uri = $edit_config_user;
            } else {
                $uri = null;
            }
            if ($usermenu->AsArticaAdministrator == true) {
                $uri = $edit_config_user;
            } else {
                $uri = null;
            }
            $displayname = $ligne["displayname"][0];
            $givenname = $ligne["givenname"][0];
            $mail = $ligne["mail"][0];
            if ($displayname == null) {
                $displayname = $ligne["uid"][0];
            }
            if ($givenname == null) {
                $givenname = '{unknown}';
            }
            if ($mail == null) {
                $mail = '{unknown}';
            }
            if ($ligne["employeenumber"][0] != null) {
                $user = new contacts($_SESSION["uid"], $ligne["employeenumber"][0]);
                $array["title"] = $user->displayName;
                $uri = "javascript:Loadjs('contact.php?employeeNumber={$ligne["employeenumber"][0]}')";
            } else {
                if ($ligne["uid"][0] != null) {
                    $array["title"] = $ligne["uid"][0];
                    $user = new user($ligne["uid"][0]);
                }
            }
            if (strlen($user->jpegPhoto) > 0) {
                $array["img"] = $user->img_identity;
            } else {
                $array["img"] = "img/contact-unknown-user.png";
            }
            writelogs("identity:{$user->img_identity} ", __FUNCTION__, __FILE__);
            $array["uri"] = $uri;
            $array["mail"] = $ligne["mail"][0];
            $array["phone"] = $ligne["telephonenumber"][0];
            $array["sn"] = $ligne["sn"][0];
            if ($displayname == null) {
                $displayname = "{$givenname} {$ligne["sn"][0]}";
            }
            $array["displayname"] = $displayname;
            $array["givenname"] = $givenname;
            $array["JS"] = $edit_config_user;
            $array["title"] = $ligne["title"][0];
            $tr_users[] = finduser_format($array);
        }
    }
    $tables[] = "<table style='width:100%'><tr>";
    $t = 0;
    while (list($key, $line) = each($tr_users)) {
        $line = trim($line);
        if ($line == null) {
            continue;
        }
        $t = $t + 1;
        $tables[] = "<td valign='top'>{$line}</td>";
        if ($t == 2) {
            $t = 0;
            $tables[] = "</tr><tr>";
        }
    }
    if ($t < 2) {
        for ($i = 0; $i <= $t; $i++) {
            $tables[] = "<td valign='top'>&nbsp;</td>";
        }
    }
    $tables[] = "</table>";
    $add = Paragraphe("my-address-book-user-add.png", '{add_new_contact}', '{add_new_contact_text}', "javascript:Loadjs('contact.php')");
    if ($_SESSION["uid"] == -100) {
        $add = null;
    }
    $html = "<p style='font-size:18px'>{search}:&laquo;{$stringtofind}&raquo; ({$count} {entries})</p>\n\t\n\t<center>\n\t<table style='width:100%'>\n\t<tr>\n\t<td valign='top'>" . implode("\n", $tables) . "\n\t\t\n\t</td>\n\t<td valign='top'>\n\t{$add}\n\t</td>\n\t</tr>\n\t</table>\n\t\n\t</center>";
    echo $tpl->_ENGINE_parse_body($html);
}
Exemple #8
0
function local_users(){
	$stringtofind=$_GET["local-users"];
	$ldap=new clladp();
	$page=CurrentPageName();
	$tpl=new templates();		
	//if($stringtofind==null){$stringtofind="*";}
	$hash=$ldap->UserSearch(null,$stringtofind);
	$sock=new sockets();
	$array=unserialize(base64_decode($sock->GET_INFO("SargAccess")));	
	$html="
<table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:100%'>
<thead class='thead'>
	<tr>
	<th colspan=4>{members}</th>
	</tr>
</thead>
<tbody class='tbody'>";		
	
	for($i=0;$i<$hash[0]["count"];$i++){
		$ligne=$hash[0][$i];
		$uid=$ligne["uid"][0];
		if($uid==null){continue;}
		if($uid=="squidinternalauth"){continue;}
		if($array[$uid]<>null){continue;}
		if($classtr=="oddRow"){$classtr=null;}else{$classtr="oddRow";}
			$ct=new user($uid);
			$js=MEMBER_JS($uid,1,1);
			$img=imgtootltip("contact-48.png","{view}",$js);
			$add=imgtootltip("plus-24.png","{add}","SargAddMember('$uid')");
			$html=$html."
			<tr class=$classtr>
			<td width=1%>$img</td>
			<td><strong style='font-size:14px'>$ct->DisplayName</td>
			<td width=1%>$add</td>
			</tr>
			";		
		
	}
	$html=$html."</tbody></table>
	<script>
	
	var x_SargAddMember= function (obj) {
			var tempvalue=obj.responseText;
			if(tempvalue.length>3){alert(tempvalue)};
			refresh_remote_users();
	}		
		function SargAddMember(uid){
			var XHR = new XHRConnection();
			XHR.appendData('member-add',uid);	
			document.getElementById('remote-users').innerHTML='<center style=\"margin:20px;padding:20px\"><img src=\"img/wait_verybig.gif\"></center>';
			XHR.sendAndLoad('$page', 'GET',x_SargAddMember);	
		}
		
	</script>
	
	";
	echo $tpl->_ENGINE_parse_body($html);
}
function finduser(){
	$keycached="{$_GET["finduser"]}";
	if(GET_CACHED(__FILE__,__FUNCTION__,$keycached)){return null;}
	header("Pragma: no-cache");	
	header("Expires: 0");
	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
	header("Cache-Control: no-cache, must-revalidate");	
	$GLOBALS["OUTPUT_DEBUG"]=false;
	$stringtofind=trim($_GET["finduser"]);
	$users=new usersMenus();
	
	if(preg_match("#debug:(.+)#",$stringtofind,$re)){
		$GLOBALS["OUTPUT_DEBUG"]=true;
		$stringtofind=trim($re[1]);
	}
	
	if($GLOBALS["OUTPUT_DEBUG"]){echo "Want to search $stringtofind<br>";}
	$tpl=new templates();
	$usermenu=new usersMenus();
	$ldap=new clladp();
	if($usermenu->AsAnAdministratorGeneric==true){
		if($GLOBALS["OUTPUT_DEBUG"]){echo "It is an administrator search in the entire tree<br>";}
		$hash_full=$ldap->UserSearch(null,$stringtofind);
	}else{
		$us=$ldap->UserDatas($_SESSION["uid"]);
		if($GLOBALS["OUTPUT_DEBUG"]){echo "It is an user search in the {$us["ou"]} tree<br>";}
		$hash_full=$ldap->UserSearch($us["ou"],$stringtofind);
	}
	
	$hash1=$hash_full[0];
	$hash2=$hash_full[1];
	if($GLOBALS["OUTPUT_DEBUG"]){echo "Search results ".count($hash1) ." users and ".count($hash2)." contacts<br>";}
	
	
	$hash=array();
	$count=0;
	
	if(is_array($hash1)){
	while (list ($num, $ligne) = each ($hash1) ){
		if(!$ldap->EnableManageUsersTroughActiveDirectory){	if(($ligne["uid"][0]==null) && ($ligne["employeenumber"][0]==null)){continue;}}
		if(strpos($ligne["dn"],"dc=pureftpd,dc=organizations")>0){continue;}
		$hash[$count]["displayname"][0]=trim($ligne["displayname"][0]);
		$hash[$count]["givenname"][0]=$ligne["givenname"][0];
		if($ldap->EnableManageUsersTroughActiveDirectory){
			$hash[$count]["uid"][0]=$ligne["samaccountname"][0];
		}else{
			$hash[$count]["uid"][0]=$ligne["uid"][0];
		}
		if(substr($hash[$count]["uid"][0],strlen($hash[$count]["uid"][0])-1,1)=='$'){continue;}
		
		$hash[$count]["employeenumber"][0]=$ligne["employeenumber"][0];
		$hash[$count]["title"][0]=$ligne["title"][0];
		$hash[$count]["uri"][0]=$ligne["uri"][0];
		$hash[$count]["mail"][0]=$ligne["mail"][0];
		$hash[$count]["phone"][0]=$ligne["telephonenumber"][0];
		$hash[$count]["sn"][0]=$ligne["sn"][0];
		$hash[$count]["dn"]=$ligne["dn"];
		$count++;
		
	}}
	
	
	
	if(is_array($hash2)){
	while (list ($num, $ligne) = each ($hash2) ){
	if(($ligne["uid"][0]==null) && ($ligne["employeenumber"][0]==null)){continue;}
		if(strpos($ligne["dn"],"dc=pureftpd,dc=organizations")>0){continue;}
		$hash[$count]["displayname"][0]=$ligne["displayname"][0];
		$hash[$count]["givenname"][0]=$ligne["givenname"][0];
		$hash[$count]["uid"][0]=$ligne["uid"][0];
		$hash[$count]["employeenumber"][0]=$ligne["employeenumber"][0];
		$hash[$count]["title"][0]=$ligne["title"][0];
		$hash[$count]["uri"][0]=$ligne["uri"][0];
		$hash[$count]["mail"][0]=$ligne["mail"][0];
		$hash[$count]["phone"][0]=$ligne["telephonenumber"][0];
		$hash[$count]["sn"][0]=$ligne["sn"][0];
		$hash[$count]["dn"]=$ligne["dn"];
		$count=$count+1;
		
	}}	
	
	
	$count=count($hash);
	writelogs("Search results $count items" ,__FUNCTION__,__FILE__);
	
	if(is_array($hash)){
		
		while (list ($num, $ligne) = each ($hash) ){
			if($GLOBALS["OUTPUT_DEBUG"]){echo "dn:{$ligne["dn"]}<br>";}
			if($GLOBALS["OUTPUT_DEBUG"]){echo "uid:{$ligne["uid"][0]}<br>";}
			if($GLOBALS["OUTPUT_DEBUG"]){echo "employeenumber:{$ligne["employeenumber"][0]}<br>";}
			if(($ligne["uid"][0]==null) && ($ligne["employeenumber"][0]==null)){
				if($GLOBALS["OUTPUT_DEBUG"]){echo "null twice, aborting...<br>";}
				continue;
			}
			
			if($ligne["uid"][0]=="squidinternalauth"){$count=$count-1;continue;}
			
			if($GLOBALS["OUTPUT_DEBUG"]){echo "edit_config_user={$ligne["uid"][0]}<br>";}
			
			$edit_config_user=MEMBER_JS($ligne["uid"][0],1,0,$ligne["dn"]);
			
			if($usermenu->AllowAddUsers==true){$uri=$edit_config_user;}else{$uri=null;}
			if($usermenu->AsOrgAdmin==true){$uri=$edit_config_user;}else{$uri=null;}
			if($usermenu->AsArticaAdministrator==true){$uri=$edit_config_user;}else{$uri=null;}
			
			
			
			$displayname=trim($ligne["displayname"][0]);
			$givenname=$ligne["givenname"][0];
			$mail=$ligne["mail"][0];
			
			if($displayname==null){$displayname=$ligne["uid"][0];}
			if($givenname==null){$givenname='{unknown}';}
			if($mail==null){$mail='{unknown}';}

			if($ligne["employeenumber"][0]<>null){
				$user=new contacts($_SESSION["uid"],$ligne["employeenumber"][0]);
				$array["title"]=$user->displayName;
				$uri="javascript:Loadjs('contact.php?employeeNumber={$ligne["employeenumber"][0]}')";			
				
			}else{
				if($ligne["uid"][0]<>null){
					$array["title"]=$ligne["uid"][0];
					$user=new user($ligne["uid"][0]);
					
					
				}
			}
			
				if(strlen($user->jpegPhoto)>0){$array["img"]=$user->img_identity;}else{$array["img"]="img/contact-unknown-user.png";}
				writelogs("identity:$user->img_identity ",__FUNCTION__,__FILE__);
				$array["uri"]=$uri;
				$array["mail"]=$ligne["mail"][0];;
				$array["phone"]=$ligne["telephonenumber"][0];
				$array["sn"]=$ligne["sn"][0];
				if(!$ldap->EnableManageUsersTroughActiveDirectory){
					if($displayname==null){$displayname="$givenname {$ligne["sn"][0]}";}
				}
				$array["displayname"]=$displayname;								
				$array["givenname"]=$givenname;
				$array["JS"]=$edit_config_user;
				$array["title"]=$ligne["title"][0];;;
				$tr_users[]=finduser_format($array);
			}
		}
	
		
$tables[]="<table style='width:100%'><tr>";
$t=0;
while (list ($key, $line) = each ($tr_users) ){
		$line=trim($line);
		if($line==null){continue;}
		$t=$t+1;
		$tables[]="<td valign='top'>$line</td>";
		if($t==2){$t=0;$tables[]="</tr><tr>";}
		
}
if($t<2){
	for($i=0;$i<=$t;$i++){
		$tables[]="<td valign='top'>&nbsp;</td>";				
	}
}
				
$tables[]="</table>";	
	
		
	$add=Paragraphe("my-address-book-user-add.png",'{add_new_contact}','{add_new_contact_text}',"javascript:Loadjs('contact.php')");
	if($_SESSION["uid"]==-100){$add=null;}		
	$html="<p style='font-size:18px'>{search}:&laquo;$stringtofind&raquo; ($count {entries})</p>
	
	<center>
	<table style='width:100%'>
	<tr>
	<td valign='top'>". implode("\n",$tables). "
		
	</td>
	<td valign='top'>
	$add
	</td>
	</tr>
	</table>
	
	</center>";
	
	$html=$tpl->_ENGINE_parse_body($html);
	SET_CACHED(__FILE__,__FUNCTION__,$keycached,$html);
	echo $html;
	
}