Commit e9a084ee authored by Dominik's avatar Dominik
Browse files

added Database-Quota Remote-Funktion

added Database-Quota dashlet
parent f42d9169
......@@ -160,4 +160,66 @@ class quota_lib {
return $emails;
}
public function get_databasequota_data($clientid = null, $readable = true) {
global $app;
$tmp_rec = $app->db->queryAllRecords("SELECT data from monitor_data WHERE type = 'database_size' ORDER BY created DESC");
$monitor_data = array();
if(is_array($tmp_rec)) {
foreach ($tmp_rec as $tmp_mon) {
$tmp_array = unserialize($app->db->unquote($tmp_mon['data']));
if(is_array($tmp_array)) {
foreach($tmp_array as $key => $data) {
if(!isset($monitor_data[$data['database_name']]['size'])) $monitor_data[$data['database_name']]['size'] = $data['size'];
}
}
}
}
//print_r($monitor_data);
// select all databases belonging to client
$databases = $app->db->queryAllRecords("SELECT * FROM web_database".(($clientid != null)? " WHERE sys_groupid = (SELECT default_group FROM sys_user WHERE client_id=?)" : ''), $clientid);
//print_r($databases);
if(is_array($databases) && !empty($databases)){
for($i=0;$i<sizeof($databases);$i++){
$databasename = $databases[$i]['database_name'];
$databases[$i]['used'] = isset($monitor_data[$databasename]['size']) ? $monitor_data[$databasename]['size'] : 0;
$databases[$i]['quota_raw'] = $databases[$i]['database_quota'];
$databases[$i]['used_raw'] = $databases[$i]['used'];
$databases[$i]['used_percentage'] = (($databases[$i]['database_quota'] > 0) && ($databases[$i]['used'] > 0)) ? round($databases[$i]['used'] * 100 / $databases[$i]['database_quota']) : 0;
if ($readable) {
// colours
$databases[$i]['display_colour'] = '#000000';
if($databases[$i]['database_quota'] > 0){
$used_ratio = $databases[$i]['used']/$databases[$i]['database_quota'];
} else {
$used_ratio = 0;
}
if($used_ratio >= 0.8) $databases[$i]['display_colour'] = '#fd934f';
if($used_ratio >= 1) $databases[$i]['display_colour'] = '#cc0000';
if($databases[$i]['database_quota'] == 0){
$databases[$i]['database_quota'] = $app->lng('unlimited');
} else {
$databases[$i]['database_quota'] = round($databases[$i]['database_quota'] / 1048576, 4).' MB';
}
if($databases[$i]['used'] < 1544000) {
$databases[$i]['used'] = round($databases[$i]['used'] / 1024, 4).' KB';
} else {
$databases[$i]['used'] = round($databases[$i]['used'] / 1048576, 4).' MB';
}
}
}
}
return $databases;
}
}
\ No newline at end of file
......@@ -966,6 +966,19 @@ class remoting_sites extends remoting {
return $app->quota_lib->get_quota_data($client_id, false);
}
public function databasequota_get_by_user($session_id, $client_id)
{
global $app;
$app->uses('quota_lib');
if(!$this->checkPerm($session_id, 'databasequota_get_by_user')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
return $app->quota_lib->get_databasequota_data($client_id, false);
}
}
......
......@@ -2,7 +2,7 @@
$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';
$function_list['domains_domain_get,domains_domain_add,domains_domain_delete,domains_get_all_by_user'] = 'Domaintool functions';
$function_list['quota_get_by_user,mailquota_get_by_user'] = 'Quota functions';
$function_list['quota_get_by_user,mailquota_get_by_user,databasequota_get_by_user'] = 'Quota functions';
?>
......@@ -157,7 +157,7 @@ while ($file = @readdir($handle)) {
/* Which dashlets in which column */
/******************************************************************************/
$default_leftcol_dashlets = array('modules', 'invoices', 'quota', 'mailquota');
$default_leftcol_dashlets = array('modules', 'invoices', 'quota', 'mailquota', 'databasequota');
$default_rightcol_dashlets = array('customer', 'products', 'shop', 'limits');
$app->uses('getconf');
......
<?php
class dashlet_databasequota {
function show() {
global $app;
//* Loading Template
$app->uses('tpl,quota_lib');
$tpl = new tpl;
$tpl->newTemplate("dashlets/templates/databasequota.htm");
$wb = array();
$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_dashlet_databasequota.lng';
if(is_file($lng_file)) include $lng_file;
$tpl->setVar($wb);
$databases = $app->quota_lib->get_databasequota_data( ($_SESSION["s"]["user"]["typ"] != 'admin') ? $_SESSION['s']['user']['client_id'] : null);
//print_r($databases);
$has_databasequota = false;
if(is_array($databases) && !empty($databases)){
$tpl->setloop('databasequota', $databases);
$has_databasequota = isset($databases[0]['used']);
}
$tpl->setVar('has_databasequota', $has_databasequota);
return $tpl->grab();
}
}
?>
<div class='table-wrapper'>
<table class='table'>
<caption>{tmpl_var name='databasequota_txt'}</caption>
<thead class="dark form-group-sm">
<tr>
<th>{tmpl_var name='database_txt'}</th>
<th>{tmpl_var name='used_txt'}</th>
<th colspan="2">{tmpl_var name='quota_txt'}</th>
</tr>
</thead>
<tbody>
<tmpl_loop name='databasequota'>
<tr>
<td>{tmpl_var name='database_name'}</td>
<td>{tmpl_var name='used'}</td>
<td>{tmpl_var name='database_quota'}</td>
<td>
<div class='progress'>
<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"}%'>
<span class='sr-only'>{tmpl_var name='used'} {tmpl_var name='of_txt'} {tmpl_var name='database_quota'}</span>
</div>
</div>
</td>
</tr>
</tmpl_loop>
</tbody>
</table>
</div>
\ No newline at end of file
<?php
$wb['databasequota_txt'] = 'Database Quota';
$wb['database_txt'] = 'Database Name';
$wb['used_txt'] = 'Used Space';
$wb['quota_txt'] = 'Quota';
$wb['no_database_accounts_txt'] = 'No databases found.';
?>
<?php
$wb['databasequota_txt'] = 'Database Quota';
$wb['database_txt'] = 'Database Name';
$wb['used_txt'] = 'Used Space';
$wb['quota_txt'] = 'Quota';
$wb['no_database_accounts_txt'] = 'No databases found.';
?>
<?php
$wb['databasequota_txt'] = 'Database Quota';
$wb['database_txt'] = 'Database Name';
$wb['used_txt'] = 'Used Space';
$wb['quota_txt'] = 'Quota';
$wb['no_database_accounts_txt'] = 'No databases found.';
?>
<?php
$wb['mailquota_txt'] = 'Database Quota';
$wb['database_txt'] = 'Database Name';
$wb['used_txt'] = 'Used Space';
$wb['quota_txt'] = 'Quota';
$wb['no_database_accounts_txt'] = 'No databases found.';
?>
<?php
$wb['databasequota_txt'] = 'Datenbank Quota';
$wb['database_txt'] = 'Datenbank Name';
$wb['used_txt'] = 'Verwendet';
$wb['quota_txt'] = 'Verfügbar';
$wb['no_database_accounts_txt'] = 'Keine Datenbanken gefunden.';
?>
<?php
$wb['databasequota_txt'] = 'Database Quota';
$wb['database_txt'] = 'Database Name';
$wb['used_txt'] = 'Used Space';
$wb['quota_txt'] = 'Quota';
$wb['no_database_accounts_txt'] = 'No databases found.';
?>
<?php
$wb['databasequota_txt'] = 'Database Quota';
$wb['database_txt'] = 'Database Name';
$wb['used_txt'] = 'Used Space';
$wb['quota_txt'] = 'Quota';
$wb['no_database_accounts_txt'] = 'No databases found.';
?>
<?php
$wb['databasequota_txt'] = 'Database Quota';
$wb['database_txt'] = 'Database Name';
$wb['used_txt'] = 'Used Space';
$wb['quota_txt'] = 'Quota';
$wb['no_database_accounts_txt'] = 'No databases found.';
?>
<?php
$wb['databasequota_txt'] = 'Database Quota';
$wb['database_txt'] = 'Database Name';
$wb['used_txt'] = 'Used Space';
$wb['quota_txt'] = 'Quota';
$wb['no_database_accounts_txt'] = 'No databases found.';
?>
<?php
$wb['databasequota_txt'] = 'Database Quota';
$wb['database_txt'] = 'Database Name';
$wb['used_txt'] = 'Used Space';
$wb['quota_txt'] = 'Quota';
$wb['no_database_accounts_txt'] = 'No databases found.';
?>
<?php
$wb['databasequota_txt'] = 'Database Quota';
$wb['database_txt'] = 'Database Name';
$wb['used_txt'] = 'Used Space';
$wb['quota_txt'] = 'Quota';
$wb['no_database_accounts_txt'] = 'No databases found.';
?>
<?php
$wb['databasequota_txt'] = 'Database Quota';
$wb['database_txt'] = 'Database Name';
$wb['used_txt'] = 'Used Space';
$wb['quota_txt'] = 'Quota';
$wb['no_database_accounts_txt'] = 'No databases found.';
?>
<?php
$wb['databasequota_txt'] = 'Database Quota';
$wb['database_txt'] = 'Database Name';
$wb['used_txt'] = 'Used Space';
$wb['quota_txt'] = 'Quota';
$wb['no_database_accounts_txt'] = 'No databases found.';
?>
<?php
$wb['databasequota_txt'] = 'Database Quota';
$wb['database_txt'] = 'Database Name';
$wb['used_txt'] = 'Used Space';
$wb['quota_txt'] = 'Quota';
$wb['no_database_accounts_txt'] = 'No databases found.';
?>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment