<?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/fic_cli.inc.php");
include_once("../inc/fic_loc.inc.php");
include_once("../inc/fic_tac.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/lst.inc.php");
Archivelog(@$_SESSION["code_log"]);
$fi="";
if (isset($_GET['fi']) && (trim($_GET['fi'])<>""))
	$fi=intval(strip_tags(trim($_GET['fi'])));
$tab_cli=array();
if (@$_SESSION["niv_log"] == 1)
	$tab_cli=give_tab_rcli($_SESSION["code_log"],TRUE);
?>
<!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; ?> : Liste Contrats Locations</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 divers -->
<script language="JavaScript" src="../jscript/divers.js"></script>

</head>

<body onLoad="metFocus();">
<?php
include_once("../inc/entete.inc.php");
if (@$_SESSION["niv_log"] >= 5)
	echo '<p align="center"><span class="titrepage">LISTE DES CONTRATS DE LOCATION</span></p>';
else
	echo '<p align="center"><span class="titrepage">VOS CONTRATS DE LOCATION</span></p>';
$fic_imp = "coloc_lsti.php";
if ((@$_SESSION["niv_log"] <> 1) AND (@$_SESSION["niv_log"] <> 11) AND (@$_SESSION["niv_log"] <> 10))
	$url_add = "cli_lst.php?td=loc";
else
	$url_add = "";
if (@$_SESSION["niv_log"] == 9)
	$url_rss = $rep_appli."/rss/rss.php?log=".$admin_code."&pw=".md5($admin_mdp)."&trss=coloc";

$tab_fi[]="Tous les contrats";
$tab_fi[]="Contrats en cours";
$tab_fi[]="Contrats clos";

$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
mysql_select_db(DBNAME);

