Skip to content

Commit 169a480

Browse files
committed
Prepare the limits table to be show for an admin or reseller but with client data, #5372
1 parent 51ae283 commit 169a480

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

interface/lib/classes/tform_base.inc.php

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

1551-
function getAuthSQL($perm, $table = '') {
1552-
if($_SESSION["s"]["user"]["typ"] == 'admin' || $_SESSION['s']['user']['mailuser_id'] > 0) {
1551+
function getAuthSQL($perm, $table = '', $userid = NULL, $groups = NULL) {
1552+
if(($_SESSION["s"]["user"]["typ"] == 'admin' || $_SESSION['s']['user']['mailuser_id'] > 0 ) && $userid == NULL && $groups == NULL) {
15531553
return '1';
15541554
} else {
15551555
if ($table != ''){
15561556
$table = ' ' . $table . '.';
15571557
}
1558-
$groups = ( $_SESSION["s"]["user"]["groups"] ) ? $_SESSION["s"]["user"]["groups"] : 0;
15591558
$sql = '(';
1560-
$sql .= "(" . $table . "sys_userid = ".$_SESSION["s"]["user"]["userid"]." AND " . $table . "sys_perm_user like '%$perm%') OR ";
1561-
$sql .= "(" . $table . "sys_groupid IN (".$groups.") AND " . $table ."sys_perm_group like '%$perm%') OR ";
1559+
if ($userid === NULL) {
1560+
$userid = $_SESSION["s"]["user"]["userid"];
1561+
}
1562+
if ($userid > 0) {
1563+
$sql .= "(" . $table . "sys_userid = ".$userid." AND " . $table . "sys_perm_user like '%$perm%') OR ";
1564+
}
1565+
1566+
if ($groups === NULL) {
1567+
$groups = ( $_SESSION["s"]["user"]["groups"] ) ? $_SESSION["s"]["user"]["groups"] : 0;
1568+
}
1569+
if ($groups > 0) {
1570+
$sql .= "(" . $table . "sys_groupid IN (".$groups.") AND " . $table ."sys_perm_group like '%$perm%') OR ";
1571+
}
15621572
$sql .= $table . "sys_perm_other like '%$perm%'";
15631573
$sql .= ')';
15641574

interface/web/dashboard/dashlets/limits.php

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

33
class dashlet_limits {
44

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

88
$limits = array();
@@ -148,6 +148,12 @@ function show() {
148148
$client = $app->db->queryOneRecord("SELECT * FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
149149
}
150150

151+
if ($limit_to_client_id == 0 || !$app->auth->is_admin()) {
152+
$client_id = $_SESSION['s']['user']['client_id'];
153+
} else {
154+
$client_id = $limit_to_client_id;
155+
}
156+
151157
$rows = array();
152158
foreach($limits as $limit) {
153159
$field = $limit['field'];
@@ -159,10 +165,10 @@ function show() {
159165
if($value != 0 || $value == $wb['unlimited_txt']) {
160166
$value_formatted = ($value == '-1')?$wb['unlimited_txt']:$value;
161167
if($limit['q_type']!=''){
162-
$usage = $this->_get_assigned_quota($limit) . " MB";
168+
$usage = $this->_get_assigned_quota($limit, $client_id) . " MB";
163169
$value_formatted = ($value == '-1')?$wb['unlimited_txt']:$value . " MB";
164170
}
165-
else $usage = $this->_get_limit_usage($limit);
171+
else $usage = $this->_get_limit_usage($limit, $client_id);
166172
$percentage = ($value == '-1' || $value == 0 ? 0 : round(100 * $usage / $value));
167173
$rows[] = array('field' => $field,
168174
'field_txt' => $wb[$field.'_txt'],
@@ -181,23 +187,26 @@ function show() {
181187

182188
}
183189

184-
function _get_limit_usage($limit) {
190+
function _get_limit_usage($limit, $limit_to_client_id) {
185191
global $app;
186192

187193
$sql = "SELECT count(sys_userid) as number FROM ?? WHERE ";
188194
if($limit['db_where'] != '') $sql .= $limit['db_where']." AND ";
189-
$sql .= $app->tform->getAuthSQL('r');
195+
$sql .= $app->tform->getAuthSQL('r', '', $limit_to_client_id);
196+
// TEST to show reseller data.
197+
//$sql .= $app->tform->getAuthSQL('r', '', 0, '3,28,39');
198+
//echo $sql;
190199
$rec = $app->db->queryOneRecord($sql, $limit['db_table']);
191200
return $rec['number'];
192201

193202
}
194203

195-
function _get_assigned_quota($limit) {
204+
function _get_assigned_quota($limit, $limit_to_client_id) {
196205
global $app;
197206

198207
$sql = "SELECT sum(??) as number FROM ?? WHERE ";
199208
if($limit['db_where'] != '') $sql .= $limit['db_where']." AND ";
200-
$sql .= $app->tform->getAuthSQL('r');
209+
$sql .= $app->tform->getAuthSQL('r', '', $limit_to_client_id);
201210
$rec = $app->db->queryOneRecord($sql, $limit['q_type'], $limit['db_table']);
202211
if($limit['db_table']=='mail_user') $quotaMB = $rec['number'] / 1048576; // Mail quota is in bytes, must be converted to MB
203212
else $quotaMB = $rec['number'];

0 commit comments

Comments
 (0)