<?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_age.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_int.inc.php");
include_once("../inc/fic_tac.inc.php");
include_once("../inc/fic_tec.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 Interventions</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 INTERVENTIONS</span></p>';
else
	echo '<p align="center"><span class="titrepage">VOS INTERVENTIONS</span></p>';

$fic_imp = "int_lsti.php";
if ((@$_SESSION["niv_log"] <> 1) AND (@$_SESSION["niv_log"] <> 11) AND (@$_SESSION["niv_log"] <> 10))
	$url_add = "cli_lst.php?td=int&tl=1";
if (@$_SESSION["niv_log"] == 9)
	$url_rss = $rep_appli."/rss/rss.php?log=".$admin_code."&pw=".md5($admin_mdp)."&trss=int";

$tab_fi[]="Toutes les interventions";
$tab_fi[]="Interventions en cours";
$tab_fi[]="Interventions closes";
if (@$_SESSION["niv_log"] <> 1)
{
	$tab_fi[]="Clients prévenus (en cours)";
	$tab_fi[]="Interventions à gérer";
	$tab_fi[]="Interventions à affecter";
	$tab_fi[]="Interventions à facturer (tous statuts)";
	$tab_fi[]="Interventions à facturer (clients prévenus)";
	$tab_fi[]="Interventions à facturer (inter. closes)";
}
else
	$tab_fi[]="Interventions avec client prévenu (en cours)";

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

$aff_sfact=FALSE;
switch ($_SESSION["niv_log"])
{
	case 1 :
		if (count($tab_cli)==1)
		{
			$rech = cree_strrechlstintc();
			if(!stristr($rech,"WHERE "))
				$rech .= " WHERE ";
			else
				$rech .= " AND ";
			$rech .= " ".TBINT.".int_codecli='".$_SESSION["code_log"]."'";
		}
		else
		{
			$rech = cree_strrechlstint($niv_urgence);
			// On rajoute les comptes complémentaires (cas des regroupements de clients)
			if(!stristr($rech,"WHERE "))
			 $rech .= " WHERE ";
			else
			 $rech .= " AND ";
			if (count($tab_cli)>1)
				$rech .= "(";
			foreach($tab_cli as $key=>$value)
			{
				$rech .= " ".TBINT.".int_codecli='".$value."' OR";
			}
			// Suppression du dernier 'OR'
			$rech = substr($rech,0,strlen($rech)-3);
		
			if (count($tab_cli)>1)
				$rech .=")";
		}
		break;
	default :
		$rech = cree_strrechlstint($niv_urgence);
		switch ($_SESSION["niv_log"])
		{
			// Agences ou Techniciens
			case 4 :
			case 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"]."'";
	
				// On rajoute les interventions non affectées à une agence
				$rech .= " OR ".TBINT.".int_codeage='')";
				if ($_SESSION["niv_log"]==4)
				{
					$row=lit_enr_age($_SESSION["code_age"],FALSE);
					if (is_array($row))
					{
						extract($row);
						if (intval($age_fact)==1)
							$aff_sfact=TRUE;
					}
				}
				break;
	
			// Donneurs d'Ordres et leurs Techniciens
			case 6 :
			case 7 :
				if(!stristr($rech,"WHERE "))
					$rech .= " WHERE ".TBINT.".int_codedo='".@$_SESSION["code_do"]."'";
				else
					$rech .= " AND ".TBINT.".int_codedo='".@$_SESSION["code_do"]."'";
				break;
			default :
				$aff_sfact=TRUE;
				break;
		}
		break;
}

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

$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"); 

	switch ($_SESSION["niv_log"])
	{
		case 1 :
			if (count($tab_cli)==1)
			{
				$rech = cree_strrechlstintc();
				if(!stristr($rech,"WHERE "))
					$rech .= " WHERE ";
				else
					$rech .= " AND ";
				$rech .= " ".TBINT.".int_codecli='".$_SESSION["code_log"]."'";
			}
			else
			{
				$rech = cree_strrechlstint($niv_urgence);
				// On rajoute les comptes complémentaires (cas des regroupements de clients)
				if(!stristr($rech,"WHERE "))
				 $rech .= " WHERE ";
				else
				 $rech .= " AND ";
				if (count($tab_cli)>1)
					$rech .= "(";
				foreach($tab_cli as $key=>$value)
				{
					$rech .= " ".TBINT.".int_codecli='".$value."' OR";
				}
				// Suppression du dernier 'OR'
				$rech = substr($rech,0,strlen($rech)-3);
			
				if (count($tab_cli)>1)
					$rech .=")";
			}
			break;
		default :
			$rech = cree_strrechlstint($niv_urgence);
			switch ($_SESSION["niv_log"])
			{
				// Agences ou Techniciens
				case 4 :
				case 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"]."'";
		
					// On rajoute les interventions non affectées à une agence
					$rech .= " OR ".TBINT.".int_codeage='')";
					if ($_SESSION["niv_log"]==4)
					{
						$row=lit_enr_age($_SESSION["code_age"],FALSE);
						if (is_array($row))
						{
							extract($row);
							if (intval($age_fact)==1)
								$aff_sfact=TRUE;
						}
					}
					break;
		
				// Donneurs d'Ordres et leurs Techniciens
				case 6 :
				case 7 :
					if(!stristr($rech,"WHERE "))
						$rech .= " WHERE ".TBINT.".int_codedo='".@$_SESSION["code_do"]."'";
					else
						$rech .= " AND ".TBINT.".int_codedo='".@$_SESSION["code_do"]."'";
					break;
				default :
					$aff_sfact=TRUE;
					break;
			}
			break;
	}
	
	switch ($fi)
	{
		case 1 :
			if(!stristr($rech,"WHERE "))
				$rech .= " WHERE ".TBINT.".int_datefin='0000-00-00'";
			else
				$rech .= " AND ".TBINT.".int_datefin='0000-00-00'";
			break;
		case 2 :
			if(!stristr($rech,"WHERE "))
				$rech .= " WHERE ".TBINT.".int_datefin<>'0000-00-00'";
			else
				$rech .= " AND ".TBINT.".int_datefin<>'0000-00-00'";
			break;
		case 3 :
			if(!stristr($rech,"WHERE "))
				$rech .= " WHERE ".TBINT.".int_dateprev<>'0000-00-00' AND int_datefin='0000-00-00'";
			else
				$rech .= " AND ".TBINT.".int_dateprev<>'0000-00-00' AND int_datefin='0000-00-00'";
			break;
		case "4" :
			if (@$_SESSION["niv_log"] <> 1)
			{
				if(!stristr($rech,"WHERE "))
					$rech .= " WHERE (".TBINT.".int_codetec='-1' OR ".TBINT.".int_codetec='')";
				else
					$rech .= " AND (".TBINT.".int_codetec='-1' OR ".TBINT.".int_codetec='')";
			}
			break;
		case "5" :
			if (@$_SESSION["niv_log"] <> 1)
			{
				if(!stristr($rech,"WHERE "))
					$rech .= " WHERE ".TBINT.".int_codeage=''";
				else
					$rech .= " AND ".TBINT.".int_codeage=''";
			}
			break;
		case "6" :
			if (@$_SESSION["niv_log"] <> 1)
			{
				if(!stristr($rech,"WHERE "))
					$rech .= " WHERE ".TBINT.".int_fact='0'";
				else
					$rech .= " AND ".TBINT.".int_fact='0'";
			}
			break;
		case "7" :
			if (@$_SESSION["niv_log"] <> 1)
			{
				if(!stristr($rech,"WHERE "))
					$rech .= " WHERE ".TBINT.".int_fact='0' AND ".TBINT.".int_dateprev<>'0000-00-00' AND ".TBINT.".int_datefin='0000-00-00'";
				else
					$rech .= " AND ".TBINT.".int_fact='0' AND ".TBINT.".int_dateprev<>'0000-00-00' AND ".TBINT.".int_datefin='0000-00-00'";
			}
			break;
		case "8" :
			if (@$_SESSION["niv_log"] <> 1)
			{
				if(!stristr($rech,"WHERE "))
					$rech .= " WHERE ".TBINT.".int_fact='0' AND ".TBINT.".int_datefin<>'0000-00-00'";
				else
					$rech .= " AND ".TBINT.".int_fact='0' AND ".TBINT.".int_datefin<>'0000-00-00'";
			}
			break;
		default :
			break;
	}

	switch(@$_SESSION["niv_log"])
	{
		case 1 :
			if (count($tab_cli)==1)
				$rech .= crestr_triord($intc_titre_col,"int_code",TRUE,$limit);
			else
				$rech .= crestr_triord($int_titre_col,"int_code",TRUE,$limit);
			break;
		default :
			$rech .= crestr_triord($int_titre_col,"int_code",TRUE,$limit);
			break;
	}

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

	// *** Pagination de début
	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
	switch(@$_SESSION["niv_log"])
	{
		case 1 :
			if (count($tab_cli)==1)
				titlst($intc_titre_col);
			else
				titlst($int_titre_col);
			break;
		default :
			titlst($int_titre_col);
			break;
	}
	echo "<th>".ucfirst($txt_ent_lst_clic)."</th>\n";
		
	
	$i = 0;
	
	while ($row = mysql_fetch_assoc($rs)) 
	{         
	 // Affichage résumé intervention

		$aff_ligne=TRUE;
		
		// Au cas où l'intervention n'est pas encore affectée et que l'on est en mode technicien agence ou agence, 
		// il faut vérifier si le client fait partie de la zone de chalandise de l'agence
		if ((($_SESSION["niv_log"]==3) OR ($_SESSION["niv_log"]==4)) AND (trim($row["int_codeage"])==""))
		{
			if (trim($row["cli_prop"])=="")
			{
				$rech2 = "SELECT * FROM `" .TBZCC. "` WHERE `zcc_code` = '".$_SESSION["code_age"]."' AND `zcc_codepays` = '".$row["cli_codepays"]."' AND `zcc_codedep` = '".$row["cli_dep"]."'";
				$rs2 = mysql_query($rech2) or die(mysql_error());
				if (mysql_num_rows($rs2) == 0)
					$aff_ligne = FALSE;
			}
			else
			{
				if (trim($row["cli_prop"])<>$_SESSION["code_age"])
					$aff_ligne = FALSE;
			}
		}
		
		if ($aff_ligne==TRUE)
		{
			// Création de l'entête de ligne (TR)
			creetrlst($i);
	
			echo "<td>";
			echo $row["int_code"];
			if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 6) OR (@$_SESSION["niv_log"] == 7))
			{
				$detfic=">>Mat&eacute;riel :<br />".$row["int_mat"]."<br /><br />>>Travail &agrave; effectuer :<br />".$row["int_pbm"];
				if ($detfic<>"")
					echo " <a href=\"#\" class=\"pop\"><img src=\"../img/help.png\" alt=\"D&eacute;tail\" border=\"0\" align=\"absmiddle\"><span>".formatetxtbr($detfic)."</span></a>";
			}
			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);
	
				$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 ($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 manuel : ".$row["int_codeman"].")";
				 echo "</div>";
			}

			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 align=\"center\">";
			echo formatedate($row["int_datedde"]);
			echo "</td>\n";
	
			echo "<td align=\"center\">";
			echo formatedate($row["int_daterdv"]);
			echo "<div align=\"center\" class=\"annot_petit_it\">";
			echo substr($row["int_hrdv"],0,5);
			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";
	
			switch(@$_SESSION["niv_log"])
			{
				case 1 :
					if (count($tab_cli)==1)
					{
						echo "<td align=\"center\">\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";
					}
					else
					{
						// 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";
					}
					break;
				default :
					// 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";
					break;
			}
			
			// Technicien / Agence traitants
			echo "<td align=\"center\">";
			if (($row["int_codetec"] <> "") AND ($row["int_codetec"] <> "-1"))
			{
				echo $row["int_codetec"];
				$row2=lit_enr_tec($row["int_codetec"],FALSE);
				if (is_array($row2))
				{
					extract($row2);
					echo "<div class=\"annot_petit_it\">";
					echo "(".$tec_civilite." ".$tec_prenom." ".$tec_nom." - ".$tec_codeage.")";
					echo "</div>";
				}
			}
			else
				echo "-";
			echo "</td>\n";
			 
			 // Affichage Icône Statut
			 echo "<td 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 "</td>\n";
	
			// CREATION lien dynamique sur icône (édition, suppression, etc...)
			 echo "<td>";
			 echo "<div align=\"center\">";
	
			if (@$_SESSION["niv_log"] <> 1)
			{
				$voir=FALSE;
				
				if (int_closed($row["int_code"],FALSE) == FALSE)
				{
					if ((@$_SESSION["niv_log"] == 7) OR (@$_SESSION["niv_log"] == 6))
					{
						if (($row["int_codetec"] <> "") AND ($row["int_codetec"] <> "-1"))
							$voir=TRUE;
					}
	
					if ((@$_SESSION["niv_log"] == 11) OR (@$_SESSION["niv_log"] == 10))
						$voir=TRUE;
				}
				else
					$voir=TRUE;
	
				if ($voir==FALSE)
				{
					$lst_maj = TRUE;
					echo "<a href=\"int_maj.php?td=edit&ci=".$row["int_code"]."&cc=".$row["int_codecli"]."&ca=".$row["int_codeage"]."\"><img src=\"../img/edit.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_edit."\"></a>";
					echo " ";
				}
				else
				{
					$lst_voir = TRUE;
					echo "<a href=\"int_maj.php?td=view&ci=".$row["int_code"]."&cc=".$row["int_codecli"]."\"><img src=\"../img/eye.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_voir."\"></a>";
					echo " ";
				}

				if ($aff_sfact==TRUE)
				{
					$affok=TRUE;
					if ((@$_SESSION["niv_log"]==4) AND (@$_SESSION["code_log"]<>$row["int_codeage"]))
						$affok=FALSE;
					if ($affok==TRUE)
					{
						$nb_intf=nb_intf_int($row["int_code"],FALSE);
						$txt_fact="facture";
						if ($nb_intf>0)
						{
							if ($nb_intf>1)
								$txt_fact.="s";
							$lst_sfact = TRUE;
							echo "<a href=\"intf_lst.php?tx=m&ci=".$row["int_code"]."&ord=ASC&tri=Facture\"><img src=\"../img/sfact.png\" border=\"0\" align=\"absmiddle\" title=\"Suivi facturation (".$nb_intf." ".$txt_fact.")\"></a>";
						}
						else
						{
							$lst_sfacta = TRUE;
							echo "<a href=\"intf_lst.php?tx=m&ci=".$row["int_code"]."&ord=ASC&tri=Facture\"><img src=\"../img/sfact_add.png\" border=\"0\" align=\"absmiddle\" title=\"Suivi facturation\"></a>";
						}
						echo " ";
					}
				}
			}
			else
			{
				$lst_voir = TRUE;
				echo "<a href=\"int_maj.php?td=view&ci=".$row["int_code"]."&cc=".$row["int_codecli"]."\"><img src=\"../img/eye.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_voir."\"></a>";
				echo " ";
			}
	
	
			$lst_imp = TRUE;
			$urlimp = "int_pdf.php?ci=".$row["int_code"]."&timp=0";
			echo "<a href=\"javascript:;\" onclick=\"lanceimp('".$urlimp."');\")><img src=\"../img/print.png\" title=\"Imprimer l'intervention\" border=\"0\" align=\"absmiddle\"></a>";
			echo " ";
	
			if (((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)  OR (@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9)) AND ($row["int_forfait"]>0))
			{
				$lst_impcl = TRUE;
				$urlimp = "int_pdf.php?ci=".$row["int_code"]."&timp=0&te=cli";
				echo "<a href=\"javascript:;\" onclick=\"lanceimp('".$urlimp."');\")><img src=\"../img/printcl.png\" title=\"Imprimer l'intervention pour le client\" border=\"0\" align=\"absmiddle\"></a>";
				echo " ";
			}

			$mail = TRUE;
			if ($_SESSION["code_age"]<>$row["int_codeage"])
			{
				if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
					$mail=FALSE;
			}
	
			if ($mail==TRUE)
			{
				$lst_mail = TRUE;
				$urlmail = "int_pdf.php?ci=".$row["int_code"]."&timp=1&tact=cop";
				echo "<a href=\"javascript:;\" onclick=\"fensaisie('".$urlmail."',1,1,'status=no,scrollbars=no,menubar=no,statusbar=no,location=no,locationbar=no');\")><img src=\"../img/mail.png\"";
				if (@$_SESSION["niv_log"] <> 1)
					echo" title=\"Renvoyer une copie par email au client\"";
				else
					echo" title=\"Obtenir une copie par email\"";
				echo " border=\"0\" align=\"absmiddle\"></a>";
				echo " ";
			}
	
			if (@$_SESSION["niv_log"] <> 1)
			{
				$del=FALSE;
				if (int_closed($row["int_code"],FALSE) == FALSE)
				{
					$del=TRUE;
					
					// Le créateur et l'administrateur peuvent toujours supprimer une intervention
					if (($row["int_codecrea"]<>$_SESSION["code_log"]) AND ($_SESSION["niv_log"]<>9))
					{
						switch ($_SESSION["niv_log"])
						{
							// On vérifie que le technicien connecté est bien celui qui est responsable du dossier
							// S'il n'y a pas de responsable de dossier, il ne peut pas supprimer l'intervention
							case 3 :
								if ($row["int_codetec"]<>"-1")
								{
									if ($row["int_codetec"]<>$_SESSION["code_log"])
										$del=FALSE;
								}
								else
									$del=FALSE;
								if ($row["int_codedo"]<>"")
									$del=FALSE;
								break;
							// Si l'agence traitante et différente de l'agence connectée, on vérifie s'il y a un technicien responsable
							// Si le technicien responsable appartient à l'agence, l'agence peut supprimer l'intervention
							case 4 :
								if ($_SESSION["code_age"]<>$row["int_codeage"])
								{
									if (($row["int_codetec"]<>"-1") AND ($row["int_codetec"]<>""))
									{
										$row=lit_enr_tec($row["int_codetec"],FALSE);
										extract($row);
										if ($tec_codeage<>$_SESSION["code_age"])
											$del=FALSE;
									}
									else
										$del=FALSE;
								}
								if ($row["int_codedo"]<>"")
									$del=FALSE;
								break;
							// Seul le donneur d'ordres peut supprimer son propre ordre
							case 6 :
							case 7 :
								if (($row["int_codedo"]<>"") AND ($row["int_codedo"]<>$_SESSION["code_do"]))
									$del=FALSE;
								break;
							default :
								break;
						}
					}
			
					if ($del==TRUE)
					{
						$lst_del = TRUE;
						echo "<a href=\"int_maj.php?td=del&ci=".$row["int_code"]."&cc=".$row["int_codecli"]."&ct=".$row["int_codetec"]."\"><img src=\"../img/del.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_del."\"></a>";
						echo " ";
					}
				}
				else
				{
					if (@$_SESSION["niv_log"] == 9)
					{
						$lst_reopen = TRUE;
						echo " ";
						echo "<a href=\"javascript:;\" onclick=\"fen_int_reopen('".$row["int_code"]."');\")><img src=\"../img/reopen.png\" title=\"R&eacute;ouvrir\" border=\"0\" align=\"absmiddle\"></a>";
					}
				}
			}
			 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");
?>
