Ejemplo n.º 1
0
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);
}