<?php
/****************************************************************************************
SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV

Copyright (C) 2006  Sylvain FATOME

This program is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation; 
either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program
(in the directory docs); 
if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
Boston, MA  02110-1301, USA.

Contact : galawa@free.fr
****************************************************************************************/

session_start(); 
?>
<?php if ((@$HTTP_SESSION_VARS["etat_log"] <> "connecte") or (@$HTTP_SESSION_VARS["niv_log"] <> 9)) header("Location: ../index.php") ?>
<?php include ("../inc/config.inc.php") ?>
<?php require ("../inc/func.inc.php") ?>
<?php require ("../inc/func_date.inc.php") ?>
<?php require ("../inc/fic.inc.php") ?>
<?php
	 	// Variables Formulaire
		$typdde = strip_tags(trim($_GET['td']));

		$dateok = TRUE;

		if (strip_tags(trim(@$_POST["purge"])) == "Purger")
		{
			$date1f = strip_tags(trim(@$_POST["date1f"]));
			if ($date1f <> "")
				$date1 = datefrang($date1f);
			else
				$dateok = FALSE;
			$date2f = strip_tags(trim(@$_POST["date2f"]));
			if ($date2f <> "")
				$date2 = datefrang($date2f);
			else
				$dateok = FALSE;
		}

		$retourliste = TRUE;

		if ($typdde == "del")
		{
			if ($dateok == TRUE)
			{
				$msg = "";

				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
	
				// Vérification de l'existence de la fourchette de dates

				if (strip_tags(trim(@$_POST["purge"])) == "Purger")
					$rech = "SELECT * FROM `" .TBLOG. "` WHERE `log_date` >= '$date1' AND `log_date` <= '$date2'";
				if (strip_tags(trim(@$_POST["purge"])) == "Tout Purger")
					$rech = "SELECT * FROM `" .TBLOG. "`";
				$rs = mysql_query($rech) or die(mysql_error());
				if (mysql_num_rows($rs) <> 0)
				{
					$fourchette = TRUE;
				}
				else
				{
					$msg = "Aucun logs sur cette fourchette de dates.";
					$fourchette=FALSE;
					$retourliste = FALSE;
				}

				if ($fourchette == TRUE)
				{	
					// SUPPRESSION des logs
	
					if (strip_tags(trim(@$_POST["purge"])) == "Purger")
						$rech = "DELETE FROM `" .TBLOG. "` WHERE `log_date` >= '$date1' AND `log_date` <= '$date2'";
					if (strip_tags(trim(@$_POST["purge"])) == "Tout Purger")
						$rech = "TRUNCATE TABLE `" .TBLOG. "`";
					$rs = mysql_query($rech) or die(mysql_error());
	
					$msg = "Logs purgés avec succès !";
					$retourliste = TRUE;
				}

				mysql_close($conn);
			}
			else
			{
				$msg = "Il y a un problème sur les dates saisies";
				$retourliste = FALSE;
			}
		}
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>SMI - ESPACE PRIVE : Logs de Connexion</title>

<!-- Feuille de style pour les affichages courants -->
<link href="../inc/smi.css" rel="stylesheet" type="text/css">

<!-- Feuille de style & Script pour le menu -->
<link href="../inc/menu.css" rel="stylesheet" type="text/css">
<script language="JavaScript" src="../coolmenus/coolmenus4.js"></script>

<!-- Scripts Javascript pour affichages -->
<script language="JavaScript" src="../inc/aff.js"></script>

</head>
<body>

<?php 
	include_once ("../inc/entete.php"); 
?>


<p align="center"><span class="titrepage">PURGE DES LOGS</span></p>
<p align="center">&nbsp;</p>
<p align="center" class="annot_gras_it"><?PHP echo $msg ?></p>

<?PHP if ($retourliste == FALSE) { ?>
	<table width="100%"  border="0">
	  <tr>
		<td width="3%">&nbsp;</td>
		<td width="44%"><div align="right"><a href="log_lst.php?ta=m"><img src="../img/liste.gif" width="33" height="34" border="0" align="absmiddle"></a> <a href="log_lst.php?ta=m" class="annot_gras_it">Retour &agrave; la liste</a></div></td>
		<td width="7%">&nbsp;</td>
		<td width="43%"><a href="index.php"><em><img src="../img/index.gif" width="48" height="48" border="0" align="absmiddle"> </em><span class="annot_gras_it">Revenir &agrave; l'accueil</span> </a></td>
		<td width="3%">&nbsp;</td>
	  </tr>
	</table>
<?PHP } else { ?>
	<script type="text/javascript">
	window.setTimeout("location=('log_lst.php?ta=m');",2000)
	</script>
	<p align="center" class="annot_std_it">Retour à la liste dans 2 secondes...</p>
	<?PHP } ?>

<?php 
	include_once ("pied.php")
?>

