<?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_time.inc.php");
include_once("../inc/func_txt.inc.php");
Archivelog(@$_SESSION["code_log"]);

$td = strip_tags(trim($_GET['td']));
$coderech = strip_tags(trim($_GET['code']));

$pbm_per=FALSE;

if ($coderech <> "")
{
	// Récupération des informations période
	$row = lit_enr_perloc($coderech);
	if (is_array($row))
	{
		extract ($row);
		$heured1 = substr($perloc_heured1,0,5);
		$heured2 = substr($perloc_heured2,0,5);
	}
	else
		$pbm_per=TRUE;
}
else
{
	if ($td <> "add")
		$pbm_per=TRUE;
}

switch ($td)
{
	case "add" :
		$titre = "CREATION PERIODE DE LOCATION";
		$perloc_jourd1=-1;
		$perloc_jourd2=-1;
		$perloc_valide=1;
		break;
	case "edit" :
		$titre = "MODIFICATION PERIODE DE LOCATION";
		break;
	case "del" :
		$titre = "SUPPRESSION PERIODE DE LOCATION";
		break;
	default :
		$pbm_per=TRUE;
		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>

<!-- Scripts Javascript pour contrôle de formulaire -->
<script	type="text/javascript" src="../jscript/vform/vform.js"></script>

<script language="javascript">
<!--
var tab1_champ=new Array(
	"nom:code ; format:alphanum ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_code); ?> ; lmx:10 ; stok:frmok ; stbad:frmbad",
	"nom:desc; format:txt ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_lib); ?> ; lmx:50 ; stok:frmok ; stbad:frmbad",
	"nom:nduree; format:unsigned ; req:Y ; txt:Durée ; vmn:1 ; lmx:3 ; stok:frmok ; stbad:frmbad");
//-->
</script>

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

<!-- Scripts Javascript divers -->
<script language="JavaScript" src="../jscript/divers.js"></script>

<!-- Scripts Javascript vérification saisies -->
<script language="JavaScript" src="../jscript/verif_field.js"></script>

</head>

<?PHP if ($td == "del"){ ?>
<body onload="warndel();metReadonly();">
<?PHP } else { ?>
<body onLoad="metFocus();">
<?PHP }
include_once("../inc/entete.inc.php"); 

if ($pbm_per==FALSE)
{
?>

<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<table width="100%"  border="0">
  <tr>
    <td width="33%"><strong><em><a href="perloc_lst.php?ta=m"><?PHP echo $txt_lnk_ret_liste; ?></a></em></strong></td>
    <td width="33%">
	<div id="oblig" align="center" class="annot_petit_it">(<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>"> : <?PHP echo $txt_div_saisoblg; ?>)
	</div>
	</td>
    <td width="33%">&nbsp;</td>
  </tr>
</table>
<form name="perloc_maj" id="perloc_maj" method="post" action="perloc_enr.php" onSubmit="javascript:; return (VForm(this,tab1_champ,'','<?PHP echo $_SESSION["lng"]; ?>'));">
      <input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
      <input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">

<table width="100%"  border="0">
    <tr>
      <td width="160" class="rubfrm" id="f_code" align="right"><?PHP echo $txt_chp_code; ?></td>
      <td>
      <?PHP if ($td == "add") { ?>
		  <input name="code" type="text" id="code" value="<?PHP echo $perloc_code ?>" size="10" maxlength="10" onChange="javascript:this.value=this.value.toUpperCase();">
          <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
      <?PHP } else { ?>
		  <input name="code" type="text" id="code" value="<?PHP echo $perloc_code ?>" size="10" maxlength="10" readonly="readonly">
      <?PHP } ?>
	  </td>
    </tr>
    <tr>
      <td width="160" class="rubfrm" id="f_desc" align="right"><?PHP echo $txt_chp_lib; ?></td>
      <td>
      <?PHP if (($td == "add") OR ($td=="edit")) { ?>
	  <input name="desc" type="text" id="desc" value="<?PHP echo htmlspecialchars($perloc_desc) ?>" size="50" onChange="javascript:this.value=this.value.toUpperCase();">
	   <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
      <?PHP } else { ?>
	  <input name="desc" type="text" id="desc" value="<?PHP echo htmlspecialchars($perloc_desc) ?>" size="50" readonly="readonly">
      <?PHP } ?>
	  </td>
    </tr>
    <tr>
      <td width="160" class="rubfrm" id="f_jourd1" align="right">Commence entre un<br />et un</td>
      <td>
      <?PHP if (($td == "add") OR ($td=="edit")) { ?>
		<select name="jourd1" size="1" id="jourd1" onChange="verif_jour1(this.value);">
		<?PHP
			foreach ($lng_tjouri as $key=>$value)
			{
				echo '<option value="'.$key.'"'; 
				if ($perloc_jourd1 == $key)
					echo ' selected';
				echo '>';
				echo $value."</option>";
			}
		?>
		</select>
		 <span class="annot_petit_it">(inclus)</span>
      	<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<br />
		<select name="jourd2" size="1" id="jourd2" onChange="verif_jour2(this.value);">
		<?PHP
			foreach ($lng_tjouri as $key=>$value)
			{
				echo '<option value="'.$key.'"'; 
				if ($perloc_jourd2 == $key)
					echo ' selected';
				echo '>';
				echo $value."</option>";
			}
		?>
		</select>
		 <span class="annot_petit_it">(inclus)</span>
      	<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
      <?PHP } else { ?>
		<input name="njourd1" type="text" id="njourd1" value="<?PHP echo $lng_tjouri[$perloc_jourd1]; ?>" readonly="readonly">
		  &agrave; partir de
		 <input name="heured1" type="text" id="heured1" value="<?PHP echo $heured1; ?>" size="5" readonly="readonly">
		 <span class="annot_petit_it">(inclus)</span>
		 <br />
		<input name="njourd2" type="text" id="njourd2" value="<?PHP echo $lng_tjouri[$perloc_jourd2]; ?>" readonly="readonly">
		 jusqu'&agrave;
		 <input name="heured2" type="text" id="heured2" value="<?PHP echo $heured2; ?>" size="5" readonly="readonly">
		 <span class="annot_petit_it">(inclus)</span>
      <?PHP } ?>
	  <br /><span class="annot_petit_it">(Jours cons&eacute;cutifs)</span>
      </td>
    </tr>
    <tr>
      <td width="160" class="rubfrm" id="f_duree" align="right">Sur une dur&eacute;e de</td>
      <td>
      <?PHP if (($td == "add") OR ($td=="edit")) { ?>
			<input name="nduree" type="text" id="nduree" value="<?PHP echo $perloc_nduree ?>" size="3">
			<select name="tduree" id="tduree">
			<?PHP
			// Création de la liste des types de durées
			foreach ($lng_tduree as $key=>$value)
			{
				echo '<option value="'.$key.'"'; 
				if ($perloc_tduree == $key)
					echo ' selected';
				echo '>';
				echo $value."</option>";
			}
			?>
			</select>
			 <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
      <?PHP } else { ?>
		<input name="nduree" type="text" id="nduree" value="<?PHP echo $perloc_nduree ?>" size="3" readonly="readonly">
		<input name="tduree" type="hidden" id="tduree" value="<?PHP echo $perloc_tduree; ?>">
		<input name="ntduree" type="text" id="ntduree" value="<?PHP echo $lng_tduree[$perloc_tduree]; ?>" readonly="readonly">
      <?PHP } ?>
	  <br /><span class="annot_petit_it">(A partir du jour de location)</span>
	  </td>
    </tr>
    <tr>
      <td width="160" class="rubfrm" id="f_valide" align="right">Valide ?</td>
      <td>
	  <?PHP
      if (($td == "add") OR ($td=="edit")) {
		echo "<select name=\"valide\" size=\"1\" id=\"valide\">";
		echo "<option value=\"Oui\"";
		if ($perloc_valide == TRUE)
			echo" selected";
		echo">".$sel_lst_oui."</option>";
		echo "<option value=\"Non\"";
		if ($perloc_valide == FALSE)
			echo" selected";
		echo ">".$sel_lst_non."</option>";
		echo "</select>";
		?>
		 <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
      <?PHP } else { ?>
		<input name="nvalide" type="text" id="nvalide" value="<?PHP echo $non_oui[$perloc_valide]; ?>">
      <?PHP } ?>
	  </td>
    </tr>
  </table>
  <p align="center">
    <?PHP if (($td == "add") OR ($td == "edit")) { ?>
    <input name="RAZ" type="reset" class="bton_std" id="RAZ" value="<?PHP echo $but_reinit; ?>">
    <input name="submit" type="submit" class="bton_std" id="submit" value="<?PHP echo $but_enr; ?>">
    <?PHP } ?>
    <?PHP if ($td == "del") { ?>
    <input name="del" type="submit" class="bton_std" id="del" value="<?PHP echo $but_del; ?>">
    <input name="annul" type="button" class="bton_std" id="annul" value="<?PHP echo $but_cancel; ?>" onclick="javascript:; history.back();">
    <?PHP } ?>
  </p>
</form>
<?PHP
}
else
	aff_ret_pbm_auto("perloc_lst.php",2000);
include_once("pied.php");
?>
