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
|
|
|
*/
|
2011-08-27 06:33:46 +00:00
|
|
|
class Controller_Admin_Module_Method extends Controller_Admin_Module {
|
2010-11-29 22:41:08 +00:00
|
|
|
/**
|
|
|
|
* Add a method to the database
|
|
|
|
*/
|
2012-11-09 23:13:57 +00:00
|
|
|
public function action_add() {
|
|
|
|
$id = $this->request->param('id');
|
|
|
|
$method = $this->request->param('sid');
|
|
|
|
|
|
|
|
$mo = ORM::factory('Module',$id);
|
2013-05-29 11:43:59 +00:00
|
|
|
$mm = $this->_methods($mo->name);
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2013-05-29 11:43:59 +00:00
|
|
|
if (! $mo->loaded() OR ! in_array($method,$mm['methods']))
|
|
|
|
HTTP::redirect(URL::link('admin','module/list'));
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2013-05-29 11:43:59 +00:00
|
|
|
if ($_POST) {
|
|
|
|
$mmo = $mo->module_method;
|
|
|
|
$mmo->name = $method;
|
|
|
|
$mmo->module_id = $mo->id;
|
|
|
|
$mmo->values($_POST);
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2013-05-29 11:43:59 +00:00
|
|
|
if (! $mmo->check() OR ! $mmo->save())
|
|
|
|
throw HTTP_Exception::factory(501,'Unable to save data :post',array(':post'=>serialize($_POST)));
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2013-05-29 11:43:59 +00:00
|
|
|
SystemMessage::factory()
|
|
|
|
->title('Record added')
|
|
|
|
->type('success')
|
|
|
|
->body(_('Method record has been added.'));
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2013-05-29 11:43:59 +00:00
|
|
|
HTTP::redirect(URL::link('admin','/module/edit/'.$mo->id));
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
|
2013-05-29 11:43:59 +00:00
|
|
|
Block::factory()
|
|
|
|
->title(sprintf(_('Add Method (%s) to Database for (%s)'),strtoupper($method),strtoupper($mo->name)))
|
|
|
|
->title_icon('icon-plus-sign')
|
|
|
|
->type('form-horizontal')
|
|
|
|
->body(View::factory('module/method/admin/add')
|
|
|
|
->set('name',$method)
|
|
|
|
->set('o',$mo)
|
|
|
|
);
|
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');
|
|
|
|
$mmo = ORM::factory('Module_Method',$id);
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
if (! $mmo->loaded()) {
|
2013-05-29 11:43:59 +00:00
|
|
|
SystemMessage::factory()
|
|
|
|
->title(_('Invalid Method ID'))
|
|
|
|
->type('error')
|
|
|
|
->body(sprintf(_('Method 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
|
|
|
if ($_POST) {
|
|
|
|
$mmo->values($_POST);
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2013-05-29 11:43:59 +00:00
|
|
|
if (! $mmo->check() OR ! $mmo->save())
|
|
|
|
throw HTTP_Exception::factory(501,'Unable to save data :post',array(':post'=>serialize($_POST)));
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2013-05-29 11:43:59 +00:00
|
|
|
foreach (ORM::factory('Group')->find_all() as $go) {
|
2010-11-29 22:41:08 +00:00
|
|
|
// If the group was defined and no longer
|
|
|
|
if ($mmo->has('group',$go) AND (! isset($_POST['groups']) OR ! in_array($go->id,$_POST['groups']))) {
|
2013-05-29 11:43:59 +00:00
|
|
|
$gmo = ORM::factory('Group_Method',array('method_id'=>$mmo->id,'group_id'=>$go->id));
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2013-05-29 11:43:59 +00:00
|
|
|
if (! $gmo->delete())
|
|
|
|
SystemMessage::factory()
|
|
|
|
->title(_('Unable to DELETE Group Method'))
|
|
|
|
->type('error')
|
|
|
|
->body(sprintf(_('Unable to delete Group Method for method %s and group %s'),$mmo->name,$go->name));
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
// If the group was not defined and now is
|
|
|
|
} elseif (! $mmo->has('group',$go) AND isset($_POST['groups']) AND in_array($go->id,$_POST['groups'])) {
|
2013-05-29 11:43:59 +00:00
|
|
|
$gmo = ORM::factory('Group_Method')
|
2010-11-29 22:41:08 +00:00
|
|
|
->values(array(
|
|
|
|
'method_id'=>$mmo->id,
|
|
|
|
'group_id'=>$go->id,
|
|
|
|
));
|
|
|
|
|
2013-05-29 11:43:59 +00:00
|
|
|
if (! $gmo->check() OR ! $gmo->save())
|
|
|
|
SystemMessage::factory()
|
|
|
|
->title(_('Unable to SAVE Group Method'))
|
|
|
|
->type('error')
|
|
|
|
->body(sprintf(_('Unable to save Group Method for method %s and group %s'),$mmo->name,$go->name));
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-29 11:43:59 +00:00
|
|
|
Block::factory()
|
|
|
|
->title(sprintf(_('Configure access to method (%s::%s)'),$mmo->controller(),$mmo->method()))
|
|
|
|
->title_icon('icon-plus-sign')
|
|
|
|
->type('form')
|
|
|
|
->body(View::factory('module/method/admin/edit')
|
|
|
|
->set('o',$mmo)
|
|
|
|
);
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|