@@ -55,7 +55,34 @@ public function onLoad()
5555
5656 $ app ->tpl ->newTemplate ("listpage.tpl.htm " );
5757 $ app ->tpl ->setInclude ('content_tpl ' ,'templates/ ' .$ app ->listform ->listDef ["name " ].'_list.htm ' );
58+
59+ //* Manipulate order by for sorting / Every list has a stored value
60+ //* Against notice error
61+ if (!isset ($ _SESSION ['search ' ][$ app ->listform ->listDef ["name " ]]['order ' ])){
62+ $ _SESSION ['search ' ][$ app ->listform ->listDef ["name " ]]['order ' ] = '' ;
63+ }
64+
65+ if (!empty ($ _GET ['orderby ' ])){
66+ $ order = str_replace ('tbl_col_ ' ,'' ,$ _GET ['orderby ' ]);
67+ //* Check the css class submited value
68+ if (preg_match ("/^[a-z\_]{1,}$/ " ,$ order )) {
69+ if ($ _SESSION ['search ' ][$ app ->listform ->listDef ["name " ]]['order ' ] == $ order ){
70+ $ _SESSION ['search ' ][$ app ->listform ->listDef ["name " ]]['order ' ] = $ order .' DESC ' ;
71+ } else {
72+ $ _SESSION ['search ' ][$ app ->listform ->listDef ["name " ]]['order ' ] = $ order ;
73+ }
74+ }
75+ }
5876
77+ // If a manuel oder by like customers isset the sorting will be infront
78+ if (!empty ($ _SESSION ['search ' ][$ app ->listform ->listDef ["name " ]]['order ' ])){
79+ if (empty ($ this ->SQLOrderBy )){
80+ $ this ->SQLOrderBy = "ORDER BY " .$ _SESSION ['search ' ][$ app ->listform ->listDef ["name " ]]['order ' ];
81+ } else {
82+ $ this ->SQLOrderBy = str_replace ("ORDER BY " ,"ORDER BY " .$ _SESSION ['search ' ][$ app ->listform ->listDef ["name " ]]['order ' ].', ' ,$ this ->SQLOrderBy );
83+ }
84+ }
85+
5986 // Getting Datasets from DB
6087 $ records = $ app ->db ->queryAllRecords ($ this ->getQueryString ());
6188
@@ -130,7 +157,99 @@ private function getQueryString() {
130157 $ limit_sql = $ app ->listform ->getPagingSQL ($ sql_where );
131158 $ app ->tpl ->setVar ('paging ' ,$ app ->listform ->pagingHTML );
132159
133- return 'SELECT * FROM ' .$ app ->listform ->listDef ['table ' ]." WHERE $ sql_where $ order_by_sql $ limit_sql " ;
160+ $ extselect = '' ;
161+ $ join = '' ;
162+ if (!empty ($ _SESSION ['search ' ][$ app ->listform ->listDef ["name " ]]['order ' ])){
163+ $ order = str_replace (' DESC ' ,'' ,$ _SESSION ['search ' ][$ app ->listform ->listDef ["name " ]]['order ' ]);
164+ if ($ order == 'server_id ' && $ app ->listform ->listDef ['table ' ] != 'server ' ){
165+ $ join .= ' LEFT JOIN server as s ON ' .$ app ->listform ->listDef ['table ' ].'.server_id = s.server_id ' ;
166+ $ order_by_sql = str_replace ('server_id ' ,'server_name ' ,$ order_by_sql );
167+ } elseif ($ order == 'client_id ' && $ app ->listform ->listDef ['table ' ] != 'client ' ){
168+ $ join .= ' LEFT JOIN client as c ON ' .$ app ->listform ->listDef ['table ' ].'.client_id = c.client_id ' ;
169+ $ order_by_sql = str_replace ('client_id ' ,'contact_name ' ,$ order_by_sql );
170+ } elseif ($ order == 'parent_domain_id ' ){
171+ $ join .= ' LEFT JOIN web_domain as wd ON ' .$ app ->listform ->listDef ['table ' ].'.parent_domain_id = wd.domain_id ' ;
172+ $ order_by_sql = str_replace ('parent_domain_id ' ,'wd.domain ' ,$ order_by_sql );
173+ $ sql_where = str_replace ('type ' ,$ app ->listform ->listDef ['table ' ].'.type ' ,$ sql_where );
174+ } elseif ($ order == 'sys_groupid ' ){
175+ $ join .= ' LEFT JOIN sys_group as sg ON ' .$ app ->listform ->listDef ['table ' ].'.sys_groupid = sg.groupid ' ;
176+ $ order_by_sql = str_replace ('sys_groupid ' ,'name ' ,$ order_by_sql );
177+ } elseif ($ order == 'rid ' ){
178+ $ join .= ' LEFT JOIN spamfilter_users as su ON ' .$ app ->listform ->listDef ['table ' ].'.rid = su.id ' ;
179+ $ order_by_sql = str_replace ('rid ' ,'email ' ,$ order_by_sql );
180+ } elseif ($ order == 'policy_id ' ){
181+ $ join .= ' LEFT JOIN spamfilter_policy as sp ON ' .$ app ->listform ->listDef ['table ' ].'.policy_id = sp.id ' ;
182+ $ order_by_sql = str_replace ('policy_id ' ,'policy_name ' ,$ order_by_sql );
183+ } elseif ($ order == 'web_folder_id ' ){
184+ $ join .= ' LEFT JOIN web_folder as wf ON ' .$ app ->listform ->listDef ['table ' ].'.web_folder_id = wf.web_folder_id ' ;
185+ $ order_by_sql = str_replace ('web_folder_id ' ,'path ' ,$ order_by_sql );
186+ } elseif ($ order == 'ostemplate_id ' && $ app ->listform ->listDef ['table ' ] != 'openvz_ostemplate ' ){
187+ $ join .= ' LEFT JOIN openvz_ostemplate as oo ON ' .$ app ->listform ->listDef ['table ' ].'.ostemplate_id = oo.ostemplate_id ' ;
188+ $ order_by_sql = str_replace ('ostemplate_id ' ,'template_name ' ,$ order_by_sql );
189+ } elseif ($ order == 'template_id ' && $ app ->listform ->listDef ['table ' ] != 'openvz_template ' ){
190+ $ join .= ' LEFT JOIN openvz_template as ot ON ' .$ app ->listform ->listDef ['table ' ].'.template_id = ot.template_id ' ;
191+ $ order_by_sql = str_replace ('template_id ' ,'template_name ' ,$ order_by_sql );
192+ } elseif ($ order == 'sender_id ' && $ app ->listform ->listDef ['table ' ] != 'sys_user ' ){
193+ $ join .= ' LEFT JOIN sys_user as su ON ' .$ app ->listform ->listDef ['table ' ].'.sender_id = su.userid ' ;
194+ $ order_by_sql = str_replace ('sender_id ' ,'username ' ,$ order_by_sql );
195+ } elseif ($ order == 'web_traffic_last_month ' ){
196+ $ tmp_year = date ('Y ' ,mktime (0 , 0 , 0 , date ("m " )-1 , date ("d " ), date ("Y " )));
197+ $ tmp_month = date ('m ' ,mktime (0 , 0 , 0 , date ("m " )-1 , date ("d " ), date ("Y " )));
198+ $ extselect .= ', SUM(wt.traffic_bytes) as calctraffic ' ;
199+ $ join .= ' JOIN web_traffic as wt ON ' .$ app ->listform ->listDef ['table ' ].'.domain = wt.hostname ' ;
200+ $ sql_where .= " AND YEAR(wt.traffic_date) = ' $ tmp_year' AND MONTH(wt.traffic_date) = ' $ tmp_month' " ;
201+ $ order_by_sql = str_replace ('web_traffic_last_month ' ,'calctraffic ' ,$ order_by_sql );
202+ $ order_by_sql = "GROUP BY domain " .$ order_by_sql ;
203+ } elseif ($ order == 'web_traffic_this_month ' ){
204+ $ tmp_year = date ('Y ' );
205+ $ tmp_month = date ('m ' );
206+ $ extselect .= ', SUM(wt.traffic_bytes) as calctraffic ' ;
207+ $ join .= ' JOIN web_traffic as wt ON ' .$ app ->listform ->listDef ['table ' ].'.domain = wt.hostname ' ;
208+ $ sql_where .= " AND YEAR(wt.traffic_date) = ' $ tmp_year' AND MONTH(wt.traffic_date) = ' $ tmp_month' " ;
209+ $ order_by_sql = str_replace ('web_traffic_this_month ' ,'calctraffic ' ,$ order_by_sql );
210+ $ order_by_sql = "GROUP BY domain " .$ order_by_sql ;
211+ } elseif ($ order == 'web_traffic_last_year ' ){
212+ $ tmp_year = date ('Y ' ,mktime (0 , 0 , 0 , date ("m " )-1 , date ("d " ), date ("Y " )));
213+ $ extselect .= ', SUM(wt.traffic_bytes) as calctraffic ' ;
214+ $ join .= ' JOIN web_traffic as wt ON ' .$ app ->listform ->listDef ['table ' ].'.domain = wt.hostname ' ;
215+ $ sql_where .= " AND YEAR(wt.traffic_date) = ' $ tmp_year' " ;
216+ $ order_by_sql = str_replace ('web_traffic_last_year ' ,'calctraffic ' ,$ order_by_sql );
217+ $ order_by_sql = "GROUP BY domain " .$ order_by_sql ;
218+ } elseif ($ order == 'web_traffic_this_year ' ){
219+ $ tmp_year = date ('Y ' );
220+ $ extselect .= ', SUM(wt.traffic_bytes) as calctraffic ' ;
221+ $ join .= ' JOIN web_traffic as wt ON ' .$ app ->listform ->listDef ['table ' ].'.domain = wt.hostname ' ;
222+ $ sql_where .= " AND YEAR(wt.traffic_date) = ' $ tmp_year' " ;
223+ $ order_by_sql = str_replace ('web_traffic_this_year ' ,'calctraffic ' ,$ order_by_sql );
224+ $ order_by_sql = "GROUP BY domain " .$ order_by_sql ;
225+ } elseif ($ order == 'mail_traffic_last_month ' ){
226+ $ tmp_date = date ('Y-m ' ,mktime (0 , 0 , 0 , date ("m " )-1 , date ("d " ), date ("Y " )));
227+ $ join .= ' JOIN mail_traffic as mt ON ' .$ app ->listform ->listDef ['table ' ].'.mailuser_id = mt.mailuser_id ' ;
228+ $ sql_where .= " AND mt.month like ' $ tmp_date%' " ;
229+ $ order_by_sql = str_replace ('mail_traffic_last_month ' ,'traffic ' ,$ order_by_sql );
230+ } elseif ($ order == 'mail_traffic_this_month ' ){
231+ $ tmp_date = date ('Y-m ' );
232+ $ join .= ' JOIN mail_traffic as mt ON ' .$ app ->listform ->listDef ['table ' ].'.mailuser_id = mt.mailuser_id ' ;
233+ $ sql_where .= " AND mt.month like ' $ tmp_date%' " ;
234+ $ order_by_sql = str_replace ('mail_traffic_this_month ' ,'traffic ' ,$ order_by_sql );
235+ } elseif ($ order == 'mail_traffic_last_year ' ){
236+ $ tmp_date = date ('Y ' ,mktime (0 , 0 , 0 , date ("m " )-1 , date ("d " ), date ("Y " )));
237+ $ extselect .= ', SUM(mt.traffic) as calctraffic ' ;
238+ $ join .= ' JOIN mail_traffic as mt ON ' .$ app ->listform ->listDef ['table ' ].'.mailuser_id = mt.mailuser_id ' ;
239+ $ sql_where .= " AND mt.month like ' $ tmp_date%' " ;;
240+ $ order_by_sql = str_replace ('mail_traffic_last_year ' ,'calctraffic ' ,$ order_by_sql );
241+ $ order_by_sql = "GROUP BY mailuser_id " .$ order_by_sql ;
242+ } elseif ($ order == 'mail_traffic_this_year ' ){
243+ $ tmp_date = date ('Y ' );
244+ $ extselect .= ', SUM(mt.traffic) as calctraffic ' ;
245+ $ join .= ' JOIN mail_traffic as mt ON ' .$ app ->listform ->listDef ['table ' ].'.mailuser_id = mt.mailuser_id ' ;
246+ $ sql_where .= " AND mt.month like ' $ tmp_date%' " ;
247+ $ order_by_sql = str_replace ('mail_traffic_this_year ' ,'calctraffic ' ,$ order_by_sql );
248+ $ order_by_sql = "GROUP BY mailuser_id " .$ order_by_sql ;
249+ }
250+ }
251+
252+ return 'SELECT ' .$ app ->listform ->listDef ['table ' ].'.* ' .$ extselect .' FROM ' .$ app ->listform ->listDef ['table ' ]."$ join WHERE $ sql_where $ order_by_sql $ limit_sql " ;
134253 }
135254
136255
@@ -145,6 +264,15 @@ public function onShow()
145264 include ($ lng_file );
146265 $ app ->tpl ->setVar ($ wb );
147266
267+ //* Limit each page
268+ $ limits = array ('5 ' =>'5 ' ,'15 ' =>'15 ' ,'25 ' =>'25 ' ,'50 ' =>'50 ' ,'100 ' =>'100 ' ,'999999999 ' => 'all ' );
269+
270+ //* create options and set selected, if default -> 15 is selected
271+ foreach ($ limits as $ key => $ val ){
272+ $ options .= '<option value=" ' .$ key .'" ' .(isset ($ _SESSION ['search ' ]['limit ' ]) && $ _SESSION ['search ' ]['limit ' ] == $ key ? 'selected="selected" ' :'' ).(!isset ($ _SESSION ['search ' ]['limit ' ]) && $ key == '15 ' ? 'selected="selected" ' :'' ).'> ' .$ val .'</option> ' ;
273+ }
274+ $ app ->tpl ->setVar ('search_limit ' ,'<select name="search_limit" style="width:50px"> ' .$ options .'</select> ' );
275+
148276 $ app ->tpl ->setVar ('toolsarea_head_txt ' ,$ app ->lng ('toolsarea_head_txt ' ));
149277 $ app ->tpl ->setVar ($ app ->listform ->wordbook );
150278 $ app ->tpl ->setVar ('form_action ' , $ app ->listform ->listDef ['file ' ]);
0 commit comments