Skip to content

Commit e9a084e

Browse files
author
Dominik
committed
added Database-Quota Remote-Funktion
added Database-Quota dashlet
1 parent f42d916 commit e9a084e

29 files changed

+307
-2
lines changed

interface/lib/classes/quota_lib.inc.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,66 @@ public function get_mailquota_data($clientid = null, $readable = true) {
160160

161161
return $emails;
162162
}
163+
164+
public function get_databasequota_data($clientid = null, $readable = true) {
165+
global $app;
166+
167+
$tmp_rec = $app->db->queryAllRecords("SELECT data from monitor_data WHERE type = 'database_size' ORDER BY created DESC");
168+
$monitor_data = array();
169+
if(is_array($tmp_rec)) {
170+
foreach ($tmp_rec as $tmp_mon) {
171+
$tmp_array = unserialize($app->db->unquote($tmp_mon['data']));
172+
if(is_array($tmp_array)) {
173+
foreach($tmp_array as $key => $data) {
174+
if(!isset($monitor_data[$data['database_name']]['size'])) $monitor_data[$data['database_name']]['size'] = $data['size'];
175+
}
176+
}
177+
}
178+
}
179+
//print_r($monitor_data);
180+
181+
// select all databases belonging to client
182+
$databases = $app->db->queryAllRecords("SELECT * FROM web_database".(($clientid != null)? " WHERE sys_groupid = (SELECT default_group FROM sys_user WHERE client_id=?)" : ''), $clientid);
183+
184+
//print_r($databases);
185+
if(is_array($databases) && !empty($databases)){
186+
for($i=0;$i<sizeof($databases);$i++){
187+
$databasename = $databases[$i]['database_name'];
188+
189+
$databases[$i]['used'] = isset($monitor_data[$databasename]['size']) ? $monitor_data[$databasename]['size'] : 0;
190+
191+
$databases[$i]['quota_raw'] = $databases[$i]['database_quota'];
192+
$databases[$i]['used_raw'] = $databases[$i]['used'];
193+
$databases[$i]['used_percentage'] = (($databases[$i]['database_quota'] > 0) && ($databases[$i]['used'] > 0)) ? round($databases[$i]['used'] * 100 / $databases[$i]['database_quota']) : 0;
194+
195+
if ($readable) {
196+
// colours
197+
$databases[$i]['display_colour'] = '#000000';
198+
if($databases[$i]['database_quota'] > 0){
199+
$used_ratio = $databases[$i]['used']/$databases[$i]['database_quota'];
200+
} else {
201+
$used_ratio = 0;
202+
}
203+
if($used_ratio >= 0.8) $databases[$i]['display_colour'] = '#fd934f';
204+
if($used_ratio >= 1) $databases[$i]['display_colour'] = '#cc0000';
205+
206+
if($databases[$i]['database_quota'] == 0){
207+
$databases[$i]['database_quota'] = $app->lng('unlimited');
208+
} else {
209+
$databases[$i]['database_quota'] = round($databases[$i]['database_quota'] / 1048576, 4).' MB';
210+
}
211+
212+
213+
if($databases[$i]['used'] < 1544000) {
214+
$databases[$i]['used'] = round($databases[$i]['used'] / 1024, 4).' KB';
215+
} else {
216+
$databases[$i]['used'] = round($databases[$i]['used'] / 1048576, 4).' MB';
217+
}
218+
}
219+
}
220+
}
221+
222+
return $databases;
223+
}
224+
163225
}

interface/lib/classes/remote.d/sites.inc.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,19 @@ public function quota_get_by_user($session_id, $client_id)
966966
return $app->quota_lib->get_quota_data($client_id, false);
967967
}
968968

969+
public function databasequota_get_by_user($session_id, $client_id)
970+
{
971+
global $app;
972+
$app->uses('quota_lib');
973+
974+
if(!$this->checkPerm($session_id, 'databasequota_get_by_user')) {
975+
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
976+
return false;
977+
}
978+
979+
return $app->quota_lib->get_databasequota_data($client_id, false);
980+
}
981+
969982

970983
}
971984

