function create_list() { $link = mysql_connect(HOST, USER, PASSWORD); mysql_select_db(DATABASE, $link); $refs = array(); $list = array(); $sql = "SELECT menu_item_id, menu_parent_id,menu_url, menu_item_name FROM menu_items ORDER BY menu_item_name"; $result = mysql_query($sql); while ($data = @mysql_fetch_assoc($result)) { $thisref =& $refs[$data['menu_item_id']]; $thisref['menu_parent_id'] = $data['menu_parent_id']; $thisref['menu_item_name'] = $data['menu_item_name']; $thisref['menu_url'] = $data['menu_url']; $thisref['menu_item_id'] = $data['menu_item_id']; if ($data['menu_parent_id'] == 0) { $list[$data['menu_item_id']] =& $thisref; } else { $refs[$data['menu_parent_id']]['children'][$data['menu_item_id']] =& $thisref; } } $idUser = $_SESSION['user_id']; $sqlTwo = "SELECT idMenu FROM menuUser where idUser={$idUser}"; $resulta = mysql_query($sqlTwo); while ($datasa = @mysql_fetch_assoc($resulta)) { $lista[] = $datasa['idMenu']; } foreach ($list as $key => $v) { if (in_array($v['menu_item_id'], $lista)) { $ke[] = array('url' => $v['menu_url'], 'descripcion' => utf8_encode($v['menu_item_name']), 'hijos' => hijos($v['children'])); } } return $ke; }
function dibujarMenu($menu, $id = 0) { $salida = ''; if (esPadre($menu, $id)) { $salida .= '<ul' . ($id == 0 ? ' id="navigation"' : '') . '>' . PHP_EOL; foreach (hijos($menu, $id) as $hijo) { $salida .= '<li>' . PHP_EOL; $salida .= '<a '; $salida .= $hijo['accion'] != '' ? 'href="' . base_url() . "{$hijo['accion']}\"" : ''; $salida .= ">{$hijo['nombre']}</a>" . PHP_EOL; $salida .= dibujarMenu($menu, $hijo['id']); $salida .= '</li>' . PHP_EOL; } $salida .= '</ul>' . PHP_EOL; } return $salida; }