<?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"] <> 1)) header("Location: ../index.php") ?>
<?php include ("../inc/config.inc.php") ?>
<?php require ("../inc/func.inc.php") ?>
<?php require ("../inc/func_time.inc.php") ?>
<?php require ("../inc/func_date.inc.php") ?>
<?php require ("../inc/func_log.inc.php") ?>
<?php require ("../inc/fic.inc.php") ?>
<?PHP
	Archivelog(@$HTTP_SESSION_VARS["code_log"]);
?>
<?php
	$co = strip_tags(trim($_GET['co'])); // Récupération code Contrat

	$nbcontrats = 0;

	if ($co <> "")
	{
		// Récupération des informations contrat client
		$row = lit_enr_cocl($co);
		if (is_array($row))
			extract ($row);

		// Vérification qu'il existe bien des contrats et nombre de ceux-ci
		$nbcontrats = nb_cocl_in_cli($cocl_codecli);

		// Vérification du nombre de ce contrat utilisé dans les interventions
		$signe = cocl_signed($co);

		$cocl_datecreaf = formatedate($cocl_datecrea);
		$cocl_datemodf = formatedate($cocl_datemod);
		$cocl_dateenvf = formatedate($cocl_dateenv);
		$cocl_daterecf = formatedate($cocl_daterec);
		$cocl_datesigf = formatedate($cocl_datesig);
		$cocl_datedf = formatedate($cocl_dated);
		$cocl_dateff = formatedate($cocl_datef);
		$cocl_daterelf = formatedate($cocl_daterel);
		$cocl_datefinf = formatedate($cocl_datefin);

		$cc=$cocl_codecli;
		$ca=$cocl_codeage;
			
		$titre = "DETAIL CONTRAT";
	}

	$nbh = sec_heure($cocl_nbs);
	$soldeh = sec_heure($cocl_soldes);
		
	if ($cc <>"")
	{
			$row = lit_enr_cli($cc);
			extract ($row);

			$cocl_codecli = $cc;
	}
?>

<!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 - ESPACE PRIVE : Fiche Contrat Client</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 validation des formulaires -->
<script language="JavaScript" src="../inc/validator.js"></script>

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

<!-- Scripts Javascript pour vérifications -->
<script language="JavaScript" src="../inc/verif.js"></script>

<!-- Définition Javascript pour calendrier popup -->

  <!-- Feuille de Style -->
  <link rel="stylesheet" type="text/css" media="all" href="../jscal/skins/aqua/theme.css" title="Aqua" />

  <!-- Script Javascript Principal -->
  <script type="text/javascript" src="../jscal/calendar.js"></script>

  <!-- Choix du langage -->
  <script type="text/javascript" src="../jscal/lang/calendar-fr.js"></script>

  <!-- the following script defines the Calendar.setup helper function, which makes
       adding a calendar a matter of 1 or 2 lines of code. -->
  <script type="text/javascript" src="../jscal/calendar-setup.js"></script>

<!-- Fin de la définition Javascript pour calendrier popup -->

<!-- Affichage nouvelle fenêtre pour impression -->
<script type="text/javascript">
	function lanceimp(page)
	{
	  window.open(page,'impression','width='+screen.width+' height='+screen.height);
	}
</script>

</head>

<body>

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

<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<table width="100%"  border="0">
<tr>
	<td width="33%"><p><strong><em><a href="cocl_lst.php">Retour &agrave; la liste<br>
	</a></em></strong></p>
	<?PHP if ($nbcontrats <> 0)
	{
		$url_coclh = "coclhd_lst.php?or=con&cc=".$cocl_codecli."&search=".$cocl_code;
	?>
		<a href="javascript:;" onclick="fensaisie('<?PHP echo $url_coclh; ?>',800,560,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');")><img src="../img/view.gif" width="22" height="22" border="0" align="absmiddle"></a> <a href="javascript:;" onclick="fensaisie('<?PHP echo $url_coclh; ?>',800,560,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');")> Historique contrat</a><?PHP
	}
	?>
    </td>
	<td width="33%" valign="top"><div align="center"></div></td>
	<td width="33%"><div align="right">
		<div align="right">
		<?PHP
			$urlimp = "cocl_pdf.php?code=".$co;
		?>
			<a href="javascript:;" onclick="lanceimp('<?PHP echo $urlimp; ?>');")><img src="../img/print.gif" title="Imprimer le contrat" width="22" height="22" border="0" align="absmiddle"></a> 
			<a href="javascript:;" onclick="lanceimp('<?PHP echo $urlimp; ?>');")> Imprimer le contrat</a></div>
		</div>
	</td>
