From 2f07ae7b851106a634c3fb0923e4bb7f3eaf32e4 Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Wed, 28 May 2008 18:57:35 +0000
Subject: [PATCH] Added mailbox traffic statistics to the interface.

---
 .../lib/classes/listform_actions.inc.php      |  6 +-
 .../mail/lib/lang/en_mail_user_stats_list.lng | 14 ++++
 interface/web/mail/lib/module.conf.php        | 12 ++++
 .../web/mail/list/mail_user_stats.list.php    | 60 +++++++++++++++++
 interface/web/mail/mail_user_stats.php        | 66 +++++++++++++++++++
 .../mail/templates/mail_user_stats_list.htm   | 33 ++++++++++
 6 files changed, 188 insertions(+), 3 deletions(-)
 create mode 100644 interface/web/mail/lib/lang/en_mail_user_stats_list.lng
 create mode 100644 interface/web/mail/list/mail_user_stats.list.php
 create mode 100644 interface/web/mail/mail_user_stats.php
 create mode 100644 interface/web/mail/templates/mail_user_stats_list.htm

diff --git a/interface/lib/classes/listform_actions.inc.php b/interface/lib/classes/listform_actions.inc.php
index 7e02066c29..6df910cdad 100644
--- a/interface/lib/classes/listform_actions.inc.php
+++ b/interface/lib/classes/listform_actions.inc.php
@@ -38,8 +38,8 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 class listform_actions {
 	
 	private $id;
-	private $idx_key;
-	private $DataRowColor;
+	public $idx_key;
+	public $DataRowColor;
 	public  $SQLExtWhere = '';
 	public  $SQLOrderBy = '';
 	
@@ -82,7 +82,7 @@ class listform_actions {
 		
 	}
 	
-	private function prepareDataRow($rec)
+	public function prepareDataRow($rec)
     {
 		global $app;
 		
diff --git a/interface/web/mail/lib/lang/en_mail_user_stats_list.lng b/interface/web/mail/lib/lang/en_mail_user_stats_list.lng
new file mode 100644
index 0000000000..75cca6dd4d
--- /dev/null
+++ b/interface/web/mail/lib/lang/en_mail_user_stats_list.lng
@@ -0,0 +1,14 @@
+<?php
+$wb["list_head_txt"] = 'Mail traffic statistic';
+$wb["email_txt"] = 'Email';
+$wb["this_month_txt"] = 'This month';
+$wb["last_month_txt"] = 'Last month';
+$wb["this_year_txt"] = 'This year';
+$wb["last_year_txt"] = 'Last year';
+$wb["page_txt"] = 'Page';
+$wb["page_of_txt"] = 'of';
+$wb["page_next_txt"] = 'Next';
+$wb["page_back_txt"] = 'Back';
+$wb["delete_txt"] = 'Delete';
+$wb["filter_txt"] = 'Filter';
+?>
\ No newline at end of file
diff --git a/interface/web/mail/lib/module.conf.php b/interface/web/mail/lib/module.conf.php
index 6e57cbd7e5..de55cbacf9 100644
--- a/interface/web/mail/lib/module.conf.php
+++ b/interface/web/mail/lib/module.conf.php
@@ -80,7 +80,19 @@ $module['nav'][] = array(	'title'	=> 'Fetchmail',
 							'open' 	=> 1,
 							'items'	=> $items);
 
+//**** Statistics menu
+$items = array();
+
+$items[] = array( 'title' 	=> 'Mailboxes',
+				  'target' 	=> 'content',
+				  'link'	=> 'mail/mail_user_stats.php');
 
+
+$module['nav'][] = array(	'title'	=> 'Statistics',
+							'open' 	=> 1,
+							'items'	=> $items);
+							
+							
 //**** Global filters menu
 $items = array();
 if($_SESSION['s']['user']['typ'] == 'admin') {
diff --git a/interface/web/mail/list/mail_user_stats.list.php b/interface/web/mail/list/mail_user_stats.list.php
new file mode 100644
index 0000000000..31930418b6
--- /dev/null
+++ b/interface/web/mail/list/mail_user_stats.list.php
@@ -0,0 +1,60 @@
+<?php
+
+/*
+	Datatypes:
+	- INTEGER
+	- DOUBLE
+	- CURRENCY
+	- VARCHAR
+	- TEXT
+	- DATE
+*/
+
+
+
+// Name of the list
+$liste["name"] 				= "mail_user_stats";
+
+// Database table
+$liste["table"] 			= "mail_user";
+
+// Index index field of the database table
+$liste["table_idx"]			= "mailuser_id";
+
+// Search Field Prefix
+$liste["search_prefix"] 	= "search_";
+
+// Records per page
+$liste["records_per_page"] 	= 15;
+
+// Script File of the list
+$liste["file"]				= "mail_user_stats.php";
+
+// Script file of the edit form
+$liste["edit_file"]			= "mail_user_edit.php";
+
+// Script File of the delete script
+$liste["delete_file"]		= "mail_user_del.php";
+
+// Paging Template
+$liste["paging_tpl"]		= "templates/paging.tpl.htm";
+
+// Enable auth
+$liste["auth"]				= "yes";
+
+
+/*****************************************************
+* Suchfelder
+*****************************************************/
+
+$liste["item"][] = array(	'field'		=> "email",
+							'datatype'	=> "VARCHAR",
+							'formtype'	=> "TEXT",
+							'op'		=> "like",
+							'prefix'	=> "%",
+							'suffix'	=> "%",
+							'width'		=> "",
+							'value'		=> "");
+
+
+?>
\ No newline at end of file
diff --git a/interface/web/mail/mail_user_stats.php b/interface/web/mail/mail_user_stats.php
new file mode 100644
index 0000000000..ad431e91fd
--- /dev/null
+++ b/interface/web/mail/mail_user_stats.php
@@ -0,0 +1,66 @@
+<?php
+require_once('../../lib/config.inc.php');
+require_once('../../lib/app.inc.php');
+
+/******************************************
+* Begin Form configuration
+******************************************/
+
+$list_def_file = "list/mail_user_stats.list.php";
+
+/******************************************
+* End Form configuration
+******************************************/
+
+// Checking module permissions
+if(!stristr($_SESSION["s"]["user"]["modules"],'mail')) {
+	header("Location: ../index.php");
+	exit;
+}
+
+$app->load('listform_actions');
+
+class list_action extends listform_actions {
+	
+	function prepareDataRow($rec)
+    {
+		global $app;
+		
+		$rec = $app->listform->decode($rec);
+
+		//* Alternating datarow colors
+		$this->DataRowColor = ($this->DataRowColor == '#FFFFFF') ? '#EEEEEE' : '#FFFFFF';
+		$rec['bgcolor'] = $this->DataRowColor;
+		
+		//* Set the statistics colums
+		//** Traffic of the current month
+		$tmp_date = date('Y-m');
+		$tmp_rec = $app->db->queryOneRecord("SELECT traffic as t FROM mail_traffic WHERE mailuser_id = ".$rec['mailuser_id']." AND month = '$tmp_date'");
+		$rec['this_month'] = number_format(intval($tmp_rec['t'])/1024, 0, '.', ' ');
+		
+		//** Traffic of the current year
+		$tmp_date = date('Y');
+		$tmp_rec = $app->db->queryOneRecord("SELECT sum(traffic) as t FROM mail_traffic WHERE mailuser_id = ".$rec['mailuser_id']." AND month like '$tmp_date%'");
+		$rec['this_year'] = number_format(intval($tmp_rec['t'])/1024, 0, '.', ' ');
+		
+		//** Traffic of the last month
+		$tmp_date = date('Y-m',mktime(0, 0, 0, date("m")-1, date("d"), date("Y")));
+		$tmp_rec = $app->db->queryOneRecord("SELECT traffic as t FROM mail_traffic WHERE mailuser_id = ".$rec['mailuser_id']." AND month = '$tmp_date'");
+		$rec['last_month'] = number_format(intval($tmp_rec['t'])/1024, 0, '.', ' ');
+		
+		//** Traffic of the last year
+		$tmp_date = date('Y',mktime(0, 0, 0, date("m"), date("d"), date("Y")-1));
+		$tmp_rec = $app->db->queryOneRecord("SELECT sum(traffic) as t FROM mail_traffic WHERE mailuser_id = ".$rec['mailuser_id']." AND month like '$tmp_date%'");
+		$rec['last_year'] = number_format(intval($tmp_rec['t'])/1024, 0, '.', ' ');
+		
+		//* The variable "id" contains always the index variable
+		$rec['id'] = $rec[$this->idx_key];
+		return $rec;
+	}
+}
+
+$list = new list_action;
+$list->onLoad();
+
+
+?>
\ No newline at end of file
diff --git a/interface/web/mail/templates/mail_user_stats_list.htm b/interface/web/mail/templates/mail_user_stats_list.htm
new file mode 100644
index 0000000000..a6e4aaff34
--- /dev/null
+++ b/interface/web/mail/templates/mail_user_stats_list.htm
@@ -0,0 +1,33 @@
+<div class="frmTextHead"><tmpl_var name="list_head_txt"></div><br />
+<table width="100%" border="0" cellspacing="0" cellpadding="4" class="listTable">
+  <tr>
+    <td class="tblHead"><tmpl_var name="email_txt"></td>
+	<td class="tblHead"><tmpl_var name="this_month_txt"></td>
+	<td class="tblHead"><tmpl_var name="last_month_txt"></td>
+	<td class="tblHead"><tmpl_var name="this_year_txt"></td>
+	<td class="tblHead"><tmpl_var name="last_year_txt"></td>
+    <td class="tblHead">&nbsp;</td>
+  </tr>
+  <tr>
+    <td class="frmText11"><input type="text" name="search_email" value="{tmpl_var name='search_email'}" class="text" /></td>
+	<td class="frmText11">&nbsp;</td>
+	<td class="frmText11">&nbsp;</td>
+	<td class="frmText11">&nbsp;</td>
+	<td class="frmText11">&nbsp;</td>
+    <td class="frmText11" align="right"><input name="Filter" type="button" id="Filter" value="{tmpl_var name="filter_txt"}" class="button" onClick="submitForm('pageForm','mail/mail_user_stats.php');"><div class="buttonEnding"></div></td>
+  </tr>
+  <tmpl_loop name="records">
+  <tr bgcolor="{tmpl_var name="bgcolor"}">
+    <td class="frmText11"><a href="#" onClick="loadContent('mail/mail_user_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="email"}</a></td>
+    <td class="frmText11"><a href="#" onClick="loadContent('mail/mail_user_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="this_month"} KB</a></td>
+	<td class="frmText11"><a href="#" onClick="loadContent('mail/mail_user_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="last_month"} KB</a></td>
+	<td class="frmText11"><a href="#" onClick="loadContent('mail/mail_user_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="this_year"} KB</a></td>
+	<td class="frmText11"><a href="#" onClick="loadContent('mail/mail_user_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="last_year"} KB</a></td>
+	<td class="frmText11" align="right">&nbsp;</td>
+  </tr>
+  </tmpl_loop>
+
+  <tr>
+  	<td colspan="6" height="40" align="center" class="tblFooter"><tmpl_var name="paging"></td>
+  </tr>
+</table>
\ No newline at end of file
-- 
GitLab