<?php
///////////////////////////////////////////////
//                @lex Guestbook             //
//      by Soulard Alexis (c) 2002 - 2006    //
//         http://www.alexphpteam.com/       //
//             all right reserved            //
///////////////////////////////////////////////

DEFINE("AGUEST", true);
$chem_absolu = "../";

//----------------------- fichiers à inclure
include($chem_absolu."config/extension.inc");
include($chem_absolu."include/admin_include.".$alex_livre_ext);

//----------------------- on controle si le visiteur est ou non autorisé à visiter cette page
verif_page("modif_options");

//----------------------- génération de la liste des champs de cases à cocher oui / non
$tab_champs_options = array(
	1 => "send_mail",
	"ok_mail",
	"ok_url",
	"ok_pays",
	"ok_note",
	"ok_aff_moteur",
	"admin_valide_messages",
	"admin_add_code_securite",
	"admin_envoyer_remerciement"
);

//----------------------- génération de la liste des champs textes de la langue
$tab_champs_langue = array(
	1 => "options_livre",
	"infos",
	"infos_",
	"options_generales",
	"langue",
	"oui",
	"non",
	"options_modules",
	"options_tech",
	"url_recharger",
	"url_variables",
	"temps_session",
	"stockage",
	"nb_pages",
	"skin_to_use",
	"enregistrer",
	"temps_ip_post",
	"minutes",
	"cut_mots",
	"format_date_boite",
	"valider_messages",
	"see_skin",
	"maxi_car",
	"add_code_securite",
	"t_chem_dossier_fonts",
	"t_color_txt_code",
	"t_color_background_code",
	"envoyer_remerciement",
	"nb_max_smileys"
);

//----------------------- inclusion de fichiers utiles à la page d'options
include($chem_absolu."config/config.".$alex_livre_ext);
include($chem_absolu."include/funct_write_files.".$alex_livre_ext);

/* fermeture de la connexion sql */
$f_db_connexion -> sql_close();

//----------------------- affichage du template
$echo_html = new ModeliXe("options.htm", "f_sid=".$_GET['f_sid']."", "", "", "", $chem_absolu.$chem_template);
$echo_html -> SetModeliXe();

//----------------------- test si l'on peut écrire dans le fichier "config.php"
$write_test = new write_files();
$write_test -> save_donnees("1");

if ($write_test -> write($chem_absolu."config/test"))
	$texte_write = $f_lang['ok_write'];
else
	$texte_write = $f_lang['no_write'];

//----------------------- test si le serveur autorise l'envoi d'email
/*if (!get_cfg_var("SMTP") && !get_cfg_var("sendmail_path"))
	$erreur_mail = $f_lang['avert_mail'];
else*/
	$erreur_mail = "";

//----------------------- enregistrement des données
if (isset($_POST['enregistrer'])){
	$_POST['temps_session'] = (int)$_POST['temps_session'];
	$_POST['temps_ip_post'] = (int)$_POST['temps_ip_post'];
	$_POST['maxi_car'] = (int)$_POST['maxi_car'];
	$_POST['cut_mots'] = (int)$_POST['cut_mots'];
	$_POST['nb_pages'] = (int)$_POST['nb_pages'];
	$_POST['nb_max_smileys'] = (int)$_POST['nb_max_smileys'];

	save_options($_POST['langue'], $_POST['skin_to_use'], $_POST['temps_session'], $_POST['send_mail'], $_POST['temps_ip_post'], $_POST['format_date'], $_POST['ok_mail'], $_POST['ok_url'], $_POST['ok_pays'], $_POST['ok_note'], $_POST['ok_aff_moteur'], $_POST['nb_pages'], $_POST['cut_mots'], $_POST['url_recharger'], $_POST['variables_url'], $_POST['admin_valide_messages'], $_POST['maxi_car'], $_POST['admin_add_code_securite'], $_POST['chem_dossier_fonts'], $_POST['color_txt_code'], $_POST['color_background_code'], $_POST['admin_envoyer_remerciement'], $_POST['nb_max_smileys']);

	if ($write_object -> write($chem_absolu."config/config.".$alex_livre_ext)){
		/* mise à jour des variables nouvellement enregistrées dans le fichier d'options */
		$f_language = $_POST['langue'];
		$skin_use = $_POST['skin_to_use'];	
		$f_temps_session = $_POST['temps_session'];
		$temps_ip_post = $_POST['temps_ip_post'];
		$format_date = $_POST['format_date'];

		for ($i = 1; $i <= count($tab_champs_options); $i++){
			${$tab_champs_options[$i]} = attribuer_val($tab_champs_options[$i]);
		}		

		$chem_dossier_fonts = stripslashes($_POST['chem_dossier_fonts']);
		$color_txt_code = $_POST['color_txt_code'];
		$color_background_code = $_POST['color_background_code'];

		$nb_pages = $_POST['nb_pages'];
		$cut_mots = $_POST['cut_mots'];
		$maxi_car = $_POST['maxi_car'];
		$nb_max_smileys = $_POST['nb_max_smileys'];
		$url_recharger = $_POST['url_recharger'];
		$extension_url = $_POST['variables_url'];

		/* ré-inclusion du fichier de langue */
		include($chem_absolu."languages/".$f_language.".".$alex_livre_ext);

		$echo_html -> MxText("message_javascript", message_javascript($f_lang['merci_options'], false));
	}
	else
		$echo_html -> MxText("message_javascript", message_javascript($f_lang['erreur_options'], false));
}

//----------------------- on récupère toutes les langues disponibles
$liste_langues = read_rep($chem_absolu."languages/");
$option_langues = generate_options($liste_langues, $f_language);

//----------------------- on récupère tous les skins disponibles
$liste_rep = read_rep($chem_absolu."templates/skins/", "rep");
$option_rep = generate_options($liste_rep, $skin_use);

/* instanciation des blocs */
template_type($f_lang['title options']);

/* langue */
generate_langue($tab_champs_langue);
generate_langue($tab_champs_options);

$echo_html -> MxText("write_file", $texte_write);
$echo_html -> MxText("avert_mail", $erreur_mail);
$echo_html -> MxText("liste_langues", $option_langues);
$echo_html -> MxText("liste_skin_to_use", $option_rep);

/* valeur des champs */
$echo_html -> MxText("value_temps_session", $f_temps_session);

generate_radio($tab_champs_options);

// pas de chemin vers les polices définis ?
if (!$chem_dossier_fonts)
	$chem_dossier_fonts = dertimner_path_fonts();

$echo_html -> MxText("value_chem_dossier_fonts", $chem_dossier_fonts);
$echo_html -> MxText("value_color_txt_code", $color_txt_code);
$echo_html -> MxText("value_color_background_code", $color_background_code);

$echo_html -> MxText("value_temps_ip_post", $temps_ip_post);
$echo_html -> MxText("value_nb_pages", $nb_pages);
$echo_html -> MxText("value_url_recharger", $url_recharger);
$echo_html -> MxText("value_variables_url", $extension_url);
$echo_html -> MxText("value_cut_mots", $cut_mots);
$echo_html -> MxText("value_maxi_car", $maxi_car);
$echo_html -> MxText("value_nb_max_smileys", $nb_max_smileys);
$echo_html -> MxText("value_format_date", $format_date);

/* urls */
$echo_html -> MxText("f_sid", $_GET['f_sid']);

/* body options */
$echo_html -> MxText("bloc1.body options", 'onload="update_see_code_securite()"');

$echo_html -> MxWrite();
?>