<?php
/****************************************************************************************
SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV

Version 0.9.7

Copyright (C) 2006-2007  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

?>
<!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 - ESPACE 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 divers -->
<script language="JavaScript" src="../jscript/divers.js"></script>

</head>

<body onLoad="metFocus();">
<?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);

$rech = cree_strrechlstot($niv_urgence);
if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
{
	if(!stristr($rech,"WHERE "))
		$rech .= " WHERE ".TBINT.".int_codeage='".@$_SESSION["code_age"]."'";
	else
		$rech .= " AND ".TBINT.".int_codeage='".@$_SESSION["code_age"]."'";
}
if ((@$_SESSION["niv_log"] == 11) OR (@$_SESSION["niv_log"] == 10))
{
	if(!stristr($rech,"WHERE "))
		$rech .= " WHERE ".TBOT.".ot_codest='".@$_SESSION["code_st"]."'";
	else
		$rech .= " AND ".TBOT.".ot_codest='".@$_SESSION["code_st"]."'";
}
$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>".$row["ot_code"]."</td>\n";
	echo "<td>";
	echo "<div align=\"center\">";
	echo formatedate($row["ot_datedde"]);
	echo "</div>";
	echo "</td>\n";

	 // Affichage Icône Lieu
	 echo "<td>";
	 echo "<div align=\"center\">";
	$lieu = $row["ot_codelieu"];
	$searchco = "SELECT * FROM ".TBLIEU." WHERE lieu_code = '$lieu'";
	
	$rsico = mysql_query($searchco) or die(mysql_error());
	
	if (mysql_num_rows($rsico) <> 0)
	{
		 while ($rowico = mysql_fetch_array($rsico)) 
		{
			extract ($rowico);
			echo $lieu_desc;
		}
	}
	 
	 echo "</div>";
	 echo "</td>\n";

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

		if ((@$_SESSION["niv_log"] <> 11) AND (@$_SESSION["niv_log"] <> 10))
		{
			echo "<td>";
			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 = "->";
			$detailst .= $row["st_nom"].", ";
			$detailst .= $row["st_resp_civilite"]." ".$row["st_resp_nom"];
			echo "<div class=\"annot_std_it\">";
			echo $detailst;
			echo "</div>";
			
			// Fin affichage détail sous-trainat
			
			echo "</td>\n";
		}

	 // Affichage Icône Statut
	 echo "<td>";
	 echo "<div align=\"center\">";
	 
	$statut = $row["ot_codestatut"];
	$searchco = "SELECT * FROM ".TBSTA." WHERE statut_code = '$statut'";
	
	$rsico = mysql_query($searchco) or die(mysql_error());
	
	if (mysql_num_rows($rsico) <> 0)
	{
		 while ($rowico = mysql_fetch_array($rsico)) 
		{
			extract ($rowico);
			echo $statut_desc;
		}
	}
	 
	mysql_free_result($rsico);

	 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);  
?>
</body>
</html>