Application cleanup
This commit is contained in:
@@ -10,65 +10,6 @@
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Auth_OSB extends Auth_ORM {
|
||||
/**
|
||||
* OSB authentication is controlled via database queries.
|
||||
*
|
||||
* This method can be used to test two situations:
|
||||
* 1) Is the user logged in? ($role == FALSE)
|
||||
* 2) Can the user run the current controller->action ($role == TRUE)
|
||||
*
|
||||
* @param boolean If authentication should be done for this module:method (ie: controller:action).
|
||||
* @return boolean
|
||||
*/
|
||||
public function logged_in($role=NULL,$debug=NULL) {
|
||||
$status = FALSE;
|
||||
|
||||
// Get the user from the session
|
||||
$uo = $this->get_user();
|
||||
|
||||
// If we are not a valid user object, then we are not logged in
|
||||
if (is_object($uo) AND ($uo instanceof Model_Account) AND $uo->loaded()) {
|
||||
if (Config::sitemode() == Kohana::DEVELOPMENT)
|
||||
SystemMessage::add(array('title'=>'Debug','type'=>'debug','body'=>Debug::vars(array('user'=>$uo->username,'r'=>$role))));
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// There is no role, so the method should be allowed to run as anonymous
|
||||
} else
|
||||
$status = TRUE;
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the currently logged in user from the session.
|
||||
* Returns NULL if no user is currently logged in.
|
||||
*
|
||||
* @param boolean Check token users too
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_user($default=NULL,$tokenuser=TRUE) {
|
||||
// Get the current user
|
||||
$uo = parent::get_user($default);
|
||||
|
||||
// If we are not logged in, see if there is token for the user
|
||||
if (is_null($uo) AND $tokenuser AND ($token=Session::instance()->get('token')) OR (! empty($_REQUEST['token']) AND $token=$_REQUEST['token']))
|
||||
$uo = $this->_get_token_user($token);
|
||||
|
||||
return $uo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user that a token applies to
|
||||
*
|
||||
@@ -103,7 +44,6 @@ class Auth_OSB extends Auth_ORM {
|
||||
'type'=>'warning',
|
||||
'body'=>_('Token expired')));
|
||||
|
||||
// @todo Log the token deletion
|
||||
Session::instance()->delete('token');
|
||||
$mmto->delete();
|
||||
|
||||
@@ -113,7 +53,6 @@ class Auth_OSB extends Auth_ORM {
|
||||
'type'=>'warning',
|
||||
'body'=>_('Token expired')));
|
||||
|
||||
// @todo Log the token deletion
|
||||
Session::instance()->delete('token');
|
||||
$mmto->delete();
|
||||
|
||||
@@ -210,5 +149,64 @@ class Auth_OSB extends Auth_ORM {
|
||||
public function authorised(Model_Account $ao) {
|
||||
return (($uo = $this->get_user()) AND $uo->loaded() AND ($uo == $ao OR in_array($ao->id,$uo->RTM->customers($uo->RTM))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the currently logged in user from the session.
|
||||
* Returns NULL if no user is currently logged in.
|
||||
*
|
||||
* @param boolean Check token users too
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_user($default=NULL,$tokenuser=TRUE) {
|
||||
// Get the current user
|
||||
$uo = parent::get_user($default);
|
||||
|
||||
// If we are not logged in, see if there is token for the user
|
||||
if (is_null($uo) AND $tokenuser AND ($token=Session::instance()->get('token')) OR (! empty($_REQUEST['token']) AND $token=$_REQUEST['token']))
|
||||
$uo = $this->_get_token_user($token);
|
||||
|
||||
return $uo;
|
||||
}
|
||||
|
||||
/**
|
||||
* OSB authentication is controlled via database queries.
|
||||
*
|
||||
* This method can be used to test two situations:
|
||||
* 1) Is the user logged in? ($role == FALSE)
|
||||
* 2) Can the user run the current controller->action ($role == TRUE)
|
||||
*
|
||||
* @param boolean If authentication should be done for this module:method (ie: controller:action).
|
||||
* @return boolean
|
||||
*/
|
||||
public function logged_in($role=NULL,$debug=NULL) {
|
||||
$status = FALSE;
|
||||
|
||||
// Get the user from the session
|
||||
$uo = $this->get_user();
|
||||
|
||||
// If we are not a valid user object, then we are not logged in
|
||||
if (is_object($uo) AND ($uo instanceof Model_Account) AND $uo->loaded()) {
|
||||
if (Config::sitemode() == Kohana::DEVELOPMENT)
|
||||
SystemMessage::add(array('title'=>'Debug','type'=>'debug','body'=>Debug::vars(array('user'=>$uo->username,'r'=>$role))));
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// There is no role, so the method should be allowed to run as anonymous
|
||||
} else
|
||||
$status = TRUE;
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -115,8 +115,6 @@ class Config extends Kohana_Config {
|
||||
// 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'))) {
|
||||
// @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'));
|
||||
echo _('Cant figure out the site, use --site= for CLI')."\n";
|
||||
die();
|
||||
|
||||
|
@@ -10,7 +10,7 @@
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Controller_Account extends Controller_TemplateDefault {
|
||||
public function action_group() {
|
||||
protected function group() {
|
||||
// List all available groups for this user.
|
||||
$output = '';
|
||||
|
||||
|
@@ -11,7 +11,6 @@
|
||||
*/
|
||||
class Controller_Admin_Account extends Controller_Account {
|
||||
protected $secure_actions = array(
|
||||
'group'=>FALSE, // @todo Testing
|
||||
);
|
||||
}
|
||||
?>
|
||||
|
@@ -72,22 +72,21 @@ class Controller_Login extends lnApp_Controller_Login {
|
||||
|
||||
// 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'),
|
||||
));
|
||||
Block::factory()
|
||||
->body(View::factory('pages/login_reset_sent'));
|
||||
|
||||
else
|
||||
HTTP::redirect('login');
|
||||
|
||||
} else {
|
||||
Block::add(array(
|
||||
'title'=>_('Reset your password'),
|
||||
'body'=>View::factory('login_reset'),
|
||||
'style'=>array('css/login.css'=>'screen'),
|
||||
));
|
||||
Block::factory()
|
||||
->body(View::factory('pages/login_reset'));
|
||||
}
|
||||
|
||||
Style::factory()
|
||||
->type('file')
|
||||
->data('media/theme/baseadmin/css/pages/login.css');
|
||||
|
||||
$this->template->shownavbar = FALSE;
|
||||
}
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ class Controller_TemplateDefault extends lnApp_Controller_TemplateDefault {
|
||||
|
||||
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()));
|
||||
throw HTTP_Exception::factory(403,'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();
|
||||
|
||||
@@ -39,8 +39,9 @@ class Controller_TemplateDefault extends lnApp_Controller_TemplateDefault {
|
||||
parent::before();
|
||||
}
|
||||
|
||||
// @todo To rework
|
||||
public function after() {
|
||||
$dc = Kohana::$config->load('config','user_default_method');
|
||||
$dc = 'u/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);
|
||||
@@ -51,21 +52,14 @@ class Controller_TemplateDefault extends lnApp_Controller_TemplateDefault {
|
||||
|
||||
/**
|
||||
* This will filter a search query to only return those accounts for a reseller
|
||||
* @todo Swap the order of these params and make flid necessary
|
||||
*/
|
||||
protected function filter($o,$af,$sort=NULL,$afid=NULL) {
|
||||
protected function filter($o,array $fl,$sort=NULL,$flid=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);
|
||||
|
||||
}
|
||||
}
|
||||
foreach ($o as $x)
|
||||
if (! is_null($flid) AND isset($x->$flid) AND in_array($x->$flid,$fl))
|
||||
array_push($result,$x);
|
||||
|
||||
if ($sort)
|
||||
Sort::MAsort($result,$sort);
|
||||
|
@@ -12,6 +12,12 @@
|
||||
class Controller_Welcome extends Controller_TemplateDefault {
|
||||
protected $auth_required = FALSE;
|
||||
|
||||
public function action_breadcrumb() {
|
||||
$this->auto_render = FALSE;
|
||||
|
||||
$this->response->body(Session::instance()->get_once('breadcrumb'));
|
||||
}
|
||||
|
||||
public function action_index() {
|
||||
if (! Kohana::$config->load('config')->appname)
|
||||
HTTP::redirect('guide/app');
|
||||
@@ -25,11 +31,5 @@ class Controller_Welcome extends Controller_TemplateDefault {
|
||||
|
||||
$this->template->content = $output;
|
||||
}
|
||||
|
||||
public function action_breadcrumb() {
|
||||
$this->auto_render = FALSE;
|
||||
|
||||
$this->response->body(Session::instance()->get_once('breadcrumb'));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -1,19 +0,0 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides Country routines
|
||||
*
|
||||
* @package OSB
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Country {
|
||||
public static function icon($cid) {
|
||||
$co = ORM::factory('Country',$cid);
|
||||
|
||||
return HTML::image(sprintf('media/img/country/%s.png',strtolower($co->two_code)),array('alt'=>$co->currency()->symbol));
|
||||
}
|
||||
}
|
||||
?>
|
@@ -1,52 +0,0 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class is for rendering the tinyMCE editor
|
||||
*
|
||||
* @package OSB
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Editor {
|
||||
private static $added = FALSE;
|
||||
|
||||
public static function add() {
|
||||
if (static::$added)
|
||||
return;
|
||||
|
||||
static::$added = TRUE;
|
||||
|
||||
Script::add(array(
|
||||
'type'=>'file',
|
||||
'data'=>'js/jquery-1.4.2.js',
|
||||
));
|
||||
Script::add(array(
|
||||
'type'=>'file',
|
||||
'data'=>'js/tiny_mce/tiny_mce.js',
|
||||
));
|
||||
Script::add(array(
|
||||
'type'=>'stdin',
|
||||
'data'=>'
|
||||
tinyMCE.init({
|
||||
mode : "specific_textareas",
|
||||
editor_selector : "mceEditor",
|
||||
theme : "advanced",
|
||||
plugins : "table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print",
|
||||
theme_advanced_buttons1_add : "fontselect,fontsizeselect",
|
||||
theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,separator,forecolor,backcolor",
|
||||
theme_advanced_buttons2_add_before: "cut,copy,paste,separator,search,replace,separator",
|
||||
theme_advanced_buttons3_add_before : "tablecontrols,separator",
|
||||
theme_advanced_buttons3_add : "iespell,media,advhr",
|
||||
theme_advanced_toolbar_location : "bottom",
|
||||
theme_advanced_toolbar_align : "center",
|
||||
plugin_insertdate_dateFormat : "%Y-%m-%d",
|
||||
plugin_insertdate_timeFormat : "%H:%M:%S",
|
||||
extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
|
||||
relative_urls: "true",
|
||||
width : "100%"
|
||||
});'));
|
||||
}
|
||||
}
|
||||
?>
|
@@ -51,22 +51,6 @@ abstract class Kohana extends Kohana_Core {
|
||||
return $x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @compat Restore KH 3.1 functionality
|
||||
* @var boolean True if Kohana is running from the command line
|
||||
*/
|
||||
public static $is_cli = FALSE;
|
||||
|
||||
/**
|
||||
* @compat Restore KH 3.1 functionality
|
||||
*/
|
||||
public static function init(array $settings = NULL) {
|
||||
parent::init($settings);
|
||||
|
||||
// Determine if we are running in a command line environment
|
||||
Kohana::$is_cli = (PHP_SAPI === 'cli');
|
||||
}
|
||||
|
||||
/**
|
||||
* Override Kohana's shutdown_handler()
|
||||
*
|
||||
|
@@ -10,22 +10,6 @@
|
||||
* @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 static::collapse($result);
|
||||
}
|
||||
|
||||
private static function collapse(array $array) {
|
||||
$result = array();
|
||||
|
||||
@@ -46,6 +30,22 @@ class Menu {
|
||||
return $result;
|
||||
}
|
||||
|
||||
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 static::collapse($result);
|
||||
}
|
||||
|
||||
public static function ul(array $result,array $append=NULL,$sub=FALSE) {
|
||||
$output = $sub ? '<ul class="dropdown-menu">' : '<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">';
|
||||
|
||||
|
@@ -12,6 +12,9 @@
|
||||
abstract class Minion_Task extends Kohana_Minion_Task {
|
||||
protected $_options = array(
|
||||
'site'=>NULL,
|
||||
'id'=>NULL,
|
||||
'force'=>FALSE,
|
||||
'verbose'=>FALSE,
|
||||
);
|
||||
}
|
||||
?>
|
||||
|
@@ -97,7 +97,7 @@ class Model_Account extends Model_Auth_UserDefault {
|
||||
}
|
||||
|
||||
public function log($message) {
|
||||
// Log the logout
|
||||
// Log a message for this account
|
||||
$alo = ORM::factory('Account_Log');
|
||||
$alo->account_id = $this->id;
|
||||
$alo->ip = Request::$client_ip;
|
||||
@@ -147,7 +147,7 @@ class Model_Account extends Model_Auth_UserDefault {
|
||||
return $active ? $o->where_active()->find_all() : $o->find_all();
|
||||
}
|
||||
|
||||
public function services_count($active=TRUE,$afid=NULL) {
|
||||
public function services_count($active=TRUE) {
|
||||
return $this->services($active)->count();
|
||||
}
|
||||
|
||||
|
@@ -45,7 +45,7 @@ class Model_Auth_UserDefault extends Model_Auth_User {
|
||||
// Columns to ignore
|
||||
protected $_ignored_columns = array('password_confirm');
|
||||
|
||||
/*
|
||||
/**
|
||||
* Complete our login
|
||||
*
|
||||
* For some database logins, we may not want to record the user last login
|
||||
@@ -53,24 +53,9 @@ class Model_Auth_UserDefault extends Model_Auth_User {
|
||||
* here.
|
||||
*
|
||||
* We can also do some other post-login actions here.
|
||||
* @todo Maybe we can do our session update here.
|
||||
*/
|
||||
public function complete_login() {
|
||||
return $this->log('Logged In');
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug function to see that has() finds
|
||||
* @todo This function could be removed
|
||||
*/
|
||||
public function has_list($alias, $model) {
|
||||
// Return list of matches
|
||||
return DB::select()
|
||||
->from($this->_has_many[$alias]['through'])
|
||||
->where($this->_has_many[$alias]['foreign_key'], '=', $this->pk())
|
||||
->where($this->_has_many[$alias]['far_key'], '=', $model->pk())
|
||||
->execute($this->_db)
|
||||
->as_array();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -10,10 +10,14 @@
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Country extends ORM_OSB {
|
||||
protected $_has_one = array(
|
||||
'currency'=>array('far_key'=>'id'),
|
||||
);
|
||||
|
||||
protected $_form = array('id'=>'id','value'=>'name');
|
||||
|
||||
public function currency() {
|
||||
return ORM::factory('Currency')->where('country_id','=',$this->id)->find();
|
||||
public static function icon() {
|
||||
return HTML::image(sprintf('media/img/country/%s.png',strtolower($this->two_code)),array('alt'=>$this->currency->symbol));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -14,23 +14,10 @@ class Model_Group extends Model_Auth_RoleDefault {
|
||||
'account'=>array('through'=>'account_group'),
|
||||
'module_method'=>array('through'=>'group_method','far_key'=>'method_id'),
|
||||
);
|
||||
|
||||
protected $_sorting = array(
|
||||
'name'=>'ASC',
|
||||
);
|
||||
|
||||
// Validation rules
|
||||
protected $_rules = array(
|
||||
'name' => array(
|
||||
'not_empty' => NULL,
|
||||
'min_length' => array(4),
|
||||
'max_length' => array(32),
|
||||
),
|
||||
'description' => array(
|
||||
'max_length' => array(255),
|
||||
),
|
||||
);
|
||||
|
||||
protected $_display_filters = array(
|
||||
'status'=>array(
|
||||
array('StaticList_YesNo::get',array(':value')),
|
||||
|
@@ -14,13 +14,12 @@
|
||||
*/
|
||||
class Model_Module extends ORM_OSB {
|
||||
// Relationships
|
||||
protected $_has_many = array(
|
||||
'module_method'=>array('far_key'=>'id'),
|
||||
);
|
||||
protected $_has_one = array(
|
||||
'record_id'=>array('model'=>'Record_ID','far_key'=>'id'),
|
||||
);
|
||||
|
||||
protected $_has_many = array(
|
||||
'module_method'=>array('far_key'=>'id'),
|
||||
);
|
||||
protected $_sorting = array(
|
||||
'status'=>'DESC',
|
||||
'name'=>'ASC',
|
||||
|
@@ -13,7 +13,6 @@ class Model_RTM extends ORM_OSB {
|
||||
protected $_belongs_to = array(
|
||||
'account' => array(),
|
||||
);
|
||||
|
||||
protected $_has_many = array(
|
||||
'customer' => array('model'=>'account','far_key'=>'id','foreign_key'=>'rtm_id'),
|
||||
'agent' => array('model'=>'rtm','far_key'=>'id','foreign_key'=>'parent_id'),
|
||||
|
@@ -7,7 +7,6 @@
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
* @todo Rename to Record/ID.php
|
||||
*/
|
||||
class Model_Record_ID extends ORM_OSB {
|
||||
protected $_primary_key = 'module_id';
|
||||
@@ -16,7 +15,6 @@ class Model_Record_ID extends ORM_OSB {
|
||||
protected $_created_column = FALSE;
|
||||
protected $_updated_column = FALSE;
|
||||
|
||||
// @todo we need $mid here, since if there is no record, we cant figure out the module that called us.
|
||||
public function next_id($mid) {
|
||||
if (is_null($this->id)) {
|
||||
$this->module_id = $mid;
|
||||
@@ -34,7 +32,7 @@ class Model_Record_ID extends ORM_OSB {
|
||||
$this->id++;
|
||||
|
||||
if (! $this->save())
|
||||
throw new Koahan_Exception(_('Unable to increase ID for :table'),array(':table'=>$mid));
|
||||
throw HTTP_Exception::factory(501,'Unable to increase ID for :table',array(':table'=>$mid));
|
||||
|
||||
return $this->id;
|
||||
}
|
||||
|
@@ -19,6 +19,20 @@ abstract class ORM extends Kohana_ORM {
|
||||
private $_formated = FALSE;
|
||||
// Our filters used to display values in a friendly format
|
||||
protected $_display_filters = array();
|
||||
// Tables that do not have a site_id column
|
||||
public static $no_site_id_tables = array('setup','country','currency','language','tax');
|
||||
|
||||
/**
|
||||
* Add our OSB site_id to each SELECT query
|
||||
* @see parent::__build()
|
||||
*/
|
||||
final protected function _build($type) {
|
||||
// Exclude tables without site ID's
|
||||
if (! in_array($this->_table_name,ORM::$no_site_id_tables))
|
||||
$this->where($this->_object_name.'.site_id','=',Company::instance()->site());
|
||||
|
||||
return parent::_build($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format fields for display purposes
|
||||
@@ -33,6 +47,13 @@ abstract class ORM extends Kohana_ORM {
|
||||
$this->_formated = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function help to find records that are active
|
||||
*/
|
||||
protected function _where_active() {
|
||||
return $this->where('status','=',TRUE);
|
||||
}
|
||||
|
||||
public function clear() {
|
||||
$this->_formated = FALSE;
|
||||
$this->_object_formated = array();
|
||||
@@ -40,23 +61,6 @@ abstract class ORM extends Kohana_ORM {
|
||||
return parent::clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a formated columns, as per the model definition
|
||||
*/
|
||||
public function display($column) {
|
||||
// Trigger a load of the record.
|
||||
$value = $this->__get($column);
|
||||
|
||||
// If some of our fields need to be formated for display purposes.
|
||||
if (! $this->_formated AND $this->_display_filters)
|
||||
$this->_format();
|
||||
|
||||
if (isset($this->_object_formated[$column]))
|
||||
return $this->_object_formated[$column];
|
||||
else
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override KH's ORM count_relations() function, to include our site_id in the query.
|
||||
*
|
||||
@@ -94,21 +98,21 @@ abstract class ORM extends Kohana_ORM {
|
||||
return (int) $count;
|
||||
}
|
||||
|
||||
/** OSB SPECIFIC ENHANCEMENTS **/
|
||||
|
||||
// Tables that do not have a site_id column
|
||||
public static $no_site_id_tables = array('setup','country','currency','language','tax');
|
||||
|
||||
/**
|
||||
* Add our OSB site_id to each SELECT query
|
||||
* @see parent::__build()
|
||||
* Return a formated columns, as per the model definition
|
||||
*/
|
||||
final protected function _build($type) {
|
||||
// Exclude tables without site ID's
|
||||
if (! in_array($this->_table_name,ORM::$no_site_id_tables))
|
||||
$this->where($this->_object_name.'.site_id','=',Company::instance()->site());
|
||||
public function display($column) {
|
||||
// Trigger a load of the record.
|
||||
$value = $this->__get($column);
|
||||
|
||||
return parent::_build($type);
|
||||
// If some of our fields need to be formated for display purposes.
|
||||
if (! $this->_formated AND $this->_display_filters)
|
||||
$this->_format();
|
||||
|
||||
if (isset($this->_object_formated[$column]))
|
||||
return $this->_object_formated[$column];
|
||||
else
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,6 +122,9 @@ abstract class ORM extends Kohana_ORM {
|
||||
return $this->_where_active()->find_all();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is our AJAX helper, used by module list_autocomplete()
|
||||
*/
|
||||
public function list_autocomplete($term,$index,$value,array $label,array $limit=array(),array $options=NULL) {
|
||||
$result = array();
|
||||
|
||||
@@ -174,13 +181,6 @@ abstract class ORM extends Kohana_ORM {
|
||||
return $x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function help to find records that are active
|
||||
*/
|
||||
protected function _where_active() {
|
||||
return $this->where('status','=',TRUE);
|
||||
}
|
||||
|
||||
public function where_active() {
|
||||
return $this->_where_active();
|
||||
}
|
||||
|
@@ -18,14 +18,14 @@ abstract class ORM_OSB extends ORM {
|
||||
protected $_created_column = array('column'=>'date_orig','format'=>TRUE);
|
||||
protected $_updated_column = array('column'=>'date_last','format'=>TRUE);
|
||||
|
||||
// Our attribute values that need to be stored as serialized
|
||||
protected $_serialize_column = array();
|
||||
// Our attributes used in forms.
|
||||
protected $_form = array();
|
||||
|
||||
// Our attributes that should be converted to NULL when empty
|
||||
protected $_nullifempty = array();
|
||||
|
||||
// Our attributes used in forms.
|
||||
protected $_form = array();
|
||||
// Our attribute values that need to be stored as serialized
|
||||
protected $_serialize_column = array();
|
||||
|
||||
// Rules to assist with site ID and getting next record ID for inserts.
|
||||
public function rules() {
|
||||
@@ -39,19 +39,6 @@ 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.
|
||||
*/
|
||||
@@ -65,6 +52,55 @@ abstract class ORM_OSB extends ORM {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto process some data as it comes from the database
|
||||
* @see parent::__get()
|
||||
*/
|
||||
public function __get($column) {
|
||||
if (array_key_exists($column,$this->_table_columns)) {
|
||||
// If the column is a blob, we'll decode it automatically
|
||||
if (
|
||||
$this->_table_columns[$column]['data_type'] == 'blob'
|
||||
AND ! is_null($this->_object[$column])
|
||||
AND ! isset($this->_changed[$column])
|
||||
AND (! isset($this->_table_columns[$column]['auto_convert']) OR ! $this->_table_columns[$column]['auto_convert'])
|
||||
) {
|
||||
|
||||
// In case our blob hasnt been saved as one.
|
||||
try {
|
||||
$this->_object[$column] = $this->_blob($this->_object[$column]);
|
||||
}
|
||||
catch(Exception $e) {
|
||||
HTTP_Exception::factory(501,Kohana_Exception::text($e));
|
||||
}
|
||||
|
||||
$this->_table_columns[$column]['auto_convert'] = TRUE;
|
||||
}
|
||||
|
||||
// If the column is a serialized object, we'll unserialize it.
|
||||
if (
|
||||
in_array($column,$this->_serialize_column)
|
||||
AND is_string($this->_object[$column])
|
||||
AND ! is_null($this->_object[$column])
|
||||
AND ! isset($this->_changed[$column])
|
||||
AND (! isset($this->_table_columns[$column]['unserialized']) OR ! $this->_table_columns[$column]['unserialized'])
|
||||
) {
|
||||
|
||||
// In case our object hasnt been saved as serialized.
|
||||
try {
|
||||
$this->_object[$column] = unserialize($this->_object[$column]);
|
||||
}
|
||||
catch(Exception $e) {
|
||||
HTTP_Exception::factory(501,Kohana_Exception::text($e));
|
||||
}
|
||||
|
||||
$this->_table_columns[$column]['unserialized'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return parent::__get($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* If a column is marked to be nullified if it is empty, this is where it is done.
|
||||
*/
|
||||
@@ -86,82 +122,15 @@ abstract class ORM_OSB extends ORM {
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto process some data as it comes from the database
|
||||
* @see parent::__get()
|
||||
* Try and (un)serialize our data, and if it fails, just return it.
|
||||
*/
|
||||
public function __get($column) {
|
||||
if (array_key_exists($column,$this->_table_columns)) {
|
||||
// If the column is a blob, we'll decode it automatically
|
||||
if (
|
||||
$this->_table_columns[$column]['data_type'] == 'blob'
|
||||
AND ! is_null($this->_object[$column])
|
||||
AND ! isset($this->_changed[$column])
|
||||
AND (! isset($this->_table_columns[$column]['auto_convert']) OR ! $this->_table_columns[$column]['auto_convert'])
|
||||
) {
|
||||
private function _serialize($data,$set=FALSE) {
|
||||
try {
|
||||
return $set ? serialize($data) : unserialize($data);
|
||||
|
||||
// In case our blob hasnt been saved as one.
|
||||
try {
|
||||
$this->_object[$column] = $this->_blob($this->_object[$column]);
|
||||
}
|
||||
catch(Exception $e) {
|
||||
// @todo Log this exception
|
||||
echo Kohana_Exception::text($e), "\n";
|
||||
echo debug_print_backtrace();
|
||||
}
|
||||
|
||||
$this->_table_columns[$column]['auto_convert'] = TRUE;
|
||||
}
|
||||
|
||||
// If the column is a serialized object, we'll unserialize it.
|
||||
if (
|
||||
in_array($column,$this->_serialize_column)
|
||||
AND is_string($this->_object[$column])
|
||||
AND ! is_null($this->_object[$column])
|
||||
AND ! isset($this->_changed[$column])
|
||||
AND (! isset($this->_table_columns[$column]['unserialized']) OR ! $this->_table_columns[$column]['unserialized'])
|
||||
) {
|
||||
|
||||
// In case our object hasnt been saved as serialized.
|
||||
try {
|
||||
$this->_object[$column] = unserialize($this->_object[$column]);
|
||||
}
|
||||
catch(Exception $e) {
|
||||
// @todo Log this exception
|
||||
echo Kohana_Exception::text($e), "\n";
|
||||
echo debug_print_backtrace();
|
||||
}
|
||||
|
||||
$this->_table_columns[$column]['unserialized'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return parent::__get($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will enhance the [Validate::filter], since it always passes
|
||||
* the value as the first argument and sometimes functions need that to not
|
||||
* be the first argument.
|
||||
*
|
||||
* Currently this implements:
|
||||
* [date()][date-ref]
|
||||
*
|
||||
* [date-ref]: http://www.php.net/date
|
||||
*
|
||||
* This function will throw an exception if called without a function
|
||||
* defined.
|
||||
*
|
||||
* @param mixed $val Value to be processed
|
||||
* @param string $func Name of function to call
|
||||
* @param string $arg Other arguments for the function
|
||||
* @todo This has probably changed in KH 3.1
|
||||
*/
|
||||
final public static function x_filters($val,$func,$arg) {
|
||||
switch ($func) {
|
||||
case 'date':
|
||||
return date($arg,$val);
|
||||
default:
|
||||
throw new Exception(sprintf(_('Unknown function: %s (%s,%s)'),$func,$arg,$val));
|
||||
// Maybe the data serialized?
|
||||
} catch (Exception $e) {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,19 +164,6 @@ abstract class ORM_OSB extends ORM {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the site ID attribute for each row update
|
||||
*/
|
||||
final public static function set_site_id($model,$field) {
|
||||
if (! is_null($model->$field))
|
||||
return TRUE;
|
||||
|
||||
$model->_changed[$field] = $field;
|
||||
$model->$field = Company::instance()->site();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public function keyget($column,$key=NULL) {
|
||||
if (is_null($key) OR ! is_array($this->$column))
|
||||
return $this->$column;
|
||||
@@ -249,6 +205,19 @@ abstract class ORM_OSB extends ORM {
|
||||
return parent::save($validation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the site ID attribute for each row update
|
||||
*/
|
||||
final public static function set_site_id($model,$field) {
|
||||
if (! is_null($model->$field))
|
||||
return TRUE;
|
||||
|
||||
$model->_changed[$field] = $field;
|
||||
$model->$field = Company::instance()->site();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public function status($render=FALSE) {
|
||||
if (! isset($this->_table_columns['status']))
|
||||
return NULL;
|
||||
|
@@ -13,10 +13,6 @@ abstract class StaticList {
|
||||
// Our Static Items List
|
||||
abstract protected function _table();
|
||||
|
||||
// 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 function _get($id) {
|
||||
$table = $this->_table();
|
||||
|
@@ -1,20 +0,0 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class extends Minions Tasks to require the site option
|
||||
*
|
||||
* @package OSB
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
abstract class Task extends Minion_Task {
|
||||
protected $_options = array(
|
||||
'site'=>NULL,
|
||||
'id'=>NULL,
|
||||
'force'=>FALSE,
|
||||
'verbose'=>FALSE,
|
||||
);
|
||||
}
|
||||
?>
|
@@ -9,7 +9,7 @@
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Task_Account_Complete extends Task {
|
||||
class Task_Account_Complete extends Minion_Task {
|
||||
protected function _execute(array $params) {
|
||||
$c = 0;
|
||||
|
||||
@@ -18,8 +18,7 @@ class Task_Account_Complete extends Task {
|
||||
|
||||
foreach ($o->find_all() as $ao) {
|
||||
if (count($ao->invoice->where_unprocessed()->find_all()) == 0 AND count($ao->service->where_active()->find_all()) == 0)
|
||||
// @todo Cant update status=0, problem with sessions in CLI
|
||||
echo $ao->id.',';
|
||||
$ao->status = 0;
|
||||
|
||||
$ao->save();
|
||||
|
||||
@@ -27,7 +26,7 @@ class Task_Account_Complete extends Task {
|
||||
$c++;
|
||||
}
|
||||
|
||||
printf('%s services updated',$c);
|
||||
printf("%s services made inactive\n",$c);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -22,21 +22,6 @@ class URL extends Kohana_URL {
|
||||
return (Request::current() AND ((Auth::instance()->logged_in() AND ! empty(URL::$method_directory[strtolower(Request::current()->directory())])) OR in_array(strtolower(Request::current()->controller()),array('login'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper to provide a URL::site() link based on function
|
||||
*/
|
||||
public static function link($dir,$src,$site=FALSE) {
|
||||
if (! $dir)
|
||||
return $src;
|
||||
|
||||
if (! array_key_exists($dir,URL::$method_directory))
|
||||
throw new Kohana_Exception('Unknown directory :dir for :src',array(':dir'=>$dir,':src'=>$src));
|
||||
|
||||
$x = URL::$method_directory[$dir].'/'.$src;
|
||||
|
||||
return $site ? URL::site($x) : $x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to reveal the real directory for a URL
|
||||
*/
|
||||
@@ -54,6 +39,21 @@ class URL extends Kohana_URL {
|
||||
return $dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper to provide a URL::site() link based on function
|
||||
*/
|
||||
public static function link($dir,$src,$site=FALSE) {
|
||||
if (! $dir)
|
||||
return $src;
|
||||
|
||||
if (! array_key_exists($dir,URL::$method_directory))
|
||||
throw new Kohana_Exception('Unknown directory :dir for :src',array(':dir'=>$dir,':src'=>$src));
|
||||
|
||||
$x = URL::$method_directory[$dir].'/'.$src;
|
||||
|
||||
return $site ? URL::site($x) : $x;
|
||||
}
|
||||
|
||||
public static function navbar() {
|
||||
$result = array();
|
||||
|
||||
|
@@ -14,9 +14,10 @@ class XML extends XML_Core {
|
||||
* Collapse an XML object into a simple array
|
||||
*/
|
||||
public function collapse(XML $xml=NULL) {
|
||||
$result = array();
|
||||
|
||||
if (is_null($xml))
|
||||
$xml = $this;
|
||||
$result = array();
|
||||
|
||||
foreach ($xml->as_array() as $j=>$k) {
|
||||
$v = $xml->$j->value();
|
||||
|
Reference in New Issue
Block a user