Initial Membership Database Work

This commit is contained in:
Deon George 2014-07-09 13:04:56 +10:00
parent d4b3b0f9bc
commit febaad9ea6
37 changed files with 1395 additions and 834 deletions

4
.gitmodules vendored
View File

@ -1,6 +1,6 @@
[submodule "includes/kohana"] [submodule "includes/kohana"]
path = includes/kohana path = includes/kohana
url = ssh://deon@l.dlcm.co:222/afs/local/git/lnkohana url = ssh://deon@l.dlcm.co:222/afs/local/git/lnkohana
[submodule "modules/lnApp"] [submodule "modules/lnapp"]
path = modules/lnApp path = modules/lnapp
url = ssh://deon@l.dlcm.co:222/afs/local/git/lnapp url = ssh://deon@l.dlcm.co:222/afs/local/git/lnapp

View File

@ -2,7 +2,7 @@
RewriteEngine On RewriteEngine On
# Installation directory # Installation directory
RewriteBase /aer RewriteBase /ebccc
# Protect hidden files from being viewed # Protect hidden files from being viewed
<Files .*> <Files .*>
@ -19,10 +19,3 @@ RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL # Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT] RewriteRule .* index.php/$0 [PT]
AuthType Basic
AuthName "Restricted !"
# (Following line optional)
AuthBasicProvider file
AuthUserFile /local/WEB/sites/net.leenooks.dev/aer/.htuser
Require valid-user

View File

