function LIST_GROUPS_FROM_OU_search()
{
    $ldap = new clladp();
    if ($ldap->IsKerbAuth()) {
        LIST_GROUPS_FROM_OU_search_ActiveDirectory();
        return;
    }
    if ($_POST["query"] != null) {
        $search = $_POST["query"];
    }
    $GLOBALS["NOUSERSCOUNT"] = false;
    $ou = base64_decode($_GET["ou"]);
    $sock = new sockets();
    $page = CurrentPageName();
    $tpl = new templates();
    $EnableManageUsersTroughActiveDirectory = $sock->GET_INFO("EnableManageUsersTroughActiveDirectory");
    if (!is_numeric($EnableManageUsersTroughActiveDirectory)) {
        $EnableManageUsersTroughActiveDirectory = 0;
    }
    $data = array();
    $data['page'] = 1;
    $data['total'] = 0;
    $data['rows'] = array();
    writelogs("[{$search}]: EnableManageUsersTroughActiveDirectory = {$EnableManageUsersTroughActiveDirectory} ", __FUNCTION__, __FILE__);
    $ldap = new clladp();
    if (!$ldap->IsOUUnderActiveDirectory($ou)) {
        if ($EnableManageUsersTroughActiveDirectory == 1) {
            $GLOBALS["NOUSERSCOUNT"] = true;
            $ldap = new ldapAD();
            writelogs("[{$search}]: ->hash_get_groups_from_ou_mysql({$ou},{$search}) ", __FUNCTION__, __FILE__);
            $hash = $ldap->hash_get_groups_from_ou_mysql($ou, $search, true);
        } else {
            $ldap = new clladp();
            $hash = $ldap->hash_groups($ou, 1);
        }
    } else {
        $GLOBALS["NOUSERSCOUNT"] = true;
        $EnableManageUsersTroughActiveDirectory = 1;
        include_once dirname(__FILE__) . "/ressources/class.external.ad.inc";
        $ad = new external_ad_search();
        $hash = $ad->hash_groups($ou);
    }
    $tr = array();
    $search = str_replace(".", '\\.', $search);
    $search = str_replace("*", '.*?', $search);
    if (!is_array($hash)) {
        json_error_show("No group");
    }
    $c = 0;
    while (list($num, $line) = each($hash)) {
        if (strtolower($line) == 'default_group') {
            continue;
        }
        if (strlen($search) > 2) {
            if (!preg_match("#{$search}#", $line)) {
                continue;
            }
        }
        $color = "black";
        $lineEnc = urlencode($line);
        $js = "javascript:Loadjs('domains.edit.group.tabs.php?gid={$num}&name={$lineEnc}&ou={$_GET["ou"]}&encoded=yes')";
        if (!$GLOBALS["NOUSERSCOUNT"]) {
            $gp = new groups($num);
            $members = count($gp->members_array);
            $text = $tpl->_ENGINE_parse_body("{manage_this_group}");
            if ($gp->description != null) {
                $text == $tpl->_ENGINE_parse_body($gp->description);
            }
            $c++;
            $data['rows'][] = array('id' => md5($line), 'cell' => array("<span style='font-size:14px;color:{$color};'><img src='img/group-24.png'></span>", "<a href=\"javascript:blur();\" OnClick=\"{$js}\" style='font-size:14px;color:{$color};text-decoration:underline'>{$line}</a>", "<span style='font-size:14px;color:{$color};'>{$members}</span>", "<a href=\"javascript:blur();\" OnClick=\"{$js}\" style='font-size:14px;color:{$color};text-decoration:underline'>{$text}</a>"));
        } else {
            $text = "{manage_this_group}";
            if (is_array($line)) {
                $members = $line["UsersCount"];
                $text = $tpl->_ENGINE_parse_body("{manage_this_group}");
                if ($line["description"] != null) {
                    $text = $tpl->_ENGINE_parse_body($line["description"]);
                }
                $c++;
                $data['rows'][] = array('id' => md5($line["groupname"]), 'cell' => array("<span style='font-size:14px;color:{$color};'><img src='img/group-24.png'></span>", "<a href=\"javascript:blur();\" OnClick=\"{$js}\" style='font-size:14px;color:{$color};text-decoration:underline'>{$line["groupname"]}</span>", "<span style='font-size:14px;color:{$color};'>{$members}</span>", "<span style='font-size:14px;color:{$color};'>{$text}</span>"));
            } else {
                $c++;
                $data['rows'][] = array('id' => md5($line), 'cell' => array("<span style='font-size:14px;color:{$color};'><img src='img/group-24.png'></span>", "<a href=\"javascript:blur();\" OnClick=\"{$js}\" style='font-size:14px;color:{$color};text-decoration:underline'>{$line}</span>", "<span style='font-size:14px;color:{$color};'>{$members}</span>", "<span style='font-size:14px;color:{$color};'>{$text}</span>"));
            }
        }
    }
    $data['total'] = $c;
    echo json_encode($data);
}
function find_member()
{
    $ldap = new clladp();
    if ($ldap->IsKerbAuth()) {
        find_member_active_directory();
        return;
    }
    if ($_POST["qtype"] == "find-member") {
        $tofind = $_POST["query"];
    }
    $t = $_GET["t"];
    $tt = $_GET["tt"];
    if ($_SESSION["uid"] == -100) {
        $ou = $_GET["ou"];
    } else {
        $ou = $_SESSION["ou"];
    }
    $sock = new sockets();
    if (is_base64_encoded($ou)) {
        $ou = base64_decode($ou);
    }
    if ($tofind == null) {
        $tofind = '*';
    } else {
        $tofind = "*{$tofind}*";
    }
    $tofind = str_replace('***', '*', $tofind);
    $tofind = str_replace('**', '*', $tofind);
    $tofind = str_replace('**', '*', $tofind);
    $EnableManageUsersTroughActiveDirectory = $sock->GET_INFO("EnableManageUsersTroughActiveDirectory");
    if (!is_numeric($EnableManageUsersTroughActiveDirectory)) {
        $EnableManageUsersTroughActiveDirectory = 0;
    }
    $tofind = str_replace(".", '\\.', $tofind);
    $tofind = str_replace("*", '.*?', $tofind);
    $ldap = new clladp();
    writelogs("FIND {$tofind} IN OU \"{$ou}\"", __FUNCTION__, __FILE__, __LINE__);
    if (!$ldap->IsOUUnderActiveDirectory($ou)) {
        if ($EnableManageUsersTroughActiveDirectory == 1) {
            $GLOBALS["NOUSERSCOUNT"] = true;
            $ldap = new ldapAD();
            writelogs("[{$tofind}]: ->hash_get_groups_from_ou_mysql({$ou},{$tofind}) ", __FUNCTION__, __FILE__);
            $hash = $ldap->hash_get_groups_from_ou_mysql($ou, $tofind, true);
        } else {
            $ldap = new clladp();
            $hash = $ldap->hash_groups($ou, 1);
        }
    } else {
        $hash = find_member_active_directory();
        $ldap->EnableManageUsersTroughActiveDirectory = true;
        $GLOBALS["NOUSERSCOUNT"] = true;
    }
    $number = count($hash);
    $data = array();
    $data['page'] = 0;
    $data['total'] = $number;
    $data['rows'] = array();
    $styla = "style='font-size:14px;text-decoration:underline;font-weight:bold'";
    $styleNum = "style='font-size:16px;font-weight:bold'";
    $search = string_to_flexregex();
    if (is_array($hash)) {
        while (list($num, $line) = each($hash)) {
            if (strtolower($line) == 'default_group') {
                continue;
            }
            if (strlen($search) > 2) {
                if (!preg_match("#{$search}#", $line)) {
                    continue;
                }
            }
            $text = null;
            $js = "javascript:Loadjs('domains.edit.group.php?js=yes&group-id={$num}&ou={$_GET["ou"]}&encoded=yes&tt={$t}&ttt={$tt}')";
            $delete = imgsimple("delete-24.png", "{delete} {$num}", "Loadjs('domains.delete.group.php?gpid={$num}')");
            if (!$GLOBALS["NOUSERSCOUNT"]) {
                $delete = "&nbsp;";
                $gp = new groups($num);
                $members = count($gp->members_array);
                if ($gp->description != null) {
                    $text = $gp->description;
                }
                $data['rows'][] = array('id' => $line, 'cell' => array("<a href=\"javascript:blur();\" OnClick=\"{$js}\" {$styla}>{$line}</a>", "<span {$styleNum}>{$members}</span>", "<span style='font-size:14px'>{$text}</span>", $delete));
            } else {
                if (is_array($line)) {
                    if ($line["description"] != null) {
                        $text = $line["description"];
                    }
                    if (strlen($search) > 2) {
                        if (!preg_match("#{$search}#", $line["groupname"])) {
                            continue;
                        }
                    }
                    if (!is_numeric($line["gid"])) {
                        $delete = imgsimple("delete-24-grey.png");
                    }
                    $js = "javascript:Loadjs('domains.edit.group.php?js=yes&group-id={$line["gid"]}&ou={$_GET["ou"]}&encoded=yes&tt={$t}&ttt={$tt}')";
                    $data['rows'][] = array('id' => md5($line["groupname"]), 'cell' => array("<a href=\"javascript:blur();\" OnClick=\"{$js}\" {$styla}>{$line["groupname"]}</a>", "<span {$styleNum}>{$line["UsersCount"]}</span>", "<span style='font-size:14px'>{$text}</span>", $delete));
                } else {
                    $data['rows'][] = array('id' => $line, 'cell' => array("<a href=\"javascript:blur();\" OnClick=\"{$js}\" {$styla}>{$line}</a>", "<span {$styleNum}>?</span>", "<span style='font-size:14px'></span>", $delete));
                }
            }
        }
    }
    echo json_encode($data);
}
function users_list()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $ldap = new clladp();
    if ($ldap->IsKerbAuth()) {
        users_list_active_directory();
        return;
    }
    $database = "artica_backup";
    $search = '%';
    $table = "squid_ssl";
    $page = 1;
    $FORCE_FILTER = "AND `type`='ssl-bump-wl'";
    $t = $_GET["t"];
    $sock = new sockets();
    $EnableManageUsersTroughActiveDirectory = $sock->GET_INFO("EnableManageUsersTroughActiveDirectory");
    if (!is_numeric($EnableManageUsersTroughActiveDirectory)) {
        $EnableManageUsersTroughActiveDirectory = 0;
    }
    if (is_base64_encoded($_GET["ou"])) {
        $ou_encoded = $_GET["ou"];
        $ou = base64_decode($_GET["ou"]);
    } else {
        $ou = $_GET["ou"];
        $ou_encoded = base64_encode($_GET["ou"]);
    }
    if ($_SESSION["uid"] != -100) {
        $ou = $_SESSION["ou"];
    }
    if ($_POST["query"] != null) {
        $tofind = $_POST["query"];
    }
    if ($tofind == null) {
        $tofind = '*';
    } else {
        $tofind = "*{$tofind}*";
    }
    $filter = "(&(objectClass=userAccount)(|(cn={$tofind})(mail={$tofind})(displayName={$tofind})(uid={$tofind}) (givenname={$tofind})))";
    $attrs = array("displayName", "uid", "mail", "givenname", "telephoneNumber", "title", "sn", "mozillaSecondEmail", "employeeNumber", "sAMAccountName");
    if (!$ldap->IsOUUnderActiveDirectory($ou)) {
        if ($EnableManageUsersTroughActiveDirectory == 1) {
            $cc = new ldapAD();
            $hash = $cc->find_users($ou, $tofind);
        } else {
            $ldap = new clladp();
            $dn = "ou={$ou},dc=organizations,{$ldap->suffix}";
            $hash = $ldap->Ldap_search($dn, $filter, $attrs, 150);
        }
    } else {
        $EnableManageUsersTroughActiveDirectory = 1;
        include_once dirname(__FILE__) . "/ressources/class.external.ad.inc";
        $ad = new external_ad_search();
        $hash = $ad->find_users($ou, $tofind);
    }
    $users = new user();
    $number = $hash["count"];
    if (!is_numeric($number)) {
        $number = 0;
    }
    $data = array();
    $data['page'] = 1;
    $data['total'] = $number;
    $data['rows'] = array();
    for ($i = 0; $i < $number; $i++) {
        $userARR = $hash[$i];
        $uid = $userARR["uid"][0];
        if ($EnableManageUsersTroughActiveDirectory == 1) {
            $uid = $userARR["samaccountname"][0];
        }
        if ($uid == "squidinternalauth") {
            continue;
        }
        $js = MEMBER_JS($uid, 1, 1);
        if ($userARR["sn"][0] == null && $userARR["givenname"][0] == null) {
            $userARR["sn"][0] = $uid;
        }
        $sn = texttooltip($userARR["sn"][0], "{display}:{$uid}", $js, null, 0, "font-size:13px");
        $givenname = texttooltip($userARR["givenname"][0], "{display}:{$uid}", $js, null, 0, "font-size:13px");
        $title = texttooltip($userARR["title"][0], "{display}:{$uid}", $js, null, 0, "font-size:13px");
        $mail = texttooltip($userARR["mail"][0], "{display}:{$uid}", $js, null, 0, "font-size:13px");
        $telephonenumber = texttooltip($userARR["telephonenumber"][0], "{display}:{$uid}", $js, null, 0, "font-size:13px");
        if ($userARR["telephonenumber"][0] == null) {
            $userARR["telephonenumber"][0] = "&nbsp;";
        }
        if ($userARR["mail"][0] == null) {
            $userARR["mail"][0] = "&nbsp;";
        }
        $img = imgsimple("contact-24.png", null, $js);
        $href = "<a href=\"javascript:blur();\" OnClick=\"javascript:{$js}\" style='text-decoration:underline'>";
        $dele = imgsimple("delete-24.png", null, "Loadjs('domains.delete.user.php?uid={$uid}&flexRT={$t}');");
        $data['rows'][] = array('id' => $uid, 'cell' => array($img, "<span style='font-size:14px;color:{$color}'>{$href}{$userARR["sn"][0]} {$userARR["givenname"][0]}</a><div><i>{$userARR["title"][0]}</i></span>", "<span style='font-size:14px;color:{$color}'>{$userARR["telephonenumber"][0]}</span>", "<span style='font-size:14px;color:{$color}'>{$href}{$userARR["mail"][0]}</a></span>", $dele));
    }
    echo json_encode($data);
}
function organization_management()
{
    $ou = $_GET["ou"];
    $ou_encoded = base64_encode($ou);
    $ldap = new clladp();
    $sock = new sockets();
    if (trim($ou == null)) {
        if (isset($_COOKIE["SwitchOrgTabsOu"])) {
            $_GET["ou"] = $_COOKIE["SwitchOrgTabsOu"];
        }
    }
    $usersmenus = new usersMenus();
    $usersmenus->LoadModulesEnabled();
    if ($usersmenus->AllowAddUsers or $usersmenus->AsOrgAdmin or $usersmenus->AsMessagingOrg) {
        $add_user = Paragraphe('folder-useradd-64.png', '{create_user}', '{create_user_text}', "javascript:Loadjs('domains.add.user.php?ou={$ou}')", null, 210, null, 0, true);
        $groups = Paragraphe('folder-group-64.png', "{manage_groups} ({$ou})", '{manage_groups_text}', "javascript:Loadjs('domains.edit.group.php?ou={$ou_encoded}&js=yes&popup=yes')", null, 210, 100, 0, true);
    }
    $find_members = Paragraphe('find-members-64.png', '{find_members}', '{find_members_text}', "javascript:Loadjs('domains.find.user.php?ou={$ou}')", null, 210, null, 0, true);
    if ($usersmenus->AsArticaAdministrator) {
        $delete = Paragraphe('64-cancel.png', "{delete_ou} {$ou}", '{delete_ou_text}', "javascript:Loadjs('domains.delete.org.php?ou={$ou}');", null, 210, 100, 0, true);
    }
    if ($usersmenus->AsOrgAdmin) {
        $img = $ldap->get_organization_picture($ou, 64);
        $ad_import = Paragraphe('folder-import-ad-64.png', '{ad_import}', '{ad_import_text}', "javascript:Loadjs('domains.ad.import.php?ou={$ou}')", null, 210, 0, 0, true);
        $ldap_import = Paragraphe('database-restore-64.png', '{ldap_importation}', '{ldap_importation_text}', "javascript:Loadjs('domains.ldap.import.php?ou={$ou}')", null, 210, 0, 0, true);
        $orgsettings = Paragraphe($img, '{ORG_SETTINGS}', '{ORG_SETTINGS_TEXT}', "javascript:Loadjs('domains.organization-settings.php?ou={$ou}')", null, 210, 0, 0, true);
        $orgsduplicate = Paragraphe('org-duplicate-64.png', '{EXPORT_ORG}', '{duplicate_to_remote_server}', "javascript:Loadjs('domains.organization-settings.php?ou={$ou}&js-export=yes')", null, 210, 0, 0, true);
    }
    if (!isset($_GET["miniadm"])) {
        if ($usersmenus->AsOrgAdmin or $usersmenus->AsMessagingOrg) {
            $transport = Paragraphe('folder-transport-64.png', '{localdomains}', '{localdomains_text}', "javascript:Loadjs('domains.edit.domains.php?js=yes&ou={$ou}')", null, 210, null, 0, true);
            if ($usersmenus->POSTFIX_INSTALLED) {
                $sendmail = "<div style='float:left'>" . Buildicon64('DEF_ICO_SENDTOALL', 210, 100, "?ou={$ou}") . "</div>";
            }
        }
    }
    if ($usersmenus->ARTICA_META_ENABLED) {
        if ($sock->GET_INFO("AllowArticaMetaAddUsers") != 1) {
            $add_user = null;
        }
    }
    if ($usersmenus->POSTFIX_INSTALLED) {
        $transport = null;
    }
    if ($usersmenus->EnableManageUsersTroughActiveDirectory or $ldap->IsOUUnderActiveDirectory($ou)) {
        $ad_import = Paragraphe('folder-import-ad-64-grey.png', '{ad_import}', '{ad_import_text}');
        $orgsduplicate = Paragraphe('org-duplicate-64-grey.png', '{EXPORT_ORG}', '{duplicate_to_remote_server}');
        $delete = Paragraphe('64-cancel-grey.png', '{delete_ou}', '{delete_ou_text}');
        $add_user = Paragraphe('folder-useradd-64-grey.png', '{create_user}', '{create_user_text}');
        $orgsettings = Paragraphe('64-org-settings-grey.png', '{ORG_SETTINGS}', '{ORG_SETTINGS_TEXT}');
        $ldap_import = Paragraphe('database-restore-64-grey.png', '{ldap_importation}', '{ldap_importation_text}');
    }
    $tr[] = $add_user;
    $tr[] = $groups;
    $tr[] = $find_members;
    $tr[] = $transport;
    $tr[] = $ad_import;
    $tr[] = $ldap_import;
    $tr[] = $orgsettings;
    $tr[] = $orgsduplicate;
    $tr[] = $sendmail;
    $tr[] = $delete;
    $tables[] = "<table style='width:99%' class=form><tr>";
    $t = 0;
    while (list($key, $line) = each($tr)) {
        $line = trim($line);
        if ($line == null) {
            continue;
        }
        $t = $t + 1;
        $tables[] = "<td valign='top'>{$line}</td>";
        if ($t == 3) {
            $t = 0;
            $tables[] = "</tr><tr>";
        }
    }
    if ($t < 3) {
        for ($i = 0; $i <= $t; $i++) {
            $tables[] = "<td valign='top'>&nbsp;</td>";
        }
    }
    $html = "<center><div style='width:700px'>" . implode("\n", $tables) . "</div></center>";
    return $html;
}
Beispiel #5
0
function ORGANISATIONS_LIST()
{
    $tpl = new templates();
    $ldap = new clladp();
    if ($ldap->IsKerbAuth()) {
        return ORGANISATIONS_LIST_ACTIVE_DIRECTORY();
    }
    include_once dirname(__FILE__) . "/ressources/class.external.ad.inc";
    $Mypage = CurrentPageName();
    $users = new usersMenus();
    $sock = new sockets();
    $ou_nozarafa_explain = $tpl->_ENGINE_parse_body("{ou_nozarafa_explain}");
    $t = $_GET["t"];
    $EnableManageUsersTroughActiveDirectory = $sock->GET_INFO("EnableManageUsersTroughActiveDirectory");
    if (!is_numeric($EnableManageUsersTroughActiveDirectory)) {
        $EnableManageUsersTroughActiveDirectory = 0;
    }
    $AllowInternetUsersCreateOrg = $sock->GET_INFO("AllowInternetUsersCreateOrg");
    if ($EnableManageUsersTroughActiveDirectory == 1) {
        $ldap = new ldapAD();
        $hash = $ldap->hash_get_ou(true);
    } else {
        $ldap = new clladp();
        $hash = $ldap->hash_get_ou(true);
    }
    if (!is_array($hash)) {
        json_error_show("No data...");
    }
    ksort($hash);
    if ($EnableManageUsersTroughActiveDirectory == 0) {
        if (!$ldap->BuildOrganizationBranch()) {
            json_error_show("{GENERIC_LDAP_ERROR}<br>{$ldap->ldap_last_error}");
        }
    }
    if ($_POST["query"] != null) {
        $search = $_POST["query"];
        $search = str_replace(".", "\\.", $search);
        $search = str_replace("*", ".*?", $search);
    }
    if (isset($_GET["ajaxmenu"])) {
        $ajax = true;
    }
    $pic = "32-environement.png";
    $style = "style='font-size:16px;'";
    $c = 0;
    $ldap2 = new clladp();
    if (count($hash) == 0) {
        json_error_show("no data");
    }
    while (list($num, $ligne) = each($hash)) {
        $ou = $ligne;
        $ou_encoded = base64_encode($ou);
        if (!preg_match("#{$search}#i", $ligne)) {
            writelogs("'{$ligne}' NO MATCH {$search}", __FUNCTION__, __FILE__, __LINE__);
            continue;
        }
        $md = md5(serialize($hash) . time());
        $md5S = $md;
        $uri = "javascript:Loadjs('domains.manage.org.index.php?js=yes&ou={$ligne}');";
        if ($ajax) {
            $uri = "javascript:Loadjs('{$Mypage}?LoadOrgPopup={$ligne}');";
        }
        $IsOUUnderActiveDirectory = $ldap2->IsOUUnderActiveDirectory($ou);
        $GroupsNB = 0;
        if ($EnableManageUsersTroughActiveDirectory == 0) {
            $img = $ldap->get_organization_picture($ligne, 32);
            writelogs("ldap->CountDeUSerOu({$ligne})", __FUNCTION__, __FILE__, __LINE__);
            $usersNB = $ldap->CountDeUSerOu($ligne);
            $usersNB = "{$usersNB}";
        } else {
            $img = $pic;
            if ($IsOUUnderActiveDirectory) {
                $ad = new external_ad_search();
                writelogs("ldap->CountDeUSerOu({$ligne})", __FUNCTION__, __FILE__, __LINE__);
                $usersNB = $ad->CountDeUSerOu($ligne);
            } else {
                writelogs("ldap->CountDeUSerOu({$ligne})", __FUNCTION__, __FILE__, __LINE__);
                $usersNB = $ldap->CountDeUSerOu($ligne);
                $usersNB = "{$usersNB}";
            }
        }
        $delete = imgtootltip("delete-32-grey.png", "<b>{delete_ou} {$ligne}</b><br><i>{delete_ou_text}</i>");
        if ($users->AsArticaAdministrator) {
            $delete = Paragraphe('64-cancel.png', "{delete_ou} {$ligne}", '{delete_ou_text}', "javascript:Loadjs('domains.delete.org.php?ou={$ligne}');", null, 210, 100, 0, true);
            $delete = imgsimple("delete-32.png", "<b>{delete_ou} {$ligne}</b><br><i>{delete_ou_text}</i>", "javascript:Loadjs('domains.delete.org.php?ou={$ligne}&t={$t}&id-table={$md5S}');");
        }
        $DomainsNB = $ldap->CountDeDomainsOU($ligne);
        if ($GroupsNB == 0) {
            if ($IsOUUnderActiveDirectory) {
                $ad = new external_ad_search();
                writelogs("->CountDeGroups({$ou})", __FUNCTION__, __FILE__, __LINE__);
                $GroupsNB = $ad->CountDeGroups($ou);
            } else {
                writelogs("->CountDeGroups({$ou})", __FUNCTION__, __FILE__, __LINE__);
                $GroupsNB = $ldap->CountDeGroups($ou);
            }
        }
        Paragraphe('folder-useradd-64.png', '{create_user}', '{create_user_text}', "javascript:Loadjs('domains.add.user.php?ou={$ou}')", null, 210, null, 0, true);
        Paragraphe('64-folder-group-add.png', '{create_user}', '{create_user_text}', "javascript:Loadjs('domains.add.user.php?ou={$ou}')", null, 210, null, 0, true);
        Paragraphe("64-folder-group-add.png", "{$ou}:{add_group}", "{add_a_new_group_in_this_org}:<b>{$ou}</b>", "javascript:Loadjs('domains.edit.group.php?popup-add-group=yes&ou={$ou}&t={$t}')");
        $select = imgsimple("domain-32.png", "{manage_organisations_text}", $uri);
        $adduser = imgsimple("folder-useradd-32.png", "{$ou}<hr><b>{create_user}</b><br><i>{create_user_text}</i>", "Loadjs('domains.add.user.php?ou={$ou_encoded}&encoded=yes');");
        $addgroup = imgsimple("32-folder-group-add.png", "{$ou}<hr><b>{add_group}</b><br><i>{add_a_new_group_in_this_org}</i>", "Loadjs('domains.edit.group.php?popup-add-group=yes&ou={$ou}&t={$t}');");
        $SearchUser = imgsimple("loupe-32.png", "{$ou}<hr><b>{search}</b>:<i>{members}</i>", "Loadjs('domains.find.user.php?ou={$ou_encoded}&encoded=yes');");
        $SearchGroup = imgsimple("loupe-32.png", "{$ou}<hr><b>{search}</b>:<i>{groups}</i>", "Loadjs('domains.find.groups.php?ou={$ou_encoded}&encoded=yes&t={$t}');");
        $searchDomain = imgsimple("loupe-32.png", "{$ou}<hr><b>{localdomains}</b>:<i>{localdomains_text}</i>", "Loadjs('domains.edit.domains.php?js=yes&ou={$ou}&master-t={$t}');");
        $NOZARAFA = 0;
        $OuZarafaText = null;
        if ($IsOUUnderActiveDirectory) {
            $delete = imgtootltip("delete-24-grey.png", "", "");
            $adduser = imgsimple("folder-useradd-32-grey.png");
            $addgroup = imgsimple("32-folder-group-add-grey.png");
        }
        if ($_GET["zarafaF"] == 1) {
            $info = $ldap->OUDatas($ou);
            if (!$info["objectClass"]["zarafa-company"]) {
                $NOZARAFA = 1;
                $OuZarafaText = "<br><a href=\"javascript:blur()\" style='color:#B20808;text-decoration:underline;font-style:italic' \n\t\t\t\tOnClick=\"javascript:Loadjs('domains.edit.zarafa.php?ou={$ou_encoded}&t={$t}')\">{$ou_nozarafa_explain}</a>";
            }
        }
        $array = array();
        $array[] = "<a href=\"javascript:blur();\" \n\t\tOnClick=\"{$uri}\" style='font-size:26px;font-weight:bolder;text-transform:capitalize;\n\t\ttext-decoration:underline'>{$ligne}</strong></a>{$OuZarafaText}";
        if ($_GET["zarafaF"] == 1) {
            $zarafaEnabled = "zarafa-logo-32.png";
            if ($NOZARAFA == 1) {
                $zarafaEnabled = "zarafa-logo-32-grey.png";
            }
            $array[] = "<center>" . imgsimple($zarafaEnabled, "<strong style=font-size:26px>{$ou}:{APP_ZARAFA}</strong>\n\t\t\t\t\t<br>{ZARAFA_OU_ICON_TEXT}", "Loadjs('domains.edit.zarafa.php?ou={$ou_encoded}&t={$t}')") . "</center>";
        } else {
            $array[] = "&nbsp;";
        }
        $array[] = "<strong style='font-size:26px'>{$usersNB}</strong>";
        $array[] = "<center style='font-size:16px'>{$SearchUser}</center>";
        $array[] = "<strong style='font-size:26px'>{$GroupsNB}</strong>";
        $array[] = "<center style='font-size:16px'>{$SearchGroup}</center>";
        $array[] = "<strong style='font-size:26px'>{$DomainsNB}</strong>";
        $array[] = "<center style='font-size:16px'>{$searchDomain}</center>";
        $array[] = "<center style='font-size:16px'>{$adduser}</center>";
        $array[] = "<center style='font-size:16px'>{$addgroup}</center>";
        $array[] = "<center style='font-size:16px'>{$delete}</center>";
        $c++;
        $data['rows'][] = array('id' => $md5S, 'cell' => $array);
    }
    $total = $c;
    $data['page'] = 1;
    $data['total'] = $total;
    echo json_encode($data);
}
function find_member()
{
    if ($_POST["qtype"] == "find-member") {
        $tofind = $_POST["query"];
    }
    if ($_SESSION["uid"] == -100) {
        $ou = $_GET["ou"];
    } else {
        $ou = $_SESSION["ou"];
    }
    $sock = new sockets();
    if (is_base64_encoded($ou)) {
        $ou = base64_decode($ou);
    }
    if ($tofind == null) {
        $tofind = '*';
    } else {
        $tofind = "*{$tofind}*";
    }
    $tofind = str_replace('***', '*', $tofind);
    $tofind = str_replace('**', '*', $tofind);
    $tofind = str_replace('**', '*', $tofind);
    $EnableManageUsersTroughActiveDirectory = $sock->GET_INFO("EnableManageUsersTroughActiveDirectory");
    if (!is_numeric($EnableManageUsersTroughActiveDirectory)) {
        $EnableManageUsersTroughActiveDirectory = 0;
    }
    writelogs("FIND {$tofind} IN OU \"{$ou}\"", __FUNCTION__, __FILE__, __LINE__);
    $ldap = new clladp();
    if (!$ldap->IsOUUnderActiveDirectory($ou)) {
        if ($EnableManageUsersTroughActiveDirectory == 1) {
            $cc = new ldapAD();
            $hash = $cc->find_users($ou, $tofind);
        } else {
            $ldap = new clladp();
            $filter = "(&(objectClass=userAccount)(|(cn={$tofind})(mail={$tofind})(displayName={$tofind})(uid={$tofind}) (givenname={$tofind}) ))";
            $attrs = array("displayName", "uid", "mail", "givenname", "telephoneNumber", "title", "sn", "mozillaSecondEmail", "employeeNumber", "sAMAccountName");
            $dn = "ou={$ou},dc=organizations,{$ldap->suffix}";
            $hash = $ldap->Ldap_search($dn, $filter, $attrs, 20);
        }
    } else {
        include_once dirname(__FILE__) . "/ressources/class.external.ad.inc";
        $p = new external_ad_search();
        $hash = $p->find_users($ou, $tofind);
        $ldap->EnableManageUsersTroughActiveDirectory = true;
    }
    $users = new user();
    $number = $hash["count"];
    $data = array();
    $data['page'] = 0;
    $data['total'] = $number;
    $data['rows'] = array();
    for ($i = 0; $i < $number; $i++) {
        $user = $hash[$i];
        $data['rows'][] = formatUser($user, $ldap->EnableManageUsersTroughActiveDirectory);
    }
    echo json_encode($data);
}
function users_search()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $ldap = new clladp();
    if ($ldap->IsKerbAuth()) {
        users_search_directory();
        return;
    }
    $page = 1;
    $t = $_GET["t"];
    $sock = new sockets();
    $EnableManageUsersTroughActiveDirectory = $sock->GET_INFO("EnableManageUsersTroughActiveDirectory");
    if (!is_numeric($EnableManageUsersTroughActiveDirectory)) {
        $EnableManageUsersTroughActiveDirectory = 0;
    }
    if (is_base64_encoded($_GET["ou"])) {
        $ou_encoded = $_GET["ou"];
        $ou = base64_decode($_GET["ou"]);
    } else {
        $ou = $_GET["ou"];
        $ou_encoded = base64_encode($_GET["ou"]);
    }
    if ($_SESSION["uid"] != -100) {
        $ou = $_SESSION["ou"];
    }
    if ($_POST["query"] != null) {
        $tofind = $_POST["query"];
    }
    if ($tofind == null) {
        $tofind = '*';
    } else {
        $tofind = "*{$tofind}*";
    }
    $filter = "(&(objectClass=userAccount)(|(cn={$tofind})(mail={$tofind})(displayName={$tofind})(uid={$tofind}) (givenname={$tofind})))";
    $attrs = array("displayName", "uid", "mail", "givenname", "telephoneNumber", "title", "sn", "mozillaSecondEmail", "employeeNumber", "sAMAccountName");
    if (!$ldap->IsOUUnderActiveDirectory($ou)) {
        if ($EnableManageUsersTroughActiveDirectory == 1) {
            $cc = new ldapAD();
            $hash = $cc->find_users($ou, $tofind);
        } else {
            $ldap = new clladp();
            $dn = "ou={$ou},dc=organizations,{$ldap->suffix}";
            $hash = $ldap->Ldap_search($dn, $filter, $attrs, 150);
        }
    } else {
        $EnableManageUsersTroughActiveDirectory = 1;
        include_once dirname(__FILE__) . "/ressources/class.external.ad.inc";
        $ad = new external_ad_search();
        $hash = $ad->find_users($ou, $tofind);
    }
    $boot = new boostrap_form();
    $users = new user();
    $number = $hash["count"];
    if (!is_numeric($number)) {
        $number = 0;
    }
    $data = array();
    $data['page'] = 1;
    $data['total'] = $number;
    $data['rows'] = array();
    $styleTD = " style='font-size:16px'";
    for ($i = 0; $i < $number; $i++) {
        $userARR = $hash[$i];
        $uid = $userARR["uid"][0];
        if ($EnableManageUsersTroughActiveDirectory == 1) {
            $uid = $userARR["samaccountname"][0];
        }
        if ($uid == "squidinternalauth") {
            continue;
        }
        $js = MEMBER_JS($uid, 1, 1);
        if ($userARR["sn"][0] == null && $userARR["givenname"][0] == null) {
            $userARR["sn"][0] = $uid;
        }
        $sn = texttooltip($userARR["sn"][0], "{display}:{$uid}", $js, null, 0, "font-size:13px");
        $givenname = texttooltip($userARR["givenname"][0], "{display}:{$uid}", $js, null, 0, "font-size:13px");
        $title = texttooltip($userARR["title"][0], "{display}:{$uid}", $js, null, 0, "font-size:13px");
        $mail = texttooltip($userARR["mail"][0], "{display}:{$uid}", $js, null, 0, "font-size:13px");
        $telephonenumber = texttooltip($userARR["telephonenumber"][0], "{display}:{$uid}", $js, null, 0, "font-size:13px");
        if ($userARR["telephonenumber"][0] == null) {
            $userARR["telephonenumber"][0] = "&nbsp;";
        }
        if ($userARR["mail"][0] == null) {
            $userARR["mail"][0] = "&nbsp;";
        }
        $dele = imgsimple("delete-24.png", null, "Loadjs('domains.delete.user.php?uid={$uid}&flexRT={$t}');");
        $link = $boot->trswitch($js);
        $tr[] = "\n\t\t<tr id='{$id}'>\n\t\t<td {$styleTD} width=99% nowrap {$link}><i class='icon-user'></i>&nbsp;{$userARR["sn"][0]} {$userARR["givenname"][0]}<div><i>{$userARR["title"][0]}</i></td>\n\t\t<td {$styleTD} width=99% nowrap {$link}>{$userARR["telephonenumber"][0]}</td>\n\t\t<td {$styleTD} width=99% nowrap {$link}>{$userARR["mail"][0]}</td>\n\t\t<td width=35px align='center' nowrap>{$dele}</td>\n\t\t</tr>";
    }
    echo $tpl->_ENGINE_parse_body("\n\t\n\t\t<table class='table table-bordered table-hover'>\n\t\n\t\t\t<thead>\n\t\t\t\t<tr>\n\t\t\t\t\t<th>{member}</th>\n\t\t\t\t\t<th>{phone}</th>\n\t\t\t\t\t<th>{email}</th>\n\t\t\t\t\t<th>&nbsp;</th>\n\t\t\t\t</tr>\n\t\t\t</thead>\n\t\t\t <tbody>\n\t\t\t") . @implode("\n", $tr) . " </tbody>\n\t\t\t\t</table>";
}