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


####################
# Administration script defaults
####################
# pas de timeout possible qql soit l'action effectuée
set_time_limit($TIME_LIMIT);

# le script continue une fois qu'il est lancé qql soit l'état de la connection après
ignore_user_abort(true);

?>
<html>
<head></head>
<link rel="stylesheet" href="admin.css">
<body rightmargin=0>
<div align=center class=trTitle>Archivage des scores</div>
<br>
<?php
if ($submit=="Archiver")
{
	# recup de la date
	if ($aDate=="")
		$aDate = date("Y-m-d H:i:s", my_local_time());

	# car dans la base le premier indice est 0
	$min--;
	$max;
	
	if ($all!=1)
		$more = "ORDER BY Score DESC, Time ASC LIMIT ".$min.", ".$max;

	main_db_query("INSERT ScoresArchive (PlayerId,Score,Date) SELECT Id,Score,'".$aDate."' FROM Players ".$more);
	echo "<br>Copie terminée";
}
else
{
	echo "Archive des scores du ".$archiveDate;
	echo "<table border=1>";
	echo "<tr class=trTitle><td>PId</td><td>Pseudo</td><td>Score</td></tr>";
	$archives = main_db_query("SELECT *,ScoresArchive.Score AS SAScore FROM ScoresArchive LEFT JOIN Players ON Players.Id=ScoresArchive.PlayerId WHERE Date='".$archiveDate."' ORDER BY SAScore DESC");
	while($archive = db_fetch_array($archives))
	{
		echo "<tr><td>".$archive[PlayerId]."</td>";
		echo "<td>".$archive[NickName]."</td>";
		echo "<td>".$archive[SAScore]."</td></tr>";
	}
	?>
</table>
<form>
Copie des scores dans ScoresArchives :
<br>
Fixer la date : <input type=text name=aDate value="<?php echo $aDate ?>"> : indiquer la date d'archivage des scores (rien = la date actuelle)
<br>
De la place : <input type=text name=min value="<?php echo $min ?>"> (à partir de 1)
<br>
en prendre n : <input type=text name=max value="<?php echo $max ?>">
<br>
Tous <input type=checkbox name=all value=1>
<br><br>
<input type=submit name=submit value="Archiver">
<br><br>
<input type=submit name=submit value="Voir l'archive du">
<select name=archiveDate>
<?php
	# on récupère toutes les dates des archives dispo
	$archives = main_db_query("SELECT DISTINCT(Date) AS ADate FROM ScoresArchive");
	while($archive = db_fetch_array($archives))
		echo "<option>".$archive[ADate]."</option>";
?>
</select>
</form>
<?php
}
?>
