function main($module_id, $mode) { global $db, $user, $auth, $template, $cache, $request; global $config, $SID, $phpbb_root_path, $phpbb_admin_path, $phpEx, $k_config, $table_prefix, $cache; include_once $phpbb_root_path . 'ext/phpbbireland/portal/config/constants.' . $phpEx; if (!function_exists('obtain_k_config')) { include $phpbb_root_path . 'ext/phpbbireland/portal/includes/functions.' . $phpEx; $k_config = obtain_k_config(); } $img_path = $phpbb_root_path . 'ext/phpbbireland/portal/images/block_images/block/'; $img_path_acp = $phpbb_root_path . 'ext/phpbbireland/portal/adm/images/'; $portal_js = $phpbb_root_path . 'ext/phpbbireland/portal/js/portal.js'; $user->add_lang_ext('phpbbireland/portal', 'k_pages'); $this->tpl_name = 'acp_pages'; $this->page_title = $user->lang['ACP_PAGES']; add_form_key('pages'); if (!class_exists('sgp_functions_admin')) { require $phpbb_root_path . 'ext/phpbbireland/portal/includes/sgp_functions_admin.' . $phpEx; $sgp_functions_admin = new sgp_functions_admin(); } $mode = $request->variable('mode', ''); $page_id = $request->variable('page_id', 0); $action = $request->variable('config', ''); $tag_id = $request->variable('tag_id', ''); $current_pages = array(); $submit = false; if ($request->is_set_post('submit')) { if (!check_form_key('pages')) { $submit = false; $mode = ''; trigger_error('FORM_INVALID'); } $submit = true; } if ($tag_id != '') { $mode = 'add'; } switch ($action) { case 'config': $template->assign_var('MESSAGE', $user->lang['SWITCHING']); meta_refresh(1, append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=k_vars&mode=config&switch=k_pages")); break; default: break; } if ($submit && !check_form_key('pages')) { $submit = false; $mode = ''; trigger_error($user->lang['FORM_INVALID'] . basename(dirname(__FILE__)) . '/' . basename(__FILE__) . $user->lang['LINE'] . __LINE__); } if ($submit) { $mod_pages = $request->variable('k_mod_folders', ''); // trap trailing commas in mod pages // if ($mod_pages && $mod_pages[strlen($mod_pages) - 1] == ',') { trigger_error($user->lang['TRAILING_COMMA'] . adm_back_link(append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=manage")), E_USER_WARNING); } // We check to see the mod folder exists, if not return... // $mod_pages = str_replace(' ', '', $mod_pages); // has mod folder been updated/modified // if (strcmp($mod_pages, $k_config['k_mod_folders'] != 0)) { $mods_folder_array = explode(',', $mod_pages); foreach ($mods_folder_array as $folder) { $folder = trim($folder); if (!file_exists($phpbb_root_path . $folder)) { $submit = false; $mod_pages = ''; trigger_error($user->lang['NO_MOD_FOLDER'] . $folder . adm_back_link(append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=manage")), E_USER_WARNING); } } $template->assign_vars(array('MESSAGE' => $user->lang['FOLDER_ADDED'])); } $sgp_functions_admin->sgp_acp_set_config('k_mod_folders', $mod_pages); } $template->assign_vars(array('U_BACK' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=manage"), 'U_ADD' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=add"), 'U_MANAGE' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=manage"), 'S_OPT' => 'S_MANAGE', 'S_PAGE' => isset($k_config['k_landing_page']) ? $k_config['k_landing_page'] : 'portal', 'IMG_PATH_ACP' => $img_path_acp)); switch ($mode) { case 'delete': $page_name = get_page_filename($page_id); if (confirm_box(true)) { $sql = 'DELETE FROM ' . K_PAGES_TABLE . ' WHERE page_id = ' . (int) $page_id; if (!($result = $db->sql_query($sql))) { trigger_error($user->lang['ERROR_PORTAL_PAGES'] . basename(dirname(__FILE__)) . '/' . basename(__FILE__) . $user->lang['LINE'] . __LINE__); } $cache->destroy('sql', K_PAGES_TABLE); $template->assign_vars(array('S_OPTION' => 'processing', 'MESSAGE' => $user->lang['REMOVING_PAGES'] . $page_name)); meta_refresh(1, append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=manage")); break; } else { confirm_box(false, sprintf("%s (%s)", $user->lang['DELETE_FROM_LIST'], $page_name), build_hidden_fields(array('id' => $page_id, 'mode' => $mode, 'action' => 'delete'))); } $template->assign_var('MESSAGE', $user->lang['ACTION_CANCELLED']); meta_refresh(1, append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=manage")); break; case 'add': if ($submit) { // drop extension $tag_id = str_replace('.php', '', $tag_id); // skip the spacer // if ($tag_id == '..') { $template->assign_vars(array('S_OPTION' => 'processing', 'MESSAGE' => sprintf($user->lang['ERROR_PAGE'], $tag_id))); meta_refresh(2, append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=manage")); return; } if (in_array($tag_id, $current_pages)) { break; } $sql_array = array('page_name' => $tag_id); $db->sql_query('INSERT INTO ' . K_PAGES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_array)); meta_refresh(1, append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=manage")); $template->assign_vars(array('S_OPTION' => 'processing', 'MESSAGE' => $user->lang['ADDING_PAGES'])); $cache->destroy('sql', K_PAGES_TABLE); break; } break; case 'land': $page_name = get_page_filename($page_id); $sgp_functions_admin->sgp_acp_set_config('k_landing_page', $page_name, 1); $template->assign_vars(array('S_OPTION' => 'processing', 'MESSAGE' => $user->lang['LANDING_PAGE_SET'] . ': ' . $page_name)); $cache->destroy('k_config'); $cache->destroy('sql', K_VARS_TABLE); meta_refresh(1, append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=manage")); break; case 'config': break; case 'manage': get_all_available_files(); get_pages_data(); break; case 'default': break; } $template->assign_var('U_ACTION', $this->u_action); }
function main($module_id, $mode) { global $db, $user, $auth, $template, $cache, $request; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx, $k_config, $table_prefix, $phpEx, $sgp_functions_admin; include_once $phpbb_root_path . 'ext/phpbbireland/portal/config/constants.' . $phpEx; include_once $phpbb_root_path . 'ext/phpbbireland/portal/helpers/tables.' . $phpEx; if (!class_exists($sgp_functions_admin)) { include_once $phpbb_root_path . 'ext/phpbbireland/portal/includes/sgp_functions_admin.' . $phpEx; } $sgp_functions_admin = new sgp_functions_admin(); $user->add_lang_ext('phpbbireland/portal', 'k_variables'); $this->tpl_name = 'acp_vars'; $this->page_title = $user->lang['ACP_VARS_TITLE']; add_form_key('blocks_vars'); if ($request->is_set_post('submit')) { if (!check_form_key('blocks_vars')) { $submit = false; $mode = ''; trigger_error('FORM_INVALID'); } $submit = true; } $choice = $request->variable('switch', ''); $block = $request->variable('block', 0); $mode = $request->variable('mode', ''); $switch = $request->variable('switch', ''); if ($mode = 'manage' && $choice == '') { $choice = 'manage'; } if (isset($block)) { $sql = "SELECT id, title, var_file_name\n\t\t\t\tFROM " . K_BLOCKS_TABLE . "\n\t\t\t\tWHERE id = " . (int) $block; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $title = strtoupper($row['title']); $title = str_replace(' ', '_', $row['title']); $block_id = $row['id']; $var_file_name = $row['var_file_name']; $db->sql_freeresult($result); $sgp_functions_admin->get_all_groups(); $sgp_functions_admin->get_teams_sort(); } $block = !empty($block) ? $block : 0; $action = $request->variable('action', ''); $submit = isset($_POST['submit']) ? true : false; // swicth to other var setups 11 March 2010 if ($switch) { $sgp_functions_admin->get_reserved_words(); $var_file_name = $switch; } $template->assign_vars(array('S_SWITCH' => $var_file_name)); if ($submit && !check_form_key('blocks_vars')) { trigger_error($user->lang['FORM_INVALID']); } $sql = 'SELECT config_name, config_value FROM ' . K_VARS_TABLE; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $k_config[$row['config_name']] = $row['config_value']; $template->assign_var('S_' . strtoupper($row['config_name']), $row['config_value']); } $db->sql_freeresult($result); $template->assign_vars(array('S_OPT' => 'manage', 'MESSAGE' => '')); if ($submit) { $mode = 'save'; } else { $mode = 'reset'; } switch ($mode) { case 'save': $k_allow_acronyms = $request->variable('k_allow_acronyms', 0); $k_allow_rand_avatar = $request->variable('k_allow_rand_avatar', 0); $k_allow_rotating_logos = $request->variable('k_allow_rotating_logos', 1); $k_blocks_display_globally = $request->variable('k_blocks_display_globally', 1); $k_footer_images_allow = $request->variable('k_footer_images_allow', 1); $k_links_forum_id = $request->variable('k_links_forum_id', ''); $k_ma_avatar_max_width = $request->variable('k_ma_avatar_max_width', '90'); $k_ma_columns = $request->variable('k_ma_columns', '5'); $k_ma_display_logged_in_only = $request->variable('k_ma_display_logged_in_only', '0'); $k_ma_max_avatars = $request->variable('k_ma_max_avatars', '0'); $k_ma_rows = $request->variable('k_ma_rows', '1'); $k_ma_user_active = $request->variable('k_ma_user_active', '0'); $k_ma_user_has_posted = $request->variable('k_ma_user_has_posted', '0'); $k_max_block_avatar_height = $request->variable('k_max_block_avatar_height', 0); $k_max_block_avatar_width = $request->variable('k_max_block_avatar_width', 0); $k_max_block_avatar_width = $request->variable('k_max_block_avatar_width', 0); $k_post_types = $request->variable('k_post_types', ''); $k_recent_topics_search_exclude = $request->variable('k_recent_topics_search_exclude', ''); $k_quick_reply = $request->variable('k_quick_reply', 1); $k_smilies_show = $request->variable('k_smilies_show', 1); $k_tooltips_active = $request->variable('k_tooltips_active', 1); $k_tooltips_which = $request->variable('k_tooltips_which', 0); $k_announce_type = $request->variable('k_announce_type', ''); $k_announce_allow = $request->variable('k_announce_allow', 1); $k_announce_item_max_length = $request->variable('k_announce_item_max_length', 0); $k_announce_to_display = $request->variable('k_announce_to_display', 5); $k_bots_to_display = $request->variable('k_bots_to_display', 10); $k_block_cache_time_default = $request->variable('k_block_cache_time_default', 600); $k_block_cache_time_fast = $request->variable('k_block_cache_time_fast', 10); $k_block_cache_time_short = $request->variable('k_block_cache_time_short', 10); $k_bot_display_allow = $request->variable('k_bot_display_allow', 1); $k_donations_max = $request->variable('k_donations_max', '100'); $k_donations_years = $request->variable('k_donations_years', '2000'); $k_last_online_max = $request->variable('k_last_online_max', 5); $k_links_to_display = $request->variable('k_links_to_display', 5); $k_news_type = $request->variable('k_news_type', ''); $k_news_allow = $request->variable('k_news_allow', 1); $k_news_items_to_display = $request->variable('k_news_items_to_display', 5); $k_news_item_max_length = $request->variable('k_news_item_max_length', 0); $k_recent_topics_to_display = $request->variable('k_recent_topics_to_display', 10); $k_recent_topics_per_forum = $request->variable('k_recent_topics_per_forum', 5); $k_recent_search_days = $request->variable('k_recent_search_days', 7); $k_referrals_to_display = $request->variable('k_referrals_to_display', ''); $k_teams = $request->variable('k_teams', ''); $k_teams_display_this_many = $request->variable('k_teams_display_this_many', 1); $k_teampage_memberships = $request->variable('k_teampage_memberships', 0); $k_teams_sort = $request->variable('k_teams_sort', ''); $k_top_downloads_per_forum = $request->variable('k_top_downloads_per_forum', 0); $k_top_downloads_search_days = $request->variable('k_top_downloads_search_days', 0); $k_top_downloads_search_exclude = $request->variable('k_top_downloads_search_exclude', ''); $k_top_downloads_to_display = $request->variable('k_top_downloads_to_display', 5); $k_top_downloads_types = $request->variable('k_top_downloads_types', ''); $k_top_posters_to_display = $request->variable('k_top_posters_to_display', 5); $k_top_topics_days = $request->variable('k_top_topics_days', 7); $k_top_topics_max = $request->variable('k_top_topics_max', 5); $k_yourtube_link = $request->variable('k_yourtube_link', ''); $k_yourtube_auto = $request->variable('k_yourtube_auto', 1); $k_yourtube_link_limit = $request->variable('k_yourtube_link_limit', 5); if ($k_ma_rows <= 0) { $k_ma_rows = 1; } if ($k_max_block_avatar_width == 0 || $k_max_block_avatar_height == 0) { $k_max_block_avatar_width = $config['avatar_max_width']; $k_max_block_avatar_height = $config['avatar_max_height']; } else { if ($k_max_block_avatar_width > $config['avatar_max_width'] || $k_max_block_avatar_height > $config['avatar_max_height']) { $k_max_block_avatar_width = $config['avatar_max_width']; $k_max_block_avatar_height = $config['avatar_max_height']; } } switch ($k_announce_type) { case 2: $k_announce_type = POST_ANNOUNCE; break; case 3: $k_announce_type = POST_GLOBAL; break; default: $k_announce_type = 0; break; } switch ($k_news_type) { case 4: $k_news_type = POST_NEWS; break; case 5: $k_news_type = POST_NEWS_GLOBAL; break; default: $k_news_type = 0; break; } // all data is escaped in $sgp_functions_admin->sgp_acp_set_config // $sgp_functions_admin->sgp_acp_set_config('k_allow_rotating_logos', $k_allow_rotating_logos); $sgp_functions_admin->sgp_acp_set_config('k_announce_allow', $k_announce_allow); $sgp_functions_admin->sgp_acp_set_config('k_bot_display_allow', $k_bot_display_allow); $sgp_functions_admin->sgp_acp_set_config('k_footer_images_allow', $k_footer_images_allow); $sgp_functions_admin->sgp_acp_set_config('k_announce_type', $k_announce_type); $sgp_functions_admin->sgp_acp_set_config('k_blocks_display_globally', $k_blocks_display_globally); $sgp_functions_admin->sgp_acp_set_config('k_smilies_show', $k_smilies_show); $sgp_functions_admin->sgp_acp_set_config('k_announce_to_display', $k_announce_to_display); $sgp_functions_admin->sgp_acp_set_config('k_bots_to_display', $k_bots_to_display); $sgp_functions_admin->sgp_acp_set_config('k_announce_item_max_length', $k_announce_item_max_length); $sgp_functions_admin->sgp_acp_set_config('k_links_forum_id', $k_links_forum_id); $sgp_functions_admin->sgp_acp_set_config('k_links_to_display', $k_links_to_display); $sgp_functions_admin->sgp_acp_set_config('k_news_allow', $k_news_allow); $sgp_functions_admin->sgp_acp_set_config('k_news_type', $k_news_type); $sgp_functions_admin->sgp_acp_set_config('k_news_items_to_display', $k_news_items_to_display); $sgp_functions_admin->sgp_acp_set_config('k_news_item_max_length', $k_news_item_max_length); $sgp_functions_admin->sgp_acp_set_config('k_post_types', $k_post_types); $sgp_functions_admin->sgp_acp_set_config('k_recent_topics_to_display', $k_recent_topics_to_display); $sgp_functions_admin->sgp_acp_set_config('k_recent_topics_per_forum', $k_recent_topics_per_forum); $sgp_functions_admin->sgp_acp_set_config('k_recent_topics_search_exclude', $k_recent_topics_search_exclude); $sgp_functions_admin->sgp_acp_set_config('k_recent_search_days', $k_recent_search_days); $sgp_functions_admin->sgp_acp_set_config('k_teams', $k_teams); $sgp_functions_admin->sgp_acp_set_config('k_teams_display_this_many', $k_teams_display_this_many); $sgp_functions_admin->sgp_acp_set_config('k_teams_sort', $k_teams_sort); $sgp_functions_admin->sgp_acp_set_config('k_top_posters_to_display', $k_top_posters_to_display); $sgp_functions_admin->sgp_acp_set_config('k_top_topics_max', $k_top_topics_max); $sgp_functions_admin->sgp_acp_set_config('k_top_topics_days', $k_top_topics_days); $sgp_functions_admin->sgp_acp_set_config('k_referrals_to_display', $k_referrals_to_display); $sgp_functions_admin->sgp_acp_set_config('k_last_online_max', $k_last_online_max); $sgp_functions_admin->sgp_acp_set_config('k_quick_reply', $k_quick_reply); $sgp_functions_admin->sgp_acp_set_config('k_block_cache_time_default', $k_block_cache_time_default); $sgp_functions_admin->sgp_acp_set_config('k_block_cache_time_fast', $k_block_cache_time_fast); $sgp_functions_admin->sgp_acp_set_config('k_yourtube_link', $k_yourtube_link); $sgp_functions_admin->sgp_acp_set_config('k_yourtube_auto', $k_yourtube_auto); $sgp_functions_admin->sgp_acp_set_config('k_yourtube_link_limit', $k_yourtube_link_limit); $sgp_functions_admin->sgp_acp_set_config('k_block_cache_time_short', $k_block_cache_time_short); $sgp_functions_admin->sgp_acp_set_config('k_allow_acronyms', $k_allow_acronyms); $sgp_functions_admin->sgp_acp_set_config('k_max_block_avatar_width', $k_max_block_avatar_width); $sgp_functions_admin->sgp_acp_set_config('k_max_block_avatar_height', $k_max_block_avatar_height); $sgp_functions_admin->sgp_acp_set_config('k_teampage_memberships', $k_teampage_memberships); $sgp_functions_admin->sgp_acp_set_config('k_tooltips_active', $k_tooltips_active); $sgp_functions_admin->sgp_acp_set_config('k_tooltips_which', $k_tooltips_which); $sgp_functions_admin->sgp_acp_set_config('k_allow_rand_avatar', $k_allow_rand_avatar); $sgp_functions_admin->sgp_acp_set_config('k_donations_years', $k_donations_years); $sgp_functions_admin->sgp_acp_set_config('k_donations_max', $k_donations_max); $sgp_functions_admin->sgp_acp_set_config('k_top_downloads_to_display', $k_top_downloads_to_display); $sgp_functions_admin->sgp_acp_set_config('k_top_downloads_search_exclude', $k_top_downloads_search_exclude); $sgp_functions_admin->sgp_acp_set_config('k_top_downloads_search_days', $k_top_downloads_search_days); $sgp_functions_admin->sgp_acp_set_config('k_top_downloads_per_forum', $k_top_downloads_per_forum); $sgp_functions_admin->sgp_acp_set_config('k_top_downloads_types', $k_top_downloads_types); $sgp_functions_admin->sgp_acp_set_config('k_ma_max_avatars', $k_ma_max_avatars); $sgp_functions_admin->sgp_acp_set_config('k_ma_columns', $k_ma_columns); $sgp_functions_admin->sgp_acp_set_config('k_ma_rows', $k_ma_rows); $sgp_functions_admin->sgp_acp_set_config('k_ma_avatar_max_width', $k_ma_avatar_max_width); $sgp_functions_admin->sgp_acp_set_config('k_ma_display_logged_in_only', $k_ma_display_logged_in_only); $sgp_functions_admin->sgp_acp_set_config('k_ma_user_has_posted', $k_ma_user_has_posted); $sgp_functions_admin->sgp_acp_set_config('k_ma_user_active', $k_ma_user_active); $mode = 'reset'; $template->assign_vars(array('S_OPT' => 'saving', 'MESSAGE' => $user->lang['SAVED'])); $cache->destroy('_k_config'); $cache->destroy('sql', K_VARS_TABLE); if ($block) { meta_refresh(0, append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=manage&block=" . $block)); } else { meta_refresh(0, append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=manage&switch=" . $switch)); } return; case 'default': break; } switch ($action) { case 'submit': $mode = 'reset'; break; case 'default': break; } }
function main($module_id, $mode) { global $db, $user, $auth, $template, $cache, $request; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx, $k_config, $table_prefix; global $helper, $root_path, $php_ext, $content_visibility; $submit = $request->is_set_post('submit'); include_once $phpbb_root_path . 'ext/phpbbireland/portal/config/constants.' . $phpEx; include_once $phpbb_root_path . 'ext/phpbbireland/portal/helpers/tables.' . $phpEx; $this->cache_setup(); if (!class_exists('sgp_functions_admin')) { require $phpbb_root_path . 'ext/phpbbireland/portal/includes/sgp_functions_admin.' . $phpEx; $sgp_functions_admin = new sgp_functions_admin(); } $k_config = $cache->get('k_config'); $user->add_lang_ext('phpbbireland/portal', 'k_blocks'); $user->add_lang_ext('phpbbireland/portal', 'k_variables'); $this->tpl_name = 'acp_blocks'; $this->page_title = $user->lang['ACP_BLOCKS']; add_form_key('acp_blocks'); if ($request->is_set_post('submit')) { if (!check_form_key('acp_blocks')) { $submit = false; $mode = ''; trigger_error('FORM_INVALID'); } $submit = true; } // Do not write values if there is an error /* if (sizeof($error)) { $mode = ''; $submit = false; } */ // Can not use append_sid here, the $block_id is assigned to the html but unknow to this code // // Would require I add a form element and use $request->variable to retrieve it // $template->assign_vars(array('U_BACK' => $this->u_action, 'PORTAL_JS' => $portal_js, 'IMG_PATH' => $img_path_acp_block_icons, 'IMG_PATH_ACP' => $img_path_acp_icons, 'CSS_PATH' => $css_path_acp, 'U_MANAGE_PAGES' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=manage"))); $mode = $request->variable('mode', ''); $block = $request->variable('block', 0); // bold current row text so things are easier to follow when moving/editing etc... // if ($block ? $block : 0) { $sql = 'UPDATE ' . K_VARS_TABLE . ' SET config_value = ' . (int) $block . ' WHERE config_name = "k_adm_block"'; $db->sql_query($sql); } else { $sql = 'SELECT config_name, config_value FROM ' . K_VARS_TABLE . "\n\t\t\t\tWHERE config_name = 'k_adm_block'"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $k_config[$row['config_name']] = $row['config_value']; } $template->assign_var('K_ADM_BLOCK', $k_config['k_adm_block']); switch ($mode) { case 'up': case 'down': $ids = $ndxs = array(); $out_of_wack = false; // get current block data using $block var // $sql = "SELECT id, ndx, position\n\t\t\t\t\tFROM " . K_BLOCKS_TABLE . "\n\t\t\t\t\tWHERE id = " . (int) $block; $result = $db->sql_query_limit($sql, 1); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $current_id = $row['id']; $current_ndx = $row['ndx']; $position = $row['position']; // get current block data suing $block var // $sql = "SELECT *FROM " . K_BLOCKS_TABLE . "\n\t\t\t\t\tWHERE position = '" . $db->sql_escape($position) . "'" . "\n\t\t\t\t\tORDER BY ndx"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $ids[] = (int) $row['id']; $ndxs[] = (int) $row['ndx']; } $db->sql_freeresult($result); // are ndx sequential for ($i = 0; $i < ($count = count($ids)); $i++) { if ($ndxs[$i] != $i + 1) { $out_of_wack = true; } } if ($out_of_wack) { for ($i = 0; $i < ($count = count($ids)); $i++) { $ndxs[$i] = $i + 1; $sql = "UPDATE " . K_BLOCKS_TABLE . " SET ndx = " . $ndxs[$i] . " WHERE id = " . $ids[$i]; $results = $db->sql_query($sql); } $db->sql_freeresult($result); $template->assign_vars(array('S_BUTTON_HIDE' => true, 'BLOCK_REPORT' => $user->lang['BLOCKS_AUTO_REINDEXED'])); $cache->destroy('sql', K_BLOCKS_TABLE); meta_refresh(1, append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=" . $mode)); //meta_refresh(1, ($k_config['base']) ? $k_config['base'] : $this->u_action); return; } $to_move = $move_to = array(); // get current block data// $sql = "SELECT id, ndx, position\n\t\t\t\t\tFROM " . K_BLOCKS_TABLE . "\n\t\t\t\t\tWHERE id = " . (int) $block; if (!($result = $db->sql_query_limit($sql, 1))) { trigger_error($user->lang['ERROR_PORTAL_BLOCKS'] . basename(dirname(__FILE__)) . '/' . basename(__FILE__) . $user->lang['LINE'] . __LINE__); } // Added function to reindex blocks after a block deletion Dicky if (isset($current_position) && $current_position != $position) { $index_start = $this->get_lowest_ndx($current_position); $this->reindex_column($current_position, $index_start); } $row = $db->sql_fetchrow($result); $to_move['id'] = (int) $row['id']; $to_move['ndx'] = $temp = (int) $row['ndx']; // position is char 'L', 'R', 'C' (char) // $position = $row['position']; if ($mode == 'up') { $temp = $temp - 1; } if ($mode == 'down') { $temp = $temp + 1; } // get move_to block data// $sql = "SELECT id, ndx, position FROM " . K_BLOCKS_TABLE . "\n\t\t\t\t\tWHERE ndx = '" . (int) $temp . "'\n\t\t\t\t\t\tAND position = '" . $db->sql_escape($position) . "'"; if (!($result = $db->sql_query_limit($sql, 1))) { trigger_error($user->lang['BLOCK_MOVE_ERROR'] . basename(dirname(__FILE__)) . '/' . basename(__FILE__) . $user->lang['LINE'] . __LINE__); } $row = $db->sql_fetchrow($result); $move_to['id'] = (int) $row['id']; $move_to['ndx'] = (int) $row['ndx']; // fix block index if out of wack, reindex and re-run code // if ($move_to['ndx'] != $temp || $move_to['id'] == '') { $this->index_column_fix($position); $to_move = $move_to = array(); // get current block data// $sql = "SELECT id, ndx, position FROM " . K_BLOCKS_TABLE . "\n\t\t\t\t\t\tWHERE id = " . (int) $block; if (!($result = $db->sql_query_limit($sql, 1))) { trigger_error($user->lang['ERROR_PORTAL_BLOCKS'] . basename(dirname(__FILE__)) . '/' . basename(__FILE__) . $user->lang['LINE'] . __LINE__); } // Added function to reindex blocks after a block deletion Dicky if (isset($current_position) && $current_position != $position) { $index_start = $this->get_lowest_ndx($current_position); $this->reindex_column($current_position, $index_start); } $row = $db->sql_fetchrow($result); $to_move['id'] = (int) $row['id']; $to_move['ndx'] = (int) ($temp = $row['ndx']); $position = $row['position']; if ($mode == 'up') { $temp = $temp - 1; } if ($mode == 'down') { $temp = $temp + 1; } // get move_to block data// $sql = "SELECT id, ndx, position FROM " . K_BLOCKS_TABLE . "\n\t\t\t\t\t\tWHERE ndx = '" . (int) $temp . "'\n\t\t\t\t\t\t\tAND position = '" . $db->sql_escape($position) . "'"; if (!($result = $db->sql_query_limit($sql, 1))) { trigger_error($user->lang['BLOCK_MOVE_ERROR'] . basename(dirname(__FILE__)) . '/' . basename(__FILE__) . $user->lang['LINE'] . __LINE__); } $row = $db->sql_fetchrow($result); $move_to['id'] = (int) $row['id']; $move_to['ndx'] = (int) $row['ndx']; } if ($mode == 'up') { // sql is not duplicated $sql = "UPDATE " . K_BLOCKS_TABLE . " SET ndx = " . $to_move['ndx'] . " WHERE id = " . $move_to['id']; if (!($result = $db->sql_query($sql))) { trigger_error($user->lang['BLOCK_MOVE_ERROR'] . basename(dirname(__FILE__)) . '/' . basename(__FILE__) . $user->lang['LINE'] . __LINE__); } $sql = "UPDATE " . K_BLOCKS_TABLE . " SET ndx = " . $move_to['ndx'] . " WHERE id = " . $to_move['id']; if (!($result = $db->sql_query($sql))) { trigger_error($user->lang['BLOCK_MOVE_ERROR'] . basename(dirname(__FILE__)) . '/' . basename(__FILE__) . $user->lang['LINE'] . __LINE__); } } if ($mode == 'down') { // sql is not duplicated $sql = "UPDATE " . K_BLOCKS_TABLE . " SET ndx = " . $move_to['ndx'] . " WHERE id = " . $to_move['id']; if (!($result = $db->sql_query($sql))) { trigger_error($user->lang['BLOCK_MOVE_ERROR'] . basename(dirname(__FILE__)) . '/' . basename(__FILE__) . $user->lang['LINE'] . __LINE__); } $sql = "UPDATE " . K_BLOCKS_TABLE . " SET ndx = " . $to_move['ndx'] . " WHERE id = " . $move_to['id']; if (!($result = $db->sql_query($sql))) { trigger_error($user->lang['BLOCK_MOVE_ERROR'] . basename(dirname(__FILE__)) . '/' . basename(__FILE__) . $user->lang['LINE'] . __LINE__); } } $template->assign_var('BLOCK_REPORT', $user->lang['BLOCK_UPDATING']); if ($position) { $mode = $position; } else { $mode = 'manage'; } $cache->destroy('sql', K_BLOCKS_TABLE); meta_refresh(1, append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=" . $mode)); return; break; case 'add': if ($submit) { if ($request->variable('html_file_name', '') == "" || $request->variable('title', '') == "") { $message = $user->lang['MISSING_BLOCK_DATA']; $template->assign_var('BLOCK_REPORT', $message . '<br />'); meta_refresh(1, append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=add")); return; } $title = utf8_normalize_nfc($request->variable('title', '', true)); $position = $request->variable('position', ''); $active = $request->variable('active', 1); $type = $request->variable('type', ''); $scroll = $request->variable('scroll', 0); $view_groups = $request->variable('view_groups', ''); $view_all = $request->variable('view_all', 1); $view_pages = $request->variable('view_pages', ''); $html_file_name = $request->variable('html_file_name', ''); $var_file_name = $request->variable('var_file_name', ''); $img_file_name = $request->variable('img_file_name', ''); $has_vars = $request->variable('has_vars', 0); $minimod_based = $request->variable('minimod_based', 0); $mod_block_id = $request->variable('mod_block_id', 0); $block_cache_time = $request->variable('block_cache_time', 600); if ($html_file_name == '...') { $html_file_name = ''; } if ($has_vars == 0) { $var_file_name = ''; } if ($minimod_based == 0) { $mod_block_id = '0'; } $view_page_id = $request->variable('view_page_id', array(0)); for ($i = 0; $i < count($view_page_id); $i++) { $view_pages .= $view_page_id[$i]; if ($i < count($view_page_id) - 1) { $view_pages .= ','; } } $ndx = $this->get_next_ndx($position); // get the next ndx to use for this position // $sql_array = array('ndx' => $ndx, 'title' => $title, 'active' => $active, 'html_file_name' => $html_file_name, 'var_file_name' => $var_file_name, 'img_file_name' => $img_file_name, 'position' => $position, 'view_groups' => $view_groups, 'view_all' => $view_all, 'view_pages' => $view_pages, 'scroll' => $scroll, 'has_vars' => $has_vars, 'minimod_based' => $minimod_based, 'mod_block_id' => $mod_block_id, 'block_cache_time' => $block_cache_time); if (!$db->sql_query('INSERT INTO ' . K_BLOCKS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_array))) { trigger_error($user->lang['COULD_NOT_ADD_BLOCK'] . basename(dirname(__FILE__)) . '/' . basename(__FILE__) . $user->lang['LINE'] . __LINE__); } else { $message = $user->lang['BLOCK_ADDED']; $template->assign_var('BLOCK_REPORT', $title . $message . '<br />'); } $cache->destroy('sql', K_BLOCKS_TABLE); meta_refresh(1, append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=manage")); return; } else { $this->parse_all_groups(); $this->get_all_pages(0); $this->get_all_vars_files($block); //Get all installed blocks// $data = ''; $c = 0; $sql = 'SELECT * FROM ' . K_BLOCKS_TABLE; if ($result = $db->sql_query($sql)) { while ($row = $db->sql_fetchrow($result)) { $data .= $row['id']; $data .= ' '; $c++; } } $dirslist = '... '; // use ... for empty // $dirs = $this->dir_file_exists($phpbb_root_path . 'ext/phpbbireland/portal/styles/common/template/blocks/'); while ($file = $dirs->read()) { if ($file != '.' && $file != '..' && !stripos($file, ".bak") && strpos($file, 'lock_')) { $dirslist .= "{$file} "; } } closedir($dirs->handle); $dirslist = explode(" ", $dirslist); sort($dirslist); for ($i = 0; $i < sizeof($dirslist); $i++) { if ($dirslist[$i] != '') { $template->assign_block_vars('html_file_name', array('S_BLOCK_FILE_HTML' => $dirslist[$i])); } } $dirslist = ''; // use ... for empty // $dirs = $this->dir_file_exists($phpbb_root_path . 'ext/phpbbireland/portal/images/block_images/block'); while ($file = $dirs->read()) { if (stripos($file, ".gif") || stripos($file, ".png")) { $dirslist .= "{$file} "; } } closedir($dirs->handle); $dirslist = explode(" ", $dirslist); sort($dirslist); for ($i = 0; $i < sizeof($dirslist); $i++) { if ($dirslist[$i] != '') { $template->assign_block_vars('img_file_name', array('S_BLOCK_FILE_I' => $dirslist[$i])); } } $dirslist = ''; // pass default empty/blank image // $template->assign_vars(array('S_FNAME_I' => '_blank.gif', 'S_OPTIONS' => strtolower($mode))); } break; case 'edit': if ($submit) { $id = $request->variable('id', 0); $ndx = $request->variable('ndx', 0); $title = utf8_normalize_nfc($request->variable('title', '', true)); $position = $request->variable('position', ''); $type = $request->variable('type', ''); $active = $request->variable('active', 1); $view_groups = $request->variable('view_groups', ''); $view_all = $request->variable('view_all', 1); $view_pages = $request->variable('view_pages', ''); $scroll = $request->variable('scroll', 0); $has_vars = $request->variable('has_vars', 0); $minimod_based = $request->variable('minimod_based', 0); $mod_block_id = $request->variable('mod_block_id', 0); $html_file_name = $request->variable('html_file_name', ''); $var_file_name = $request->variable('var_file_name', ''); $img_file_name = $request->variable('img_file_name', ''); $block_cache_time = $request->variable('block_cache_time', 600); $view_page_id = $request->variable('view_page_id', array(0)); for ($i = 0; $i < count($view_page_id); $i++) { $view_pages .= $view_page_id[$i]; if ($i < count($view_page_id) - 1) { $view_pages .= ','; } } // this shoud not happen but just in case // if (!$id) { $template->assign_var('BLOCK_REPORT', $user->lang['UNKNOWN_ERROR']); $submit = false; return; } if ($type == 1) { $type = 'H'; //html } else { $type = 'B'; //bbcode } if ($view_all) { $view_groups = $sgp_functions_admin->get_all_groups(); if ($view_groups == '') { $view_groups = 0; } } if ($html_file_name == '...') { $html_file_name = ''; } if ($var_file_name == '...') { $var_file_name = ''; } /* if ($has_vars == 0) { $var_file_name = ''; }*/ if ($minimod_based == 0) { $mod_block_id = '0'; } // get the current block position // $current_position = $this->get_current_position($id); // if moving block position (column) // if ($current_position != $position) { $ndx = $this->get_next_ndx($position); } $sql_ary = array('ndx' => $ndx, 'active' => $active, 'title' => $title, 'position' => $position, 'type' => $type, 'html_file_name' => $html_file_name, 'var_file_name' => $var_file_name, 'img_file_name' => $img_file_name, 'view_groups' => $view_groups, 'view_pages' => $view_pages, 'view_all' => $view_all, 'scroll' => $scroll, 'has_vars' => $has_vars, 'minimod_based' => $minimod_based, 'mod_block_id' => $mod_block_id, 'block_cache_time' => $block_cache_time); $sql = 'UPDATE ' . K_BLOCKS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " WHERE id = " . (int) $id; if (!($result = $db->sql_query($sql))) { trigger_error($user->lang['COULD_NOT_EDIT_BLOCK'] . basename(dirname(__FILE__)) . '/' . basename(__FILE__) . $user->lang['LINE'] . __LINE__); } if ($has_vars) { $var_path = 'ext/phpbbireland/portal/acp/variables/'; $file = $var_file_name; $file = str_replace('.html', '.php', $file); if ($file == 'k_the_teams_vars.php') { $sgp_functions_admin->get_teams_sort(); } if (!file_exists($phpbb_root_path . $var_path . $file)) { trigger_error('NO_FILENAME' . $phpbb_root_path . $var_path . $file); } include_once $phpbb_root_path . $var_path . $file; } $template->assign_var('BLOCK_REPORT', $user->lang['SAVING']); $cache->destroy('sql', K_BLOCKS_TABLE); $this->delete_this_block_cached_file($html_file_name); if ($position) { $mode = $position; } else { $mode = 'manage'; } meta_refresh(1, append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=" . $mode)); return; } // search our common styles folder for all available html files // $dirslist = '... '; $dirs = $this->dir_file_exists($phpbb_root_path . 'ext/phpbbireland/portal/styles/common/template/blocks'); while ($file = $dirs->read()) { if ($file != '.' && $file != '..' && !stripos($file, ".bak")) { $dirslist .= "{$file} "; } } closedir($dirs->handle); $dirslist = explode(" ", $dirslist); sort($dirslist); for ($i = 0; $i < sizeof($dirslist); $i++) { if ($dirslist[$i] != '') { $template->assign_block_vars('html_file_name', array('S_BLOCK_FILE_HTML' => $dirslist[$i])); } } // get all available block images // $dirslist = ''; $dirs = $this->dir_file_exists($phpbb_root_path . 'ext/phpbbireland/portal/images/block_images/block'); while ($file = $dirs->read()) { if (stripos($file, ".gif") || stripos($file, ".png")) { $dirslist .= "{$file} "; } } closedir($dirs->handle); $dirslist = explode(" ", $dirslist); sort($dirslist); for ($i = 0; $i < sizeof($dirslist); $i++) { if ($dirslist[$i] != '') { $template->assign_block_vars('img_file_name', array('S_BLOCK_FILE_I' => $dirslist[$i])); } } $dirslist = ''; $template->assign_var('S_OPTIONS', 'add'); // not a language var // if ($block == '' || $block == 0) { trigger_error($user->lang['NO_BLOCK_ID'] . adm_back_link($this->u_action), E_USER_WARNING); } $sql = 'SELECT * FROM ' . K_BLOCKS_TABLE . ' WHERE id=' . (int) $block; if ($result = $db->sql_query($sql)) { $row = $db->sql_fetchrow($result); } if ($row['img_file_name'] == '') { $row['img_file_name'] = 'default.gif'; } $template->assign_vars(array('S_ID' => $row['id'], 'S_NDX' => $row['ndx'], 'S_TITLE' => $row['title'], 'S_POSITION' => $row['position'], 'S_ACTIVE' => $row['active'], 'S_TYPE' => $row['type'], 'S_FNAME_H' => $row['html_file_name'], 'S_FNAME_V' => $row['var_file_name'], 'S_FNAME_I' => $row['img_file_name'], 'S_VIEW_GROUPS' => $row['view_groups'], 'S_VIEW_ALL' => $row['view_all'], 'S_VIEW_PAGES' => $row['view_pages'], 'S_SCROLL' => $row['scroll'], 'S_HAS_VARS' => $row['has_vars'], 'S_MINIMOD_BASED' => $row['minimod_based'], 'S_MOD_BLOCK_ID' => $row['mod_block_id'], 'BLOCK_CACHE_TIME' => $row['block_cache_time'], 'S_BLOCK_VAR' => $row['var_file_name'] ? $row['var_file_name'] : '')); $sgp_functions_admin->get_link_images(); // get all groups and fill array // $this->get_all_pages($block); $this->parse_all_groups(); $this->get_all_vars_files($block); if ($row['has_vars'] && $row['var_file_name']) { $var_path = 'ext/phpbbireland/portal/acp/variables/'; $file = $row['var_file_name']; $file = str_replace('.html', '.php', $file); if ($file == 'k_the_teams_vars.php') { $sgp_functions_admin->get_teams_sort(); } if (!file_exists($phpbb_root_path . $var_path . $file)) { $error = sprintf($user->lang['NO_VAR_FILE'], $phpbb_root_path . $var_path . $file); trigger_error($error . adm_back_link($this->u_action), E_USER_NOTICE); } include_once $phpbb_root_path . $var_path . $file; } $db->sql_freeresult($result); $template->assign_var('S_OPTIONS', strtolower($mode)); break; case 'delete': if (!$block) { trigger_error($user->lang['MUST_SELECT_VALID_BLOCK_DATA'] . adm_back_link($this->u_action), E_USER_WARNING); } if (confirm_box(true)) { $sql = 'SELECT title, id, position FROM ' . K_BLOCKS_TABLE . ' WHERE id = ' . (int) $block; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $title = $row['title']; $id = $row['id']; $position = $row['position']; $db->sql_freeresult($result); // Get lowest ndx for current position block Dicky $index_start = $this->get_lowest_ndx($position); $sql = "DELETE FROM " . K_BLOCKS_TABLE . "\n\t\t\t\t\t\tWHERE id = " . (int) $block; $db->sql_query($sql); // Added function to reindex blocks after a block deletion $this->reindex_column($position, $index_start); $template->assign_var('BLOCK_REPORT', $title . $user->lang['BLOCK_DELETED'] . '<br />'); $cache->destroy('sql', K_BLOCKS_TABLE); meta_refresh(1, append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=manage")); break; } else { confirm_box(false, $user->lang['CONFIRM_OPERATION_BLOCKS'], build_hidden_fields(array('i' => $module_id, 'mode' => $mode, 'action' => 'delete'))); } $template->assign_var('BLOCK_REPORT', $user->lang['ACTION_CANCELLED']); meta_refresh(1, append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=manage")); break; case 'reindex': $index_no = 1; if (confirm_box(true)) { $thispos = $newpos = ''; $list = array(); $sql = 'SELECT * FROM ' . K_BLOCKS_TABLE . ' ORDER by position, ndx'; if ($result = $db->sql_query($sql)) { while ($row = $db->sql_fetchrow($result)) { $thispos = $row['position']; if ($thispos == $newpos) { $index_no++; } else { $index_no = 1; } $sql = "UPDATE " . K_BLOCKS_TABLE . " SET ndx = '" . (int) $index_no . "' WHERE id = " . (int) $row['id']; //reset ndx to 1 when position changes $newpos = $row['position']; $results = $db->sql_query($sql); if (!$results) { trigger_error($user->lang['RE-INDEXING BLOCKS'] . basename(dirname(__FILE__)) . '/' . basename(__FILE__) . $user->lang['LINE'] . __LINE__); } } } $db->sql_freeresult($result); $template->assign_vars(array('S_BUTTON_HIDE' => true, 'BLOCK_REPORT' => $user->lang['BLOCKS_REINDEXED'])); $cache->destroy('sql', K_BLOCKS_TABLE); meta_refresh(1, append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=manage")); break; } else { confirm_box(false, $user->lang['CONFIRM_OPERATION_BLOCKS_REINDEX'], build_hidden_fields(array('i' => $module_id, 'mode' => $mode, 'action' => 'reindex'))); } $template->assign_var('BLOCK_REPORT', $user->lang['ACTION_CANCELLED']); meta_refresh(1, append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=manage")); break; case 'tools': $template->assign_var('S_OPTIONS', 'tools'); // not language var // break; case 'l': case 'c': case 'r': case 'L': case 'C': case 'R': case '1': case '2': case '3': case 'manage': $template->assign_var('S_TYPE', $mode); if ($mode != 'manage') { $sql = "SELECT * FROM " . K_BLOCKS_TABLE . " WHERE position = '" . $db->sql_escape($mode) . "' ORDER by ndx, type"; } else { $sql = 'SELECT * FROM ' . K_BLOCKS_TABLE . ' ORDER by position, ndx'; } $l_b_first = $r_b_first = $c_b_first = $l_b_last = $r_b_last = $c_b_last = 1; if ($result = $db->sql_query($sql)) { while ($row = $db->sql_fetchrow($result)) { if ($row['img_file_name'] == '') { $row['img_file_name'] = 'default.gif'; } if ($row['position'] == 'L') { $l_b_last = $l_b_last + 1; } else { if ($row['position'] == 'R') { $r_b_last = $r_b_last + 1; } else { if ($row['position'] == 'C') { $c_b_last = $c_b_last + 1; } } } $template->assign_block_vars('bdata', array('S_ID' => $row['id'], 'S_NDX' => $row['ndx'], 'S_TITLE' => $row['title'], 'S_POSITION' => $row['position'], 'S_ACTIVE' => $row['active'], 'S_TYPE' => $row['type'], 'S_FNAME_H' => $row['html_file_name'], 'S_FNAME_V' => $row['var_file_name'], 'S_FNAME_I' => $row['img_file_name'], 'S_VIEW_GROUPS' => $row['view_groups'], 'S_VIEW_ALL' => $row['view_all'], 'S_VIEW_PAGES' => $row['view_pages'], 'S_SCROLL' => $row['scroll'], 'S_HAS_VARS' => $row['has_vars'], 'S_MINIMOD_BASED' => $row['minimod_based'], 'S_MOD_BLOCK_ID' => $row['mod_block_id'], 'S_BLOCK_CACHE_TIME' => $row['block_cache_time'], 'S_BLOCK' => $row['id'] == $block ? $block : '.....', 'U_EDIT2' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=edit&block=" . $row['id']), 'U_UP' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=up&block=" . $row['id']), 'U_DOWN' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=down&block=" . $row['id']), 'U_DELETE' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=delete&block=" . $row['id']), 'U_SET_VARS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=config&block=" . $row['id']))); } $db->sql_freeresult($result); } //$template->assign_var('U_ACTION', $this->u_action); $template->assign_vars(array('S_OPTIONS' => strtolower($mode), 'S_LBL' => $l_b_last - 1, 'S_RBL' => $r_b_last - 1, 'S_CBL' => $c_b_last - 1, 'S_LRC' => '1')); //$module_id = $request->variable('i', ''); break; case 'reset': $sql = "UPDATE " . USERS_TABLE . " SET user_left_blocks = '', user_center_blocks = '', user_right_blocks = '';"; if (!($result = $db->sql_query($sql))) { trigger_error($user->lang['COULD_NOT_RESET_BLOCKS'] . basename(dirname(__FILE__)) . '/' . basename(__FILE__) . $user->lang['LINE'] . __LINE__); } $template->assign_var('BLOCK_REPORT', $user->lang['BLOCK_LAYOUT_RESET']); meta_refresh(1, append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}")); return; case 'config': if ($submit) { meta_refresh(1, append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=manage")); return; } $block_file = $this->get_varfile($block); $template->assign_vars(array('U_BACK' => $this->u_action, 'PORTAL_JS' => $portal_js, 'IMG_PATH' => $img_path_acp_block_icons, 'IMG_PATH_ACP' => $img_path_acp_icons, 'CSS_PATH' => $css_path_acp, 'S_OPTIONS' => 'config', 'S_BLOCK_VAR' => $block_file)); process_block_variables($block_file, $submit, $module_id); break; case 'default': break; } }
function main($module_id, $mode) { global $db, $user, $auth, $template, $cache, $request; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx, $k_config, $table_prefix; global $helper, $root_path, $php_ext, $content_visibility; include_once $phpbb_root_path . 'ext/phpbbireland/portal/config/constants.' . $phpEx; include_once $phpbb_root_path . 'ext/phpbbireland/portal/helpers/tables.' . $phpEx; include_once $phpbb_root_path . 'ext/phpbbireland/portal/includes/sgp_functions.' . $phpEx; $this->cache_setup(); $submit = $request->is_set_post('submit'); if (!class_exists('sgp_functions_admin')) { include_once $phpbb_root_path . 'ext/phpbbireland/portal/includes/sgp_functions_admin.' . $phpEx; $sgp_functions_admin = new sgp_functions_admin(); } /* $k_config = $cache->get('k_config'); $sgp_functions_admin->sgp_acp_set_config('base', $module_id); if ($mode != 'edit' && $mode != 'delete' && $mode != 'up' && $mode != 'down') { //$sgp_functions_admin->sgp_acp_set_config('base', $this->u_action); } */ $user->add_lang_ext('phpbbireland/portal', 'k_menus'); $user->add_lang_ext('phpbbireland/portal', 'k_variables'); $this->tpl_name = 'acp_menus'; $this->page_title = $user->lang['ACP_MENUS']; add_form_key('menus'); if ($request->is_set_post('submit')) { if (!check_form_key('menus')) { $submit = false; $mode = ''; trigger_error('FORM_INVALID'); } $submit = true; } // Can not use append_sid here, the $block_id is assigned to the html but unknow to this code // // Would require I add a form element and use $request->variable to retrieve it // $template->assign_vars(array('U_BACK' => $this->u_action, 'PORTAL_JS' => $portal_js, 'IMG_PATH' => $img_path_acp_menu_icons, 'IMG_PATH_ACP' => $img_path_acp_icons, 'CSS_PATH' => $css_path_acp)); $mode = $request->variable('mode', ''); $menu = $request->variable('menu', 0); $menuitem = $request->variable('menuitem', '', false); $type = $request->variable('type', '', false); if ($submit) { if ($mode == 'nav' || $mode == 'sub' || $mode == 'link') { $mode = 'add'; } } else { if ($mode == 'nav' || $mode == 'sub' || $mode == 'link') { $store = $mode; } } // bold current row text so things are easier to follow when moving/editing etc... // if ($menu ? $menu : 0) { $sql = 'UPDATE ' . K_VARS_TABLE . ' SET config_value = ' . (int) $menu . ' WHERE config_name = "k_adm_block"'; $db->sql_query($sql); } else { $sql = 'SELECT config_name, config_value FROM ' . K_VARS_TABLE . "\n\t\t\t\tWHERE config_name = 'k_adm_block'"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $k_config[$row['config_name']] = $row['config_value']; } $template->assign_var('K_ADM_BLOCK', $k_config['k_adm_block']); switch ($mode) { case 'nav': $this->get_menu(NAV_MENUS, $module_id); $template->assign_var('S_OPTIONS', 'nav'); break; case 'sub': $this->get_menu(SUB_MENUS, $module_id); $template->assign_var('S_OPTIONS', 'sub'); break; case 'link': $this->get_menu(LINKS_MENUS, $module_id); $template->assign_var('S_OPTIONS', 'link'); break; case 'all': $this->get_menu(ALL_MENUS, $module_id); $template->assign_var('S_OPTIONS', 'all'); break; case 'unalloc': $this->get_menu(UNALLOC_MENUS, $module_id); $template->assign_var('S_OPTIONS', 'unalloc'); break; case 'edit': if ($submit) { $m_id = $request->variable('m_id', 0); $ndx = $request->variable('ndx', 0); $menu_type = $request->variable('menu_type', ''); $menu_icon = $request->variable('menu_icon', ''); $name = utf8_normalize_nfc($request->variable('name', '', true)); $link_to = $request->variable('link_to', ''); $append_sid = $request->variable('append_sid', 0); $append_uid = $request->variable('append_uid', 0); $extern = $request->variable('extern', 0); $soft_hr = $request->variable('soft_hr', 0); $sub_heading = $request->variable('sub_heading', 0); $view = $request->variable('view', 1); $view_all = $request->variable('view_all', 1); $view_groups = $request->variable('view_groups', ''); if ($view_all) { $view_groups = $sgp_functions_admin->get_all_groups(); if ($view_groups == '') { $view_groups = 0; } } if (strstr($menu_icon, '..')) { $menu_icon = 'default.png'; } $sql_ary = array('menu_type' => $menu_type, 'ndx' => $ndx, 'menu_icon' => $menu_icon, 'name' => $name, 'link_to' => $link_to, 'append_sid' => $append_sid, 'append_uid' => $append_uid, 'extern' => $extern, 'soft_hr' => $soft_hr, 'sub_heading' => $sub_heading, 'view_all' => $view_all, 'view_groups' => $view_groups); $sql = 'UPDATE ' . K_MENUS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " WHERE m_id = " . (int) $m_id; if (!($result = $db->sql_query($sql))) { trigger_error($user->lang['ERROR_PORTAL_MENUS'] . basename(dirname(__FILE__)) . '/' . basename(__FILE__) . $user->lang['LINE'] . __LINE__); } $cache->destroy('sql', K_MENUS_TABLE); switch ($menu_type) { case 1: $mode = 'nav'; break; case 2: $mode = 'sub'; break; case 3: $mode = 'head'; break; case 3: $mode = 'foot'; break; case 5: $mode = 'link'; break; default: $mode = $mode; break; } $template->assign_vars(array('L_MENU_REPORT' => $user->lang['SAVED'] . '<br />', 'S_OPTIONS' => 'save')); meta_refresh(1, append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=" . $mode)); break; } // get all groups and fill array // $this->parse_all_groups(); if ($submit == 1) { $this->get_menu_item($m_id); } else { $this->get_menu_item($menu); } $template->assign_var('S_OPTIONS', 'edit'); $this->get_menu_icons(); break; case 'delete': if (!$menu) { trigger_error($user->lang['MUST_SELECT_VALID_MENU_DATA'] . adm_back_link($this->u_action), E_USER_WARNING); } if (confirm_box(true)) { $sql = 'SELECT name, m_id FROM ' . K_MENUS_TABLE . ' WHERE m_id = ' . (int) $menu; $result = $db->sql_query($sql); $name = (string) $db->sql_fetchfield('name'); $db->sql_freeresult($result); $name .= ' ' . $user->lang['MENU']; $sql = 'DELETE FROM ' . K_MENUS_TABLE . "\n\t\t\t\t\t\tWHERE m_id = " . (int) $menu; $db->sql_query($sql); $db->sql_freeresult($result); $template->assign_var('L_MENU_REPORT', $name . $user->lang['DELETED'] . '<br />'); $cache->destroy('sql', K_MENUS_TABLE); meta_refresh(1, append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=" . $type)); return; } else { confirm_box(false, $user->lang['CONFIRM_OPERATION_MENUS'], build_hidden_fields(array('i' => $module_id, 'mode' => $mode, 'action' => 'delete'))); } $template->assign_var('L_MENU_REPORT', $user->lang['ACTION_CANCELLED']); meta_refresh(1, append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=" . $type)); break; case 'up': case 'down': $current_ndx = $current_id = $first_id = $last_id = $first_ndx = $last_ndx = $prev_ndx = $next_ndx = $col_count = $current_count = $error = 0; $id_array = array(); $ndx_array = array(); // get current menu id // $sql = "SELECT m_id, ndx, menu_type\n\t\t\t\t\tFROM " . K_MENUS_TABLE . "\n\t\t\t\t\tWHERE m_id = " . (int) $menu; $result = $db->sql_query_limit($sql, 1); $row = $db->sql_fetchrow($result); $type = $row['menu_type']; $db->sql_freeresult($result); $sql = "SELECT m_id, ndx, menu_type\n\t\t\t\t\tFROM " . K_MENUS_TABLE . "\n\t\t\t\t\tWHERE menu_type = '" . $db->sql_escape($type) . "'" . "\n\t\t\t\t\tORDER BY ndx"; $result = $db->sql_query($sql); if ($result = $db->sql_query($sql)) { while ($row = $db->sql_fetchrow($result)) { $id_array[] = $row['m_id']; $ndx_array[] = $row['ndx']; if ($menu == $row['m_id']) { $current_ndx = $row['ndx']; $current_id = $row['m_id']; $current_count = $col_count; } $col_count++; } } $db->sql_freeresult($result); $first_ndx = $ndx_array[0]; $first_id = $id_array[0]; $last_ndx = $ndx_array[$col_count - 1]; $last_id = $id_array[$col_count - 1]; if ($current_count - 1 > 0) { $prev_ndx = $ndx_array[$current_count - 1]; $prev_id = $id_array[$current_count - 1]; } else { // can't happen // } if ($current_count + 1 < $col_count) { $next_ndx = $ndx_array[$current_count + 1]; $next_id = $id_array[$current_count + 1]; } else { // can't happen //; } if ($mode == 'up') { // sql is not duplicated $sql = "UPDATE " . K_MENUS_TABLE . " SET ndx = " . (int) $prev_ndx . " WHERE m_id = " . (int) $current_id; if (!($result = $db->sql_query($sql))) { $error = true; } $sql = "UPDATE " . K_MENUS_TABLE . " SET ndx = " . (int) $current_ndx . " WHERE m_id = " . (int) $prev_id; if (!($result = $db->sql_query($sql))) { $error = true; } } if ($mode == 'down') { // sql is not duplicated $sql = "UPDATE " . K_MENUS_TABLE . " SET ndx = " . (int) $next_ndx . " WHERE m_id = " . (int) $current_id; if (!($result = $db->sql_query($sql))) { $error = true; } $sql = "UPDATE " . K_MENUS_TABLE . " SET ndx = " . (int) $current_ndx . " WHERE m_id = " . (int) $next_id; if (!($result = $db->sql_query($sql))) { $error = true; } } if ($error) { trigger_error($user->lang['MENU_MOVE_ERROR'] . basename(dirname(__FILE__)) . '/' . basename(__FILE__) . $user->lang['LINE'] . __LINE__); } $template->assign_vars(array('L_MENU_REPORT' => $user->lang['SORT_ORDER_UPDATING'], 'S_OPTIONS' => 'updn')); $cache->destroy('sql', K_MENUS_TABLE); switch ($type) { /* case HEAD_MENUS: $current_menu_type = 'head'; break; case FOOT_MENUS: $current_menu_type = 'foot'; break; */ case NAV_MENUS: $current_menu_type = 'nav'; break; case SUB_MENUS: $current_menu_type = 'sub'; break; case LINKS_MENUS: $current_menu_type = 'link'; break; default: $current_menu_type = 'nav'; break; } meta_refresh(1, append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=" . $current_menu_type)); break; case 'add': if ($submit) { //$m_id = $request->variable('m_id', ''); //$ndx = $request->variable('ndx', ''); $menu_type = $request->variable('menu_type', ''); $menu_icon = $request->variable('menu_icon', ''); $name = utf8_normalize_nfc($request->variable('name', '', true)); $link_to = $request->variable('link_to', ''); $append_sid = $request->variable('append_sid', 0); $append_uid = $request->variable('append_uid', 0); $extern = $request->variable('extern', 0); $soft_hr = $request->variable('soft_hr', 0); $sub_heading = $request->variable('sub_heading', 0); $view_all = $request->variable('view_all', 1); $view_groups = $request->variable('view_groups', ''); if ($menu_type == null || $name == null) { // catch all we check menu_type, $name, view) $template->assign_vars(array('L_MENU_REPORT' => $user->lang['MISSING_DATA'], 'S_OPTIONS' => 'updn')); return; } if (strstr($menu_icon, '..') && !$sub_heading) { $menu_icon = 'default.png'; } $ndx = $this->get_next_ndx($menu_type); if ($view_all) { $view = 1; $view_groups = ''; } $sql_array = array('menu_type' => $menu_type, 'ndx' => $ndx, 'menu_icon' => $menu_icon, 'name' => $name, 'link_to' => $link_to, 'append_sid' => $append_sid, 'append_uid' => $append_uid, 'extern' => $extern, 'soft_hr' => $soft_hr, 'sub_heading' => $sub_heading, 'view_all' => $view_all, 'view_groups' => $view_groups); $db->sql_query('INSERT INTO ' . K_MENUS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_array)); $cache->destroy('sql', K_MENUS_TABLE); switch ($menu_type) { case 1: $mode = 'nav'; break; case 2: $mode = 'sub'; break; case 3: $mode = 'head'; break; case 3: $mode = 'foot'; break; case 5: $mode = 'link'; break; default: $mode = $mode; break; } //fix for the different menus... meta_refresh(1, append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$module_id}&mode=" . $mode)); $template->assign_var('L_MENU_REPORT', $user->lang['MENU_CREATED']); return; } else { // get all groups and fill array // $this->parse_all_groups(); $this->get_menu_icons(); $template->assign_var('S_OPTIONS', 'add'); $template->assign_vars(array('S_MENU_ICON' => 'acp.png', 'S_OPTIONS' => 'add', 'S_MENU_TYPE' => $type)); return; } break; case 'icons': $dirslist = ''; $i = $this->get_menu_icons(); $template->assign_vars(array('S_OPTIONS' => 'icons', 'S_HIDE' => 'HIDE', 'L_ICONS_REPORT' => '', 'S_MENU_ICON_COUNT' => $i, 'S_MENU_ICONS_LIST' => $dirslist)); break; case 'manage': $template->assign_var('L_MENU_REPORT', $user->lang['FUTURE_DEVELOPMENT'] . '<br />'); $template->assign_var('S_OPTIONS', 'manage'); break; case 'sync': $template->assign_vars('L_MENU_REPORT', $user->lang['NOT_ASSIGNED'] . '<br />'); $template->assign_var('S_OPTIONS', 'sync'); break; case 'tools': $template->assign_var('S_OPTIONS', 'tools'); break; case 'default': break; } //$template->assign_var('U_ACTION', $u_action); }