<?php
##############################################################################
# ajout de Cadeaux
##############################################################################

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

# nb de lignes à afficher
$nbRowsToShow = 100;
$error = "";

?>
<html>
<head></head>
<link rel="stylesheet" href="admin.css">
<body rightmargin=0>
<div align=center class=trTitle>Gestion du traitement des mails SAV</div>
<br>




<?

	
switch($submit)
{
	case "Valider":
		# formatage de toutes les chaines de char
		$Name = AddSlashes($Name);
		
		if ($Id==0)
		{
			# on insere une nouvelle réponse
			main_db_query("INSERT INTO SAV (aDate, Traitement, PlayerId, Subject, Email,Contenu) VALUES ('".$aDate."','".$Traitement."','".$PlayerId."','".$Subject."','".$Email."','".$Contenu."')");
		}
		else
		{
			# on update si c'est une modif
			//main_db_query("UPDATE SAV SET aDate='".$aDate."', Traitement='".$Traitement."', PlayerId='".$PlayerId."', Subject='".$Subject."',Email='".$Email."',Contenu='".$Contenu."' WHERE Id='".$Id."'");
			main_db_query("UPDATE SAV SET Traitement='".$Traitement."' WHERE Id='".$Id."'");
			echo "<span class=smallWhite><font color=red>Modification enregistrée</font></span><br>";
			echo "<a class=under href='Sav.php3#$Id'>Retour à la liste des mails SAV</a>";
		}
		break;
		
	case "Supprimer":
		main_db_query("DELETE FROM SAV WHERE Id='".$Id."'");
		$Id=0;
		$aDate  = "";
		$Traitement  = "";
		$PlayerId  = "";
		$Subject  = "";
		$Email  = "";
		$Contenu  = "";
		break;
	
	case "Infos":
		$info = db_fetch_array(main_db_query("SELECT * FROM SAV WHERE Id='".$Id."'"));
		
		$aDate = $info[aDate];
		$Traitement = $info[Traitement];
		$PlayerId = $info[PlayerId];
		$Subject = $info[Subject];
		$Email = $info[Email];
		$Contenu  = $info[Contenu];
		break;
	case "InfosparDate" :
		$info = db_fetch_array(main_db_query("SELECT * FROM SAV WHERE aDate='".$aDate."'"));
		
		$Id=$info[Id];
		//$aDate = $info[aDate];
		$Traitement = $info[Traitement];
		$PlayerId = $info[PlayerId];
		$Subject = $info[Subject];
		$Email = $info[Email];
		$Contenu  = $info[Contenu];
		break;
	case "InfosparMail" :
		$info = db_fetch_array(main_db_query("SELECT * FROM SAV WHERE Email='".$Email."'"));
		
		$Id=$info[Id];
		$aDate = $info[aDate];
		$Traitement = $info[Traitement];
		$PlayerId = $info[PlayerId];
		$Subject = $info[Subject];
		//$Email = $info[Email];
		$Contenu  = $info[Contenu];
		break;
}

$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];

$Ttraitement= array();
$Ttraitement[0]="En cours de traitement";
$Ttraitement[1]="Réponse auto";
$Ttraitement[2]="Traité";
?>
<form>
<table>
	<tr>
		<td>
			
		</td>
		<td>
			
			<input type="hidden" size=3 name=Id value="<?php echo $Id; ?>"> 
		</td>
	</tr>
	<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>
			<?$tempoReply="-----------Message d origine-----------------";
			//$tempoReply.=chr(127);
			$tempoReply.=$Contenu;
			
			?>	
				
			<a href="mailto:<?echo $Email;?>?subject=RE: SCl : Star-Six : Problème technique&body=<?echo $tempoReply;?>"><font color=#0000FF><?php echo $Email; ?></font></a>
		</td>
	</tr>
	<tr>
		<td>
			Traitement :
		</td>
		<td>
			<select  name="Traitement">
	       		<?php for($i=0;$i<=2;$i++){
	       			if($Traitement==$i)
	       			{
	       				echo "<option value=\"$i\" selected>$Ttraitement[$i]</option>";
	       			}
	       			else
	       			{	       		
		       			echo "<option value=\"$i\">$Ttraitement[$i]</option>";
		       		}	       		
			}
			?>
			</select>
			
			<!--<input type="text" size="1" name="Traitement" value="<?php echo $Traitement; ?>">
			-->
		</td>
	</tr>
	

		<td>
			Sujet :
		</td>
		<td>
			<?php echo $Subject; ?>
		</td>
	</tr>

	<tr>
		<td>
			Contenu :
		</td>
		<td>
			<?php echo $Contenu; ?>
		</td>
	</tr>
</table>
<br>
  <!--  <input type=submit name=submit value="Infos">&nbsp;&nbsp;&nbsp;
    <input type=submit name=submit value="InfosparDate">&nbsp;&nbsp;&nbsp;
        <input type=submit name=submit value="InfosparMail">&nbsp;&nbsp;&nbsp;
    -->
    <input type=submit name=submit value="Valider">&nbsp;&nbsp;&nbsp;
<!--	<input type=submit name=submit value="Supprimer">-->

<br>
	</form>

