2010-11-29 22:41:08 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class provides MODULE management
|
|
|
|
*
|
2013-03-19 22:35:19 +00:00
|
|
|
* @package OSB
|
|
|
|
* @category Controllers/Admin
|
2010-11-29 22:41:08 +00:00
|
|
|
* @author Deon George
|
2013-03-19 22:35:19 +00:00
|
|
|
* @copyright (c) 2009-2013 Open Source Billing
|
|
|
|
* @license http://dev.osbill.net/license.html
|
2010-11-29 22:41:08 +00:00
|
|
|
*/
|
2013-04-04 22:42:29 +00:00
|
|
|
class Controller_Admin_Module extends Controller_Module {
|
2011-08-26 01:16:48 +00:00
|
|
|
protected $secure_actions = array(
|
2011-08-27 06:33:46 +00:00
|
|
|
'add'=>TRUE,
|
2011-08-26 01:16:48 +00:00
|
|
|
'edit'=>TRUE,
|
|
|
|
'list'=>TRUE,
|
2011-09-17 10:45:08 +00:00
|
|
|
);
|
2011-08-26 01:16:48 +00:00
|
|
|
|
2010-11-29 22:41:08 +00:00
|
|
|
/**
|
2011-08-26 01:16:48 +00:00
|
|
|
* Get the list of methods for a class
|
2010-11-29 22:41:08 +00:00
|
|
|
*/
|
2011-08-26 01:16:48 +00:00
|
|
|
protected function _methods($class) {
|
|
|
|
// Get a list of methods this module has
|
|
|
|
$ch = 'Controller_%s';
|
2013-05-29 11:43:59 +00:00
|
|
|
$methods = $secure_actions = $auth_required = array();
|
2011-08-26 01:16:48 +00:00
|
|
|
|
|
|
|
// List of classes where all our methods are, including this one.
|
2013-02-12 11:14:59 +00:00
|
|
|
$classes = URL::$method_directory;
|
2011-08-26 01:16:48 +00:00
|
|
|
array_unshift($classes,'');
|
|
|
|
|
|
|
|
foreach ($classes as $c) {
|
2013-05-29 11:43:59 +00:00
|
|
|
$x = URL::dir($c);
|
|
|
|
$cn = Kohana::classname('Controller_'.($x ? $x.'_'.$class : $class));
|
2011-08-26 01:16:48 +00:00
|
|
|
|
|
|
|
if (class_exists($cn)) {
|
|
|
|
$r = new ReflectionClass($cn);
|
|
|
|
|
2013-05-29 11:43:59 +00:00
|
|
|
$rdp = $r->getDefaultProperties();
|
|
|
|
$secure_actions[$cn] = $rdp['secure_actions'];
|
|
|
|
$auth_required[$cn] = $rdp['auth_required'];
|
|
|
|
|
|
|
|
foreach ($r->getMethods() as $method) {
|
|
|
|
if (preg_match('/^action_/',$method->name))
|
|
|
|
array_push($methods,str_replace('action_',strtolower(($x ? $x.'_' : $x)),$method->name));
|
|
|
|
}
|
2011-08-26 01:16:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-29 11:43:59 +00:00
|
|
|
return array('methods'=>$methods,'secure_actions'=>$secure_actions,'auth_required'=>$auth_required);
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Edit a Module Configuration
|
|
|
|
*/
|
2011-08-27 06:33:46 +00:00
|
|
|
public function action_edit() {
|
2013-05-29 11:43:59 +00:00
|
|
|
$id = $this->request->param('id');
|
|
|
|
$mo = ORM::factory('Module',$id);
|
|
|
|
|
|
|
|
$methods = array();
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
if (! $mo->loaded()) {
|
2013-05-29 11:43:59 +00:00
|
|
|
SystemMessage::factory()
|
|
|
|
->title(_('Invalid Module ID'))
|
|
|
|
->type('error')
|
|
|
|
->body(sprintf(_('Module with ID %s doesnt appear to exist?'),$id));
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2013-05-29 11:43:59 +00:00
|
|
|
HTTP::redirect(URL::link('admin','module/list'));
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
|
2013-05-29 11:43:59 +00:00
|
|
|
$mm = $this->_methods($mo->name);
|
|
|
|
$methods['exist'] = array();
|
|
|
|
foreach ($mo->module_method->find_all() as $mmo) {
|
|
|
|
if (in_array($mmo->name,$mm['methods'])) {
|
|
|
|
$k = array_search($mmo->name,$mm['methods']);
|
|
|
|
unset($mm['methods'][$k]);
|
|
|
|
|
|
|
|
$mmo->status('INDB');
|
|
|
|
} else
|
|
|
|
$mmo->status('ORPHAN');
|
|
|
|
|
|
|
|
if (! empty($mm['secure_actions'][$mmo->controller()][$mmo->method()]))
|
|
|
|
unset($mm['secure_actions'][$mmo->controller()][$mmo->method()]);
|
|
|
|
|
|
|
|
array_push($methods['exist'],$mmo);
|
|
|
|
}
|
|
|
|
|
|
|
|
$methods['missing'] = array();
|
|
|
|
foreach ($mm['methods'] as $k=>$method) {
|
|
|
|
$mmo = ORM::factory('Module_Method');
|
|
|
|
$mmo->module_id = $mo->id;
|
|
|
|
$mmo->name = $method;
|
|
|
|
|
|
|
|
if (! empty($mm['auth_required'][$mmo->controller()]) AND $mm['auth_required'][$mmo->controller()])
|
|
|
|
$mmo->status('MISSING');
|
|
|
|
|
|
|
|
array_push($methods['missing'],$mmo);
|
|
|
|
}
|
|
|
|
|
|
|
|
Block::factory()
|
|
|
|
->title(sprintf('%s: %s ',_('Defined Module Methods For'),$mo->display('name')))
|
|
|
|
->title_icon('icon-cog')
|
|
|
|
->body(Table::factory()
|
|
|
|
->data($methods['exist'])
|
|
|
|
->columns(array(
|
|
|
|
'id'=>'ID',
|
|
|
|
'name'=>'Name',
|
|
|
|
'notes'=>'Notes',
|
|
|
|
'menu_display'=>'Menu',
|
|
|
|
'status()'=>'Status',
|
|
|
|
))
|
|
|
|
->prepend(array(
|
|
|
|
'id'=>array('url'=>URL::link('admin','module_method/edit/')),
|
|
|
|
))
|
|
|
|
);
|
|
|
|
|
|
|
|
Block::factory()
|
|
|
|
->title(sprintf('%s: %s ',_('Missing Module Methods For'),$mo->display('name')))
|
|
|
|
->title_icon('icon-exclamation-sign')
|
|
|
|
->body(Table::factory()
|
|
|
|
->data($methods['missing'])
|
|
|
|
->columns(array(
|
|
|
|
'name'=>'Name',
|
|
|
|
'status()'=>'Status',
|
|
|
|
))
|
|
|
|
->prepend(array(
|
|
|
|
'name'=>array('url'=>URL::link('admin','module_method/add/'.$mo->id.'/')),
|
|
|
|
))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List our installed modules
|
|
|
|
*/
|
|
|
|
public function action_list() {
|
|
|
|
$mo = ORM::factory('Module');
|
|
|
|
|
|
|
|
Block::factory()
|
|
|
|
->title('Defined Modules')
|
|
|
|
->title_icon('icon-cog')
|
|
|
|
->body(Table::factory()
|
|
|
|
->data($mo->find_all())
|
|
|
|
->jssort(TRUE)
|
|
|
|
->columns(array(
|
|
|
|
'id'=>'ID',
|
|
|
|
'name'=>'Name',
|
|
|
|
'notes'=>'Notes',
|
|
|
|
'status(TRUE)'=>'Active',
|
|
|
|
'external(TRUE)'=>'External',
|
|
|
|
))
|
|
|
|
->prepend(array(
|
|
|
|
'id'=>array('url'=>URL::link('admin','module/edit/')),
|
|
|
|
))
|
|
|
|
);
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|