Fixes to OSB to work with KH 3.3

This commit is contained in:
Deon George
2012-11-10 10:13:57 +11:00
parent ea36639638
commit 6db02ae77d
238 changed files with 813 additions and 938 deletions

View File

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

View File

@@ -0,0 +1,78 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides Admin Account management
*
* @package lnApp
* @subpackage Page/Account
* @category Controllers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Controller_Admin_Account extends Controller_TemplateDefault_Admin {
protected $secure_actions = array(
'ajaxlist'=>FALSE, // @todo To Change
'list'=>TRUE,
'listlog'=>TRUE,
);
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'=>'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'=>'user/account/view',
)),
));
}
}
?>

View File

@@ -0,0 +1,131 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides MODULE management
*
* @package lnApp
* @subpackage Page/Module
* @category Controllers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Controller_Admin_Module extends Controller_TemplateDefault_Admin {
protected $secure_actions = array(
'add'=>TRUE,
'edit'=>TRUE,
'list'=>TRUE,
);
/**
* 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->load('config')->method_directory;
array_unshift($classes,'');
foreach ($classes as $c) {
$cn = sprintf($ch,$c ? ucfirst($c).'_'.ucfirst($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;
}
/**
* List our installed modules
*/
public function action_list() {
$mo = ORM::factory('Module');
Block::add(array(
'title'=>_('Defined Modules'),
'body'=>Table::display(
$mo->find_all(),
25,
array(
'id'=>array('label'=>'ID','url'=>'admin/module/edit/'),
'name'=>array('label'=>'Name'),
'status'=>array('label'=>'Active'),
),
array(
'page'=>TRUE,
'type'=>'list',
)),
));
}
/**
* Edit a Module Configuration
*
* @todo Highlight those methods that have security, but the class does not have auth_required set to YES or the method isnt defined in secure_actions
*/
public function action_edit() {
$mid = $this->request->param('id');
$mo = ORM::factory('Module',$mid);
if (! $mo->loaded()) {
SystemMessage::add(array(
'title'=>_('Invalid Module ID'),
'type'=>'error',
'body'=>sprintf(_('Module with ID %s doesnt appear to exist?'),$mid),
));
return;
}
$output = '';
$methods = $this->_methods($mo->name);
// Show methods defined in the DB already.
Block::add(array(
'title'=>sprintf('%s: %s ',_('Defined Module Methods For'),$mo->display('name')),
'body'=>Table::display(
$mo->module_method->find_all(),
25,
array(
'id'=>array('label'=>'ID','url'=>'admin/module_method/edit/'),
'name'=>array('label'=>'Name'),
'notes'=>array('label'=>'Notes'),
'menu_display'=>array('label'=>'Menu'),
),
array(
'page'=>TRUE,
'type'=>'list',
)),
));
// Show new methods NOT defined in the DB already.
foreach ($mo->module_method->find_all() as $meo)
if (($method = array_search($meo->name,$methods)) !== false)
unset($methods[$method]);
if (count($methods))
Block::add(array(
'title'=>sprintf('%s: %s ',_('Undefined Module Methods For'),$mo->display('name')),
'body'=>Table::display(
$methods,
25,
array(
'__VALUE__'=>array('label'=>'Name','url'=>sprintf('admin/module_method/add/%s/',$mo->id)),
),
array(
'page'=>TRUE,
'type'=>'list',
)),
));
}
}
?>

View File

