Skip to content

Commit e406c48

Browse files
committed
Revert "Fixes #6528 Account limit incorrectly informed in dashboard"
This reverts commit 224a596.
1 parent 476b8e8 commit e406c48

File tree

4 files changed

+64
-31
lines changed

4 files changed

+64
-31
lines changed

interface/web/dashboard/dashlets/databasequota.php

Lines changed: 16 additions & 5 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,19 +23,30 @@ 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;
36+
$total_used = 0;
3137
if(is_array($databases) && !empty($databases)){
38+
foreach ($databases as &$db) {
39+
$total_used += $db['used_raw'] * 1000 * 1000;
40+
}
3241
$databases = $app->functions->htmlentities($databases);
3342
$tpl->setloop('databasequota', $databases);
3443
$has_databasequota = isset($databases[0]['used']);
44+
45+
$tpl->setVar('has_databasequota', $has_databasequota);
46+
$tpl->setVar('total_used', $app->functions->formatBytes($total_used, 0));
47+
48+
return $tpl->grab();
3549
}
36-
$tpl->setVar('has_databasequota', $has_databasequota);
37-
38-
return $tpl->grab();
3950
}
4051

4152
}

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: 15 additions & 5 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,23 +16,33 @@ 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;
29+
$total_used = 0;
2330
if(is_array($emails) && !empty($emails)){
2431
foreach($emails as &$email) {
2532
$email['email'] = $app->functions->idn_decode($email['email']);
33+
$total_used += $email['used_raw'];
2634
}
2735
unset($email);
2836
// email username is quoted in quota.lib already, so no htmlentities here to prevent double encoding
2937
//$emails = $app->functions->htmlentities($emails);
3038
$tpl->setloop('mailquota', $emails);
3139
$has_mailquota = isset($emails[0]['used']);
32-
}
33-
$tpl->setVar('has_mailquota', $has_mailquota);
3440

35-
return $tpl->grab();
41+
$tpl->setVar('has_mailquota', $has_mailquota);
42+
$tpl->setVar('total_used', $app->functions->formatBytes($total_used, 0));
43+
44+
return $tpl->grab();
45+
}
3646
}
3747

3848
}

interface/web/dashboard/dashlets/quota.php

Lines changed: 13 additions & 6 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,26 +24,33 @@ 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;
3137
if(is_array($sites) && !empty($sites)){
3238
foreach($sites as &$site) {
3339
$site['domain'] = $app->functions->idn_decode($site['domain']);
3440
$site['progressbar'] = $site['hd_quota'];
41+
$total_used += $site['used_raw'] * 1000;
3542
}
3643
unset($site);
3744

3845
$sites = $app->functions->htmlentities($sites);
3946
$tpl->setloop('quota', $sites);
4047
$has_quota = isset($sites[0]['used']);
41-
}
42-
$tpl->setVar('has_quota', $has_quota);
43-
44-
return $tpl->grab();
4548

49+
$tpl->setVar('has_quota', $has_quota);
50+
$tpl->setVar('total_used', $app->functions->formatBytes($total_used, 0));
4651

52+
return $tpl->grab();
53+
}
4754
}
4855

4956
}

0 commit comments

Comments
 (0)