@ -1,6 +1,9 @@
<?php defined('SYSPATH') or die('No direct script access.'); <?php defined('SYSPATH') or die('No direct script access.');
// -- Environment setup -------------------------------------------------------- // -- Environment setup --------------------------------------------------------
$SERVER_NAMES = array(
'dev.leenooks.vpn',
);
// Load the core Kohana class // Load the core Kohana class
require SYSPATH.'classes/Kohana/Core'.EXT; require SYSPATH.'classes/Kohana/Core'.EXT;
@ -69,6 +72,12 @@ I18n::lang('en-us');
* Note: If you supply an invalid environment name, a PHP warning will be thrown * Note: If you supply an invalid environment name, a PHP warning will be thrown
* saying "Couldn't find constant Kohana::<INVALID_ENV_NAME>" * saying "Couldn't find constant Kohana::<INVALID_ENV_NAME>"
*/ */
/**
* Set the environment status by the domain.
*/
Kohana::$environment = (! isset($_SERVER['SERVER_NAME']) OR in_array($_SERVER['SERVER_NAME'],$SERVER_NAMES)) ? Kohana::PRODUCTION : Kohana::DEVELOPMENT;
if (isset($_SERVER['KOHANA_ENV'])) if (isset($_SERVER['KOHANA_ENV']))
{ {
Kohana::$environment = constant('Kohana::'.strtoupper($_SERVER['KOHANA_ENV'])); Kohana::$environment = constant('Kohana::'.strtoupper($_SERVER['KOHANA_ENV']));
@ -90,9 +99,10 @@ if (isset($_SERVER['KOHANA_ENV']))
* - boolean expose set the X-Powered-By header FALSE * - boolean expose set the X-Powered-By header FALSE
*/ */
Kohana::init(array( Kohana::init(array(
'base_url' => '/aer', 'base_url' => Kohana::$environment === Kohana::PRODUCTION ? '/ebccc' : '/ebccc',
'caching' => TRUE, 'caching' => Kohana::$environment === Kohana::PRODUCTION,
'index_file' => '', 'profile' => Kohana::$environment !== Kohana::PRODUCTION,
'index_file' => FALSE,
)); ));
/** /**
@ -109,10 +119,10 @@ Kohana::$config->attach(new Config_File);
* Enable modules. Modules are referenced by a relative or absolute path. * Enable modules. Modules are referenced by a relative or absolute path.
*/ */
Kohana::modules(array( Kohana::modules(array(
'lnapp' => MODPATH.'lnApp', // lnApp Base Application Tools 'lnapp' => MODPATH.'lnapp', // lnApp Base Application Tools
// 'oauth' => MODPATH.'oauth', // OAuth Module for External Authentication // 'oauth' => MODPATH.'oauth', // OAuth Module for External Authentication
'auth' => SMDPATH.'auth', // Basic authentication 'auth' => SMDPATH.'auth', // Basic authentication
'cache' => SMDPATH.'cache', // Caching with multiple backends // 'cache' => SMDPATH.'cache', // Caching with multiple backends
// 'cron' => SMDPATH.'cron', // Kohana Cron Module // 'cron' => SMDPATH.'cron', // Kohana Cron Module
// 'codebench' => SMDPATH.'codebench', // Benchmarking tool // 'codebench' => SMDPATH.'codebench', // Benchmarking tool
'database' => SMDPATH.'database', // Database access 'database' => SMDPATH.'database', // Database access
@ -122,12 +132,17 @@ Kohana::modules(array(
// 'khemail' => SMDPATH.'khemail', // Email module for Kohana 3 PHP Framework // 'khemail' => SMDPATH.'khemail', // Email module for Kohana 3 PHP Framework
// 'minion' => SMDPATH.'minion', // CLI Tasks // 'minion' => SMDPATH.'minion', // CLI Tasks
'orm' => SMDPATH.'orm', // Object Relationship Mapping 'orm' => SMDPATH.'orm', // Object Relationship Mapping
'pagination' => SMDPATH.'pagination', // Kohana Pagination module for Kohana 3 PHP Framework // 'pagination' => SMDPATH.'pagination', // Kohana Pagination module for Kohana 3 PHP Framework
// 'unittest' => SMDPATH.'unittest', // Unit testing // 'unittest' => SMDPATH.'unittest', // Unit testing
// 'userguide' => SMDPATH.'userguide', // User guide and API documentation // 'userguide' => SMDPATH.'userguide', // User guide and API documentation
'xml' => SMDPATH.'xml', // XML module for Kohana 3 PHP Framework // 'xml' => SMDPATH.'xml', // XML module for Kohana 3 PHP Framework
)); ));
/**
* Load our modules defined in the DB
*/
Kohana::modules(array_merge(Kohana::modules(),Config::modules()));
/** /**
* Enable specalised interfaces * Enable specalised interfaces
*/ */

View File

@ -0,0 +1,229 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* Membership Database Auth driver.
*
* @package Membership Database
* @category Classes
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Auth_MDB extends Auth_ORM {
/**
* We need to override Kohana's __construct(), for tasks, which attempt to open a session
* and probably dont have access to PHP sessions path.
* Tasks dont need sessions anyway?
*/
public function __construct($config = array()) {
// Save the config in the object
$this->_config = $config;
if (PHP_SAPI !== 'cli')
parent::__construct($config);
}
/**
* Get the user that a token applies to
*
* This will check that the token is valid (not expired and for the request)
*
* @param $token The token
* @return Model_Account|NULL The user that the token is valid for.
*/
private function _get_token_user($token) {
// This has been implemented, as we sometimes we seem to come here twice
static $uo = NULL;
if (! is_null($uo))
return $uo;
$mmto = ORM::factory('Module_Method_Token',array('token'=>$token));
// Ignore the token if it doesnt exist.
if ($mmto->loaded()) {
// Check that the token is for this URI
$mo = ORM::factory('Module',array('name'=>Request::current()->controller()));
$mmo = $mo->module_method
->where('name','=',strtolower(Request::current()->directory() ? sprintf('%s:%s',Request::current()->directory(),Request::current()->action()) : Request::current()->action()))
->find();
// Ignore the token if this is not the right method.
if ($mmo->id == $mmto->method_id) {
if (! is_null($mmto->date_expire) AND $mmto->date_expire < time()) {
SystemMessage::add(array(
'title'=>_('Token Not Valid'),
'type'=>'warning',
'body'=>_('Token expired')));
Session::instance()->delete('token');
$mmto->delete();
} elseif (! is_null($mmto->uses) AND $mmto->uses < 1) {
SystemMessage::add(array(
'title'=>_('Token Not Valid'),
'type'=>'warning',
'body'=>_('Token expired')));
Session::instance()->delete('token');
$mmto->delete();
} else {
// If this is a usage count token, reduce the count.
if (! is_null($mmto->uses))
$mmto->uses -= 1;
// Record the date this token was used
$mmto->date_last = time();
$mmto->save();
Session::instance()->set('token',$token);
$uo = ORM::factory('Account',$mmto->account_id);
$uo->log(sprintf('Token %s used for method %s [%s]',$mmto->token,$mmto->module_method->id,Request::current()->param('id')));
}
}
}
return $uo;
}
/**
* Logs a user in.
*
* @param string username
* @param string password
* @param boolean enable autologin
* @return boolean
*/
protected function _login($user,$password,$remember) {
if (! is_object($user)) {
$username = $user;
// Load the user
$user = ORM::factory('Account');
$user->where('username','=',$username)->find();
// If no user loaded, return
if (! $user->loaded())
return FALSE;
}
// Create a hashed password
if (is_string($password))
$password = $this->hash($password);
// If the passwords match, perform a login
if ($user->active AND $user->has_any('group',ORM::factory('Group',array('name'=>'Registered Users'))->list_childgrps(TRUE)) AND $user->password === $password) {
// @todo This is not currently used.
if ($remember === TRUE) {
// Create a new autologin token
$token = ORM::factory('User_Token');
// Set token data
$token->user_id = $user->id;
$token->expires = time() + $this->_config['lifetime'];
$token->save();
// Set the autologin cookie
Cookie::set('authautologin', $token->token, $this->_config['lifetime']);
}
// Record our session ID, we may need to update our DB when we get a new ID
$oldsess = session_id();
// Finish the login
$this->complete_login($user);
// Do we need to update databases with our new sesion ID
$sct = Kohana::$config->load('config')->session_change_trigger;
if (session_id() != $oldsess AND count($sct))
foreach ($sct as $t => $c)
if (Config::module_exist($t))
foreach (ORM::factory(ucwords($t))->where($c,'=',$oldsess)->find_all() as $o)
$o->set('session_id',session_id())
->update();
return TRUE;
}
// Login failed
return FALSE;
}
/**
* Determine if a user is authorised to view an account
*
* @param Model_Account Account Ojbect to validate if the current user has access
* @return boolean TRUE if authorised, FALSE if not.
*/
public function authorised(Model_Account $ao) {
return (($uo = $this->get_user()) AND $uo->loaded() AND ($uo == $ao OR in_array($ao->id,$uo->RTM->customers($uo->RTM))));
}
/**
* Gets the currently logged in user from the session.
* Returns NULL if no user is currently logged in.
*
* @param boolean Check token users too
* @return mixed
*/
public function get_user($default=NULL,$tokenuser=TRUE) {
// If we are a CLI, we are not logged in
if (PHP_SAPI === 'cli')
throw new Kohana_Exception('Calling :method from the CLI is not allowed!',array(':method'=>__METHOD__));
// Get the current user
$uo = parent::get_user($default);
// If we are not logged in, see if there is token for the user
if (is_null($uo) AND $tokenuser AND ($token=Session::instance()->get('token')) OR (! empty($_REQUEST['token']) AND $token=$_REQUEST['token']))
$uo = $this->_get_token_user($token);
return $uo;
}
public function get_groups() {
return is_null($x=$this->get_user()) ? ORM::factory('Group')->where('id','=',0)->find_all() : $x->groups();
}
/**
* OSB authentication is controlled via database queries.
*
* This method can be used to test two situations:
* 1) Is the user logged in? ($role == FALSE)
* 2) Can the user run the current controller->action ($role == TRUE)
*
* @param boolean If authentication should be done for this module:method (ie: controller:action).
* @return boolean
*/
public function logged_in($role=NULL,$debug=NULL) {
$status = FALSE;
// If we are a CLI, we are not logged in
if (PHP_SAPI === 'cli')
return $status;
// Get the user from the session
$uo = $this->get_user();
// If we are not a valid user object, then we are not logged in
if (is_object($uo) AND ($uo instanceof Model_Account) AND $uo->loaded())
if (! empty($role)) {
if (($x = Request::current()->mmo()) instanceof Model)
// If the role has the authorisation to run the method
foreach ($x->group->find_all() as $go)
if ($go->id == 0 OR $uo->has_any('group',$go->list_childgrps(TRUE))) {
$status = TRUE;
break;
}
// There is no role, so the method should be allowed to run as anonymous
} else
$status = TRUE;
return $status;
}
}
?>

View File

@ -0,0 +1,22 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class overrides Kohana's Auth
*
* @package Membership Database
* @category Modifications
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Auth_ORM extends Kohana_Auth_ORM {
// Override Kohana Auth requirement to have a hash_key
public function hash($str) {
switch ($this->_config['hash_method']) {
case '' : return $str;
case 'md5': return md5($str);
default: return hash_hmac($this->_config['hash_method'], $str, $this->_config['hash_key']);
}
}
}
?>

View File

@ -0,0 +1,122 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class is for access company information.
*
* @package Membership Database
* @category Helpers
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Company {
public static $instance = array();
// Our Company Setup object
private $so;
protected function __construct(Model_Setup $so) {
$this->so = $so;
if (! $this->so->loaded())
throw new Kohana_Exception(_('Site [:site] not defined in DB?'),array(':site'=>URL::base('http')));
Kohana::$environment = (int)$this->so->status;
}
public static function instance() {
$x = URL::base('http');
if (! isset(Company::$instance[$x]))
Company::$instance[$x] = new Company(ORM::factory('Setup',array('url'=>$x)));
return Company::$instance[$x];
}
public function admin() {
return $this->so->account->name();
}
public function address($ln='<br/>') {
return implode($ln,array($this->street($ln),sprintf('%s, %s %s',$this->city(),$this->state(),$this->pcode())));
}
public function city() {
return $this->so->site_details('city');
}
public function contacts() {
return 'Tel: '.$this->phone();
}
public function country() {
return $this->so->country;
}
public function date_format() {
return $this->so->date_format;
}
public function decimals() {
return $this->so->decimal_place;
}
public function email() {
return $this->so->site_details('email');
}
public function fax() {
return $this->so->site_details('fax');
}
public function faq() {
return $this->so->site_details('faqurl');
}
public function language() {
return $this->so->language;
}
public function logo_file() {
list ($path,$suffix) = explode('.',Config::$logo);
return ($x=Kohana::find_file(sprintf('media/site/%s',$this->site()),$path,$suffix)) ? $x : Kohana::find_file('media',$path,$suffix);
}
public function name() {
return $this->so->site_details('name');
}
public function module_config($item,array $value=NULL) {
return $this->so->module_config($item,$value);
}
public function pcode() {
return $this->so->site_details('pcode');
}
public function phone() {
return $this->so->site_details('phone');
}
public function site($format=FALSE) {
return $format ? sprintf('%02s',$this->so->id) : $this->so->id;
}
public function so() {
return $this->so;
}
public function state() {
return $this->so->site_details('state');
}
public function street($ln='<br/>') {
return $this->so->site_details('address2') ? implode($ln,array($this->so->site_details('address1'),$this->so->site_details('address2'))) : $this->so->site_details('address1');
}
public function time_format() {
return $this->so->time_format;
}
}
?>

View File

@ -4,16 +4,13 @@
* This class extends the core Kohana class by adding some core application * This class extends the core Kohana class by adding some core application
* specific functions, and configuration. * specific functions, and configuration.
* *
* @package WWZ * @package Membership Database
* @category Helpers * @category Helpers
* @author Deon George * @author Deon George
* @copyright (c) 2014 Deon George * @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html * @license http://dev.leenooks.net/license.html
*/ */
class Config extends Kohana_Config { class Config extends Kohana_Config {
// Our default logo, if there is no site logo
public static $logo = 'img/logo-small.png';
/** /**
* Some early initialisation * Some early initialisation
* *
@ -41,73 +38,64 @@ class Config extends Kohana_Config {
return Config::$_instance; return Config::$_instance;
} }
/** public static function Copywrite() {
* Return our caching mechanism
*/
public static function cachetype() {
return is_null(Kohana::$config->load('config')->cache_type) ? 'file' : Kohana::$config->load('config')->cache_type;
}
public static function copywrite() {
return '(c) 2014 Deon George'; return '(c) 2014 Deon George';
} }
public static function country() {
return NULL;
}
/**
* Show a date using a site configured format
*/
public static function date($date) {
return (is_null($date) OR ! $date) ? '' : date('d-M-Y',$date);
}
public static function language() {
// @todo To implement
return 'auto';
}
/**
* The URI to show for the login prompt.
* Normally if the user is logged in, we can replace it with something else
*/
public static function login_uri() {
return ($ao = Auth::instance()->get_user() AND is_object($ao)) ? $ao->name() : HTML::anchor('login',_('Login'));
}
public static function logo() {
return HTML::image(static::logo_uri(),array('class'=>'headlogo','alt'=>_('Logo')));
}
public static function logo_uri($protocol=NULL) {
list ($path,$suffix) = explode('.',static::$logo);
return URL::site(Route::get('default/media')->uri(array('file'=>$path.'.'.$suffix),array('alt'=>static::sitename())),$protocol);
}
public static function siteid($format=FALSE) {
return '';
}
/**
* Work out our site mode (dev,test,prod)
*/
public static function sitemode() {
return Kohana::$config->load('config.site')->mode;
}
public static function sitename() {
return 'AER Translate';
}
public static function theme() {
return 'theme/'.Kohana::$config->load('config')->theme;
}
public static function version() { public static function version() {
// @todo Work out our versioning // @todo Work out our versioning
return 'TBA'; return 'TBA';
} }
/**
* Find a list of all database enabled modules
*
* Our available modules are defined in the DB (along with method
* security).
*/
public static function modules() {
static $result = array();
if (! count($result)) {
// We need to know our site here, so that we can subsequently load our enabled modules.
if (PHP_SAPI === 'cli') {
if (! ($site = Minion_CLI::options('site'))) {
echo _('Cant figure out the site, use --site= for CLI')."\n";
die();
} else
$_SERVER['SERVER_NAME'] = $site;
}
foreach (ORM::factory('Module')->list_external() as $mo)
$result[$mo->name] = MODPATH.$mo->name;
}
return $result;
}
public static function module_config($item,array $value=NULL) {
return Company::instance()->module_config($item,$value);
}
public static function module_exist($module) {
return array_key_exists(strtolower($module),self::modules()) ? TRUE : FALSE;
}
/**
* See if our emails for the template should be sent to configured admin(s)
*
* @param string template - Template to test for
* @return mixed|array - Email to send test emails to
*/
public static function testmail($template) {
$config = Kohana::$config->load('debug')->email_admin_only;
if (is_null($config) OR ! is_array($config) OR empty($config[$template]))
return FALSE;
else
return $config[$template];
}
} }
?> ?>

View File

@ -1,218 +0,0 @@
<?php defined('SYSPATH') or die('No direct script access.');
include_once 'includes/kohana/modules/simplehtmldom/classes/simple_html_dom.php';
class Controller_Translate extends Controller_TemplateDefault {
private $_tags = array(
'span.aer_title',
'span.source_panel_heading',
'td.section_heading',
'td.standard_point ul li',
'span.source_panel_heading',
'td.document_name',
'td.collection',
'td.author',
'td.business_case_heading',
'span.source_panel_heading',
'span.target_panel_heading',
'td.grid_header',
'td.tco_label',
'td.summary_header',
'td.summary_tag',
'td.summary_data',
'span.target_mig_panel_heading',
);
private function aer() {
$file = '/local/WEB/sites/net.leenooks.dev/aer/application/media/aer/Honda Foundry_aer.htm';
// Fix errors in the HTML file
$data = file_get_contents($file);
$data = preg_replace('/<td class="grid_total"<td class="grid_header">/','<td class="grid_header">',$data);
return $data;
}
public function action_index() {
HTTP::redirect(URL::link('','translate/render'));
$output = '';
Block::factory()
->title('Hello')
->title_icon('icon-cog')
->body($output);
}
public function action_import() {
$html = new simple_html_dom();
$html->load($this->aer());
$this->store($html->find('head',0)->find('title',0));
foreach ($this->_tags as $z)
foreach ($html->find($z) as $x)
$this->store($x);
HTTP::redirect(URL::link('','translate/index'));
}
public function action_render() {
$output = '';
if ($this->request->post('language_id')) {
$html = new simple_html_dom();
$html->load($this->aer());
$x = $html->find('head',0);
$x->innertext .= '<meta http-equiv="content-type" content="text/html;charset=utf-8">';
$lo = ORM::factory('Language',$this->request->post('language_id'));
foreach ($this->_tags as $z)
foreach ($html->find($z) as $x)
$x->innertext = $this->translate($x,$lo);
// Convert order the img tags
foreach ($html->find('img') as $z) {
$z->src = sprintf('%s/%s',URL::site('media/aer'),$z->src);
}
$this->response->body($html);
$this->auto_render = FALSE;
// We dont know what sort of payment type yet
} else {
$x = $this->lang();
$output .= Form::open();
$output .= Form::select('language_id',ORM::factory('Language')->list_select(),$x->id);
$output .= Form::button('submit','Submit',array('class'=>'btn btn-primary'));
$output .= Form::close();
}
Block::factory()
->title('Render in...')
->title_icon('icon-share')
->body($output);
}
public function action_save() {
foreach ($this->request->post('x') as $id => $value) {
if (! $value)
continue;
$to = ORM::factory('Translate',array('language_id'=>$this->request->post('language_id'),'original_id'=>$id));
$to->translation = $value;
$to->language_id = $this->request->post('language_id');
$to->original_id = $id;
$to->save();
}
HTTP::redirect(sprintf('%s?language_id=%s&page=%s',URL::link('','translate/text'),$this->request->post('language_id'),$this->request->post('page')));
}
private function lang() {
foreach ($this->request->accept_lang() as $k=>$v) {
if (strlen($k) == 2)
$k = sprintf('%s_%s',strtolower($k),strtoupper($k));
else {
list($k,$v) = preg_split('/[-_]/',$k,2);
$k = sprintf('%s_%s',strtolower($k),strtoupper($v));
}
if ($x=ORM::factory('Language',array('iso'=>$k)))
return $x;
}
}
private function store(simple_html_dom_node $x,$l=0) {
if ($x->children()) {
foreach ($x->children() as $y) {
$this->store($y,$l+1);
$y->innertext = '%s';
}
}
// If we have a numeric value, convert it to %d
$x->innertext = preg_replace('/[0-9.]+/','%d',$x->innertext);
$oo = ORM::factory('Original',array('sentence'=>$x->innertext));
if (! trim($x->innertext) or (in_array(trim($x->innertext),array('$','&nbsp;')) or preg_match('/%d%?$/',$x->innertext))) {
return $x->innertext;
} elseif (! $oo->loaded()) {
$oo->sentence = $x->innertext;
$oo->save();
}
return $x->innertext;
}
private function translate(simple_html_dom_node $x,Model_Language $lo,$l=0) {
$nums = NULL;
$matches = array();
$dom_tmp = str_get_html($x->outertext);
$dom_tmp_node = $dom_tmp->firstChild();
$string = $this->store($dom_tmp_node,$l);
$oo = ORM::factory('Original',array('sentence'=>$string));
// If we have numbers, we'll need to save them.
if (preg_match('/%d/',$string))
$nums = preg_match('/[0-9.]+/',$x->innertext,$matches);
if ($oo->loaded()) {
$to = ORM::factory('Translate',array('original_id'=>$oo->id,'language_id'=>$lo->id));
$string = $to->loaded() ? $to->translation : $x->innertext;
}
if ($nums && $nums == 1)
$string = str_replace('%d',$matches[0],$string);
elseif ($nums > 1)
throw HTTP_Exception::factory('501','Argh, didnt allow for more than 1 match');
if ($x->children()) {
foreach ($x->children() as $y) {
$string = preg_replace('/%s/',$this->translate($y,$lo,$l+1),$string);
}
}
return $string;
}
public function action_text() {
$output = '';
if ($this->request->query('language_id')) {
$output .= Form::open(URL::link('','translate/save'));
$output .= Form::hidden('language_id',$this->request->query('language_id'));
$oo = ORM::factory('Original')
->select('translate.translation')
->join('translate','LEFT OUTER')
->on('original.id','=','translate.original_id')
->on('translate.language_id','=',$this->request->query('language_id'));
$output .= View::factory('translate')
->set('o',$oo->find_all());
// We dont know what sort of payment type yet
} else {
$x = $this->lang();
$output .= Form::open(NULL,array('method'=>'GET'));
$output .= Form::select('language_id',ORM::factory('Language')->list_select(),$x->id);
}
$output .= Form::button('submit','Submit',array('class'=>'btn btn-primary'));
$output .= Form::close();
Block::factory()
->title('Translate Text')
->title_icon('icon-share')
->body($output);
}
} // End Welcome

View File

@ -1,10 +1,18 @@
<?php defined('SYSPATH') or die('No direct script access.'); <?php defined('SYSPATH') or die('No direct script access.');
class Controller_Welcome extends Controller { class Controller_Welcome extends Controller_TemplateDefault {
public function action_index() public function action_index() {
{ if (! Kohana::$config->load('config')->appname)
HTTP::redirect(URL::link('','translate')); throw HTTP_Exception::factory(500,'Site not setup!');
$output = '';
$output = View::factory('pages/welcome');
Style::factory()
->type('file')
->data('media/css/pages/welcome.css');
$this->template->content = $output;
} }
} // End Welcome } // End Welcome

View File

@ -3,13 +3,13 @@
/** /**
* This class overrides Kohana's Cookie * This class overrides Kohana's Cookie
* *
* @package AER * @package Membership Database
* @category Modifications * @category Modifications
* @author Deon George * @author Deon George
* @copyright (c) 2014 Deon George * @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html * @license http://dev.leenooks.net/license.html
*/ */
class Cookie extends Kohana_Cookie { class Cookie extends Kohana_Cookie {
public static $salt = 'AER'; public static $salt = 'Photo';
} }
?> ?>

View File

@ -0,0 +1,35 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class overrides Kohana's DB
*
* @package Membership Database
* @category Modifications
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
class DB extends Kohana_DB {
// Add the site_id to the delete query
public static function delete($table = NULL)
{
$db = new Database_Query_Builder_Delete($table);
if (! in_array($table,ORM::$no_site_id_tables))
return $db->where($table.'.site_id','=',Company::instance()->site());
else
return $db;
}
// Add the site_id to the update query
final public static function update($table = NULL)
{
$db = new Database_Query_Builder_Update($table);
if (! in_array($table,ORM::$no_site_id_tables))
return $db->where($table.'.site_id','=',Company::instance()->site());
else
return $db;
}
}
?>

View File

@ -0,0 +1,18 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class extends the core Kohana class by adding some core application
* specific functions, and configuration.
*
* @package Membership Database
* @category Modifications
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
abstract class Database extends Kohana_Database {
public function caching() {
return isset($this->_config['caching']) ? $this->_config['caching'] : FALSE;
}
}
?>

View File

@ -0,0 +1,20 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* MySQL database connection.
*
* Modified for MDB, so that ORM can use enhanced SQL queries. This has been
* achieved by simply removing the identifier backtick.
* (IE: SELECT function()...)
*
* @package Membership Database
* @category Modifications
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Database_MySQL extends Kohana_Database_MySQL {
// MySQL uses a backtick for identifiers
protected $_identifier = '';
}
?>

View File

@ -0,0 +1,72 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class overrides Kohana's Core
*
* @package Membership Database
* @category Modifications
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
abstract class Kohana extends Kohana_Core {
/**
* Work out our Class Name as per Kohana's standards
*/
public static function classname($name) {
return str_replace(' ','_',ucwords(strtolower(str_replace('_',' ',$name))));
}
/**
* Find files using a multi-site enabled application
*
* In order of precedence, we'll return:
* 1) site-theme file, ie: site/X/THEME/${file}
* 2) site file, ie: site/X/${file}
* 3) theme file, ie: THEME/${file}
* 4) normal search, ie: ${file}
*/
public static function find_file($dir,$file,$ext=NULL,$array=FALSE) {
// Limit our scope to the following dirs
// @note, we cannot have classes checked, since Config() doesnt exist yet
$dirs = array('views','media');
if (! in_array($dir,$dirs) OR PHP_SAPI === 'cli')
return parent::find_file($dir,$file,$ext,$array);
$prefixes = array('');
// Our search order.
array_unshift($prefixes,Site::Theme().'/');
array_unshift($prefixes,sprintf('site/%s/',Site::ID()));
array_unshift($prefixes,sprintf('site/%s/%s/',Site::ID(),Site::Theme()));
foreach ($prefixes as $p)
if ($x = parent::find_file($dir,$p.$file,$ext,$array))
break;
// We found a path.
return $x;
}
/**
* Override Kohana's shutdown_handler()
*
* When set up for multi-site, we need to disable Kohana's caching
* unless each site has exactly the same modules enabled.
* This is because Kohana::$file is cached with the enabled modules
* and is not OSB multi-site aware.
*/
public static function shutdown_handler() {
// If caching isnt enabled, we can skip this anyway
if (! Kohana::$caching)
return parent::shutdown_handler();
Kohana::$caching = FALSE;
$result = parent::shutdown_handler();
Kohana::$caching = TRUE;
return $result;
}
}
?>

View File

@ -0,0 +1,144 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This Model manages both the accounts that users use to login to the system, as well as the account where services are owned.
*
* @package Membership Database
* @category Models
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Model_Account extends Model_Auth_UserDefault {
// Relationships
protected $_has_many = array(
'user_tokens'=>array('model'=>'user_token'),
'email_log'=>array('far_key'=>'id'),
'group'=>array('through'=>'account_group'),
);
protected $_has_one = array(
'country'=>array('foreign_key'=>'id'),
'currency'=>array('foreign_key'=>'id'),
'language'=>array('foreign_key'=>'id'),
);
protected $_display_filters = array(
'date_orig'=>array(
array('Site::Date',array(':value')),
),
'date_last'=>array(
array('Site::Date',array(':value')),
),
'active'=>array(
array('StaticList_YesNo::get',array(':value',TRUE)),
),
);
protected $_form = array('id'=>'id','value'=>'name(TRUE)');
protected $_save_message = TRUE;
/**
* Our account number format
*/
public function accnum() {
return sprintf('%s-%04s',Company::instance()->site(TRUE),$this->id);
}
/**
* Get the groups that an account belongs to
*/
public function groups() {
$result = array();
foreach ($this->group->where_active()->find_all() as $go)
foreach ($go->list_parentgrps(TRUE) as $cgo)
if (empty($result[$cgo->id]))
$result[$cgo->id] = $cgo;
return $result;
}
public function log($message) {
// Log a message for this account
$alo = ORM::factory('Account_Log');
$alo->account_id = $this->id;
$alo->ip = Request::$client_ip;
$alo->details = $message;
$alo->save();
return $alo->saved();
}
/**
* This function will extract the available methods for this account
* This is used both for menu options and method security
*/
public function methods() {
static $result = array();
// @todo We may want to optimise this with some session caching.
if ($result)
return $result;
foreach ($this->groups() as $go)
foreach ($go->module_method->find_all() as $mmo)
if (empty($result[$mmo->id]))
$result[$mmo->id] = $mmo;
Sort::MAsort($result,'module->name,menu_display');
return $result;
}
/**
* Return an account name
*/
public function name() {
return trim(sprintf('%s %s',$this->first_name,$this->last_name));
}
/**
* Search for accounts matching a term
*/
public function list_autocomplete($term,$index,$value,array $label,array $limit=array(),array $options=NULL) {
$ao = Auth::instance()->get_user();
$this->clear();
$this->where_active();
// Build our where clause
// First Name, Last name
if (preg_match('/\ /',$term)) {
list($fn,$ln) = explode(' ',$term,2);
$this->where_open()
->where_open()
->where('first_name','like','%'.$fn.'%')
->and_where('last_name','like','%'.$ln.'%')
->where_close()
->or_where('company','like','%'.$term.'%')
->where_close();
} elseif (is_numeric($term)) {
$this->where('id','like','%'.$term.'%');
} elseif (preg_match('/\@/',$term)) {
$this->where('email','like','%'.$term.'%');
} else {
$this->where_open()
->where('company','like','%'.$term.'%')
->or_where('first_name','like','%'.$term.'%')
->or_where('last_name','like','%'.$term.'%')
->where_close();
}
// Restrict results to authorised accounts
array_push($limit,array('id','IN',$ao->RTM->customers($ao->RTM)));
return parent::list_autocomplete($term,$index,$value,$label,$limit,$options);
}
}
?>

View File

@ -1,27 +1,26 @@
<?php defined('SYSPATH') or die('No direct access allowed.'); <?php defined('SYSPATH') or die('No direct access allowed.');
/** /**
* This class supports AER Original Text Memos. * This class supports Account Login Logging
* *
* @package AER * @package Membership Database
* @category Models * @category Models
* @author Deon George * @author Deon George
* @copyright (c) 2014 Deon George * @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html * @license http://dev.leenooks.net/license.html
*/ */
class Model_Original extends ORM_OSB { class Model_Account_Log extends ORM {
// Relationships
protected $_belongs_to = array( protected $_belongs_to = array(
); 'account'=>array(),
protected $_has_one = array( );
protected $_sorting = array(
'id'=>'DESC',
); );
/**
* Filters used to format the display of values into friendlier values
*/
protected $_display_filters = array( protected $_display_filters = array(
'date_orig'=>array( 'date_orig'=>array(
array('Config::datetime',array(':value')), array('Site::Datetime',array(':value')),
), ),
); );
} }

View File

@ -0,0 +1,42 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
*
* @package Membership Database
* @category Models
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Model_Auth_UserDefault extends Model_Auth_User {
// Validation rules
public function rules() {
return array(
'username' => array(
array('not_empty'),
array('min_length', array(':value', 4)),
array('max_length', array(':value', 256)),
),
'email' => array(
array('not_empty'),
array('min_length', array(':value', 4)),
array('max_length', array(':value', 127)),
array('email'),
),
);
}
/**
* Complete our login
*
* For some database logins, we may not want to record the user last login
* details in the repository, so we just override that parent function
* here.
*
* We can also do some other post-login actions here.
*/
public function complete_login() {
return $this->log('Logged In');
}
}
?>

View File

@ -0,0 +1,71 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
*
* @package Membership Database
* @category Models
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Model_Group extends Model_Auth_Role {
// Relationships
protected $_has_many = array(
'account'=>array('through'=>'account_group'),
'module_method'=>array('through'=>'group_method','far_key'=>'method_id'),
);
protected $_sorting = array(
'name'=>'ASC',
);
protected $_display_filters = array(
'active'=>array(
array('StaticList_YesNo::get',array(':value',TRUE)),
),
);
/**
* This function will, given a group, list all of the children that
* are also related to this group, in the group heirarchy.
*/
public function list_childgrps($incParent=FALSE) {
$result = array();
if (! $this->loaded())
return $result;
foreach (ORM::factory('Group')->where_active()->and_where('parent_id','=',$this)->find_all() as $go) {
array_push($result,$go);
$result = array_merge($result,$go->list_childgrps());
}
if ($incParent)
array_push($result,$this);
return $result;
}
/**
* This function will, given a group, list all of the parent that
* are also related to this group, in the group heirarchy.
*/
public function list_parentgrps($incParent=FALSE) {
$result = array();
if (! $this->loaded())
return $result;
foreach (ORM::factory('Group')->where_active()->and_where('id','=',$this->parent_id)->find_all() as $go) {
array_push($result,$go);
$result = array_merge($result,$go->list_parentgrps());
}
if ($incParent)
array_push($result,$this);
return $result;
}
}
?>

View File

@ -1,30 +0,0 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class supports AER Languages Memos.
*
* @package AER
* @category Models
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Model_Language extends ORM_OSB {
// Relationships
protected $_belongs_to = array(
);
protected $_has_one = array(
);
protected $_form = array('id'=>'id','value'=>'name');
/**
* Filters used to format the display of values into friendlier values
*/
protected $_display_filters = array(
'date_orig'=>array(
array('Config::datetime',array(':value')),
),
);
}
?>

View File

@ -0,0 +1,55 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* MDB Application Module Model
*
* This module must remain in applications/ as it is used very early in the
* MDB initialisation.
*
* @package Membership Database
* @category Models
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Model_Module extends ORM {
// Relationships
protected $_has_one = array(
'record_id'=>array('model'=>'Record_ID','far_key'=>'id'),
);
protected $_has_many = array(
'module_method'=>array('far_key'=>'id'),
);
protected $_sorting = array(
'name'=>'ASC',
);
protected $_display_filters = array(
'external'=>array(
array('StaticList_YesNo::get',array(':value',TRUE)),
),
'name'=>array(
array('strtoupper',array(':value')),
),
'active'=>array(
array('StaticList_YesNo::get',array(':value',TRUE)),
),
);
/**
* Return an instance of this Module's Model
*
* @param $id PK of Model
*/
public function instance($id=NULL) {
if (! $this->loaded())
throw new Kohana_Exception('Cant call an instance of a model when it is not loaded');
return ORM::factory(Kohana::classname($this->name),$id);
}
public function list_external() {
return $this->where_active()->where('external','=',TRUE)->find_all();
}
}
?>

View File

@ -0,0 +1,40 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
*
* @package Membership Database
* @category Models
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Model_Record_ID extends ORM {
protected $_primary_key = 'module_id';
// This module doesnt keep track of column updates automatically
protected $_created_column = FALSE;
protected $_updated_column = FALSE;
public function next_id($mid) {
if (is_null($this->id)) {
$this->module_id = $mid;
// We'll get the next ID as the MAX(id) of the table
$mo = ORM::factory('Module',$mid);
$max = DB::select(array('MAX(id)','id'))
->from($mo->name)
->where('site_id','=',Company::instance()->site());
$this->id = $max->execute()->get('id');
}
$this->id++;
if (! $this->save())
throw HTTP_Exception::factory(501,'Unable to increase ID for :table',array(':table'=>$mid));
return $this->id;
}
}
?>

View File

@ -0,0 +1,115 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* Membership Database Setup Model
*
* This module must remain in applications/ as it is used very early in the
* Membership Database initialisation.
*
* @package Membership Database
* @category Models
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Model_Setup extends ORM {
// Setup doesnt use the update column
protected $_updated_column = FALSE;
protected $_has_one = array(
'account'=>array('foreign_key'=>'id','far_key'=>'admin_id'),
'country'=>array('foreign_key'=>'id','far_key'=>'country_id'),
'language'=>array('foreign_key'=>'id','far_key'=>'language_id'),
);
protected $_compress_column = array(
'module_config',
'site_details',
);
// Validation rules
public function rules() {
$x = Arr::merge(parent::rules(), array(
'url' => array(
array('not_empty'),
array('min_length', array(':value', 8)),
array('max_length', array(':value', 127)),
array('url'),
),
));
// This module doesnt use site_id.
unset($x['site_id']);
return $x;
}
/**
* Get/Set Module Configuration
*
* @param $key Module name.
* @param $value Values to store. If NULL, retrieves the value stored, otherwise stores value.
*/
public function module_config($key,array $value=NULL) {
// If we are not loaded, we dont have any config.
if (! $this->loaded() OR (is_null($value) AND ! $this->module_config))
return array();
$mo = ORM::factory('Module',array('name'=>$key));
if (! $mo->loaded())
throw new Kohana_Exception('Unknown module :name',array(':name'=>$key));
$mc = $this->module_config ? $this->module_config : array();
// If $value is NULL, we are a getter
if ($value === NULL)
return empty($mc[$mo->id]) ? array() : $mc[$mo->id];
// Store new value
$mc[$mo->id] = $value;
$this->module_config = $mc;
return $this;
}
public function module_config_id($key=NULL) {
$result = array();
foreach (array_keys($this->module_config) as $mid) {
if (is_null($key) OR $key == $mid) {
$result[$mid] = array(
'object'=>ORM::factory('Module',$mid),
'data'=>$this->module_config[$mid],
);
// If we are just after our key, we can continue here
if ($key AND $key==$mid)
break;
}
}
return $result;
}
/**
* Get/Set our Site Configuration from the DB
*
* @param $key Key
* @param $value Values to store. If NULL, retrieves the value stored, otherwise stores value.
*/
public function site_details($key,array $value=NULL) {
if (! in_array($key,array('name','address1','address2','city','state','pcode','phone','fax','email','faqurl')))
throw new Kohana_Exception('Unknown Site Configuration Key :key',array(':key'=>$key));
// If $value is NULL, we are a getter
if ($value === NULL)
return empty($this->site_details[$key]) ? '' : $this->site_details[$key];
// Store new value
$sc[$key] = $value;
return $this;
}
}
?>

View File

@ -1,30 +0,0 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class supports AER Translated Text.
*
* @package AER
* @category Models
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Model_Translate extends ORM_OSB {
// Relationships
protected $_belongs_to = array(
);
protected $_has_one = array(
);
protected $_form = array('id'=>'id','value'=>'translation');
/**
* Filters used to format the display of values into friendlier values
*/
protected $_display_filters = array(
'date_orig'=>array(
array('Config::datetime',array(':value')),
),
);
}
?>

179
application/classes/ORM.php Normal file
View File

@ -0,0 +1,179 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class extends Kohana's [ORM] class to create defaults for Membership Database.
*
* @package Membership Database
* @category Helpers
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
abstract class ORM extends lnApp_ORM {
/**
* @var string Database to connect to
*/
protected $_db = 'default';
// Tables that do not have a site_id column
public static $no_site_id_tables = array('setup','country','currency','language');
protected $_save_message = TRUE;
// Rules to assist with site ID and getting next record ID for inserts.
public function rules() {
return array(
'id'=>array(
array('ORM::get_next_id',array(':model',':field')),
),
'site_id'=>array(
array('ORM::set_site_id',array(':model',':field')),
),
);
}
/**
* Add our OSB site_id to each SELECT query
* @see parent::__build()
*/
final protected function _build($type) {
// Exclude tables without site ID's
if (! in_array($this->_table_name,ORM::$no_site_id_tables))
$this->where($this->_object_name.'.site_id','=',Company::instance()->site());
// Ensure we Cache our queries
$caching = FALSE;
foreach ($this->_db_pending as $method)
if ($method['name'] == 'cached') {
$caching = TRUE;
break;
}
if (! $caching)
$this->cached(Kohana::$config->load('cache.orm.'.$this->_table_name));
return parent::_build($type);
}
/**
* Determine if the account is authoised by the user
*/
public function authorised(Model $o=NULL,Model_Account $ao=NULL,$aid='account_id') {
if (is_null($o))
$o = $this;
if (is_null($ao))
$ao = Auth::instance()->get_user();
return in_array($o->{$aid},$ao->RTM->customers($ao->RTM));
}
/**
* Override KH's ORM count_relations() function, to include our site_id in the query.
*
* This is a copy of KH's ORM count_relations() function, with the addition of a where
* clause to include the site id.
*/
public function count_relations($alias, $far_keys = NULL)
{
if ($far_keys === NULL)
{
return (int) DB::select(array(DB::expr('COUNT(*)'), 'records_found'))
->from($this->_has_many[$alias]['through'])
->where($this->_has_many[$alias]['foreign_key'], '=', $this->pk())
->where('site_id', '=', Company::instance()->site())
->execute($this->_db)->get('records_found');
}
$far_keys = ($far_keys instanceof ORM) ? $far_keys->pk() : $far_keys;
// We need an array to simplify the logic
$far_keys = (array) $far_keys;
// Nothing to check if the model isn't loaded or we don't have any far_keys
if ( ! $far_keys OR ! $this->_loaded)
return 0;
$count = (int) DB::select(array(DB::expr('COUNT(*)'), 'records_found'))
->from($this->_has_many[$alias]['through'])
->where($this->_has_many[$alias]['foreign_key'], '=', $this->pk())
->where($this->_has_many[$alias]['far_key'], 'IN', $far_keys)
->where('site_id', '=', Company::instance()->site())
->execute($this->_db)->get('records_found');
// Rows found need to match the rows searched
return (int) $count;
}
public function config($key) {
$mc = Config::instance()->module_config($this->_object_name);
return empty($mc[$key]) ? '' : $mc[$key];
}
/**
* Get Next record id
*
* @param array Validate object
* @param string Primary Key
*/
final 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;
}
final public function mid() {
return ORM::factory('Module',array('name'=>$this->_table_name));
}
/**
* Set the site ID attribute for each row update
*/
final public static function set_site_id($model,$field) {
if (! is_null($model->$field))
return TRUE;
$model->_changed[$field] = $field;
$model->$field = Company::instance()->site();
return TRUE;
}
/**
* Function help to find records that are active
*/
public function list_active($active=TRUE) {
$x=($active ? $this->_where_active() : $this);
return $x->find_all();
}
public function list_count($active=TRUE) {
$x=($active ? $this->_where_active() : $this);
return $x->find_all()->count();
}
public function where_active() {
return $this->where('active','=',TRUE);
}
public function where_authorised(Model_Account $ao=NULL,$aid='account_id') {
if (is_null($ao))
$ao = Auth::instance()->get_user();
return $this->where($aid,'IN',$ao->RTM->customers($ao->RTM));
}
}
?>

View File

@ -1,287 +0,0 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class extends Kohana's [ORM] class to create defaults for OSB.
*
* @package OSB
* @category Helpers
* @author Deon George
* @copyright (c) 2009-2013 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 attributes used in forms.
protected $_form = array();
// Our attributes that should be converted to NULL when empty
protected $_nullifempty = array();
// Our attribute values that need to be stored as serialized
protected $_serialize_column = array();
// If we need to load any sub items on loading this model
protected $_sub_items = array();
protected $_sub_items_load = array();
protected $_sub_items_sorted = FALSE;
// Rules to assist with site ID and getting next record ID for inserts.
public function xrules() {
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')),
),
);
}
/**
* Retrieve and Store DB BLOB data.
*/
private function _blob($data,$set=FALSE) {
try {
return $set ? gzcompress($this->_serialize($data,$set)) : $this->_serialize(gzuncompress($data));
// Maybe the data isnt compressed?
} catch (Exception $e) {
return $this->_serialize($data,$set);
}
}
/**
* Auto process some data as it comes from the database
* @see parent::__get()
*/
public function __get($column) {
if (array_key_exists($column,$this->_table_columns)) {
// If the column is a blob, we'll decode it automatically
if (
$this->_table_columns[$column]['data_type'] == 'blob'
AND ! is_null($this->_object[$column])
AND ! isset($this->_changed[$column])
AND (! isset($this->_table_columns[$column]['auto_convert']) OR ! $this->_table_columns[$column]['auto_convert'])
) {
// In case our blob hasnt been saved as one.
try {
$this->_object[$column] = $this->_blob($this->_object[$column]);
}
catch(Exception $e) {
HTTP_Exception::factory(501,Kohana_Exception::text($e));
}
$this->_table_columns[$column]['auto_convert'] = TRUE;
}
// If the column is a serialized object, we'll unserialize it.
if (
in_array($column,$this->_serialize_column)
AND is_string($this->_object[$column])
AND ! is_null($this->_object[$column])
AND ! isset($this->_changed[$column])
AND (! isset($this->_table_columns[$column]['unserialized']) OR ! $this->_table_columns[$column]['unserialized'])
) {
// In case our object hasnt been saved as serialized.
try {
$this->_object[$column] = unserialize($this->_object[$column]);
}
catch(Exception $e) {
HTTP_Exception::factory(501,Kohana_Exception::text($e));
}
$this->_table_columns[$column]['unserialized'] = TRUE;
}
}
return parent::__get($column);
}
/**
* Intercept our object load, so that we can load our subitems
*/
protected function _load_values(array $values) {
parent::_load_values($values);
$sort = FALSE;
if ($this->_loaded AND $this->_sub_items_load AND count($this->_sub_items_load) == 1)
foreach ($this->_sub_items_load as $item => $sort)
$this->_sub_items = $this->$item->find_all()->as_array();
if ($sort) {
Sort::MAsort($this->_sub_items,$sort);
$this->_sub_items_sorted = TRUE;
}
return $this;
}
/**
* If a column is marked to be nullified if it is empty, this is where it is done.
*/
private function _nullifempty(array $array) {
foreach ($array as $k=>$v) {
if (is_array($v)) {
if (is_null($x=$this->_nullifempty($v)))
unset($array[$k]);
else
$array[$k] = $x;
} elseif (! $v AND $v !== 0 AND $v !== '0')
unset($array[$k]);
}
return count($array) ? $array : NULL;
}
/**
* Try and (un)serialize our data, and if it fails, just return it.
*/
private function _serialize($data,$set=FALSE) {
try {
return $set ? serialize($data) : unserialize($data);
// Maybe the data serialized?
} catch (Exception $e) {
return $data;
}
}
public function config($key) {
$mc = Config::instance()->module_config($this->_object_name);
return empty($mc[$key]) ? '' : $mc[$key];
}
public function dump() {
$result = array();
$result['this'] = $this->object();
foreach ($this->_sub_items as $o)
$result['sub'][] = $o->dump();
return $result;
}
/**
* Get Next record id
*
* @param array Validate object
* @param string Primary Key
*/
final 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;
}
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;
}
final public function mid() {
return ORM::factory('Module',array('name'=>$this->_table_name));
}
public function xsave(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 (! is_null($this->_object[$c]) AND $this->_table_columns[$c]['data_type'] == 'blob') {
$this->_object[$c] = $this->_blob($this->_object[$c],TRUE);
// We need to reset our auto_convert flag
if (isset($this->_table_columns[$c]['auto_convert']))
$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]);
}
// Test if the value has still changed
if ($this->_original_values AND $this->_object[$c] == $this->_original_values[$c])
unset($this->_changed[$c]);
}
return parent::save($validation);
}
/**
* Set the site ID attribute for each row update
*/
final public static function set_site_id($model,$field) {
if (! is_null($model->$field))
return TRUE;
$model->_changed[$field] = $field;
$model->$field = Company::instance()->site();
return TRUE;
}
public function subitems() {
return $this->_sub_items;
}
/**
* Override the Kohana processing so we can null values if required.
*/
public function values(array $values,array $expected=NULL) {
foreach ($values as $k=>$v) {
// Convert to NULL
if (in_array($k,$this->_nullifempty)) {
if (is_array($v))
$values[$k] = $this->_nullifempty($v);
elseif (! $v AND $v !== 0 AND $v !== '0')
$values[$k] = NULL;
}
}
return parent::values($values,$expected);
}
/**
* Function help to find records that are active
*/
public function list_active($active=TRUE) {
$x=($active ? $this->_where_active() : $this);
return $x->find_all();
}
public function list_count($active=TRUE) {
$x=($active ? $this->_where_active() : $this);
return $x->find_all()->count();
}
}
?>

