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