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

if (!isset($_SESSION["lng"])) $_SESSION["lng"]="fr";
include_once("../lng/".$_SESSION["lng"].".inc.php"); // Paramètres de language
include_once("../inc/config.inc.php");
include_once("../inc/fic_age.inc.php");
include_once("../inc/fic_do.inc.php");
include_once("../inc/fic_pw.inc.php");
include_once("../inc/fic_st.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_log.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"]);

$pbm_tec=FALSE;

$tl = intval(strip_tags(trim(@$_GET['tl']))); // Type de liste
$td = strip_tags(trim(@$_GET['td'])); // Type de type d'affichage

if (($tl<1) OR ($tl>3))
	$pbm_tec=TRUE;
	
if (($td<>"std") AND ($td<>"loc"))
	$pbm_tec=TRUE;
	
if ($pbm_tec==FALSE)
{
	if (@$_SESSION["niv_log"] == 4)
	{
		$row = lit_enr_age(@$_SESSION["code_age"],TRUE);
		if (is_array($row))
		{
			extract ($row);
			if ($td=="std")
				$tl=1;
		}
		else
			$pbm_tec=TRUE;
	}
	
	if (@$_SESSION["niv_log"] == 6)
	{
		$row = lit_enr_do(@$_SESSION["code_do"]);
		if (is_array($row))
		{
			extract ($row);
			$tl=2;
		}
		else
			$pbm_tec=TRUE;
	}
	
	if (@$_SESSION["niv_log"] == 10)
	{
		$row = lit_enr_st(@$_SESSION["code_st"]);
		if (is_array($row))
		{
			extract ($row);
			$tl=3;
		}
		else
			$pbm_tec=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 Techniciens</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"); ?>
<p align="center"><span class="titrepage">
<?PHP
echo "TECHNICIENS";
switch ($tl)
{
	case 1 :
		echo " AGENCES";
		break;
	case 2 :
		echo " DONNEURS D'ORDRES";
		break;
	case 3 :
		echo " SOUS-TRAITANTS";
		break;
	default :
		break;
}
?>
</span></p>
<?PHP
if ($td=="loc")
{
	echo "<p align=\"center\"><span class=\"annot_gras_it\">";
	echo "Pour location";
	echo "</span></p>";
}

if ($pbm_tec==FALSE)
{
if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 10) OR (@$_SESSION["niv_log"] == 6)) AND ($td=="std")))
{
	$fic_imp = "tec_lsti.php?tl=".$tl;
	$url_add = "tec_maj.php?td=add&code=&tl=".$tl;
}
else
{
	$fic_imp = "";
	$url_add = "";
}

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

$rech = cree_strrechlsttec(@$_SESSION["niv_log"]);