View File

@ -0,0 +1,39 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class is for Site Information
*
* @package Membership Database
* @category Helpers
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Site extends lnApp_Site {
/**
* Show a date using a site configured format
*/
public static function Date($date) {
return (is_null($date) OR ! $date) ? '' : date(Company::instance()->date_format(),$date);
}
/**
* Work out our site ID for multihosting
*/
public static function ID($format=FALSE) {
return Company::instance()->site($format);
}
public static function Theme() {
// If we are using user admin pages (and login), we'll choose the admin theme.
return 'theme/'.(URL::admin_url() ? Kohana::$config->load('config')->theme_admin : Kohana::$config->load('config')->theme);
}
/**
* Show a date using a site configured format
*/
public static function Time($date) {
return date(Company::instance()->time_format(),($date ? $date : time()));
}
}
?>

View File

@ -0,0 +1,40 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class adds committee support
*
* @package Membership Database
* @category Modifications
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
class URL extends lnApp_URL {
// Our method paths for different functions
public static $method_directory = array(
'admin'=>'a',
'committee'=>'c',
'user'=>'u',
);
public static function navbar() {
$result = array();
foreach (array_reverse(self::$method_directory) as $k=>$v)
switch ($k) {
case 'admin': $result[$k] = array('name'=>'Administrator','icon'=>'icon-globe');
break;
case 'committe': $result[$k] = array('name'=>'Reseller','icon'=>'icon-th-list');
break;
case 'user': $result[$k] = array('name'=>Auth::instance()->get_user()->name(),'icon'=>'icon-user');
break;
default: $result[$k] = array('name'=>$k,'icon'=>'icon-question-sign');
}
return $result;
}
}
?>

