Пример #1
0
function items_list()
{
    //ini_set('html_errors',0);ini_set('display_errors', 1);ini_set('error_reporting', E_ALL);ini_set('error_prepend_string','');ini_set('error_append_string','');
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql_squid_builder();
    $ID = $_GET["ID"];
    $FORCE_FILTER = null;
    $search = '%';
    $table = "webfilters_sqitems";
    $page = 1;
    if ($q->COUNT_ROWS($table) == 0) {
        json_error_show("No data");
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE gpid={$ID} {$FORCE_FILTER} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
        $total = $ligne["TCOUNT"];
    } else {
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE gpid={$ID} {$FORCE_FILTER}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
        $total = $ligne["TCOUNT"];
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT *  FROM `{$table}` WHERE gpid={$ID} {$searchstring} {$FORCE_FILTER} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        json_error_show($q->mysql_error);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (mysql_num_rows($results) == 0) {
        json_error_show("no data");
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        $val = 0;
        $disable = Field_checkbox("itemid_{$ligne['ID']}", 1, $ligne["enabled"], "EnableDisableItem('{$ligne['ID']}')");
        $macname = $q->MAC_TO_NAME($ligne['pattern']);
        $ligne['pattern'] = utf8_encode($ligne['pattern']);
        $delete = imgtootltip("delete-24.png", "{delete} {$ligne['pattern']}", "DeleteGroupItem('{$ligne['ID']}')");
        $additional_text = null;
        if ($macname) {
            $additional_text = "<div style='font-size:10px'>{$macname}</div>";
        }
        if (preg_match("#AD:(.*?):(.+)#", $ligne["pattern"], $re)) {
            $dnEnc = $re[2];
            $LDAPID = $re[1];
            $ad = new ActiveDirectory($LDAPID);
            $tty = $ad->ObjectProperty(base64_decode($dnEnc));
            $entries = $ad->search_users_from_group(base64_decode($dnEnc), 0);
            $ligne['pattern'] = "Active Directory:&nbsp;" . $tty["cn"] . " - " . count($entries) . " items";
        }
        $data['rows'][] = array('id' => "item{$ligne['ID']}", 'cell' => array("<span style='font-size:13px;font-weight:bold'>{$ligne['pattern']}</span>{$additional_text}", "<div style='padding-top:5px'>{$disable}</div>", $delete));
    }
    echo json_encode($data);
}
Пример #2
0
function UsersBrowselist()
{
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . " line " . __LINE__ . "<br>\n";
    }
    $CurPage = CurrentPageName();
    $tpl = new templates();
    $search = $_POST["query"];
    $dn = base64_decode($_GET["dn"]);
    $ad = new ActiveDirectory($_GET["ADID"]);
    $Array = $ad->search_users_from_group($dn, $_POST["rp"]);
    if ($ad->ldap_last_error != null) {
        json_error_show("{$dn}  {$ad->ldap_last_error}", 1);
    }
    if (count($Array) == 0) {
        json_error_show("{$dn} no such user", 1);
    }
    $data = array();
    $data['page'] = 1;
    $data['total'] = count($Array);
    $data['rows'] = array();
    $rp = $_POST["rp"];
    if (!is_numeric($rp)) {
        $rp = 15;
    }
    if ($rp < 10) {
        $rp = 15;
    }
    $displayname = $tpl->_ENGINE_parse_body("{displayname}");
    $account = $tpl->_ENGINE_parse_body("{account}");
    $search = $_POST["query"];
    if ($search != null) {
        $search = str_replace(".", "\\.", $search);
        $search = str_replace("*", ".*?", $search);
    }
    $c = 0;
    while (list($dn, $GPARR) = each($Array)) {
        if ($search != null) {
            if (!preg_match("#{$search}#i", serialize($GPARR))) {
                continue;
            }
        }
        $icon = "user-32.png";
        $dnEnc = base64_encode($dn);
        $type = $GPARR["TYPE"];
        $GroupxName = $GPARR["cn"];
        $GroupxName = str_replace("'", "`", $GroupxName);
        $GroupxName = replace_accents($GroupxName);
        $descriptions = array();
        while (list($a, $b) = each($GPARR)) {
            $GPARR[$a] = utf8_encode($b);
        }
        $cn = htmlentities($GPARR["cn"]);
        $cn = str_replace("'", "`", $cn);
        $description = $GPARR["description"];
        $description = htmlentities($description);
        $description = str_replace("'", "`", $description);
        if ($type == "group") {
            $icon = "win7groups-32.png";
            $js = "Loadjs('{$CurPage}?UsersGroup-js=yes&GroupName={$GroupxName}&dn={$dnEnc}&ADID={$_GET["ADID"]}')";
            if ($ad->LDAP_RECURSIVE == 1) {
                writelogs("Group -> ParseUsersGroups({$dn},{$search})", __FUNCTION__, __FILE__, __LINE__);
                $newrow = ParseUsersGroups($dn, $search);
                if (count($newrow) > 0) {
                    while (list($a, $b) = each($newrow)) {
                        $data['rows'][] = $b;
                        $c++;
                        if (!$c > $rp) {
                            $data['total'] = $c;
                            echo json_encode($data);
                            return;
                        }
                    }
                }
            }
        } else {
            $cn = $GPARR["uid"];
            if (strlen($description) > 2) {
                $descriptions[] = $description;
            }
            if (strlen(trim($GPARR["name"])) > 0) {
                $descriptions[] = "<strong>{$GPARR["name"]}</strong>";
            }
            if (strlen($GPARR["displayname"]) > 0) {
                $descriptions[] = "<strong>{$displayname}:</strong>&nbsp;{$GPARR["displayname"]}";
            }
            if (strlen($GPARR["userprincipalname"]) > 0) {
                $descriptions[] = "<strong>{$account}</strong>:&nbsp;" . $GPARR["userprincipalname"];
            }
            $js = "Loadjs('ActiveDirectory.user.php?dn={$dnEnc}&ADID={$_GET["ADID"]}')";
            $js = null;
        }
        $icon = imgsimple($icon, null, "Loadjs('{$CurPage}?var-export-js={$dnEnc}&cn={$cn}&ADID={$_GET["ADID"]}')");
        $link = "<a href=\"javascript:blur();\" Onclick=\"javascript:{$js}\" style='font-size:14px;text-decoration:underline'>";
        if ($js == null) {
            $link = "<span style='font-size:14px;'>";
        }
        $md5 = md5($dn);
        $c++;
        $data['rows'][] = array('id' => $md5, 'cell' => array($icon, "<span style='font-size:14px;'>{$cn}</a></span><div style='font-size:11px'>" . @implode("<br>", $descriptions) . "</div>", $delete));
        if (count($data['rows']) > $rp) {
            $data['total'] = $c;
            echo json_encode($data);
            return;
        }
    }
    $data['total'] = $c;
    echo json_encode($data);
}