<?php

/*
Name: goldbook.php
Author: NicoSoft
Création: 14/08/01
MAJ      : 23/09/01
*/

require_once "include/standard.inc.php";

extract($_POST);
if ($_GET["GoldbookFile"] != "")
	$GoldbookFile = $_GET["GoldbookFile"];

if (isset($GoldbookFile) && $GoldbookFile != "")
	$GoldbookFile="default";
	
$Cpt = 0;

echo "<form method='post' action='";
if (isset($goldbooktype) && ($goldbooktype == "comment"))
{
        echo "?modulepage=commentnews&File=$File&idnews=".$MyNews["index"].">\n";
        $modulepage = "commentnews";
        $gbparam = "<table><tr><td><input name='File' value='$File' type='hidden' />\n<input name='idnews' value='".$MyNews["index"]."' type='hidden' />";
}
else
        //echo "?modulepage=goldbook'>\n";
        echo "livre.html'>\n";
	$VMessage = str_replace("\'","'",$VMessage);
        echo "<input name='param' value='postgb' type='hidden'></input>
	<input name='GoldBookFile' value='".$GoldbookFile."' type='hidden'></input>
        <table><tr><td>
        <i>Nom/Pseudo (facultatif)</i> <input name='VName' type='text' size='10' value=''></input>
        <i>e-mail (facultatif)</i> <input name='VEmail' type='text' size='10' value=''></input></td></tr>
        <tr><td><i>Message</i><br /><textarea name='VMessage' cols='50' rows='12'></textarea></td></tr>
        ".$gbparam."
        <tr><td>
	<input name='Ecrire' value='Ecrire' type='submit' class='boutton' />
	<input name='reset' value='Effaçer' type='reset' class='boutton' />
	</td></tr></table></form>
       <hr /></td></tr>\n";
unset($File);

// si le fichier n'existe pas, on le crée:
if (!(file_exists("goldbook/$GoldbookFile.csv")))
{
        $goldbook = fopen("goldbook/$GoldbookFile.csv","w+");
        fclose($goldbook);
}

// ajout des messages
if ($param == "postgb")
{
        if ($VMessage != "")
        {
                $date = strftime ("%d/%m/%Y", time());
                $iheure= date("H:i");
		$VMessage = htmlentities(parse_string($VMessage,"yes"));
                $gbline = sprintf("\"".$date."\",\"".$iheure."\",\"".htmlspecialchars($VName)."\",\"".$VEmail."\",\"".$VMessage."\"\n");
                $goldbook = fopen("modules/goldbook/$GoldbookFile.csv","a");
                
		fwrite($goldbook,$gbline);
                fclose($goldbook);
		
		//unlink("$GoldbookFile.dat");
		//mailalert("n@tourmentine.com","post livre d'or",$VName,$VEmail,$VMessage);
		mail("n@tourmentine.com","[Tourmentine] post livre d'or ",$VMessage,"From: ".$VName." <".$VEmail.">\r\nX-Mailer: PHP/" . phpversion());
        }
}

// lecture des messages
$goldbook = fopen("/www/website/modules/goldbook/$GoldbookFile.csv","r");

while ($data = fgetcsv($goldbook, 1000, ","))
{
        $VisitorDate[$Cpt] = $data[0];
        $VisitorTime[$Cpt] = $data[1];
        $VisitorName[$Cpt] = stripcslashes($data[2]);
        $VisitorEmail[$Cpt] = $data[3];
        $VisitorMessage[$Cpt++] = stripcslashes($data[4]);
}

fclose($goldbook);
unset($data);
unset($goldbook);

// si $NbMaxPost n'est pas défini, ou si il est plus grand que le nombre d'éléments, on l'ajuste à ce nombre
if ((!isset($NbMaxPost)) || ($NbMaxPost > $Cpt))
{
        $NbMaxPost = $Cpt;
}

// affichage des messages
for($i=0;$i<=$NbMaxPost-1;$i++)
{
        if ($VisitorName[$i] == "")
                $VisitorName[$i] = "Anonyme";

        if ($VisitorEmail[$i] != "")
                $Visiteur = "<a href='mailto:".$VisitorEmail[$i]."'>".$VisitorName[$i]."</a>";
        else
		$Visiteur = $VisitorName[$i];

	echo "<tr><td>Posté le ".$VisitorDate[$i]." à ".$VisitorTime[$i]." par <b>".$Visiteur."</b>:
        <br />&quot;<i>".$VisitorMessage[$i]."</i>&quot;<br />";

        if ($i != ($NbMaxPost-1))
	{
                echo "<hr />";
                echo "</td></tr>\n";
	}
 }

$footerbox = 0;
$footerboxtext = "Retour au menu";
$footerlien = "/";

?>