<?php
include("../config.php3");
include($BIB."bib_generic.php3");
?>
<html>
<head></head>
<link rel="stylesheet" href="admin.css">
<body rightmargin=0>
<div align=center class=trTitle>Stats Promo</div>
<br>

<table border=1>
	<tr class=trTitle>
		<td>Id</td>
		<td>Libellé</td>
		<td>Total clicks</td>
		<td>Total Affichés</td>
		<td>Transformation</td>
	</tr>
<?php
switch($submit)
{
	case "Valider":
		$info = db_fetch_array(main_db_query("SELECT * FROM FromNews WHERE NewsId='".$Id."'"));
	
		if ($Id==0)
		{
			# on insere une nouvelle réponse
			main_db_query("INSERT INTO FromNews (Lib, Nb_Mails_Envoyes) VALUES ('".$Text."', '".$NbMailSent."')");
		}
		elseif (!$info)
		{
			# on insere une nouvelle réponse
			main_db_query("INSERT INTO FromNews (NewsId, Lib, Nb_Mails_Envoyes) VALUES ('".$Id."', '".$Text."', '".$NbMailSent."')");
		}
		else
		{
			# on update si c'est une modif
			main_db_query("UPDATE FromNews SET Lib='".$Text."', Nb_Mails_Envoyes = '".$NbMailSent."' WHERE NewsId='".$Id."'");
		}
		$Id=0;
		break;
		
	case "Supprimer":
		main_db_query("DELETE FROM FromNews WHERE NewsId='".$Id."'");
		$Id=0;
		$Text = "";
		$Quantite = "";
		$Chances = "";
		$ShowTime = "";
		$EndTime = "";
		$Image = "";
		break;
	
	case "Infos":
		$info = db_fetch_array(main_db_query("SELECT * FROM FromNews WHERE NewsId='".$Id."'"));
		
		$Text = $info[Lib];
		$Quantite = $info[Quantite];
		$Chances = $info[Chances];
		$ShowTime = $info[ShowTime];
		$EndTime = $info[EndTime];
		$Image = $info[Image];
		break;
}




$rows = main_db_query("SELECT * FROM FromNews ORDER BY NewsId ASC");

while($row = db_fetch_array($rows))
{
	echo "<tr><td>".$row['NewsId']."</td>";
	echo "<td>".$row['Lib']."</td>";
	echo "<td align=right>".$row['Total']."</td>";
	echo "<td align=right>".$row['Nb_Mails_Envoyes']."</td>";
	if ($row['Nb_Mails_Envoyes'] > 0)
		echo "<td align=right>".intval($row['Total'] * 100 / $row['Nb_Mails_Envoyes'])."%</td></tr>";
	else
		echo "<td align=right>-</td></tr>";
}

?>
</table>


<form>
<table>
	<tr>
		<td>
			Id :
		</td>
		<td>
			<input type="text" size=3 name=Id value="<?php echo $Id ?>">
		</td>
	</tr>
	<tr>
		<td>
			Libellé :
		</td>
		<td>
			<input type="text" size=30 name=Text value="<?php echo $Text ?>">
		</td>
	</tr>
	<tr>
		<td>
			Total affichés :
		</td>
		<td>
			<input type="text" size=30 name=NbMailSent value="<?php echo $NbMailSent ?>">
		</td>
	</tr>
</table>
<br>
    <input type=submit name=submit value="Infos">&nbsp;&nbsp;&nbsp;
    <input type=submit name=submit value="Valider">&nbsp;&nbsp;&nbsp;
	<input type=submit name=submit value="Supprimer"><br>
	</form>
<a class=under href="<?php echo $PHP_SELF ?>">Rafraichir la page</a>