@@ -0,0 +1,138 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides MODULE management
*
* @package lnApp
* @subpackage Page/Module
* @category Controllers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Controller_Admin_Module_Method extends Controller_Admin_Module {
/**
* Add a method to the database
*/
public function action_add() {
$id = $this->request->param('id');
$method = $this->request->param('sid');
$mo = ORM::factory('Module',$id);
$mmo = ORM::factory('Module_Method');
if (! $mo->loaded() OR ! in_array($method,$this->_methods($mo->name)))
throw new Kohana_Exception('Method (:method) does not exist in :class',array(':method'=>$method,':class'=>$mo->name));
$mmo->name = $method;
$mmo->module_id = $mo->id;
$mmo->values($_POST);
$output = '';
if ($_POST AND $mmo->values($_POST)->check()) {
$mmo->save();
if ($mmo->saved()) {
SystemMessage::add(array(
'title'=>_('Method Added'),
'type'=>'info',
'body'=>sprintf(_('Method %s defined to database'),$mmo->name),
));
HTTP::redirect(sprintf('admin/module/edit/%s',$mo->id));
} else {
SystemMessage::add(array(
'title'=>_('Method Not Saved'),
'type'=>'error',
'body'=>sprintf(_('Unable to define Method %s to database?'),$mmo->name),
));
}
}
$output .= View::factory('module/admin/method_add')
->set('module',$mo)
->set('method',$mmo);
Block::add(array(
'title'=>sprintf(_('Add Method (%s) to Database for (%s)'),strtoupper($mmo->name),strtoupper($mo->name)),
'body'=>$output,
));
}
/**
* Edit a Module Configuration
*
* @param int $mid Module ID
*/
public function action_edit() {
$mid = $this->request->param('id');
$mmo = ORM::factory('Module_Method',$mid);
if (! $mmo->loaded()) {
SystemMessage::add(array(
'title'=>_('Invalid Method ID'),
'type'=>'error',
'body'=>sprintf(_('Method with ID %s doesnt appear to exist?'),$mid),
));
return;
}
$output = '';
// The groups that can run this method.
$groups = ORM::factory('Group');
if ($_POST) {
foreach ($groups->find_all() as $go) {
// If the group was defined and no longer
if ($mmo->has('group',$go) AND (! isset($_POST['groups']) OR ! in_array($go->id,$_POST['groups']))) {
$gm = ORM::factory('Group_Method',array('method_id'=>$mmo->id,'group_id'=>$go->id));
if (! $gm->delete())
SystemMessage::add(array(
'title'=>_('Unable to DELETE Group Method'),
'type'=>'error',
'body'=>sprintf(_('Unable to delete Group Method for method %s and group %s'),$mmo->name,$go->name),
));
// If the group was not defined and now is
} elseif (! $mmo->has('group',$go) AND isset($_POST['groups']) AND in_array($go->id,$_POST['groups'])) {
$gm = ORM::factory('Group_Method')
->values(array(
'method_id'=>$mmo->id,
'group_id'=>$go->id,
));
if (! $gm->check() OR ! $gm->save())
SystemMessage::add(array(
'title'=>_('Unable to SAVE Group Method'),
'type'=>'error',
'body'=>sprintf(_('Unable to save Group Method for method %s and group %s'),$mmo->name,$go->name),
));
}
}
}
$output .= Form::open();
$output .= View::factory('module/admin/method_detail_head');
foreach ($groups->find_all() as $go) {
$output .= View::factory('module/admin/method_detail_body')
->set('group',$go)
->set('defined',$mmo->has('group',$go));
}
$output .= View::factory('module/admin/method_detail_foot');
$output .= '<div>'.Form::submit('submit',_('Update'),array('class'=>'form_button')).'</div>';
$output .= Form::close();
Block::add(array(
'title'=>sprintf(_('%s->%s Method'),strtoupper($mmo->module->name),strtoupper($mmo->name)),
'body'=>$output,
));
}
}
?>

View File

@@ -0,0 +1,74 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides Siet Configuration Setup
*
* @package lnApp
* @subpackage Page/Setup
* @category Controllers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Controller_Admin_Setup extends Controller_TemplateDefault_Admin {
protected $secure_actions = array(
'edit'=>TRUE,
);
/**
* View/Update the site configuration
*/
public function action_edit() {
$o = Config::instance()->so;
$output = '';
if ($_POST) {
// Entry updated
if ($o->values($_POST)->check() AND $o->save())
SystemMessage::add(array(
'title'=>'Site Configuration Recorded',
'type'=>'info',
'body'=>'Site Config successfully recorded.',
));
}
$output .= Form::open();
// site_details
$output .= View::factory($this->viewpath())
->set('o',$o);;
$output .= '<div>'.Form::submit('submit','submit',array('class'=>'form_button')).'</div>';
$output .= Form::close();
Block::add(array(
'title'=>_('Update Site Configuration'),
'body'=>$output,
));
// module_config
$output = '';
$output .= View::factory($this->viewpath().'/module/head');
foreach ($o->module_config as $mid => $detail) {
$mo = ORM::factory('Module',$mid);
$output .= View::factory($this->viewpath().'/module/body')
->set('mo',$mo);
Script::add(array('type'=>'stdin','data'=>'
$(document).ready(function() {
$("div[id='.$mo->name.']").load("'.URL::site('admin/'.$mo->name.'/setup').'");
});'
));
}
$output .= View::factory($this->viewpath().'/module/foot');
Block::add(array(
'title'=>_('Update Module Specific Configuration'),
'body'=>$output,
));
}
}
?>

