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

Version 0.9.6
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
****************************************************************************************/

include ("../inc/config.inc.php");
?>
<?php require ("../inc/func.inc.php") ?>
<?php require ("../inc/func_date.inc.php") ?>
<?php require ("../inc/func_time.inc.php") ?>
<?php require ("../inc/func_log.inc.php") ?>
<?php require ("../inc/func_txt.inc.php") ?>
<?php require ("../inc/fic.inc.php") ?>
<?php require ("../inc/lst.inc.php") ?>
<?PHP
	Archivelog(@$HTTP_SESSION_VARS["code_log"]);
?>
<?php
	$codecocl = strip_tags(trim($_GET['cocl'])); // Récupération code contrat

	$contrat_ok = TRUE;
	
	if ($codecocl <> "")
	{
		// Récupération des informations client
		$row = lit_enr_cocl($codecocl);
		if (is_array($row))
		{
			extract ($row);
			
			if (@$HTTP_SESSION_VARS["niv_log"] >=3)
			{
				if ((@$HTTP_SESSION_VARS["niv_log"] == 4) OR (@$HTTP_SESSION_VARS["niv_log"] == 3))
				{
					if ($cocl_codeage <> @$HTTP_SESSION_VARS["code_age"]) 
					{
						$contrat_ok = FALSE;
					}
				}
			}
			else
			{
				$contrat_ok = FALSE;
			}
		}
		else
			$contrat_ok = FALSE;
	}
	else
		$contrat_ok = FALSE;
?>

<!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 : R&eacute;sum&eacute; contrat</title>

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

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

<!-- 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>

</head>
<body>
<?PHP
if ($contrat_ok == TRUE)
{
	$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);

	$nbh = sec_heure($cocl_nbs);
	$soldeh = sec_heure($cocl_soldes);
