<?php
##############################################################################
# ajout de Cadeaux
##############################################################################
$IDNEPASREPONDRE = 2;


include("../config.php3");
include($BIB."bib_generic.php3");
include($BIB."bib_mailing.php3");

$info = db_fetch_array(main_db_query("SELECT SAV.*,Players.NickName,Members.Name,Members.FirstName FROM SAV ".
		"LEFT JOIN Players ON Players.Id=SAV.PlayerId ".
		"LEFT JOIN Members ON Members.Id=Players.MemberId ".
		"WHERE SAV.Id=$Id"));
		
$aDate = $info[aDate];
$Traitement = $info[Traitement];
$PlayerId = $info[PlayerId];
$Subject = $info[Subject];
$Email = $info[Email];
$Contenu = $info[Contenu];
$doSendMail = true;

if ($ReponseId == $IDNEPASREPONDRE )
{
	$doSendMail = false;
	$submit = true;
}

if (isset($submit))
{
	if ($txtPbType != "")
		$sPbType = $txtPbType;
	else
		$sPbType = $slctPbType;
	
	main_db_query("UPDATE SAV SET Traitement='".$ReponseId."', Reponse='".$Reponse."', PbType='".$sPbType."' WHERE Id='".$Id."'");
	
	$msg = stripslashes($Reponse)."\n\n----------------- Votre message d'origine ----------------\n\n".$Contenu;
	
	# traitement du mail
	if ($doSendMail)
	{
		generic_mail($Email, "Re : ".$Subject, $msg,
		     "From: $FROM_FIELD\n" . 
		     "Reply-To: $REPLY_TO_FIELD\n" . 
		     "X-Mailer: PHP/" . phpversion()."\n".
		     "MIME-Version: 1.0\n".
		     "Content-Type: text; charset=iso-8859-1"."\n"
		     );	
	}     
	# après on revient à l'écran de sav
	header("Location: Sav.php3?Repondu=1&MsgOrder=".$MsgOrder);
}

$Ttraitement= array();
$Ttraitement[0]="En cours de traitement";
$Ttraitement[1]="Réponse auto";
$Ttraitement[2]="Traité";

$rowRepType = db_fetch_assoc(main_db_query("SELECT * FROM SAV_ReponsesType WHERE Id='".$ReponseId."'"));
$Reponse = $rowRepType['Contenu'];

?>
<html>
<head></head>
<link rel="stylesheet" href="admin.css">
<body rightmargin=0>
<div align=center class=trTitle>Réponse SAV</div>
<br>

<form>
<input type="hidden" size=3 name=Id value="<?php echo $Id; ?>"> 
<input type="hidden" size=3 name=ReponseId value="<?php echo $ReponseId; ?>">
<input type="hidden" size=3 name=MsgOrder value="<?php echo $MsgOrder; ?>">

<table border=1>
	<tr>
		<td>
			Date :
		</td>
		<td>
			<b><?php echo $aDate; ?></b>
		</td>
	</tr>
	<tr>
		<td>
			Joueur :
		</td>
		<td>
			
			<font color=#0000FF>				
			<b><?echo "$info[Name] $info[FirstName]";?> &nbsp;</b></font>Pseudo : &nbsp;<font color=#0000FF><?echo $info[NickName];?>
			</font>
		</td>
	</tr>
	<tr>
	<tr>
		<td>
			Email :
		</td>
		<td>
			<?php echo $Email; ?>
		</td>
	</tr>	
	<tr>
		<td>
			Sujet :
		</td>
		<td>
			<?php echo $Subject; ?>
		</td>
	</tr>
	<tr>
		<td>
			Contenu :
		</td>
		<td>
			<?php echo $Contenu; ?>
		</td>
	</tr>
</table>

<textarea cols=80 rows=20 name=Reponse size=1>
<?php echo $Reponse; ?>
</textarea>
<hr>
<table>
	<tr>
		<td>Sélectionnez un pb existant<br>
<select name="slctPbType">
<?php
$rows = main_db_query("SELECT PbType FROM SAV GROUP BY PbType ORDER BY PbType ASC");
while($row = db_fetch_assoc($rows))
{
	echo "<option value=\"".$row['PbType']."\">".$row['PbType']."</option>";
}

?>
</select>
		</td>
		<td align=center rowspan=2>... Puis validez !<br><input type=submit name=submit value="Valider"></td>
	<tr>
		<td>... Saisissez un nouveau type de pb<br><input type=text name=txtPbType size=80></td>
	</tr>
</table>
<br>
</form>
<a href="Sav.php3?MsgOrder=<?php echo $MsgOrder ?>"><u>Retour aux messages</u></a>