View File

@@ -0,0 +1,110 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* OSB Admin Main home page
*
* @package OSB
* @subpackage Page/Home
* @category Controllers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Controller_Admin_Welcome extends Controller_TemplateDefault_Admin {
public $secure_actions = array(
'index'=>TRUE,
);
public function action_index() {
$ao = ORM::factory('Account',Auth::instance()->get_user()->id);
$t = time();
// Show outstanding invoices
$o = ORM::factory('Invoice');
Block_Sub::add(array(
'title'=>'Invoices Overdue - No Auto Billing',
'body'=>Table::display(
$o->list_overdue_billing($t),
25,
array(
'due_date'=>array('label'=>'Due Date'),
'account->accnum()'=>array('label'=>'Num'),
'account->name()'=>array('label'=>'Account'),
'account->display("status")'=>array('label'=>'Active'),
'id'=>array('label'=>'ID','url'=>'user/invoice/view/'),
'total(TRUE)'=>array('label'=>'Total','class'=>'right'),
'due(TRUE)'=>array('label'=>'Amount Due','class'=>'right'),
),
array('page'=>TRUE)),
'position'=>1,
'order'=>1,
));
Block_Sub::add(array(
'title'=>'Invoices Overdue - Auto Billing',
'body'=>Table::display(
$o->list_overdue_billing($t,TRUE),
25,
array(
'due_date'=>array('label'=>'Due Date'),
'account->accnum()'=>array('label'=>'Num'),
'account->name()'=>array('label'=>'Account'),
'account->display("status")'=>array('label'=>'Active'),
'id'=>array('label'=>'ID','url'=>'user/invoice/view/'),
'total(TRUE)'=>array('label'=>'Total','class'=>'right'),
'due(TRUE)'=>array('label'=>'Amount Due','class'=>'right'),
),
array('page'=>TRUE)),
'position'=>2,
'order'=>1,
));
Block_Sub::add(array(
'title'=>'Invoices Due',
'body'=>Table::display(
$o->list_due(),
25,
array(
'due_date'=>array('label'=>'Due Date'),
'account->accnum()'=>array('label'=>'Num'),
'account->name()'=>array('label'),
'account->display("status")'=>array('label'=>'Active'),
'id'=>array('label'=>'ID','url'=>'user/invoice/view/'),
'total(TRUE)'=>array('label'=>'Total','class'=>'right'),
'due(TRUE)'=>array('label'=>'Amount Due','class'=>'right'),
),
array('show_other'=>'due()')),
'position'=>3,
'order'=>1,
));
// Show un-applied payments
Block_Sub::add(array(
'title'=>'Unapplied Payments',
'body'=>Table::display(
ORM::factory('Payment')->list_unapplied(),
25,
array(
'date_payment'=>array('label'=>'Pay Date'),
'account->accnum()'=>array('label'=>'Num'),
'account->name()'=>array('label'=>'Account'),
'account->display("status")'=>array('label'=>'Active'),
'id'=>array('label'=>'ID','url'=>'admin/payment/view/'),
'total_amt'=>array('label'=>'Total','class'=>'right'),
'balance(TRUE)'=>array('label'=>'Balance','class'=>'right'),
),
array('show_other'=>'balance()')),
'position'=>1,
'order'=>2,
));
Block::add(array(
'title'=>sprintf('%s: %s %s',$ao->accnum(),$ao->first_name,$ao->last_name),
'subtitle'=>_('Administrator Overview'),
'body'=>(string)Block_Sub::factory(),
));
}
}
?>

View File