?>
	
	<p align="center"> <span class="titrepage">RESUME CONTRAT</span></p>
	<table width="880"  border="0">
	<tr>
		<td width="33%" align="left">&nbsp;</td>
		<td width="33%"><div align="center"><span class="titre_gras">Num&eacute;ro <?php echo $codecocl; ?></span></div></td>
		<td width="33%"><div align="right"><input name="ferm" type="button" id="ferm" value="Quitter" onclick="javascript:; window.self.close('');"></div></td>
	</tr>
	</table>
	
	<!-- Date de création -->
	<table width="800"  border="0">
	<tr>
		<td width="160" class="rubfrm" 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>
	
	<!-- Type de contrat -->
	<table width="800"  border="0">
	  <tr>
		<td width="160" class="rubfrm" id="f_co"><div align="right">Contrat Type </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="rubfrm" 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="tcope" type="text" id="tcope" 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="rubfrm" id="f_delai" align="right">
			D&eacute;lai Interv.
		</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="rubfrm" id="f_nbheures"><div align="right">Nb heures</div></td>
		<td>
			<input name="nbh" type="text" id="nbh" value="<?PHP echo substr($nbh,0,5) ?>" size="5" maxlength="5" readonly="1">
			<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)
			{
			?> 
				<span class="annot_std_it"> (Solde :</span>		
				<input name="soldeh" type="text" id="soldeh" value="<?PHP echo substr($soldeh,0,5) ?>" size="5" maxlength="5" readonly="1">
				<span class="annot_std_it">)</span>		
			<?PHP
			}
			?>
	  </tr>
	</table>
	
	<!-- Dates de "vie" du contrat -->
	<table width="800"  border="0">
	  <tr>
		<td width="160" class="rubfrm" 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="rubfrm" 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"> 
			<span class="annot_std_gras">jours avant date d'&eacute;ch&eacute;ance</span> 
		</td>
	  </tr>
	</table>
	
	<!-- Détail matériel concerné -->
	<table width="800"  border="0">
	  <tr>
		<td width="160" valign="top" class="rubfrm" id="f_matos"><div align="right">Mat&eacute;riel Concern&eacute; </div></td>
		<td>
			<textarea name="matos" cols="95" rows="20" id="matos" readonly="readonly"><?PHP echo $cocl_matos ?></textarea>
		</td>
	  </tr>
	</table>
	
	<p align="center"><span class="annot_std_gras">Site couverts par le contrat</span></p>

	<!-- Sites couverts -->
	<?PHP
	// Création de la liste des sites secondaires
	
	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	
	// Vérification si site principal couvert
	$sitep=FALSE;
	$rech = "SELECT * FROM " .TBCOCL. " WHERE `cocl_code`= '".$codecocl."'";
	$rs = mysql_query($rech);
	
	if (mysql_num_rows($rs) <> 0)
	{
		if ($row = mysql_fetch_assoc($rs)) 
		{
			if ($row["cocl_sitep"]==1)
				$sitep=TRUE;
		}
	}

	// Vérification si site principal couvert
	$rech = "SELECT * FROM " .TBSCLI. "," .TBSCLIC. " WHERE `sclic_codecocl`= '".$codecocl."' AND " .TBSCLIC. ".sclic_idscli=" .TBSCLI. ".scli_id ORDER BY " .TBSCLI. ".scli_ste";
	$rs = mysql_query($rech);
	if ((mysql_num_rows($rs) <> 0) OR ($sitep==TRUE))
	{
		echo "<table class=\"MtableD\" border=\"0\" width=\"850\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">\n";
		 
		// Création de l'entête de la table "sites d'intervention"
		echo "<th>";
		echo "Coordonn&eacute;es";
		echo "</th>\n";
		echo "<th>";
		echo "Tel/Fax";
		echo "</th>\n";
		echo "<th>";
		echo "Contact";
		echo "</th>\n";
		echo "<th>";
		echo "Créé le";
		echo "</th>\n";
		
		$j = 0;

		if ($sitep==TRUE)
		{
			// Création de l'entête de ligne (TR)
			creetrlstdet($j);
			
			echo "<td>\n";
			echo "Site principal";
			echo "</td>\n";
			echo "<td align=\"center\">\n";
			echo "&nbsp;";
			echo "</td>\n";
			echo "<td align=\"center\">\n";
			echo "&nbsp;";
			echo "</td>\n";
			echo "<td align=\"center\">\n";
			echo "&nbsp;";
			echo "</td>\n";

			echo "</tr>\n";
		
			$j++;
		}

		while ($row = mysql_fetch_assoc($rs)) 
		{         
			// Création de l'entête de ligne (TR)
			creetrlstdet($j);
			
			echo "<td>\n";
			echo $row["scli_ste"];
			echo "<br>";
			echo $row["scli_adr1"];
			echo "<br>";
			if ($row["scli_adr2"]<>"")
			{
				echo $row["scli_adr2"];
				echo "<br>";
			}
			echo Retournecp($row["scli_ville"])." ".Retourneville($row["scli_ville"])."<br>";
			echo "</td>\n";
			echo "<td align=\"center\">\n";
			echo "T.".$row["scli_telf"];
			if ($row["scli_fax"]<>"")
			{
				echo"<br>";
				echo "F.".$row["scli_fax"];
			}
			echo "</td>\n";
			echo "<td align=\"center\">\n";
			echo $row["scli_rcivil"]." ".$row["scli_rprenom"]." ".$row["scli_rnom"];
			echo "<br>";
			echo "T.".$row["scli_rtelf"];
			if ($row["scli_rfax"]<>"")
			{
				echo "<br>";
				echo "F.".$row["scli_rfax"];
			}
			if ($row["scli_rtelp"]<>"")
			{
				echo "<br>";
				echo "P.".$row["scli_rtelp"];
			}
			echo "</td>\n";
			echo "<td align=\"center\">\n";
			echo formatedate($row["scli_datecrea"]);
			echo "</td>\n";

			echo "</tr>\n";
		
			$j++;
		}
		
		echo "</table>\n";
		// Fin affichage table liste sites
	}
	mysql_free_result($rs);
	?>

	<!-- bouton de fermeture de la fenêtre -->
	<p align="center">
		<input name="ferm" type="button" id="ferm" value="Quitter" onclick="javascript:; window.self.close('');">
	</p>
<?PHP
}
else
{
?>
	<script type="text/javascript">
	window.self.close('');
	</script>
<?PHP
}
?>

</body>
</html>
