Ejemplo n.º 1
0
function query_group()
{
    if ($_GET["OnlyUsers"] == "yes") {
        $_GET["OnlyUsers"] = 1;
    }
    $users = new user();
    $query = $_POST["query"];
    $nogetent = false;
    $OnlyUsers = $_GET["OnlyUsers"];
    $OnlyGroups = $_GET["OnlyGroups"];
    $OnlyGUID = $_GET["OnlyGUID"];
    $OnlyName = $_GET["OnlyName"];
    $OnlyCheckAD = $_GET["OnlyCheckAD"];
    $UseDN = $_GET["UseDN"];
    $Zarafa = $_GET["Zarafa"];
    if (!is_numeric($_POST["rp"])) {
        $_POST["rp"] = 250;
    }
    $ObjectZarafa = false;
    if (!is_numeric($OnlyGUID)) {
        $OnlyGUID = 0;
    }
    if (!is_numeric($OnlyUsers)) {
        $OnlyUsers = 0;
    }
    if (!is_numeric($OnlyName)) {
        $OnlyName = 0;
    }
    if (!is_numeric($OnlyCheckAD)) {
        $OnlyCheckAD = 0;
    }
    if ($Zarafa == 1) {
        $nogetent = true;
        $ObjectZarafa = true;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . ":" . __LINE__ . " OnlyUsers={$OnlyUsers},OnlyGroups={$OnlyGroups}<br>\n";
    }
    $OnlyUsers = 0;
    $OnlyGroups = 1;
    $ObjectZarafa = false;
    $Zarafa = $_GET["Zarafa"];
    if ($Zarafa == 1) {
        $nogetent = true;
        $ObjectZarafa = true;
    }
    $hash = array();
    if (!isset($_GET["prepend"])) {
        $_GET["prepend"] = 0;
    } else {
        if ($_GET["prepend"] == 'yes') {
            $_GET["prepend"] = 1;
        }
        if ($_GET["prepend"] == 'no') {
            $_GET["prepend"] = 0;
        }
    }
    $WORKGROUP = null;
    $sock = new sockets();
    $ldap = new clladp();
    if ($query == null) {
        $query = "*";
    }
    if ($ldap->IsKerbAuth()) {
        $adKerb = new external_ad_search();
        if ($GLOBALS["VERBOSE"]) {
            echo "<strong>searchGroup({$query},array(),{$_POST["rp"]})</strong><br>\n";
        }
        $hash = $adKerb->searchGroup($query, array(), $_POST["rp"]);
        if ($adKerb->IsError) {
            json_error_show($adKerb->error, 1);
        }
    } else {
        if ($GLOBALS["VERBOSE"]) {
            echo "<strong>IsKerbAuth = false</strong><br>\n";
        }
        if ($OnlyGroups == 1) {
            if ($GLOBALS["VERBOSE"]) {
                echo "<strong>find_ldap_items_groups({$query},...)</strong><br>\n";
            }
            $hash = $users->find_ldap_items_groups($query, $_GET["organization"], $nogetent, $ObjectZarafa, $_POST["rp"], $OnlyGUID, $OnlyUsers, $OnlyCheckAD);
        } else {
            if ($GLOBALS["VERBOSE"]) {
                echo "<strong>find_ldap_items({$query},{$_GET["organization"]},{$nogetent},{$ObjectZarafa},{$_POST["rp"]},{$OnlyGUID},{$OnlyUsers},{$OnlyCheckAD})<br>\n";
            }
            $hash = $users->find_ldap_items($query, $_GET["organization"], $nogetent, $ObjectZarafa, $_POST["rp"], $OnlyGUID, $OnlyUsers, $OnlyCheckAD);
        }
    }
    $query = $_POST["query"];
    if ($query == null) {
        $query = "*";
    }
    $data = array();
    $data['page'] = 1;
    $data['total'] = count($hash);
    $data['rows'] = array();
    $c = 0;
    while (list($num, $ligne) = each($hash)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "<code>&raquo;{$num}&laquo; = {$ligne}</code><br>\n";
        }
        if ($num == null) {
            continue;
        }
        $gid = 0;
        if (!preg_match("#^@(.+?):(.+?)\$#", $ligne, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "<code style='color:red'>&raquo;{$ligne}&laquo; ! = ^@(.+?):([0-9]+)</code><br>\n";
            }
            continue;
        }
        if ($OnlyUsers == 1) {
            if ($GLOBALS["VERBOSE"]) {
                echo "<code style='color:red'>OnlyUsers = 1 -> next</code><br>\n";
            }
            continue;
        }
        $img = "wingroup.png";
        $Displayname = "{$re[1]}";
        $prepend = "group:";
        $gid = $re[2];
        if ($OnlyName == 1) {
            if (preg_match("#^@(.+)#", $num, $ri)) {
                $num = $ri[1];
            }
        }
        $js = "SambaBrowseSelect('{$num}','{$prepend}','{$gid}')";
        if ($_GET["callback"] != null) {
            $js = "{$_GET["callback"]}('{$num}','{$prepend}','{$gid}')";
        }
        $c++;
        if ($c > $_POST["rp"]) {
            if ($GLOBALS["VERBOSE"]) {
                echo "<code style='color:red'>\$c ({$c}) > {$_POST["rp"]} break</code><br>\n";
            }
            break;
        }
        $data['rows'][] = array('id' => md5(serialize($ligne["displayname"])), 'cell' => array("<img src='img/{$img}'>", "<span style='font-size:14px;font-weight:bolder'>{$Displayname}</span> <span style='font-size:11px'>({$num})</span>", "<span style='font-size:14px'>" . imgsimple("arrow-right-24.png", "{add}", $js) . "</span>"));
    }
    $data['total'] = $c;
    echo json_encode($data);
}