<?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_date.inc.php");
include_once("../inc/func_time.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/fic_co.inc.php");
include_once("../inc/fic_cocl.inc.php");
include_once("../inc/fic_int.inc.php");
include_once("../inc/lst.inc.php");
Archivelog(@$_SESSION["code_log"]);

$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 (CheckNivLog("1-3-4-5-9")==TRUE)
		{
			if (CheckNivLog("3-4")==TRUE)
			{
				if ($cocl_codeage <> @$_SESSION["code_age"]) 
					$contrat_ok = FALSE;
			}

			if (CheckNivLog("1")==TRUE)
			{
				if ($cocl_codecli <> @$_SESSION["code_log"]) 
					$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 - <?PHP echo $title_esp_prive; ?> : R&eacute;sum&eacute; contrat</title>

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

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

<!-- Scripts Javascript pour vérifications -->
<script language="JavaScript" src="../jscript/verif_field.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,3,TRUE);
	$soldeh = sec_heure(soldes_contrat($codecocl,TRUE),3,TRUE);
?>
	
	<p align="center"> <span class="titrepage">RESUME CONTRAT</span></p>
	<table width="100%"  border="0">
	<tr>
		<td width="33%" align="left">&nbsp;</td>
		<td width="33%" align="center"><span class="titre_gras">Num&eacute;ro <?php echo $codecocl; ?></span></td>
		<td width="33%" align="right"><input name="ferm" type="button" class="bton_std" id="ferm" value="<?PHP echo $but_quit; ?>" onclick="javascript:; window.self.close('');"></td>
	</tr>
	</table>
	
	<!-- Date de création -->
	<table width="100%"  border="0">
	<tr>
		<td width="160" class="rubfrm" id="f_datecreaf" align="right">Date Cr&eacute;ation </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="100%"  border="0">
	  <tr>
		<td width="160" class="rubfrm" id="f_co" align="right">Contrat Type </td>
		<td>
			<?PHP
				$row = lit_enr_co($cocl_codeco);
				extract($row);
			?>
			<input name="nomco" type="text" id="nomco" value="<?PHP echo htmlspecialchars($co_nom,ENT_NOQUOTES) ?>" size="50" readonly="1">
		</td>
	  </tr>
	</table>

	<!-- Périodicité du contrat -->
	<table width="100%"  border="0">
	  <tr>
		<td width="160" class="rubfrm" id="f_cope" align="right">Fr&eacute;quence</td>
		<td>
			<?PHP
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
				$rech = "SELECT * FROM ".TBPER." WHERE `per_code` = '".$cocl_codeper."'";
				$rs = mysql_query($rech) or die(mysql_error());
				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 htmlspecialchars($per_desc,ENT_NOQUOTES) ?>" size="20" readonly="1">
		 </td>
	  </tr>
	</table>
	
	<!-- Délai d'intervention -->
	<table width="100%"  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="100%"  border="0">
	  <tr>
		<td width="160" class="rubfrm" id="f_nbheures" align="right">Nb heures</td>
		<td>
			<input name="nbh" type="text" id="nbh" value="<?PHP echo heure_to_hhmm($nbh); ?>" size="6" maxlength="6" 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 heure_to_hhmm($soldeh); ?>" size="6" maxlength="6" readonly="1">
				<span class="annot_std_it"> <span class="annot_petit_it">(Heures &agrave; sortir : <?PHP echo heure_to_hhmm(sec_heure(tps_trav_non_clot($cocl_code,TRUE),3,TRUE)); ?></span>)</span>		
				
			<?PHP
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);

				// Création de la liste des reports affectés à ce contrat (s'il y en a)
				$rech = "SELECT * FROM ".TBCOCLR." WHERE coclr_cocldest = '".$codecocl."' ORDER BY coclr_codeint";
				$rs = mysql_query($rech) or die(mysql_error());
				
				if (mysql_num_rows($rs) <> 0)
				{
					echo "<table class=\"MtableD\" border=\"0\" width=\"600\" cellpadding=\"0\" cellspacing=\"0\">\n";     
					 
					// Création de l'entête de la table "détails reports"
					echo "<th>";
					echo "D&eacute;tails des reports affect&eacute;s &agrave; ce contrat";
					echo "</th>\n";
					echo "<th>";
					echo "Dur&eacute;e";
					echo "</th>\n";
				
					$j = 0;
					
					while ($row = mysql_fetch_assoc($rs)) 
					{         
						extract($row);
						
						// Création de l'entête de ligne (TR)
						creetrlstdet($j);
						
						echo "<td>\n";
						if ($coclr_nbsrep>0)
							$txt="Report non ";
						else
							$txt="D&eacute;duction sur-";
						$txt.="consomm&eacute; du contrat ".$coclr_coclori;
						if ($coclr_codeint<>'')
							$txt.=" (Intervention ".$coclr_codeint.")";
						else
							$txt.=" (Cl&ocirc;ture manuelle)";
						echo $txt;
						echo "</td>\n";
				
						echo "<td align=\"center\">\n";
						echo heure_to_hhmm(sec_heure($coclr_nbsrep,3,TRUE));
						echo "</td>\n";

						echo "</tr>\n";
					
						$j++;
					}
				
					echo "</table>\n";
					// Fin affichage table détails reports
				}
				mysql_free_result($rs);

				// Création de la liste des reports affectés depuis ce contrat (s'il y en a)
				$rech = "SELECT * FROM ".TBCOCLR." WHERE coclr_coclori = '".$codecocl."' ORDER BY coclr_codeint";
				$rs = mysql_query($rech) or die(mysql_error());
				
				if (mysql_num_rows($rs) <> 0)
				{
					echo "<table class=\"MtableD\" border=\"0\" width=\"600\" cellpadding=\"0\" cellspacing=\"0\">\n";     
					 
					// Création de l'entête de la table "détails reports"
					echo "<th>";
					echo "D&eacute;tails des reports affect&eacute;s depuis ce contrat";
					echo "</th>\n";
					echo "<th>";
					echo "Dur&eacute;e";
					echo "</th>\n";
				
					$j = 0;
					
					while ($row = mysql_fetch_assoc($rs)) 
					{         
						extract($row);
						
						// Création de l'entête de ligne (TR)
						creetrlstdet($j);
						
						echo "<td>\n";
						if ($coclr_nbsrep>0)
							$txt="Report non ";
						else
							$txt="D&eacute;duction sur-";
						$txt.="consomm&eacute; vers contrat ".$coclr_cocldest;
						if ($coclr_codeint<>'')
							$txt.=" (Intervention ".$coclr_codeint.")";
						else
							$txt.=" (Cl&ocirc;ture manuelle)";
						echo $txt;
						echo "</td>\n";
				
						echo "<td align=\"center\">\n";
						echo heure_to_hhmm(sec_heure($coclr_nbsrep,3,TRUE));
						echo "</td>\n";

						echo "</tr>\n";
					
						$j++;
					}
				
					echo "</table>\n";
					// Fin affichage table détails reports
				}
				mysql_free_result($rs);
				mysql_close($conn);
			}
			?>
	  </tr>
	</table>
	
	<!-- Dates de "vie" du contrat -->
	<table width="100%"  border="0">
	  <tr>
		<td width="160" class="rubfrm" id="f_validite" align="right">Validit&eacute;</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="100%"  border="0">
	  <tr>
		<td width="160" class="rubfrm" id="f_preavis" align="right">Pr&eacute;avis</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="100%"  border="0">
	  <tr>
		<td width="160" valign="top" class="rubfrm" id="f_matos" align="right">Mat&eacute;riel Concern&eacute; </td>
		<td>
			<textarea name="matos" rows="20" id="matos" readonly="readonly"><?PHP echo htmlspecialchars($cocl_matos,ENT_NOQUOTES) ?></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) or die(mysql_error());
	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) or die(mysql_error());
	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 "-";
			echo "</td>\n";
			echo "<td align=\"center\">\n";
			echo "-";
			echo "</td>\n";
			echo "<td align=\"center\">\n";
			echo "-";
			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 htmlspecialchars($row["scli_ste"],ENT_NOQUOTES);
			echo "<br>";
			echo htmlspecialchars($row["scli_adr1"],ENT_NOQUOTES);
			echo "<br>";
			if ($row["scli_adr2"]<>"")
			{
				echo htmlspecialchars($row["scli_adr2"],ENT_NOQUOTES);
				echo "<br>";
			}
			echo Retournecp_openId($row["scli_ville"],FALSE)." ".Retourneville_openId($row["scli_ville"],FALSE)."<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 htmlspecialchars($row["scli_rcivil"],ENT_NOQUOTES)." ".htmlspecialchars($row["scli_rprenom"],ENT_NOQUOTES)." ".htmlspecialchars($row["scli_rnom"],ENT_NOQUOTES);
			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
	}
	else
	{
		echo "<div class=\"annot_std_it\" align=\"center\">";
		echo "Site principal non couvert.";
		echo "<br>Aucun site secondaire.";
		echo "</div>";
	}
	mysql_free_result($rs);
	mysql_close($conn);
	?>
	<!-- bouton de fermeture de la fenêtre -->
	<p align="center">
		<input name="ferm" type="button" class="bton_std" id="ferm" value="<?PHP echo $but_quit; ?>" onclick="javascript:; window.self.close('');">
	</p>
<?PHP
}
else
{
?>
	<script type="text/javascript">
	<!--
	window.self.close('');
	//-->
	</script>
<?PHP
}
?>

</body>
</html>
