Skip to content

Commit 024ca6a

Browse files
author
Till Brehm
committed
Merge branch 'patch-client-info-tab' into 'develop'
Add an info tab for the client page #5372 See merge request ispconfig/ispconfig3!941
2 parents 94e8c3b + ba4c321 commit 024ca6a

File tree

11 files changed

+124
-30
lines changed

11 files changed

+124
-30
lines changed

interface/lib/classes/tform_base.inc.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,17 +1614,27 @@ function datalogSave($action, $primary_id, $record_old, $record_new) {
16141614
return true;
16151615
}
16161616

1617-
function getAuthSQL($perm, $table = '') {
1618-
if($_SESSION["s"]["user"]["typ"] == 'admin' || $_SESSION['s']['user']['mailuser_id'] > 0) {
1617+
function getAuthSQL($perm, $table = '', $userid = NULL, $groups = NULL) {
1618+
if(($_SESSION["s"]["user"]["typ"] == 'admin' || $_SESSION['s']['user']['mailuser_id'] > 0 ) && $userid == NULL && $groups == NULL) {
16191619
return '1';
16201620
} else {
16211621
if ($table != ''){
16221622
$table = ' ' . $table . '.';
16231623
}
1624-
$groups = ( $_SESSION["s"]["user"]["groups"] ) ? $_SESSION["s"]["user"]["groups"] : 0;
16251624
$sql = '(';
1626-
$sql .= "(" . $table . "sys_userid = ".$_SESSION["s"]["user"]["userid"]." AND " . $table . "sys_perm_user like '%$perm%') OR ";
1627-
$sql .= "(" . $table . "sys_groupid IN (".$groups.") AND " . $table ."sys_perm_group like '%$perm%') OR ";
1625+
if ($userid === NULL) {
1626+
$userid = $_SESSION["s"]["user"]["userid"];
1627+
}
1628+
if ($userid > 0) {
1629+
$sql .= "(" . $table . "sys_userid = ".$userid." AND " . $table . "sys_perm_user like '%$perm%') OR ";
1630+
}
1631+
1632+
if ($groups === NULL) {
1633+
$groups = ( $_SESSION["s"]["user"]["groups"] ) ? $_SESSION["s"]["user"]["groups"] : 0;
1634+
}
1635+
if ($groups > 0) {
1636+
$sql .= "(" . $table . "sys_groupid IN (".$groups.") AND " . $table ."sys_perm_group like '%$perm%') OR ";
1637+
}
16281638
$sql .= $table . "sys_perm_other like '%$perm%'";
16291639
$sql .= ')';
16301640

interface/web/client/client_edit.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,42 @@ function onShowNew() {
7070
}
7171
}
7272

73+
// Hide the info tab when creating a new client.
74+
unset($app->tform->formDef["tabs"]['info']);
75+
$app->tform->formDef["tab_default"] = "address";
76+
7377
parent::onShowNew();
7478
}
7579

80+
function onShowEdit() {
81+
global $app, $conf;
82+
chdir('../dashboard');
83+
84+
$dashlet_list = array();
85+
$dashlets = array('databasequota.php', 'limits.php', 'mailquota.php', 'quota.php');
86+
$current_client_id = $this->id;
87+
88+
foreach ($dashlets as $file) {
89+
if ($file != '.' && $file != '..' && !is_dir(ISPC_WEB_PATH.'/dashboard/dashlets/'.$file)) {
90+
$dashlet_name = substr($file, 0, -4);
91+
$dashlet_class = 'dashlet_'.$dashlet_name;
92+
include_once ISPC_WEB_PATH.'/dashboard/dashlets/'.$file;
93+
$dashlet_list[$dashlet_name] = new $dashlet_class;
94+
$dashlets_html .= $dashlet_list[$dashlet_name]->show($current_client_id);
95+
}
96+
}
97+
$app->tpl->setVar('dashlets', $dashlets_html);
98+
99+
chdir('../client');
100+
101+
$tmp = $app->db->queryOneRecord("SELECT company_name, contact_firstname, contact_name, email FROM client WHERE client_id = ?", $current_client_id);
102+
$app->tpl->setVar('company_name', $tmp['company_name']);
103+
$app->tpl->setVar('contact_name', $tmp['contact_name']);
104+
$app->tpl->setVar('email', $tmp['email']);
105+
106+
parent::onShowEdit();
107+
}
108+
76109

77110
function onSubmit() {
78111
global $app, $conf;

interface/web/client/form/client.tform.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
$form["db_table"] = "client";
4646
$form["db_table_idx"] = "client_id";
4747
$form["db_history"] = "yes";
48-
$form["tab_default"] = "address";
48+
$form["tab_default"] = "info";
4949
$form["list_default"] = "client_list.php";
5050
$form["auth"] = 'yes';
5151

@@ -80,6 +80,12 @@
8080
}
8181
}
8282

83+
$form["tabs"]['info'] = array (
84+
'title' => "Info",
85+
'width' => 100,
86+
'template' => "templates/client_edit_info.htm",
87+
'fields' => array ()
88+
);
8389
$form["tabs"]['address'] = array (
8490
'title' => "Address",
8591
'width' => 100,
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<input type="hidden" name="id" value="{tmpl_var name='id'}">
2+
<div class='page-header'>
3+
<legend>Client info</legend>
4+
<div>
5+
<ul>
6+
<li>Company Name: {tmpl_var name='company_name'}</li>
7+
<li>Contact Name: {tmpl_var name='contact_name'}</li>
8+
<li>E-mail: <a href="mailto:{tmpl_var name='email'}">{tmpl_var name='email'}</a></li>
9+
<li>Login as:
10+
<tmpl_if name="is_admin">
11+
<a class="btn btn-default formbutton-success formbutton-narrow" data-load-content="login/login_as.php?cid={tmpl_var name='id'}"><span class="icon icon-loginas"></span></a>
12+
<tmpl_elseif name="is_reseller">
13+
<a class="btn btn-default formbutton-success formbutton-narrow" data-load-content="login/login_as.php?cid={tmpl_var name='id'}"><span class="icon icon-loginas"></span></a>
14+
</tmpl_if>
15+
</li>
16+
</ul>
17+
</div>
18+
19+
20+
<tmpl_var name="dashlets">
21+
22+
</div>
23+

interface/web/dashboard/dashlets/databasequota.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class dashlet_databasequota {
44

5-
function show() {
5+
function show($limit_to_client_id = null) {
66
global $app;
77

88
//* Loading Template
@@ -23,8 +23,13 @@ function show() {
2323
$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_dashlet_databasequota.lng';
2424
if(is_file($lng_file)) include $lng_file;
2525
$tpl->setVar($wb);
26+
if ($_SESSION["s"]["user"]["typ"] != 'admin') {
27+
$client_id = $_SESSION['s']['user']['client_id'];
28+
} else {
29+
$client_id = $limit_to_client_id;
30+
}
2631

27-
$databases = $app->quota_lib->get_databasequota_data( ($_SESSION["s"]["user"]["typ"] != 'admin') ? $_SESSION['s']['user']['client_id'] : null);
32+
$databases = $app->quota_lib->get_databasequota_data($client_id);
2833
//print_r($databases);
2934

3035
$has_databasequota = false;

interface/web/dashboard/dashlets/limits.php

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class dashlet_limits
44
{
5-
public function show()
5+
public function show($limit_to_client_id = 0)
66
{
77
global $app, $conf;
88

@@ -147,33 +147,35 @@ public function show()
147147
}
148148
$tpl->setVar($wb);
149149

150-
if ($app->auth->is_admin()) {
151-
$user_is_admin = true;
150+
if ($limit_to_client_id == 0) {
151+
$client_id = $_SESSION['s']['user']['client_id'];
152+
$user_is_admin = true;
152153
} else {
153-
$user_is_admin = false;
154+
$client_id = $limit_to_client_id;
155+
$user_is_admin = false;
154156
}
155-
$tpl->setVar('is_admin', $user_is_admin);
156157

157-
if ($user_is_admin == false) {
158-
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
159-
$client = $app->db->queryOneRecord("SELECT * FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
160-
}
158+
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
159+
$client = $app->db->queryOneRecord("SELECT * FROM client WHERE client_id = ?", $client_id);
160+
161161

162162
$rows = array();
163163
foreach ($limits as $limit) {
164164
$field = $limit['field'];
165+
$value = $client[$field];
165166
if ($user_is_admin) {
166167
$value = $wb['unlimited_txt'];
167168
} else {
168169
$value = $client[$field];
169170
}
171+
170172
if ($value != 0 || $value == $wb['unlimited_txt']) {
171173
$value_formatted = ($value == '-1')?$wb['unlimited_txt']:$value;
172174
if (isset($limit['q_type']) && $limit['q_type'] != '') {
173-
$usage = $this->_get_assigned_quota($limit) . " MB";
175+
$usage = $this->_get_assigned_quota($limit, $client_id) . " MB";
174176
$value_formatted = ($value == '-1')?$wb['unlimited_txt']:$value . " MB";
175177
} else {
176-
$usage = $this->_get_limit_usage($limit);
178+
$usage = $this->_get_limit_usage($limit, $client_id);
177179
}
178180
$percentage = ($value == '-1' || intval($value) == 0 || trim($value) == '' ? -1 : round(100 * (int)$usage / (int)$value));
179181
$progressbar = $percentage > 100 ? 100 : $percentage;
@@ -195,28 +197,31 @@ public function show()
195197
return $tpl->grab();
196198
}
197199

198-
public function _get_limit_usage($limit)
200+
public function _get_limit_usage($limit, $limit_to_client_id)
199201
{
200202
global $app;
201203

202204
$sql = "SELECT count(sys_userid) as number FROM ?? WHERE ";
203205
if ($limit['db_where'] != '') {
204206
$sql .= $limit['db_where']." AND ";
205207
}
206-
$sql .= $app->tform->getAuthSQL('r');
208+
$sql .= $app->tform->getAuthSQL('r', '', $limit_to_client_id);
209+
// TEST to show reseller data.
210+
//$sql .= $app->tform->getAuthSQL('r', '', 0, '3,28,39');
211+
//echo $sql;
207212
$rec = $app->db->queryOneRecord($sql, $limit['db_table']);
208213
return $rec['number'];
209214
}
210215

211-
public function _get_assigned_quota($limit)
216+
public function _get_assigned_quota($limit, $limit_to_client_id)
212217
{
213218
global $app;
214219

215220
$sql = "SELECT sum(??) as number FROM ?? WHERE ";
216221
if ($limit['db_where'] != '') {
217222
$sql .= $limit['db_where']." AND ";
218223
}
219-
$sql .= $app->tform->getAuthSQL('r');
224+
$sql .= $app->tform->getAuthSQL('r', '', $limit_to_client_id);
220225
$rec = $app->db->queryOneRecord($sql, $limit['q_type'], $limit['db_table']);
221226
if ($limit['db_table']=='mail_user') {
222227
$quotaMB = $rec['number'] / 1048576;

interface/web/dashboard/dashlets/mailquota.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class dashlet_mailquota {
44

5-
function show() {
5+
function show($limit_to_client_id = null) {
66
global $app;
77

88
//* Loading Template
@@ -16,7 +16,13 @@ function show() {
1616
if(is_file($lng_file)) include $lng_file;
1717
$tpl->setVar($wb);
1818

19-
$emails = $app->quota_lib->get_mailquota_data( ($_SESSION["s"]["user"]["typ"] != 'admin') ? $_SESSION['s']['user']['client_id'] : null);
19+
if ($_SESSION["s"]["user"]["typ"] != 'admin') {
20+
$client_id = $_SESSION['s']['user']['client_id'];
21+
} else {
22+
$client_id = $limit_to_client_id;
23+
}
24+
25+
$emails = $app->quota_lib->get_mailquota_data($client_id);
2026
//print_r($emails);
2127

2228
$has_mailquota = false;

interface/web/dashboard/dashlets/quota.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class dashlet_quota {
44

5-
function show() {
5+
function show($limit_to_client_id = null) {
66
global $app;
77

88
//* Loading Template
@@ -24,7 +24,13 @@ function show() {
2424
if(is_file($lng_file)) include $lng_file;
2525
$tpl->setVar($wb);
2626

27-
$sites = $app->quota_lib->get_quota_data( ($_SESSION["s"]["user"]["typ"] != 'admin') ? $_SESSION['s']['user']['client_id'] : null);
27+
if ($_SESSION["s"]["user"]["typ"] != 'admin') {
28+
$client_id = $_SESSION['s']['user']['client_id'];
29+
} else {
30+
$client_id = $limit_to_client_id;
31+
}
32+
33+
$sites = $app->quota_lib->get_quota_data($client_id);
2834
//print_r($sites);
2935

3036
$has_quota = false;

interface/web/dashboard/dashlets/templates/databasequota.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<tbody>
1212
<tmpl_loop name='databasequota'>
1313
<tr>
14-
<td>{tmpl_var name='database_name'}</td>
14+
<td><a href="#" data-load-content="sites/database_edit.php?id={tmpl_var name='database_id'}" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="{tmpl_var name='database_name'}">{tmpl_var name='database_name'}</a></td>
1515
<td>{tmpl_var name='used'}</td>
1616
<td>{tmpl_var name='database_quota'}</td>
1717
{tmpl_if name="quota_raw" op="!=" value="-1"}<td>

interface/web/dashboard/dashlets/templates/mailquota.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<td>{tmpl_var name='name'}</td>
1717
<td>{tmpl_var name='used'}</td>
1818
<td>{tmpl_var name='quota'}</td>
19-
{tmpl_if name="quota_raw" op="!=" value="0"}<td>
19+
{tmpl_if name="quota_raw" op="!=" value="-1"}<td>
2020
<div class='progress'>
2121
<div class='progress-bar-striped progress-bar progress-bar-{tmpl_if name="used_percentage" op="<" value="50"}success{tmpl_elseif name="used_percentage" op="<" value="75"}warning{tmpl_else}danger{/tmpl_if}' role='progressbar' aria-valuemin='0' aria-valuemax='100' aria-valuenow='{tmpl_var name="used_percentage"}' style='width:{tmpl_var name="used_percentage"}%'><span>{tmpl_var name="used_percentage"}%</span>
2222
<span class='sr-only'>{tmpl_var name='used'} {tmpl_var name='of_txt'} {tmpl_var name='quota'}</span>

0 commit comments

Comments
 (0)