<?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_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'])));
?>
<!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; ?> : Impression Liste Interventions</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 alertes -->
<script language="JavaScript" src="../jscript/alertes.js"></script>

</head>

<body onLoad="warnimplst();">
<?php
if ((@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 1))
	entimplst("LISTE DE VOS INTERVENTIONS");
else
	entimplst("LISTE DES INTERVENTIONS");

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

if (@$_SESSION["niv_log"] <> 1)
{
	$rech = cree_strrechlstint($niv_urgence);
	if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
	{
		if(!stristr($rech,"WHERE "))
			$rech .= " WHERE (".TBINT.".int_codeage='".@$_SESSION["code_age"]."' OR ".TBINT.".int_codeages='".@$_SESSION["code_age"]."')";
		else
			$rech .= " AND (".TBINT.".int_codeage='".@$_SESSION["code_age"]."' OR ".TBINT.".int_codeages='".@$_SESSION["code_age"]."')";
	}
	if ((@$_SESSION["niv_log"] == 7) OR (@$_SESSION["niv_log"] == 6))
	{
		if(!stristr($rech,"WHERE "))
			$rech .= " WHERE ".TBINT.".int_codedo='".@$_SESSION["code_do"]."'";
		else
			$rech .= " AND ".TBINT.".int_codedo='".@$_SESSION["code_do"]."'";
	}
}
else
{
	$rech = cree_strrechlstintc();
	if(!stristr($rech,"WHERE "))
		$rech .= " WHERE ".TBINT.".int_codecli='".@$_SESSION["code_log"]."'";
	else
		$rech .= " AND ".TBINT.".int_codecli='".@$_SESSION["code_log"]."'";
}

switch ($fi)
{
	case 1 :
		if(!stristr($rech,"WHERE "))
			$rech .= " WHERE int_datefin='0000-00-00'";
		else
			$rech .= " AND int_datefin='0000-00-00'";
		break;
	case 2 :
		if(!stristr($rech,"WHERE "))
			$rech .= " WHERE int_datefin<>'0000-00-00'";
		else
			$rech .= " AND int_datefin<>'0000-00-00'";
		break;
	case 3 :
		if(!stristr($rech,"WHERE "))
			$rech .= " WHERE int_dateprev<>'0000-00-00' AND int_datefin='0000-00-00'";
		else
			$rech .= " AND int_dateprev<>'0000-00-00' AND int_datefin='0000-00-00'";
		break;
	case "4" :
		if(!stristr($rech,"WHERE "))
			$rech .= " WHERE int_codetec='-1'";
		else
			$rech .= " AND int_codetec='-1'";
		break;
	case "5" :
		if(!stristr($rech,"WHERE "))
			$rech .= " WHERE int_codeage=''";
		else
			$rech .= " AND int_codeage=''";
		break;
	default :
		break;
}
if (@$_SESSION["niv_log"] <> 1)
	$rech .= crestr_triord($int_titre_col,"int_code",FALSE,$limit);
else
	$rech .= crestr_triord($intc_titre_col,"int_code",FALSE,$limit);

$rs = mysql_query($rech) or die(mysql_error());
$numrows = mysql_num_rows($rs); // Nombre de résultats à la requête
	
// *** Affichage de la table
 echo "<table class=\"MItable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";     

// Création entête
if (@$_SESSION["niv_log"] <> 1)
	titimplst($int_titre_col);
else
	titimplst($intc_titre_col);	
	 
