From 313d29c252ad2fad1207a59a0b2f0863b839a3e0 Mon Sep 17 00:00:00 2001 From: SJ Date: Thu, 14 Mar 2013 23:09:24 +0100 Subject: [PATCH] fixed the chart drawing --- util/db-mysql.sql | 2 +- util/db-upgrade-0.1.22-vs-0.1.23.sql | 6 ++++++ webui/controller/stat/graph.php | 15 +-------------- webui/model/stat/chart.php | 19 ++++++++++++++++--- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/util/db-mysql.sql b/util/db-mysql.sql index ea3f40d0..f8fa72a7 100644 --- a/util/db-mysql.sql +++ b/util/db-mysql.sql @@ -76,7 +76,7 @@ create index `rcpt_idx2` on `rcpt`(`to`); drop view if exists `v_messages`; -create view `v_messages` AS select `metadata`.`id` AS `id`,`metadata`.`piler_id` AS `piler_id`,`metadata`.`from` AS `from`,`metadata`.`fromdomain` AS `fromdomain`,`rcpt`.`to` AS `to`,`rcpt`.`todomain` AS `todomain`,`metadata`.`subject` AS `subject`, `metadata`.`size` AS `size`, `metadata`.`direction` AS `direction`, `metadata`.`sent` AS `sent`, `metadata`.`digest` AS `digest`, `metadata`.`bodydigest` AS `bodydigest` from (`metadata` join `rcpt`) where (`metadata`.`id` = `rcpt`.`id`); +create view `v_messages` AS select `metadata`.`id` AS `id`,`metadata`.`piler_id` AS `piler_id`,`metadata`.`from` AS `from`,`metadata`.`fromdomain` AS `fromdomain`,`rcpt`.`to` AS `to`,`rcpt`.`todomain` AS `todomain`,`metadata`.`subject` AS `subject`, `metadata`.`size` AS `size`, `metadata`.`direction` AS `direction`, `metadata`.`sent` AS `sent`, `metadata`.`arrived` AS `arrived`, `metadata`.`digest` AS `digest`, `metadata`.`bodydigest` AS `bodydigest` from (`metadata` join `rcpt`) where (`metadata`.`id` = `rcpt`.`id`); drop table if exists `attachment`; diff --git a/util/db-upgrade-0.1.22-vs-0.1.23.sql b/util/db-upgrade-0.1.22-vs-0.1.23.sql index fe412bef..297c17f5 100644 --- a/util/db-upgrade-0.1.22-vs-0.1.23.sql +++ b/util/db-upgrade-0.1.22-vs-0.1.23.sql @@ -24,3 +24,9 @@ CREATE TABLE IF NOT EXISTS `counter_stats` ( alter table metadata drop index message_id; + +drop view if exists `v_messages`; +create view `v_messages` AS select `metadata`.`id` AS `id`,`metadata`.`piler_id` AS `piler_id`,`metadata`.`from` AS `from`,`metadata`.`fromdomain` AS `fromdomain`,`rcpt`.`to` AS `to`,`rcpt`.`todomain` AS `todomain`,`metadata`.`subject` AS `subject`, `metadata`.`size` AS `size`, `metadata`.`direction` AS `direction`, `metadata`.`sent` AS `sent`, `metadata`.`arrived` AS `arrived`, `metadata`.`digest` AS `digest`, `metadata`.`bodydigest` AS `bodydigest` from (`metadata` join `rcpt`) where (`metadata`.`id` = `rcpt`.`id`); + + + diff --git a/webui/controller/stat/graph.php b/webui/controller/stat/graph.php index 1347310c..405afdfe 100644 --- a/webui/controller/stat/graph.php +++ b/webui/controller/stat/graph.php @@ -23,22 +23,9 @@ class ControllerStatGraph extends Controller { $db->select_db($db->database); - $emails = ""; - - /* let the admin users see the whole statistics */ - - if(Registry::get('admin_user') == 0 && Registry::get('readonly_admin') == 0) { - $uid = $this->model_user_user->get_uid_by_name($this->data['username']); - $emails = "AND rcpt IN ('" . preg_replace("/\n/", "','", $this->model_user_user->get_emails_by_uid((int)$uid)) . "')"; - } - else if(isset($this->request->get['uid']) && is_numeric($this->request->get['uid']) && $this->request->get['uid'] > 0){ - $emails = "AND rcpt IN ('" . preg_replace("/\n/", "','", $this->model_user_user->get_emails_by_uid((int)$this->request->get['uid'])) . "')"; - } - - $aa = new ModelStatChart(); - $aa->lineChartHamSpam($emails, $timespan, $this->data['text_archived_messages'], SIZE_X, SIZE_Y, ""); + $aa->lineChartHamSpam($timespan, $this->data['text_archived_messages'], SIZE_X, SIZE_Y, ""); } diff --git a/webui/model/stat/chart.php b/webui/model/stat/chart.php index a34e315d..31b110cf 100644 --- a/webui/model/stat/chart.php +++ b/webui/model/stat/chart.php @@ -2,7 +2,7 @@ class ModelStatChart extends Model { - public function lineChartHamSpam($emails, $timespan, $title, $size_x, $size_y, $output){ + public function lineChartHamSpam($timespan, $title, $size_x, $size_y, $output){ $ydata = array(); $ydata2 = array(); $dates = array(); @@ -25,13 +25,26 @@ class ModelStatChart extends Model { if($timespan == "daily"){ - $query = $this->db->query("select arrived-(arrived%3600) as ts, count(*) as num from " . TABLE_META . " where arrived > $range $emails $grouping ORDER BY ts DESC limit $limit"); + $delta = 3600; $date_format = "H:i"; } else { - $query = $this->db->query("select arrived-(arrived%86400) as ts, count(*) as num from " . TABLE_META . " where arrived > $range $emails $grouping ORDER BY ts DESC limit $limit"); + $delta = 86400; $date_format = "m.d."; } + if(Registry::get('admin_user') == 0) { + + $q = ''; + foreach($_SESSION['auditdomains'] as $a) { + if($q) { $q .= ",?"; } else { $q = "?"; } + } + reset($_SESSION['auditdomains']); + $query = $this->db->query("select arrived-(arrived%$delta) as ts, count(*) as num from " . VIEW_MESSAGES . " where arrived > $range AND todomain IN ($q) $domains $grouping ORDER BY ts DESC limit $limit", $_SESSION['auditdomains']); + } else { + $query = $this->db->query("select arrived-(arrived%$delta) as ts, count(*) as num from " . TABLE_META . " where arrived > $range $grouping ORDER BY ts DESC limit $limit"); + } + + foreach ($query->rows as $q) { array_push($ydata, $q['num']); array_push($dates, date($date_format, $q['ts']));