93 lines
2.7 KiB
PHP
93 lines
2.7 KiB
PHP
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
/**
|
|
* This class extends renders OSB menu tree.
|
|
*
|
|
* @package lnApp
|
|
* @subpackage Tree
|
|
* @category Controllers
|
|
* @author Deon George
|
|
* @copyright (c) 2010 Open Source Billing
|
|
* @license http://dev.osbill.net/license.html
|
|
*/
|
|
class Controller_Tree extends Controller_lnApp_Tree {
|
|
protected $auth_required = TRUE;
|
|
|
|
/**
|
|
* Draw the Tree Menu
|
|
*
|
|
* The incoming ID is either a Branch B_x or a Node N_x
|
|
* Where X is actually the module.
|
|
*
|
|
* @param array $data Tree data passed in by inherited methods
|
|
*/
|
|
public function action_json(array $data=array()) {
|
|
// Get the user details
|
|
$id = (is_null($this->request->param('id')) AND isset($_REQUEST['id'])) ? substr($_REQUEST['id'],2) : $this->request->param('id');
|
|
$user = Auth::instance()->get_user();
|
|
|
|
if ($user) {
|
|
if (! $id) {
|
|
$modules = array();
|
|
foreach ($user->groups() as $go)
|
|
foreach ($go->list_parentgrps(TRUE) as $cgo)
|
|
foreach ($cgo->module_method->find_all() as $mmo)
|
|
if ($mmo->menu_display AND empty($modules[$mmo->module_id]))
|
|
$modules[$mmo->module_id] = $mmo->module;
|
|
|
|
Sort::masort($modules,'name');
|
|
|
|
foreach ($modules as $id => $mo)
|
|
if (! $mo->parent_id)
|
|
array_push($data,array('id'=>$id,'name'=>$mo->name,'state'=>'closed'));
|
|
|
|
} else {
|
|
$mo = ORM::factory('module',$id);
|
|
|
|
$methods = array();
|
|
if ($mo->loaded()) {
|
|
foreach ($mo->module_method->find_all() as $mmo)
|
|
if ($mmo->menu_display)
|
|
foreach ($mmo->group->find_all() as $gmo)
|
|
if ($user->has_any('group',$gmo->list_childgrps(TRUE)))
|
|
$methods[$mmo->id] = $mmo;
|
|
|
|
Sort::masort($modules,'name');
|
|
|
|
foreach ($methods as $id => $mmo) {
|
|
if (preg_match('/_/',$mmo->name)) {
|
|
list($mode,$action) = explode('_',$mmo->name);
|
|
$url = URL::site(sprintf('/%s/%s/%s',$mode,$mmo->module->name,$action));
|
|
} else {
|
|
$url = URL::site(sprintf('/%s/%s',$mmo->module->name,$mmo->name));
|
|
}
|
|
|
|
array_push($data,array(
|
|
'id'=>sprintf('%s_%s',$mmo->module_id,$id),
|
|
'name'=>$mmo->name,
|
|
'state'=>'none',
|
|
'attr_id'=>sprintf('%s_%s',$mmo->module->name,$id),
|
|
'attr_href'=>(empty($details['page']) ? $url : $details['page'])
|
|
));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->output = array();
|
|
|
|
foreach ($data as $branch) {
|
|
array_push($this->output,array(
|
|
'attr'=>array('id'=>sprintf('B_%s',$branch['id'])),
|
|
'state'=>$branch['state'],
|
|
'data'=>array('title'=>$branch['name']),
|
|
'attr'=>array('id'=>sprintf('N_%s',$branch['id']),'href'=>empty($branch['attr_href']) ? URL::site(sprintf('/%s/menu',$branch['name'])) : $branch['attr_href']),
|
|
)
|
|
);
|
|
}
|
|
|
|
return parent::action_json($data);
|
|
}
|
|
}
|
|
?>
|