@@ -0,0 +1,43 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides Affiliate Account functions
*
* @package OSB
* @subpackage Account
* @category Controllers/Affiliate
* @author Deon George
* @copyright (c) 2010 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'=>'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'=>'user/account/view',
)),
));
}
}
?>

View File

@@ -0,0 +1,28 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
class Controller_Debug extends Controller_TemplateDefault {
public function before() {
if (! in_array(Config::sitemode(),array(Kohana::DEVELOPMENT,Kohana::TESTING)))
HTTP::redirect();
parent::before();
}
public function action_site() {
$output = '';
$output .= debug::vars(array(
'm'=>__METHOD__,
'site'=>Config::site(),
'siteID'=>Config::siteid(),
'siteMode'=>Config::sitemodeverbose(),
'modules'=>Config::appmodules(),
));
Block::add(array(
'title'=>_('Site debug'),
'body'=>$output,
));
}
}
?>

View File

@@ -0,0 +1,4 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
class Controller_Default extends lnApp_Controller_Default {}
?>

View File

@@ -0,0 +1,138 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides login capability
*
* @package OSB
* @subpackage Page/Login
* @category Controllers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
* @also [logout]
*/
class Controller_Login extends lnApp_Controller_Login {
public function action_register() {
// If user already signed-in
if (Auth::instance()->logged_in()!= 0) {
// Redirect to the user account
HTTP::redirect('welcome/index');
}
// Instantiate a new user
$account = ORM::factory('Account');
// If there is a post and $_POST is not empty
if ($_POST) {
// Check Auth
$status = $account->values($_POST)->check();
if (! $status) {
foreach ($account->validation()->errors('form/register') as $f => $r) {
// $r[0] has our reason for validation failure
switch ($r[0]) {
// Generic validation reason
default:
SystemMessage::add(array(
'title'=>_('Validation failed'),
'type'=>'error',
'body'=>sprintf(_('The defaults on your submission were not valid for field %s (%s).'),$f,$r)
));
}
}
}
$ido = ORM::factory('Module')
->where('name','=','account')
->find();
$account->id = $ido->record_id->next_id($ido->id);
// Save the user details
if ($account->save()) {}
}
SystemMessage::add(array(
'title'=>_('Already have an account?'),
'type'=>'info',
'body'=>_('If you already have an account, please login..')
));
Block::add(array(
'title'=>_('Register'),
'body'=>View::factory('register')
->set('account',$account)
->set('errors',$account->validation()->errors('form/register')),
));
$this->template->left = HTML::anchor('login','Login').'...';
}
/**
* Enable user password reset
*/
public function action_reset() {
// Minutes to keep our token
$token_expire = 15;
// If user already signed-in
if (Auth::instance()->logged_in()!= 0) {
// Redirect to the user account
HTTP::redirect('welcome/index');
}
// If the user posted their details to reset their password
if ($_POST) {
// If the username is correct, create a method token
if (! empty($_POST['username']) AND ($ao=ORM::factory('Account',array('username'=>$_POST['username']))) AND $ao->loaded()) {
$mmto = ORM::factory('Module_Method_Token')
->method(array('account','user_resetpassword'))
->account($ao)
->uses(2)
->expire(time()+$token_expire*60);
if ($mmto->generate()) {
// Send our email with the token
// @todo Need to provide an option if Email_Template is not installed/activited.
// @todo Need to provide an option if account_reset_password template doesnt exist.
$et = Email_Template::instance('account_reset_password');
$et->to = array('account'=>array($mmto->account_id));
$et->variables = array(
'SITE'=>URL::base(TRUE,TRUE),
'SITE_ADMIN'=>Config::sitename(),
'SITE_NAME'=>Config::sitename(),
'TOKEN'=>$mmto->token,
'TOKEN_EXPIRE_MIN'=>$token_expire,
'USER_NAME'=>sprintf('%s %s',$mmto->account->first_name,$mmto->account->last_name),
);
$et->send();
// Log the password reset
$ao->log('Password reset token sent');
}
// Redirect to our password reset, the Auth will validate the token.
} elseif (! empty($_REQUEST['token'])) {
HTTP::redirect(sprintf('user/account/resetpassword?token=%s',$_REQUEST['token']));
}
// Show our token screen even if the email was invalid.
if (isset($_POST['username']))
Block::add(array(
'title'=>_('Reset your password'),
'body'=>View::factory('login_reset_sent'),
'style'=>array('css/login.css'=>'screen'),
));
else
HTTP::redirect('login');
} else {
Block::add(array(
'title'=>_('Reset your password'),
'body'=>View::factory('login_reset'),
'style'=>array('css/login.css'=>'screen'),
));
}
}
}
?>

