function format_menu($data, $parent = 0) { static $i = 1; $start = 0; $tab = str_repeat("\t\t", $i); if (isset($data[$parent])) { $start++; $html = $start == 1 ? "\n{$tab}<ul id='menu'>" : "\n{$tab}<ul>"; $i++; foreach ($data[$parent] as $v) { //$child = get_menu($data, $v->id); $child = format_menu($data, $v->NID); $html .= $child ? "\n\t{$tab}<li class='node'>" : "\n\t{$tab}<li>"; //$html .= '<a href="'.$v->url.'">'.$v->title.'</a>'; $url = ''; $url .= isset($v->CI_PATH) ? $v->CI_PATH : ''; $url .= '/' . $v->CI_CONTROLLER; $url .= !isset($v->CI_FUNC_CONTROLLER) || $v->CI_FUNC_CONTROLLER == 'index' ? '' : '/' . $v->CI_FUNC_CONTROLLER; $url = site_url($url); if ($v->IS_MAIN) { $html .= '<a href="' . $url . '" ' . ($child ? '' : ' class="' . $v->ICON_CLASS . '"') . '>' . $v->CMENU . '</a>'; } else { $html .= '<a href="#" onclick="javascript:window.open(\'' . site_url() . '' . $v->CI_CONTROLLER . '/' . $module . '\',\'' . $module . '\',500,500);"' . ($child ? '' : ' class="' . $v->ICON_CLASS . '"') . ')>' . $v->CMENU . '</a>'; } if ($child) { $i--; $html .= $child; $html .= "\n\t{$tab}"; } $html .= '</li>'; } $html .= "\n{$tab}</ul>"; return $html; } else { return false; } }
<?php if (b_logged()) { $data = load_menus(); $menu = format_menu($data); ?> <div id="header-box"> <div id="module-status"> <span class="loggedin-users">Login as <?php echo $this->session->userdata('SESS_USER_NAME'); ?> </span> <a href='<?php echo base_url(); ?> '><span class="panel">Panel</span></a> <a href='<?php echo base_url() . '/auth/logout'; ?> '><span class="logout">logout</span></a> </div> <div id="module-menu"> <?php echo $menu; ?> </div> <div class='clr'></div> </div> <?php }