</tr>
</table>

<form name="cocl_maj" method="post" action="#">
<input name="codecli" type="hidden" id="codecli" value="<?PHP echo $cocl_codecli ?>">

<!-- Date de création -->
<table width="800"  border="0">
<tr>
	<td width="160" class="tfvNormal" id="f_datecreaf"><div align="right">Date Cr&eacute;ation </div></td>
	<td>
		<input name="datecreaf" type="text" id="datecreaf" value="<?PHP echo $cocl_datecreaf ?>" size="10" maxlength="10" readonly="1">
	</td>
</tr>
</table>

<!-- Code du contrat client (affiché uniquement si édition ou suppression) -->
<table width="800"  border="0">
<tr>
	<td width="160" class="tfvNormal" id="f_codecocl"><div align="right">Code </div></td>
	<td>
		<input name="code" type="text" id="code" value="<?PHP echo $cocl_code ?>" size="20" maxlength="20" readonly="1">
	</td>
</tr>
</table>

<!-- Affichage du client -->
<table width="800"  border="0">
<tr>
	<td width="400" class="tfvNormal" colspan="2"  id="f_codecli">
		<div align="center">Client 
		</div>
	</td>
	</tr>
</table>

<!-- Détails client -->
<table width="800"  border="0">
<tr>
	<td width="400" valign="top" bgcolor="#CCFFCC">
	<?PHP
	echo "<b>";
	if ($cli_ste <>"") 
	{
		echo $cli_ste."<br>";
		echo "<span class=\"annot_gras_it\">";
	}
	echo $cli_civilite." ".$cli_prenom." ".$cli_nom."<br>";
	if ($cli_ste <>"") 
	{
		echo "</span>";
	}
	echo "</b>";
	echo $cli_adr1."<br>";
	if ($cli_adr2 <>"") 
		echo $cli_adr2."<br>";
	echo Retournecp($cli_ville)." ".Retourneville($cli_ville)."<br>";
	echo "Tel : ".$cli_telf."<br>";
	?>
	</td>
	</tr>
</table>

<!-- Code de l'agence (choisi uniquement si création, affiché uniquement si édition ou suppression) -->
<table width="800"  border="0">
<tr>
	<td width="160" class="tfvNormal" id="f_agence"><div align="right">Agence</div></td>
	<td>
		<?PHP 
			$row = lit_enr_age($cocl_codeage);
			extract($row);
		?>
		<input name="nomage" type="text" id="nomage" value="<?PHP echo $age_nom ?>" size="50" maxlength="50" readonly="1">
	</td>
</tr>
</table>

<!-- Type de contrat -->
<table width="800"  border="0">
  <tr>
    <td width="160" class="tfvNormal" id="f_co"><div align="right">Type de contrat </div></td>
    <td>
		<?PHP
			$row = lit_enr_co($cocl_codeco);
			extract($row);
		?>
        <input name="nomco" type="text" id="nomco" value="<?PHP echo $co_nom ?>" size="50" maxlength="50" readonly="1">
    </td>
  </tr>
</table>

<!-- Périodicité du contrat -->
<table width="800"  border="0">
  <tr>
    <td width="160" class="tfvNormal" id="f_cope"><div align="right">Fr&eacute;quence</div></td>
    <td>
		<?PHP
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBPER." WHERE `cope_code` = '".$cocl_codecope."'";
			$rs = mysql_query($rech);
			if ($row = mysql_fetch_array($rs))
				extract ($row);
			mysql_free_result($rs);
			mysql_close($conn);
		?>
        <input name="cope" type="text" id="cope" value="<?PHP echo $cope_desc ?>" size="20" maxlength="20" readonly="1">
	 </td>
  </tr>
</table>

<!-- Délai d'intervention -->
<table width="800"  border="0">
<tr>
	<td width="160" class="tfvNormal" id="f_delai">
		<div align="right">D&eacute;lai Interv.
		</div>
		<div align="right"></div>
	</td>
    <td>
	        <input name="delai" type="text" id="delai" value="<?PHP echo $cocl_delai ?>" size="2" maxlength="2" align="right" readonly="1">
		<span class="annot_petit_it">heures ouvr&eacute;es </span>
	</td>
