<?php
/***************************************************************************
 *                            admin_tableaudechasse.php
 *                            -------------------
 * 	par pitimarsu - www.lecanarddechaine.fr
 *
 ***************************************************************************/

define('IN_PHPBB', 1);
if( !empty($setmodules) )
{
	$file = basename(__FILE__);
	$module['AreaBB Extensions']['Chasse'] = '../areabb/mods/tableaudechasse/'.$file;
	return;
}

//
// Let's set the root dir for phpBB
//
define('ROOT_STYLE','admin');
$phpbb_root_path = '../../../';
require($phpbb_root_path . 'extension.inc');
require($phpbb_root_path . 'admin/pagestart.' . $phpEx);
include($phpbb_root_path . 'areabb/fonctions/preload.' . $phpEx);
load_lang('admin');



// --------------------------------------------------------------------------------------------
// TRAITEMENT DES PARAMETRES
//
if (isset($HTTP_POST_VARS['action']) || isset($HTTP_GET_VARS['action']))
{
	if (isset($HTTP_POST_VARS['action'])) 
	{
		$action = $HTTP_POST_VARS['action']; 
	}else{
		$action = $HTTP_GET_VARS['action'];
	}
	switch($action)
	{
		case 'enregistrer':
			// Enregistrement des modifications effectuées sur la config générale	
			$sql = 'SELECT * FROM ' . AREABB;
			if(!$result = $db->sql_query($sql))
			{
				message_die(CRITICAL_ERROR, "Could not query config information in admin_arcade", "", __LINE__, __FILE__, $sql);
			}
			while( $row = $db->sql_fetchrow($result) )
			{
				$nom = $row['nom'];
				$valeur = $row['valeur'];
				$defaut[$nom] = $valeur;
				
				$new[$nom] = ( isset($HTTP_POST_VARS[$nom]) ) ? $HTTP_POST_VARS[$nom] : $defaut[$nom];
		
				$sql = 'UPDATE ' . AREABB . ' 
					SET valeur = \'' . str_replace("\'", "''", $new[$nom]) . '\'
					WHERE nom = \''.$nom.'\'';
				if( !$db->sql_query($sql) )
				{
					message_die(GENERAL_ERROR, 'Failed to update areabb configuration for '.$nom, '', __LINE__, __FILE__, $sql);
				}
			}
		break;
	}
}
// --------------------------------------------------------------------------------------------
// AFFICHAGE
//
$sql = 'SELECT * FROM ' . AREABB;
if(!$result = $db->sql_query($sql))
{
	message_die(CRITICAL_ERROR, "Could not query config information in admin_arcade", "", __LINE__, __FILE__, $sql);
}
while( $row = $db->sql_fetchrow($result) )
{
	$new[$row['nom']]= $row['valeur'];	
}



$template->set_filenames(array(
	'body' => 'areabb/mods/tableaudechasse/tpl/areabb_config.tpl'
));



$sql = 'SELECT user_id, username
	FROM ' . USERS_TABLE . ' 
	WHERE user_id > 0 
	ORDER BY username ASC';
if (!$result = $db->sql_query($sql))
{
	message_die(GENERAL_ERROR, 'Could not query recent topics information', '', __LINE__, __FILE__, $sql);
}	
while ($row = $db->sql_fetchrow($result)) {
	$template->assign_block_vars('list_users', array(
		'LIST_USER_ID'			=> $row['user_id'],
		'LIST_USER_USERNAME'	=> $row['username']
	));
}





$template->assign_vars(array(
	'L_SUBMIT'							=> $lang['Submit'], 
	'L_RESET'							=> $lang['Reset'],
	'L_CHASSE_CONFIGURATION_TITLE'		=> $lang['L_CHASSE_CONFIGURATION_TITLE'],
	'L_CHASSE_CONFIGURATION_EXPLAIN'	=> $lang['L_CHASSE_CONFIGURATION_EXPLAIN'],
	'L_CHASSE_SETTINGS'					=> $lang['L_CHASSE_SETTINGS'],	
	'TITRE'								=> $new['chasse_titre'],
	'L_CHASSE_ID'						=> $lang['L_CHASSE_ID'],
	'L_CHASSE_TITRE'					=> $lang['L_CHASSE_TITRE']
));

// Génération de la page

$template->pparse('body');
include($phpbb_root_path . 'admin/page_footer_admin.'.$phpEx);
?>