| | |
| | | <?php |
| | | |
| | | class quota_lib { |
| | | public function get_quota_data($groupid = null, $readable = true) { |
| | | public function get_quota_data($clientid = null, $readable = true) { |
| | | global $app; |
| | | |
| | | $tmp_rec = $app->db->queryAllRecords("SELECT data from monitor_data WHERE type = 'harddisk_quota' ORDER BY created DESC"); |
| | |
| | | } |
| | | //print_r($monitor_data); |
| | | |
| | | if($groupid != null){ |
| | | $sql_where = " AND sys_groupid = ".$groupid; |
| | | } |
| | | // select all websites or websites belonging to client |
| | | $sites = $app->db->queryAllRecords("SELECT * FROM web_domain WHERE active = 'y' AND type = 'vhost'".(($clientid != null)?" AND sys_groupid = (SELECT default_group FROM sys_user WHERE client_id=?)":''), $app->functions->intval($client_id)); |
| | | |
| | | // select websites belonging to client |
| | | $sites = $app->db->queryAllRecords("SELECT * FROM web_domain WHERE active = 'y' AND type = 'vhost'".$sql_where); |
| | | //print_r($sites); |
| | | if(is_array($sites) && !empty($sites)){ |
| | | for($i=0;$i<sizeof($sites);$i++){ |
| | |
| | | return $sites; |
| | | } |
| | | |
| | | public function get_mailquota_data($groupid = null, $readable = true) { |
| | | public function get_mailquota_data($clientid = null, $readable = true) { |
| | | global $app; |
| | | |
| | | $tmp_rec = $app->db->queryAllRecords("SELECT data from monitor_data WHERE type = 'email_quota' ORDER BY created DESC"); |
| | |
| | | } |
| | | //print_r($monitor_data); |
| | | |
| | | if($groupid != null){ |
| | | $sql_where = " AND sys_groupid = ".$groupid; |
| | | } |
| | | // select all email accounts or email accounts belonging to client |
| | | $emails = $app->db->queryAllRecords("SELECT * FROM mail_user".(($clientid != null)? " WHERE sys_groupid = (SELECT default_group FROM sys_user WHERE client_id=?)" : ''), $app->functions->intval($client_id)); |
| | | |
| | | |
| | | // select email accounts belonging to client |
| | | $emails = $app->db->queryAllRecords("SELECT * FROM mail_user WHERE 1".$sql_where); |
| | | //print_r($emails); |
| | | if(is_array($emails) && !empty($emails)){ |
| | | for($i=0;$i<sizeof($emails);$i++){ |
| | |
| | | $emails[$i]['used'] = isset($monitor_data[$email]['used']) ? $monitor_data[$email]['used'] : array(1 => 0); |
| | | |
| | | if (!is_numeric($emails[$i]['used'])) $emails[$i]['used']=$emails[$i]['used'][1]; |
| | | |
| | | // colours |
| | | $emails[$i]['display_colour'] = '#000000'; |
| | | if($emails[$i]['quota'] > 0){ |
| | | $used_ratio = $emails[$i]['used']/$emails[$i]['quota']; |
| | | } else { |
| | | $used_ratio = 0; |
| | | } |
| | | if($used_ratio >= 0.8) $emails[$i]['display_colour'] = '#fd934f'; |
| | | if($used_ratio >= 1) $emails[$i]['display_colour'] = '#cc0000'; |
| | | |
| | | if($emails[$i]['quota'] == 0){ |
| | | $emails[$i]['quota'] = $app->lng('unlimited'); |
| | | } else { |
| | | $emails[$i]['quota'] = round($emails[$i]['quota'] / 1048576, 4).' MB'; |
| | | } |
| | | |
| | | |
| | | if($emails[$i]['used'] < 1544000) { |
| | | $emails[$i]['used'] = round($emails[$i]['used'] / 1024, 4).' KB'; |
| | | } else { |
| | | $emails[$i]['used'] = round($emails[$i]['used'] / 1048576, 4).' MB'; |
| | | |
| | | if ($readable) { |
| | | // colours |
| | | $emails[$i]['display_colour'] = '#000000'; |
| | | if($emails[$i]['quota'] > 0){ |
| | | $used_ratio = $emails[$i]['used']/$emails[$i]['quota']; |
| | | } else { |
| | | $used_ratio = 0; |
| | | } |
| | | if($used_ratio >= 0.8) $emails[$i]['display_colour'] = '#fd934f'; |
| | | if($used_ratio >= 1) $emails[$i]['display_colour'] = '#cc0000'; |
| | | |
| | | if($emails[$i]['quota'] == 0){ |
| | | $emails[$i]['quota'] = $app->lng('unlimited'); |
| | | } else { |
| | | $emails[$i]['quota'] = round($emails[$i]['quota'] / 1048576, 4).' MB'; |
| | | } |
| | | |
| | | |
| | | if($emails[$i]['used'] < 1544000) { |
| | | $emails[$i]['used'] = round($emails[$i]['used'] / 1024, 4).' KB'; |
| | | } else { |
| | | $emails[$i]['used'] = round($emails[$i]['used'] / 1048576, 4).' MB'; |
| | | } |
| | | } |
| | | } |
| | | } |