View File

@ -0,0 +1,17 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* Membership Database Configuration - Authentication
*
* @package Membership Database
* @category Configuration
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
return array(
'driver' => 'MDB',
'hash_method' => 'md5',
);
?>

View File

@ -0,0 +1,10 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
return array
(
'appname' => 'Membership Database',
'session_change_trigger'=>array( // Updates to tables to make when our session ID is changed
),
'theme' => 'focusbusiness',
'theme_admin' => 'baseadmin',
);

View File

@ -18,13 +18,13 @@ return array
* *
* Ports and sockets may be appended to the hostname. * Ports and sockets may be appended to the hostname.
*/ */
'hostname' => 'localhost', 'hostname' => 'mysql.leenooks.vpn',
'database' => 'weblnaer', 'database' => 'weblnebcccmdb',
'username' => 'aer', 'username' => 'ln-ebccc',
'password' => 'AeR', 'password' => 'ebccc',
'persistent' => TRUE, 'persistent' => TRUE,
), ),
'table_prefix' => '', 'table_prefix' => 'mdb_',
'charset' => 'utf8', 'charset' => 'utf8',
'caching' => FALSE, 'caching' => FALSE,
), ),

View File

@ -0,0 +1,16 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* Photo system default configurable items.
*
* @package Membership Database
* @category Configuration
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
return array(
'Duplicates' => array('icon'=>'icon-edit','url'=>URL::site('photo/duplicate')),
);
?>

