/**
  * 后台首页
  */
 public function index()
 {
     $where['display'] = 1;
     $menu = M("menu");
     $mlist = $menu->where($where)->order('listorder Asc')->select();
     $menulist = generateTree($mlist);
     $menu = C('W_NAME');
     $this->assign("menu", $menu);
     $this->assign("menulist", $menulist);
     $this->display();
 }
Example #2
0
File: tree.php Project: qquk/IBAG2
function generateTree($parent_id)
{
    $sql = "SELECT * FROM articles WHERE div_id = " . $_GET['div_id'] . " AND parent_id = " . $parent_id . " ORDER BY artname COLLATE latin1_general_ci";
    $result = mysql_query($sql) or die(mysql_error());
    $arr = array();
    while ($row = mysql_fetch_array($result)) {
        $children = generateTree($row['art_id']);
        $arr[] = array('id' => $row['art_id'], 'text' => iconv("Windows-1251", "UTF-8", $row['artname']), 'leaf' => !(bool) count($children), 'children' => $children);
    }
    return $arr;
}
Example #3
0
function generateTree($m, $name = 'child', $f_id = 0)
{
    $arr = array();
    foreach ($m as $v) {
        if ($v['parent_id'] == $f_id) {
            $v[$name] = generateTree($m, $name, $v['id']);
            $arr[] = $v;
        }
    }
    return $arr;
}
Example #4
0
function generateTree($arr, $id, $deep=1){
	static $list = array();
	foreach($arr as $key => $value){
		if($value['pid'] == $id){
			echo str_repeat('|-', $deep).$arr[$key]['area'].'<br />';
			$list[] = $value;
			generateTree($arr,$value['id'], $deep+1);
		}
	}

	return $list;

}
 public function getCategoryTree()
 {
     $cate = F('category');
     $cateTreeData = generateTree($cate);
     $this->assign('cateTreeData', $cateTreeData);
 }
 /**
  * Introduction: 修改角色
  * User: arpeng
  * Date: 15/11/12
  * Time: 09:00
  * Last date: 15/11/14 09:00
  * Last user: arpeng
  */
 public function update()
 {
     $id = I('post.id');
     $data = I('post.data');
     $authRule = D('AuthRule', 'Logic');
     $logic = D('AuthGroup', 'Logic');
     if (!$id) {
         $id = $data['id'];
         unset($data['id']);
         $this->ajaxReturn($logic::update(['id' => $id], $data));
     } else {
         $this->data = $data = $logic::getOneData(['id' => $id]);
         $checked = explode(',', $data['rules']);
         $rule = $authRule::getData('', '0,100000', 'id,title,pid');
         foreach ($rule as $v) {
             $rules[$v['id']] = $v;
         }
         $rules = generateTree($rules);
         $this->ruleTree = self::getHtmlTree($rules, $checked);
         $this->display();
     }
 }
 public function loadMenu()
 {
     //只能是Ajax请求
     !IS_AJAX || !IS_POST && $this->ajaxReturn(['code' => 300, 'info' => '非法请求']);
     $menuid = I('post.menuid') ? I('post.menuid') : 0;
     $level = I('post.level') ? I('post.level') : false;
     !$level && $this->ajaxReturn(['code' => 300, 'info' => '请传入菜单等级参数']);
     $aurhRuleLogic = D('AuthRule', 'Logic');
     $fileds = 'id,pid,title,name,icon,child,cpath,ismenu';
     //需要获取的字段
     //如果是加载第三级菜单则需要把第四级菜单一起加载出来
     if ($level == 2) {
         //获取第三级ID
         $path = $aurhRuleLogic::getMenus('id = ' . $menuid, 'cpath');
         $cpath = explode(',', $path[0]['cpath']);
         unset($cpath[array_search($menuid, $cpath)]);
         $cpath = implode(',', $cpath);
         $where = 'id IN(' . $cpath . ')';
         //获取第三级数据
         $this->menu = $aurhRuleLogic::getMenus($where, $fileds);
         //获取第四级所有ID
         $cpath = '';
         foreach ($this->menu as $k => $v) {
             $cpath .= ',' . $v['cpath'];
         }
         //去除重复ID
         $cpath = $cpath . ',' . $path[0]['cpath'];
         $cpath = explode(',', $cpath);
         unset($cpath[array_search($menuid, $cpath)]);
         $cpath = implode(',', $cpath);
         $cpath = array_unique(explode(',', $cpath));
         $cpath = trim(implode(',', $cpath), ',');
         $where = 'id IN(' . $cpath . ')';
     } else {
         $where = "pid = " . $menuid;
     }
     $menus = $aurhRuleLogic::getMenus($where, $fileds);
     foreach ($menus as $v) {
         if ($this->AUTH->check($v['name'], session('uid'))) {
             //权限过滤
             $menu[] = $v;
         }
     }
     $this->menu = $menu;
     switch ($level) {
         case 1:
             $this->display('Index/menu/second');
             break;
         case 2:
             $newarr = [];
             foreach ($this->menu as $k => $v) {
                 $newarr[$v['id']] = $v;
             }
             $this->menu = generateTree($newarr, 'children');
             $this->display('Index/menu/third');
             break;
         default:
             $this->ajaxReturn(['code' => 300, 'info' => '请传入菜单等级参数']);
             break;
     }
 }
Example #8
0
function generateTree(&$node)
{
    $hasChildren = count($node['children']) > 0;
    $expandButton = $hasChildren ? '<span class="fn-expand" id="fn-' . $node['functionId'] . '">[+] </span>' : '----';
    // parse params
    $params = '';
    if ($node['paramCount'] > 0) {
        $maxLen = 80;
        $pArray = [];
        foreach ($node['params'] as $pItem) {
            $pArray[] = strlen($pItem) > $maxLen ? substr($pItem, 0, $maxLen) . '...' : $pItem;
        }
        $params = implode(', ', $pArray);
    }
    if ($params == '' && $node['includeFile'] != '') {
        $params = $node['includeFile'];
    }
    $filePath = $node['filePath'];
    $filePath = str_replace('/var/www/tala', '', $filePath);
    $timeCost = isset($node['timeCost']) ? number_format($node['timeCost'], 5) . 's' : '';
    // render
    echo "<li><div class='fn-line'>" . $expandButton . "<span class='fn-id'>#{$node['functionId']}</span> <span class='fn-time'>{$timeCost}</span><span\n        class='fn-file'>{$filePath} [line {$node['lineNumber']}]</span>:\n        <span class='fn-name'>{$node['functionName']}(<span class='fn-params'>{$params}</span>)</span></div>";
    if ($hasChildren) {
        echo "<ul class='fn-sub hidden' id='sub-fn-{$node['functionId']}'>";
        foreach ($node['children'] as &$item) {
            generateTree($item);
        }
        echo "</ul>";
    }
    echo "</li>";
}