From 73c10e7e3b08c692c82c48fc4dcdb01a3a4c9ec8 Mon Sep 17 00:00:00 2001 From: Latif Khalifa Date: Mon, 7 Oct 2013 09:47:59 +0200 Subject: [PATCH] Implemented filtering --- htdocs/crashes.php | 7 +- htdocs/lib/CrashReport.php | 9 +- htdocs/lib/Layout.php | 2 +- htdocs/lib/SearchFilter.php | 178 ++++++++++++++++++++++++++++++++++++ 4 files changed, 189 insertions(+), 7 deletions(-) create mode 100644 htdocs/lib/SearchFilter.php diff --git a/htdocs/crashes.php b/htdocs/crashes.php index d8fb510..901d639 100644 --- a/htdocs/crashes.php +++ b/htdocs/crashes.php @@ -4,9 +4,12 @@ define("SITE_ROOT", realpath(dirname(__file__))); require_once SITE_ROOT . "/lib/init.php"; $S->requireUser(); -$total = CrashReport::getTotal(); -$reports = CrashReport::getReports(); +$filter = new SearchFilter(); +$total = CrashReport::getTotal($filter); +$reports = CrashReport::getReports($filter); Layout::header(); + +$filter->render(); ?>

Reports

diff --git a/htdocs/lib/CrashReport.php b/htdocs/lib/CrashReport.php index 5ec8827..176ea7c 100644 --- a/htdocs/lib/CrashReport.php +++ b/htdocs/lib/CrashReport.php @@ -61,11 +61,12 @@ class CrashReport } return $ret; } - function getTotal() + function getTotal($filter) { global $DB; - if (!$res = $DB->query("select count(id) as total from reports") OR !$row = $DB->fetchRow($res)) + $where = $filter->getWhere(); + if (!$res = $DB->query("select count(id) as total from reports $where") OR !$row = $DB->fetchRow($res)) { return 0; } @@ -75,12 +76,12 @@ class CrashReport } } - function getReports($offset = 0, $limit = 100) + function getReports($filter) { global $DB; $ret = array(); - if (!$res = $DB->query(kl_str_sql("select * from reports order by id desc limit !i offset !i", $limit, $offset))) + if (!$res = $DB->query("select * from reports " . $filter->getWhere() . kl_str_sql(" order by id desc limit !i offset !i", $filter->limit, $filter->offset))) { return $ret; } diff --git a/htdocs/lib/Layout.php b/htdocs/lib/Layout.php index 3d04cac..6e85eed 100644 --- a/htdocs/lib/Layout.php +++ b/htdocs/lib/Layout.php @@ -156,7 +156,7 @@ $().ready(function(){
- Sigularity Viewer + Singularity Viewer
Automated Crash Report Processing
diff --git a/htdocs/lib/SearchFilter.php b/htdocs/lib/SearchFilter.php new file mode 100644 index 0000000..14cc333 --- /dev/null +++ b/htdocs/lib/SearchFilter.php @@ -0,0 +1,178 @@ +sort_by = $_GET["sort_by"]; + } + + if (in_array($_GET["sort_order"], self::$sort_orders)) + { + $this->sort_by = $_GET["sort_order"]; + } + + if (strlen($_GET["os"])) + { + $this->os = $_GET["os"]; + } + + if (strlen($_GET["chan"])) + { + $this->chan = $_GET["chan"]; + } + + if (strlen($_GET["version"])) + { + $this->version = $_GET["version"]; + } + + if (strlen($_GET["page"])) + { + $this->page = $_GET["page"]; + } + + if (strlen($_GET["grid"])) + { + $this->grid = $_GET["grid"]; + } + } + + function getWhere() + { + $cond = array(); + if ($this->os) $cond[] = kl_str_sql("os_type=!s", $this->os); + if ($this->version) $cond[] = kl_str_sql("client_version=!s", $this->version); + if ($this->chan) $cond[] = kl_str_sql("client_channel=!s", $this->chan); + if ($this->grid) $cond[] = kl_str_sql("grid=!s", $this->grid); + if (!count($cond)) return ""; + return "where " . implode(" and ", $cond); + } + + function getVersions() + { + global $DB; + + $ret = array(); + $where = $this->chan ? kl_str_sql("where client_channel=!s", $this->chan) : ''; + $q = "select distinct client_version from reports $where order by client_version desc"; + if (!$res = $DB->query($q)) + { + return $ret; + } + + while ($row = $DB->fetchRow($res)) + { + $ret[] = $row["client_version"]; + } + + return $ret; + } + + function getGrids() + { + global $DB; + + $ret = array(); + $q = "select distinct grid from reports order by grid asc"; + if (!$res = $DB->query($q)) + { + return $ret; + } + + while ($row = $DB->fetchRow($res)) + { + $ret[] = $row["grid"]; + } + + return $ret; + } + + function render() + { + $ver = $this->getVersions(); + $grids = $this->getGrids(); +?> + + +
+
+
Filter
+ +
+
+ Channel
+ chan ? 'checked="checked"' : '' ?>/> + chan == "Singularity" ? 'checked="checked"' : '' ?>/> + chan == "SingularityAlpha" ? 'checked="checked"' : '' ?>/> +
+
+ +
+ Version
+ +
+ +
+
+ Operating system
+ os ? 'checked="checked"' : '' ?>/> + os == "Windows NT" ? 'checked="checked"' : '' ?>/> + os == "Linux" ? 'checked="checked"' : '' ?>/> + os == "Mac OS X" ? 'checked="checked"' : '' ?> /> +
+
+ +
+ Grid
+ +
+ +
+
+ +