General tidying up

This commit is contained in:
Deon George 2011-08-26 11:16:48 +10:00
parent 8598408a59
commit 1c66acd7e4
19 changed files with 173 additions and 115 deletions

View File

@ -39,7 +39,7 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
* @var array actions that require a valid user * @var array actions that require a valid user
*/ */
protected $secure_actions = array( protected $secure_actions = array(
'menu' => TRUE, 'menu' => FALSE,
); );
/** /**
@ -203,7 +203,7 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
* Default Method to call from the tree menu * Default Method to call from the tree menu
*/ */
public function action_menu() { public function action_menu() {
$this->template->content = 'See menu on tree'; $this->template->content = _('Please choose from the menu.');
} }
protected function _headimages() { protected function _headimages() {

View File

@ -0,0 +1,15 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* OSB User Main home page controller
*
* @package OSB
* @subpackage Page/Admin
* @category Controllers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Controller_TemplateDefault_Admin extends Controller_TemplateDefault_User {
}
?>

View File

@ -0,0 +1,30 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* OSB User Main home page controller
*
* @package OSB
* @subpackage Page/User
* @category Controllers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Controller_TemplateDefault_User extends Controller_TemplateDefault {
protected $auth_required = TRUE;
// Our acccount object
protected $ao;
public function before() {
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 = ORM::factory('account',Auth::instance()->get_user()->id);
if (! $this->ao->loaded())
throw new Kohana_Exception('Account doesnt exist :account ?',array(':account'=>Auth::instance()->get_user()->id));
}
}
?>

View File

@ -10,40 +10,35 @@
* @copyright (c) 2010 Deon George * @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html * @license http://dev.leenooks.net/license.html
*/ */
class Controller_User_Account extends Controller_TemplateDefault { class Controller_User_Account extends Controller_TemplateDefault_User {
public $secure_actions = array( protected $secure_actions = array(
'edit'=>TRUE, 'edit'=>TRUE,
'resetpassword'=>TRUE, 'resetpassword'=>TRUE,
); );
public function action_resetpassword() { public function action_resetpassword() {
$ao = Auth::instance()->get_user();
if (! $ao->loaded())
throw new Kohana_Exception('Account doesnt exist :account ?',array(':account'=>$ao->id));
// @todo Fix this next logic, since matches_ifset is not being called when the value is on the form, but empty // @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'])) if (empty($_POST['password_confirm']))
$_POST['password_confirm'] = ' '; $_POST['password_confirm'] = ' ';
// Store our new values // Store our new values
$ao->values($_POST); $this->ao->values($_POST);
// Run validation and save // Run validation and save
if ($ao->changed()) if ($this->ao->changed())
if ($ao->check()) { if ($this->ao->check()) {
SystemMessage::add(array( SystemMessage::add(array(
'title'=>_('Record updated'), 'title'=>_('Record updated'),
'type'=>'info', 'type'=>'info',
'body'=>_('Your account record has been updated.') 'body'=>_('Your account record has been updated.')
)); ));
$ao->save(); $this->ao->save();
Request::current()->redirect('login'); Request::current()->redirect('login');
} else { } else {
$output = ''; $output = '';
foreach ($ao->validation()->errors('forms/login') as $field => $error) foreach ($this->ao->validation()->errors('forms/login') as $field => $error)
$output .= sprintf('<li><b>%s</b> %s</li>',$field,$error); $output .= sprintf('<li><b>%s</b> %s</li>',$field,$error);
if ($output) if ($output)
@ -59,7 +54,7 @@ class Controller_User_Account extends Controller_TemplateDefault {
Block::add(array( Block::add(array(
'title'=>_('Password Reset'), 'title'=>_('Password Reset'),
'body'=>View::factory('account/password_reset') 'body'=>View::factory('account/password_reset')
->set('record',$ao), ->set('record',$this->ao),
)); ));
} }
@ -67,28 +62,23 @@ class Controller_User_Account extends Controller_TemplateDefault {
* Show a product * Show a product
*/ */
public function action_edit() { public function action_edit() {
$ao = Auth::instance()->get_user();
if (! $ao->loaded())
throw new Kohana_Exception('Account doesnt exist :account ?',array(':account'=>$ao->id));
// Store our new values // Store our new values
$ao->values($_POST); $this->ao->values($_POST);
// Run validation and save // Run validation and save
if ($ao->changed()) if ($this->ao->changed())
if ($ao->check()) { if ($this->ao->check()) {
SystemMessage::add(array( SystemMessage::add(array(
'title'=>_('Record updated'), 'title'=>_('Record updated'),
'type'=>'info', 'type'=>'info',
'body'=>_('Your account record has been updated.') 'body'=>_('Your account record has been updated.')
)); ));
$ao->save(); $this->ao->save();
} else { } else {
$output = ''; $output = '';
foreach ($ao->validation()->errors('forms/login') as $field => $error) foreach ($this->ao->validation()->errors('forms/login') as $field => $error)
$output .= sprintf('<li><b>%s</b> %s</li>',$field,$error); $output .= sprintf('<li><b>%s</b> %s</li>',$field,$error);
if ($output) if ($output)
@ -102,9 +92,9 @@ class Controller_User_Account extends Controller_TemplateDefault {
} }
Block::add(array( Block::add(array(
'title'=>sprintf('%s: %s - %s',_('Account Edit'),$ao->accnum(),$ao->name(TRUE)), 'title'=>sprintf('%s: %s - %s',_('Account Edit'),$this->ao->accnum(),$this->ao->name(TRUE)),
'body'=>View::factory('account/edit') 'body'=>View::factory('account/edit')
->set('record',$ao), ->set('record',$this->ao),
)); ));
} }
} }

View File

@ -0,0 +1,15 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides email management
*
* @package lnApp
* @subpackage Page/Email
* @category Controllers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Controller_Email extends Controller_TemplateDefault {
}
?>

View File

@ -10,13 +10,13 @@
* @copyright (c) 2010 Deon George * @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html * @license http://dev.leenooks.net/license.html
*/ */
class Controller_Admin_EmailTemplate extends Controller_TemplateDefault { class Controller_Admin_EmailTemplate extends Controller_TemplateDefault_Admin {
public $secure_actions = array( protected $secure_actions = array(
'add'=>TRUE,
'edit'=>TRUE,
'list'=>TRUE,
); );
public function action_menu() {
}
/** /**
* List our defined email templates * List our defined email templates
*/ */

View File

@ -0,0 +1,15 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides email management
*
* @package lnApp
* @subpackage Page/Email
* @category Controllers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Controller_EmailTemplate extends Controller_TemplateDefault {
}
?>

View File

@ -25,7 +25,7 @@ class Model_EmailTemplate extends ORMOSB {
); );
protected $_display_filters = array( protected $_display_filters = array(
'status'=>array( 'active'=>array(
array('StaticList_YesNo::display',array(':value')), array('StaticList_YesNo::display',array(':value')),
), ),
); );

View File

@ -10,9 +10,9 @@
* @copyright (c) 2010 Open Source Billing * @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html * @license http://dev.osbill.net/license.html
*/ */
class Controller_Admin_Export extends Controller_TemplateDefault { class Controller_Admin_Export extends Controller_TemplateDefault_Admin {
protected $control_title = 'Export'; protected $control_title = 'Export';
public $secure_actions = array( protected $secure_actions = array(
'index'=>TRUE, 'index'=>TRUE,
'export'=>TRUE, 'export'=>TRUE,
); );

View File

@ -10,7 +10,7 @@
* @copyright (c) 2010 Open Source Billing * @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html * @license http://dev.osbill.net/license.html
*/ */
class Controller_Admin_Invoice extends Controller_TemplateDefault { class Controller_Admin_Invoice extends Controller_TemplateDefault_Admin {
public function action_convert() { public function action_convert() {
if (Config::sitemode() != KOHANA::DEVELOPMENT) if (Config::sitemode() != KOHANA::DEVELOPMENT)
throw new Kohana_Exception(__METHOD__.' can only be run in development'); throw new Kohana_Exception(__METHOD__.' can only be run in development');

View File

@ -10,8 +10,8 @@
* @copyright (c) 2010 Deon George * @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html * @license http://dev.leenooks.net/license.html
*/ */
class Controller_User_Invoice extends Controller_TemplateDefault { class Controller_User_Invoice extends Controller_TemplateDefault_User {
public $secure_actions = array( protected $secure_actions = array(
'download'=>TRUE, 'download'=>TRUE,
'list'=>TRUE, 'list'=>TRUE,
'view'=>TRUE, 'view'=>TRUE,
@ -21,16 +21,10 @@ class Controller_User_Invoice extends Controller_TemplateDefault {
* Show a product * Show a product
*/ */
public function action_list() { public function action_list() {
$id = Auth::instance()->get_user()->id;
$ao = ORM::factory('account',$id);
if (! $ao->loaded())
throw new Kohana_Exception('Account doesnt exist :account ?',array(':account'=>$id));
Block::add(array( Block::add(array(
'title'=>sprintf('%s: %s - %s',_('Invoices For'),$ao->accnum(),$ao->name(TRUE)), 'title'=>sprintf('%s: %s - %s',_('Invoices For'),$this->ao->accnum(),$this->ao->name(TRUE)),
'body'=>View::factory('invoice/user/list') 'body'=>View::factory('invoice/user/list')
->set('invoices',$ao->invoice->find_all()), ->set('invoices',$this->ao->invoice->find_all()),
)); ));
} }

View File

@ -125,7 +125,7 @@ SELECT i.id AS iid,i.due_date AS due FROM ab_invoice i,ab_invoice_item ii WHERE
$pdf->drawRemittenceStub(); $pdf->drawRemittenceStub();
$pdf->drawPaymentMethods(); $pdf->drawPaymentMethods();
if ($this->io->billing_status !=1 && $this->io->suspend_billing != 1 && $this->io->due_date <= time()) if ($this->io->billing_status !=1 && $this->io->due_date <= time())
$pdf->drawInvoiceDueNotice(); $pdf->drawInvoiceDueNotice();
elseif($this->io->billing_status == 1) elseif($this->io->billing_status == 1)
$pdf->drawInvoicePaidNotice(); $pdf->drawInvoicePaidNotice();

View File

@ -10,14 +10,37 @@
* @copyright (c) 2010 Deon George * @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html * @license http://dev.leenooks.net/license.html
*/ */
class Controller_Admin_Module extends Controller_Module { class Controller_Admin_Module extends Controller_TemplateDefault_Admin {
protected $secure_actions = array(
'edit'=>TRUE,
'list'=>TRUE,
);
/** /**
* Our menu method * Get the list of methods for a class
*
* We need this method, otherwise we have redirect from our parent
*/ */
public function action_menu() { protected function _methods($class) {
$this->template->content = _('See menu on tree'); // Get a list of methods this module has
$ch = 'Controller_%s';
$methods = array();
// List of classes where all our methods are, including this one.
$classes = Kohana::config('config.method_directory');
array_unshift($classes,'');
foreach ($classes as $c) {
$cn = sprintf($ch,$c ? $c.'_'.$class : $class);
if (class_exists($cn)) {
$r = new ReflectionClass($cn);
foreach ($r->getMethods() as $method)
if (preg_match('/^Controller_(.*_)?'.$class.'$/i',$method->class) AND ! preg_match('/^_/',$method->name))
array_push($methods,str_replace('action_',($c ? $c.'_' : $c),$method->name));
}
}
return $methods;
} }
/** /**

View File

@ -11,42 +11,5 @@
* @license http://dev.leenooks.net/license.html * @license http://dev.leenooks.net/license.html
*/ */
class Controller_Module extends Controller_TemplateDefault { class Controller_Module extends Controller_TemplateDefault {
public $secure_actions = array(
'edit'=>TRUE,
'list'=>TRUE,
'menu'=>TRUE,
);
public function action_menu() {
// Redirect us to the admin menu, no user facilities here!
Request::current()->redirect('/admin/module/menu');
}
/**
* Get the list of methods for a class
*/
protected function _methods($class) {
// Get a list of methods this module has
$ch = 'Controller_%s';
$methods = array();
// List of classes where all our methods are, including this one.
$classes = Kohana::config('config.method_directory');
array_unshift($classes,'');
foreach ($classes as $c) {
$cn = sprintf($ch,$c ? $c.'_'.$class : $class);
if (class_exists($cn)) {
$r = new ReflectionClass($cn);
foreach ($r->getMethods() as $method)
if (preg_match('/^Controller_(.*_)?'.$class.'$/i',$method->class) AND ! preg_match('/^_/',$method->name))
array_push($methods,str_replace('action_',($c ? $c.'_' : $c),$method->name));
}
}
return $methods;
}
} }
?> ?>

View File

@ -0,0 +1,15 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides payment management
*
* @package lnApp
* @subpackage Page/Payment
* @category Controllers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Controller_Payment extends Controller_TemplateDefault {
}
?>

View File

@ -10,26 +10,19 @@
* @copyright (c) 2010 Deon George * @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html * @license http://dev.leenooks.net/license.html
*/ */
class Controller_User_Payment extends Controller_TemplateDefault { class Controller_User_Payment extends Controller_TemplateDefault_User {
public $secure_actions = array( protected $secure_actions = array(
'list'=>TRUE, 'list'=>TRUE,
'view'=>TRUE,
); );
/** /**
* Show a payments received * Show a payments received
*/ */
public function action_list() { public function action_list() {
$id = Auth::instance()->get_user()->id;
$ao = ORM::factory('account',$id);
if (! $ao->loaded())
throw new Kohana_Exception('Account doesnt exist :account ?',array(':account'=>$id));
Block::add(array( Block::add(array(
'title'=>sprintf('%s: %s - %s',_('Payments For'),$ao->accnum(),$ao->name(TRUE)), 'title'=>sprintf('%s: %s - %s',_('Payments For'),$this->ao->accnum(),$this->ao->name(TRUE)),
'body'=>View::factory('payment/user/list') 'body'=>View::factory('payment/user/list')
->set('payments',$ao->payment->find_all()), ->set('payments',$this->ao->payment->find_all()),
)); ));
} }
} }

View File

@ -10,10 +10,10 @@
* @copyright (c) 2010 Open Source Billing * @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html * @license http://dev.osbill.net/license.html
*/ */
class Controller_Admin_Service extends Controller_TemplateDefault { class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
protected $control = array('Services'=>'services'); protected $control = array('Services'=>'services');
public $secure_actions = array( protected $secure_actions = array(
'listbycheckout'=>TRUE, 'listbycheckout'=>TRUE,
'listadslservices'=>TRUE, 'listadslservices'=>TRUE,
'listhspaservices'=>TRUE, 'listhspaservices'=>TRUE,

View File

@ -0,0 +1,15 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides service management
*
* @package lnApp
* @subpackage Page/Service
* @category Controllers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Controller_Service extends Controller_TemplateDefault {
}
?>

View File

@ -10,21 +10,11 @@
* @copyright (c) 2010 Deon George * @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html * @license http://dev.leenooks.net/license.html
*/ */
class Controller_User_Service extends Controller_TemplateDefault { class Controller_User_Service extends Controller_TemplateDefault_User {
public $secure_actions = array( protected $secure_actions = array(
'list'=>TRUE, 'list'=>TRUE,
'view'=>TRUE, 'view'=>TRUE,
); );
// Our acccount object
private $ao;
public function before() {
parent::before();
$this->ao = ORM::factory('account',Auth::instance()->get_user()->id);
if (! $this->ao->loaded())
throw new Kohana_Exception('Account doesnt exist :account ?',array(':account'=>Auth::instance()->get_user()->id));
}
/** /**
* Show a product * Show a product