Exemple #1
0
function members_list()
{
    $page = 1;
    $MyPage = CurrentPageName();
    $users = new usersMenus();
    $tpl = new templates();
    $sock = new sockets();
    $q = new mysql();
    $table = "user";
    $tableOrg = $table;
    $database = "mysql";
    $instance_id = $_GET["instance-id"];
    if (!is_numeric($instance_id)) {
        $instance_id = 0;
    }
    if ($instance_id > 0) {
        $q = new mysql_multi($instance_id);
    }
    $FORCE_FILTER = 1;
    $t = $_GET["t"];
    if ($q->COUNT_ROWS($table, $database) == 0) {
        json_error_show("{$table}/{$database} is empty");
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if ($_POST["query"] != null) {
        $_POST["query"] = str_replace("*", "%", $_POST["query"]);
        $search = $_POST["query"];
        $searchstring = "AND (`{$_POST["qtype"]}` LIKE '{$search}')";
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE {$FORCE_FILTER} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database));
        if (!$q->ok) {
            json_error_show("{$q->mysql_error} <strong>{$sql}</strong>");
        }
        $total = $ligne["TCOUNT"];
    } else {
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE {$FORCE_FILTER}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database));
        if (!$q->ok) {
            json_error_show("{$q->mysql_error} <strong>{$sql}</strong>");
        }
        $total = $ligne["TCOUNT"];
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    if ($OnlyEnabled) {
        $limitSql = null;
    }
    $sql = "SELECT *  FROM `{$table}` WHERE  {$FORCE_FILTER} {$searchstring} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql, $database);
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (mysql_num_rows($results) == 0) {
        json_error_show("Query return empty array, {$sql}, ({$q->mysql_error})");
    }
    $mysqlD = new mysqlserver();
    $griseNoIp = false;
    if ($mysqlD->main_array["skip_name_resolve"] == "yes") {
        $griseNoIp = true;
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        $password = $ligne["Password"];
        if ($classtr == "oddRow") {
            $classtr = null;
        } else {
            $classtr = "oddRow";
        }
        $array = array("host" => $ligne["Host"], "user" => $ligne["User"]);
        $databaseText = null;
        $dbs = members_list_access_db($ligne["User"], $ligne["Host"], $_GET["instance-id"]);
        if (count($dbs) == 0) {
            $databaseText = "<span style='color:#9B9999'>{no_database_selected}</span>";
        } else {
            while (list($key, $line) = each($dbs)) {
                $databaseText = $databaseText . "{$key}, ";
            }
        }
        $color = "black";
        if ($griseNoIp) {
            if ($ligne["Host"] != "%") {
                if ($ligne["Host"] != "localhost") {
                    if (!preg_match("#^[0-9\\%]+\\.[0-9\\%]+\\.[0-9\\%]+#", $ligne["Host"])) {
                        $color = "#9B9999";
                    }
                }
            }
        }
        $ligne["Host"] = str_replace("%", "{all}", $ligne["Host"]);
        $databaseText = $tpl->_ENGINE_parse_body($databaseText);
        $md5S = md5("{$ligne["User"]}@{$ligne["Host"]}{$databaseText}");
        $delete = imgsimple("delete-32.png", "{delete}", "DeleteMysqlUser{$t}('" . base64_encode(serialize($array)) . "','{$ligne["User"]}@{$ligne["Host"]}','{$md5S}')");
        $data['rows'][] = array('id' => $md5S, 'cell' => array("<code style='font-size:16px;color:{$color}'>{$ligne["User"]}@{$ligne["Host"]}</code>", "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('{$MyPage}?selectDB-js=yes&host={$ligne["Host"]}&user={$ligne["User"]}&instance-id={$_GET["instance-id"]}&t={$t}')\"\n\t\t\tstyle='font-size:16px;font-weight:bold;text-decoration:underline;color:{$color}'\n\t\t\t>{$databaseText}</a>", "<center>{$delete}</center>"));
    }
    echo json_encode($data);
}
function rows_list_json()
{
    $search = $_GET["search"];
    $MyPage = CurrentPageName();
    $page = 1;
    $users = new usersMenus();
    $tpl = new templates();
    $sock = new sockets();
    $q = new mysql();
    $table = $_GET["table"];
    $tableOrg = $table;
    $database = $_GET["database"];
    $fields = unserialize(base64_decode($_GET["fields"]));
    $sqlQuery = base64_decode($_GET["sql"]);
    $instance_id = $_GET["instance-id"];
    if (!is_numeric($instance_id)) {
        $instance_id = 0;
    }
    if ($instance_id > 0) {
        $q = new mysql_multi($instance_id);
    }
    if (!is_array($fields)) {
        json_error_show("Fields is empty {$_GET["fields"]}");
    }
    $t = $_GET["t"];
    if ($q->COUNT_ROWS($table, $database) == 0) {
        json_error_show("{$table} is empty");
    }
    if ($sqlQuery != null) {
        $table = "({$sqlQuery}) as tt";
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if ($_POST["query"] != null) {
        $_POST["query"] = str_replace("*", "%", $_POST["query"]);
        $search = $_POST["query"];
        $searchstring = "AND (`{$_POST["qtype"]}` LIKE '{$search}')";
        $sql = "SELECT COUNT(*) as TCOUNT FROM {$table} WHERE 1 {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database));
        if (!$q->ok) {
            json_error_show("{$q->mysql_error}");
        }
        $total = $ligne["TCOUNT"];
        if ($total == 0) {
            json_error_show("No rows {$sql}");
        }
    } else {
        if ($sqlQuery != null) {
            $sql = "SELECT COUNT(*) as TCOUNT FROM {$table}";
            $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database));
            $total = $ligne["TCOUNT"];
        } else {
            $total = $q->COUNT_ROWS($table, $database);
        }
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    if ($OnlyEnabled) {
        $limitSql = null;
    }
    if ($sqlQuery != null) {
        $sql = $sqlQuery . " {$searchstring} {$FORCE_FILTER} {$ORDER} {$limitSql}";
    } else {
        $sql = "SELECT *  FROM {$tableOrg} WHERE 1 {$searchstring} {$FORCE_FILTER} {$ORDER} {$limitSql}";
    }
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql, $database);
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (mysql_num_rows($results) == 0) {
        json_error_show("Query return empty array, {$sql}, ({$q->mysql_error})");
    }
    $ldap = new clladp();
    while ($ligne = mysql_fetch_assoc($results)) {
        reset($fields);
        $cells = array();
        while (list($key, $line) = each($fields)) {
            $cellencoded = base64_encode($ligne[$key]);
            $cells[] = "<a href=\"javascript:blur();\" Onclick=\"javascript:Loadjs('admin.index.php?json-error-js={$cellencoded}');\">{$ligne[$key]}</a>";
        }
        $data['rows'][] = array('id' => md5(serialize($ligne)), 'cell' => $cells);
    }
    echo json_encode($data);
}