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

Version 0.9.9

Copyright (C) 2006-2009  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

Web : http://smitst.homelinux.com
****************************************************************************************/

// Vérification des tentatives de hack
$pos=strpos($_SERVER['PHP_SELF'],"inc.php");
if ($pos===FALSE)
	$ok_inc=TRUE;
else
	$ok_inc=FALSE;
if ($ok_inc==FALSE) header("Location: ../index.php");

include_once("../inc/func.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
Archivelog(@$_SESSION["code_log"]);

// Variables Formulaire
$titre = stripslashes(strip_tags(trim(@$_POST["titre"])));
$td = strip_tags(trim(@$_POST["td"]));

$code = str_majuscules(strip_tags(trim(@$_POST["code"])));
$desc = str_majuscules(strip_tags(str_escape(trim(@$_POST["desc"]))));
$jourd1 = strip_tags(trim(@$_POST["jourd1"]));
$jourd2 = strip_tags(trim(@$_POST["jourd2"]));
$nduree = strip_tags(trim(@$_POST["nduree"]));
$tduree = strip_tags(trim(@$_POST["tduree"]));
$val = strip_tags(trim(@$_POST["valide"]));
if ($val == "Oui")
	$valide = TRUE;
else
	$valide = FALSE;

$retourliste = TRUE;

$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
mysql_select_db(DBNAME);

switch ($td)
{
	// Ajout de la fiche Période
	case "add" :
		$rech = "SELECT * FROM " .TBPERLOC. " WHERE `perloc_code` = '$code'";
		$rs = mysql_query($rech) or die(mysql_error());
		if (mysql_num_rows($rs) == 0)
		{
			$rech = "INSERT INTO " .TBPERLOC. " (perloc_code,perloc_desc,perloc_jourd1,perloc_jourd2,";
			$rech.= "perloc_nduree,perloc_tduree,perloc_valide)";
			$rech.=" VALUES ('$code','$desc','$jourd1','$jourd2','$nduree','$tduree','$valide')";
			$rs = mysql_query($rech) or die(mysql_error());
			$msg = $txt_fiche_add;
		}
		else
		{
			$msg = $txt_fiche_exist;
			$retourliste = FALSE;
		}
		mysql_close($conn);
		break;
		
	// MAJ de la fiche Période
	case "edit" :
		mysql_close($conn);
		
		// Vérifie si utilisé dans un barême
		if (exist_perloc_in_barloc($code) == TRUE)
		{
			$msg = "Cette p&eacute;riode est utilis&eacute;e dans un bar&ecirc;me de location.";
			$retourliste = FALSE;
		}
		else
		{
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
	
			// MAJ de la fiche Période
			$rech = "UPDATE `" .TBPERLOC. "` SET `perloc_code`='".$code."', `perloc_desc`='".$desc."', `perloc_jourd1`='".$jourd1."',";
			$rech.= " `perloc_jourd2`='".$jourd2."',";
			$rech.= " `perloc_nduree`='".$nduree."', `perloc_tduree`='".$tduree."', `perloc_valide`='".$valide."'";
			$rech.= " WHERE `perloc_code` = '".$code."'";
			$rs = mysql_query($rech) or die(mysql_error());
			mysql_close($conn);
	
			$msg = $txt_fiche_mod;
			$retourliste = TRUE;
		}
		break;
	
	// Suppression de la fiche Période
	case "del" :
		mysql_close($conn);
		
		// Vérifie si utilisé dans un barême
		if (exist_perloc_in_barloc($code) == TRUE)
		{
			$msg = "Cette p&eacute;riode est utilis&eacute;e dans un bar&ecirc;me de location.";
			$retourliste = FALSE;
		}
		else		
		{
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
	
			// SUPPRESSION de la fiche Période
			$rech = "DELETE FROM `" .TBPERLOC. "` WHERE `perloc_code` = '$code'";
			$rs = mysql_query($rech) or die(mysql_error());
			mysql_close($conn);

			$msg = $txt_fiche_del;			
		}
		break;
		
	default :
		break;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>SMI - <?PHP echo $title_esp_prive; ?> : Fiche P&eacute;riode de Location</title>

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

<!-- Feuille de style & Script pour le menu -->

<script language="JavaScript" src="../jscript/coolmenus/coolmenus4.js"></script>

<!-- Scripts Javascript pour fenêtres -->
<script language="JavaScript" src="../jscript/fen.js"></script>

</head>
<body>

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

<p align="center"><span class="titrepage"><?PHP echo $titre ?></span></p>
<p align="center">&nbsp;</p>
<p align="center">
<?PHP if ($retourliste==FALSE)
	echo '<span class="alerte1">';
else
	echo '<span class="annot_std_gras">';
?>
<?PHP echo $msg ?>
</span>
</p>
<?PHP 
if ($retourliste == FALSE)
	aff_ret_idx_man($td,"perloc_lst.php?ta=m",$txt_lnk_ret_liste,TRUE);
else
	aff_ret_lst_auto("perloc_lst.php?ta=m",2000);
include_once("pied.php");
?>
