From 7180e01dcf3fd13e4bf35b90a6d3866c2a6ee493 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 17 Sep 2011 20:45:08 +1000 Subject: [PATCH] Misc many fixes --- application/classes/config.php | 17 +------ .../classes/controller/admin/module.php | 4 +- application/classes/controller/debug.php | 28 ++++++++++ .../classes/controller/lnapp/login.php | 2 + .../controller/lnapp/templatedefault.php | 4 +- .../classes/controller/templatedefault.php | 2 +- application/classes/lnapp/config.php | 11 ++++ application/classes/orm.php | 51 +++++++++++++++++++ application/views/login.php | 2 +- modules/account/classes/auth/osb.php | 20 ++++---- modules/core/database_search.inc.php | 2 +- modules/core/static_var.inc.php | 3 ++ modules/email/classes/email/template.php | 34 ++++++++----- .../classes/model/group.php | 18 +++++++ .../product/views/product/category/list.php | 6 +-- .../classes/controller/admin/service.php | 3 +- .../classes/controller/user/statement.php | 4 +- .../views/staticpage/category/list.php | 6 +-- 18 files changed, 162 insertions(+), 55 deletions(-) create mode 100644 application/classes/controller/debug.php rename modules/{account_group => group}/classes/model/group.php (67%) diff --git a/application/classes/config.php b/application/classes/config.php index 2af30dd4..9ad3bb00 100644 --- a/application/classes/config.php +++ b/application/classes/config.php @@ -4,20 +4,10 @@ class Config extends lnApp_Config { /** * Find a list of all database enabled modules * - * @uses cache + * Our available modules are defined in the DB (along with method + * security). */ public static function appmodules() { - $cacheable = TRUE; - - if (array_key_exists('cache',Kohana::modules())) { - $cache = Cache::instance(static::cachetype()); - - if ($cacheable AND $cache->get('modules')) - return $cache->get('modules'); - - } else - $cache = ''; - $modules = array(); $module_table = 'module'; @@ -28,9 +18,6 @@ class Config extends lnApp_Config { $modules[$o->name] = MODPATH.$o->name; } - if ($cache) - $cache->set('modules',$modules); - return $modules; } } diff --git a/application/classes/controller/admin/module.php b/application/classes/controller/admin/module.php index 6ddc6a0c..b5af85d3 100644 --- a/application/classes/controller/admin/module.php +++ b/application/classes/controller/admin/module.php @@ -15,7 +15,7 @@ class Controller_Admin_Module extends Controller_TemplateDefault_Admin { 'add'=>TRUE, 'edit'=>TRUE, 'list'=>TRUE, - ); + ); /** * Get the list of methods for a class @@ -51,7 +51,7 @@ class Controller_Admin_Module extends Controller_TemplateDefault_Admin { $mo = ORM::factory('module'); Block::add(array( - 'title'=>sprintf('%s: %s - %s',_('Email For'),$this->ao->accnum(),$this->ao->name(TRUE)), + 'title'=>_('Defined Modules'), 'body'=>Table::display( $mo->find_all(), 25, diff --git a/application/classes/controller/debug.php b/application/classes/controller/debug.php new file mode 100644 index 00000000..1bc76ee7 --- /dev/null +++ b/application/classes/controller/debug.php @@ -0,0 +1,28 @@ +request->redirect(); + + parent::before(); + } + + public function action_site() { + $output = ''; + + $output .= debug::vars(array( + 'm'=>__METHOD__, + 'site'=>Config::site(), + 'siteID'=>Config::siteid(), + 'siteMode'=>Config::sitemodeverbose(), + 'modules'=>Config::appmodules(), + )); + + Block::add(array( + 'title'=>_('Site debug'), + 'body'=>$output, + )); + } +} +?> diff --git a/application/classes/controller/lnapp/login.php b/application/classes/controller/lnapp/login.php index f37c50a2..76bb800e 100644 --- a/application/classes/controller/lnapp/login.php +++ b/application/classes/controller/lnapp/login.php @@ -155,6 +155,8 @@ class Controller_lnApp_Login extends Controller_TemplateDefault { $mt->save(); // 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($mt->account_id)); $et->variables = array( diff --git a/application/classes/controller/lnapp/templatedefault.php b/application/classes/controller/lnapp/templatedefault.php index c31d0d2f..88391da7 100644 --- a/application/classes/controller/lnapp/templatedefault.php +++ b/application/classes/controller/lnapp/templatedefault.php @@ -89,7 +89,7 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template { SystemMessage::add(array( 'title'=>_('Insufficient Access'), 'type'=>'debug', - 'body'=>Kohana::debug(array('required'=>$this->auth_required,'action'=>$this->request->action(),'user'=>Auth::instance()->get_user()->username)), + 'body'=>Debug::vars(array('required'=>$this->auth_required,'action'=>$this->request->action(),'user'=>Auth::instance()->get_user()->username)), )); // @todo Login No Access redirects are not handled in JS? @@ -206,7 +206,7 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template { * Default Method to call from the tree menu */ public function action_menu() { - $this->template->content = _('Please choose from the menu.'); + $this->template->content = _('Please choose from the menu on the left - you may need to expand the items by pressing on the triangle.'); } protected function _headimages() { diff --git a/application/classes/controller/templatedefault.php b/application/classes/controller/templatedefault.php index 969d0356..b6d6e5e3 100644 --- a/application/classes/controller/templatedefault.php +++ b/application/classes/controller/templatedefault.php @@ -27,7 +27,7 @@ class Controller_TemplateDefault extends Controller_lnApp_TemplateDefault { } private function _cart() { - if (! Cart::instance()->contents()->reset(FALSE)->count_all()) + if (! class_exists('cart') OR ! Cart::instance()->contents()->reset(FALSE)->count_all()) return ''; return Cart::instance()->cart_block(); diff --git a/application/classes/lnapp/config.php b/application/classes/lnapp/config.php index 774ebc1c..fe399497 100644 --- a/application/classes/lnapp/config.php +++ b/application/classes/lnapp/config.php @@ -53,6 +53,17 @@ abstract class lnApp_Config extends Kohana_Config { return $sites[static::site()]; } + public static function sitemodeverbose() { + $modes = array( + Kohana::PRODUCTION=>'Production', + Kohana::STAGING=>'Staging', + Kohana::TESTING=>'Testing', + Kohana::DEVELOPMENT=>'Development', + ); + + return (! isset($modes[static::sitemode()])) ? 'Unknown' : $modes[static::sitemode()]; + } + public static function sitename() { return Kohana::config('config.site_name'); } diff --git a/application/classes/orm.php b/application/classes/orm.php index 27d8554b..b9389a67 100644 --- a/application/classes/orm.php +++ b/application/classes/orm.php @@ -73,5 +73,56 @@ class ORM extends Kohana_ORM { else return HTML::nbsp($value); } + + /** + * Override KH's ORM has() function, to include our site_id in the query. + * + * This is a copy of KH's ORM has() function, with the addition of a where + * clause to include the site id. + */ + public function has($alias, $far_keys) { + $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 FALSE; + + $count = (int) DB::select(array('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', '=', Config::siteid()) + ->execute($this->_db)->get('records_found'); + + // Rows found need to match the rows searched + return $count === count($far_keys); + } + + /** + * Tests if this object has a relationship to a different model, + * or an array of different models. + * + * // Check for any of the following roles + * $model->has('roles', array(1, 2, 3, 4)); + * + * @param string $alias Alias of the has_many "through" relationship + * @param mixed $far_keys An array of primary keys + * @return Database_Result + */ + public function has_any($alias, array $far_keys) { + // Nothing to check if the model isn't loaded or we don't have any far_keys + if ( ! $far_keys) + return FALSE; + + // Rows found need to match the rows searched + return (int) DB::select(array('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) + ->execute($this->_db)->get('records_found'); + } } ?> diff --git a/application/views/login.php b/application/views/login.php index 5761fb70..a66bb5fd 100644 --- a/application/views/login.php +++ b/application/views/login.php @@ -8,7 +8,7 @@ 'login-pwd','size'=>40));?>   - + 'form_button'));?> diff --git a/modules/account/classes/auth/osb.php b/modules/account/classes/auth/osb.php index b0da3719..d241da62 100644 --- a/modules/account/classes/auth/osb.php +++ b/modules/account/classes/auth/osb.php @@ -35,8 +35,8 @@ class Auth_OSB extends Auth_ORM { if (! empty($role)) { // Get the module details - $module = ORM::factory('module',array('name'=>Request::current()->controller())); - if (! $module->loaded() OR ! $module->status) { + $mo = ORM::factory('module',array('name'=>Request::current()->controller())); + if (! $mo->loaded() OR ! $mo->status) { SystemMessage::add(array( 'title'=>'Module is not defined or active in the Database', 'type'=>'warning', @@ -50,21 +50,21 @@ class Auth_OSB extends Auth_ORM { $method_name = Request::current()->action(); // Get the method number - $method = ORM::factory('module_method',array('module_id'=>$module->id,'name'=>$method_name)); - if (! $method->loaded()) { + $mmo = ORM::factory('module_method',array('module_id'=>$mo->id,'name'=>$method_name)); + if (! $mmo->loaded()) { SystemMessage::add(array( 'title'=>'Method is not defined or active in the Database', 'type'=>'warning', - 'body'=>sprintf('Method not defined: %s for %s',Request::current()->action(),$module->name), + 'body'=>sprintf('Method not defined: %s for %s',Request::current()->action(),$mo->name), )); } else { // If the role has the authorisation to run the method - $group_method = ORM::factory('group_method') - ->where('method_id','=',$method->id); + $gmo = ORM::factory('group_method') + ->where('method_id','=',$mmo->id); $roles = ''; - foreach ($group_method->find_all() as $gm) { + foreach ($gmo->find_all() as $gm) { $roles .= ($roles ? '|' : '').$gm->group->name; $ro = ORM::factory('group', array('name' => $gm->group->name)); @@ -82,7 +82,7 @@ class Auth_OSB extends Auth_ORM { SystemMessage::add(array( 'title'=>'User is not authorised in Database', 'type'=>'debug', - 'body'=>sprintf('Role(s) checked: %s
User: %s
Module: %s
Method: %s',$roles,$user->username,$module->name,$method->name), + 'body'=>sprintf('Role(s) checked: %s
User: %s
Module: %s
Method: %s',$roles,$user->username,$mo->name,$mmo->name), )); } } @@ -199,7 +199,7 @@ class Auth_OSB extends Auth_ORM { } // If the passwords match, perform a login - if ($user->has('group', ORM::factory('group', array('name' => 'Registered Users'))) AND $user->password === $password) + if ($user->status AND $user->has_any('group',ORM::factory('group',array('name'=>'Registered Users'))->list_childgrps(TRUE)) AND $user->password === $password) { if ($remember === TRUE) { diff --git a/modules/core/database_search.inc.php b/modules/core/database_search.inc.php index 3cf9a6b6..2f7ad794 100644 --- a/modules/core/database_search.inc.php +++ b/modules/core/database_search.inc.php @@ -152,6 +152,7 @@ function CORE_database_search($VAR,$construct,$type) { # Get any static vars to search $join_list = ''; $pre = AGILE_DB_PREFIX; +/* if (! empty($VAR['static_relation']) && count($VAR['static_relation']>0)) { while (list($idx,$value) = each($VAR['static_relation'])) { if ($value != '') { @@ -168,7 +169,6 @@ function CORE_database_search($VAR,$construct,$type) { } } -/* # standard where list $q .= $join_list . $where_list ." ".AGILE_DB_PREFIX."account.site_id = " . $db->qstr(DEFAULT_SITE); diff --git a/modules/core/static_var.inc.php b/modules/core/static_var.inc.php index 2fe5ef46..e162634c 100644 --- a/modules/core/static_var.inc.php +++ b/modules/core/static_var.inc.php @@ -765,6 +765,7 @@ return false; #################################################################### ### Get all the associated STATIC RELATION records +return false; $sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'static_relation WHERE site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND module_id = ' . $db->qstr($module_id) .' ORDER BY sort_order'; @@ -1031,6 +1032,7 @@ return false; $module_id = $result->fields['id']; +return false; #################################################################### ### Get all the associated STATIC RELATION records @@ -1197,6 +1199,7 @@ return false; $module_id = $result->fields['id']; +return false; #################################################################### ### Get all the associated STATIC RELATION records diff --git a/modules/email/classes/email/template.php b/modules/email/classes/email/template.php index 24b1d045..6fe55f73 100644 --- a/modules/email/classes/email/template.php +++ b/modules/email/classes/email/template.php @@ -25,13 +25,14 @@ class Email_Template { throw new Kohana_Exception('Email template :template not defined in DB',array(':template'=>$template)); if (is_null($language_id)) - $language_id=$this->default_lang; + $language_id = $this->default_lang; $this->etto = $this->template->email_template_translate->where('language_id','=',$language_id)->find(); if (! $this->etto->loaded() AND ($this->etto = $this->template->email_template_translate->where('language_id','=',$this->default_lang)->find()) AND ! $this->etto->loaded()) // @todo Change this to log/email the admin + return; throw new Kohana_Exception('No template (:template) found for user language (:language_id) or default language (:default_lang)', array(':template'=>$this->template->name,':language_id'=>$language_id,':default_lang'=>$this->default_lang)); } @@ -110,21 +111,26 @@ class Email_Template { ->setFrom(Kohana::config('config.email_from')); foreach ($this->components as $component) { - $s = $this->etto->resolve($this->email_data['variables'],$component); + if ($this->etto->loaded()) { + $s = $this->etto->resolve($this->email_data['variables'],$component); - switch ($component) { - case 'message_html': - $sm->setBody($s,'text/html'); - break; - case 'message_text': - $sm->setBody($s,'text/plain'); - break; - case 'subject': - $sm->setSubject($s); - break; + switch ($component) { + case 'message_html': + $sm->setBody($s,'text/html'); + break; + case 'message_text': + $sm->setBody($s,'text/plain'); + break; + case 'subject': + $sm->setSubject($s); + break; - default: - throw new Kohana_Exception('Component :component has not been configured in :method',array(':component'=>$component,':method'=>__METHOD__)); + default: + throw new Kohana_Exception('Component :component has not been configured in :method',array(':component'=>$component,':method'=>__METHOD__)); + } + } else { + $sm->setSubject(_('Email from').' '.Config::sitename()); + $sm->setBody(print_r($this->email_data['variables'],TRUE),'text/plain'); } } diff --git a/modules/account_group/classes/model/group.php b/modules/group/classes/model/group.php similarity index 67% rename from modules/account_group/classes/model/group.php rename to modules/group/classes/model/group.php index a8b683f9..a8ecc92c 100644 --- a/modules/account_group/classes/model/group.php +++ b/modules/group/classes/model/group.php @@ -35,5 +35,23 @@ class Model_Group extends Model_Auth_RoleDefault { array('StaticList_YesNo::display',array(':value')), ), ); + + public function list_childgrps($incParent=FALSE) { + $return = array(); + + if (! $this->loaded()) + return $return; + + foreach (ORM::factory('group')->where('status','=',1)->and_where('parent_id','=',$this)->find_all() as $go) { + array_push($return,$go); + + $return = array_merge($return,$go->list_childgrps()); + } + + if ($incParent) + array_push($return,$this); + + return $return; + } } ?> diff --git a/modules/product/views/product/category/list.php b/modules/product/views/product/category/list.php index 49d90c29..b255591e 100644 --- a/modules/product/views/product/category/list.php +++ b/modules/product/views/product/category/list.php @@ -1,7 +1,7 @@ - + - + - +
diff --git a/modules/service/classes/controller/admin/service.php b/modules/service/classes/controller/admin/service.php index 495a0312..ce06aac0 100644 --- a/modules/service/classes/controller/admin/service.php +++ b/modules/service/classes/controller/admin/service.php @@ -56,10 +56,11 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin { */ public function action_listbycheckout() { // @todo need to add the DB prefix here + // @todo need to remove the explicit references to the group_id $services = DB::query(Database::SELECT,' SELECT c.id AS cid,c.name as checkout_plugin_name,s.id AS sid,a.company,a.first_name,a.last_name,a.id as aid FROM ab_service s LEFT JOIN ab_account_billing ab ON (s.account_billing_id=ab.id) LEFT JOIN ab_checkout c ON (ab.checkout_plugin_id=c.id),ab_account a, ab_account_group ag -WHERE s.active=1 AND s.price > 0 AND s.account_id=a.id AND a.id=ag.account_id AND ((s.account_billing_id IS NOT NULL AND ag.group_id IS NOT NULL) OR (a.id=ag.account_id and ag.group_id=1003)) +WHERE s.active=1 AND s.price > 0 AND s.account_id=a.id AND a.id=ag.account_id AND ((s.account_billing_id IS NOT NULL AND ag.group_id!=2 ) OR (a.id=ag.account_id and ag.group_id=1003)) ORDER BY c.id,s.recur_schedule,c.name,a.company,a.last_name,a.first_name ') ->execute(); diff --git a/modules/statement/classes/controller/user/statement.php b/modules/statement/classes/controller/user/statement.php index f161c9cb..6b2e5a12 100644 --- a/modules/statement/classes/controller/user/statement.php +++ b/modules/statement/classes/controller/user/statement.php @@ -27,7 +27,7 @@ class Controller_User_Statement extends Controller_TemplateDefault_User { $ta[$i]['payment'] = $o; } - foreach ($this->ao->invoice->find_all() as $o) { + foreach ($this->ao->invoice->where('status','!=',0)->find_all() as $o) { $i = count($ta); $ta[$i]['time'] = $o->date_orig; $ta[$i]['invoice'] = $o; @@ -76,7 +76,7 @@ class Controller_User_Statement extends Controller_TemplateDefault_User { $output .= View::factory('statement/user/show_foot'); Block::add(array( - 'title'=>sprintf('%s: %s - %s',_('Transaactions For'),$this->ao->accnum(),$this->ao->name(TRUE)), + 'title'=>sprintf('%s: %s - %s',_('Transactions For'),$this->ao->accnum(),$this->ao->name(TRUE)), 'body'=>$output, )); } diff --git a/modules/static_page/views/staticpage/category/list.php b/modules/static_page/views/staticpage/category/list.php index 2a115152..48960f37 100644 --- a/modules/static_page/views/staticpage/category/list.php +++ b/modules/static_page/views/staticpage/category/list.php @@ -1,8 +1,8 @@ - + - + - +