First start at retiring Affiliate in favour of RTM

This commit is contained in:
Deon George
2013-04-05 09:42:29 +11:00
parent 9d4b2f50ff
commit 43dfd88bce
49 changed files with 680 additions and 570 deletions

View File

@@ -8,8 +8,26 @@
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
* @also [logout]
*/
class Controller_Account extends Controller_TemplateDefault {
public function action_group() {
$output = '';
$cg = $this->ao->group->find_all();
foreach ($cg as $go) {
$output .= sprintf('Group %s: %s<br/>',$go->id,$go->display('name'));
foreach ($go->list_childgrps(TRUE) as $cgo)
$output .= sprintf('- %s: %s (%s)<br/>',$cgo->id,$cgo->display('name'),$cgo->parent_id);
$output .= sprintf('END Group %s<br/><br/>',$go->id);
}
Block::add(array(
'title'=>'Group Structure',
'body'=>$output,
));
}
}
?>

View File

@@ -9,69 +9,9 @@
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_Admin_Account extends Controller_TemplateDefault_Admin {
class Controller_Admin_Account extends Controller_Account {
protected $secure_actions = array(
'ajaxlist'=>FALSE, // @todo To Change
'list'=>TRUE,
'listlog'=>TRUE,
'group'=>FALSE, // @todo Testing
);
public function action_ajaxlist() {
$return = array();
if (isset($_REQUEST['term']) AND trim($_REQUEST['term']))
$return += ORM::factory('Account')->list_autocomplete($_REQUEST['term']);
$this->auto_render = FALSE;
$this->response->headers('Content-Type','application/json');
$this->response->body(json_encode(array_values($return)));
}
/**
* Show a list of account logins
*/
public function action_listlog() {
Block::add(array(
'title'=>_('Account Login Log'),
'body'=>Table::display(
ORM::factory('Account_Log')->order_by('id','DESC')->find_all(),
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,
)),
));
}
/**
* Show a list of accounts
*/
public function action_list() {
Block::add(array(
'title'=>_('Customer List'),
'body'=>Table::display(
ORM::factory('Account')->list_active(),
25,
array(
'id'=>array('label'=>'ID','url'=>URL::link('user','account/view/')),
'accnum()'=>array('label'=>'Num'),
'name(TRUE)'=>array('label'=>'Account'),
'email'=>array('label'=>'Email'),
'invoices_due_total(NULL,TRUE)'=>array('label'=>'Invoices','class'=>'right'),
'count_services(TRUE,NULL)'=>array('label'=>'Services','class'=>'right'),
),
array(
'page'=>TRUE,
'type'=>'select',
'form'=>URL::link('user','account/view'),
)),
));
}
}
?>

View File

