From 820e4a545e723976ce3f4ce0e57eef02f9b3cf7d Mon Sep 17 00:00:00 2001
From: ftimme <ft@falkotimme.com>
Date: Thu, 04 Jul 2013 19:48:42 -0400
Subject: [PATCH] - Added mailbox quota dashlet.
---
interface/web/dashboard/lib/lang/en_dashlet_mailquota.lng | 8 ++
interface/web/dashboard/dashboard.php | 2
interface/web/mail/user_quota_stats.php | 13 ++-
interface/web/dashboard/dashlets/templates/mailquota.htm | 29 +++++++++
interface/web/dashboard/lib/lang/de_dashlet_mailquota.lng | 8 ++
interface/web/dashboard/dashlets/mailquota.php | 93 +++++++++++++++++++++++++++++++
6 files changed, 147 insertions(+), 6 deletions(-)
diff --git a/interface/web/dashboard/dashboard.php b/interface/web/dashboard/dashboard.php
index 9fafb6e..dae00f8 100644
--- a/interface/web/dashboard/dashboard.php
+++ b/interface/web/dashboard/dashboard.php
@@ -157,7 +157,7 @@
/* Which dashlets in which column */
/******************************************************************************/
-$leftcol_dashlets = array('modules','invoices','quota');
+$leftcol_dashlets = array('modules','invoices','quota','mailquota');
$rightcol_dashlets = array('limits');
/******************************************************************************/
diff --git a/interface/web/dashboard/dashlets/mailquota.php b/interface/web/dashboard/dashlets/mailquota.php
new file mode 100644
index 0000000..a65b06d
--- /dev/null
+++ b/interface/web/dashboard/dashlets/mailquota.php
@@ -0,0 +1,93 @@
+<?php
+
+class dashlet_mailquota {
+
+ function show() {
+ global $app, $conf;
+
+ //* Loading Template
+ $app->uses('tpl');
+
+ $tpl = new tpl;
+ $tpl->newTemplate("dashlets/templates/mailquota.htm");
+
+ $wb = array();
+ $lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_dashlet_mailquota.lng';
+ if(is_file($lng_file)) include($lng_file);
+ $tpl->setVar($wb);
+
+ $tmp_rec = $app->db->queryAllRecords("SELECT data from monitor_data WHERE type = 'email_quota' ORDER BY created DESC");
+ $monitor_data = array();
+ if(is_array($tmp_rec)) {
+ foreach ($tmp_rec as $tmp_mon) {
+ //$monitor_data = array_merge_recursive($monitor_data,unserialize($app->db->unquote($tmp_mon['data'])));
+ $tmp_array = unserialize($app->db->unquote($tmp_mon['data']));
+ if(is_array($tmp_array)) {
+ foreach($tmp_array as $username => $data) {
+ if(!$monitor_data[$username]['used']) $monitor_data[$username]['used'] = $data['used'];
+ }
+ }
+ }
+ }
+ //print_r($monitor_data);
+ if($_SESSION["s"]["user"]["typ"] != 'admin'){
+ $sql_where = " AND sys_groupid = ".$_SESSION['s']['user']['default_group'];
+ }
+
+ $has_mailquota = false;
+ // select email accounts belonging to client
+ $emails = $app->db->queryAllRecords("SELECT * FROM mail_user WHERE 1".$sql_where);
+ //print_r($emails);
+ if(is_array($emails) && !empty($emails)){
+ for($i=0;$i<sizeof($emails);$i++){
+ $email = $emails[$i]['email'];
+
+ $emails[$i]['used'] = isset($monitor_data[$email]['used']) ? $monitor_data[$email]['used'] : array(1 => 0);
+
+ if (!is_numeric($emails[$i]['used'])) $emails[$i]['used']=$emails[$i]['used'][1];
+
+ // colours
+ $emails[$i]['display_colour'] = '#000000';
+ if($emails[$i]['quota'] > 0){
+ $used_ratio = $emails[$i]['used']/$emails[$i]['quota'];
+ } else {
+ $used_ratio = 0;
+ }
+ if($used_ratio >= 0.8) $emails[$i]['display_colour'] = '#fd934f';
+ if($used_ratio >= 1) $emails[$i]['display_colour'] = '#cc0000';
+
+ if($emails[$i]['quota'] == 0){
+ $emails[$i]['quota'] = $app->lng('unlimited');
+ } else {
+ $emails[$i]['quota'] = round($emails[$i]['quota'] / 1048576,4).' MB';
+ }
+
+
+ if($emails[$i]['used'] < 1544000) {
+ $emails[$i]['used'] = round($emails[$i]['used'] / 1024,4).' KB';
+ } else {
+ $emails[$i]['used'] = round($emails[$i]['used'] / 1048576,4).' MB';
+ }
+
+ }
+ $has_mailquota = true;
+ $tpl->setloop('mailquota', $emails);
+ }
+ //print_r($sites);
+
+ $tpl->setVar('has_mailquota',$has_mailquota);
+
+ return $tpl->grab();
+
+
+ }
+}
+
+
+
+
+
+
+
+
+?>
\ No newline at end of file
diff --git a/interface/web/dashboard/dashlets/templates/mailquota.htm b/interface/web/dashboard/dashlets/templates/mailquota.htm
new file mode 100644
index 0000000..25ee9d7
--- /dev/null
+++ b/interface/web/dashboard/dashlets/templates/mailquota.htm
@@ -0,0 +1,29 @@
+<div style="float: left;">
+ <h2>{tmpl_var name='mailquota_txt'}</h2>
+ <div style="width:320px;">
+ <table class="list">
+ <thead>
+ <tr>
+ <td>{tmpl_var name='email_txt'}</td>
+ <td>{tmpl_var name='name_txt'}</td>
+ <td>{tmpl_var name='used_txt'}</td>
+ <td>{tmpl_var name='quota_txt'}</td>
+ </tr>
+ </thead>
+ <tmpl_if name="has_mailquota">
+ <tmpl_loop name='mailquota'>
+ <tr class="tbl_row_<tmpl_if name='__EVEN__'}even<tmpl_else>uneven</tmpl_if>">
+ <td style="color:{tmpl_var name='display_colour'}">{tmpl_var name='email'}</td>
+ <td style="color:{tmpl_var name='display_colour'}">{tmpl_var name='name'}</td>
+ <td style="color:{tmpl_var name='display_colour'}">{tmpl_var name='used'}</td>
+ <td style="color:{tmpl_var name='display_colour'}">{tmpl_var name='quota'}</td>
+ </tr>
+ </tmpl_loop>
+ <tmpl_else>
+ <tr>
+ <td colspan="4" style="text-align:center;">{tmpl_var name='no_email_accounts_txt'}</td>
+ </tr>
+ </tmpl_if>
+ </table>
+ </div>
+</div>
\ No newline at end of file
diff --git a/interface/web/dashboard/lib/lang/de_dashlet_mailquota.lng b/interface/web/dashboard/lib/lang/de_dashlet_mailquota.lng
new file mode 100644
index 0000000..2fb3f6d
--- /dev/null
+++ b/interface/web/dashboard/lib/lang/de_dashlet_mailquota.lng
@@ -0,0 +1,8 @@
+<?php
+$wb["mailquota_txt"] = 'Mailbox-Speicherplatz';
+$wb["email_txt"] = 'E-Mail-Adresse';
+$wb["name_txt"] = 'Name';
+$wb["used_txt"] = 'Verwendet';
+$wb["quota_txt"] = 'Verfügbar';
+$wb["no_email_accounts_txt"] = 'Kein E-Mail-Konto gefunden.';
+?>
\ No newline at end of file
diff --git a/interface/web/dashboard/lib/lang/en_dashlet_mailquota.lng b/interface/web/dashboard/lib/lang/en_dashlet_mailquota.lng
new file mode 100644
index 0000000..2c2b6cd
--- /dev/null
+++ b/interface/web/dashboard/lib/lang/en_dashlet_mailquota.lng
@@ -0,0 +1,8 @@
+<?php
+$wb["mailquota_txt"] = 'Mailbox Quota';
+$wb["email_txt"] = 'Email Address';
+$wb["name_txt"] = 'Name';
+$wb["used_txt"] = 'Used Space';
+$wb["quota_txt"] = 'Quota';
+$wb["no_email_accounts_txt"] = 'No email accounts found.';
+?>
\ No newline at end of file
diff --git a/interface/web/mail/user_quota_stats.php b/interface/web/mail/user_quota_stats.php
index 5766ff7..4933103 100644
--- a/interface/web/mail/user_quota_stats.php
+++ b/interface/web/mail/user_quota_stats.php
@@ -50,15 +50,18 @@
$rec['used'] = isset($monitor_data[$email]['used']) ? $monitor_data[$email]['used'] : array(1 => 0);
if (!is_numeric($rec['used'])) $rec['used']=$rec['used'][1];
-
- $rec['quota'] = round($rec['quota'] / 1048576,2).' MB';
- if($rec['quota'] == "0 MB") $rec['quota'] = $app->lng('unlimited');
+
+ if($rec['quota'] == 0){
+ $rec['quota'] = $app->lng('unlimited');
+ } else {
+ $rec['quota'] = round($rec['quota'] / 1048576,4).' MB';
+ }
if($rec['used'] < 1544000) {
- $rec['used'] = round($rec['used'] / 1024,2).' KB';
+ $rec['used'] = round($rec['used'] / 1024,4).' KB';
} else {
- $rec['used'] = round($rec['used'] / 1048576,2).' MB';
+ $rec['used'] = round($rec['used'] / 1048576,4).' MB';
}
//* The variable "id" contains always the index variable
--
Gitblit v1.9.1