$board_menu_links_check = array();
 while ($row = $db->sql_fetchrow($result)) {
     $bl_links[] = $row['bl_id'];
     $board_menu_links = $row['bl_img'] != '' ? '<img src="' . get_bl_theme() . $row['bl_img'] . '" border="0" />&nbsp;' : '';
     if (substr($row['bl_link'], 0, 10) != 'javascript') {
         $board_menu_links .= '<a href="' . append_sid($row['bl_link'] . '.' . $phpEx . ($row['bl_parameter'] != '' ? '?' . $row['bl_parameter'] : ''));
     } else {
         $board_menu_links .= '<a href="' . $row['bl_link'] . ($row['bl_parameter'] != '' ? '?' . $row['bl_parameter'] : '');
     }
     $board_menu_links .= '" class="mainmenu" title="' . $lang[$row['bl_name']] . '">' . $lang[$row['bl_name']] . '</a>';
     $saved_link = $row['bl_id'];
     $board_menu_links_user[] = $board_menu_links;
     $board_menu_links_check[] = '<input type="checkbox" name="bl_id[]" value="' . $saved_link . '" checked="checked" />';
 }
 $db->sql_freeresult($result);
 $sql_access = get_bllink_access();
 $sql_where = '';
 if ($user_links_count != 0) {
     $sql_where = $sql_access != '' ? ' AND bl_id NOT IN (' . implode(',', $bl_links) . ')' : 'WHERE bl_id NOT IN (' . implode(',', $bl_links) . ')';
 }
 $sql = 'SELECT * FROM ' . BOARD_LINKS_TABLE . "\n        {$sql_access}\n        {$sql_where}\n        ORDER BY bl_dsort";
 if (!($result = $db->sql_query($sql))) {
     message_die(GENERAL_ERROR, 'Could not read board menu for user', '', __LINE__, __FILE__, $sql);
 }
 while ($row = $db->sql_fetchrow($result)) {
     $board_menu_links = $row['bl_img'] != '' ? '<img src="' . get_bl_theme() . $row['bl_img'] . '" border="0" />&nbsp;' : '';
     if (substr($row['bl_link'], 0, 10) != 'javascript') {
         $board_menu_links .= '<a href="' . append_sid($row['bl_link'] . '.' . $phpEx . ($row['bl_parameter'] != '' ? '?' . $row['bl_parameter'] : ''));
     } else {
         $board_menu_links .= '<a href="' . $row['bl_link'] . ($row['bl_parameter'] != '' ? '?' . $row['bl_parameter'] : '');
     }
 function imp_menu_block_func()
 {
     global $template, $portal_config, $db, $userdata, $images, $lang, $phpEx, $cache, $phpbb_root_path;
     include_once $phpbb_root_path . 'includes/functions_menu.' . $phpEx;
     // Get the Menus
     if ($cache->exists('_menu_data')) {
         $menu_data = $cache->get('_menu_data');
     } else {
         $menu_data = array();
         $sql = "SELECT * FROM " . BOARD_LINKS_TABLE . " ORDER BY bl_dsort, bl_id";
         if (!($result = $db->sql_query($sql))) {
             message_die(GENERAL_ERROR, 'Could not read board menu for user', '', __LINE__, __FILE__, $sql);
         }
         while ($row = $db->sql_fetchrow($result)) {
             $menu_data[$row['bl_id']] = array();
             $menu_data[$row['bl_id']]['bl_img'] = $row['bl_img'];
             $menu_data[$row['bl_id']]['bl_name'] = $row['bl_name'];
             $menu_data[$row['bl_id']]['bl_parameter'] = $row['bl_parameter'];
             $menu_data[$row['bl_id']]['bl_link'] = $row['bl_link'];
             $menu_data[$row['bl_id']]['bl_level'] = $row['bl_level'];
             $menu_data[$row['bl_id']]['bl_dsort'] = $row['bl_dsort'];
         }
         $cache->put('_menu_data', $menu_data);
     }
     // Create the personal board menu
     if ($userdata['session_logged_in']) {
         $sql = "SELECT board_link as ID FROM " . USER_BOARD_LINKS_TABLE . "\n                WHERE user_id = " . $userdata['user_id'] . "\n                ORDER BY board_sort";
         if (!($result = $db->sql_query($sql))) {
             message_die(GENERAL_ERROR, 'Could not read board menu for user', '', __LINE__, __FILE__, $sql);
         }
         $user_links_count = $db->sql_numrows($result);
         if ($user_links_count > 0) {
             $menus = array();
             while ($row = $db->sql_fetchrow($result)) {
                 $menus[] = $row['ID'];
             }
             $db->sql_freeresult($result);
         }
     }
     $sqlwhereaccess = get_bllink_access();
     if (!$userdata['session_logged_in'] || $user_links_count == 0) {
         // Use the Default Menu
         if ($cache->exists('default_menu')) {
             $menus = $cache->get('default_menu');
         } else {
             /*
             $sql = "SELECT bl_id as ID FROM " . BOARD_LINKS_TABLE . "
                 WHERE bl_level = " . ANONYMOUS . "
                 ORDER BY bl_dsort";
             
             if ( !$result = $db->sql_query($sql) )
             {
                 message_die(GENERAL_ERROR, 'Could not read board menu for user', '', __LINE__, __FILE__, $sql);
             }
             */
             if (!$userdata['session_logged_in'] || $user_links_count == 0) {
                 $sql = "SELECT bl_id as ID FROM " . BOARD_LINKS_TABLE . "\n\t\t\t\t\t\t\t{$sqlwhereaccess}\n\t\t\t\t\t\t\tORDER BY bl_dsort";
                 if (!($result = $db->sql_query($sql))) {
                     message_die(GENERAL_ERROR, 'Could not read board menu for user', '', __LINE__, __FILE__, $sql);
                 }
             }
             $menus = array();
             while ($row = $db->sql_fetchrow($result)) {
                 $menus[] = $row['ID'];
             }
             $db->sql_freeresult($result);
         }
     }
     $board_menu_links = compile_menu($menu_data, $menus);
     $template->assign_vars(array('BOARD_MENU' => $board_menu_links));
 }