This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/application/classes/Controller/Admin/Module/Method.php

115 lines
3.4 KiB
PHP
Raw Normal View History

2013-10-10 02:44:53 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides MODULE management
*
* @package OSB
* @category Controllers/Admin
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_Admin_Module_Method extends Controller_Admin_Module {
/**
* Add a method to the database
*/
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);
2013-10-10 02:44:53 +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'));
2013-10-10 02:44:53 +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);
2013-10-10 02:44:53 +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)));
2013-10-10 02:44:53 +00:00
2013-05-29 11:43:59 +00:00
SystemMessage::factory()
->title('Record added')
->type('success')
->body(_('Method record has been added.'));
2013-10-10 02:44:53 +00:00
HTTP::redirect(URL::link('admin','module/edit/'.$mo->id));
2013-10-10 02:44:53 +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)
);
2013-10-10 02:44:53 +00:00
}
/**
* Edit a Module Configuration
*/
public function action_edit() {
2013-05-29 11:43:59 +00:00
$id = $this->request->param('id');
$mmo = ORM::factory('Module_Method',$id);
2013-10-10 02:44:53 +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));
2013-10-10 02:44:53 +00:00
2013-05-29 11:43:59 +00:00
HTTP::redirect(URL::link('admin','module/list'));
2013-10-10 02:44:53 +00:00
}
2013-05-29 11:43:59 +00:00
if ($_POST) {
$mmo->values($_POST);
2013-10-10 02:44:53 +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)));
2013-10-10 02:44:53 +00:00
2013-05-29 11:43:59 +00:00
foreach (ORM::factory('Group')->find_all() as $go) {
2013-10-10 02:44:53 +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));
2013-10-10 02:44:53 +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));
2013-10-10 02:44:53 +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')
2013-10-10 02:44:53 +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));
2013-10-10 02:44:53 +00:00
}
}
HTTP::redirect(URL::link('admin','module/edit/'.$mmo->module_id));
2013-10-10 02:44:53 +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)
);
2013-10-10 02:44:53 +00:00
}
}
?>