interface/web/client/lib/remote.conf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
$function_list['client_get_all,client_get,client_add,client_update,client_delete,client_get_sites_by_user,client_get_by_username,client_change_password,client_get_id,client_delete_everything,client_get_emailcontact'] = 'Client functions';
44
$function_list['domains_domain_get,domains_domain_add,domains_domain_delete,domains_get_all_by_user'] = 'Domaintool functions';
5-
$function_list['quota_get_by_user,mailquota_get_by_user'] = 'Quota functions';
5+
$function_list['quota_get_by_user,mailquota_get_by_user,databasequota_get_by_user'] = 'Quota functions';
66

77

88
?>

interface/web/dashboard/dashboard.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157

158158
/* Which dashlets in which column */
159159
/******************************************************************************/
160-
$default_leftcol_dashlets = array('modules', 'invoices', 'quota', 'mailquota');
160+
$default_leftcol_dashlets = array('modules', 'invoices', 'quota', 'mailquota', 'databasequota');
161161
$default_rightcol_dashlets = array('customer', 'products', 'shop', 'limits');
162162

163163
$app->uses('getconf');
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
class dashlet_databasequota {
4+
5+
function show() {
6+
global $app;
7+
8+
//* Loading Template
9+
$app->uses('tpl,quota_lib');
10+
11+
$tpl = new tpl;
12+
$tpl->newTemplate("dashlets/templates/databasequota.htm");
13+
14+
$wb = array();
15+
$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_dashlet_databasequota.lng';
16+
if(is_file($lng_file)) include $lng_file;
17+
$tpl->setVar($wb);
18+
19+
$databases = $app->quota_lib->get_databasequota_data( ($_SESSION["s"]["user"]["typ"] != 'admin') ? $_SESSION['s']['user']['client_id'] : null);
20+
//print_r($databases);
21+
22+
$has_databasequota = false;
23+
if(is_array($databases) && !empty($databases)){
24+
$tpl->setloop('databasequota', $databases);
25+
$has_databasequota = isset($databases[0]['used']);
26+
}
27+
$tpl->setVar('has_databasequota', $has_databasequota);
28+
29+
return $tpl->grab();
30+
}
31+
32+
}
33+
34+
35+
36+
37+
38+
39+
40+
41+
?>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<div class='table-wrapper'>
2+
<table class='table'>
3+
<caption>{tmpl_var name='databasequota_txt'}</caption>
4+
<thead class="dark form-group-sm">
5+
<tr>
6+
<th>{tmpl_var name='database_txt'}</th>
7+
<th>{tmpl_var name='used_txt'}</th>
8+
<th colspan="2">{tmpl_var name='quota_txt'}</th>
9+
</tr>
10+
</thead>
11+
<tbody>
12+
<tmpl_loop name='databasequota'>
13+
<tr>
14+
<td>{tmpl_var name='database_name'}</td>
15+
<td>{tmpl_var name='used'}</td>
16+
<td>{tmpl_var name='database_quota'}</td>
17+
<td>
18+
<div class='progress'>
19+
<div class='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"}%'>
20+
<span class='sr-only'>{tmpl_var name='used'} {tmpl_var name='of_txt'} {tmpl_var name='database_quota'}</span>
21+
</div>
22+
</div>
23+
</td>
24+
</tr>
25+
</tmpl_loop>
26+
</tbody>
27+
</table>
28+
</div>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
$wb['databasequota_txt'] = 'Database Quota';
3+
$wb['database_txt'] = 'Database Name';
4+
$wb['used_txt'] = 'Used Space';
5+
$wb['quota_txt'] = 'Quota';
6+
$wb['no_database_accounts_txt'] = 'No databases found.';
7+
?>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
$wb['databasequota_txt'] = 'Database Quota';
3+
$wb['database_txt'] = 'Database Name';
4+
$wb['used_txt'] = 'Used Space';
5+
$wb['quota_txt'] = 'Quota';
6+
$wb['no_database_accounts_txt'] = 'No databases found.';
7+
?>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
$wb['databasequota_txt'] = 'Database Quota';
3+
$wb['database_txt'] = 'Database Name';
4+
$wb['used_txt'] = 'Used Space';
5+
$wb['quota_txt'] = 'Quota';
6+
$wb['no_database_accounts_txt'] = 'No databases found.';
7+
?>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
$wb['mailquota_txt'] = 'Database Quota';
3+
$wb['database_txt'] = 'Database Name';
4+
$wb['used_txt'] = 'Used Space';
5+
$wb['quota_txt'] = 'Quota';
6+
$wb['no_database_accounts_txt'] = 'No databases found.';
7+
?>

0 commit comments

Comments
 (0)