Theme work with focusbusiness and baseadmin
Improvements to NAVBAR, updates to StaticList methods, other minor items Enable product category rendering and other minor improvements Added ADSL-large category price plan
This commit is contained in:
@@ -31,82 +31,21 @@ class Auth_OSB extends Auth_ORM {
|
||||
if (Config::sitemode() == Kohana::DEVELOPMENT)
|
||||
SystemMessage::add(array('title'=>'Debug','type'=>'debug','body'=>Debug::vars(array('user'=>$uo->username,'r'=>$role))));
|
||||
|
||||
if (! empty($role)) {
|
||||
// Get the module details
|
||||
$mo = ORM::factory('Module',array('name'=>Request::current()->controller()));
|
||||
if (! $mo->loaded() OR ! $mo->status) {
|
||||
SystemMessage::add(array(
|
||||
'title'=>'Module is not defined or active in the Database',
|
||||
'type'=>'warning',
|
||||
'body'=>sprintf('Module not defined: %s',Request::current()->controller()),
|
||||
));
|
||||
if (! empty($role) AND Request::current()->mmo()) {
|
||||
// If the role has the authorisation to run the method
|
||||
$gmo = ORM::factory('Group_Method')
|
||||
->where('method_id','=',Request::current()->mmo()->id);
|
||||
|
||||
} else {
|
||||
if (Request::current()->directory())
|
||||
$method_name = sprintf('%s_%s',Request::current()->directory(),Request::current()->action());
|
||||
else
|
||||
$method_name = Request::current()->action();
|
||||
|
||||
// Get the method number
|
||||
$mmo = ORM::factory('Module_Method',array('module_id'=>$mo->id,'name'=>$method_name));
|
||||
if (! $mmo->loaded()) {
|
||||
SystemMessage::add(array(
|
||||
'title'=>'Method is not defined or active in the Database',
|
||||
'type'=>'warning',
|
||||
'body'=>sprintf('Method not defined: %s for %s',Request::current()->action(),$mo->name),
|
||||
));
|
||||
|
||||
} else {
|
||||
// If the role has the authorisation to run the method
|
||||
$gmo = ORM::factory('Group_Method')
|
||||
->where('method_id','=',$mmo->id);
|
||||
|
||||
$roles = '';
|
||||
foreach ($gmo->find_all() as $gm) {
|
||||
$roles .= ($roles ? '|' : '').$gm->group->name;
|
||||
|
||||
// $gm->group->id == 0 means all users.
|
||||
if ($gm->group->id == 0 OR $uo->has_any('group',$gm->group->list_childgrps(TRUE))) {
|
||||
$status = TRUE;
|
||||
$roles = '';
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (! $status) {
|
||||
if (Config::sitemode() == Kohana::DEVELOPMENT)
|
||||
SystemMessage::add(array(
|
||||
'title'=>'User is not authorised in Database',
|
||||
'type'=>'debug',
|
||||
'body'=>sprintf('Role(s) checked: %s<br/>User: %s</br>Module: %s<br/>Method: %s',$roles,$uo->username,$mo->name,$mmo->name),
|
||||
));
|
||||
}
|
||||
foreach ($gmo->find_all() as $gm)
|
||||
// $gm->group->id == 0 means all users.
|
||||
if ($gm->group->id == 0 OR $uo->has_any('group',$gm->group->list_childgrps(TRUE))) {
|
||||
$status = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (Config::sitemode() == Kohana::DEVELOPMENT)
|
||||
SystemMessage::add(array(
|
||||
'title'=>'Debug',
|
||||
'type'=>'debug',
|
||||
'body'=>sprintf('User: <b>%s</b>, Module: <b>%s</b>, Method: <b>%s</b>, Role: <b>%s</b>, Status: <b>%s</b>, Data: <b>%s</b>',
|
||||
$uo->username,Request::current()->controller(),Request::current()->action(),$role,$status,$debug)));
|
||||
|
||||
// There is no role, so the method should be allowed to run as anonymous
|
||||
} else {
|
||||
if (Config::sitemode() == Kohana::DEVELOPMENT)
|
||||
SystemMessage::add(array(
|
||||
'title'=>'Debug',
|
||||
'type'=>'debug',
|
||||
'body'=>sprintf('User: <b>%s</b>, Module: <b>%s</b>, Method: <b>%s</b>, Status: <b>%s</b>, Data: <b>%s</b>',
|
||||
$uo->username,Request::current()->controller(),Request::current()->action(),'No Role Default Access',$debug)));
|
||||
|
||||
} else
|
||||
$status = TRUE;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (Config::sitemode() == Kohana::DEVELOPMENT)
|
||||
SystemMessage::add(array('title'=>'Debug','type'=>'debug','body'=>'No user logged in'));
|
||||
}
|
||||
|
||||
return $status;
|
||||
|
@@ -63,7 +63,7 @@ class Company {
|
||||
}
|
||||
|
||||
public function language() {
|
||||
return $this->so->language->iso;
|
||||
return $this->so->language;
|
||||
}
|
||||
|
||||
public function logo() {
|
||||
|
@@ -88,6 +88,10 @@ class Config extends Kohana_Config {
|
||||
return ($ao = Auth::instance()->get_user() AND is_object($ao)) ? HTML::anchor(URL::link('user','account/edit'),$ao->name()) : HTML::anchor('login',_('Login'));
|
||||
}
|
||||
|
||||
public static function logout_uri() {
|
||||
return ($ao = Auth::instance()->get_user() AND is_object($ao)) ? HTML::anchor('logout','Logout',array('class'=>'lnk_logout')) : '';
|
||||
}
|
||||
|
||||
public static function logo() {
|
||||
return HTML::image(static::logo_uri(),array('class'=>'headlogo','alt'=>_('Logo')));
|
||||
}
|
||||
@@ -110,11 +114,15 @@ class Config extends Kohana_Config {
|
||||
if (! count($result)) {
|
||||
// We need to know our site here, so that we can subsequently load our enabled modules.
|
||||
if (PHP_SAPI === 'cli') {
|
||||
if (! $site = Minion_CLI::options('site'))
|
||||
if (! ($site = Minion_CLI::options('site'))) {
|
||||
// @todo Need to figure out how to make this CLI error nicer.
|
||||
throw new Minion_Exception_InvalidTask(_('Cant figure out the site, use --site= for CLI'));
|
||||
else
|
||||
#throw new Minion_Exception_InvalidTask(_('Cant figure out the site, use --site= for CLI'));
|
||||
echo _('Cant figure out the site, use --site= for CLI')."\n";
|
||||
die();
|
||||
|
||||
} else
|
||||
$_SERVER['SERVER_NAME'] = $site;
|
||||
|
||||
}
|
||||
|
||||
foreach (ORM::factory('Module')->list_external() as $mo)
|
||||
|
@@ -11,23 +11,25 @@
|
||||
*/
|
||||
class Controller_Account extends Controller_TemplateDefault {
|
||||
public function action_group() {
|
||||
// List all available groups for this user.
|
||||
$output = '';
|
||||
|
||||
$cg = $this->ao->group->find_all();
|
||||
|
||||
foreach ($cg as $go) {
|
||||
foreach ($this->ao->groups() 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);
|
||||
Block::factory()
|
||||
->title('Group Structure')
|
||||
->body($output);
|
||||
|
||||
$output .= sprintf('END Group %s<br/><br/>',$go->id);
|
||||
}
|
||||
// List all available methods for this user.
|
||||
$output = '';
|
||||
|
||||
Block::add(array(
|
||||
'title'=>'Group Structure',
|
||||
'body'=>$output,
|
||||
));
|
||||
foreach ($this->ao->methods() as $mmo)
|
||||
$output .= sprintf('Module: %s, Method %s: %s<br/>',$mmo->module->name,$mmo->name,$mmo->url());
|
||||
|
||||
Block::factory()
|
||||
->title('Available Methods')
|
||||
->body($output);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -87,6 +87,8 @@ class Controller_Login extends lnApp_Controller_Login {
|
||||
'style'=>array('css/login.css'=>'screen'),
|
||||
));
|
||||
}
|
||||
|
||||
$this->template->shownavbar = FALSE;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -16,36 +16,11 @@ class Controller_TemplateDefault extends lnApp_Controller_TemplateDefault {
|
||||
protected $ao;
|
||||
|
||||
public function __construct(Request $request, Response $response) {
|
||||
if (Config::theme())
|
||||
$this->template = Config::theme().'/page';
|
||||
$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::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() {
|
||||
return ($this->template->right) ? $this->template->right : '';
|
||||
}
|
||||
|
||||
public function before() {
|
||||
// If our action doesnt exist, no point processing any further.
|
||||
if (! method_exists($this,'action_'.Request::current()->action()))
|
||||
|
@@ -1,131 +0,0 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class extends renders OSB menu tree.
|
||||
*
|
||||
* @package OSB
|
||||
* @category Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 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::link($mode,$mmo->module->name.'/'.$action,TRUE);
|
||||
|
||||
} else {
|
||||
$url = URL::site($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);
|
||||
}
|
||||
}
|
||||
?>
|
@@ -25,34 +25,34 @@ class Controller_User_Account extends Controller_Account {
|
||||
// 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.')
|
||||
));
|
||||
SystemMessage::factory()
|
||||
->title('Record updated')
|
||||
->type('success')
|
||||
->body(_('Your account record has been updated.'));
|
||||
|
||||
$this->ao->save();
|
||||
|
||||
} else {
|
||||
$output = '';
|
||||
|
||||
// @todo Need to check that this still works with the new bootstrap theming
|
||||
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,
|
||||
));
|
||||
SystemMessage::factory()
|
||||
->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),
|
||||
));
|
||||
Block::factory()
|
||||
->title(sprintf('Account: %s',$this->ao->accnum()))
|
||||
->title_icon('icon-wrench')
|
||||
->type('form-horizontal')
|
||||
->body(View::factory('account/user/edit')->set('o',$this->ao));
|
||||
}
|
||||
|
||||
public function action_resetpassword() {
|
||||
@@ -66,11 +66,10 @@ class Controller_User_Account extends Controller_Account {
|
||||
// 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.')
|
||||
));
|
||||
SystemMessage::factory()
|
||||
->title('Record updated')
|
||||
->type('success')
|
||||
->body(_('Your account record has been updated.'));
|
||||
|
||||
$this->ao->save();
|
||||
|
||||
@@ -80,25 +79,27 @@ class Controller_User_Account extends Controller_Account {
|
||||
HTTP::redirect('login');
|
||||
|
||||
} else {
|
||||
// @todo Need to check that this still works with the new bootstrap theming
|
||||
$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,
|
||||
));
|
||||
SystemMessage::factory()
|
||||
->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),
|
||||
));
|
||||
// @todo To add JS password validation (minimum length and both values equal)
|
||||
Block::factory()
|
||||
->title(sprintf('Password Reset: %s',$this->ao->accnum()))
|
||||
->title_icon('icon-cog')
|
||||
->type('form-horizontal')
|
||||
->body(View::factory('account/user/resetpassword')->set('o',$this->ao));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -16,8 +16,14 @@ class Controller_Welcome extends Controller_TemplateDefault {
|
||||
if (! Kohana::$config->load('config')->appname)
|
||||
HTTP::redirect('guide/app');
|
||||
|
||||
// @todo This should be in the DB or something.
|
||||
HTTP::redirect('product/categorys');
|
||||
$output = '';
|
||||
|
||||
$output = View::factory('pages/welcome');
|
||||
Style::factory()
|
||||
->type('file')
|
||||
->data('media/css/pages/welcome.css');
|
||||
|
||||
$this->template->content = $output;
|
||||
}
|
||||
|
||||
public function action_breadcrumb() {
|
||||
|
@@ -10,6 +10,47 @@
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
abstract class Kohana extends Kohana_Core {
|
||||
/**
|
||||
* Work out our Class Name as per Kohana's standards
|
||||
*/
|
||||
public static function classname($name) {
|
||||
return str_replace(' ','_',ucwords(strtolower(str_replace('_',' ',$name))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Find files using a multi-site enabled application
|
||||
*
|
||||
* In order of precedence, we'll return:
|
||||
* 1) site-theme file, ie: site/X/THEME/${file}
|
||||
* 2) site file, ie: site/X/${file}
|
||||
* 3) theme file, ie: THEME/${file}
|
||||
* 4) normal search, ie: ${file}
|
||||
*/
|
||||
public static function find_file($dir,$file,$ext=NULL,$array=FALSE) {
|
||||
// Limit our scope to the following dirs
|
||||
// @note, we cannot have classes checked, since Config() doesnt exist yet
|
||||
$dirs = array('views','media');
|
||||
|
||||
if (! in_array($dir,$dirs) OR PHP_SAPI === 'cli')
|
||||
return parent::find_file($dir,$file,$ext,$array);
|
||||
|
||||
// Our search order.
|
||||
$prefixes = array(
|
||||
sprintf('site/%s/%s/',Config::siteid(),Config::theme()),
|
||||
sprintf('site/%s/',Config::siteid()),
|
||||
Config::theme().'/',
|
||||
'',
|
||||
);
|
||||
|
||||
foreach ($prefixes as $p) {
|
||||
if ($x = parent::find_file($dir,$p.$file,$ext,$array))
|
||||
return $x;
|
||||
}
|
||||
|
||||
// We found a site path.
|
||||
return $x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @compat Restore KH 3.1 functionality
|
||||
* @var boolean True if Kohana is running from the command line
|
||||
@@ -45,12 +86,5 @@ abstract class Kohana extends Kohana_Core {
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Work out our Class Name as per Kohana's standards
|
||||
*/
|
||||
public static function classname($name) {
|
||||
return str_replace(' ','_',ucwords(strtolower(str_replace('_',' ',$name))));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
29
application/classes/Menu.php
Normal file
29
application/classes/Menu.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class is used to create our Menu/Navbars
|
||||
*
|
||||
* @package OSB
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Menu {
|
||||
public static function items($type) {
|
||||
$result = array();
|
||||
|
||||
if (empty(URL::$method_directory[$type]))
|
||||
return NULL;
|
||||
|
||||
$uo = Auth::instance()->get_user();
|
||||
|
||||
foreach ($uo->methods() as $mmo)
|
||||
if ($mmo->menu_display AND preg_match('/^'.$type.'_/',$mmo->name))
|
||||
if (empty($result[$mmo->id]))
|
||||
$result[$mmo->id] = $mmo;
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
@@ -35,7 +35,7 @@ class Model_Account extends Model_Auth_UserDefault {
|
||||
array('Config::date',array(':value')),
|
||||
),
|
||||
'status'=>array(
|
||||
array('StaticList_YesNo::display',array(':value')),
|
||||
array('StaticList_YesNo::get',array(':value')),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -50,7 +50,14 @@ class Model_Account extends Model_Auth_UserDefault {
|
||||
* Get the groups that an account belongs to
|
||||
*/
|
||||
public function groups() {
|
||||
return $this->group->where_active()->find_all();
|
||||
$result = array();
|
||||
|
||||
foreach ($this->group->where_active()->find_all() as $go)
|
||||
foreach ($go->list_parentgrps(TRUE) as $cgo)
|
||||
if (empty($result[$cgo->id]))
|
||||
$result[$cgo->id] = $cgo;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,6 +107,27 @@ class Model_Account extends Model_Auth_UserDefault {
|
||||
return $alo->saved();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will extract the available methods for this account
|
||||
* This is used both for menu options and method security
|
||||
*/
|
||||
public function methods() {
|
||||
static $result = array();
|
||||
|
||||
// @todo We may want to optimise this with some session caching.
|
||||
if ($result)
|
||||
return $result;
|
||||
|
||||
foreach ($this->groups() as $go)
|
||||
foreach ($go->module_method->find_all() as $mmo)
|
||||
if (empty($result[$mmo->id]))
|
||||
$result[$mmo->id] = $mmo;
|
||||
|
||||
Sort::MAsort($result,'module->name,name');
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an account name
|
||||
*/
|
||||
|
@@ -10,6 +10,8 @@
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Country extends ORM_OSB {
|
||||
protected $_form = array('id'=>'id','value'=>'name');
|
||||
|
||||
public function currency() {
|
||||
return ORM::factory('Currency')->where('country_id','=',$this->id)->find();
|
||||
}
|
||||
|
@@ -10,5 +10,6 @@
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Currency extends ORM_OSB {
|
||||
protected $_form = array('id'=>'id','value'=>'name');
|
||||
}
|
||||
?>
|
||||
|
@@ -33,7 +33,7 @@ class Model_Group extends Model_Auth_RoleDefault {
|
||||
|
||||
protected $_display_filters = array(
|
||||
'status'=>array(
|
||||
array('StaticList_YesNo::display',array(':value')),
|
||||
array('StaticList_YesNo::get',array(':value')),
|
||||
),
|
||||
);
|
||||
|
||||
|
@@ -31,7 +31,7 @@ class Model_Module extends ORM_OSB {
|
||||
array('strtoupper',array(':value')),
|
||||
),
|
||||
'status'=>array(
|
||||
array('StaticList_YesNo::display',array(':value')),
|
||||
array('StaticList_YesNo::get',array(':value')),
|
||||
),
|
||||
);
|
||||
|
||||
|
@@ -10,6 +10,10 @@
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Module_Method extends ORM_OSB {
|
||||
// This module doesnt keep track of column updates automatically
|
||||
protected $_created_column = FALSE;
|
||||
protected $_updated_column = FALSE;
|
||||
|
||||
// Relationships
|
||||
protected $_belongs_to = array(
|
||||
'module'=>array(),
|
||||
@@ -25,19 +29,24 @@ class Model_Module_Method extends ORM_OSB {
|
||||
'name'=>'ASC',
|
||||
);
|
||||
|
||||
protected $_display_filters = array(
|
||||
'menu_display'=>array(
|
||||
array('StaticList_YesNo::display',array(':value')),
|
||||
),
|
||||
);
|
||||
/**
|
||||
* Calculate the description for this method on any menu link
|
||||
*/
|
||||
public function menu_display() {
|
||||
// @todo The test for value equal 1 is for legacy, remove when all updated.
|
||||
if ($this->menu_display AND $this->menu_display != 1)
|
||||
return $this->menu_display;
|
||||
else
|
||||
return sprintf('%s: %s',$this->module->name,$this->name);
|
||||
}
|
||||
|
||||
// This module doesnt keep track of column updates automatically
|
||||
protected $_created_column = FALSE;
|
||||
protected $_updated_column = FALSE;
|
||||
public function url() {
|
||||
if (! preg_match('/_/',$this->name))
|
||||
return NULL;
|
||||
|
||||
// Return the method name.
|
||||
public function name() {
|
||||
return sprintf('%s::%s',$this->module->name,$this->name);
|
||||
list($type,$action) = preg_split('/_/',$this->name,2);
|
||||
|
||||
return URL::link($type,$this->module->name.'/'.$action);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -47,7 +47,7 @@ abstract class ORM extends Kohana_ORM {
|
||||
if (isset($this->_object_formated[$column]))
|
||||
return $this->_object_formated[$column];
|
||||
else
|
||||
return HTML::nbsp($value);
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -21,6 +21,9 @@ abstract class ORM_OSB extends ORM {
|
||||
// Our attribute values that need to be stored as serialized
|
||||
protected $_serialize_column = array();
|
||||
|
||||
// Our attributes that should be converted to NULL when empty
|
||||
protected $_nullifempty = array();
|
||||
|
||||
// Our attributes used in forms.
|
||||
protected $_form = array();
|
||||
|
||||
@@ -36,6 +39,52 @@ abstract class ORM_OSB extends ORM {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try and (un)serialize our data, and if it fails, just return it.
|
||||
*/
|
||||
private function _serialize($data,$set=FALSE) {
|
||||
try {
|
||||
return $set ? serialize($data) : unserialize($data);
|
||||
|
||||
// Maybe the data serialized?
|
||||
} catch (Exception $e) {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve and Store DB BLOB data.
|
||||
*/
|
||||
private function _blob($data,$set=FALSE) {
|
||||
try {
|
||||
return $set ? gzcompress($this->_serialize($data,$set)) : $this->_serialize(gzuncompress($data));
|
||||
|
||||
// Maybe the data isnt compressed?
|
||||
} catch (Exception $e) {
|
||||
return $this->_serialize($data,$set);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If a column is marked to be nullified if it is empty, this is where it is done.
|
||||
*/
|
||||
private function _nullifempty(array $array) {
|
||||
foreach ($array as $k=>$v) {
|
||||
if (is_array($v)) {
|
||||
if (is_null($x=$this->_nullifempty($v)))
|
||||
unset($array[$k]);
|
||||
else
|
||||
$array[$k] = $x;
|
||||
|
||||
} else
|
||||
if (! $v)
|
||||
unset($array[$k]);
|
||||
|
||||
}
|
||||
|
||||
return count($array) ? $array : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto process some data as it comes from the database
|
||||
* @see parent::__get()
|
||||
@@ -52,9 +101,10 @@ abstract class ORM_OSB extends ORM {
|
||||
|
||||
// In case our blob hasnt been saved as one.
|
||||
try {
|
||||
$this->_object[$column] = $this->blob($this->_object[$column]);
|
||||
$this->_object[$column] = $this->_blob($this->_object[$column]);
|
||||
}
|
||||
catch(Exception $e) {
|
||||
echo Debug::vars($e);die();
|
||||
// @todo Log this exception
|
||||
echo Kohana_Exception::text($e), "\n";
|
||||
echo debug_print_backtrace();
|
||||
@@ -116,23 +166,6 @@ abstract class ORM_OSB extends ORM {
|
||||
}
|
||||
}
|
||||
|
||||
final public static function xform($table,$blank=FALSE) {
|
||||
return ORM::factory($table)->formselect($blank);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve and Store DB BLOB data.
|
||||
*/
|
||||
private function blob($data,$set=FALSE) {
|
||||
try {
|
||||
return $set ? gzcompress(serialize($data)) : unserialize(gzuncompress($data));
|
||||
|
||||
// Maybe the data isnt compressed?
|
||||
} catch (Exception $e) {
|
||||
return $set ? serialize($data) : unserialize($data);
|
||||
}
|
||||
}
|
||||
|
||||
public function config($key) {
|
||||
$mc = Config::instance()->module_config($this->_object_name);
|
||||
|
||||
@@ -176,18 +209,6 @@ abstract class ORM_OSB extends ORM {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public function xformselect($blank) {
|
||||
$result = array();
|
||||
|
||||
if ($blank)
|
||||
$result[] = '';
|
||||
|
||||
foreach ($this->find_all() as $o)
|
||||
$result[$o->{$this->_form['id']}] = $o->{$this->_form['value']};
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function keyget($column,$key=NULL) {
|
||||
if (is_null($key) OR ! is_array($this->$column))
|
||||
return $this->$column;
|
||||
@@ -202,10 +223,19 @@ abstract class ORM_OSB extends ORM {
|
||||
public function save(Validation $validation = NULL) {
|
||||
// Find any fields that have changed, and process them.
|
||||
if ($this->_changed)
|
||||
foreach ($this->_changed as $c)
|
||||
foreach ($this->_changed as $c) {
|
||||
// Convert to NULL
|
||||
if (in_array($c,$this->_nullifempty)) {
|
||||
if (is_array($this->_object[$c]))
|
||||
$this->_object[$c] = $this->_nullifempty($this->_object[$c]);
|
||||
|
||||
elseif (! $this->_object[$c])
|
||||
$this->_object[$c] = NULL;
|
||||
}
|
||||
|
||||
// Any fields that are blobs, and encode them.
|
||||
if ($this->_table_columns[$c]['data_type'] == 'blob') {
|
||||
$this->_object[$c] = $this->blob($this->_object[$c],TRUE);
|
||||
if (! is_null($this->_object[$c]) AND $this->_table_columns[$c]['data_type'] == 'blob') {
|
||||
$this->_object[$c] = $this->_blob($this->_object[$c],TRUE);
|
||||
|
||||
// We need to reset our auto_convert flag
|
||||
if (isset($this->_table_columns[$c]['auto_convert']))
|
||||
@@ -215,14 +245,51 @@ abstract class ORM_OSB extends ORM {
|
||||
} elseif (is_array($this->_object[$c]) AND in_array($c,$this->_serialize_column)) {
|
||||
$this->_object[$c] = serialize($this->_object[$c]);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::save($validation);
|
||||
}
|
||||
|
||||
public function status($render=FALSE) {
|
||||
if (! isset($this->_table_columns['status']))
|
||||
return NULL;
|
||||
|
||||
if (! $render)
|
||||
return $this->display('status');
|
||||
|
||||
return View::factory(Config::theme().'/status')
|
||||
->set('label',$this->status ? 'label-success' : '')
|
||||
->set('status',$this->display('status'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Function help to find records that are active
|
||||
*/
|
||||
public function list_active() {
|
||||
return $this->_where_active()->find_all();
|
||||
}
|
||||
|
||||
public function list_count($active=TRUE) {
|
||||
$x=($active ? $this->_where_active() : $this);
|
||||
|
||||
return $x->find_all()->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of data that can be used in a SELECT statement.
|
||||
* The ID and VALUE is defined in the model for the select.
|
||||
*/
|
||||
public function list_select($blank=FALSE) {
|
||||
$result = array();
|
||||
|
||||
if ($blank)
|
||||
$result[] = '';
|
||||
|
||||
if ($this->_form AND array_intersect(array('id','value'),$this->_form))
|
||||
foreach ($this->find_all() as $o)
|
||||
$result[$o->{$this->_form['id']}] = $o->{$this->_form['value']};
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -27,5 +27,31 @@ class Request extends Kohana_Request {
|
||||
|
||||
return parent::directory($directory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get our Module_Method object for this request
|
||||
*/
|
||||
public function mmo() {
|
||||
static $result = FALSE;
|
||||
|
||||
if (is_null($result) OR $result)
|
||||
return $result;
|
||||
|
||||
$result = NULL;
|
||||
|
||||
$mo = ORM::factory('Module',array('name'=>$this->_controller));
|
||||
|
||||
if ($mo->loaded() AND $mo->status) {
|
||||
$method = strtolower($this->_directory ? sprintf('%s_%s',$this->_directory,$this->_action) : $this->_action);
|
||||
|
||||
// Get the method number
|
||||
$mmo = ORM::factory('Module_Method',array('module_id'=>$mo->id,'name'=>$method));
|
||||
|
||||
if ($mmo->loaded())
|
||||
$result = $mmo;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -10,33 +10,16 @@
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
abstract class StaticList {
|
||||
// This is our list of items that will be rendered
|
||||
protected $list = array();
|
||||
// Our Static Items List
|
||||
abstract protected function _table();
|
||||
|
||||
/**
|
||||
* Each static list type must provide the table function that contains
|
||||
* the table of list and values.
|
||||
*/
|
||||
abstract protected function table();
|
||||
|
||||
public static function factory() {
|
||||
throw new Kohana_Exception(':class is calling :method, when it should have its own method',
|
||||
array(':class'=>get_called_class(),':method'=>__METHOD__));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a static name for a value
|
||||
*
|
||||
* @param key $id value to render
|
||||
* @see _display()
|
||||
*/
|
||||
public static function display($value) {
|
||||
return static::_display($value);
|
||||
}
|
||||
// To get an individual item from the table
|
||||
// @note This must be declared in the child class due to static scope
|
||||
//abstract public static function get($value);
|
||||
|
||||
// Due to static scope, sometimes we need to call this function from the child class.
|
||||
protected static function _display($id) {
|
||||
$table = static::factory()->table();
|
||||
protected function _get($id) {
|
||||
$table = $this->_table();
|
||||
|
||||
if (! $table)
|
||||
return 'No Table';
|
||||
@@ -47,10 +30,13 @@ abstract class StaticList {
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists our available keys
|
||||
* Setup our class instantiation
|
||||
* @note This must be declared in the child class due to static scope
|
||||
*/
|
||||
public static function keys() {
|
||||
return array_keys(static::factory()->table());
|
||||
public static function factory() {
|
||||
$x = get_called_class();
|
||||
|
||||
return new $x;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,13 +45,24 @@ abstract class StaticList {
|
||||
* @param string Form name to render
|
||||
* @param string Default value to populate in the Form input.
|
||||
*/
|
||||
public static function form($name,$default='',$addblank=FALSE) {
|
||||
$table = static::factory()->table();
|
||||
public static function form($name,$default='',$addblank=FALSE,array $attributes=NULL) {
|
||||
$table = static::factory()->_table();
|
||||
|
||||
if ($addblank)
|
||||
$table = array_merge(array(''=>' '),$table);
|
||||
|
||||
return Form::Select($name,$table,$default);
|
||||
return Form::Select($name,$table,$default,$attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists our available keys
|
||||
*/
|
||||
public static function keys() {
|
||||
return array_keys(static::factory()->_table());
|
||||
}
|
||||
|
||||
public static function table() {
|
||||
return static::factory()->_table();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -12,6 +12,9 @@
|
||||
class StaticList_Module extends StaticList {
|
||||
protected static $record = array();
|
||||
|
||||
protected function _table() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a static name for a value
|
||||
*/
|
||||
@@ -81,13 +84,8 @@ class StaticList_Module extends StaticList {
|
||||
return Form::select($name,$x,$default,$attributes);
|
||||
}
|
||||
|
||||
protected function table($module=NULL) {
|
||||
if (is_null($module))
|
||||
throw new Kohana_Exception('Module is a required attribute.');
|
||||
}
|
||||
|
||||
public static function factory() {
|
||||
return new StaticList_Module;
|
||||
public static function get($value) {
|
||||
return static::factory()->_get($value);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -10,7 +10,7 @@
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class StaticList_PriceType extends StaticList {
|
||||
protected function table() {
|
||||
protected function _table() {
|
||||
return array(
|
||||
0=>_('One-time Charge'),
|
||||
1=>_('Recurring Membership/Subscription'),
|
||||
@@ -18,12 +18,8 @@ class StaticList_PriceType extends StaticList {
|
||||
);
|
||||
}
|
||||
|
||||
public static function factory() {
|
||||
return new StaticList_PriceType;
|
||||
}
|
||||
|
||||
public static function display($value) {
|
||||
return static::_display($value);
|
||||
public static function get($value) {
|
||||
return static::factory()->_get($value);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -10,7 +10,7 @@
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class StaticList_RecurSchedule extends StaticList {
|
||||
protected function table() {
|
||||
protected function _table() {
|
||||
return array(
|
||||
0=>_('Weekly'),
|
||||
1=>_('Monthly'),
|
||||
@@ -22,34 +22,8 @@ class StaticList_RecurSchedule extends StaticList {
|
||||
);
|
||||
}
|
||||
|
||||
public static function factory() {
|
||||
return new StaticList_RecurSchedule;
|
||||
}
|
||||
|
||||
public static function display($value) {
|
||||
return static::_display($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the price display for a product
|
||||
*
|
||||
* @uses product
|
||||
*/
|
||||
public static function form($name,$product='',$default='',$addblank=FALSE) {
|
||||
if (empty($product))
|
||||
throw new Kohana_Exception('Product is a required field for :method',array(':method'=>__METHOD__));
|
||||
|
||||
$x = '';
|
||||
$table = static::factory()->table();
|
||||
|
||||
foreach ($product->get_price_array() as $term => $price) {
|
||||
$x[$term] = sprintf('%s %s',Currency::display(Tax::add($price['price_base'])),$table[$term]);
|
||||
|
||||
if ($price['price_setup'] > 0)
|
||||
$x[$term] .= sprintf(' + %s %s',Currency::display(Tax::add($price['price_setup'])),_('Setup'));
|
||||
}
|
||||
|
||||
return Form::select($name,$x,$default);
|
||||
public static function get($value) {
|
||||
return static::factory()->_get($value);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -10,19 +10,15 @@
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class StaticList_RecurType extends StaticList {
|
||||
protected function table() {
|
||||
protected function _table() {
|
||||
return array(
|
||||
0=>_('Bill on Aniversary Date of Subscription'),
|
||||
1=>_('Bill on Fixed Schedule'),
|
||||
);
|
||||
}
|
||||
|
||||
public static function factory() {
|
||||
return new StaticList_RecurType;
|
||||
}
|
||||
|
||||
public static function display($value) {
|
||||
return static::_display($value);
|
||||
public static function get($value) {
|
||||
return static::factory()->_get($value);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -10,7 +10,7 @@
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class StaticList_SweepType extends StaticList {
|
||||
protected function table() {
|
||||
protected function _table() {
|
||||
return array(
|
||||
0=>_('Daily'),
|
||||
1=>_('Weekly'),
|
||||
@@ -22,12 +22,8 @@ class StaticList_SweepType extends StaticList {
|
||||
);
|
||||
}
|
||||
|
||||
public static function factory() {
|
||||
return new StaticList_SweepType;
|
||||
}
|
||||
|
||||
public static function display($value) {
|
||||
return static::_display($value);
|
||||
public static function get($value) {
|
||||
return static::factory()->_get($value);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -10,7 +10,7 @@
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class StaticList_Title extends StaticList {
|
||||
protected function table() {
|
||||
protected function _table() {
|
||||
return array(
|
||||
'mr'=>_('Mr'),
|
||||
'ms'=>_('Ms'),
|
||||
@@ -21,8 +21,8 @@ class StaticList_Title extends StaticList {
|
||||
);
|
||||
}
|
||||
|
||||
public static function factory() {
|
||||
return new StaticList_Title;
|
||||
public static function get($value) {
|
||||
return static::factory()->_get($value);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -10,19 +10,15 @@
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class StaticList_YesNo extends StaticList {
|
||||
protected function table() {
|
||||
protected function _table() {
|
||||
return array(
|
||||
0=>_('No'),
|
||||
1=>_('Yes'),
|
||||
);
|
||||
}
|
||||
|
||||
public static function factory() {
|
||||
return new StaticList_YesNo;
|
||||
}
|
||||
|
||||
public static function display($value) {
|
||||
return static::_display($value);
|
||||
public static function get($value) {
|
||||
return static::factory()->_get($value);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -13,7 +13,6 @@ class URL extends Kohana_URL {
|
||||
// Our method paths for different functions
|
||||
public static $method_directory = array(
|
||||
'admin'=>'a',
|
||||
'affiliate'=>'affiliate', // @todo To retire
|
||||
'reseller'=>'r',
|
||||
'task'=>'task',
|
||||
'user'=>'u',
|
||||
|
Reference in New Issue
Block a user