switch ($_SESSION["niv_log"])
{
	case 4 : 
		if ($td=="std")
		{
			if(!stristr($rech,"OR "))
				$rech .= " WHERE tec_codeage = '".@$_SESSION["code_age"]."'";
			else
				$rech .= " AND tec_codeage = '".@$_SESSION["code_age"]."'";
				$rech .= crestr_triord($tec_titre_col,"tec_codeage",FALSE,$limit);
		}
		else
		{
			switch ($tl)
			{
				// Filtrage sur techniciens agences
				case 1 :
					if(!stristr($rech,"OR "))
						$rech .= " WHERE tec_codeage <> ''";
					else
						$rech .= " AND tec_codeage <> ''";
					$rech .= crestr_triord($tec_titre_col,"tec_codeage",FALSE,$limit);
					break;
				// Filtrage sur techniciens sous-traitant
				case 3 :
					if(!stristr($rech,"OR "))
						$rech .= " WHERE tec_codest <> ''";
					else
						$rech .= " AND tec_codest <> ''";
					break;
				$rech .= crestr_triord($tec3_titre_col,"tec_codest",FALSE,$limit);
			}
		}
		break;
	case 6 :
		if(!stristr($rech,"OR "))
			$rech .= " WHERE tec_codedo = '".@$_SESSION["code_do"]."'";
		else
			$rech .= " AND tec_codedo = '".@$_SESSION["code_do"]."'";
		$rech .= crestr_triord($tec2_titre_col,"tec_codedo",FALSE,$limit);
		break;
	case 10 :
		if(!stristr($rech,"OR "))
			$rech .= " WHERE tec_codest = '".@$_SESSION["code_st"]."'";
		else
			$rech .= " AND tec_codest = '".@$_SESSION["code_st"]."'";
		$rech .= crestr_triord($tec3_titre_col,"tec_codest",FALSE,$limit);
		break;
	case 5 :
	case 9 :
		switch ($tl)
		{
			case 1 :
				if(!stristr($rech,"OR "))
					$rech .= " WHERE tec_codeage LIKE 'A%'";
				else
					$rech .= " AND tec_codeage LIKE 'A%'";
				$rech .= crestr_triord($tec_titre_col,"tec_codeage",FALSE,$limit);
				break;
			case 2 :
				if(!stristr($rech,"OR "))
					$rech .= " WHERE tec_codedo LIKE 'D%'";
				else
					$rech .= " AND tec_codedo LIKE 'D%'";
				$rech .= crestr_triord($tec2_titre_col,"tec_codedo",FALSE,$limit);
				break;
			case 3 :
				if(!stristr($rech,"OR "))
					$rech .= " WHERE tec_codest LIKE 'S%'";
				else
					$rech .= " AND tec_codest LIKE 'S%'";
				$rech .= crestr_triord($tec3_titre_col,"tec_codest",FALSE,$limit);
				break;
			default :
				break;
		}
		break;
	default :
		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("../inc/formr.inc.php"); 

	$rech = cree_strrechlsttec(@$_SESSION["niv_log"]);

	switch ($_SESSION["niv_log"])
	{
		case 4 : 
			if ($td=="std")
			{
				if(!stristr($rech,"OR "))
					$rech .= " WHERE tec_codeage = '".@$_SESSION["code_age"]."'";
				else
					$rech .= " AND tec_codeage = '".@$_SESSION["code_age"]."'";
				$rech .= crestr_triord($tec_titre_col,"tec_codeage",FALSE,$limit);
			}
			else
			{
				switch ($tl)
				{
					// Filtrage sur techniciens agences
					case 1 :
						if(!stristr($rech,"OR "))
							$rech .= " WHERE tec_codeage <> ''";
						else
							$rech .= " AND tec_codeage <> ''";
						$rech .= crestr_triord($tec_titre_col,"tec_codeage",FALSE,$limit);
						break;
					// Filtrage sur techniciens sous-traitant
					case 3 :
						if(!stristr($rech,"OR "))
							$rech .= " WHERE tec_codest <> ''";
						else
							$rech .= " AND tec_codest <> ''";
						break;
					$rech .= crestr_triord($tec3_titre_col,"tec_codest",FALSE,$limit);
				}
			}
			break;
		case 6 :
			if(!stristr($rech,"OR "))
				$rech .= " WHERE tec_codedo = '".@$_SESSION["code_do"]."'";
			else
				$rech .= " AND tec_codedo = '".@$_SESSION["code_do"]."'";
			$rech .= crestr_triord($tec2_titre_col,"tec_codedo",FALSE,$limit);
			break;
		case 10 :
			if(!stristr($rech,"OR "))
				$rech .= " WHERE tec_codest = '".@$_SESSION["code_st"]."'";
			else
				$rech .= " AND tec_codest = '".@$_SESSION["code_st"]."'";
			$rech .= crestr_triord($tec3_titre_col,"tec_codest",FALSE,$limit);
			break;
		case 5 :
		case 9 :
			switch ($tl)
			{
				case 1 :
					if(!stristr($rech,"OR "))
						$rech .= " WHERE tec_codeage LIKE 'A%'";
					else
						$rech .= " AND tec_codeage LIKE 'A%'";
					$rech .= crestr_triord($tec_titre_col,"tec_codeage",FALSE,$limit);
					break;
				case 2 :
					if(!stristr($rech,"OR "))
						$rech .= " WHERE tec_codedo LIKE 'D%'";
					else
						$rech .= " AND tec_codedo LIKE 'D%'";
					$rech .= crestr_triord($tec2_titre_col,"tec_codedo",FALSE,$limit);
					break;
				case 3 :
					if(!stristr($rech,"OR "))
						$rech .= " WHERE tec_codest LIKE 'S%'";
					else
						$rech .= " AND tec_codest LIKE 'S%'";
					$rech .= crestr_triord($tec3_titre_col,"tec_codest",FALSE,$limit);
					break;
				default :
					break;
			}
			break;
		default :
			break;
	}

	$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
	switch ($tl)
	{
		case 1 :
			titlst($tec_titre_col);
			break;
		case 2 :
			titlst($tec2_titre_col);
			break;
		case 3 :
			titlst($tec3_titre_col);
			break;
		default :
			break;
	}
	echo "<th>".ucfirst($txt_ent_lst_clic)."</th>\n";
		
	$i = 0;
	
	while ($row = mysql_fetch_assoc($rs)) 
	{         
		// Création de l'entête de ligne (TR)
		creetrlst($i);
		
		echo "<td>";
		switch ($tl)
		{
			case 1 :
			 	echo $row["tec_codeage"];
				break;
			case 2 :
			 	echo $row["tec_codedo"];
				break;
			case 3 :
			 	echo $row["tec_codest"];
				break;
			default :
				echo "&nbsp;";
				break;
		 }
		 echo "</td>\n";
		 echo "<td>".$row["tec_code"];
	
		// CREATION d'icône si manque prix de revient
		if (((@$_SESSION["niv_log"] == 4) AND (@$_SESSION["code_age"]==$row["tec_codeage"])) OR (@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 10))
		{
			if (nb_tecpr($row["tec_code"],FALSE)==0)
				echo " <img src=\"../img/warn.png\" title =\"Manque prix de revient\" border=\"0\" align=\"absmiddle\">";

			// CREATION d'icône en cas de congés
			 if ((comp_date($row["tec_congd"],$datea) == TRUE) AND (comp_date($datea,$row["tec_congf"]) == TRUE))
			 {
				$lst_vac = TRUE;
		
				echo " <img src=\"../img/vac.png\" title =\"Cong&eacute;s du ".formatedate($row["tec_congd"]).$txt_div_to.formatedate($row["tec_congf"]).".\" border=\"0\" align=\"absmiddle\">";
			}
		
			// CREATION d'icône si le technicien n'est plus salarié
			 if ($row["tec_out"] == TRUE)
			 {
				$lst_lic = TRUE;
				echo " <img src=\"../img/out.png\" title =\"N'est plus salari&eacute; depuis le ".formatedate($row["tec_dateout"]).".\" border=\"0\" align=\"absmiddle\">";
			}
		
			 // Verrouillé ?
			if (account_locked($row["tec_code"],FALSE)==TRUE)
			{
				echo " <img src=\"../img/locked.png\" title=\"".$cnx_comptedes."\" alt=\"".$cnx_comptedes."\" border=\"0\" align=\"absmiddle\">";
				$locked=TRUE;
			}
		}

		 echo "</td>\n";
		 echo "<td>".htmlspecialchars($row["tec_prenom"])."</td>\n";
		 echo "<td>".htmlspecialchars($row["tec_nom"])."</td>\n";
		 echo "<td>".$row["tec_telf"]."</td>\n";
		 echo "<td>".$row["tec_telp"]."</td>\n";
	
		// CREATION lien dynamique sur email
		 echo "<td>";
		 echo "<a href=\"mailto:".$row["tec_email"]."\">".$row["tec_email"]."</a>";
		 echo "</td>\n";
	
		// CREATION lien dynamique sur icône (édition, suppression, etc...)
	
		 echo "<td>";
		 echo "<div align=\"center\">";
	
		if (((@$_SESSION["niv_log"] == 4) AND (@$_SESSION["code_age"]==$row["tec_codeage"])) OR ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 10) OR (@$_SESSION["niv_log"] == 6)))
		{
			if ($row["tec_out"] == FALSE)
			{
				$lst_maj = TRUE;
				echo "<a href=\"tec_maj.php?td=edit&code=".$row["tec_code"]."&dep=".$row["tec_dep"]."&tl=".$tl."\"><img src=\"../img/edit.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_edit."\"></a>";
			}
			else
			{
				$lst_voir = TRUE;
				echo "<a href=\"tec_maj.php?td=view&code=".$row["tec_code"]."&dep=".$row["tec_dep"]."&tl=".$tl."\"><img src=\"../img/eye.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_voir."\"></a>";
			}
	
			if ($row["tec_out"] == FALSE)
			{
				$lst_del = TRUE;
				echo " ";
				echo "<a href=\"tec_maj.php?td=del&code=".$row["tec_code"]."&dep=".$row["tec_dep"]."&tl=".$tl."\"><img src=\"../img/del.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_del."\"></a>";
			}

			if ($row["tec_out"] == TRUE)
			{
				if (@$_SESSION["niv_log"] == 9)
				{
					$lst_reopen = TRUE;
					echo " ";
					echo "<a href=\"javascript:;\" onclick=\"fen_tec_reopen('".$row["tec_code"]."');\")><img src=\"../img/reopen.png\" title=\"R&eacute;ouvrir\" border=\"0\" align=\"absmiddle\"></a>";
				}
			}
		}
	
		if (((@$_SESSION["niv_log"] == 4) AND (@$_SESSION["code_age"]==$row["tec_codeage"])) OR ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9)))
		{
			$lst_coloc = TRUE;
			echo " ";
			echo "<a href=\"coloc_maj.php?td=add&tc=2&co=&cc=".$row["tec_code"]."&ca=\"><img src=\"../img/coloc.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_addcoloc."\"></a>";
		}

		if (((@$_SESSION["niv_log"] == 4) AND (@$_SESSION["code_age"]==$row["tec_codeage"])) OR ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 10) OR (@$_SESSION["niv_log"] == 6)))
		{
			$lst_imp = TRUE;
			echo " ";
			$urlimp = "tec_maji.php?code=".$row["tec_code"];
			echo "<a href=\"javascript:;\" onclick=\"lanceimp('".$urlimp."');\")><img src=\"../img/print.png\" title=\"".$alt_impfic."\" border=\"0\" align=\"absmiddle\"></a>";
		}		
		echo "</div>";
		echo "</td>\n";
		
		echo "</tr>\n";
		
		$i++;
	}  
	echo "</table>\n";
	// *** Fin affichage de la table
	
	mysql_free_result($rs);
	mysql_close($conn);  
	
	if ($locked==TRUE)
	{
		echo " <img src=\"../img/locked.png\" title=\"".$cnx_comptedes."\" alt=\"".$cnx_comptedes."\" border=\"0\" align=\"absmiddle\">";
		echo " : ".$cnx_comptedes;
	}
	
	// *** Pagination de pied
	pagine_lst($numrows,$limit);
	
	$taille_piedla="";
	include_once("../inc/piedla.inc.php");
}
}
else
{
?>
<script type="text/javascript">
<!--
setTimeout("self.location.href=('index.php');",2000)
//-->
</script>
<p align="center" class="annot_std_it">Probl&ecirc;me de param&egrave;tres...</p>
<?PHP
}
include_once("pied.php");
?>
