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, $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; } }