<?php
/***************************************************************************
*                               admin_best_players.php
*                              -------------------
*     begin                : 16/10/2005
*     copyright            : Ours
*
*
****************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

define('IN_PHPBB', 1);

if( !empty($setmodules) )
{
	$file = basename(__FILE__);
	$module['Admin_arcade_games']['Manage_Best_Players'] = $file;
	return;
}

$phpbb_root_path = "./../";
require($phpbb_root_path . 'extension.inc');
require('./pagestart.' . $phpEx);
require( $phpbb_root_path . 'gf_funcs/gen_funcs.' . $phpEx);

//
// Pull all config data
//
$sql = "SELECT *
	FROM " . ARCADE_TABLE;
if(!$result = $db->sql_query($sql))
{
	message_die(CRITICAL_ERROR, "Could not query config information in admin_arcade", "", __LINE__, __FILE__, $sql);
}
else
{
	while( $row = $db->sql_fetchrow($result) )
	{
		$arcade_name = $row['arcade_name'];
		$arcade_value = $row['arcade_value'];
		$default_arcade[$arcade_name] = $arcade_value;
		
		$new[$arcade_name] = ( isset($HTTP_POST_VARS[$arcade_name]) ) ? $HTTP_POST_VARS[$arcade_name] : $default_arcade[$arcade_name];

		if( isset($HTTP_POST_VARS['submit']) )
		{
			$sql = "UPDATE " . ARCADE_TABLE . " SET
				arcade_value = '" . str_replace("\'", "''", $new[$arcade_name]) . "'
				WHERE arcade_name = '$arcade_name'";
			if( !$db->sql_query($sql) )
			{
				message_die(GENERAL_ERROR, "Failed to update arcade configuration for $arcade_name", "", __LINE__, __FILE__, $sql);
			}
		}
	}
	if( isset($HTTP_POST_VARS['submit']) )
	    {
		   $message = $lang['Config_updated'] . "<br /><br />" . sprintf($lang['Click_return_best_config'], "<a href=\"" . append_sid("admin_best_players.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
       message_die(GENERAL_MESSAGE, $message);
	    }
}

$bestplayers_arcade_yes = ( $new['bestplayers_arcade'] ) ? "checked=\"checked\"" : "";
$bestplayers_arcade_no = ( !$new['bestplayers_arcade'] ) ? "checked=\"checked\"" : "";

$bestplayers_games_yes = ( $new['bestplayers_games'] ) ? "checked=\"checked\"" : "";
$bestplayers_games_no = ( !$new['bestplayers_games'] ) ? "checked=\"checked\"" : "";

$bestplayers_portal_yes = ( $new['bestplayers_portal'] ) ? "checked=\"checked\"" : "";
$bestplayers_portal_no = ( !$new['bestplayers_portal'] ) ? "checked=\"checked\"" : "";

$bestplayers_forum_yes = ( $new['bestplayers_forum'] ) ? "checked=\"checked\"" : "";
$bestplayers_forum_no = ( !$new['bestplayers_forum'] ) ? "checked=\"checked\"" : "";

$bestplayers_viewforum_yes = ( $new['bestplayers_viewforum'] ) ? "checked=\"checked\"" : "";
$bestplayers_viewforum_no = ( !$new['bestplayers_viewforum'] ) ? "checked=\"checked\"" : "";

$bestplayers_viewtopic_yes = ( $new['bestplayers_viewtopic'] ) ? "checked=\"checked\"" : "";
$bestplayers_viewtopic_no = ( !$new['bestplayers_viewtopic'] ) ? "checked=\"checked\"" : "";

$s_one = ( $new['limit_bestplayers'] == '1' ) ? "selected" : "";
$s_two = ( $new['limit_bestplayers'] == '2' ) ? "selected" : "";
$s_three = ( $new['limit_bestplayers'] == '3' ) ? "selected" : "";
$s_four = ( $new['limit_bestplayers'] == '4' ) ? "selected" : "";
$s_five = ( $new['limit_bestplayers'] == '5' ) ? "selected" : "";
$s_six = ( $new['limit_bestplayers'] == '6' ) ? "selected" : "";
$s_seven = ( $new['limit_bestplayers'] == '7' ) ? "selected" : "";
$s_eight = ( $new['limit_bestplayers'] == '8' ) ? "selected" : "";
$s_nine = ( $new['limit_bestplayers'] == '9' ) ? "selected" : "";
$s_ten = ( $new['limit_bestplayers'] == '10' ) ? "selected" : "";

$s_orderlimit  = "<option value='1' $s_one>1</option>\n";
$s_orderlimit .= "<option value='2' $s_two>2</option>\n";
$s_orderlimit .= "<option value='3' $s_three>3</option>\n";
$s_orderlimit .= "<option value='4' $s_four>4</option>\n";
$s_orderlimit .= "<option value='5' $s_five>5</option>\n";
$s_orderlimit .= "<option value='6' $s_six>6</option>\n";
$s_orderlimit .= "<option value='7' $s_seven>7</option>\n";
$s_orderlimit .= "<option value='8' $s_eight>8</option>\n";
$s_orderlimit .= "<option value='9' $s_nine>9</option>\n";
$s_orderlimit .= "<option value='10' $s_ten>10</option>\n";

$use_stats_link_yes = ( $new['use_stats_link'] ) ? "checked=\"checked\"" : "";
$use_stats_link_no = ( !$new['use_stats_link'] ) ? "checked=\"checked\"" : "";

$use_gender_img_yes = ( $new['use_gender_img'] ) ? "checked=\"checked\"" : "";
$use_gender_img_no = ( !$new['use_gender_img'] ) ? "checked=\"checked\"" : "";

$use_flag_img_yes = ( $new['use_flag_img'] ) ? "checked=\"checked\"" : "";
$use_flag_img_no = ( !$new['use_flag_img'] ) ? "checked=\"checked\"" : "";

$admins_yes = ( $new['admin_best_on'] ) ? "checked=\"checked\"" : "";
$admins_no = ( !$new['admin_best_on'] ) ? "checked=\"checked\"" : "";

$modos_yes = ( $new['modo_best_on'] ) ? "checked=\"checked\"" : "";
$modos_no = ( !$new['modo_best_on'] ) ? "checked=\"checked\"" : "";

$template->set_filenames(array(
	"body" => "admin/admin_best_players.tpl")
);

$template->assign_vars(array(
	"S_CONFIG_ACTION" => append_sid("admin_best_players.$phpEx"),

	"L_YES" => $lang['Yes'],
	"L_NO" => $lang['No'],
	"L_CONFIGURATION_TITLE" => $lang['best_Config'],
	"L_CONFIGURATION_EXPLAIN" => $lang['best_config_explain'],

	"S_ARCADE_SEE_YES" => $bestplayers_arcade_yes,
	"S_ARCADE_SEE_NO" => $bestplayers_arcade_no,
	"S_GAMES_SEE_YES" => $bestplayers_games_yes,
	"S_GAMES_SEE_NO" => $bestplayers_games_no,
	"S_PORTAL_SEE_YES" => $bestplayers_portal_yes,
	"S_PORTAL_SEE_NO" => $bestplayers_portal_no,
	"S_FORUM_SEE_YES" => $bestplayers_forum_yes,
	"S_FORUM_SEE_NO" => $bestplayers_forum_no,
	"S_VIEWFORUM_SEE_YES" => $bestplayers_viewforum_yes,
	"S_VIEWFORUM_SEE_NO" => $bestplayers_viewforum_no,
	"S_VIEWTOPIC_SEE_YES" => $bestplayers_viewtopic_yes,
	"S_VIEWTOPIC_SEE_NO" => $bestplayers_viewtopic_no,
  "S_USE_GENDER_IMG_YES" => $use_gender_img_yes,
  "S_USE_GENDER_IMG_NO" => $use_gender_img_no,
  "S_USE_FLAG_IMG_YES" => $use_flag_img_yes,
  "S_USE_FLAG_IMG_NO" => $use_flag_img_no,
  "S_USE_TOPSTATARCADE_YES" => $use_stats_link_yes,
  "S_USE_TOPSTATARCADE_NO" => $use_stats_link_no,
	"S_LINK_STATS_YES" => $use_stats_link_yes,
  "S_LINK_STATS_NO" => $use_stats_link_no,
	"S_ADMINS_YES" => $admins_yes,
	"S_ADMINS_NO" => $admins_no,
	"S_MODOS_YES" => $modos_yes,
	"S_MODOS_NO" => $modos_no,
	"S_LIMIT_BEST" => $s_orderlimit,
	"S_WIDTH_BEST" => intval($new['avatar_best']),

	"L_ADMINS" => $lang['admin_best_on'],
	"L_ADMINS_EXPLAIN" => $lang['admin_best_on_explain'],
	"L_MODOS" => $lang['modo_best_on'],
	"L_MODOS_EXPLAIN" => $lang['modo_best_on_explain'],
	"L_BEST_SEE_SETTINGS" => $lang['best_see_setting'],
	"L_ARCADE_SEE" => $lang['best_arcade_see'],
	"L_GAMES_SEE" => $lang['best_games_see'],
	"L_PORTAL_SEE" => $lang['best_portal_see'],
	"L_FORUM_SEE" => $lang['best_forum_see'],
	"L_VIEWFORUM_SEE" => $lang['best_viewforum_see'],
	"L_VIEWTOPIC_SEE" => $lang['best_viewtopic_see'],
	"L_ARCADE_SEE_EXPLAIN" => $lang['best_arcade_see_explain'],
	"L_GAMES_SEE_EXPLAIN" => $lang['best_games_see_explain'],
	"L_PORTAL_SEE_EXPLAIN" => $lang['best_portal_see_explain'],
	"L_FORUM_SEE_EXPLAIN" => $lang['best_forum_see_explain'],
	"L_VIEWFORUM_SEE_EXPLAIN" => $lang['best_viewforum_see_explain'],
	"L_VIEWTOPIC_SEE_EXPLAIN" => $lang['best_viewtopic_see_explain'],
	"L_USE_GENDER" => $lang['best_use_gender'],
	"L_USE_GENDER_EXPLAIN" => $lang['best_use_gender_explain'],
	"L_USE_FLAG" => $lang['best_use_flag'],
	"L_USE_FLAG_EXPLAIN" => $lang['best_use_flag_explain'],
  "L_USE_TOPSTATARCADE" => $lang['best_use_stats'],
  "L_USE_TOPSTATARCADE_EXPLAIN" => $lang['best_use_stats_explain'],
	"L_BEST_ORDER" => $lang['best_order'],
	"L_BEST_ORDER_EXPLAIN" => $lang['best_order_explain'],
	"L_LIMIT_BEST" => $lang['limit_best'],
	"L_LIMIT_BEST_EXPLAIN" => $lang['limit_best_explain'],
	"L_WIDTH_BEST" => $lang['avatar_best'],
	"L_WIDTH_BEST_EXPLAIN" => $lang['avatar_best_explain'],

	"L_SUBMIT" => $lang['Submit'],
	"L_RESET" => $lang['Reset'])
);

// Génération de la page
$template->pparse("body");

include('./page_footer_admin.'.$phpEx);

?>