<?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 require ("../inc/lst.inc.php") ?>
<?PHP
	Archivelog(@$HTTP_SESSION_VARS["code_log"]);
?>
<?php
	$orig =  strip_tags(trim($_GET['or'])); // Récupération origine de l'appel
	$cc = @$HTTP_SESSION_VARS["code_log"]; // Récupération code Client
	$search = strip_tags(trim($_GET['search'])); // Récupération clef de recherche

	if ($cc <> "")
	{
		// Récupération des informations clients
		$row = lit_enr_cli($cc);
		extract ($row);
	}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>

<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<title>SMI - ESPACE PRIVE : Historique des Contrats</title>

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

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

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

<p align="center"><span class="titrepage">HISTORIQUE DES CONTRATS</span></p>
<p align="center"><span class="titre_gras">
<?php 
	if ($cli_ste <> "")
		echo $cli_ste;
	else
		echo $cli_civilite." ".$cli_prenom." ".$cli_nom;
	echo " (Compte : ".$cc.")";
?>
</span></p>

<!-- Formulaire de demande du numéro de contrat -->
<form name="dde_cocl" id="dde_cocl" method="GET" action="coclhd_lst.php">
	<input name="cc" type="hidden" id="cc" value="<?PHP echo $cc ?>">
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
<tr>
	<td>
		Contrat : <select name="search" size="1" id="search" onChange="dde_cocl.submit()">
		
		<?PHP 
		// Création de la liste des contrats
		
		if ($co <> "")
			echo "<option value=\"\">-- Choisissez un contrat --</option>";
		else
			echo "<option value=\"\" selected>-- Choisissez un contrat --</option>";
		
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rs = mysql_query("SELECT * FROM ".TBCOCL." WHERE `cocl_codecli` = '".$cc."' ORDER BY cocl_code");
		
		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);
			
			if ($cocl_code == $search)
				echo '<option value="'.$cocl_code.'" selected>'.$cocl_code.'</option>';
			else
				echo '<option value="'.$cocl_code.'">'.$cocl_code.'</option>';
		}
		mysql_free_result($rs);
		mysql_close($conn);
		?>
		</select>
	</td>
	<td>
		<div align="right">
		<input name="ferm" type="button" id="ferm" value="Fermer la fen&ecirc;tre" onClick="javascript:; self.close('fscomp');">
		</div>
	</td>
</tr>
</table>
</form>
<!-- Fin de formulaire de demande du numéro de contrat -->

<?PHP
	if( isset($_GET['search']) && !empty($_GET['search']))  
	{
		echo "<span class=\"annot_std_it\">";
		echo "Ce contrat est ";
		echo "</span>";
		echo "<span class=\"annot_gras_it\">";
		if (cocl_clot($search) == TRUE)
			echo "clôt";
		else
			echo "ouvert";
		echo "</span>";
		echo "<span class=\"annot_std_it\">";
		echo ".<br>";
		echo "</span>";

		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	
		$rech = cree_strrechlstcoclh();
		$rech .= crestr_triord($coclh_titre_col,TBINT.".int_code",FALSE,$limit);
			 
		$rs = mysql_query($rech) or die(mysql_error());
		$numrows = mysql_num_rows($rs); // Nombre de résultats à la requête
		
		if ($numrows <> 0)
		{
	
			// *** Affichage de la table
			echo "<table class=\"Mtable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";     
		
			// Création entête
			titlst(TRUE,$coclh_titre_col);
		
			$i = 0;
			
			while ($row = mysql_fetch_assoc($rs)) 
			{         
			 // Affichage résumé Contrat Client
		
				// Création de l'entête de ligne (TR)
				creetrlst($i);
		
				 echo "<td>".$row["int_code"]."</td>\n";
				 echo "<td>".formatedate($row["int_datedde"])."</td>\n";
				 echo "<td>";
				 if (formatedate($row["int_daterdv"]) <> "")
					echo formatedate($row["int_daterdv"]);
				else
					echo "&nbsp;";
				 echo "</td>\n";
				 echo "<td>";
				 if (formatedate($row["int_datefin"]) <> "")
					echo formatedate($row["int_datefin"]);
				else
					echo "&nbsp;";
				 echo "</td>\n";
				 echo "<td>".$row["int_codeage"]."</td>\n";
				 echo "<td>";
				 if (formateheure($row["int_heurea"]) <> "")
					echo formateheure($row["int_heurea"]);
				 else
					echo "&nbsp;";
				 echo "</td>\n";
				 echo "<td>";
				 if (formateheure($row["int_heuref"]) <> "")
					echo formateheure($row["int_heuref"]);
				 else
					echo "&nbsp;";
				 echo "</td>\n";
	
				 // Affichage Icône Statut
				 
				 echo "<td>";
				 
				 echo "<div align=\"center\">";
				 
				 $statut = $row["int_codestatut"];
				 $rechico = "SELECT * FROM ".TBSTA." WHERE statut_code = '$statut'";
				 
				 $rsico = mysql_query($rechico) or die(mysql_error());
				 
					if (mysql_num_rows($rsico) <> 0)
					{
						if ($rowico = mysql_fetch_array($rsico))
						{
							extract ($rowico);
							if ($rowico["statut_img"] <> "")
							{
								echo "<img src=\"".$rowico["statut_img"]."\" title=\"".$rowico["statut_desc"]."\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\" align=\"absmiddle\">";
							}
							else
							{
								 echo "<span class=\"annot_std_it\">";
								 echo $statut;
								 echo "</span>";
							}
						}
					}
			 
					mysql_free_result($rsico);
		
				 	$url = "int_maj.php?td=edit&ci=".$row["int_code"];
					$desc = "Voir fiche d'intervention";
				 ?>
				 <a href="javascript:void(0)" onClick="javascript:; window.opener.location='<?PHP echo $url ?>'; self.close('fscomp');")>
				 <img src="../img/view.gif" title="<?PHP echo $desc ?>" width="<?PHP echo $hl_vign ?>" height="<?PHP echo $hl_vign ?>" border="0" align="absmiddle">
				 </a>
				 <?PHP
				 echo "</div>";
				 echo "</td>\n";
		
				 echo "</tr>\n";
			 // Fin affichage résumé Contrat Client
				
				$i++;    
			}  
			echo "</table>\n";
			// *** Fin affichage de la table
		}
		else
			echo "<span class=\"annot_std_gras\">Aucun historique sur ce contrat.</span><br>";
		
		mysql_free_result($rs);
		mysql_close($conn);
	}
	else
		echo "<span class=\"annot_std_gras\">Merci de choisir un contrat.</span><br>";

?>

</body>
</html>