<?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_geo.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/lst.inc.php");
Archivelog(@$_SESSION["code_log"]);

$ci = strip_tags(trim($_GET['ci'])); // Récupération code Intervention

$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; ?> : Liste Ordres Sous-traitants</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 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"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 11) OR (@$_SESSION["niv_log"] == 10))
	entimplst("ORDRES DE TRAVAIL");
else
	entimplst("VOS ORDRES DE TRAVAIL");

if ($ci<>"")
{
?>
<p align="center"><span class="annot_std_it">(Pour l'intervention n°<span class="annot_std_gras"><?PHP echo $ci; ?></span>)</span></p>
<?PHP
}

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

switch (@$_SESSION["niv_log"])
{
	case 10 :
	case 11 :
		$rech = cree_strrechlstotst($niv_urgence);
		if(!stristr($rech,"WHERE "))
			$rech .= " WHERE ".TBOT.".ot_codest='".@$_SESSION["code_st"]."'";
		else
			$rech .= " AND ".TBOT.".ot_codest='".@$_SESSION["code_st"]."'";
		break;
	case 3 :
	case 4 :
		$rech = cree_strrechlstot($niv_urgence);
		if(!stristr($rech,"WHERE "))
		{
			$rech .= " WHERE (".TBINT.".int_codeage='".@$_SESSION["code_age"]."'";
			$rech .= " OR ".TBINT.".int_codeages='".@$_SESSION["code_age"]."')";
		}
		else
		{
			$rech .= " AND (".TBINT.".int_codeage='".@$_SESSION["code_age"]."'";
			$rech .= " OR ".TBINT.".int_codeages='".@$_SESSION["code_age"]."')";
		}
		break;
	default :
		$rech = cree_strrechlstot($niv_urgence);
		break;
}

switch ($fi)
{
	case "1" :
		if(!stristr($rech,"WHERE "))
			$rech .= " WHERE ot_datefin='0000-00-00'";
		else
			$rech .= " AND ot_datefin='0000-00-00'";
		break;
	case "2" :
		if(!stristr($rech,"WHERE "))
			$rech .= " WHERE ot_datefin<>'0000-00-00'";
		else
			$rech .= " AND ot_datefin<>'0000-00-00'";
		break;
	default :
		break;
}

$rech .= crestr_triord($ot_titre_col,"ot_code",FALSE,$limit);

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

// *** Affichage de la table
// *** 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"] <> 11) AND (@$_SESSION["niv_log"] <> 10))
	titimplst($ot_titre_col);
else
	titimplst($ot2_titre_col);

$i = 0;

while ($row = mysql_fetch_assoc($rs)) 
{         
	echo "<tr>";

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

	// Affichage détail intervention rattachée
	if ($tx=="m")
	{
		// Icône si tâche rattachée
		$nb_tac_actives=nb_tac_actives(6,$row["ot_code"],FALSE);
		if ($nb_tac_actives>0)
		{
			$url_taclst="tac_lst.php?ord=DES&tri=Code&fi=8&search=".$row["ot_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 bon de travail)";
			echo " <a href=\"".$url_taclst."\"><img src=\"../img/tacwarn.png\" title=\"".$txt_tac."\" border=\"0\" align=\"absmiddle\"></a>";
		}
		if ((@$_SESSION["niv_log"] <> 11) AND (@$_SESSION["niv_log"] <> 10))
		{
			echo "<div class=\"annot_petit_it\" align=\"right\">";
			$txtint="";
			if ($row["int_codedo"]<>"")
				$txtint="Ordre intervention";
			else
				$txtint="Intervention";
			echo $txtint." ".$row["ot_codeint"];
			if (formatedate($row["int_datefin"])<>"")
				echo " <img src=\"../img/ok.png\" border=\"0\" align=\"absmiddle\" title=\"Termin&eacute;\">";
			else
			{
				if (formatedate($row["int_dateprev"])<>"")
					echo " <img src=\"../img/phone.png\" border=\"0\" align=\"absmiddle\" title=\"Client pr&eacute;venu\">";
			}
			if (formatedate($row["int_datefin"])=="")
				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\" width=\"14\" height=\"14\" border=\"0\" align=\"absmiddle\" title=\"Editer/Voir ".$txtint."\"></a>";
			else
				echo " <a href=\"int_maj.php?td=view&ci=".$row["int_code"]."&cc=".$row["int_codecli"]."&ca=".$row["int_codeage"]."\"><img src=\"../img/eye.png\" width=\"14\" height=\"14\" border=\"0\" align=\"absmiddle\" title=\"Editer/Voir ".$txtint."\"></a>";
			echo "</div>";
			echo "<div class=\"annot_petit_it\" align=\"right\">";
			echo Client." ".$row["int_codecli"];
			echo " <a href=\"cli_maj.php?td=edit&cc=".$row["int_codecli"]."\"><img src=\"../img/edit.png\" width=\"14\" height=\"14\" border=\"0\" align=\"absmiddle\" title=\"".$alt_editcli."\"></a>";
			echo "</div>";
		}

	}
	echo "</td>\n";

	echo "<td align=\"center\">";
	echo formatedate($row["ot_datedde"]);
	echo "</td>\n";

	 // Affichage Icône Lieu
	 echo "<td align=\"center\">";
	 $lieu = $row["ot_codelieu"];
	 $rechlieu = "SELECT * FROM ".TBLIEU." WHERE lieu_code = '$lieu'";
	 
	 $rslieu = mysql_query($rechlieu) or die(mysql_error());
	 
		if (mysql_num_rows($rslieu) <> 0)
		{
			 while ($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 "</td>\n";

	// Affichage détail urgence
	echo "<td align=\"center\">";
	echo "<div align=\"center\">";
	echo $niv_urgence[$row["ot_urg"]];
	echo "</td>\n";
	// Fin affichage détail urgence

	if ((@$_SESSION["niv_log"] <> 11) AND (@$_SESSION["niv_log"] <> 10))
	{
		echo "<td align=\"center\">";
		echo $row["ot_codest"];
		if ($tx=="m")
		{
			$rech2="SELECT st_dep FROM ".TBST." WHERE `st_code`='".$row["ot_codest"]."'";
			$rs2 = mysql_query($rech2) or die(mysql_error());
			if ($row2 = mysql_fetch_array($rs2))
			{
				echo " <a href=\"st_maj.php?td=edit&code=".$row["ot_codest"]."&dep=".$row2["st_dep"]."\"><img src=\"../img/edit.png\" width=\"14\" height=\"14\" border=\"0\" align=\"absmiddle\" title=\"Editer sous-traitant\"></a>";
			}
		}
		
		// Affichage détail sous-traitant
		$detailst = $row["st_nom"].", ";
		$detailst .= $row["st_resp_civilite"]." ".$row["st_resp_nom"];
		echo "<div class=\"annot_petit_it\" style=\"margin-left:5px;\">";
		echo $detailst;
		echo "</div>";
		// Fin affichage détail sous-trainat
		echo "</td>\n";
	}

	// Affichage technicien traitant
	echo "<td align=\"center\">";
	if (($row["ot_codetec"] <> "") AND ($row["ot_codetec"] <> "-1"))
		echo $row["ot_codetec"];
	else
		echo "&nbsp;";
	echo "</td>\n";

	// Affichage Icône Statut
	echo "<td align=\"center\">";
	$statut = $row["ot_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";
	
	$i++;    
}  
echo "</table>\n";
// *** Fin affichage de la table

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