Marius Cramer
2015-08-06 37b29231e47a0c4458dc1c15d98588f16f07e1e2
commit | author | age
2f07ae 1 <?php
7fe908 2 require_once '../../lib/config.inc.php';
MC 3 require_once '../../lib/app.inc.php';
2f07ae 4
T 5 /******************************************
6 * Begin Form configuration
7 ******************************************/
8
9 $list_def_file = "list/mail_user_stats.list.php";
10
11 /******************************************
12 * End Form configuration
13 ******************************************/
14
910093 15 //* Check permissions for module
T 16 $app->auth->check_module_permissions('mail');
2f07ae 17
ad24a1 18 $app->uses('functions');
FS 19
2f07ae 20 $app->load('listform_actions');
T 21
22 class list_action extends listform_actions {
7fe908 23
2f07ae 24     function prepareDataRow($rec)
7fe908 25     {
2f07ae 26         global $app;
7fe908 27
2f07ae 28         $rec = $app->listform->decode($rec);
T 29
30         //* Alternating datarow colors
31         $this->DataRowColor = ($this->DataRowColor == '#FFFFFF') ? '#EEEEEE' : '#FFFFFF';
32         $rec['bgcolor'] = $this->DataRowColor;
7fe908 33
2f07ae 34         //* Set the statistics colums
T 35         //** Traffic of the current month
36         $tmp_date = date('Y-m');
2af58c 37         $tmp_rec = $app->db->queryOneRecord("SELECT traffic as t FROM mail_traffic WHERE mailuser_id = ? AND month = ?", $rec['mailuser_id'], $tmp_date);
ad24a1 38 //        $rec['this_month'] = number_format($app->functions->intval($tmp_rec['t'])/1024/1024, 0, '.', ' ');
FS 39         $rec['this_month'] = $app->functions->formatBytes($tmp_rec['t']);
40         if ($rec['this_month'] == 'NAN') $rec['this_month'] = '0 KB';
7fe908 41
2f07ae 42         //** Traffic of the current year
T 43         $tmp_date = date('Y');
2af58c 44         $tmp_rec = $app->db->queryOneRecord("SELECT sum(traffic) as t FROM mail_traffic WHERE mailuser_id = ? AND month like ?", $rec['mailuser_id'], $tmp_date . '%');
ad24a1 45 //        $rec['this_year'] = number_format($app->functions->intval($tmp_rec['t'])/1024/1024, 0, '.', ' ');
FS 46         $rec['this_year'] = $app->functions->formatBytes($tmp_rec['t']);
47         if ($rec['this_year'] == 'NAN') $rec['this_year'] = '0 KB';
7fe908 48
2f07ae 49         //** Traffic of the last month
7fe908 50         $tmp_date = date('Y-m', mktime(0, 0, 0, date("m")-1, date("d"), date("Y")));
2af58c 51         $tmp_rec = $app->db->queryOneRecord("SELECT traffic as t FROM mail_traffic WHERE mailuser_id = ? AND month = ?", $rec['mailuser_id'], $tmp_date);
ad24a1 52 //        $rec['last_month'] = number_format($app->functions->intval($tmp_rec['t'])/1024/1024, 0, '.', ' ');
FS 53         $rec['last_month'] = $app->functions->formatBytes($tmp_rec['t']);
54         if ($rec['last_month'] == 'NAN') $rec['last_month'] = '0 KB';
7fe908 55
2f07ae 56         //** Traffic of the last year
7fe908 57         $tmp_date = date('Y', mktime(0, 0, 0, date("m"), date("d"), date("Y")-1));
2af58c 58         $tmp_rec = $app->db->queryOneRecord("SELECT sum(traffic) as t FROM mail_traffic WHERE mailuser_id = ? AND month like ?", $rec['mailuser_id'], $tmp_date . '%');
ad24a1 59 //        $rec['last_year'] = number_format($app->functions->intval($tmp_rec['t'])/1024/1024, 0, '.', ' ');
FS 60         $rec['last_year'] = $app->functions->formatBytes($tmp_rec['t']);
61         if ($rec['last_year'] == 'NAN') $rec['last_year'] = '0 KB';
7fe908 62
2f07ae 63         //* The variable "id" contains always the index variable
T 64         $rec['id'] = $rec[$this->idx_key];
65         return $rec;
66     }
7fe908 67
4e09cb 68     function getQueryString($no_limit = false) {
615a0a 69         global $app;
T 70         $sql_where = '';
71
72         //* Generate the search sql
73         if($app->listform->listDef['auth'] != 'no') {
74             if($_SESSION['s']['user']['typ'] == "admin") {
75                 $sql_where = '';
76             } else {
7fe908 77                 $sql_where = $app->tform->getAuthSQL('r', $app->listform->listDef['table']).' and';
MC 78                 //$sql_where = $app->tform->getAuthSQL('r').' and';
615a0a 79             }
7fe908 80         }
615a0a 81         if($this->SQLExtWhere != '') {
T 82             $sql_where .= ' '.$this->SQLExtWhere.' and';
83         }
7fe908 84
615a0a 85         $sql_where = $app->listform->getSearchSQL($sql_where);
T 86         if($app->listform->listDef['join_sql']) $sql_where .= ' AND '.$app->listform->listDef['join_sql'];
87         $app->tpl->setVar($app->listform->searchValues);
7fe908 88
615a0a 89         $order_by_sql = $this->SQLOrderBy;
T 90
91         //* Generate SQL for paging
92         $limit_sql = $app->listform->getPagingSQL($sql_where);
7fe908 93         $app->tpl->setVar('paging', $app->listform->pagingHTML);
615a0a 94
T 95         $extselect = '';
96         $join = '';
7fe908 97
615a0a 98         if(!empty($_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order'])){
7fe908 99             $order = str_replace(' DESC', '', $_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order']);
MC 100             list($tmp_table, $order) = explode('.', $order);
101             if($order == 'mail_traffic_last_month'){
102                 $tmp_date = date('Y-m', mktime(0, 0, 0, date("m")-1, date("d"), date("Y")));
103                 $join .= ' INNER JOIN mail_traffic as mt ON '.$app->listform->listDef['table'].'.mailuser_id = mt.mailuser_id ';
104                 $sql_where .= " AND mt.month like '$tmp_date%'";
105                 $order_by_sql = str_replace($app->listform->listDef['table'].'.mail_traffic_last_month', 'traffic', $order_by_sql);
106             } elseif($order == 'mail_traffic_this_month'){
107                 $tmp_date = date('Y-m');
108                 $join .= ' INNER JOIN mail_traffic as mt ON '.$app->listform->listDef['table'].'.mailuser_id = mt.mailuser_id ';
109                 $sql_where .= " AND mt.month like '$tmp_date%'";
110                 $order_by_sql = str_replace($app->listform->listDef['table'].'.mail_traffic_this_month', 'traffic', $order_by_sql);
111             } elseif($order == 'mail_traffic_last_year'){
112                 $tmp_date = date('Y', mktime(0, 0, 0, date("m")-1, date("d"), date("Y")));
113                 $extselect .= ', SUM(mt.traffic) as calctraffic';
114                 $join .= ' INNER JOIN mail_traffic as mt ON '.$app->listform->listDef['table'].'.mailuser_id = mt.mailuser_id ';
115                 $sql_where .= " AND mt.month like '$tmp_date%'";;
116                 $order_by_sql = str_replace($app->listform->listDef['table'].'.mail_traffic_last_year', 'calctraffic', $order_by_sql);
117                 $order_by_sql = "GROUP BY mailuser_id ".$order_by_sql;
118             } elseif($order == 'mail_traffic_this_year'){
119                 $tmp_date = date('Y');
120                 $extselect .= ', SUM(mt.traffic) as calctraffic';
121                 $join .= ' INNER JOIN mail_traffic as mt ON '.$app->listform->listDef['table'].'.mailuser_id = mt.mailuser_id ';
122                 $sql_where .= " AND mt.month like '$tmp_date%'";
123                 $order_by_sql = str_replace($app->listform->listDef['table'].'.mail_traffic_this_year', 'calctraffic', $order_by_sql);
124                 $order_by_sql = "GROUP BY mailuser_id ".$order_by_sql;
125             }
615a0a 126         }
7fe908 127
615a0a 128         if($this->SQLExtSelect != '') {
7fe908 129             if(substr($this->SQLExtSelect, 0, 1) != ',') $this->SQLExtSelect = ','.$this->SQLExtSelect;
615a0a 130             $extselect .= $this->SQLExtSelect;
T 131         }
7fe908 132
615a0a 133         $table_selects = array();
T 134         $table_selects[] = trim($app->listform->listDef['table']).'.*';
135         $app->listform->listDef['additional_tables'] = trim($app->listform->listDef['additional_tables']);
136         if($app->listform->listDef['additional_tables'] != ''){
137             $additional_tables = explode(',', $app->listform->listDef['additional_tables']);
138             foreach($additional_tables as $additional_table){
139                 $table_selects[] = trim($additional_table).'.*';
140             }
141         }
142         $select = implode(', ', $table_selects);
143
144         $sql = 'SELECT '.$select.$extselect.' FROM '.$app->listform->listDef['table'].($app->listform->listDef['additional_tables'] != ''? ','.$app->listform->listDef['additional_tables'] : '')."$join WHERE $sql_where $order_by_sql $limit_sql";
145         return $sql;
146     }
7fe908 147
2f07ae 148 }
T 149
150 $list = new list_action;
151 $list->onLoad();
152
153
7fe908 154 ?>