2010-11-29 22:41:08 +00:00
|
|
|
<?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
|
|
|
|
*/
|
2012-01-29 10:08:54 +00:00
|
|
|
class Controller_Tree extends lnApp_Controller_Tree {
|
2010-11-29 22:41:08 +00:00
|
|
|
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.
|
|
|
|
*
|
2011-09-24 13:13:38 +00:00
|
|
|
* @param array $data Tree data passed in by inherited methods
|
2010-11-29 22:41:08 +00:00
|
|
|
*/
|
2011-09-24 13:13:38 +00:00
|
|
|
public function action_json(array $data=array()) {
|
2010-11-29 22:41:08 +00:00
|
|
|
// Get the user details
|
2011-09-24 13:13:38 +00:00
|
|
|
$id = (is_null($this->request->param('id')) AND isset($_REQUEST['id'])) ? substr($_REQUEST['id'],2) : $this->request->param('id');
|
2010-11-29 22:41:08 +00:00
|
|
|
$user = Auth::instance()->get_user();
|
|
|
|
|
2011-08-31 06:54:44 +00:00
|
|
|
if ($user) {
|
|
|
|
if (! $id) {
|
|
|
|
$modules = array();
|
|
|
|
foreach ($user->groups() as $go)
|
2011-09-24 13:13:38 +00:00
|
|
|
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;
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2011-09-28 06:46:22 +00:00
|
|
|
Sort::MAsort($modules,'name');
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2011-09-24 13:13:38 +00:00
|
|
|
foreach ($modules as $id => $mo)
|
|
|
|
if (! $mo->parent_id)
|
|
|
|
array_push($data,array('id'=>$id,'name'=>$mo->name,'state'=>'closed'));
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2011-08-31 06:54:44 +00:00
|
|
|
} else {
|
2011-10-14 07:09:52 +00:00
|
|
|
$idx = NULL;
|
2011-10-14 05:44:12 +00:00
|
|
|
if (preg_match('/_/',$id))
|
|
|
|
list($id,$idx) = explode('_',$id,2);
|
2011-10-14 07:09:52 +00:00
|
|
|
|
2012-11-09 23:13:57 +00:00
|
|
|
$mo = ORM::factory('Module',$id);
|
2011-09-24 13:13:38 +00:00
|
|
|
|
2011-08-31 06:54:44 +00:00
|
|
|
$methods = array();
|
2011-09-24 13:13:38 +00:00
|
|
|
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;
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2011-09-28 06:46:22 +00:00
|
|
|
Sort::MASort($modules,'name');
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2011-10-14 07:09:52 +00:00
|
|
|
$subdata = array();
|
2011-09-24 13:13:38 +00:00
|
|
|
foreach ($methods as $id => $mmo) {
|
|
|
|
if (preg_match('/_/',$mmo->name)) {
|
|
|
|
list($mode,$action) = explode('_',$mmo->name);
|
2011-10-07 01:00:34 +00:00
|
|
|
$url = URL::site(sprintf('%s/%s/%s',$mode,$mmo->module->name,$action));
|
2011-09-24 13:13:38 +00:00
|
|
|
} else {
|
2011-10-07 01:00:34 +00:00
|
|
|
$url = URL::site(sprintf('%s/%s',$mmo->module->name,$mmo->name));
|
2011-09-24 13:13:38 +00:00
|
|
|
}
|
2011-08-31 06:54:44 +00:00
|
|
|
|
2011-10-14 07:09:52 +00:00
|
|
|
// We can split our menus into sub menus using the _ char.
|
|
|
|
if (preg_match('/_/',$mmo->name)) {
|
|
|
|
list($sub,$name) = explode('_',$mmo->name,2);
|
|
|
|
$subdata[$sub][$name]['name'] = preg_replace('/^(.*: )/','',$mmo->notes);
|
|
|
|
$subdata[$sub][$name]['id'] = sprintf('%s_%s',$mmo->module_id,$id);
|
|
|
|
$subdata[$sub][$name]['href'] = (empty($details['page']) ? $url : $details['page']);
|
2012-08-01 12:43:33 +00:00
|
|
|
|
2011-10-14 07:09:52 +00:00
|
|
|
} else {
|
|
|
|
// We dont want to show these items again, if we can through on a submenu
|
|
|
|
if (! $idx)
|
|
|
|
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'])
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If our sub menus only have 1 branch, then we'll display it as normal.
|
|
|
|
if (count($subdata) == 1) {
|
|
|
|
$sk = array_keys($subdata);
|
|
|
|
$idx = array_shift($sk);
|
2011-09-24 13:13:38 +00:00
|
|
|
}
|
2011-10-14 07:09:52 +00:00
|
|
|
|
|
|
|
if ($idx)
|
|
|
|
foreach ($subdata[$idx] as $k=>$v) {
|
|
|
|
array_push($data,array(
|
|
|
|
'id'=>$v['id'],
|
|
|
|
'name'=>$v['name'],
|
|
|
|
'state'=>'none',
|
|
|
|
'attr_id'=>$v['id'],
|
|
|
|
'attr_href'=>$v['href']
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
foreach ($subdata as $t=>$x)
|
2011-10-14 05:44:12 +00:00
|
|
|
array_push($data,array('id'=>$mmo->module_id.'_'.$t,'name'=>$t,'state'=>'closed'));
|
2011-10-14 07:09:52 +00:00
|
|
|
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-14 07:35:33 +00:00
|
|
|
$this->output = array();
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
foreach ($data as $branch) {
|
2011-05-14 07:35:33 +00:00
|
|
|
array_push($this->output,array(
|
2010-11-29 22:41:08 +00:00
|
|
|
'attr'=>array('id'=>sprintf('B_%s',$branch['id'])),
|
|
|
|
'state'=>$branch['state'],
|
|
|
|
'data'=>array('title'=>$branch['name']),
|
2011-10-07 01:00:34 +00:00
|
|
|
'attr'=>array('id'=>sprintf('N_%s',$branch['id']),'href'=>empty($branch['attr_href']) ? URL::site(sprintf('%s/menu',$branch['name'])) : $branch['attr_href']),
|
2010-11-29 22:41:08 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2011-07-13 22:59:32 +00:00
|
|
|
|
2011-09-24 13:13:38 +00:00
|
|
|
return parent::action_json($data);
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|