View File

@@ -0,0 +1,4 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
class Controller_Logout extends lnApp_Controller_Logout {}
?>

View File

@@ -0,0 +1,4 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
class Controller_Media extends lnApp_Controller_Media {}
?>

View File

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

View File

@@ -0,0 +1,4 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
class Controller_Task extends lnApp_Controller_Task {}
?>

View File

@@ -0,0 +1,55 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides the default template controller for rendering pages.
*
* @package OSB
* @subpackage Page/Template
* @category Controllers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Controller_TemplateDefault extends lnApp_Controller_TemplateDefault {
public function __construct(Request $request, Response $response) {
if (Config::theme())
$this->template = Config::theme().'/page';
return parent::__construct($request,$response);
}
protected function _headimages() {
// This is where we should be able to change our country
// @todo To implement
$co = Config::instance()->so->country;
HeadImages::add(array(
'img'=>sprintf('img/country/%s.png',strtolower($co->two_code)),
'attrs'=>array('onclick'=>"target='_blank';",'title'=>$co->display('name'))
));
return HeadImages::factory();
}
protected function _left() {
if ($this->template->left)
return $this->template->left;
elseif (Auth::instance()->logged_in(NULL,get_class($this).'|'.__METHOD__))
return Controller_Tree::js();
}
protected function _right() {
if ($this->template->right)
return $this->template->right;
else
return $this->_cart();
}
private function _cart() {
if (! Config::moduleexist('cart') OR ! class_exists('cart') OR ! Cart::instance()->contents()->reset(FALSE)->count_all())
return '';
return Cart::instance()->cart_block();
}
}
?>

View File

@@ -0,0 +1,47 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* lnApp User Main home page controller
*
* @package lnApp
* @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 {
protected function setup(array $config_items=array()) {
$module = Request::current()->controller();
if ($_POST AND isset($_POST['module_config'][$module]))
Config::instance()->so->module_config($module,$_POST['module_config'][$module])->save();
if ($config_items) {
$output = '';
$mc = Config::instance()->so->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

@@ -0,0 +1,38 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* OSB User Main home page controller
*
* @package OSB
* @subpackage Page/Affiliate
* @category Controllers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.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();
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;
}
}
?>

View File

@@ -0,0 +1,44 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* lnApp User Main home page controller
*
* @package lnApp
* @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 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());
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();
}
}
?>

View File

