Marius Cramer
2015-08-06 37b29231e47a0c4458dc1c15d98588f16f07e1e2
commit | author | age
a73335 1 <?php
7fe908 2 require_once '../../lib/config.inc.php';
MC 3 require_once '../../lib/app.inc.php';
a73335 4
M 5 /******************************************
6 * Begin Form configuration
7 ******************************************/
8
9 $list_def_file = "list/web_sites_stats.list.php";
10
11 /******************************************
12 * End Form configuration
13 ******************************************/
14
15 //* Check permissions for module
16 $app->auth->check_module_permissions('sites');
17
91c842 18 $app->uses('functions');
FS 19
a73335 20 $app->load('listform_actions');
M 21
22 class list_action extends listform_actions {
7fe908 23
6ac26d 24     private $sum_this_month = 0;
T 25     private $sum_this_year = 0;
26     private $sum_last_month = 0;
27     private $sum_last_year = 0;
7fe908 28
a73335 29     function prepareDataRow($rec)
7fe908 30     {
a73335 31         global $app;
7fe908 32
a73335 33         $rec = $app->listform->decode($rec);
M 34
35         //* Alternating datarow colors
36         $this->DataRowColor = ($this->DataRowColor == '#FFFFFF') ? '#EEEEEE' : '#FFFFFF';
37         $rec['bgcolor'] = $this->DataRowColor;
7fe908 38
a73335 39         //* Set the statistics colums
M 40         //** Traffic of the current month
41         $tmp_year = date('Y');
7fe908 42         $tmp_month = date('m');
cc7a82 43         $tmp_rec = $app->db->queryOneRecord("SELECT SUM(traffic_bytes) as t FROM web_traffic WHERE hostname = ? AND YEAR(traffic_date) = ? AND MONTH(traffic_date) = ?", $rec['domain'], $tmp_year, $tmp_month);
91c842 44         $rec['this_month'] = $app->functions->formatBytes($tmp_rec['t']);
024e13 45         $this->sum_this_month += $tmp_rec['t'];
91c842 46
7fe908 47
a73335 48         //** Traffic of the current year
cc7a82 49         $tmp_rec = $app->db->queryOneRecord("SELECT sum(traffic_bytes) as t FROM web_traffic WHERE hostname = ? AND YEAR(traffic_date) = ?", $rec['domain'], $tmp_year);
91c842 50         $rec['this_year'] = $app->functions->formatBytes($tmp_rec['t']);
024e13 51         $this->sum_this_year += $tmp_rec['t'];
7fe908 52
a73335 53         //** Traffic of the last month
7fe908 54         $tmp_year = date('Y', mktime(0, 0, 0, date("m")-1, date("d"), date("Y")));
MC 55         $tmp_month = date('m', mktime(0, 0, 0, date("m")-1, date("d"), date("Y")));
cc7a82 56         $tmp_rec = $app->db->queryOneRecord("SELECT sum(traffic_bytes) as t FROM web_traffic WHERE hostname = ? AND YEAR(traffic_date) = ? AND MONTH(traffic_date) = ?", $rec['domain'], $tmp_year, $tmp_month);
91c842 57         $rec['last_month'] = $app->functions->formatBytes($tmp_rec['t']);
024e13 58         $this->sum_last_month += $tmp_rec['t'];
7fe908 59
a73335 60         //** Traffic of the last year
7fe908 61         $tmp_year = date('Y', mktime(0, 0, 0, date("m"), date("d"), date("Y")-1));
cc7a82 62         $tmp_rec = $app->db->queryOneRecord("SELECT sum(traffic_bytes) as t FROM web_traffic WHERE hostname = ? AND YEAR(traffic_date) = ?", $rec['domain'], $tmp_year);
91c842 63         $rec['last_year'] = $app->functions->formatBytes($tmp_rec['t']);
024e13 64         $this->sum_last_year += $tmp_rec['t'];
7fe908 65
a73335 66         //* The variable "id" contains always the index variable
M 67         $rec['id'] = $rec[$this->idx_key];
7fe908 68
a73335 69         return $rec;
M 70     }
7fe908 71
6ac26d 72     function onShowEnd()
7fe908 73     {
6ac26d 74         global $app;
7fe908 75
024e13 76         $app->tpl->setVar('sum_this_month', $app->functions->formatBytes($this->sum_this_month));
MC 77         $app->tpl->setVar('sum_this_year', $app->functions->formatBytes($this->sum_this_year));
78         $app->tpl->setVar('sum_last_month', $app->functions->formatBytes($this->sum_last_month));
79         $app->tpl->setVar('sum_last_year', $app->functions->formatBytes($this->sum_last_year));
7fe908 80         $app->tpl->setVar('sum_txt', $app->listform->lng('sum_txt'));
MC 81
6ac26d 82         $app->tpl_defaults();
T 83         $app->tpl->pparse();
84     }
7fe908 85
4e09cb 86     function getQueryString($no_limit = false) {
615a0a 87         global $app;
T 88         $sql_where = '';
89
90         //* Generate the search sql
91         if($app->listform->listDef['auth'] != 'no') {
92             if($_SESSION['s']['user']['typ'] == "admin") {
93                 $sql_where = '';
94             } else {
7fe908 95                 $sql_where = $app->tform->getAuthSQL('r', $app->listform->listDef['table']).' and';
MC 96                 //$sql_where = $app->tform->getAuthSQL('r').' and';
615a0a 97             }
7fe908 98         }
615a0a 99         if($this->SQLExtWhere != '') {
T 100             $sql_where .= ' '.$this->SQLExtWhere.' and';
101         }
7fe908 102
615a0a 103         $sql_where = $app->listform->getSearchSQL($sql_where);
T 104         if($app->listform->listDef['join_sql']) $sql_where .= ' AND '.$app->listform->listDef['join_sql'];
105         $app->tpl->setVar($app->listform->searchValues);
7fe908 106
615a0a 107         $order_by_sql = $this->SQLOrderBy;
T 108
109         //* Generate SQL for paging
110         $limit_sql = $app->listform->getPagingSQL($sql_where);
7fe908 111         $app->tpl->setVar('paging', $app->listform->pagingHTML);
615a0a 112
T 113         $extselect = '';
114         $join = '';
7fe908 115
615a0a 116         if(!empty($_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order'])){
7fe908 117             $order = str_replace(' DESC', '', $_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order']);
MC 118             list($tmp_table, $order) = explode('.', $order);
119             if($order == 'web_traffic_last_month'){
120                 $tmp_year = date('Y', mktime(0, 0, 0, date("m")-1, date("d"), date("Y")));
121                 $tmp_month = date('m', mktime(0, 0, 0, date("m")-1, date("d"), date("Y")));
122                 $extselect .= ', SUM(wt.traffic_bytes) as calctraffic';
123                 $join .= ' INNER JOIN web_traffic as wt ON '.$app->listform->listDef['table'].'.domain = wt.hostname ';
124                 $sql_where .= " AND YEAR(wt.traffic_date) = '$tmp_year' AND MONTH(wt.traffic_date) = '$tmp_month'";
125                 $order_by_sql = str_replace($app->listform->listDef['table'].'.web_traffic_last_month', 'calctraffic', $order_by_sql);
126                 $order_by_sql = "GROUP BY domain ".$order_by_sql;
127             } elseif($order == 'web_traffic_this_month'){
128                 $tmp_year = date('Y');
129                 $tmp_month = date('m');
130                 $extselect .= ', SUM(wt.traffic_bytes) as calctraffic';
131                 $join .= ' INNER JOIN web_traffic as wt ON '.$app->listform->listDef['table'].'.domain = wt.hostname ';
132                 $sql_where .= " AND YEAR(wt.traffic_date) = '$tmp_year' AND MONTH(wt.traffic_date) = '$tmp_month'";
133                 $order_by_sql = str_replace($app->listform->listDef['table'].'.web_traffic_this_month', 'calctraffic', $order_by_sql);
134                 $order_by_sql = "GROUP BY domain ".$order_by_sql;
135             } elseif($order == 'web_traffic_last_year'){
136                 $tmp_year = date('Y', mktime(0, 0, 0, date("m")-1, date("d"), date("Y")));
137                 $extselect .= ', SUM(wt.traffic_bytes) as calctraffic';
138                 $join .= ' INNER JOIN web_traffic as wt ON '.$app->listform->listDef['table'].'.domain = wt.hostname ';
139                 $sql_where .= " AND YEAR(wt.traffic_date) = '$tmp_year'";
140                 $order_by_sql = str_replace($app->listform->listDef['table'].'.web_traffic_last_year', 'calctraffic', $order_by_sql);
141                 $order_by_sql = "GROUP BY domain ".$order_by_sql;
142             } elseif($order == 'web_traffic_this_year'){
143                 $tmp_year = date('Y');
144                 $extselect .= ', SUM(wt.traffic_bytes) as calctraffic';
145                 $join .= ' INNER JOIN web_traffic as wt ON '.$app->listform->listDef['table'].'.domain = wt.hostname ';
146                 $sql_where .= " AND YEAR(wt.traffic_date) = '$tmp_year'";
147                 $order_by_sql = str_replace($app->listform->listDef['table'].'.web_traffic_this_year', 'calctraffic', $order_by_sql);
148                 $order_by_sql = "GROUP BY domain ".$order_by_sql;
149             }
615a0a 150         }
7fe908 151
615a0a 152         if($this->SQLExtSelect != '') {
7fe908 153             if(substr($this->SQLExtSelect, 0, 1) != ',') $this->SQLExtSelect = ','.$this->SQLExtSelect;
615a0a 154             $extselect .= $this->SQLExtSelect;
T 155         }
7fe908 156
615a0a 157         $table_selects = array();
T 158         $table_selects[] = trim($app->listform->listDef['table']).'.*';
159         $app->listform->listDef['additional_tables'] = trim($app->listform->listDef['additional_tables']);
160         if($app->listform->listDef['additional_tables'] != ''){
161             $additional_tables = explode(',', $app->listform->listDef['additional_tables']);
162             foreach($additional_tables as $additional_table){
163                 $table_selects[] = trim($additional_table).'.*';
164             }
165         }
166         $select = implode(', ', $table_selects);
167
168         $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";
169         return $sql;
170     }
7fe908 171
a73335 172 }
M 173
174 $list = new list_action;
511ba5 175 $list->SQLExtWhere = "(web_domain.type = 'vhost' or web_domain.type = 'vhostsubdomain' or web_domain.type = 'vhostalias')";
615a0a 176 $list->SQLOrderBy = 'ORDER BY web_domain.domain';
a73335 177 $list->onLoad();
M 178
179
7fe908 180 ?>