// All config names with default values
$default_cfg_str = array('bt_announce_url' => 'http://demo.torrentpier.me/bt/');
$default_cfg_bool = array('bt_disable_dht' => 1, 'bt_show_peers' => 1, 'bt_add_auth_key' => 1, 'bt_show_dl_list' => 0, 'bt_dl_list_only_1st_page' => 1, 'bt_dl_list_only_count' => 1, 'bt_replace_ann_url' => 1, 'bt_show_ip_only_moder' => 1, 'bt_show_port_only_moder' => 1, 'bt_check_announce_url' => 0, 'bt_show_dl_list_buttons' => 1, 'bt_show_dl_but_will' => 1, 'bt_show_dl_but_down' => 0, 'bt_show_dl_but_compl' => 1, 'bt_show_dl_but_cancel' => 1, 'bt_show_dl_stat_on_index' => 1, 'bt_newtopic_auto_reg' => 1, 'bt_tor_browse_only_reg' => 1, 'bt_search_bool_mode' => 1, 'bt_allow_spmode_change' => 1, 'bt_del_addit_ann_urls' => 1, 'bt_set_dltype_on_tor_reg' => 1, 'bt_unset_dltype_on_tor_unreg' => 1);
$default_cfg_num = array('bt_show_peers_mode' => SHOW_PEERS_COUNT);
$default_cfg = array_merge($default_cfg_str, $default_cfg_bool, $default_cfg_num);
$db_fields_bool = array('allow_reg_tracker' => 0, 'allow_porno_topic' => 0, 'self_moderated' => 0);
// Get config
$cfg = bb_get_config(BB_CONFIG, true, false);
// Submit new config
if ($submit && $confirm) {
    foreach ($db_fields_bool as $field_name => $field_def_val) {
        update_table_bool(BB_FORUMS, 'forum_id', $field_name, $field_def_val);
    }
    update_config_table(BB_CONFIG, $default_cfg_str, $cfg, 'str');
    update_config_table(BB_CONFIG, $default_cfg_bool, $cfg, 'bool');
    update_config_table(BB_CONFIG, $default_cfg_num, $cfg, 'num');
    $datastore->update('cat_forums');
    bb_die($lang['CONFIG_UPD'] . '<br /><br />' . sprintf($lang['RETURN_CONFIG'], '<a href="admin_bt_forum_cfg.php">', '</a>') . '<br /><br />' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '<a href="index.php?pane=right">', '</a>'));
}
// Set template vars
set_tpl_vars($default_cfg_str, $cfg);
set_tpl_vars_lang($default_cfg_str);
set_tpl_vars_bool($default_cfg_bool, $cfg);
set_tpl_vars_lang($default_cfg_bool);
set_tpl_vars($default_cfg_num, $cfg);
set_tpl_vars_lang($default_cfg_num);
set_tpl_vars_lang($db_fields_bool);
// Get Forums list
$sql = "SELECT f.*\n\tFROM " . BB_CATEGORIES . " c, " . BB_FORUMS . " f\n\tWHERE f.cat_id = c.cat_id\n\tORDER BY c.cat_order, f.forum_order";
if (!($result = DB()->sql_query($sql))) {
    bb_die('Could not obtain forum names');
// All config names with default values
$default_cfg_str = array('bt_announce_url' => 'http://yourdomain.com/bt/', 'bt_add_comment' => '', 'bt_add_publisher' => '');
$default_cfg_bool = array('bt_show_peers' => 1, 'bt_add_auth_key' => 1, 'bt_show_dl_list' => 1, 'bt_dl_list_only_1st_page' => 1, 'bt_dl_list_only_count' => 1, 'bt_gen_passkey_on_reg' => 1, 'bt_replace_ann_url' => 1, 'bt_show_ip_only_moder' => 1, 'bt_show_port_only_moder' => 1, 'bt_check_announce_url' => 0, 'bt_show_dl_list_buttons' => 1, 'bt_show_dl_but_will' => 1, 'bt_show_dl_but_down' => 0, 'bt_show_dl_but_compl' => 0, 'bt_show_dl_but_cancel' => 1, 'bt_show_dl_stat_on_index' => 1, 'bt_newtopic_auto_reg' => 1, 'bt_tor_browse_only_reg' => 1, 'bt_search_bool_mode' => 0, 'bt_allow_spmode_change' => 1, 'bt_force_passkey' => 1, 'bt_del_addit_ann_urls' => 1, 'bt_set_dltype_on_tor_reg' => 1, 'bt_unset_dltype_on_tor_unreg' => 0);
$default_cfg_num = array('bt_dl_list_expire' => 30, 'bt_show_peers_mode' => SHOW_PEERS_COUNT);
$default_cfg = array_merge($default_cfg_str, $default_cfg_bool, $default_cfg_num);
$db_fields_bool = array('allow_reg_tracker' => 0, 'allow_dl_topic' => 0, 'dl_type_default' => 0, 'show_dl_buttons' => 0, 'self_moderated' => 0);
// Get config
$cfg = get_config_ary(CONFIG_TABLE);
// Submit new config
if ($submit && $confirm) {
    foreach ($db_fields_bool as $field_name => $field_def_val) {
        update_table_bool(FORUMS_TABLE, 'forum_id', $field_name, $field_def_val);
    }
    update_config_table(CONFIG_TABLE, $default_cfg_str, $cfg, 'str');
    update_config_table(CONFIG_TABLE, $default_cfg_bool, $cfg, 'bool');
    update_config_table(CONFIG_TABLE, $default_cfg_num, $cfg, 'num');
    $message = $lang['config_upd'] . '<br /><br />' . sprintf($lang['return_config'], '<a href="' . append_sid("admin_bt_forum_cfg.php") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.php?pane=right") . '">', '</a>');
    message_die(GENERAL_MESSAGE, $message);
}
// Set template vars
set_tpl_vars($default_cfg_str, $cfg);
set_tpl_vars_lang($default_cfg_str);
set_tpl_vars_bool($default_cfg_bool, $cfg);
set_tpl_vars_lang($default_cfg_bool);
set_tpl_vars($default_cfg_num, $cfg);
set_tpl_vars_lang($default_cfg_num);
set_tpl_vars_lang($db_fields_bool);
// Get Forums list
$sql = 'SELECT f.*
	FROM ' . CATEGORIES_TABLE . ' c, ' . FORUMS_TABLE . ' f
	WHERE f.cat_id = c.cat_id
$values[] = "(NULL, 'MAX_ROW_LISTS_ATTR_OPTIONS', '10', '1000', '53', NULL , NOW(), NULL , NULL);";
$values[] = "(NULL, 'MAX_ROW_LISTS_ATTR_VALUES', '50', '1000', '54', NULL , NOW(), NULL , NULL);";
$values[] = "(NULL, 'WHOS_ONLINE_TIME_LAST_CLICK', '900', '1000', '60', NULL, NOW(), NULL, NULL);";
$values[] = "(NULL, 'WHOS_ONLINE_IP_WHOIS_SERVICE', 'http://www.utrace.de/?query=', '1000', '62', NULL, NOW(), NULL, NULL);";
$values[] = "(NULL, 'CONFIRM_SAVE_ENTRY', 'true', '1000', '70', NULL, NOW(), NULL, 'xtc_cfg_select_option(array(\\'true\\', \\'false\\'),');";
$values_update[] = array('values' => "configuration_group_id = '1000', sort_order = '30'", 'configuration_key' => 'MAX_DISPLAY_ORDER_RESULTS');
//configuration_group_id 111125 --- "Paypal"
//##############################//
//install configuration group
$cfg_group_install = insert_into_config_group_table($values_group);
//update configuration group
$cfg_group_update = update_config_group_table($values_group_update);
//install configuration
$cfg_install = insert_into_config_table($values);
//update configuration
$cfg_update = update_config_table($values_update);
//redirect
if ($cfg_install || $cfg_group_install || $cfg_update || $cfg_group_update) {
    xtc_redirect(xtc_href_link(FILENAME_CONFIGURATION, 'gID=' . (int) $_GET['gID']));
}
//---------- FUNCTIONS ----------//
/**
 * insert_into_config_table()
 *
 * @param string $values
 * @return boolean
 */
function insert_into_config_table($values)
{
    global $messageStack;
    //print_r($values);