@@ -0,0 +1,130 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class extends renders OSB menu tree.
*
* @package lnApp
* @subpackage Tree
* @category Controllers
* @author Deon George
* @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_Tree extends lnApp_Controller_Tree {
protected $auth_required = TRUE;
/**
* Draw the Tree Menu
*
* The incoming ID is either a Branch B_x or a Node N_x
* Where X is actually the module.
*
* @param array $data Tree data passed in by inherited methods
*/
public function action_json(array $data=array()) {
// Get the user details
$id = (is_null($this->request->param('id')) AND isset($_REQUEST['id'])) ? substr($_REQUEST['id'],2) : $this->request->param('id');
$user = Auth::instance()->get_user();
if ($user) {
if (! $id) {
$modules = array();
foreach ($user->groups() as $go)
foreach ($go->list_parentgrps(TRUE) as $cgo)
foreach ($cgo->module_method->find_all() as $mmo)
if ($mmo->menu_display AND empty($modules[$mmo->module_id]))
$modules[$mmo->module_id] = $mmo->module;
Sort::MAsort($modules,'name');
foreach ($modules as $id => $mo)
if (! $mo->parent_id)
array_push($data,array('id'=>$id,'name'=>$mo->name,'state'=>'closed'));
} else {
$idx = NULL;
if (preg_match('/_/',$id))
list($id,$idx) = explode('_',$id,2);
$mo = ORM::factory('Module',$id);
$methods = array();
if ($mo->loaded()) {
foreach ($mo->module_method->find_all() as $mmo)
if ($mmo->menu_display)
foreach ($mmo->group->find_all() as $gmo)
if ($user->has_any('group',$gmo->list_childgrps(TRUE)))
$methods[$mmo->id] = $mmo;
Sort::MASort($modules,'name');
$subdata = array();
foreach ($methods as $id => $mmo) {
if (preg_match('/_/',$mmo->name)) {
list($mode,$action) = explode('_',$mmo->name);
$url = URL::site(sprintf('%s/%s/%s',$mode,$mmo->module->name,$action));
} else {
$url = URL::site(sprintf('%s/%s',$mmo->module->name,$mmo->name));
}
// We can split our menus into sub menus using the _ char.
if (preg_match('/_/',$mmo->name)) {
list($sub,$name) = explode('_',$mmo->name,2);
$subdata[$sub][$name]['name'] = preg_replace('/^(.*: )/','',$mmo->notes);
$subdata[$sub][$name]['id'] = sprintf('%s_%s',$mmo->module_id,$id);
$subdata[$sub][$name]['href'] = (empty($details['page']) ? $url : $details['page']);
} else {
// We dont want to show these items again, if we can through on a submenu
if (! $idx)
array_push($data,array(
'id'=>sprintf('%s_%s',$mmo->module_id,$id),
'name'=>$mmo->name,
'state'=>'none',
'attr_id'=>sprintf('%s_%s',$mmo->module->name,$id),
'attr_href'=>(empty($details['page']) ? $url : $details['page'])
));
}
}
// If our sub menus only have 1 branch, then we'll display it as normal.
if (count($subdata) == 1) {
$sk = array_keys($subdata);
$idx = array_shift($sk);
}
if ($idx)
foreach ($subdata[$idx] as $k=>$v) {
array_push($data,array(
'id'=>$v['id'],
'name'=>$v['name'],
'state'=>'none',
'attr_id'=>$v['id'],
'attr_href'=>$v['href']
));
}
else
foreach ($subdata as $t=>$x)
array_push($data,array('id'=>$mmo->module_id.'_'.$t,'name'=>$t,'state'=>'closed'));
}
}
}
$this->output = array();
foreach ($data as $branch) {
array_push($this->output,array(
'attr'=>array('id'=>sprintf('B_%s',$branch['id'])),
'state'=>$branch['state'],
'data'=>array('title'=>$branch['name']),
'attr'=>array('id'=>sprintf('N_%s',$branch['id']),'href'=>empty($branch['attr_href']) ? URL::site(sprintf('%s/menu',$branch['name'])) : $branch['attr_href']),
)
);
}
return parent::action_json($data);
}
}
?>

View File

@@ -0,0 +1,105 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides User Account Update functions
*
* @package OSB
* @subpackage Account
* @category Controllers/User
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Controller_User_Account extends Controller_TemplateDefault_User {
protected $secure_actions = array(
'edit'=>TRUE,
'resetpassword'=>TRUE,
);
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']))
$_POST['password_confirm'] = ' ';
// 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();
// Log the password reset
$this->ao->log('Password reset');
HTTP::redirect('login');
} 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'=>_('Password Reset'),
'body'=>View::factory($this->viewpath())
->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

@@ -0,0 +1,27 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* lnApp Main home page
*
* @package lnApp
* @subpackage Page/Home
* @category Controllers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Controller_User_Welcome extends Controller_TemplateDefault_User {
protected $secure_actions = array(
'index'=>FALSE,
);
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',
));
}
}
?>

View File

@@ -0,0 +1,30 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* OSB Main home page
*
* @package OSB
* @subpackage Page/Home
* @category Controllers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Controller_Welcome extends Controller_TemplateDefault {
protected $auth_required = FALSE;
public function action_index() {
if (! Kohana::$config->load('config')->appname)
HTTP::redirect('guide/app');
// @todo This should be in the DB or something.
HTTP::redirect('product/categorys');
}
public function action_breadcrumb() {
$this->auto_render = FALSE;
$this->response->body(Session::instance()->get_once('breadcrumb'));
}
}
?>