$rech = cree_strrechlstcoloc($fi,$tab_cli);
$rech .= crestr_triord($coloc_titre_col,"coloc_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)
	retpp();
else
{
	include_once("formr.inc.php"); 

	$rech = cree_strrechlstcoloc($fi,$tab_cli);
	$rech .= crestr_triord($coloc_titre_col,"coloc_code",TRUE,$limit);

	$rs = mysql_query($rech) or die(mysql_error());

	// *** Pagination de pied
	pagine_lst($numrows,$limit);

	// *** Affichage de la table
	 echo "<table class=\"Mtable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";     

	// Création entête
	titlst($coloc_titre_col);
	echo "<th>".ucfirst($txt_ent_lst_clic)."</th>\n";
	
	$i = 0;
	
	while ($row = mysql_fetch_assoc($rs)) 
	{         
	 // Affichage résumé contrat location

		// Création de l'entête de ligne (TR)
		creetrlst($i);

		echo "<td>";
		echo $row["coloc_code"];

		$nb_pdtloc=nb_pdtloc_in_coloc($row["coloc_code"],FALSE);

		// CREATION d'icône si terminé
		if (formatedate($row["coloc_dateclos"]) =="")
		{
			if (all_pdtloc_ret_in_coloc($row["coloc_code"],FALSE)==TRUE)
			{
				$row["coloc_dateclos"]=lastdate_ret_in_coloc($row["coloc_code"],FALSE);
				clot_coloc($row["coloc_code"],$row["coloc_dateclos"],FALSE);
			}
		}

		if (formatedate($row["coloc_dateclos"]) <> "")
		{
			$lst_fini = TRUE;
			echo " <img src=\"../img/warn.png\" title =\"Terminé le ".formatedate($row["coloc_dateclos"])."\" border=\"0\" align=\"absmiddle\">";
		}

		// Icône si pas de produit dans le contrat
		if ($nb_pdtloc==0)
			echo " <img src=\"../img/nopdt.png\" title =\"Aucun produit dans ce contrat\" border=\"0\" align=\"absmiddle\">";

		if (@$_SESSION["niv_log"]<>1)
		{
			// Icône si tâche rattachée
			$nb_tac_actives=nb_tac_actives(3,$row["coloc_code"],FALSE);
			if ($nb_tac_actives>0)
			{
				$url_taclst="tac_lst.php?ord=DES&tri=Code&fi=5&search=".$row["coloc_code"];
				$txt_tac=$nb_tac_actives." t&acirc;che";
				if ($nb_tac_actives>1)
					$txt_tac.="s";
				$txt_tac.=" non termin&eacute;e";
				if ($nb_tac_actives>1)
					$txt_tac.="s";
				$txt_tac.=" (cliquez pour la liste des t&acirc;ches rattach&eacute;es &agrave; ce contrat)";
				echo " <a href=\"".$url_taclst."\"><img src=\"../img/tacwarn.png\" title=\"".$txt_tac."\" border=\"0\" align=\"absmiddle\"></a>";
			}
		}
		
		// Géré par
		if ((@$_SESSION["niv_log"] <>3) AND (@$_SESSION["niv_log"] <>4))
		{
			 echo "<br>";
			 echo "<span class=\"annot_petit_it\">";
			 $txt = formatetxt($row["coloc_codeage"]);
			 echo "->Agence : ".htmlspecialchars($txt,ENT_NOQUOTES);
			 echo "</span>";
		}
		echo "</td>\n";

		echo "<td>";
		echo $row["coloc_codecli"];
		// Affichage détail contact
		$detailcli = "->";
		switch ($row["coloc_typcli"])
		{
			// Client
			case 0 :
				if ((@$_SESSION["niv_log"] <>3) AND (@$_SESSION["niv_log"] <>4))
					echo " <a href=\"cli_maj.php?td=edit&cc=".$row["coloc_codecli"]."&dep=".$row["cli_dep"]."\"><img src=\"../img/edit.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_editcli."\"></a>";
				if ($row["cli_ste"] <> "")
					$detailcli .= $row["cli_ste"].", ";
				$detailcli .= $row["cli_civilite"]." ".$row["cli_nom"];
				break;
			// Agence
			case 1 :
				if ((@$_SESSION["niv_log"] <>3) AND (@$_SESSION["niv_log"] <>4))
					echo " <a href=\"age_maj.php?td=edit&code=".$row["coloc_codecli"]."&dep=".$row["cli_dep"]."\"><img src=\"../img/edit.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_editage."\"></a>";
				$detailcli .= $row["cli_ste"].", ";
				$detailcli .= $row["cli_civilite"]." ".$row["cli_nom"];
				break;
			// Technicien
			case 2 :
			case 4 :
				if ((@$_SESSION["niv_log"] <>3) AND (@$_SESSION["niv_log"] <>4))
				{
					echo " <a href=\"tec_maj.php?td=edit&code=".$row["coloc_codecli"]."&dep=".$row["cli_dep"];
					if ($row["coloc_typcli"]==2)
						echo "&tl=1";
					else
						echo "&tl=3";
					echo "\"><img src=\"../img/edit.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_edittec."\"></a>";
				}
				$detailcli .= $row["cli_civilite"]." ".$row["cli_nom"];
				break;
			case 3 :
				if ((@$_SESSION["niv_log"] <>3) AND (@$_SESSION["niv_log"] <>4))
					echo " <a href=\"st_maj.php?td=edit&code=".$row["coloc_codecli"]."&dep=".$row["cli_dep"]."\"><img src=\"../img/edit.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_editage."\"></a>";
				$detailcli .= $row["cli_ste"].", ";
				$detailcli .= $row["cli_civilite"]." ".$row["cli_nom"];
				break;
		}
		echo "<br>";
		echo "<span class=\"annot_petit_it\">";
		echo $detailcli;
		echo "</span>";
		// Fin affichage détail contact
		echo "</td>\n";

		// Début
		echo "<td align=\"center\">";
		if (formatedate($row["coloc_datedeb"]) <> "")
			echo formatedate($row["coloc_datedeb"]);
		else
			echo "-";
		echo "</td>\n";

		// Fin
		echo "<td align=\"center\">";
		if (formatedate($row["coloc_datefin"]) <> "")
			echo formatedate($row["coloc_datefin"]);
		else
			echo "-";
		echo "</td>\n";

		// CREATION lien dynamique sur icône (édition, suppression, etc...)
		 echo "<td>";
		 echo "<div align=\"center\">";

		if (@$_SESSION["niv_log"] <> 1)
		{
			if (formatedate($row["coloc_dateclos"]) == "")
			{
				$lst_maj = TRUE;
				echo "<a href=\"coloc_maj.php?td=edit&tc=".$row["coloc_typcli"]."&co=".$row["coloc_code"]."&cc=".$row["coloc_codecli"]."&ca=".$row["coloc_codeage"]."\"><img src=\"../img/edit.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_edit."\"></a>";
				echo " ";
			}
			else
			{
				$lst_voir = TRUE;
				echo "<a href=\"coloc_maj.php?td=view&tc=".$row["coloc_typcli"]."&co=".$row["coloc_code"]."&cc=".$row["coloc_codecli"]."&ca=".$row["coloc_codeage"]."\"><img src=\"../img/eye.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_voir."\"></a>";
				echo " ";
			}
		}
		else
		{
			$lst_voir = TRUE;
			echo "<a href=\"coloc_maj.php?td=view&tc=".$row["coloc_typcli"]."&co=".$row["coloc_code"]."\"><img src=\"../img/eye.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_voir."\"></a>";
			echo " ";
		}

		if (($nb_pdtloc>0) AND ($_SESSION["niv_log"]<>1))
		{
			$lst_imp = TRUE;
			$urlimp = "coloc_pdf.php?cl=".$row["coloc_code"];
			echo "<a href=\"javascript:;\" onclick=\"lanceimp('".$urlimp."');\")><img src=\"../img/print.png\" title=\"".$alt_impcocl."\" border=\"0\" align=\"absmiddle\"></a>";
			echo " ";
		}

		if (@$_SESSION["niv_log"] <> 1)
		{
			if (formatedate($row["coloc_dateclos"]) == "")
			{
				$lst_del = TRUE;
				echo "<a href=\"coloc_maj.php?td=del&tc=".$row["coloc_typcli"]."&co=".$row["coloc_code"]."&cc=".$row["coloc_codecli"]."&ca=".$row["coloc_codeage"]."\"><img src=\"../img/del.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_del."\"></a>";
				echo " ";
			}
		}
		 echo "</div>";
		 echo "</td>\n";

		 echo "</tr>\n";
	 // Fin affichage résumé intervention
		
		$i++;    
	}  
	echo "</table>\n";
	// *** Fin affichage de la table
	
	mysql_free_result($rs);
	mysql_close($conn);  
	
	// *** Pagination de pied
	pagine_lst($numrows,$limit);
	
	$taille_piedla="";
	include_once("piedla.inc.php"); 
}
include_once("pied.php");
?>
