function events_search()
{
    $Mypage = CurrentPageName();
    $tpl = new templates();
    $q = new mysql_squid_builder();
    $table = "updateblks_events";
    $FORCE = 1;
    if ($_GET["category"] != null) {
        $FORCE = " `category`='{$_GET["category"]}'";
    }
    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'];
    }
    if ($_POST["query"] != null) {
        $_POST["query"] = "*" . trim($_POST["query"]) . "*";
        $_POST["query"] = str_replace("**", "*", $_POST["query"]);
        $_POST["query"] = str_replace("**", "*", $_POST["query"]);
        $_POST["query"] = str_replace("*", "%", $_POST["query"]);
        $search = $_POST["query"];
        $searchstring = "AND (`{$_POST["qtype"]}` LIKE '{$search}')";
        $sql = "SELECT * FROM {$table} WHERE {$FORCE} {$searchstring}";
        $results = $q->QUERY_SQL($sql);
        $total = mysql_num_rows($results);
        writelogs("{$sql} = `{$total}`", __FUNCTION__, __FILE__, __LINE__);
    } else {
        $sql = "SELECT COUNT(*) AS TCOUNT FROM {$table} WHERE {$FORCE}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
        $total = $ligne["TCOUNT"];
    }
    $style = "style='font-size:14px;'";
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT * FROM {$table} WHERE 1 {$searchstring} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql);
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (!$q->ok) {
        json_error_show($q->mysql_error . "<br>{$sql}");
    }
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        if ($classtr == "oddRow") {
            $classtr = null;
        } else {
            $classtr = "oddRow";
        }
        $ligne["text"] = $tpl->_ENGINE_parse_body($ligne["text"]);
        if (preg_match("#line:([0-9]+)#", $ligne["text"], $re)) {
            $ligne["text"] = str_replace("line:{$re[1]}", "", $ligne["text"]);
            $line = $re[1];
        }
        if (preg_match("#script:(.+)#", $ligne["text"], $re)) {
            $ligne["text"] = str_replace("script:{$re[1]}", "", $ligne["text"]);
            $file = $re[1];
        }
        $ligne["text"] = trim($ligne["text"]);
        $ligne["text"] = htmlentities($ligne["text"]);
        $ligne["text"] = nl2br($ligne["text"]);
        $data['rows'][] = array('id' => md5("{$ligne["zDate"]}{$ligne["text"]}"), 'cell' => array("<span {$style}>{$ligne["zDate"]}</span>", "<span {$style}>" . table_error_showZoom($ligne["text"], 0) . "<div style='font-size:11px'>{$file} Pid:{$ligne["PID"]} - {$ligne["function"]}() line:{$line}</div></span>"));
    }
    echo json_encode($data);
}
function search()
{
    $Mypage = CurrentPageName();
    $tpl = new templates();
    $q = new mysql();
    $table = "ufdbguard_admin_events";
    $database = "artica_events";
    $FORCE = 1;
    if ($_GET["category"] != null) {
        $FORCE = " `category`='{$_GET["category"]}'";
    }
    if ($q->COUNT_ROWS($table, $database) == 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'];
    }
    if ($_POST["query"] != null) {
        $_POST["query"] = "*" . trim($_POST["query"]) . "*";
        $_POST["query"] = str_replace("**", "*", $_POST["query"]);
        $_POST["query"] = str_replace("**", "*", $_POST["query"]);
        $_POST["query"] = str_replace("*", "%", $_POST["query"]);
        $search = $_POST["query"];
        $searchstring = "AND (`{$_POST["qtype"]}` LIKE '{$search}')";
        $sql = "SELECT * FROM {$table} WHERE {$FORCE} {$searchstring}";
        $results = $q->QUERY_SQL($sql, $database);
        $total = mysql_num_rows($results);
        writelogs("{$sql} = `{$total}`", __FUNCTION__, __FILE__, __LINE__);
    } else {
        $sql = "SELECT COUNT(*) AS TCOUNT FROM {$table} WHERE {$FORCE}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database));
        $total = $ligne["TCOUNT"];
    }
    $style = "style='font-size:14px;'";
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT * FROM {$table} WHERE {$FORCE} {$searchstring} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql, $database);
    if (mysql_num_rows($results) == 0) {
        json_error_show("Category: {$_GET["category"]} {$searchstring} No data");
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (!$q->ok) {
        json_error_show($q->mysql_error);
    }
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        $ligne["description"] = $tpl->_ENGINE_parse_body($ligne["description"]);
        $textadd = $tpl->_ENGINE_parse_body("<div style='font-size:11px;margin-left:-5px'><strong>{$ligne["category"]}</strong> - {$ligne["filename"]} - {$ligne["function"]}() {line}:{$ligne["line"]}</div>");
        $ligne["description"] = str_replace("\n", ",<br>", $ligne["description"]);
        $data['rows'][] = array('id' => md5("{$ligne["zDate"]}{$ligne["description"]}"), 'cell' => array("<span {$style}>{$ligne["zDate"]}</span>", "<span {$style}>" . table_error_showZoom("{$ligne["description"]}", 0) . "{$textadd}</span>"));
    }
    echo json_encode($data);
}