piler/webui/controller/accounting/accounting.php

132 lines
5.5 KiB
PHP
Raw Permalink Normal View History

2013-02-16 12:33:25 +01:00
<?php
class ControllerAccountingAccounting extends Controller {
private $error = array();
public function index(){
$this->id = "content";
$this->template = "accounting/accounting.tpl";
$this->layout = "common/layout";
$request = Registry::get('request');
$db = Registry::get('db');
$this->load->model('user/user');
$this->load->model('group/group');
2013-09-18 22:59:51 +02:00
$this->load->model('domain/domain');
2013-02-16 12:33:25 +01:00
$this->load->model('accounting/accounting');
2013-07-20 11:15:13 +02:00
if(ENABLE_SAAS == 1) {
$this->load->model('saas/ldap');
}
2013-02-16 12:33:25 +01:00
$this->data['page'] = 0;
$this->data['page_len'] = get_page_length();
$this->data['sort'] = 'item';
$this->data['sorttype'] = 0;
$this->data['order'] = 0;
$this->data['search'] = '';
/* get search term if there's any */
if(isset($this->request->post['search'])) { $this->data['search'] = $this->request->post['search']; }
else if(isset($this->request->get['search'])) { $this->data['search'] = $this->request->get['search']; }
2013-02-16 12:33:25 +01:00
// get page
if(isset($this->request->get['page']) && is_numeric($this->request->get['page']) && $this->request->get['page'] > 0) {
$this->data['page'] = $this->request->get['page'];
}
// get sort field
if ( isset($this->request->get['sort']) ) {
if(@$this->request->get['sort'] == "item") { $this->data['sort'] = 'item'; }
if(@$this->request->get['sort'] == "oldest") { $this->data['sort'] = 'oldest'; $this->data['sorttype'] = 1; }
if(@$this->request->get['sort'] == "newest") { $this->data['sort'] = 'newest'; $this->data['sorttype'] = 1; }
if(@$this->request->get['sort'] == "sent") { $this->data['sort'] = 'sent'; }
if(@$this->request->get['sort'] == "sentsize") { $this->data['sort'] = 'sentsize'; $this->data['sorttype'] = 2; }
if(@$this->request->get['sort'] == "sentavg") { $this->data['sort'] = 'sentavg'; $this->data['sorttype'] = 2; }
if(@$this->request->get['sort'] == "recd") { $this->data['sort'] = 'recd'; }
if(@$this->request->get['sort'] == "recdsize") { $this->data['sort'] = 'recdsize'; $this->data['sorttype'] = 2; }
if(@$this->request->get['sort'] == "recdavg") { $this->data['sort'] = 'recdavg'; $this->data['sorttype'] = 2; }
}
// get sort order
if(isset($this->request->get['order']) && is_numeric($this->request->get['order'])) {
$this->data['order'] = $this->request->get['order'];
}
// get type of accounting view
if(@$this->request->get['view'] == "email") {
$this->data['view'] = 'email';
2013-03-28 16:37:12 +01:00
$this->data['viewname'] = $this->data['text_email'];
2013-07-20 11:15:13 +02:00
$this->data['accounting'] = $this->model_accounting_accounting->get_accounting('email',$this->data['search'], $this->data['page'], $this->data['page_len'], $this->data['sort'], $this->data['order']);
$this->data['total_records'] = $this->model_accounting_accounting->count_accounting('email',$this->data['search']);
2013-02-16 12:33:25 +01:00
}
if(@$this->request->get['view'] == "domain") {
$this->data['view'] = 'domain';
2013-03-28 16:37:12 +01:00
$this->data['viewname'] = $this->data['text_domain'];
2013-07-20 11:15:13 +02:00
$this->data['accounting'] = $this->model_accounting_accounting->get_accounting('domain',$this->data['search'], $this->data['page'], $this->data['page_len'], $this->data['sort'], $this->data['order']);
$this->data['total_records'] = $this->model_accounting_accounting->count_accounting('domain',$this->data['search']);
2013-09-18 22:59:51 +02:00
$this->data['mydomain_count'] = $this->model_domain_domain->count_mydomains();
$this->data['user_count'] = 0;
2013-07-20 11:15:13 +02:00
if(ENABLE_SAAS == 1) {
$this->data['accounts'] = array();
foreach($this->data['accounting'] as $a) {
$this->data['accounts'][$a['item']] = $this->model_saas_ldap->get_accounts_in_domain($a['item']);
2013-09-18 22:59:51 +02:00
$this->data['user_count'] += count($this->data['accounts'][$a['item']]);
2013-07-20 11:15:13 +02:00
}
2013-09-18 22:59:51 +02:00
2013-07-20 11:15:13 +02:00
}
2013-02-16 12:33:25 +01:00
}
2013-07-20 11:15:13 +02:00
if(@$this->request->get['view'] == "accounts" && isset($this->request->get['domain'])) {
$this->template = "accounting/accounts.tpl";
$this->data['domain'] = $this->request->get['domain'];
$this->data['accounts'] = $this->model_saas_ldap->get_accounts_in_domain($this->request->get['domain']);
}
2013-02-16 12:33:25 +01:00
if($this->data['accounting']) {
foreach($this->data['accounting'] as $id=>$row) {
if($this->data['sorttype'] == 0){
$this->data['accounting'][$id]['display'] = $row[$this->data['sort']];
}
if($this->data['sorttype'] == 1){
2013-08-18 13:59:55 +02:00
$this->data['accounting'][$id]['display'] = date(DATE_TEMPLATE, $row[$this->data['sort']]);
2013-02-16 12:33:25 +01:00
}
if($this->data['sorttype'] == 2){
$this->data['accounting'][$id]['display'] = nice_size($row[$this->data['sort']]);
}
}
}
$this->document->title = $this->data['text_accounting'];
$this->data['today'] = time()-(time()%86400);
$this->data['days'] = 15;
$this->data['timespan'] = @$this->request->get['timespan'];
$this->data['uid'] = @$this->request->get['uid'];
$this->data['admin_user'] = Registry::get('admin_user');
$this->data['readonly_admin'] = Registry::get('readonly_admin');
$this->data['prev_page'] = $this->data['page'] - 1;
$this->data['next_page'] = $this->data['page'] + 1;
$this->data['total_pages'] = floor($this->data['total_records'] / $this->data['page_len']);
$this->render();
}
}
?>