@@ -9,7 +9,7 @@
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_Admin_Module extends Controller_TemplateDefault_Admin {
class Controller_Admin_Module extends Controller_Module {
protected $secure_actions = array(
'add'=>TRUE,
'edit'=>TRUE,

View File

@@ -9,7 +9,7 @@
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_Admin_Setup extends Controller_TemplateDefault_Admin {
class Controller_Admin_Setup extends Controller_TemplateDefault {
protected $secure_actions = array(
'edit'=>TRUE,
);

View File

@@ -9,13 +9,13 @@
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_Admin_Welcome extends Controller_TemplateDefault_Admin {
class Controller_Admin_Welcome extends Controller_Welcome {
protected $auth_required = TRUE;
public $secure_actions = array(
'index'=>TRUE,
);
public function action_index() {
$ao = ORM::factory('Account',Auth::instance()->get_user()->id);
$t = time();
// Show outstanding invoices
@@ -99,11 +99,31 @@ class Controller_Admin_Welcome extends Controller_TemplateDefault_Admin {
));
Block::add(array(
'title'=>sprintf('%s: %s %s',$ao->accnum(),$ao->first_name,$ao->last_name),
'title'=>sprintf('%s: %s %s',$this->ao->accnum(),$this->ao->first_name,$this->ao->last_name),
'subtitle'=>_('Administrator Overview'),
'body'=>(string)Block_Sub::factory(),
));
// We are a site administrator
if ($this->ao->rtm_id == NULL) {
$rtmo = ORM::factory('RTM',array('account_id','=',$this->ao->id))->find();
// Quick validation, if we are an admin, we should have an entry in the RTM table.
if (! $rtmo->loaded())
throw new Kohana_Exception('User :aid not set up properly',array(':aid'=>$this->ao->id));
$output = View::factory('welcome/admin')
->set('o',$rtmo);
} else {
$rtmo = ORM::factory('RTM',$this->ao->rmt_id);
}
if ($output)
Block::add(array(
'title'=>sprintf('Reseller %s',$this->ao->display('company')),
'body'=>$output,
));
}
}
?>

View File

@@ -1,42 +0,0 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides Affiliate Account functions
*
* @package OSB
* @category Controllers/Affiliate
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_Affiliate_Account extends Controller_TemplateDefault_Affiliate {
protected $secure_actions = array(
'list'=>TRUE,
);
/**
* 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->affiliate->id,'sortkey(TRUE)'),
25,
array(
'id'=>array('label'=>'ID','url'=>URL::link('user','account/view/')),
'accnum()'=>array('label'=>'Num'),
'name(TRUE)'=>array('label'=>'Account'),
'email'=>array('label'=>'Email'),
'invoices_due_total(NULL,TRUE)'=>array('label'=>'Invoices','class'=>'right'),
'count_services(TRUE,'.$this->ao->affiliate->id.')'=>array('label'=>'Services','class'=>'right'),
),
array(
'page'=>TRUE,
'type'=>'select',
'form'=>URL::link('user','account/view'),
)),
));
}
}
?>

View File

@@ -0,0 +1,81 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides Reseller Account management
*
* @package OSB
* @category Controllers/Reseller
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_Reseller_Account extends Controller_Account {
protected $secure_actions = array(
'ajaxlist'=>TRUE,
'list'=>TRUE,
'listlog'=>TRUE,
);
/**
* Used by AJAX calls to find accounts
* @note list_autocomplete() will limit to authorised accounts
*/
public function action_ajaxlist() {
$return = array();
if (isset($_REQUEST['term']) AND trim($_REQUEST['term']))
$return += ORM::factory('Account')->list_autocomplete($_REQUEST['term']);
$this->auto_render = FALSE;
$this->response->headers('Content-Type','application/json');
$this->response->body(json_encode(array_values($return)));
}
/**
* 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),'sortkey(TRUE)','id'),
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'),
)),
));
}
/**
* 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),NULL,'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,
)),
));
}
}
?>

View File

@@ -0,0 +1,25 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* lnApp Main home page
*
* @package OSB
* @category Controllers/Reseller
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_Reseller_Welcome extends Controller_Welcome {
protected $auth_required = TRUE;
protected $secure_actions = array(
'index'=>TRUE,
);
public function action_index() {
Block::add(array(
'title'=>sprintf('%s: %s',$this->ao->accnum(),$this->ao->name(TRUE)),
'body'=>View::factory('welcome/reseller'),
));
}
}
?>

View File

@@ -10,9 +10,14 @@
* @license http://dev.osbill.net/license.html
*/
class Controller_TemplateDefault extends lnApp_Controller_TemplateDefault {
protected $auth_required = TRUE;
// Our acccount object
protected $ao;
public function __construct(Request $request, Response $response) {
if (Config::theme())
$this->template = Config::theme().'/page';
$this->template = 'theme/'.Config::theme().'/page';
return parent::__construct($request,$response);
}
@@ -38,11 +43,91 @@ class Controller_TemplateDefault extends lnApp_Controller_TemplateDefault {
}
protected function _right() {
return ($this->template->right) ? $this->template->right : $this->_cart();
return ($this->template->right) ? $this->template->right : '';
}
private function _cart() {
return (! Config::module_exist('cart') OR ! class_exists('Cart') OR ! count(Cart::instance()->contents()) OR strtolower(Request::current()->controller()) == 'cart') ? '' : Cart::instance()->cart_block();
public function before() {
// If our action doesnt exist, no point processing any further.
if (! method_exists($this,'action_'.Request::current()->action()))
return;
if ($this->auth_required) {
if (! count($this->secure_actions) OR (! isset($this->secure_actions[Request::current()->action()])))
throw new Kohana_Exception('Class has no security defined :class, or no security configured for :method',array(':class'=>get_class($this),':method'=>Request::current()->action()));
$this->ao = Auth::instance()->get_user();
if (! is_null($this->ao) AND (is_string($this->ao) OR ! $this->ao->loaded()))
throw new Kohana_Exception('Account doesnt exist :account ?',array(':account'=>(is_string($this->ao) OR is_null($this->ao)) ? $this->ao : Auth::instance()->get_user()->id));
}
parent::before();
}
public function after() {
$dc = Kohana::$config->load('config','user_default_method');
$m = sprintf('%s/%s',Request::current()->directory(),Request::current()->controller());
BreadCrumb::URL(Request::current()->directory(),sprintf('%s/%s',Request::current()->directory(),$dc),FALSE);
BreadCrumb::URL($m,method_exists($this,'action_menu') ? $m.'/menu' : sprintf('%s/%s',Request::current()->directory(),$dc),FALSE);
parent::after();
}
/**
* This will filter a search query to only return those accounts for a reseller
*/
protected function filter($o,$af,$sort=NULL,$afid=NULL) {
$result = array();
foreach ($o as $x) {
if (! is_null($afid) AND isset($x->$afid)) {
if ((is_array($af) AND in_array($x->$afid,$af)) OR ($x->$afid == $af))
array_push($result,$x);
} elseif (method_exists($x,'list_reseller')) {
if (in_array($af,$x->list_reseller()))
array_push($result,$x);
}
}
if ($sort)
Sort::MAsort($result,$sort);
return $result;
}
protected function setup(array $config_items=array()) {
$module = Request::current()->controller();
if ($_POST AND isset($_POST['module_config'][$module]))
Config::instance()->module_config($module,$_POST['module_config'][$module])->save();
if ($config_items) {
$output = '';
$mc = Config::instance()->module_config($module);
$output .= Form::open();
$output .= View::factory('setup/admin/module/head');
foreach ($config_items as $k=>$v)
$output .= View::factory('setup/admin/module/body')
->set('module',$module)
->set('mc',$mc)
->set('key',$k)
->set('info',$v)
->set('val',isset($mc[$k]) ? $mc[$k] : '');
$output .= View::factory('setup/admin/module/foot');
$output .= Form::submit('submit',_('Submit'),array('class'=>'form_button'));
$output .= Form::close();
Block::add(array(
'title'=>sprintf('%s: %s',strtoupper($module),_('Configuration')),
'body'=>$output,
));
}
}
}
?>

View File

@@ -10,37 +10,14 @@
* @license http://dev.osbill.net/license.html
*/
class Controller_TemplateDefault_Admin extends Controller_TemplateDefault_User {
protected function setup(array $config_items=array()) {
$module = Request::current()->controller();
public function after() {
SystemMessage::add(array(
'title'=>'Retire this class extension',
'type'=>'info',
'body'=>__METHOD__,
));
if ($_POST AND isset($_POST['module_config'][$module]))
Config::instance()->module_config($module,$_POST['module_config'][$module])->save();
if ($config_items) {
$output = '';
$mc = Config::instance()->module_config($module);
$output .= Form::open();
$output .= View::factory('setup/admin/module/head');
foreach ($config_items as $k=>$v)
$output .= View::factory('setup/admin/module/body')
->set('module',$module)
->set('mc',$mc)
->set('key',$k)
->set('info',$v)
->set('val',isset($mc[$k]) ? $mc[$k] : '');
$output .= View::factory('setup/admin/module/foot');
$output .= Form::submit('submit',_('Submit'),array('class'=>'form_button'));
$output .= Form::close();
Block::add(array(
'title'=>sprintf('%s: %s',strtoupper($module),_('Configuration')),
'body'=>$output,
));
}
return parent::after();
}
}
?>

View File

@@ -10,28 +10,14 @@
* @license http://dev.osbill.net/license.html
*/
class Controller_TemplateDefault_Affiliate extends Controller_TemplateDefault_User {
/**
* This will filter a search query to only return the affiliates
*/
protected function filter($o,$af,$sort='account->name()',$afid='affiliate_id') {
$result = array();
public function after() {
SystemMessage::add(array(
'title'=>'Retire this class extension',
'type'=>'info',
'body'=>__METHOD__,
));
foreach ($o as $x) {
if (isset($x->$afid)) {
if ($x->$afid == $af)
array_push($result,$x);
} elseif (method_exists($x,'list_affiliates')) {
if (in_array($af,$x->list_affiliates()))
array_push($result,$x);
}
}
if ($sort)
Sort::MAsort($result,$sort);
return $result;
return parent::after();
}
}
?>

View File

@@ -10,34 +10,14 @@
* @license http://dev.osbill.net/license.html
*/
class Controller_TemplateDefault_User extends Controller_TemplateDefault {
protected $auth_required = TRUE;
// Our acccount object
protected $ao;
public function before() {
// If our action doesnt exist, no point processing any further.
if (! method_exists($this,'action_'.Request::current()->action()))
return;
if (! count($this->secure_actions) OR (! isset($this->secure_actions[Request::current()->action()])))
throw new Kohana_Exception('Class has no security defined :class, or no security configured for :method',array(':class'=>get_class($this),':method'=>Request::current()->action()));
parent::before();
$this->ao = Auth::instance()->get_user();
if (is_string($this->ao) OR ! $this->ao->loaded())
throw new Kohana_Exception('Account doesnt exist :account ?',array(':account'=>is_string($this->ao) ? $this->ao : Auth::instance()->get_user()->id));
}
public function after() {
$dc = 'welcome/index';
$m = sprintf('%s/%s',Request::current()->directory(),Request::current()->controller());
SystemMessage::add(array(
'title'=>'Retire this class extension',
'type'=>'info',
'body'=>__METHOD__,
));
BreadCrumb::URL(Request::current()->directory(),sprintf('%s/%s',Request::current()->directory(),$dc),FALSE);
BreadCrumb::URL($m,method_exists($this,'action_menu') ? $m.'/menu' : sprintf('%s/%s',Request::current()->directory(),$dc),FALSE);
parent::after();
return parent::after();
}
}
?>

View File

@@ -9,12 +9,52 @@
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_User_Account extends Controller_TemplateDefault_User {
class Controller_User_Account extends Controller_Account {
protected $secure_actions = array(
'edit'=>TRUE,
'resetpassword'=>TRUE,
);
/**
* Enable User to Edit their Account Details
*/
public function action_edit() {
// Store our new values
$this->ao->values($_POST);
// Run validation and save
if ($this->ao->changed())
if ($this->ao->check()) {
SystemMessage::add(array(
'title'=>_('Record updated'),
'type'=>'info',
'body'=>_('Your account record has been updated.')
));
$this->ao->save();
} else {
$output = '';
foreach ($this->ao->validation()->errors('forms/login') as $field => $error)
$output .= sprintf('<li><b>%s</b> %s</li>',$field,$error);
if ($output)
$output = sprintf('<ul>%s</ul>',$output);
SystemMessage::add(array(
'title'=>_('Record NOT updated'),
'type'=>'error',
'body'=>_('Your updates didnt pass validation.').'<br/>'.$output,
));
}
Block::add(array(
'title'=>sprintf('%s: %s - %s',_('Account Edit'),$this->ao->accnum(),$this->ao->name(TRUE)),
'body'=>View::factory($this->viewpath())
->set('record',$this->ao),
));
}
public function action_resetpassword() {
// @todo Fix this next logic, since matches_ifset is not being called when the value is on the form, but empty
if (empty($_POST['password_confirm']))
@@ -60,45 +100,5 @@ class Controller_User_Account extends Controller_TemplateDefault_User {
->set('record',$this->ao),
));
}
/**
* Show a product
*/
public function action_edit() {
// Store our new values
$this->ao->values($_POST);
// Run validation and save
if ($this->ao->changed())
if ($this->ao->check()) {
SystemMessage::add(array(
'title'=>_('Record updated'),
'type'=>'info',
'body'=>_('Your account record has been updated.')
));
$this->ao->save();
} else {
$output = '';
foreach ($this->ao->validation()->errors('forms/login') as $field => $error)
$output .= sprintf('<li><b>%s</b> %s</li>',$field,$error);
if ($output)
$output = sprintf('<ul>%s</ul>',$output);
SystemMessage::add(array(
'title'=>_('Record NOT updated'),
'type'=>'error',
'body'=>_('Your updates didnt pass validation.').'<br/>'.$output,
));
}
Block::add(array(
'title'=>sprintf('%s: %s - %s',_('Account Edit'),$this->ao->accnum(),$this->ao->name(TRUE)),
'body'=>View::factory($this->viewpath())
->set('record',$this->ao),
));
}
}
?>

View File

@@ -9,17 +9,16 @@
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_User_Welcome extends Controller_TemplateDefault_User {
class Controller_User_Welcome extends Controller_Welcome {
protected $auth_required = TRUE;
protected $secure_actions = array(
'index'=>FALSE,
);
'index'=>TRUE,
);
public function action_index() {
$ao = ORM::factory('Account',Auth::instance()->get_user()->id);
Block::add(array(
'title'=>sprintf('%s: %s %s',$ao->accnum(),$ao->first_name,$ao->last_name),
'body'=>'Please select from the tree on the left',
'title'=>sprintf('%s: %s',$this->ao->accnum(),$this->ao->name(TRUE)),
'body'=>View::factory('welcome/user'),
));
}
}