Skip to content

Commit 1c6fba6

Browse files
committed
Lookup a client's group + all groups he is reselling.
1 parent 9a27599 commit 1c6fba6

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

interface/web/dashboard/dashlets/limits.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,12 @@ public function _get_limit_usage($limit, $limit_to_client_id)
202202
if ($limit['db_where'] != '') {
203203
$sql .= $limit['db_where']." AND ";
204204
}
205-
$group = $app->db->queryOneRecord("SELECT `groupid` FROM `sys_group` WHERE client_id=?", $limit_to_client_id);
206-
$sql .= $app->tform->getAuthSQL('r', '', $limit_to_client_id, $group['groupid']);
207-
// TEST to show reseller data.
208-
//$sql .= $app->tform->getAuthSQL('r', '', 0, '3,28,39');
209-
//echo $sql;
205+
$sql .= $app->tform->getAuthSQL('r', '', '', $this->clientid_to_groups_list($limit_to_client_id));
206+
210207
$rec = $app->db->queryOneRecord($sql, $limit['db_table']);
211208
return $rec['number'];
212209
}
213-
210+
214211
public function _get_assigned_quota($limit, $limit_to_client_id)
215212
{
216213
global $app;
@@ -219,14 +216,32 @@ public function _get_assigned_quota($limit, $limit_to_client_id)
219216
if ($limit['db_where'] != '') {
220217
$sql .= $limit['db_where']." AND ";
221218
}
222-
$sql .= $app->tform->getAuthSQL('r', '', $limit_to_client_id);
219+
$sql .= $app->tform->getAuthSQL('r', '', '', $this->clientid_to_groups_list($limit_to_client_id));
223220
$rec = $app->db->queryOneRecord($sql, $limit['q_type'], $limit['db_table']);
224221
if ($limit['db_table'] == 'mail_user') {
225222
$quotaMB = $rec['number'] / 1048576;
226223
} // Mail quota is in bytes, must be converted to MB
227224
else {
228225
$quotaMB = $app->functions->intval($rec['number']);
229-
}
230-
return $quotaMB;
226+
}
227+
return $quotaMB;
228+
}
229+
230+
/**
231+
* Lookup a client's group + all groups he is reselling.
232+
*
233+
* @return string Comma separated list of groupid's
234+
*/
235+
function clientid_to_groups_list($client_id) {
236+
global $app;
237+
238+
if ($client_id != null) {
239+
// Get the clients groupid, and incase it's a reseller the groupid's of it's clients.
240+
$group = $app->db->queryOneRecord("SELECT GROUP_CONCAT(groupid) AS groups FROM `sys_group` WHERE client_id IN (SELECT client_id FROM `client` WHERE client_id=? OR parent_client_id=?)", $client_id, $client_id);
241+
dnl($group);
242+
dnl($client_id);
243+
return $group['groups'];
244+
}
245+
return null;
231246
}
232247
}

0 commit comments

Comments
 (0)