Skip to content

Commit c71060d

Browse files
committed
Implemented: FS#556 - See limits in control panel
Implemented: FS#951 - Dashboard module
1 parent 1ac4ff4 commit c71060d

File tree

9 files changed

+329
-40
lines changed

9 files changed

+329
-40
lines changed

interface/web/dashboard/dashboard.php

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,27 +99,44 @@
9999

100100
$app->tpl->setloop('info', $info);
101101

102-
/*
103-
* Show all modules, the user is allowed to use
104-
*/
105-
$modules = explode(',', $_SESSION['s']['user']['modules']);
106-
$mod = array();
107-
if(is_array($modules)) {
108-
foreach($modules as $mt) {
109-
if(is_file('../' . $mt . '/lib/module.conf.php')) {
110-
if(!preg_match("/^[a-z]{2,20}$/i", $mt)) die('module name contains unallowed chars.');
111-
include_once('../' . $mt.'/lib/module.conf.php');
112-
/* We don't want to show the dashboard */
113-
if ($mt != 'dashboard') {
114-
$mod[] = array( 'modules_title' => $app->lng($module['title']),
115-
'modules_startpage' => $module['startpage'],
116-
'modules_name' => $module['name']);
117-
}
118-
}
102+
/* Load the dashlets*/
103+
$dashlet_list = array();
104+
$handle = @opendir(ISPC_WEB_PATH.'/dashboard/dashlets');
105+
while ($file = @readdir ($handle)) {
106+
if ($file != '.' && $file != '..' && !is_dir($file)) {
107+
$dashlet_name = substr($file,0,-4);
108+
$dashlet_class = 'dashlet_'.$dashlet_name;
109+
include_once(ISPC_WEB_PATH.'/dashboard/dashlets/'.$file);
110+
$dashlet_list[$dashlet_name] = new $dashlet_class;
119111
}
112+
}
113+
114+
115+
/* Which dashlets in which column */
116+
/******************************************************************************/
117+
$leftcol_dashlets = array('modules');
118+
$rightcol_dashlets = array('limits');
119+
/******************************************************************************/
120+
120121

121-
$app->tpl->setloop('modules', $mod);
122+
/* Fill the left column */
123+
$leftcol = array();
124+
foreach($leftcol_dashlets as $name) {
125+
if(isset($dashlet_list[$name])) {
126+
$leftcol[]['content'] = $dashlet_list[$name]->show();
127+
}
122128
}
129+
$app->tpl->setloop('leftcol', $leftcol);
130+
131+
/* Fill the right columnn */
132+
$rightcol = array();
133+
foreach($rightcol_dashlets as $name) {
134+
if(isset($dashlet_list[$name])) {
135+
$rightcol[]['content'] = $dashlet_list[$name]->show();
136+
}
137+
}
138+
$app->tpl->setloop('rightcol', $rightcol);
139+
123140

124141
//* Do Output
125142
$app->tpl->pparse();
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<?php
2+
3+
class dashlet_limits {
4+
5+
function show() {
6+
global $app, $conf;
7+
8+
$limits = array();
9+
10+
/* Limits to be shown*/
11+
12+
$limits[] = array('field' => 'limit_maildomain',
13+
'db_table' => 'mail_domain',
14+
'db_where' => '');
15+
16+
$limits[] = array('field' => 'limit_mailbox',
17+
'db_table' => 'mail_user',
18+
'db_where' => '');
19+
20+
$limits[] = array('field' => 'limit_mailalias',
21+
'db_table' => 'mail_forwarding',
22+
'db_where' => "type = 'alias'");
23+
24+
$limits[] = array('field' => 'limit_mailaliasdomain',
25+
'db_table' => 'mail_forwarding',
26+
'db_where' => "type = 'aliasdomain'");
27+
28+
$limits[] = array('field' => 'limit_mailforward',
29+
'db_table' => 'mail_forwarding',
30+
'db_where' => "type = 'forward'");
31+
32+
$limits[] = array('field' => 'limit_mailcatchall',
33+
'db_table' => 'mail_forwarding',
34+
'db_where' => "type = 'catchall'");
35+
36+
$limits[] = array('field' => 'limit_mailrouting',
37+
'db_table' => 'mail_transport',
38+
'db_where' => "");
39+
40+
$limits[] = array('field' => 'limit_mailfilter',
41+
'db_table' => 'mail_user_filter',
42+
'db_where' => "");
43+
44+
$limits[] = array('field' => 'limit_fetchmail',
45+
'db_table' => 'mail_get',
46+
'db_where' => "");
47+
48+
$limits[] = array('field' => 'limit_spamfilter_wblist',
49+
'db_table' => 'spamfilter_wblist',
50+
'db_where' => "");
51+
52+
$limits[] = array('field' => 'limit_spamfilter_user',
53+
'db_table' => 'spamfilter_users',
54+
'db_where' => "");
55+
56+
$limits[] = array('field' => 'limit_spamfilter_policy',
57+
'db_table' => 'spamfilter_policy',
58+
'db_where' => "");
59+
60+
$limits[] = array('field' => 'limit_web_domain',
61+
'db_table' => 'web_domain',
62+
'db_where' => "type = 'vhost'");
63+
64+
$limits[] = array('field' => 'limit_web_subdomain',
65+
'db_table' => 'web_domain',
66+
'db_where' => "type = 'subdomain'");
67+
68+
$limits[] = array('field' => 'limit_web_aliasdomain',
69+
'db_table' => 'web_domain',
70+
'db_where' => "type = 'aliasdomain'");
71+
72+
$limits[] = array('field' => 'limit_ftp_user',
73+
'db_table' => 'ftp_user',
74+
'db_where' => "");
75+
76+
$limits[] = array('field' => 'limit_shell_user',
77+
'db_table' => 'shell_user',
78+
'db_where' => "");
79+
80+
$limits[] = array('field' => 'limit_dns_zone',
81+
'db_table' => 'dns_soa',
82+
'db_where' => "");
83+
84+
$limits[] = array('field' => 'limit_dns_record',
85+
'db_table' => 'dns_rr',
86+
'db_where' => "");
87+
88+
$limits[] = array('field' => 'limit_database',
89+
'db_table' => 'web_database',
90+
'db_where' => "");
91+
92+
$limits[] = array('field' => 'limit_cron',
93+
'db_table' => 'cron',
94+
'db_where' => "");
95+
96+
$limits[] = array('field' => 'limit_client',
97+
'db_table' => 'client',
98+
'db_where' => "");
99+
100+
101+
102+
103+
//* Loading Template
104+
$app->uses('tpl,tform');
105+
106+
$tpl = new tpl;
107+
$tpl->newTemplate("dashlets/templates/limits.htm");
108+
109+
$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_dashlet_limits.lng';
110+
include($lng_file);
111+
$tpl->setVar($wb);
112+
113+
if($app->auth->is_admin()) {
114+
$user_is_admin = 1;
115+
} else {
116+
$user_is_admin = 0;
117+
}
118+
$tpl->setVar('is_admin',$user_is_admin);
119+
120+
if($user_is_admin == 0) {
121+
$client_group_id = $_SESSION["s"]["user"]["default_group"];
122+
$client = $app->db->queryOneRecord("SELECT * FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
123+
124+
$rows = array();
125+
foreach($limits as $limit) {
126+
$field = $limit['field'];
127+
if($client[$field] != 0) {
128+
$value = ($client[$field] == '-1')?$wb['unlimited_txt']:$client[$field];
129+
$rows[] = array('field' => $field,
130+
'field_txt' => $wb[$field.'_txt'],
131+
'value' => $value,
132+
'usage' => $this->_get_limit_usage($limit));
133+
}
134+
}
135+
$tpl->setLoop('rows',$rows);
136+
}
137+
138+
139+
return $tpl->grab();
140+
141+
}
142+
143+
function _get_limit_usage($limit) {
144+
global $app;
145+
146+
$sql = "SELECT count(sys_userid) as number FROM ".$limit['db_table']." WHERE ";
147+
if($limit['db_where'] != '') $sql .= $limit['db_where']." AND ";
148+
$sql .= $app->tform->getAuthSQL('r');
149+
$rec = $app->db->queryOneRecord($sql);
150+
return $rec['number'];
151+
152+
}
153+
154+
}
155+
156+
157+
158+
159+
160+
161+
162+
163+
?>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
class dashlet_modules {
4+
5+
function show() {
6+
global $app, $conf;
7+
8+
//* Loading Template
9+
$app->uses('tpl');
10+
11+
$tpl = new tpl;
12+
$tpl->newTemplate("dashlets/templates/modules.htm");
13+
14+
$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_dashlet_modules.lng';
15+
include($lng_file);
16+
$tpl->setVar($wb);
17+
18+
/*
19+
* Show all modules, the user is allowed to use
20+
*/
21+
$modules = explode(',', $_SESSION['s']['user']['modules']);
22+
$mod = array();
23+
if(is_array($modules)) {
24+
foreach($modules as $mt) {
25+
if(is_file('../' . $mt . '/lib/module.conf.php')) {
26+
if(!preg_match("/^[a-z]{2,20}$/i", $mt)) die('module name contains unallowed chars.');
27+
include_once('../' . $mt.'/lib/module.conf.php');
28+
/* We don't want to show the dashboard */
29+
if ($mt != 'dashboard') {
30+
$mod[] = array( 'modules_title' => $app->lng($module['title']),
31+
'modules_startpage' => $module['startpage'],
32+
'modules_name' => $module['name']);
33+
}
34+
}
35+
}
36+
37+
$tpl->setloop('modules', $mod);
38+
}
39+
40+
return $tpl->grab();
41+
42+
}
43+
}
44+
45+
46+
47+
48+
49+
50+
51+
52+
?>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<h2>{tmpl_var name='limits_txt'}</h2>
2+
<div style="width:350px;">
3+
<table class="list">
4+
<tmpl_loop name='rows'>
5+
<tr class="tbl_row_<tmpl_if name='__EVEN__'}even<tmpl_else>uneven</tmpl_if>">
6+
<td>{tmpl_var name='field_txt'}</td>
7+
<td>{tmpl_var name='usage'} {tmpl_var name='of_txt'} {tmpl_var name='value'}</td>
8+
</tr>
9+
</tmpl_loop>
10+
</table>
11+
</div>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<h2>{tmpl_var name='available_modules_txt'}</h2>
2+
<div style="width:350px;">
3+
<tmpl_loop name='modules'>
4+
<div class="dashboard-modules {tmpl_var name='modules_name'}">
5+
<a href="#" onclick="capp('{tmpl_var name='modules_name'}')">
6+
{tmpl_var name='modules_title'}
7+
</a>
8+
</div>
9+
</tmpl_loop>
10+
</div>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
$wb['limits_txt'] = "Account limits";
3+
$wb['of_txt'] = "of";
4+
$wb['unlimited_txt'] = "Unlimited";
5+
$wb['limit_maildomain_txt'] = "Number of email domains";
6+
$wb['limit_mailbox_txt'] = "Number of mailboxes";
7+
$wb["limit_mailalias_txt"] = 'Number of email aliases';
8+
$wb["limit_mailaliasdomain_txt"] = 'Number of domain aliases';
9+
$wb["limit_mailforward_txt"] = 'Number of email forwarders';
10+
$wb["limit_mailcatchall_txt"] = 'Number of email catchall accounts';
11+
$wb["limit_mailrouting_txt"] = 'Number of email routes';
12+
$wb["limit_mailfilter_txt"] = 'Number of email filters';
13+
$wb["limit_fetchmail_txt"] = 'Number of fetchmail accounts';
14+
$wb["limit_spamfilter_wblist_txt"] = 'Number of spamfilter white / blacklist filters';
15+
$wb["limit_spamfilter_user_txt"] = 'Number of spamfilter users';
16+
$wb["limit_spamfilter_policy_txt"] = 'Number of spamfilter policys';
17+
$wb["limit_cron_txt"] = 'Number of cron jobs';
18+
$wb["limit_web_domain_txt"] = 'Number of web domains';
19+
$wb["limit_web_aliasdomain_txt"] = 'Number of web aliasdomains';
20+
$wb["limit_web_subdomain_txt"] = 'Number of web subdomains';
21+
$wb["limit_ftp_user_txt"] = 'Number of FTP users';
22+
$wb["limit_dns_zone_txt"] = 'Number of DNS zones';
23+
$wb["limit_dns_record_txt"] = 'Number DNS records';
24+
$wb["limit_shell_user_txt"] = 'Number of Shell users';
25+
$wb["limit_webdav_user_txt"] = 'Number of Webdav users';
26+
$wb["limit_client_txt"] = 'Number of Clients';
27+
$wb["limit_database_txt"] = 'Number of Databases';
28+
?>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
$wb['available_modules_txt'] = "Available Modules";
3+
?>

interface/web/dashboard/templates/dashboard.htm

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
<h1><tmpl_var name="welcome_user"></h1>
3-
3+
<hr />
44
<div class="panel panel_dashboard">
55
<div>
66
<tmpl_if name='error'>
@@ -25,15 +25,16 @@ <h1><tmpl_var name="welcome_user"></h1>
2525
</div>
2626
</tmpl_if>
2727
</div>
28+
<div style="float:left; width:350px;">
29+
<tmpl_loop name='leftcol'>
30+
{tmpl_var name='content'}
31+
<p>&nbsp;</p>
32+
</tmpl_loop>
33+
</div>
34+
<div style="float:left; width:350px;">
35+
<tmpl_loop name='rightcol'>
36+
{tmpl_var name='content'}
2837
<p>&nbsp;</p>
29-
<h2>{tmpl_var name='available_modules_txt'}</h2>
30-
<div style="width:700px;">
31-
<tmpl_loop name='modules'>
32-
<div class="dashboard-modules {tmpl_var name='modules_name'}">
33-
<a href="#" onclick="capp('{tmpl_var name='modules_name'}')">
34-
{tmpl_var name='modules_title'}
35-
</a>
36-
</div>
3738
</tmpl_loop>
3839
</div>
3940
</div>

0 commit comments

Comments
 (0)