Marius Cramer
2015-08-06 37b29231e47a0c4458dc1c15d98588f16f07e1e2
commit | author | age
532ae5 1 <?php
L 2
3 class dashlet_limits {
7fe908 4
532ae5 5     function show() {
L 6         global $app, $conf;
7fe908 7
532ae5 8         $limits = array();
7fe908 9
532ae5 10         /* Limits to be shown*/
7fe908 11
532ae5 12         $limits[] = array('field' => 'limit_maildomain',
7fe908 13             'db_table' => 'mail_domain',
MC 14             'db_where' => '');
15
532ae5 16         $limits[] = array('field' => 'limit_mailmailinglist',
7fe908 17             'db_table' => 'mail_mailinglist',
MC 18             'db_where' => '');
19
532ae5 20         $limits[] = array('field' => 'limit_mailbox',
7fe908 21             'db_table' => 'mail_user',
MC 22             'db_where' => '');
23
532ae5 24         $limits[] = array('field' => 'limit_mailalias',
7fe908 25             'db_table' => 'mail_forwarding',
MC 26             'db_where' => "type = 'alias'");
27
532ae5 28         $limits[] = array('field' => 'limit_mailaliasdomain',
7fe908 29             'db_table' => 'mail_forwarding',
MC 30             'db_where' => "type = 'aliasdomain'");
31
532ae5 32         $limits[] = array('field' => 'limit_mailforward',
7fe908 33             'db_table' => 'mail_forwarding',
MC 34             'db_where' => "type = 'forward'");
35
532ae5 36         $limits[] = array('field' => 'limit_mailcatchall',
7fe908 37             'db_table' => 'mail_forwarding',
MC 38             'db_where' => "type = 'catchall'");
39
532ae5 40         $limits[] = array('field' => 'limit_mailrouting',
7fe908 41             'db_table' => 'mail_transport',
MC 42             'db_where' => "");
43
532ae5 44         $limits[] = array('field' => 'limit_mailfilter',
7fe908 45             'db_table' => 'mail_user_filter',
MC 46             'db_where' => "");
47
532ae5 48         $limits[] = array('field' => 'limit_fetchmail',
7fe908 49             'db_table' => 'mail_get',
MC 50             'db_where' => "");
51
532ae5 52         $limits[] = array('field' => 'limit_spamfilter_wblist',
7fe908 53             'db_table' => 'spamfilter_wblist',
MC 54             'db_where' => "");
55
532ae5 56         $limits[] = array('field' => 'limit_spamfilter_user',
7fe908 57             'db_table' => 'spamfilter_users',
MC 58             'db_where' => "");
59
532ae5 60         $limits[] = array('field' => 'limit_spamfilter_policy',
7fe908 61             'db_table' => 'spamfilter_policy',
MC 62             'db_where' => "");
63
532ae5 64         $limits[] = array('field' => 'limit_web_domain',
7fe908 65             'db_table' => 'web_domain',
MC 66             'db_where' => "type = 'vhost'");
67
532ae5 68         $limits[] = array('field' => 'limit_web_subdomain',
7fe908 69             'db_table' => 'web_domain',
MC 70             'db_where' => "(type = 'subdomain' OR type = 'vhostsubdomain')");
71
532ae5 72         $limits[] = array('field' => 'limit_web_aliasdomain',
7fe908 73             'db_table' => 'web_domain',
779b17 74                           'db_where' => "(type = 'alias' OR type = 'vhostalias')");
7fe908 75
532ae5 76         $limits[] = array('field' => 'limit_ftp_user',
7fe908 77             'db_table' => 'ftp_user',
MC 78             'db_where' => "");
532ae5 79
L 80         $limits[] = array('field' => 'limit_shell_user',
7fe908 81             'db_table' => 'shell_user',
MC 82             'db_where' => "");
83
532ae5 84         $limits[] = array('field' => 'limit_dns_zone',
7fe908 85             'db_table' => 'dns_soa',
MC 86             'db_where' => "");
532ae5 87
L 88         $limits[] = array('field' => 'limit_dns_slave_zone',
7fe908 89             'db_table' => 'dns_slave',
MC 90             'db_where' => "");
532ae5 91
L 92         $limits[] = array('field' => 'limit_dns_record',
7fe908 93             'db_table' => 'dns_rr',
MC 94             'db_where' => "");
95
532ae5 96         $limits[] = array('field' => 'limit_database',
7fe908 97             'db_table' => 'web_database',
MC 98             'db_where' => "");
99
532ae5 100         $limits[] = array('field' => 'limit_cron',
7fe908 101             'db_table' => 'cron',
MC 102             'db_where' => "");
103
532ae5 104         $limits[] = array('field' => 'limit_client',
7fe908 105             'db_table' => 'client',
MC 106             'db_where' => "");
107
4aec30 108         $limits[] = array('field' => 'limit_domain',
TB 109             'db_table' => 'domain',
110             'db_where' => "");
7fe908 111
MC 112
532ae5 113         //* Loading Template
L 114         $app->uses('tpl,tform');
7fe908 115
532ae5 116         $tpl = new tpl;
L 117         $tpl->newTemplate("dashlets/templates/limits.htm");
7fe908 118
532ae5 119         $wb = array();
L 120         $lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_dashlet_limits.lng';
7fe908 121         if(is_file($lng_file)) include $lng_file;
532ae5 122         $tpl->setVar($wb);
7fe908 123
532ae5 124         if($app->auth->is_admin()) {
L 125             $user_is_admin = true;
126         } else {
127             $user_is_admin = false;
128         }
7fe908 129         $tpl->setVar('is_admin', $user_is_admin);
MC 130
532ae5 131         if($user_is_admin == false) {
604c0c 132             $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
cc7a82 133             $client = $app->db->queryOneRecord("SELECT * FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
532ae5 134         }
7fe908 135
532ae5 136         $rows = array();
L 137         foreach($limits as $limit) {
138             $field = $limit['field'];
139             if($user_is_admin) {
140                 $value = $wb['unlimited_txt'];
141             } else {
142                 $value = $client[$field];
143             }
144             if($value != 0 || $value == $wb['unlimited_txt']) {
145                 $value_formatted = ($value == '-1')?$wb['unlimited_txt']:$value;
d2713e 146                 $usage = $this->_get_limit_usage($limit);
MC 147                 $percentage = ($value == '-1' || $value == 0 ? 0 : round(100 * $usage / $value));
532ae5 148                 $rows[] = array('field' => $field,
7fe908 149                     'field_txt' => $wb[$field.'_txt'],
MC 150                     'value' => $value_formatted,
d2713e 151                     'value_raw' => $value,
MC 152                     'usage' => $usage,
153                     'usage_raw' => $usage,
154                     'percentage' => $percentage);
532ae5 155             }
L 156         }
7fe908 157         $tpl->setLoop('rows', $rows);
MC 158
159
532ae5 160         return $tpl->grab();
7fe908 161
532ae5 162     }
7fe908 163
532ae5 164     function _get_limit_usage($limit) {
L 165         global $app;
7fe908 166
cc7a82 167         $sql = "SELECT count(sys_userid) as number FROM ?? WHERE ";
532ae5 168         if($limit['db_where'] != '') $sql .= $limit['db_where']." AND ";
L 169         $sql .= $app->tform->getAuthSQL('r');
cc7a82 170         $rec = $app->db->queryOneRecord($sql, $limit['db_table']);
532ae5 171         return $rec['number'];
7fe908 172
532ae5 173     }
7fe908 174
532ae5 175 }
L 176
177
178
179
180
181
182
183
184 ?>