diff --git a/application/classes/Controller/Reseller/Account.php b/application/classes/Controller/Reseller/Account.php index 87f7d7cb..d38fcb0e 100644 --- a/application/classes/Controller/Reseller/Account.php +++ b/application/classes/Controller/Reseller/Account.php @@ -36,47 +36,44 @@ class Controller_Reseller_Account extends Controller_Account { * Show a list of accounts */ public function action_list() { - Block::add(array( - 'title'=>_('Customer List'), - 'body'=>Table::display( - $this->filter(ORM::factory('Account')->list_active(),$this->ao->RTM->customers($this->ao->RTM),'id','sortkey(TRUE)'), - 25, - array( - 'id'=>array('label'=>'ID','url'=>URL::link('reseller','invoice/list/')), - 'accnum()'=>array('label'=>'Num'), - 'name(TRUE)'=>array('label'=>'Account'), - 'email'=>array('label'=>'Email'), - 'invoices_due_total(NULL,TRUE)'=>array('label'=>'Invoices','class'=>'right'), - 'services_count(TRUE)'=>array('label'=>'Services','class'=>'right'), - ), - array( - 'page'=>TRUE, - 'type'=>'select', - 'form'=>URL::link('reseller','invoice/list'), - )), - )); + Block::factory() + ->title(_('Customer List')) + ->title_icon('icon-th-list') + ->body(Table::factory() + ->data(ORM::factory('Account')->where('id','IN',$this->ao->RTM->customers($this->ao->RTM))->find_all()) + ->jssort('customer') + ->columns(array( + 'id'=>'ID', + 'accnum()'=>'Num', + 'name(TRUE)'=>'Account', + 'email'=>'Email', + 'invoices_due_total(NULL,TRUE)'=>'Invoices', + 'services_count(TRUE)'=>'Services', + )) + ->prepend(array( + 'id'=>array('url'=>URL::link('reseller','account/view/')), + )) + ); } /** * Show a list of account logins */ public function action_listlog() { - Block::add(array( - 'title'=>_('Account Login Log'), - 'body'=>Table::display( - $this->filter(ORM::factory('Account_Log')->find_all(),$this->ao->RTM->customers($this->ao->RTM),'account_id'), - 25, - array( - 'id'=>array('label'=>'ID'), - 'date_orig'=>array('label'=>'Date'), - 'account->name()'=>array('label'=>'Account'), - 'ip'=>array('label'=>'IP Address'), - 'details'=>array('label'=>'Details'), - ), - array( - 'page'=>TRUE, - )), - )); + Block::factory() + ->title(_('Customer Login Activity')) + ->title_icon('icon-eye-open') + ->body(Table::factory() + ->data(ORM::factory('Account_Log')->where('account_id','IN',$this->ao->RTM->customers($this->ao->RTM))->find_all()) + ->page_items(25) + ->columns(array( + 'id'=>'ID', + 'date_orig'=>'Date', + 'account->name()'=>'Account', + 'ip'=>'IP Address', + 'details'=>'Details', + )) + ); } public function action_view() { @@ -90,13 +87,13 @@ class Controller_Reseller_Account extends Controller_Account { ->span(6) ->body(Table::factory() ->data($ao->service->list_active()) - ->columns(array( - 'id'=>'ID', - 'service_name()'=>'Service', - )) - ->prepend(array( - 'id'=>array('url'=>URL::link('user','service/view/')), - )) + ->columns(array( + 'id'=>'ID', + 'service_name()'=>'Service', + )) + ->prepend(array( + 'id'=>array('url'=>URL::link('user','service/view/')), + )) ); Block::factory() @@ -105,15 +102,15 @@ class Controller_Reseller_Account extends Controller_Account { ->span(6) ->body(Table::factory() ->data($ao->invoice->list_due()) - ->columns(array( - 'id'=>'ID', - 'due_date'=>'Date Due', - 'total(TRUE)'=>'Invoice Total', - 'due(TRUE)'=>'Amount Due', - )) - ->prepend(array( - 'id'=>array('url'=>URL::link('user','invoice/view/')), - )) + ->columns(array( + 'id'=>'ID', + 'due_date'=>'Date Due', + 'total(TRUE)'=>'Invoice Total', + 'due(TRUE)'=>'Amount Due', + )) + ->prepend(array( + 'id'=>array('url'=>URL::link('user','invoice/view/')), + )) ); Block::factory() @@ -122,14 +119,14 @@ class Controller_Reseller_Account extends Controller_Account { ->span(6) ->body(Table::factory() ->data($ao->service->list_expiring()) - ->columns(array( - 'id'=>'ID', - 'service_name()'=>'Service', - 'expire(TRUE)'=>'Date', - )) - ->prepend(array( - 'id'=>array('url'=>URL::link('user','service/view/')), - )) + ->columns(array( + 'id'=>'ID', + 'service_name()'=>'Service', + 'expire(TRUE)'=>'Date', + )) + ->prepend(array( + 'id'=>array('url'=>URL::link('user','service/view/')), + )) ); } } diff --git a/application/classes/Controller/TemplateDefault.php b/application/classes/Controller/TemplateDefault.php index c82100cf..431e9f49 100644 --- a/application/classes/Controller/TemplateDefault.php +++ b/application/classes/Controller/TemplateDefault.php @@ -50,27 +50,6 @@ class Controller_TemplateDefault extends lnApp_Controller_TemplateDefault { parent::after(); } - /** - * This will filter a search query to only return those accounts for a reseller - * - * @param $o Our ORM Object that we are searching on - * @param $fl Our array of items that we must return - * @param $flid The ID that must be in the $fl - * @param $sort Sort the results - */ - protected function filter($o,array $fl,$flid,$sort=NULL) { - $result = array(); - - foreach ($o as $x) - if (! is_null($flid) AND isset($x->$flid) AND in_array($x->$flid,$fl)) - array_push($result,$x); - - if ($sort) - Sort::MAsort($result,$sort); - - return $result; - } - protected function setup(array $config_items=array()) { $module = Request::current()->controller(); diff --git a/modules/adsl/classes/Controller/Reseller/Service/Adsl.php b/modules/adsl/classes/Controller/Reseller/Service/Adsl.php index e2d7ee9e..5e5322af 100644 --- a/modules/adsl/classes/Controller/Reseller/Service/Adsl.php +++ b/modules/adsl/classes/Controller/Reseller/Service/Adsl.php @@ -47,7 +47,7 @@ class Controller_Reseller_Service_Adsl extends Controller_Service { } public function action_list() { - $svs = $this->filter(ORM::factory('Service')->list_byplugin('ADSL'),$this->ao->RTM->customers($this->ao->RTM),'account_id','name()'); + $svs = ORM::factory('Service')->where('account_id','IN',$this->ao->RTM->customers($this->ao->RTM))->list_byplugin('ADSL'); $data = $this->consoltraffic($svs,time()); diff --git a/modules/domain/classes/Controller/Reseller/Service/Domain.php b/modules/domain/classes/Controller/Reseller/Service/Domain.php index ee9ca90e..0bbf46ba 100644 --- a/modules/domain/classes/Controller/Reseller/Service/Domain.php +++ b/modules/domain/classes/Controller/Reseller/Service/Domain.php @@ -19,8 +19,8 @@ class Controller_Reseller_Service_Domain extends Controller_Service { ->title('Domain License Services') ->title_icon('icon-th-list') ->body(Table::factory() - ->jssort('adsl') - ->data($this->filter(ORM::factory('Service')->list_byplugin('DOMAIN'),$this->ao->RTM->customers($this->ao->RTM),'account_id','name()')) + ->jssort('domain') + ->data(ORM::factory('Service')->where('account_id','IN',$this->ao->RTM->customers($this->ao->RTM))->list_byplugin('DOMAIN')) ->columns(array( 'id'=>'ID', 'name()'=>'Service', diff --git a/modules/domain/classes/Controller/Reseller/Service/Host.php b/modules/host/classes/Controller/Reseller/Service/Host.php similarity index 86% rename from modules/domain/classes/Controller/Reseller/Service/Host.php rename to modules/host/classes/Controller/Reseller/Service/Host.php index 4d3d1058..ac6ffd40 100644 --- a/modules/domain/classes/Controller/Reseller/Service/Host.php +++ b/modules/host/classes/Controller/Reseller/Service/Host.php @@ -19,8 +19,8 @@ class Controller_Reseller_Service_Host extends Controller_Service { ->title('Hosting Services') ->title_icon('icon-th-list') ->body(Table::factory() - ->jssort('adsl') - ->data($this->filter(ORM::factory('Service')->list_byplugin('HOST'),$this->ao->RTM->customers($this->ao->RTM),'account_id','name()')) + ->jssort('host') + ->data(ORM::factory('Service')->where('account_id','IN',$this->ao->RTM->customers($this->ao->RTM))->list_byplugin('HOST')) ->columns(array( 'id'=>'ID', 'name()'=>'Service', diff --git a/modules/invoice/classes/Controller/Reseller/Invoice.php b/modules/invoice/classes/Controller/Reseller/Invoice.php index 7985c7dc..51b812cd 100644 --- a/modules/invoice/classes/Controller/Reseller/Invoice.php +++ b/modules/invoice/classes/Controller/Reseller/Invoice.php @@ -10,22 +10,31 @@ * @license http://dev.osbill.net/license.html */ class Controller_Reseller_Invoice extends Controller_Invoice { + protected $secure_actions = array( + 'list'=>TRUE, + ); + public function action_list() { - list($id,$output) = Table::page(__METHOD__); - - $ao = ORM::factory('Account',$id); - - if (! $ao->loaded() OR ! Auth::instance()->authorised($ao)) - throw HTTP_Exception::factory(403,'Unauthorised or doesnt exist?'); - - Block::add(array( - 'body'=>$output, - )); - - $this->ao = $ao; - - // @todo Our pagination is broken if we select multiple accounts, and those accounts have multiple invoices. - return parent::action_list(); + Block::factory() + ->title('Customer Invoices') + ->title_icon('icon-th-list') + ->body(Table::factory() + ->jssort('invoices') + ->data(ORM::factory('Invoice')->where('account_id','IN',$this->ao->RTM->customers($this->ao->RTM))->where_active()->find_all()) + ->page_items(25) + ->columns(array( + 'id'=>'ID', + 'date_orig'=>'Date Created', + 'due_date'=>'Date Due', + 'total(TRUE)'=>'Total', + 'due(TRUE)'=>'Due', + 'account->accnum()'=>'Cust ID', + 'account->name()'=>'Customer', + )) + ->prepend(array( + 'id'=>array('url'=>URL::link('user','invoice/view/')), + )) + ); } } ?> diff --git a/modules/service/classes/Controller/Reseller/Service.php b/modules/service/classes/Controller/Reseller/Service.php index 8cd8b11e..e5a13a48 100644 --- a/modules/service/classes/Controller/Reseller/Service.php +++ b/modules/service/classes/Controller/Reseller/Service.php @@ -25,7 +25,7 @@ class Controller_Reseller_Service extends Controller_Service { ->title_icon('icon-th-list') ->body(Table::factory() ->jssort('services') - ->data($this->filter(ORM::factory('Service')->find_all(),$this->ao->RTM->customers($this->ao->RTM),'account_id')) + ->data(ORM::factory('Service')->where('account_id','IN',$this->ao->RTM->customers($this->ao->RTM))->find_all()) ->columns(array( 'id'=>'ID', 'service_name()'=>'Service', @@ -49,9 +49,9 @@ class Controller_Reseller_Service extends Controller_Service { // @todo This needs to be configurable $go = ORM::factory('Group',array('name'=>'Personal')); - foreach (ORM::factory('Account')->list_active() as $ao) + foreach (ORM::factory('Account')->where_active()->where('id','IN',$this->ao->RTM->customers($this->ao->RTM))->find_all() as $ao) if ($ao->has_any('group',array($go))) - foreach ($this->filter($ao->service->list_active(),$this->ao->RTM->customers($this->ao->RTM),'account_id') as $so) + foreach ($ao->service->list_active() as $so) if (! $so->service_billing->checkout_plugin_id) array_push($svs,$so); @@ -80,8 +80,8 @@ class Controller_Reseller_Service extends Controller_Service { foreach (ORM::factory('Checkout')->find_all() as $co) { $svs = array(); - foreach ($co->account->find_all() as $ao) - foreach ($this->filter($ao->service->list_active(),$this->ao->RTM->customers($this->ao->RTM),'account_id') as $so) + foreach ($co->account->where('account.id','IN',$this->ao->RTM->customers($this->ao->RTM))->find_all() as $ao) + foreach ($ao->service->list_active() as $so) if ($so->service_billing->checkout_plugin_id == $co->id) array_push($svs,$so);