diff --git a/application/bootstrap.php b/application/bootstrap.php index d0d0927c..4841ad50 100644 --- a/application/bootstrap.php +++ b/application/bootstrap.php @@ -152,7 +152,7 @@ Route::set('default', '((/(/)))', array('id' => '[a-zA-Z /** * If APC is enabled, and we need to clear the cache */ -if (file_exists(APPPATH.'cache/CLEAR_APC_CACHE') AND function_exists('apc_clear_cache') AND ! Kohana::$is_cli) { +if (file_exists(APPPATH.'cache/CLEAR_APC_CACHE') AND function_exists('apc_clear_cache') AND (PHP_SAPI !== 'cli')) { if (! apc_clear_cache() OR ! unlink(APPPATH.'cache/CLEAR_APC_CACHE')) throw new Kohana_Exception('Unable to clear the APC cache.'); } diff --git a/application/classes/ORM/OSB.php b/application/classes/ORM/OSB.php new file mode 100644 index 00000000..6ce16d06 --- /dev/null +++ b/application/classes/ORM/OSB.php @@ -0,0 +1,220 @@ +'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(); + + // Rules to assist with site ID and getting next record ID for inserts. + public function rules() { + return array( + 'id'=>array( + array('ORM_OSB::get_next_id',array(':model',':field')), + ), + 'site_id'=>array( + array('ORM_OSB::set_site_id',array(':model',':field')), + ), + ); + } + + /** + * 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 _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)); + } + } + + final public static function form($table,$blank=FALSE) { + return ORM::factory($table)->formselect($blank); + } + + /** + * Get Next record id + * + * @param array Validate object + * @param string Primary Key + */ + public static function get_next_id($model,$field) { + if (! is_null($model->$field)) + return TRUE; + + $model->_changed[$field] = $field; + + $ido = ORM::factory('module') + ->where('name','=',$model->_table_name) + ->find(); + + if (! $ido->loaded()) + throw new Kohana_Exception('Problem getting record_id for :table',array(':table'=>$model->_table_name)); + + $model->$field = $ido->record_id->next_id($ido->id); + + return TRUE; + } + + /** + * Set the site ID attribute for each row update + */ + public static function set_site_id($model,$field) { + if (! is_null($model->$field)) + return TRUE; + + $model->_changed[$field] = $field; + $model->$field = Config::siteid(); + + return TRUE; + } + + 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) { + // @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); + } + + public function formselect($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; + else + return array_key_exists($key,$this->$column) ? $this->{$column}[$key] : NULL; + } + + public function save(Validation $validation = NULL) { + // Find any fields that have changed, and process them. + if ($this->_changed) + foreach ($this->_changed as $c) + // 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); + + // We need to reset our auto_convert flag + if (isset($this->_table_columns[$c]['auto_convert'])) + $this->_table_columns[$c]['auto_convert'] = FALSE; + + // Any fields that should be seriailzed, we'll do that. + } elseif (is_array($this->_object[$c]) AND in_array($c,$this->_serialize_column)) { + $this->_object[$c] = serialize($this->_object[$c]); + } + + return parent::save($validation); + } + + /** + * Retrieve and Store DB BLOB data. + */ + private function blob($data,$set=FALSE) { + return $set ? gzcompress(serialize($data)) : unserialize(gzuncompress($data)); + } + + public function config($key) { + $mc = Config::instance()->so->module_config($this->_object_name); + + return empty($mc[$key]) ? '' : $mc[$key]; + } + + public function list_active() { + return $this->_where_active()->find_all(); + } + + public function list_count($active=TRUE) { + $a=($active ? $this->_where_active() : $this); + + return $a->find_all()->count(); + } +} +?> diff --git a/application/classes/controller/login.php b/application/classes/controller/login.php index 74a18836..c55a72f4 100644 --- a/application/classes/controller/login.php +++ b/application/classes/controller/login.php @@ -1,4 +1,138 @@ 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'), + )); + } + } +} ?> diff --git a/application/classes/controller/templatedefault.php b/application/classes/controller/templatedefault.php index 0e148280..5f6f420c 100644 --- a/application/classes/controller/templatedefault.php +++ b/application/classes/controller/templatedefault.php @@ -3,7 +3,7 @@ /** * This class provides the default template controller for rendering pages. * - * @package lnApp + * @package OSB * @subpackage Page/Template * @category Controllers * @author Deon George diff --git a/application/classes/controller/welcome.php b/application/classes/controller/welcome.php index 2d0131b3..6e1ffcb0 100644 --- a/application/classes/controller/welcome.php +++ b/application/classes/controller/welcome.php @@ -1,9 +1,9 @@ uri(array('file'=>$value['data']))); break; + case 'src': + $foutput .= HTML::script($value['data']); + break; case 'stdin': $soutput .= sprintf("",$value['data']); break; diff --git a/application/classes/model/account/log.php b/application/classes/model/account/log.php index 7992b751..498d993e 100644 --- a/application/classes/model/account/log.php +++ b/application/classes/model/account/log.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_Account_Log extends ORMOSB { +class Model_Account_Log extends ORM_OSB { protected $_belongs_to = array( 'account'=>array(), ); diff --git a/application/classes/model/auth/userdefault.php b/application/classes/model/auth/userdefault.php index a5e6ee26..2a7f9d81 100644 --- a/application/classes/model/auth/userdefault.php +++ b/application/classes/model/auth/userdefault.php @@ -1,7 +1,7 @@ where('country_id','=',$this->id)->find(); } diff --git a/application/classes/model/currency.php b/application/classes/model/currency.php index 24e68ace..fcb102e8 100644 --- a/application/classes/model/currency.php +++ b/application/classes/model/currency.php @@ -10,6 +10,6 @@ * @copyright (c) 2010 Deon George * @license http://dev.leenooks.net/license.html */ -class Model_Currency extends ORMOSB { +class Model_Currency extends ORM_OSB { } ?> diff --git a/application/classes/model/group/method.php b/application/classes/model/group/method.php index 6b44eaac..0c63e3f2 100644 --- a/application/classes/model/group/method.php +++ b/application/classes/model/group/method.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Deon George * @license http://dev.leenooks.net/license.html */ -class Model_Group_Method extends ORMOSB { +class Model_Group_Method extends ORM_OSB { // Relationships protected $_has_one = array( 'record_id'=>array(), diff --git a/application/classes/model/language.php b/application/classes/model/language.php index ae88714f..5b469a9b 100644 --- a/application/classes/model/language.php +++ b/application/classes/model/language.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Deon George * @license http://dev.leenooks.net/license.html */ -class Model_Language extends ORMOSB { +class Model_Language extends ORM_OSB { protected $_form = array('id'=>'id','value'=>'name'); } ?> diff --git a/application/classes/model/module.php b/application/classes/model/module.php index 2fc039cf..183125d5 100644 --- a/application/classes/model/module.php +++ b/application/classes/model/module.php @@ -13,7 +13,7 @@ * @copyright (c) 2010 Deon George * @license http://dev.leenooks.net/license.html */ -class Model_Module extends ORMOSB { +class Model_Module extends ORM_OSB { // Relationships protected $_has_many = array( 'module_method'=>array('far_key'=>'id'), diff --git a/application/classes/model/module/method.php b/application/classes/model/module/method.php index 4150ab07..932a2127 100644 --- a/application/classes/model/module/method.php +++ b/application/classes/model/module/method.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Deon George * @license http://dev.leenooks.net/license.html */ -class Model_Module_Method extends ORMOSB { +class Model_Module_Method extends ORM_OSB { // Relationships protected $_belongs_to = array( 'module'=>array(), diff --git a/application/classes/model/module/method/token.php b/application/classes/model/module/method/token.php index a5f747b9..48b56d5b 100644 --- a/application/classes/model/module/method/token.php +++ b/application/classes/model/module/method/token.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Deon George * @license http://dev.leenooks.net/license.html */ -class Model_Module_Method_Token extends ORMOSB { +class Model_Module_Method_Token extends ORM_OSB { // Relationships protected $_belongs_to = array( 'account'=>array(), diff --git a/application/classes/model/record/id.php b/application/classes/model/record/id.php index 5a364801..926964ae 100644 --- a/application/classes/model/record/id.php +++ b/application/classes/model/record/id.php @@ -8,7 +8,7 @@ * @copyright (c) 2010 Deon George * @license http://dev.leenooks.net/license.html */ -class Model_Record_Id extends ORMOSB { +class Model_Record_Id extends ORM_OSB { protected $_primary_key = 'module_id'; // This module doesnt keep track of column updates automatically diff --git a/application/classes/model/setup.php b/application/classes/model/setup.php index a20cc812..4b1f8ec8 100644 --- a/application/classes/model/setup.php +++ b/application/classes/model/setup.php @@ -13,7 +13,7 @@ * @copyright (c) 2010 Deon George * @license http://dev.leenooks.net/license.html */ -class Model_Setup extends ORMOSB { +class Model_Setup extends ORM_OSB { // Setup doesnt use the update column protected $_updated_column = FALSE; diff --git a/application/classes/orm.php b/application/classes/orm.php index 274034e0..bea437fe 100644 --- a/application/classes/orm.php +++ b/application/classes/orm.php @@ -10,9 +10,9 @@ * @copyright (c) 2010 Deon George * @license http://dev.leenooks.net/license.html */ -class ORM extends Kohana_ORM { - protected $_table_names_plural = false; - protected $_model_names_plural = false; +abstract class ORM extends Kohana_ORM { + protected $_table_names_plural = FALSE; + protected $_model_names_plural = FALSE; private $_object_formated = array(); private $_formated = FALSE; // Our filters used to display values in a friendly format diff --git a/application/config/cache.php b/application/config/cache.php index d5f61103..e73ad4a4 100644 --- a/application/config/cache.php +++ b/application/config/cache.php @@ -11,11 +11,22 @@ * @license http://dev.osbill.net/license.html */ -return array ( - 'file' => array ( +return array( + 'apc' => array( + 'driver' => 'apc', + 'default_expire' => 3600, + ), + + 'file' => array( 'driver' => 'file', 'cache_dir' => Kohana::$cache_dir ? Kohana::$cache_dir : '/dev/shm/lnapp', 'default_expire' => 3600, - ) + 'ignore_on_delete' => array( + '.gitignore', + '.git', + '.htaccess', + '.svn' + ) + ), ); ?> diff --git a/application/config/config.php b/application/config/config.php index c6292f4c..3e7cdeba 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -10,10 +10,10 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ + return array( 'appname' => '', 'cache_type' => 'file', - 'theme' => '', // @todo This should be in the DB 'email_from' => array('noreply@graytech.net.au'=>'Graytech Hosting'), 'email_admin_only'=> array( 'adsl_traffic_notice'=>array('deon@c5t61p.leenooks.vpn'=>'Deon George'), @@ -39,5 +39,6 @@ return array( 'accnum' => '120 440 821', // @todo This should come from the DB 'site_name' => 'Graytech Hosting Pty Ltd', // @todo This should come from the DB 'taxid' => 'ABN: 49 106 229 476', // @todo This should come from the DB + 'theme' => 'yaml', // @todo This should be in the DB ); ?> diff --git a/modules/adsl/classes/model/adsl/plan.php b/modules/adsl/classes/model/adsl/plan.php index 0b8b9036..466f8e2b 100644 --- a/modules/adsl/classes/model/adsl/plan.php +++ b/modules/adsl/classes/model/adsl/plan.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_ADSL_Plan extends ORMOSB { +class Model_ADSL_Plan extends ORM_OSB { // Relationships // @todo This model should probably be joined with product_plugin_adsl protected $_belongs_to = array( diff --git a/modules/adsl/classes/model/adsl/supplier.php b/modules/adsl/classes/model/adsl/supplier.php index 397155ab..dd642f5d 100644 --- a/modules/adsl/classes/model/adsl/supplier.php +++ b/modules/adsl/classes/model/adsl/supplier.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_ADSL_Supplier extends ORMOSB { +class Model_ADSL_Supplier extends ORM_OSB { // Relationships protected $_has_many = array( 'adsl_supplier_plan'=>array('foreign_key'=>'supplier_id','far_key'=>'id'), diff --git a/modules/adsl/classes/model/adsl/supplier/plan.php b/modules/adsl/classes/model/adsl/supplier/plan.php index 36ba2d48..26781deb 100644 --- a/modules/adsl/classes/model/adsl/supplier/plan.php +++ b/modules/adsl/classes/model/adsl/supplier/plan.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_ADSL_Supplier_Plan extends ORMOSB { +class Model_ADSL_Supplier_Plan extends ORM_OSB { // Relationships protected $_has_many = array( 'adsl_plan'=>array('far_key'=>'id'), diff --git a/modules/adsl/classes/model/service/plugin/adsl.php b/modules/adsl/classes/model/service/plugin/adsl.php index 57622432..bb3ed426 100644 --- a/modules/adsl/classes/model/service/plugin/adsl.php +++ b/modules/adsl/classes/model/service/plugin/adsl.php @@ -241,26 +241,21 @@ class Model_Service_Plugin_ADSL extends Model_Service_Plugin { $date = mktime(0,0,0,date('n',$period),$day,date('Y',$period)); $daysleft = date('d',strtotime('last day of',$date))-$day; - $google = GoogleChart::factory('vertical_bar'); - $google->title = sprintf('DSL traffic usage as at %s',Config::date($date)); + $google = GoogleChart::factory('Legacy') + ->type('vertical_bar') + ->title(sprintf('DSL traffic usage as at %s',Config::date($date))); foreach ($traffic_data as $k => $details) - $google->series(array( - 'title'=>array((isset($friendly[$k]) ? $friendly[$k] : $k)), - 'axis'=>'x', - 'data'=>array((isset($friendly[$k]) ? $friendly[$k] : $k)=>$traffic_data[$k]))); + $google->data(array('yl'=>($x=isset($friendly[$k]) ? $friendly[$k] : $k)),array($x=>$traffic_data[$k])); // Work out comulative numbers foreach ($traffic_data as $k => $details) - $google->series(array( - 'title'=>array((isset($friendly['cumulative_'.$k]) ? $friendly['cumulative_'.$k] : 'cumulative_'.$k)), - 'axis'=>'r', - 'data'=>array((isset($friendly['cumulative_'.$k]) ? $friendly['cumulative_'.$k] : 'cumulative_'.$k)=>$this->cumulative($traffic_data[$k])))); + $google->data(array('yr'=>($x=isset($friendly['cumulative'.$k]) ? $friendly['cumulative'.$k] : 'cumulative'.$k)),array($x=>$this->cumulative($traffic_data[$k]))); foreach ($array as $item) { switch ($item) { case 'MONTH_GRAPH': $value = (string)$google; break; - case 'MONTH_TABLE': $value = $google->html_table(FALSE,array( + case 'MONTH_TABLE': $value = $google->table(FALSE,array( 'table'=>'style="border: 1px solid #bebcb7; padding: 5px 5px; background: none repeat scroll 0% 0% #f8f7f5; font-size: 70%;"', )); break; @@ -367,35 +362,27 @@ class Model_Service_Plugin_ADSL extends Model_Service_Plugin { * Render a google chart of traffic */ public function graph_traffic($month=NULL) { - $google = GoogleChart::factory('vertical_bar'); + $google = GoogleChart::factory('Legacy') + ->type('vertical_bar'); // If we came in via a post to show a particular month, then show that, otherwise show the yearly result if (! is_null($month) AND trim($month)) { - $google->title = sprintf('DSL traffic usage for %s',$_POST['month']); + $google->title(sprintf('DSL traffic usage for %s',$_POST['month'])); $traffic_data = $this->get_traffic_data_daily(strtotime($_POST['month'].'-01')); foreach ($traffic_data as $k => $details) - $google->series(array( - 'title'=>array((isset($friendly[$k]) ? $friendly[$k] : $k)), - 'axis'=>'x', - 'data'=>array((isset($friendly[$k]) ? $friendly[$k] : $k)=>$traffic_data[$k]))); + $google->data(array('yl'=>($x=isset($friendly[$k]) ? $friendly[$k] : $k)),array($x=>$traffic_data[$k])); foreach ($traffic_data as $k => $details) - $google->series(array( - 'title'=>array((isset($friendly['cumulative'.$k]) ? $friendly['cumulative'.$k] : 'cumulative'.$k)), - 'axis'=>'r', - 'data'=>array((isset($friendly['cumulative'.$k]) ? $friendly['cumulative'.$k] : 'cumulative'.$k)=>$this->cumulative($traffic_data[$k])))); + $google->data(array('yr'=>($x=isset($friendly['cumulative'.$k]) ? $friendly['cumulative'.$k] : 'cumulative'.$k)),array($x=>$this->cumulative($traffic_data[$k]))); } else { // @todo Change the date to the last record date - $google->title = sprintf('Monthly DSL traffic usage as at %s',Config::date(strtotime('yesterday'))); + $google->title(sprintf('Monthly DSL traffic usage as at %s',Config::date(strtotime('yesterday')))); $traffic_data = $this->get_traffic_data_monthly(); foreach ($traffic_data as $k => $details) - $google->series(array( - 'title'=>array((isset($friendly[$k]) ? $friendly[$k] : $k)), - 'axis'=>'x', - 'data'=>array((isset($friendly[$k]) ? $friendly[$k] : $k)=>$traffic_data[$k]))); + $google->data(array('yl'=>($x=isset($friendly[$k]) ? $friendly[$k] : $k)),array($x=>$traffic_data[$k])); } return (string)$google; diff --git a/modules/adsl/classes/model/service/plugin/adsl/traffic.php b/modules/adsl/classes/model/service/plugin/adsl/traffic.php index cc626224..bbe9c13e 100644 --- a/modules/adsl/classes/model/service/plugin/adsl/traffic.php +++ b/modules/adsl/classes/model/service/plugin/adsl/traffic.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_Service_Plugin_ADSL_Traffic extends ORMOSB { +class Model_Service_Plugin_ADSL_Traffic extends ORM_OSB { protected $_table_name = 'service__adsl_traffic'; protected $_primary_key = 'service'; protected $_disable_wild_select = TRUE; diff --git a/modules/affiliate/classes/model/affiliate.php b/modules/affiliate/classes/model/affiliate.php index 8464ea41..9fb257ad 100644 --- a/modules/affiliate/classes/model/affiliate.php +++ b/modules/affiliate/classes/model/affiliate.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_Affiliate extends ORMOSB { +class Model_Affiliate extends ORM_OSB { // Relationships protected $_belongs_to = array( 'host_server_affiliate'=>array('far_key'=>'affiliate_id','foreign_key'=>'id'), diff --git a/modules/cart/classes/model/cart.php b/modules/cart/classes/model/cart.php index 5a9b6b2a..4bfc6d3f 100644 --- a/modules/cart/classes/model/cart.php +++ b/modules/cart/classes/model/cart.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_Cart extends ORMOSB { +class Model_Cart extends ORM_OSB { protected $_belongs_to = array( 'product'=>array(), ); diff --git a/modules/charge/classes/model/charge.php b/modules/charge/classes/model/charge.php index 8d51c382..9d9560cc 100644 --- a/modules/charge/classes/model/charge.php +++ b/modules/charge/classes/model/charge.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_Charge extends ORMOSB { +class Model_Charge extends ORM_OSB { // Charge doesnt use the update column protected $_updated_column = FALSE; protected $_serialize_column = array( diff --git a/modules/checkout/classes/model/checkout.php b/modules/checkout/classes/model/checkout.php index b98d9e41..f493ad94 100644 --- a/modules/checkout/classes/model/checkout.php +++ b/modules/checkout/classes/model/checkout.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_Checkout extends ORMOSB { +class Model_Checkout extends ORM_OSB { protected $_has_many = array( 'account'=>array('through'=>'account_billing','foreign_key'=>'checkout_plugin_id'), 'payment'=>array(), diff --git a/modules/domain/classes/model/domain/registrar.php b/modules/domain/classes/model/domain/registrar.php index 942b3f59..81037f65 100644 --- a/modules/domain/classes/model/domain/registrar.php +++ b/modules/domain/classes/model/domain/registrar.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_Domain_Registrar extends ORMOSB { +class Model_Domain_Registrar extends ORM_OSB { /** * The button that provides a login to the Registrar to manage the domain license */ diff --git a/modules/domain/classes/model/domain/tld.php b/modules/domain/classes/model/domain/tld.php index 18fb0b4d..ece00130 100644 --- a/modules/domain/classes/model/domain/tld.php +++ b/modules/domain/classes/model/domain/tld.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_Domain_TLD extends ORMOSB { +class Model_Domain_TLD extends ORM_OSB { protected $_display_filters = array( 'name'=>array( array('strtoupper',array(':value')), diff --git a/modules/email/classes/model/email/log.php b/modules/email/classes/model/email/log.php index 88ee69ff..e0bffc24 100644 --- a/modules/email/classes/model/email/log.php +++ b/modules/email/classes/model/email/log.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_Email_Log extends ORMOSB { +class Model_Email_Log extends ORM_OSB { // Email Log doesnt use the update column protected $_updated_column = FALSE; diff --git a/modules/email/classes/model/email/template.php b/modules/email/classes/model/email/template.php index d11dee05..6d5a1a42 100644 --- a/modules/email/classes/model/email/template.php +++ b/modules/email/classes/model/email/template.php @@ -9,7 +9,7 @@ * @copyright (c) 2010 Deon George * @license http://dev.leenooks.net/license.html */ -class Model_Email_Template extends ORMOSB { +class Model_Email_Template extends ORM_OSB { protected $_has_many = array( 'email_template_translate'=>array('foreign_key'=>'email_template_id','far_key'=>'id'), ); diff --git a/modules/email/classes/model/email/template/translate.php b/modules/email/classes/model/email/template/translate.php index 6616cc81..2908962c 100644 --- a/modules/email/classes/model/email/template/translate.php +++ b/modules/email/classes/model/email/template/translate.php @@ -9,7 +9,7 @@ * @copyright (c) 2010 Deon George * @license http://dev.leenooks.net/license.html */ -class Model_Email_Template_Translate extends ORMOSB { +class Model_Email_Template_Translate extends ORM_OSB { // This module doesnt keep track of column updates automatically protected $_created_column = FALSE; protected $_updated_column = FALSE; diff --git a/modules/export/classes/model/export.php b/modules/export/classes/model/export.php index f215121c..b9d8055a 100644 --- a/modules/export/classes/model/export.php +++ b/modules/export/classes/model/export.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_Export extends ORMOSB { +class Model_Export extends ORM_OSB { protected $_serialize_column = array( 'map_data', ); diff --git a/modules/gchart/classes/GoogleChart.php b/modules/gchart/classes/GoogleChart.php new file mode 100644 index 00000000..91f1aeb8 --- /dev/null +++ b/modules/gchart/classes/GoogleChart.php @@ -0,0 +1,176 @@ +_plotdata); + } + public function current() { + return current($this->_plotdata); + } + public function key() { + return key($this->_plotdata); + } + public function next() { + return next($this->_plotdata); + } + public function rewind() { + reset($this->_plotdata); + } + public function valid() { + return key($this->_plotdata) ? TRUE : FALSE; + } + + public function __call($name,$args) { + switch ($name) { + case 'title': $this->_title = array_shift($args); + break; + default: + throw new Kohana_Exception('Unknown method :name',array(':name'=>$name)); + } + + return $this; + } + + /** + * Render the URL that generates the graph + */ + final public function __toString() { + try { + return (string)$this->render(); + } catch (Exception $e) { + echo Debug::vars($e); + } + } + + /** + * Pick the driver that will render the graph + * @param $class The child class to invoke + */ + final public static function factory($class) { + $c = sprintf('%s_%s',get_called_class(),$class); + + if (! class_exists($c)) + throw new Kohana_Exception('Unknown Google Chart Type :class',array(':class'=>$class)); + else + return new $c(); + } + + // Our child class should define how to render as a string + abstract public function render(); + + /** + * Record one series of data + * @param $axis Axis used and legend title, eg: (yr->"Right Y",yl->"Left Y") + * @param $data Data for Axis in the format ("x label"=>value); + * + * Example: + * $this->data('yl'=>'Base Down Peak',array('11-12'=>1,'11-11'=>2)); + */ + public function data(array $axis,array $data) { + // Some sanity checking + if (count($axis) != 1) + throw new Kohana_Exception('We can only take 1 series at time.'); + + // This should only iterate once + foreach ($axis as $key => $l) { + if (! in_array($key,array('yr','yl'))) + throw new Kohaan_Exception('Unknown AXIS :axis',array(':axis'=>$key)); + + $this->_axis[$l] = $key; + $this->_data[$l] = $data[$l]; + + // Upate our plot data + foreach ($data[$l] as $k=>$v) + $this->_plotdata[$k][$l] = $v; + + ksort($this->_plotdata); + + $this->_max[$l] = max($data[$l]); + } + + return $this; + } + + /** + * Return the colors that will be used for this series + */ + protected function seriescolors() { + return array_slice($this->series_colors,0,count($this->_axis)); + } + + /** + * Render the chart data in a table format + */ + public function table($vertical=TRUE,$class=array()) { + if (! $this->_data) + return sprintf('
%s
',_('No Data')); + + $output = sprintf('', + isset($class['table']) ? $class['table'] : 'class="google-data-table"'); + + if ($vertical) { + $output .= ''; + $output .= ''; + foreach ($this->_axis as $l => $axis) + $output .= sprintf('',$l); + + $output .= ''; + + foreach ($this as $k => $details) { + $output .= ''; + $output .= sprintf('',$k); + foreach ($this->_axis as $l => $axis) + $output .= sprintf('',$details[$l]); + $output .= ''; + } + + // Horizontal table + } else { + $output .= ''; + $output .= ''; + foreach ($this as $k => $details) + $output .= sprintf('',$k); + $output .= ''; + + foreach ($this->_axis as $l => $axis) { + $output .= ''; + + $output .= sprintf('',$l); + + foreach ($this as $k => $v) + $output .= sprintf('',$v[$l]); + + $output .= ''; + } + } + + $output .= '
 %s
%s%s
 %s
%s%s
'; + + return $output; + } +} +?> diff --git a/modules/gchart/classes/GoogleChart/Legacy.php b/modules/gchart/classes/GoogleChart/Legacy.php new file mode 100644 index 00000000..060e4e5d --- /dev/null +++ b/modules/gchart/classes/GoogleChart/Legacy.php @@ -0,0 +1,219 @@ + 'lc', +// 'sparkline' => 'ls', +// 'line_xy' => 'lxy', + // Bar +// 'horizontal_bar' => 'bhs', + 'vertical_bar' => 'bvs', +// 'horizontal_bar_grp' => 'bhg', +// 'vertical_bar_grp' => 'bvg', + // Pie +// 'pie' => 'p', +// 'pie_3d' => 'p3', +// 'pie_concentric' => 'pc', + // Venn +// 'venn' => 'v', + // Scatter +// 'scatter' => 's', + // Radar +// 'radar' => 'r', +// 'radar_fill' => 'rs', + // Maps +// 'map' => 't', + // Google-o-meter +// 'google_o_meter' => 'gom', + // QR +// 'qr' => 'qr', + ); + + /** + * Set the type of the chart + * @param $type Chart type as per $this->cht + */ + public function type($type) { + if (empty($this->cht[$type])) + throw new Kohana_Exception('Unknown chart type :type for :class',array(':type'=>$type,':class'=>get_class($this))); + + $this->_type = $this->cht[$type]; + + return $this; + } + + /** + * Count how many metrics are being graphed per side + * @param $side Side YL (left) OR YR (right) + */ + private function axiscount($side) { + $i = 0; + + foreach ($this->_axis as $l => $axis) + if ($axis == $side) + $i++; + + return $i; + } + + /** + * Calculate our maximum for each side of the chart + */ + private function maxes() { + $return = array(); + + foreach ($this->_axis as $l => $axis) { + if (! isset($return[$axis])) + $return[$axis] = 0; + + $return[$axis] += $this->_max[$l]*1.1; // @todo This scaleup should be configurable + } + + return $return; + } + + /** CHART FIELDS **/ + + private function chd() { + $return = array(); + $maxes = $this->maxes(); + + // Perform our encoding + foreach ($this->_axis as $l => $axis) + array_push($return,$this->encode($this->_data[$l],$maxes[$axis])); + + $prefix = (count($maxes) > 1) ? sprintf('%s:',$this->axiscount('yl')) : ':'; + + // If encoding is text, we need to separate the series with a | + return ($this->_encodetype == 't') ? $prefix.implode('|',$return) : $prefix.implode(',',$return); + } + + private function chm() { + $return = array(); + $sc = $this->seriescolors(); + $i = 0; + + foreach ($this->_axis as $l => $axis) { + if ($axis == 'yr') + array_push($return,sprintf('%s,%s,%s,%s,%s,%s','D',$sc[$i],$i,0,2,2));// @todo 'D,0,2,2' May need to be configurable + + $i++; + } + + return count($return) ? implode('|',$return) : ''; + } + + private function chxl() { + $return = array(); + + // @todo This should be performed better - it may be a wrong assumption that all keys in the series have data. + foreach ($this->_data as $series => $data) + // @todo Why the 0:? + return '0:|'.implode('|',array_keys($data)); + } + + private function chxr() { + $return = array(); + $i = 1; + + foreach ($this->maxes() as $key => $value) + array_push($return,sprintf('%s,0,%s,0',$i++,$value)); + + return implode('|',$return); + } + + /** + * Return URL that renders the chart + */ + public function render() { + return sprintf('%s',$this->_url,http_build_query($this->build()),_('Google Chart')); + } + + /** + * Build the chart + */ + private function build() { + if ($this->_data ) { + return array( + 'chf'=>'bg,s,FFFFFF00', + 'cht'=>$this->_type, + 'chs'=>$this->_size, + 'chtt'=>$this->_title, + 'chbh'=>'a', // @todo This might need to be calculated, valid options (a,r); + 'chg'=>'7.7,12.5,1,5', // @todo This should be calculated + 'chco'=>implode(',',$this->seriescolors()), + 'chdl'=>implode('|',array_keys($this->_axis)), + 'chd'=>$this->_encodetype.$this->chd(), + 'chm'=>$this->chm(), + 'chxt'=>'x,y,r', // @todo configurable? + 'chxl'=>$this->chxl(), + 'chxr'=>$this->chxr(), + ); + + } else + return array(); + } + + /** + * Encode the series data + * @param $data String of data to encode + * @param $max The maximum to scale to + */ + private function encode($data,$max=NULL) { + $table = array(); + $table['simple'] = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + $table['extend'] = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.'; + + $size = array(); + $size['simple'] = strlen($table['simple']); + $size['extend'] = strlen($table['extend']); + + if (is_null($max) OR $max == 0) + $max = max($data) > 0 ? max($data) : 1; + + $encode = ''; + + switch ($this->_encodetype) { + case 't' : + return join(',',$data); + + case 's' : + foreach ($data as $v) + $encode .= ($v > -1) ? substr($table['simple'],($size['simple']-1)*($v/$max),1) : '_'; + + break; + + case 'e' : + foreach ($data as $v) { + # Convert to a 0-4095 data range + $y = 4095*$v/$max; + $first = substr($table['extend'],floor($y/$size['extend']),1); + $second = substr($table['extend'],$y%$size['extend'],1); + $encode .= "$first$second"; + } + + break; + } + + return $encode; + } +} +?> diff --git a/modules/gchart/classes/googlechart.php b/modules/gchart/classes/googlechart.php deleted file mode 100644 index 95676b12..00000000 --- a/modules/gchart/classes/googlechart.php +++ /dev/null @@ -1,423 +0,0 @@ -plotdata); - } - public function current() { - return current($this->plotdata); - } - public function key() { - return key($this->plotdata); - } - public function next() { - return next($this->plotdata); - } - public function valid() { - return key($this->plotdata) ? TRUE : FALSE; - } - public function count() { - return count($this->plotdata); - } - - // Chart Types - private $cht = array( - // Line -// 'line' => 'lc', -// 'sparkline' => 'ls', -// 'line_xy' => 'lxy', - // Bar -// 'horizontal_bar' => 'bhs', - 'vertical_bar' => 'bvs', -// 'horizontal_bar_grp' => 'bhg', -// 'vertical_bar_grp' => 'bvg', - // Pie -// 'pie' => 'p', -// 'pie_3d' => 'p3', -// 'pie_concentric' => 'pc', - // Venn -// 'venn' => 'v', - // Scatter -// 'scatter' => 's', - // Radar -// 'radar' => 'r', -// 'radar_fill' => 'rs', - // Maps -// 'map' => 't', - // Google-o-meter -// 'google_o_meter' => 'gom', - // QR -// 'qr' => 'qr', - ); - - public function __construct($type) { - if (empty($this->cht[$type])) - throw new Kohana_Exception('Unknown chart type :type for :class',array(':type'=>$type,':class'=>get_class($this))); - - $this->chart_type = $this->cht[$type]; - } - - public function __set($key,$value) { - switch ($key) { - case 'div': - $this->div_mode = $value; - break; - - case 'encode': - // Encoding options are t=none,s=simple,e=extend - if (! in_array($value,array('t','s','e'))) - throw new Kohana_Exception('Unknown encoding type :type',array(':type'=>$value)); - - $this->data_encode = $value; - break; - - case 'title': - $this->chart_title = $value; - break; - - default: - throw new Kohana_Exception('Unknown variable :key (:value) for :class',array(':key'=>$key,':value'=>$value,':class'=>get_class($this))); - } - } - - public function __toString() { - try { - return $this->render(); - } - catch (Exception $e) { - echo Debug::vars($e); - } - } - - /** - * Return an instance of this class - * - * @return GoogleChart - */ - public static function factory($type) { - return new GoogleChart($type); - } - - public function series($data) { - // Quick Sanity check that we have the right indexes - foreach (array('data','axis') as $k) - if (! isset($data[$k])) - throw new Kohana_Exception('Missing key :key',array(':key'=>$k)); - - // Quick check that we have the right types - if (! in_array($data['axis'],array('x','r'))) - throw new Kohana_Exception('Unknown data type :type',array(':type'=>$data['axis'])); - - if (is_array($data['data'])) { - foreach ($data['data'] as $title => $values) { - $this->numseries++; - - $this->chartdata['legend'][$this->numseries] = $title; - $this->chartdata['axis'][$data['axis']][] = $this->numseries; - - if (is_array($values)) - foreach ($values as $k => $v) - $this->plotdata[$k][$data['axis']][$this->numseries] = $v; - else - throw new Kohana_Exception('Series data needs to be an array'); - } - - } else { - throw new Kohana_Exception('Series data needs to be an array'); - } - } - - private function seriescolors() { - $return = array(); - - $i = 0; - for ($j=0;$j<$this->numseries;$j++) { - array_push($return,$this->series_colors[$i++]); - - // Reset $i if we exceed our available colors - if ($i > count($this->series_colors)) - $i = 0; - } - - return $return; - } - - public function series_colors() { - return implode(',',$this->seriescolors()); - } - - public function series_chm() { - if (! isset($this->chartdata['axis']['r'])) - return ''; - - $return = array(); - $c = $this->seriescolors(); - foreach ($this->chartdata['axis']['r'] as $v) - array_push($return,sprintf('%s,%s,%s,%s,%s,%s','D',$c[$v-1],$v-1,0,2,2));// @todo 'D,0,2,2' May need to be configurable - - return implode('|',$return); - } - - public function series_x_labels() { - // @todo Why the 0:? - return '0:|'.implode('|',array_keys($this->plotdata)); - } - - public function series_scaling() { - $return = array(); - - foreach ($this->chartdata['max'] as $k => $v) - array_push($return,sprintf('%s,%s',empty($this->chartdata['min']) ? 0 : $this->chartdata['min'],$v)); - - return implode(',',$return); - } - - public function series_scale() { - $return = array(); - - $i = 1; - // @todo need to add min values - foreach ($this->chartdata['max'] as $k => $v) - array_push($return,sprintf('%s,0,%s,0',$i++,$v)); - - return implode('|',$return); - } - - public function series_legend() { - return implode('|',$this->chartdata['legend']); - } - - public function series_data() { - $return = $sreturn = $invs = array(); - - $sd = $max = array(); - foreach ($this->plotdata as $label => $seriesdata) - foreach ($seriesdata as $type => $data) { - foreach ($data as $key => $value) { - $sd[$key][$label] = $value; - $max[$key] = $this->chartdata['max'][$type]; - $invs[$type][$key] = TRUE; - } - } - - foreach ($sd as $k => $v) - array_push($sreturn,$this->encode($v,$max[$k])); - - // @todo This might need some more work, when used with different graph types. - if (count($invs) > 1) - $prefix = sprintf('%s:',count($invs['x'])); - else - $prefix = ':'; - - // If encoding is text, we need to separate the series with a | - if ($this->data_encode == 't') - return $prefix.implode('|',$sreturn); - else - return $prefix.implode(',',$sreturn); - } - - private function render() { - $output = ''; - - // Testing - if ($this->div_mode) { - $output .= '
GoogleChart
'; - $output .= '
'; - } - - // Render - $output .= sprintf('%s',$this->url,http_build_query($this->build()),_('Traffic Summary')); -// $output .= Debug::vars($this->build()); -// $output .= Debug::vars($this->chartdata); -// $output .= Debug::vars($this->plotdata); - - // Toggle the display of the chart. - // @todo This JS should be placed elsewhere for HTML validation - if ($this->div_mode) { - $output .= '
'; - $output .= ''; - } - - return $output; - } - - public function html_table($vertical=TRUE,$class=array()) { - if (! count($this)) - return sprintf('
%s
',_('No Data')); - - $output = sprintf('', - isset($class['table']) ? $class['table'] : 'class="google-data-table"'); - - if ($vertical) { - $output .= ''; - $output .= ''; - foreach ($this->chartdata['axis'] as $axis => $adetails) - foreach ($adetails as $k) - $output .= sprintf('',$this->chartdata['legend'][$k]); - $output .= ''; - - foreach ($this as $k => $v) { - $output .= ''; - $output .= sprintf('',$k); - foreach ($this->chartdata['axis'] as $axis => $adetails) - foreach ($adetails as $k) - $output .= sprintf('',$v[$axis][$k]); - $output .= ''; - } - - // Horizontal table - } else { - $output .= ''; - $output .= ''; - foreach ($this as $k => $v) - $output .= sprintf('',$k); - $output .= ''; - - foreach ($this->chartdata['axis'] as $axis => $adetails) - foreach ($adetails as $id) { - $output .= ''; - - $output .= sprintf('',$this->chartdata['legend'][$id]); - - foreach ($this as $k => $v) - $output .= sprintf('',$v[$axis][$id]); - - $output .= ''; - } - } - - $output .= '
 %s
%s%s
 %s
%s%s
'; - - return $output; - } - - /** - * Some pre-render processing - */ - private function process() { - $max = array(); - - // Work out our maximum number for each series. - foreach ($this->plotdata as $label => $seriesdata) { - - foreach ($seriesdata as $type => $data) { - $c = 0; - foreach ($data as $value) - $c += $value; - - // Scale up our max, so we get some extra space at the top of our chart. - // @todo This should be configurable. - $c *= 1.1; - - if (! isset($this->chartdata['max'][$type])) - $this->chartdata['max'][$type] = $c; - else - $this->chartdata['max'][$type] = ($c > $this->chartdata['max'][$type]) ? $c : $this->chartdata['max'][$type]; - } - } - } - - /** - * Build the chart - */ - private function build() { - if ($this->plotdata) { - $this->process(); - - return array( - 'chf'=>'bg,s,FFFFFF00', - 'cht'=>$this->chart_type, - 'chs'=>$this->chart_size, - 'chtt'=>$this->chart_title, - 'chbh'=>'a', // @todo This might need to be calculated, valid options (a,r); - 'chg'=>'7.7,12.5,1,5', // @todo This should be calculated - 'chco'=>$this->series_colors(), - 'chdl'=>$this->series_legend(), - 'chd'=>$this->data_encode.$this->series_data(), -// 'chds'=>$this->series_scaling(), - 'chm'=>$this->series_chm(), - 'chxt'=>'x,y,r', // @todo configurable? - 'chxl'=>$this->series_x_labels(), - 'chxr'=>$this->series_scale(), - ); - - } else - return array(); - } - - /** - * Encode the series data - */ - private function encode($data,$max=NULL) { - $table = array(); - $table['simple'] = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; - $table['extend'] = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.'; - - $size = array(); - $size['simple'] = strlen($table['simple']); - $size['extend'] = strlen($table['extend']); - - if (is_null($max) OR $max == 0) - $max = max($data) > 0 ? max($data) : 1; - - $encode = ''; - - switch ($this->data_encode) { - case 't' : - return join(',',$data); - - case 's' : - foreach ($data as $v) - if ($v > -1) - $encode .= substr($table['simple'],($size['simple']-1)*($v/$max),1); - else - $encode .= '_'; - - break; - - case 'e' : - foreach ($data as $v) { - # Convert to a 0-4095 data range - $y = 4095*$v/$max; - $first = substr($table['extend'],floor($y/$size['extend']),1); - $second = substr($table['extend'],$y%$size['extend'],1); - $encode .= "$first$second"; - } - - break; - } - - return $encode; - } -} -?> diff --git a/modules/host/classes/model/host/server.php b/modules/host/classes/model/host/server.php index ab357a04..034b2055 100644 --- a/modules/host/classes/model/host/server.php +++ b/modules/host/classes/model/host/server.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_Host_Server extends ORMOSB { +class Model_Host_Server extends ORM_OSB { // Host Server doesnt use the update column protected $_updated_column = FALSE; diff --git a/modules/host/classes/model/host/server/affiliate.php b/modules/host/classes/model/host/server/affiliate.php index ba9c66ca..63297ca4 100644 --- a/modules/host/classes/model/host/server/affiliate.php +++ b/modules/host/classes/model/host/server/affiliate.php @@ -10,6 +10,6 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_Host_Server_Affiliate extends ORMOSB { +class Model_Host_Server_Affiliate extends ORM_OSB { } ?> diff --git a/modules/invoice/classes/model/invoice.php b/modules/invoice/classes/model/invoice.php index 9e1e7063..984c441e 100644 --- a/modules/invoice/classes/model/invoice.php +++ b/modules/invoice/classes/model/invoice.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_Invoice extends ORMOSB { +class Model_Invoice extends ORM_OSB { protected $_belongs_to = array( 'account'=>array() ); diff --git a/modules/invoice/classes/model/invoice/item.php b/modules/invoice/classes/model/invoice/item.php index da45e246..cfbfbc81 100644 --- a/modules/invoice/classes/model/invoice/item.php +++ b/modules/invoice/classes/model/invoice/item.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_Invoice_Item extends ORMOSB { +class Model_Invoice_Item extends ORM_OSB { protected $_updated_column = FALSE; // @todo No update columns // Relationships diff --git a/modules/payment/classes/model/payment.php b/modules/payment/classes/model/payment.php index 219bc7d2..0f79e54b 100644 --- a/modules/payment/classes/model/payment.php +++ b/modules/payment/classes/model/payment.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_Payment extends ORMOSB { +class Model_Payment extends ORM_OSB { // Relationships protected $_has_many = array( 'payment_item'=>array('far_key'=>'id'), diff --git a/modules/payment/classes/model/payment/item.php b/modules/payment/classes/model/payment/item.php index 7c653037..781786b0 100644 --- a/modules/payment/classes/model/payment/item.php +++ b/modules/payment/classes/model/payment/item.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_Payment_Item extends ORMOSB { +class Model_Payment_Item extends ORM_OSB { protected $_belongs_to = array('payment'=>array(),'invoice'=>array()); } ?> diff --git a/modules/product/classes/model/product.php b/modules/product/classes/model/product.php index 19959f4f..b11f654e 100644 --- a/modules/product/classes/model/product.php +++ b/modules/product/classes/model/product.php @@ -13,7 +13,7 @@ * Column Definitions: * + price_type: 0=One Time, 1=Recurring, 2=Trial */ -class Model_Product extends ORMOSB { +class Model_Product extends ORM_OSB { // @todo this doesnt have our site_id when getting the translation protected $_has_many = array( 'product_translate'=>array('far_key'=>'id'), diff --git a/modules/product/classes/model/product/category.php b/modules/product/classes/model/product/category.php index 72b2c77b..b266b426 100644 --- a/modules/product/classes/model/product/category.php +++ b/modules/product/classes/model/product/category.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_Product_Category extends ORMOSB { +class Model_Product_Category extends ORM_OSB { protected $_table_name = 'product_cat'; protected $_has_many = array( diff --git a/modules/product/classes/model/product/category/translate.php b/modules/product/classes/model/product/category/translate.php index d68324bb..e33eca8c 100644 --- a/modules/product/classes/model/product/category/translate.php +++ b/modules/product/classes/model/product/category/translate.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_Product_Category_Translate extends ORMOSB { +class Model_Product_Category_Translate extends ORM_OSB { protected $_table_name = 'product_cat_translate'; protected $_belongs_to = array( diff --git a/modules/product/classes/model/product/plugin.php b/modules/product/classes/model/product/plugin.php index d341984f..0edd7a6e 100644 --- a/modules/product/classes/model/product/plugin.php +++ b/modules/product/classes/model/product/plugin.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -abstract class Model_Product_Plugin extends ORMOSB { +abstract class Model_Product_Plugin extends ORM_OSB { // Reset any sorting that may be defined in our parent protected $_sorting = array(); diff --git a/modules/product/classes/model/product/translate.php b/modules/product/classes/model/product/translate.php index c5451349..1c7344b3 100644 --- a/modules/product/classes/model/product/translate.php +++ b/modules/product/classes/model/product/translate.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_Product_Translate extends ORMOSB { +class Model_Product_Translate extends ORM_OSB { protected $_updated_column = FALSE; protected $_belongs_to = array( diff --git a/modules/product/views/product/admin/update.php b/modules/product/views/product/admin/update.php index be0900d9..c134c0aa 100644 --- a/modules/product/views/product/admin/update.php +++ b/modules/product/views/product/admin/update.php @@ -48,7 +48,7 @@ Product Descriptions - +   diff --git a/modules/service/classes/controller/admin/service.php b/modules/service/classes/controller/admin/service.php index 9c79d8c5..6f8e9cd3 100644 --- a/modules/service/classes/controller/admin/service.php +++ b/modules/service/classes/controller/admin/service.php @@ -179,12 +179,19 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin { $svs = ORM::factory('service')->list_bylistgroup('ADSL'); $data = $this->consoltraffic($svs,time()); - $google = GoogleChart::factory('vertical_bar'); - $google->title = sprintf('ADSL traffic as at %s',date('Y-m-d',strtotime('yesterday'))); - $google->series(array('title'=>array_keys($data['data']),'axis'=>'x','data'=>$data['data'])); - $google->series(array('title'=>'Services','axis'=>'r','data'=>array('Services'=>$data['svs']))); + $google = GoogleChart::factory('Legacy') + ->type('vertical_bar') + ->title(sprintf('ADSL traffic as at %s',date('Y-m-d',strtotime('yesterday')))); - Block::add(array('body'=>$google)); + foreach ($data['data'] as $key => $values) + $google->data(array('yl'=>$key),array($key=>$values)); + + $google->data(array('yr'=>'services'),array('services'=>$data['svs'])); + + Block::add(array('body'=>(string)$google)); + Block::add(array('body'=>$google->table(FALSE,array( + 'table'=>'style="border: 1px solid #bebcb7; padding: 5px 5px; background: none repeat scroll 0% 0% #f8f7f5; font-size: 70%;"', + )))); Block::add(array( 'title'=>_('ADSL Services'), @@ -243,12 +250,16 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin { $svs = ORM::factory('service')->list_bylistgroup('HSPA'); $data = $this->consoltraffic($svs,time()); - $google = GoogleChart::factory('vertical_bar'); - $google->title = sprintf('HSPA traffic as at %s',date('Y-m-d',strtotime('yesterday'))); - $google->series(array('title'=>array_keys($data['data']),'axis'=>'x','data'=>$data['data'])); - $google->series(array('title'=>'Services','axis'=>'r','data'=>array('Services'=>$data['svs']))); + $google = GoogleChart::factory('Legacy') + ->type('vertical_bar') + ->title(sprintf('HSPA traffic as at %s',date('Y-m-d',strtotime('yesterday')))); - Block::add(array('body'=>$google)); + foreach ($data['data'] as $key => $values) + $google->data(array('yl'=>$key),array($key=>$values)); + + $google->data(array('yr'=>'services'),array('services'=>$data['svs'])); + + Block::add(array('body'=>(string)$google)); Block::add(array( 'title'=>_('HSPA Services'), diff --git a/modules/service/classes/controller/affiliate/service.php b/modules/service/classes/controller/affiliate/service.php index 2d19717f..c3232ce6 100644 --- a/modules/service/classes/controller/affiliate/service.php +++ b/modules/service/classes/controller/affiliate/service.php @@ -74,7 +74,7 @@ class Controller_Affiliate_Service extends Controller_TemplateDefault_Affiliate 'status'=>array('label'=>'Active'), 'account->accnum()'=>array('label'=>'Cust ID'), 'account->name()'=>array('label'=>'Customer'), - 'date_next_invoice'=>array('label'=>'Next Invoice'), + 'date_next_invoice'=>array('label'=>'Next Invoice'), 'account->invoices_due_total(NULL,TRUE)'=>array('label'=>'Due Invoices'), ), array( @@ -159,12 +159,16 @@ class Controller_Affiliate_Service extends Controller_TemplateDefault_Affiliate $svs = $this->filter(ORM::factory('service')->list_bylistgroup('ADSL'),$this->ao->affiliate->id,'name()'); $data = $this->consoltraffic($svs,time()); - $google = GoogleChart::factory('vertical_bar'); - $google->title = sprintf('ADSL traffic as at %s',date('Y-m-d',strtotime('yesterday'))); - $google->series(array('title'=>array_keys($data['data']),'axis'=>'x','data'=>$data['data'])); - $google->series(array('title'=>'Services','axis'=>'r','data'=>array('Services'=>$data['svs']))); + $google = GoogleChart::factory('Legacy') + ->type('vertical_bar') + ->title(sprintf('ADSL traffic as at %s',date('Y-m-d',strtotime('yesterday')))); - Block::add(array('body'=>$google)); + foreach ($data['data'] as $key => $values) + $google->data(array('yl'=>$key),array($key=>$values)); + + $google->data(array('yr'=>'services'),array('services'=>$data['svs'])); + + Block::add(array('body'=>(string)$google)); Block::add(array( 'title'=>_('ADSL Services'), @@ -196,12 +200,16 @@ class Controller_Affiliate_Service extends Controller_TemplateDefault_Affiliate $svs = $this->filter(ORM::factory('service')->list_bylistgroup('HSPA'),$this->ao->affiliate->id,'name()'); $data = $this->consoltraffic($svs,time()); - $google = GoogleChart::factory('vertical_bar'); - $google->title = sprintf('HSPA traffic as at %s',date('Y-m-d',strtotime('yesterday'))); - $google->series(array('title'=>array_keys($data['data']),'axis'=>'x','data'=>$data['data'])); - $google->series(array('title'=>'Services','axis'=>'r','data'=>array('Services'=>$data['svs']))); + $google = GoogleChart::factory('Legacy') + ->type('vertical_bar') + ->title(sprintf('HSPA traffic as at %s',date('Y-m-d',strtotime('yesterday')))); - Block::add(array('body'=>$google)); + foreach ($data['data'] as $key => $values) + $google->data(array('yl'=>$key),array($key=>$values)); + + $google->data(array('yr'=>'services'),array('services'=>$data['svs'])); + + Block::add(array('body'=>(string)$google)); Block::add(array( 'title'=>_('HSPA Services'), diff --git a/modules/service/classes/model/service.php b/modules/service/classes/model/service.php index d92255d5..0579d8fd 100644 --- a/modules/service/classes/model/service.php +++ b/modules/service/classes/model/service.php @@ -13,7 +13,7 @@ * Fields: * + queue: PROVISION (to be provisioned) */ -class Model_Service extends ORMOSB { +class Model_Service extends ORM_OSB { // Relationships protected $_has_one = array( 'affiliate'=>array('far_key'=>'affiliate_id','foreign_key'=>'id'), diff --git a/modules/service/classes/model/service/billing.php b/modules/service/classes/model/service/billing.php index 05f1c296..d5f2c513 100644 --- a/modules/service/classes/model/service/billing.php +++ b/modules/service/classes/model/service/billing.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_Service_Billing extends ORMOSB { +class Model_Service_Billing extends ORM_OSB { protected $_table_name = 'account_billing'; // Relationships diff --git a/modules/service/classes/model/service/plugin.php b/modules/service/classes/model/service/plugin.php index 84917420..74cd57b7 100644 --- a/modules/service/classes/model/service/plugin.php +++ b/modules/service/classes/model/service/plugin.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -abstract class Model_Service_Plugin extends ORMOSB { +abstract class Model_Service_Plugin extends ORM_OSB { // Reset any sorting that may be defined in our parent protected $_sorting = array(); diff --git a/modules/ssl/classes/model/ssl.php b/modules/ssl/classes/model/ssl.php index 19fe9a75..a6bef12e 100644 --- a/modules/ssl/classes/model/ssl.php +++ b/modules/ssl/classes/model/ssl.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_SSL extends ORMOSB { +class Model_SSL extends ORM_OSB { protected $_updated_column = FALSE; } ?> diff --git a/modules/ssl/classes/model/ssl/ca.php b/modules/ssl/classes/model/ssl/ca.php index 6ef48885..be603b13 100644 --- a/modules/ssl/classes/model/ssl/ca.php +++ b/modules/ssl/classes/model/ssl/ca.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_SSL_CA extends ORMOSB { +class Model_SSL_CA extends ORM_OSB { protected $_updated_column = FALSE; // Relationships diff --git a/modules/ssl/classes/ssl.php b/modules/ssl/classes/ssl.php index 7a9345f9..ca4c44df 100644 --- a/modules/ssl/classes/ssl.php +++ b/modules/ssl/classes/ssl.php @@ -35,6 +35,28 @@ class SSL { return _('Unknown'); } + public static function aki($cert,$key=NULL) { + $k = array(); + foreach (explode("\n",preg_replace("/\n$/",'',static::extensions($cert,'authorityKeyIdentifier'))) as $x) { + list($a,$b) = explode(":",$x,2); + $k[strtolower($a)] = $b; + } + + return is_null($key) ? $k : $k[$key]; + } + + public static function aki_keyid($key) { + return static::aki($key,'keyid'); + } + + public static function aki_dirname($key) { + return static::aki($key,'dirname'); + } + + public static function aki_serial($key) { + return static::aki($key,'serial'); + } + public static function dn($cert) { if (! $cert) return ''; @@ -84,12 +106,17 @@ class SSL { return $format ? Config::date($k) : $k; } + public static function extensions($cert,$key=NULL) { + $k = static::details($cert,'extensions'); + return is_null($key) ? $k : $k[$key]; + } + public static function hash($key) { return static::details($key,'hash'); } public static function serial($key) { - return static::details($key,'serialNumber'); + return static::dec_to_hex(static::details($key,'serialNumber')); } public static function subject($key) { @@ -97,6 +124,10 @@ class SSL { return $k['CN']; } + public static function ski($key) { + return static::extensions($key,'subjectKeyIdentifier'); + } + public static function version($key) { return static::details($key,'version'); } @@ -106,5 +137,25 @@ class SSL { return $c['CN']; } + + private static function dec_to_hex($number) { + $hex = array(); + + if ($number == 0) + return '00'; + + while ($number > 0) { + if ($number == 0) { + array_push($hex, '0'); + + } else { + $x = (int) ($number/16); + array_push($hex,strtoupper(dechex((int)($number-($x*16))))); + $number = $x; + } + } + + return preg_replace('/^:/','',preg_replace('/(..)/',":$1",implode(array_reverse($hex)))); + } } ?> diff --git a/modules/ssl/views/ssl/admin/add_view.php b/modules/ssl/views/ssl/admin/add_view.php index a0591254..b4d980ed 100644 --- a/modules/ssl/views/ssl/admin/add_view.php +++ b/modules/ssl/views/ssl/admin/add_view.php @@ -1,11 +1,19 @@ - + + + + + - + + + + + @@ -15,10 +23,6 @@ - - - - diff --git a/modules/static_page/classes/model/staticpage.php b/modules/static_page/classes/model/staticpage.php index 6d14ecb7..bcd8ed16 100644 --- a/modules/static_page/classes/model/staticpage.php +++ b/modules/static_page/classes/model/staticpage.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_StaticPage extends ORMOSB { +class Model_StaticPage extends ORM_OSB { protected $_table_name = 'static_page'; protected $_sorting = array( diff --git a/modules/static_page/classes/model/staticpage/category.php b/modules/static_page/classes/model/staticpage/category.php index 7ce2169f..74ef8aec 100644 --- a/modules/static_page/classes/model/staticpage/category.php +++ b/modules/static_page/classes/model/staticpage/category.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_StaticPage_Category extends ORMOSB { +class Model_StaticPage_Category extends ORM_OSB { protected $_table_name = 'static_page_category'; protected $_sorting = array( diff --git a/modules/static_page/classes/model/staticpage/translate.php b/modules/static_page/classes/model/staticpage/translate.php index 7a64f264..ecb7a5a3 100644 --- a/modules/static_page/classes/model/staticpage/translate.php +++ b/modules/static_page/classes/model/staticpage/translate.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_StaticPage_Translate extends ORMOSB { +class Model_StaticPage_Translate extends ORM_OSB { protected $_table_name = 'static_page_translate'; protected $_belongs_to = array( diff --git a/modules/task/classes/model/task.php b/modules/task/classes/model/task.php index bc6ccdd9..62453833 100644 --- a/modules/task/classes/model/task.php +++ b/modules/task/classes/model/task.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_Task extends ORMOSB { +class Model_Task extends ORM_OSB { protected $_display_filters = array( 'date_run'=>array( array('Config::datetime',array(':value')), diff --git a/modules/task/classes/model/task/log.php b/modules/task/classes/model/task/log.php index b126b658..427bf562 100644 --- a/modules/task/classes/model/task/log.php +++ b/modules/task/classes/model/task/log.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_Task_Log extends ORMOSB { +class Model_Task_Log extends ORM_OSB { protected $_belongs_to = array( 'task'=>array(), ); diff --git a/modules/tax/classes/model/invoice/item/tax.php b/modules/tax/classes/model/invoice/item/tax.php index 4db80941..4439e90b 100644 --- a/modules/tax/classes/model/invoice/item/tax.php +++ b/modules/tax/classes/model/invoice/item/tax.php @@ -10,6 +10,6 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_Invoice_Item_Tax extends ORMOSB { +class Model_Invoice_Item_Tax extends ORM_OSB { } ?> diff --git a/modules/tax/classes/model/tax.php b/modules/tax/classes/model/tax.php index 70093d88..0ea3e575 100644 --- a/modules/tax/classes/model/tax.php +++ b/modules/tax/classes/model/tax.php @@ -10,6 +10,6 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_Tax extends ORMOSB { +class Model_Tax extends ORM_OSB { } ?>
Subjectsign_cert); ?>sign_cert),SSL::serial($so->sign_cert)); ?>
Subject Key IDsign_cert); ?>
Issuersign_cert); ?>sign_cert),SSL::aki_serial($so->sign_cert)); ?>
Issuer Key IDsign_cert); ?>
Valid FromValid To sign_cert,TRUE); ?>
Serial Numsign_cert); ?>
Hash sign_cert); ?>