SSL, Google Chart updates, lnAPP improvements

This commit is contained in:
Deon George 2012-12-11 08:48:30 +11:00
parent c4e760fa21
commit 6588de4f7f
67 changed files with 940 additions and 539 deletions

View File

@ -152,7 +152,7 @@ Route::set('default', '(<controller>(/<action>(/<id>)))', 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.');
}

View File

@ -0,0 +1,220 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class extends Kohana's [ORM] class to create defaults for OSB.
*
* @package OSB
* @subpackage Core
* @category ORM
* @author Deon George
* @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
abstract class ORM_OSB extends ORM {
/**
* @var string Database to connect to
*/
protected $_db = 'default';
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();
// 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();
}
}
?>

View File

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

View File

@ -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

View File

@ -1,9 +1,9 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* lnApp Main home page
* OSB Main home page
*
* @package lnApp
* @package OSB
* @subpackage Page/Home
* @category Controllers
* @author Deon George

View File

@ -64,7 +64,6 @@ $(function () {
id = data.rslt.obj.attr(\'id\').substr(a+1);
if (href = $("#N_"+id).attr("href")) {
if (! use_ajax) {
window.location = href;
return;

View File

@ -40,6 +40,9 @@ abstract class lnApp_Script extends HTMLRender {
case 'file':
$foutput .= HTML::script($mediapath->uri(array('file'=>$value['data'])));
break;
case 'src':
$foutput .= HTML::script($value['data']);
break;
case 'stdin':
$soutput .= sprintf("<script type=\"text/javascript\">//<![CDATA[\n%s\n//]]></script>",$value['data']);
break;

View File

@ -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(),
);

View File

@ -1,7 +1,7 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* @package lnApp
* @package OSB
* @subpackage Auth
* @category Models
* @author Deon George

View File

@ -10,7 +10,7 @@
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Model_Country extends ORMOSB {
class Model_Country extends ORM_OSB {
public function currency() {
return ORM::factory('currency')->where('country_id','=',$this->id)->find();
}

View File

@ -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 {
}
?>

View File

@ -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(),

View File

@ -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');
}
?>

View File

@ -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'),

View File

@ -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(),

View File

@ -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(),

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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'
)
),
);
?>

View File

@ -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
);
?>

View File

@ -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(

View File

@ -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'),

View File

@ -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'),

View File

@ -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;

View File

@ -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;

View File

@ -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'),

View File

@ -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(),
);

View File

@ -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(

View File

@ -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(),

View File

@ -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
*/

View File

@ -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')),

View File

@ -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;

View File

@ -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'),
);

View File

@ -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;

View File

@ -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',
);

View File

@ -0,0 +1,176 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides access to Google's Chart API
*
* @package lnApp
* @subpackage GoogleChart
* @category Helper
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
abstract class GoogleChart implements Iterator,Countable {
// Hold the data for our chart
protected $_data = array();
protected $_axis = array();
private $_plotdata = array();
protected $_max = array();
// Chart title
protected $_title = '';
// Default chart size.
protected $_size = '700x200';
// Colors to use for series
private $series_colors = array('AAACCC','E0E0E0','CCC888','EEEBBB','666CCC','888888');
// Implementation Methods
public function count() {
return count($this->_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('<table><tr><td>%s</td></tr></table>',_('No Data'));
$output = sprintf('<table %s>',
isset($class['table']) ? $class['table'] : 'class="google-data-table"');
if ($vertical) {
$output .= '<tr>';
$output .= '<td>&nbsp;</td>';
foreach ($this->_axis as $l => $axis)
$output .= sprintf('<th style="text-align: right;">%s</th>',$l);
$output .= '</tr>';
foreach ($this as $k => $details) {
$output .= '<tr>';
$output .= sprintf('<th style="text-align: right;">%s</th>',$k);
foreach ($this->_axis as $l => $axis)
$output .= sprintf('<td style="text-align: right;">%s</td>',$details[$l]);
$output .= '</tr>';
}
// Horizontal table
} else {
$output .= '<tr>';
$output .= '<td>&nbsp;</td>';
foreach ($this as $k => $details)
$output .= sprintf('<th style="text-align: right;">%s</th>',$k);
$output .= '</tr>';
foreach ($this->_axis as $l => $axis) {
$output .= '<tr>';
$output .= sprintf('<th style="text-align: right;">%s</th>',$l);
foreach ($this as $k => $v)
$output .= sprintf('<td style="text-align: right;">%s</td>',$v[$l]);
$output .= '</tr>';
}
}
$output .= '</table>';
return $output;
}
}
?>

View File

@ -0,0 +1,219 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides access to Google's Chart Legacy API
*
* @package lnApp
* @subpackage GoogleChart
* @category Helper
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class GoogleChart_Legacy extends GoogleChart {
// Chart URL
private $_url = 'http://chart.apis.google.com/chart';
// The type of chart we'll plot
private $_type = 'bvs';
// Data encoding type to use
private $_encodetype = 's';
// 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',
);
/**
* 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('<img src="%s?%s" alt="%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;
}
}
?>

View File

@ -1,423 +0,0 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides access to Google's Chart API
*
* @package lnApp
* @subpackage GoogleChart
* @category Helper
* @author Deon George
* @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class GoogleChart implements Iterator,Countable {
// Chart URL
private $url = 'http://chart.apis.google.com/chart';
// Hold our plot data
private $plotdata = array();
private $chartdata = array();
// Number of Series to plot
private $numseries = 0;
// The type of chart we'll plot
private $chart_type = '';
// Default chart tytle.
private $chart_title = '';
// Default chart size.
private $chart_size = '700x200';
// Colors to use for series
private $series_colors = array('AAACCC','E0E0E0','CCC888','EEEBBB','666CCC','888888');
// Data encoding type to use
private $data_encode = 's';
private $div_mode = FALSE;
// Implementation Methods
public function rewind() {
reset($this->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 .= '<div id="GoogleChart">GoogleChart</div>';
$output .= '<div id="showgc" style="display: inline;">';
}
// Render
$output .= sprintf('<img src="%s?%s" alt="%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 .= '</div>';
$output .= '<script type="text/javascript">$("#GoogleChart").click(function() {$(\'#showgc\').toggle();});</script>';
}
return $output;
}
public function html_table($vertical=TRUE,$class=array()) {
if (! count($this))
return sprintf('<table><tr><td>%s</td></tr></table>',_('No Data'));
$output = sprintf('<table %s>',
isset($class['table']) ? $class['table'] : 'class="google-data-table"');
if ($vertical) {
$output .= '<tr>';
$output .= '<td>&nbsp;</td>';
foreach ($this->chartdata['axis'] as $axis => $adetails)
foreach ($adetails as $k)
$output .= sprintf('<th style="text-align: right;">%s</th>',$this->chartdata['legend'][$k]);
$output .= '</tr>';
foreach ($this as $k => $v) {
$output .= '<tr>';
$output .= sprintf('<th style="text-align: right;">%s</th>',$k);
foreach ($this->chartdata['axis'] as $axis => $adetails)
foreach ($adetails as $k)
$output .= sprintf('<td style="text-align: right;">%s</td>',$v[$axis][$k]);
$output .= '</tr>';
}
// Horizontal table
} else {
$output .= '<tr>';
$output .= '<td>&nbsp;</td>';
foreach ($this as $k => $v)
$output .= sprintf('<th style="text-align: right;">%s</th>',$k);
$output .= '</tr>';
foreach ($this->chartdata['axis'] as $axis => $adetails)
foreach ($adetails as $id) {
$output .= '<tr>';
$output .= sprintf('<th style="text-align: right;">%s</th>',$this->chartdata['legend'][$id]);
foreach ($this as $k => $v)
$output .= sprintf('<td style="text-align: right;">%s</td>',$v[$axis][$id]);
$output .= '</tr>';
}
}
$output .= '</table>';
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;
}
}
?>

View File

@ -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;

View File

@ -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 {
}
?>

View File

@ -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()
);

View File

@ -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

View File

@ -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'),

View File

@ -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());
}
?>

View File

@ -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'),

View File

@ -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(

View File

@ -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(

View File

@ -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();

View File

@ -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(

View File

@ -48,7 +48,7 @@
</tr>
<tr>
<td>Product Descriptions</td>
<td><?php echo Form::select('language_id',ORMOSB::form('language',TRUE)); ?></td>
<td><?php echo Form::select('language_id',ORM_OSB::form('language',TRUE)); ?></td>
</tr>
<tr>
<td>&nbsp;</td>

View File

@ -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'),

View File

@ -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'),

View File

@ -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'),

View File

@ -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

View File

@ -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();

View File

@ -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;
}
?>

View File

@ -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

View File

@ -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))));
}
}
?>

View File

@ -1,11 +1,19 @@
<table border="0">
<tr>
<td>Subject</td>
<td class="data"><?php echo SSL::subject($so->sign_cert); ?></td>
<td class="data"><?php printf('%s (%s)',SSL::subject($so->sign_cert),SSL::serial($so->sign_cert)); ?></td>
</tr>
<tr>
<td>Subject Key ID</td>
<td class="data"><?php echo SSL::ski($so->sign_cert); ?></td>
</tr>
<tr>
<td>Issuer</td>
<td class="data"><?php echo SSL::issuer($so->sign_cert); ?></td>
<td class="data"><?php printf('%s (%s)',SSL::issuer($so->sign_cert),SSL::aki_serial($so->sign_cert)); ?></td>
</tr>
<tr>
<td>Issuer Key ID</td>
<td class="data"><?php echo SSL::aki_keyid($so->sign_cert); ?></td>
</tr>
<tr>
<td>Valid From</td>
@ -15,10 +23,6 @@
<td>Valid To</td>
<td class="data"><?php echo SSL::expire($so->sign_cert,TRUE); ?></td>
</tr>
<tr>
<td>Serial Num</td>
<td class="data"><?php echo SSL::serial($so->sign_cert); ?></td>
</tr>
<tr>
<td>Hash</td>
<td class="data"><?php echo SSL::hash($so->sign_cert); ?></td>

View File

@ -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(

View File

@ -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(

View File

@ -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(

View File

@ -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')),

View File

@ -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(),
);

View File

@ -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 {
}
?>

View File

@ -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 {
}
?>