<?php
##############################################################################
# ajout de Cadeaux
##############################################################################
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 (isset($submit) )
{
	if(checkEmail($toEmail))
	{
		if ($txtPbType != "")
			$sPbType = $txtPbType;
		else
			$sPbType = $slctPbType;
		
		main_db_query("UPDATE SAV SET Traitement='1', Reponse='Tranférer à ".$toEmail."', PbType='".$sPbType."' WHERE Id='".$Id."'");
		
		$msg = $MessageTranfer;
		
		# traitement du mail
		if ($doSendMail)
		{
			generic_mail($toEmail, "TR : ".$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);
	}
	else
	{
		echo "<font color=#FF0000>Adresse email de tranfers incorrecte</font>";
	}
}

$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; ?>">
<?php
if(!isset($toEmail))
{
	$toEmail = "serei.lor@viralgames.com";
}
?>
A transférer à <input type="text" size=50 name=toEmail value="<?php echo $toEmail; ?>">

<textarea cols=80 rows=20 name=MessageTranfer size=1>
<?php
echo "\n\n----------------- Message d'origine ----------------\n\n".
"Joueur : $info[Name] $info[FirstName]\n".
"Pseudo : $info[NickName]\n".
"Date : $aDate\n".
"Email : $Email\n".
"Sujet : $Subject\n".
"Contenu : $Contenu\n".
stripslashes($Contenu);
?>
</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>