</tr>
</table>

<!-- Nombre d'heures par contrat -->
<table width="800"  border="0">
  <tr>
    <td width="160" class="tfvNormal" id="f_nbheures"><div align="right">Nb heures</div></td>
    <td>
		<input name="nbh" type="text" id="nbh" value="<?PHP echo $nbh ?>" size="8" maxlength="8" readonly="1">
		<span class="annot_petit_it">(0 = sans limite)</span><span class="annot_std_gras">,</span>
		<input name="typh" type="text" id="typh" value="<?PHP echo $typ_horaire[$cocl_typh]; ?>" size="20" maxlength="20" readonly="1">
		<?PHP
		if ($cocl_typh == 1)
		{
		?>
			<br>
			<span class="annot_std_it">Solde :</span>		
			<input name="soldeh" type="text" id="soldeh" value="<?PHP echo $soldeh ?>" size="8" maxlength="8">
		<?PHP
		}
		?>
  </tr>
</table>

<!-- Dates de "vie" du contrat -->
<table width="800"  border="0">
  <tr>
    <td width="160" class="tfvNormal" id="f_validite"><div align="right">Validit&eacute;</div></td>
    <td>
		<span class="annot_petit_gras">Du</span>      
		<input name="datedf" type="text" id="datedf" value="<?PHP echo $cocl_datedf ?>" size="10" maxlength="10" readonly="1">
		 <span class="annot_petit_gras">au</span>	    
		 <input name="dateff" type="text" id="dateff" value="<?PHP echo $cocl_dateff ?>" size="10" maxlength="10" readonly="1">
	</td>
  </tr>
</table>

<!-- Nombre de jours de préavis -->
<table width="800"  border="0">
  <tr>
    <td width="160" class="tfvNormal" id="f_preavis"><div align="right">Pr&eacute;avis</div></td>
    <td>
		<input name="preavis" type="text" id="preavis" value="<?PHP echo $cocl_preavis ?>" size="3" maxlength="3" align="right" readonly="1"> 
	</td>
  </tr>
</table>

<!-- Détail matériel concerné -->
<table width="800"  border="0">
  <tr>
    <td width="160" valign="top" class="tfvNormal" id="f_matos"><div align="right">Mat&eacute;riel Concern&eacute; </div></td>
    <td>
		<textarea name="matos" cols="80" rows="20" id="matos" readonly><?PHP echo $cocl_matos ?></textarea>
	</td>
  </tr>
</table>

<!-- Signataire du contrat -->
<table width="800"  border="0">
<tr>
	<td width="160" class="tfvNormal" id="f_datesig"><div align="right">Sign&eacute; le </div></td>
	<td>
		<input name="datesig" type="text" id="datesig" value="<?PHP echo $cocl_datesigf ?>" size="10" maxlength="10" readonly="1">
	</td>
</tr>
<tr>
	<td width="160" class="tfvNormal" id="f_signe"><div align="right">Sign&eacute; par </div></td>
	<td>
		<input name="signe" type="text" id="signe" value="<?PHP echo $cocl_signe ?>" size="70" maxlength="70" readonly="1">
	</td>
</tr>
</table>

<br>

<!-- Contrat renouvelé ou pas ? -->
<table width="800"  border="0">
<tr>
	<td width="160" class="tfvNormal" id="f_renouv"><div align="right">Renouvel&eacute;</div></td>
	<td>
		<input name="renouv" type="text" id="renouv" value="<?PHP echo $niv_renouv[$cocl_renouv]; ?>" size="3" maxlength="3" readonly="1">
		<span class="annot_std_gras">Nouveau contrat :</span>
		<input name="num" type="text" id="num" value="<?PHP echo $cocl_rnum; ?>" size="20" maxlength="20" readonly="1">
	</td>
</tr>
</table>

<!-- Date de clôture du contrat -->
<table width="800"  border="0">
<tr>
	<td width="160" class="tfvNormal" id="f_datefinf"><div align="right">Contrat cl&ocirc;t le </div></td>
	<td>
		<input name="datefinf" type="text" id="datefinf" value="<?PHP echo $cocl_datefinf ?>" size="10" maxlength="10" readonly="1">
	</td>
</tr>
</table>

</form>

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