while ($row = mysql_fetch_assoc($rs)) 
{         
	echo "<tr>";

	echo "<td>";
	echo $row["int_code"];
	if ((formatedate($row["int_dateprev"])<>"") AND (formatedate($row["int_datefin"])==""))
	{
		echo " <img src=\"../img/phone.png\" border=\"0\" align=\"absmiddle\"";
		if (@$_SESSION["niv_log"] <> 1)
			echo " title=\"Client pr&eacute;venu\"";
		else
			echo " title=\"Vous avez &eacute;t&eacute; pr&eacute;venu(e)\"";
		echo">";
	}
	if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
	{
		$rech2 = "SELECT * FROM `" .TBOT. "` WHERE `ot_codeint` = '".$row["int_code"]."'";
		$rs2 = mysql_query($rech2)or die(mysql_error());
		$nbexist_ot = mysql_num_rows($rs2);
		if ($nbexist_ot>0)
		{
			if ($nbexist_ot>1)
				$txt_ot = $nbexist_ot." bons de travail rattach&eacute;s";
			else
				$txt_ot = $nbexist_ot." bon de travail rattach&eacute;";
			$rech3 = "SELECT * FROM `" .TBOT. "` WHERE `ot_codeint` = '".$row["int_code"]."' AND `ot_datefin` = '0000-00-00'";
			$rs3 = mysql_query($rech3)or die(mysql_error());
			$nbexist_oto = mysql_num_rows($rs3);
			if ($nbexist_oto>0)
			{
				if ($nbexist_oto>1)
					$txt_ot.= ", dont ".$nbexist_oto." non termin&eacute;s";
				else
					$txt_ot.= ", dont ".$nbexist_oto." non termin&eacute;";
				echo " <img src=\"../img/otolink.png\" title=\"".$txt_ot."\" border=\"0\" align=\"absmiddle\">";
			}
			else
				echo " <img src=\"../img/otlink.png\" title=\"".$txt_ot."\" border=\"0\" align=\"absmiddle\">";
			mysql_free_result($rs3);
		}
		mysql_free_result($rs2);

		if ((@$_SESSION["niv_log"] <> 4) AND (@$_SESSION["niv_log"] <> 3) AND ($row["int_codeage"]<>""))
		{
			echo "<div align=\"center\" class=\"annot_petit_it\">";
			echo "G&eacute;r&eacute;e par ".$row["int_codeage"];
			echo "</div>";
		}

		if ($row["int_codeman"]<>"")
		{
			 echo "<div align=\"center\" class=\"annot_petit_it\">";
			 echo "(Code saisie manuelle : ".$row["int_codeman"].")";
			 echo "</div>";
		}
		$nb_tac_actives=nb_tac_actives(1,$row["int_code"],FALSE);
		if ($nb_tac_actives>0)
		{
			$url_taclst="tac_lst.php?ord=DES&tri=Code&fi=3&search=".$row["int_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; cette intervention)";
			echo " <a href=\"".$url_taclst."\"><img src=\"../img/tacwarn.png\" title=\"".$txt_tac."\" border=\"0\" align=\"absmiddle\"></a>";
		}
	}
	if ((@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6) AND (@$_SESSION["niv_log"] <> 2) AND (@$_SESSION["niv_log"] <> 1))
	{
		if ($row["int_codedo"]<>"")
		{
			 echo "<div align=\"center\" class=\"annot_petit_it\">";
			 echo "Ordre de ".$row["int_codedo"];
			 echo "</div>";
		}
	}
	if ((@$_SESSION["niv_log"] <> 2) AND (@$_SESSION["niv_log"] <> 1))
	{
		if ($row["int_codeext"]<>"")
		{
			 echo "<div align=\"center\" class=\"annot_petit_it\">";
			 echo "(Dossier : ".$row["int_codeext"].")";
			 echo "</div>";
		}
	}
	echo "</td>\n";
	echo "<td>";
	echo "<div align=\"center\">";
	echo formatedate($row["int_datedde"]);
	echo "</div>";
	echo "</td>\n";

	 // Affichage Icône Lieu
	 echo "<td>";
	 echo "<div align=\"center\">";
	 
	 $lieu = $row["int_codelieu"];
	 $rechlieu = "SELECT * FROM ".TBLIEU." WHERE lieu_code = '$lieu'";
	 
	 $rslieu = mysql_query($rechlieu) or die(mysql_error());
	 
		if (mysql_num_rows($rslieu) <> 0)
		{
			if ($rowlieu = mysql_fetch_array($rslieu)) 
			{
				extract ($rowlieu);
				if ($rowlieu["lieu_img"] <> "")
				{
					$lieuint = $rowlieu["lieu_desc"]." (".$lieu.")";
					echo "<img src=\"".$rowlieu["lieu_img"]."\" title=\"".$lieuint."\" border=\"0\" align=\"absmiddle\">";
				}
				else
				{
					 echo "<span class=\"annot_std_it\">";
					 echo $lieu;
					 echo "</span>";
				}
			}
		}
	 
		mysql_free_result($rslieu);

	 echo "</div>";
	 echo "</td>\n";

	if (@$_SESSION["niv_log"] <> 1)
	{
		// Affichage détail urgence
		echo "<td>";
		echo "<div align=\"center\">";
		echo $niv_urgence[$row["int_urg"]];
		echo "</div>";
		echo "</td>\n";
		// Fin affichage détail urgence

		echo "<td>";
		echo $row["int_codecli"];
		$rech2="SELECT cli_dep FROM ".TBCLI." WHERE `cli_code`='".$row["int_codecli"]."'";
		$rs2 = mysql_query($rech2) or die(mysql_error());
		if ($row2 = mysql_fetch_array($rs2))
		{
			echo " <a href=\"cli_maj.php?td=edit&cc=".$row["int_codecli"]."&dep=".$row2["cli_dep"]."\"><img src=\"../img/edit.png\" width=\"14\" height=\"14\" border=\"0\" align=\"absmiddle\" title=\"".$alt_editcli."\"></a>";
		}
		
		// Affichage détail client
		$detailcli = "";
		if ($row["cli_ste"] <> "")
			$detailcli .= $row["cli_ste"].", ";
		$detailcli .= $row["cli_civilite"]." ".$row["cli_nom"];
		echo "<div class=\"annot_petit_itgras\" style=\"margin-left:5px;\">";
		echo $detailcli;
		echo "</div>";
		
		// Affichage site client
		$sitecli = "";
		switch (trim($row["int_idsite"]))
		{
			case "0" :
				break;
			default :
				$rech2 = "SELECT * FROM `" .TBSCLI. "` WHERE `scli_id` = '".trim($row["int_idsite"])."'";
				$rs2 = mysql_query($rech2) or die(mysql_error());
				if ($row2 = mysql_fetch_array($rs2))
				{
					extract($row2);
					$sitecli.= $scli_ste."<br />";
					$sitecli.= $scli_adr1."<br />";
					if ($scli_adr2 <> "")
						$sitecli.= $scli_adr2."<br />";
					$sitecli.= Retournecp_openId($scli_ville,FALSE)." ".Retourneville_openId($scli_ville,FALSE)."<br />";
				}
				mysql_free_result($rs2);
		}
		if ($sitecli<>"")
		{
			echo "<div class=\"annot_petit_itsoul\" style=\"margin-left:5px;padding-top:2px;\">";
			echo "Site";
			if (trim($row["int_codeage"])<>"")
			{
				echo " (G&eacute;r&eacute; par ";
				if (trim($row["int_codeages"])<>"")
					echo $row["int_codeages"];
				else
					echo $row["int_codeage"];
				echo ")";
			}
			echo "</div>";
			echo "<div class=\"annot_petit_it\" style=\"margin-left:7px;\">";
			echo $sitecli;
			echo "</div>";
		}
		
		// Fin affichage détail client
		
		echo "</td>\n";
	}
	else
	{
		echo "<td>\n".substr($row["int_codeage"],1)."</td>\n";
		echo "<td>";
		// Affichage site client
		$sitecli = "";
		switch (trim($row["int_idsite"]))
		{
			case "0" :
				$sitecli = "Site principal";
				break;
			default :
				$rech2 = "SELECT * FROM `" .TBSCLI. "` WHERE `scli_id` = '".trim($row["int_idsite"])."'";
				$rs2 = mysql_query($rech2) or die(mysql_error());
				if ($row2 = mysql_fetch_array($rs2))
				{
					extract($row2);
					$sitecli.= $scli_ste."<br />";
					$sitecli.= $scli_adr1."<br />";
					if ($scli_adr2 <> "")
						$sitecli.= $scli_adr2."<br />";
					$sitecli.= Retournecp_openId($scli_ville,FALSE)." ".Retourneville_openId($scli_ville,FALSE)."<br />";
				}
				mysql_free_result($rs2);
		}
		// echo "<div class=\"annot_petit_it\" style=\"margin-left:7px;\">";
		echo $sitecli;
		// echo "</div>";
		echo "</td>\n";
		
		echo "<td align=\"center\">\n";
		if (formatedate($row["int_datefin"])<>"")
		{
			echo "<span class=\"annot_std_gras\">";
			echo "Termin&eacute;e";
			echo "</span>";
			echo "<br>(Le ".formatedate($row["int_datefin"]).")";
		}
		else
		{
			if (formatedate($row["int_dateprev"])<>"")
			{
				echo "<span class=\"annot_std_gras\">";
				echo "Termin&eacute;e";
				echo "</span>";
				echo "<br>(Le ".formatedate($row["int_dateprev"]).")";
			}
			else
			{
				echo "<span class=\"annot_std_it\">";
				echo "En cours";
				echo "</span>";
				echo "<br>(modif. : ".formatedate($row["int_datemod"]).")";
			}
		}
		echo "</td>\n";
	}
	
	// Technicien / Agence traitants
	echo "<td align=\"center\">";
	if (($row["int_codetec"] <> "") AND ($row["int_codetec"] <> "-1"))
	{
		echo $row["int_codetec"];
		if (@$_SESSION["niv_log"] <> 1)
		{
			$rech2 = "SELECT tec_codeage FROM `" .TBTEC. "` WHERE `tec_code` = '".trim($row["int_codetec"])."'";
			$rs2 = mysql_query($rech2) or die(mysql_error());
			if ($row2 = mysql_fetch_array($rs2))
			{
				extract($row2);
				echo "<div class=\"annot_petit_it\">";
				echo "(Agence ".$tec_codeage.")";
				echo "</div>";
			}
			mysql_free_result($rs2);
		}
	}
	else
		echo "-";
	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)
		{
			 while ($rowico = mysql_fetch_array($rsico)) 
			{
				extract ($rowico);
				if ($rowico["statut_img"] <> "")
				{
					$statint = $rowico["statut_desc"]." (".$statut.")";
					echo "<img src=\"".$rowico["statut_img"]."\" title=\"".$statint."\" border=\"0\" align=\"absmiddle\">";
				}
				else
				{
					 echo "<span class=\"annot_std_it\">";
					 echo $statut;
					 echo "</span>";
				}
			}
		}
	 
		mysql_free_result($rsico);

	 echo "</div>";
	 echo "</td>\n";

	 echo "</tr>\n";
}  
echo "</table>\n";
// *** Fin affichage de la table

mysql_free_result($rs);
mysql_close($conn);  
?>
</body>
</html>