Misc many fixes
This commit is contained in:
parent
52074d239b
commit
7180e01dcf
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
28
application/classes/controller/debug.php
Normal file
28
application/classes/controller/debug.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
class Controller_Debug extends Controller_TemplateDefault {
|
||||
public function before() {
|
||||
if (! in_array(Config::sitemode(),array(Kohana::DEVELOPMENT,Kohana::TESTING)))
|
||||
$this->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,
|
||||
));
|
||||
}
|
||||
}
|
||||
?>
|
@ -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(
|
||||
|
@ -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() {
|
||||
|
@ -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();
|
||||
|
@ -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');
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -8,7 +8,7 @@
|
||||
<tr><td><?php echo Form::password('password',null,array('id'=>'login-pwd','size'=>40));?></td></tr>
|
||||
<tr><td colspan="2"> </td></tr>
|
||||
<!-- @todo Password reset ability should be a config option (or auto detected) -->
|
||||
<tr><td colspan="2"><?echo HTML::anchor('login/reset',_('Forgot your password?')); ?></td></tr>
|
||||
<tr><td colspan="2"><?php echo HTML::anchor('login/reset',_('Forgot your password?')); ?></td></tr>
|
||||
<tr><td colspan="2" style="text-align: center;"><?php echo Form::submit('submit',_('Authenticate'),array('class'=>'form_button'));?></td></tr>
|
||||
</table>
|
||||
<?php echo Form::close(); ?>
|
||||
|
@ -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<br/>User: %s</br>Module: %s<br/>Method: %s',$roles,$user->username,$module->name,$method->name),
|
||||
'body'=>sprintf('Role(s) checked: %s<br/>User: %s</br>Module: %s<br/>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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
@ -32,6 +32,7 @@ class Email_Template {
|
||||
($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,6 +111,7 @@ class Email_Template {
|
||||
->setFrom(Kohana::config('config.email_from'));
|
||||
|
||||
foreach ($this->components as $component) {
|
||||
if ($this->etto->loaded()) {
|
||||
$s = $this->etto->resolve($this->email_data['variables'],$component);
|
||||
|
||||
switch ($component) {
|
||||
@ -126,6 +128,10 @@ class Email_Template {
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
if ($admin OR ($admin = Config::testmail($this->template->name))) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
?>
|
@ -1,7 +1,7 @@
|
||||
<table width="100%" border="0">
|
||||
<?php foreach ($results as $value) { ?>
|
||||
<tr>
|
||||
<td class="menu"><a href="<?echo URL::site('product/category/'.$value->id);?>"><?php echo $value->name?></a></td>
|
||||
<td class="menu"><a href="<?php echo URL::site('product/category/'.$value->id); ?>"><?php echo $value->name; ?></a></td>
|
||||
</tr>
|
||||
<?}?>
|
||||
<?php } ?>
|
||||
</table>
|
||||
|
@ -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();
|
||||
|
@ -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,
|
||||
));
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
<table width="100%" border="0">
|
||||
<?php foreach ($results as $value) { ?>
|
||||
<tr>
|
||||
<td class="menu"><a href="<?echo URL::site(Request::current()->uri(array('action'=>'view','id'=>$value->id)));?>"><?php echo $value->name?></a></td>
|
||||
<td class="menu"><a href="<?php echo URL::site(Request::current()->uri(array('action'=>'view','id'=>$value->id))); ?>"><?php echo $value->name; ?></a></td>
|
||||
</tr>
|
||||
<?}?>
|
||||
<?php } ?>
|
||||
</table>
|
||||
|
Reference in New Issue
Block a user