View File

@ -1,130 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title><?php echo $meta->title; ?></title>
<link rel="shortcut icon" href="<?php echo $meta->shortcut_icon ? $meta->shortcut_icon : '/favicon.ico' ?>" type="image/vnd.microsoft.icon" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="<?php echo $meta->language; ?>" />
<meta name="keywords" content="<?php echo $meta->keywords; ?>" />
<meta name="description" content="<?php echo $meta->description; ?>" />
<meta name="copyright" content="<?php echo Config::copywrite(); ?>" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<?php
if (Kohana::$environment >= Kohana::TESTING OR Request::current()->secure()) {
echo HTML::style('media/theme/bootstrap/css/bootstrap.min.css');
echo HTML::style('media/theme/bootstrap/css/bootstrap-responsive.min.css');
echo HTML::style('media/vendor/font-awesome/css/font-awesome.min.css');
} else {
echo HTML::style($meta->secure().'netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap.min.css');
echo HTML::style($meta->secure().'netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-responsive.min.css');
echo HTML::style($meta->secure().'netdna.bootstrapcdn.com/font-awesome/3.0.2/css/font-awesome.css');
}
echo HTML::style($meta->secure().'fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,800italic,400,600,800');
echo HTML::style('media/css/ui-lightness/jquery-ui-1.10.0.custom.min.css');
echo HTML::style('media/theme/baseadmin/css/base-admin-2.css');
echo HTML::style('media/theme/baseadmin/css/base-admin-2-responsive.css');
echo HTML::style('media/theme/baseadmin/css/custom.css');
echo Style::factory()->render_all();
?>
</head>
<body>
<?php if (! empty($shownavbar)) : ?>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"><i class="icon-cog"></i> </a>
<a class="brand" href="<?php echo URL::site(); ?>"><?php echo Config::sitename(); ?><sup></sup></a>
<div class="nav-collapse collapse">
<ul class="nav pull-right">
<?php echo $navbar; ?>
</ul>
<div class="navbar-search pull-right">
<div class="navbar-search-addon">
<i class="icon-search"></i>
<?php echo HTML::image('media/img/spinner.gif',array('class'=>'right','name'=>'searching')); ?>
<input type="text" name="search-query" class="search-query" placeholder="Search" data-provide="typeahead" disabled="disabled">
</div>
</div>
</div><!--/.nav-collapse -->
</div> <!-- /container -->
</div> <!-- /navbar-inner -->
</div> <!-- /nvarbar -->
<div class="subnavbar">
<div class="subnavbar-inner">
<div class="container">
<a class="btn-subnavbar collapsed" data-toggle="collapse" data-target=".subnav-collapse">
<i class="icon-reorder"></i>
</a>
<div class="subnav-collapse collapse">
<ul class="mainnav">
<li class="">
<a href="<?php echo URL::link('','index',TRUE); ?>"><i class="icon-home"></i> <span>Home</span></a>
</li>
<li class="">
<a href="<?php echo URL::link('','import',TRUE); ?>"><i class="icon-tasks"></i> <span>Import</span></a>
</li>
<li class="">
<a href="<?php echo URL::link('','text',TRUE); ?>"><i class="icon-tasks"></i> <span>Strings</span></a>
</li>
<li class="">
<a href="<?php echo URL::link('','render',TRUE); ?>"><i class="icon-tasks"></i> <span>Render</span></a>
</li>
<?php if (($ao = Auth::instance()->get_user()) AND $ao->isAdmin()) : ?>
<li class="">
<a href="<?php echo URL::link('admin','welcome',TRUE); ?>"><i class="icon-tasks"></i> <span>Admin</span></a>
</li>
<?php endif ?>
</ul>
</div> <!-- /.subnav-collapse -->
</div> <!-- /container -->
</div> <!-- /subnavbar-inner -->
</div> <!-- /subnavbar -->
<?php endif ?>
<div class="error_container">
<div class="error_details">
<div class="row">
<div class="span10 offset2">
<?php echo SystemMessage::factory()->render_all(); ?>
</div>
</div> <!-- /row -->
</div> <!-- /error_details -->
</div> <!-- /error_container -->
<div class="main">
<div class="container">
<div class="row">
<?php echo $content; ?>
</div> <!-- /row -->
</div> <!-- /container -->
</div> <!-- /main -->
<?php
if (Kohana::$environment >= Kohana::TESTING OR Request::current()->secure()) {
echo HTML::script('media/js/jquery/jquery-1.9.1.min.js');
echo HTML::script('media/theme/bootstrap/js/bootstrap.min.js');
echo HTML::script('media/js/lodash/lodash-1.2.1.min.js');
} else {
echo HTML::script($meta->secure().'code.jquery.com/jquery-1.9.1.min.js');
echo HTML::script($meta->secure().'netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js');
echo HTML::script($meta->secure().'cdnjs.cloudflare.com/ajax/libs/lodash.js/1.2.1/lodash.min.js');
}
echo HTML::script('media/theme/baseadmin/js/backtotop.js');
echo HTML::script('media/js/search.js');
echo HTML::script('media/js/custom.js');
echo Script::factory()->render_all();
?>
</body>
</html>

