Skip to content

Commit 8145fbd

Browse files
author
xaver
committed
Sort and limit in ispconfig all templates... additional info howtoforge - http://www.howtoforge.com/forums/showthread.php?p=274790
1 parent b4daebf commit 8145fbd

File tree

62 files changed

+289
-83
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+289
-83
lines changed

interface/lib/classes/listform.inc.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,16 @@ public function getSearchSQL($sql_where = '')
191191
public function getPagingSQL($sql_where = '1')
192192
{
193193
global $app, $conf;
194+
195+
//* Add Global Limit from selectbox
196+
if(!empty($_POST['search_limit']) AND intval($_POST['search_limit'])){
197+
$_SESSION['search']['limit'] = $_POST['search_limit'];
198+
}
194199

195200
//* Get Config variables
196201
$list_name = $this->listDef['name'];
197202
$search_prefix = $this->listDef['search_prefix'];
198-
$records_per_page = $this->listDef['records_per_page'];
203+
$records_per_page = (empty($_SESSION['search']['limit']) ? $this->listDef['records_per_page'] : $_SESSION['search']['limit']) ;
199204
$table = $this->listDef['table'];
200205

201206
//* set PAGE to zero, if in session not set

interface/lib/classes/listform_actions.inc.php

Lines changed: 129 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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']);

interface/lib/classes/plugin_listview.inc.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,43 @@ function onShow() {
8282
if(isset($this->options["sql_order_by"])) {
8383
$sql_order_by = $this->options["sql_order_by"];
8484
}
85-
85+
86+
//* Limit each page
87+
$limits = array('5'=>'5','15'=>'15','25'=>'25','50'=>'50','100'=>'100','999999999' => 'all');
88+
89+
//* create options and set selected, if default -> 15 is selected
90+
foreach($limits as $key => $val){
91+
$options .= '<option value="'.$key.'" '.(isset($_SESSION['search']['limit']) && $_SESSION['search']['limit'] == $key ? 'selected="selected"':'' ).(!isset($_SESSION['search']['limit']) && $key == '15' ? 'selected="selected"':'').'>'.$val.'</option>';
92+
}
93+
$listTpl->setVar('search_limit','<select name="search_limit" style="width:50px">'.$options.'</select>');
94+
95+
96+
//Sorting
97+
if(!isset($_SESSION['search'][$app->listform->listDef["name"]]['order'])){
98+
$_SESSION['search'][$app->listform->listDef["name"]]['order'] = '';
99+
}
100+
101+
if(!empty($_GET['orderby'])){
102+
$order = str_replace('tbl_col_','',$_GET['orderby']);
103+
//* Check the css class submited value
104+
if (preg_match("/^[a-z\_]{1,}$/",$order)) {
105+
if($_SESSION['search'][$app->listform->listDef["name"]]['order'] == $order){
106+
$_SESSION['search'][$app->listform->listDef["name"]]['order'] = $order.' DESC';
107+
} else {
108+
$_SESSION['search'][$app->listform->listDef["name"]]['order'] = $order;
109+
}
110+
}
111+
}
112+
113+
// If a manuel oder by like customers isset the sorting will be infront
114+
if(!empty($_SESSION['search'][$app->listform->listDef["name"]]['order'])){
115+
if(empty($sql_order_by)){
116+
$sql_order_by = "ORDER BY ".$_SESSION['search'][$app->listform->listDef["name"]]['order'];
117+
} else {
118+
$sql_order_by = str_replace("ORDER BY ","ORDER BY ".$_SESSION['search'][$app->listform->listDef["name"]]['order'].', ',$sql_order_by);
119+
}
120+
}
121+
86122
// Loading language field
87123
$lng_file = "lib/lang/".$_SESSION["s"]["language"]."_".$app->listform->listDef['name']."_list.lng";
88124
include($lng_file);

interface/web/admin/templates/firewall_list.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ <h2><tmpl_var name="list_head_txt"></h2>
2222
<th class="tbl_col_server_id" scope="col"><tmpl_var name="server_id_txt"></th>
2323
<th class="tbl_col_tcp_port" scope="col"><tmpl_var name="tcp_port_txt"></th>
2424
<th class="tbl_col_udp_port" scope="col"><tmpl_var name="udp_port_txt"></th>
25-
<th class="tbl_col_buttons" scope="col">&nbsp;</th>
25+
<th scope="col">{tmpl_var name='search_limit'}</th>
2626
</tr>
2727
<tr>
2828
<td class="tbl_col_active"><select name="search_active">{tmpl_var name='search_active'}</select></td>

interface/web/admin/templates/remote_user_list.htm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ <h2><tmpl_var name="list_head_txt"></h2>
1616
<thead>
1717
<tr>
1818
<th class="tbl_col_remote_userid" scope="col"><tmpl_var name="parent_remote_userid_txt"></th>
19-
<th class="tbl_col_username" scope="col"><tmpl_var name="username_txt"></th>
20-
<th class="tbl_col_buttons" scope="col">&nbsp;</th>
19+
<th class="tbl_col_remote_username" scope="col"><tmpl_var name="username_txt"></th>
20+
<th class="" scope="col">{tmpl_var name='search_limit'}</th>
2121
</tr>
2222
<tr>
2323
<td class="tbl_col_remote_userid"></td>
24-
<td class="tbl_col_username"><input type="text" name="search_username" value="{tmpl_var name='search_username'}" /></td>
24+
<td class="tbl_col_remote_username"><input type="text" name="search_username" value="{tmpl_var name='search_username'}" /></td>
2525
<td class="tbl_col_buttons"><div class="buttons"><button type="button" class="icons16 icoFilter" name="Filter" id="Filter" value="{tmpl_var name="filter_txt"}" onClick="submitForm('pageForm','admin/remote_user_list.php');"><span>{tmpl_var name="filter_txt"}</span></button></div></td>
2626
</tr>
2727
</thead>
2828
<tbody>
2929
<tmpl_loop name="records">
3030
<tr class="tbl_row_<tmpl_if name='__EVEN__'}even<tmpl_else>uneven</tmpl_if>">
3131
<td class="tbl_col_remote_userid"><a href="#" onClick="loadContent('admin/remote_user_edit.php?id={tmpl_var name='remote_userid'}');">{tmpl_var name="remote_userid"}</a></td>
32-
<td class="tbl_col_username"><a href="#" onClick="loadContent('admin/remote_user_edit.php?id={tmpl_var name='remote_userid'}');">{tmpl_var name="remote_username"}</a></td>
32+
<td class="tbl_col_remote_username"><a href="#" onClick="loadContent('admin/remote_user_edit.php?id={tmpl_var name='remote_userid'}');">{tmpl_var name="remote_username"}</a></td>
3333
<td class="tbl_col_buttons">
3434
<div class="buttons icons16">
3535
<a class="icons16 icoDelete" href="javascript: del_record('admin/remote_user_del.php?id={tmpl_var name='remote_userid'}&phpsessid={tmpl_var name='phpsessid'}','{tmpl_var name='delete_confirmation'}');"><span>{tmpl_var name='delete_txt'}</span></a>

interface/web/admin/templates/server_config_list.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ <h2><tmpl_var name="list_head_txt"></h2>
99
<thead>
1010
<tr>
1111
<th class="tbl_col_server_name" scope="col"><tmpl_var name="server_name_txt"></th>
12-
<th class="tbl_col_buttons" scope="col">&nbsp;</th>
12+
<th scope="col">{tmpl_var name='search_limit'}</th>
1313
</tr>
1414
<tr>
1515
<td class="tbl_col_server_name"><input type="text" name="search_server_name" value="{tmpl_var name='search_server_name'}" /></td>

interface/web/admin/templates/server_ip_list.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ <h2><tmpl_var name="list_head_txt"></h2>
2323
<th class="tbl_col_ip_address" scope="col"><tmpl_var name="ip_address_txt"></th>
2424
<th class="tbl_col_virtualhost" scope="col"><tmpl_var name="virtualhost_txt"></th>
2525
<th class="tbl_col_virtualhost_port" scope="col"><tmpl_var name="virtualhost_port_txt"></th>
26-
<th class="tbl_col_buttons" scope="col">&nbsp;</th>
26+
<th class="tbl_col_buttons" scope="col">{tmpl_var name='search_limit'}</th>
2727
</tr>
2828
<tr>
2929
<td class="tbl_col_server_id"><select name="search_server_id">{tmpl_var name='search_server_id'}</select></td>

interface/web/admin/templates/server_list.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ <h2><tmpl_var name="list_head_txt"></h2>
1515
<th class="tbl_col_file_server" scope="col"><tmpl_var name="file_server_txt"></th>
1616
<th class="tbl_col_db_server" scope="col"><tmpl_var name="db_server_txt"></th>
1717
<th class="tbl_col_vserver_server" scope="col"><tmpl_var name="vserver_server_txt"></th>
18-
<th class="tbl_col_buttons" scope="col">&nbsp;</th>
18+
<th scope="col">{tmpl_var name='search_limit'}</th>
1919
</tr>
2020
<tr>
2121
<td class="tbl_col_server_name"><input type="text" name="search_server_name" value="{tmpl_var name='search_server_name'}" /></td>

interface/web/admin/templates/users_list.htm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ <h2><tmpl_var name="list_head_txt"></h2>
2020
<thead>
2121
<tr>
2222
<th class="tbl_col_username" scope="col"><tmpl_var name="username_txt"></th>
23-
<th class="tbl_col_vorname" scope="col"><tmpl_var name="vorname_txt"></th>
24-
<th class="tbl_col_name" scope="col"><tmpl_var name="name_txt"></th>
25-
<th class="tbl_col_ort" scope="col"><tmpl_var name="ort_txt"></th>
26-
<th class="tbl_col_buttons" scope="col">&nbsp;</th>
23+
<th class="" scope="col"><tmpl_var name="vorname_txt"></th>
24+
<th class="" scope="col"><tmpl_var name="name_txt"></th>
25+
<th class="" scope="col"><tmpl_var name="ort_txt"></th>
26+
<th scope="col">{tmpl_var name='search_limit'}</th>
2727
</tr>
2828
<tr>
2929
<td class="tbl_col_username"><input type="text" name="search_username" value="{tmpl_var name='search_username'}" /></td>

interface/web/client/list/client_template.list.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@
4545
* Suchfelder
4646
*****************************************************/
4747

48+
$liste["item"][] = array( 'field' => "template_id",
49+
'datatype' => "INTEGER",
50+
'formtype' => "TEXT",
51+
'op' => "=",
52+
'prefix' => "",
53+
'suffix' => "",
54+
'width' => "",
55+
'value' => "");
56+
57+
4858
$liste["item"][] = array( 'field' => "template_type",
4959
'datatype' => "VARCHAR",
5060
'formtype' => "SELECT",

0 commit comments

Comments
 (0)