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

138 lines
3.8 KiB
PHP
Raw Normal View History

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
*/
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);
$mmo = ORM::factory('Module_Method');
2010-11-29 22:41:08 +00:00
if (! $mo->loaded() OR ! in_array($method,$this->_methods($mo->name)))
throw new Kohana_Exception('Method (:method) does not exist in :class',array(':method'=>$method,':class'=>$mo->name));
$mmo->name = $method;
$mmo->module_id = $mo->id;
$mmo->values($_POST);
$output = '';
if ($_POST AND $mmo->values($_POST)->check()) {
$mmo->save();
if ($mmo->saved()) {
SystemMessage::add(array(
'title'=>_('Method Added'),
'type'=>'info',
'body'=>sprintf(_('Method %s defined to database'),$mmo->name),
));
HTTP::redirect(URL::link('admin','/module/edit/'.$mo->id));
2010-11-29 22:41:08 +00:00
} else {
SystemMessage::add(array(
'title'=>_('Method Not Saved'),
'type'=>'error',
'body'=>sprintf(_('Unable to define Method %s to database?'),$mmo->name),
));
}
}
$output .= View::factory('module/admin/method_add')
->set('module',$mo)
->set('method',$mmo);
Block::add(array(
'title'=>sprintf(_('Add Method (%s) to Database for (%s)'),strtoupper($mmo->name),strtoupper($mo->name)),
'body'=>$output,
));
}
/**
* Edit a Module Configuration
*
* @param int $mid Module ID
*/
public function action_edit() {
$mid = $this->request->param('id');
2012-11-09 23:13:57 +00:00
$mmo = ORM::factory('Module_Method',$mid);
2010-11-29 22:41:08 +00:00
if (! $mmo->loaded()) {
SystemMessage::add(array(
'title'=>_('Invalid Method ID'),
'type'=>'error',
'body'=>sprintf(_('Method with ID %s doesnt appear to exist?'),$mid),
));
return;
}
$output = '';
// The groups that can run this method.
2012-11-09 23:13:57 +00:00
$groups = ORM::factory('Group');
2010-11-29 22:41:08 +00:00
if ($_POST) {
foreach ($groups->find_all() as $go) {
// If the group was defined and no longer
if ($mmo->has('group',$go) AND (! isset($_POST['groups']) OR ! in_array($go->id,$_POST['groups']))) {
2012-11-09 23:13:57 +00:00
$gm = ORM::factory('Group_Method',array('method_id'=>$mmo->id,'group_id'=>$go->id));
2010-11-29 22:41:08 +00:00
if (! $gm->delete())
SystemMessage::add(array(
'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),
));
// 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'])) {
2012-11-09 23:13:57 +00:00
$gm = ORM::factory('Group_Method')
2010-11-29 22:41:08 +00:00
->values(array(
'method_id'=>$mmo->id,
'group_id'=>$go->id,
));
if (! $gm->check() OR ! $gm->save())
SystemMessage::add(array(
'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),
));
}
}
}
$output .= Form::open();
$output .= View::factory('module/admin/method_detail_head');
2010-11-29 22:41:08 +00:00
foreach ($groups->find_all() as $go) {
$output .= View::factory('module/admin/method_detail_body')
->set('group',$go)
->set('defined',$mmo->has('group',$go));
}
$output .= View::factory('module/admin/method_detail_foot');
2010-11-29 22:41:08 +00:00
$output .= '<div>'.Form::submit('submit',_('Update'),array('class'=>'form_button')).'</div>';
2010-11-29 22:41:08 +00:00
$output .= Form::close();
Block::add(array(
'title'=>sprintf(_('%s->%s Method'),strtoupper($mmo->module->name),strtoupper($mmo->name)),
'body'=>$output,
));
}
}
?>