View File

@ -1,33 +0,0 @@
<?php $pag = new Pagination(array('total_items'=>$o->count(),'items_per_page'=>10)); ?>
<?php echo (string)$pag; ?>
<?php echo Form::hidden('page',$pag->current_page()); ?>
<table class="table table-striped table-condensed table-hover" id="list-table">
<thead><tr>
<th>Text</th>
<th>Translation</th>
<th>Ignore</th>
</tr></thead>
<tbody>
<?php $i=0;foreach ($o as $oo) : ?>
<?php
if (++$i < $pag->current_first_item())
continue;
elseif ($i > $pag->current_last_item())
break;
?>
<?php while (preg_match('/</',$oo->sentence) OR preg_match('/>/',$oo->sentence)) :
$oo->sentence = preg_replace('/</','&lt',$oo->sentence);
$oo->sentence = preg_replace('/>/','&gt',$oo->sentence);
endwhile
?>
<tr>
<td width="49%"><?php echo $oo->sentence; ?></td>
<td width="49%"><?php echo Form::input(sprintf('x[%s]',$oo->id),$oo->translation,array('style'=>'width: 100%;')); ?></td>
<!-- <td><?php echo Form::checkbox('ignore',FALSE); ?></td> -->
</tr>
<?php endforeach ?>
</tbody>
</table>

@ -1 +1 @@
Subproject commit e2475dba9e6eaeafc6ecc4c71542937638354cd4 Subproject commit 5ffa395307a3b26f901dde5f3064c48a15979f0d

@ -1 +0,0 @@
Subproject commit a889d25eda0d6c1b8766b15f2d71f3dd4f0357d9

1
modules/lnapp Submodule

@ -0,0 +1 @@
Subproject commit e6bc2de66ab85d5fd9e6de01c118e07a911f9921