<?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/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/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;

$td = intval(strip_tags(trim($_GET['td'])));

if (($td<1) OR ($td>3))
	$pbm_tec=TRUE;
	
if (@$_SESSION["niv_log"] == 4)
{
	$row = lit_enr_age(@$_SESSION["code_age"]);
	if (is_array($row))
	{
		extract ($row);
		$td=1;
	}
	else
		$pbm_tec=TRUE;
}

if (@$_SESSION["niv_log"] == 6)
{
	$row = lit_enr_do(@$_SESSION["code_do"]);
	if (is_array($row))
	{
		extract ($row);
		$td=2;
	}
	else
		$pbm_tec=TRUE;
}

if (@$_SESSION["niv_log"] == 10)
{
	$row = lit_enr_st(@$_SESSION["code_st"]);
	if (is_array($row))
	{
		extract ($row);
		$td=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 - ESPACE 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">LISTE DES TECHNICIENS</span></p>
<?PHP
if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
{
	echo "<p align=\"center\"><span class=\"annot_std_it\">";
	switch ($td)
	{
		case 1 :
			echo "(Des agences)";
			break;
		case 2 :
			echo "(Des donneurs d'ordres)";
			break;
		case 2 :
			echo "(Des sous-traitants)";
			break;
		default :
			break;
	}
	echo "</span></p>";
}

if ($pbm_tec==FALSE)
{
$fic_imp = "tec_lsti.php?td=".$td;
$url_add = "tec_maj.php?td=add&code=&tl=".$td;

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

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

switch ($_SESSION["niv_log"])
{
	case 4 : 
		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);
		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 ($td)
		{
			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


// *** Pagination
if(empty($_GET['page']))$_GET['page'] = 0; // Valeur de par défaut du nombre de pages

$pages = intval($numrows/$limit); // Nombre total de pages

if($numrows%$limit) $pages++; // S'il y a un reste à la division, alors page+1
$current = ($_GET['page']/$limit) + 1; // Numéro de page courante
	
if(($pages < 1) || ($pages == 0)) 
  $total = 1; // Si le nombre de pages est inférieur à 1 ou égal à 0, alors le nombre total de pages est 1
else 
 $total = $pages; // Sinon, on conserve la variable $page telle qu'elle
	
$first = $_GET['page'] + 1; // Premier résultat
	
if(((($_GET['page'] + $limit) / $limit) >= $pages) && $pages != 1) 
	 $last = $_GET['page'] + $limit; // Si ce n'est pas la dernière page de résultats, alors la dernière page de résultat est $page + $limit
else
	$last = $numrows; // Si c'est la dernière page de résultats, le dernier résultat est égal au nombre total de résultats
// *** Fin de Pagination

if($numrows == 0)
{
	retpp();
}
 else
{
	include_once("../inc/formr.inc.php"); 

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

	switch ($_SESSION["niv_log"])
	{
		case 4 : 
			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);
			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 ($td)
			{
				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);
	
		
	// *** Affichage de la table
	echo "<table class=\"Mtable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";     
	
	// Création entête
	switch ($td)
	{
		case 1 :
			titlst(TRUE,$tec_titre_col);
			break;
		case 2 :
			titlst(TRUE,$tec2_titre_col);
			break;
		case 3 :
			titlst(TRUE,$tec3_titre_col);
			break;
		default :
			break;
	}
	echo "<th>".ucfirst("cliquer")."</th>\n";
		
	
	$i = 0;
	
	
	while ($row = mysql_fetch_assoc($rs)) 
	{         
		// Création de l'entête de ligne (TR)
		creetrlst($i);
		
		 echo "<td>";
		switch ($td)
		{
			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 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és du ".formatedate($row["tec_congd"])." au ".formatedate($row["tec_congf"]).".\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" 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.gif\" title =\"N'est plus salarié depuis le ".formatedate($row["tec_dateout"]).".\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\" align=\"absmiddle\">";
		}
	
		 // Verrouillé ?
		if (account_locked($row["tec_code"],FALSE)==TRUE)
		{
			echo " <img src=\"../img/locked.gif\" title=\"Compte d&eacute;sactiv&eacute;\" alt=\"Compte d&eacute;sactiv&eacute;\" width=\"22\" height=\"22\" 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 ($row["tec_out"] == FALSE)
		{
			$lst_maj = TRUE;
			echo "<a href=\"tec_maj.php?td=edit&code=".$row["tec_code"]."&dep=".$row["tec_dep"]."&tl=".$td."\"><img src=\"../img/edit.png\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\" align=\"absmiddle\"></a>";
		}
		else
		{
			$lst_voir = TRUE;
			echo "<a href=\"tec_maj.php?td=view&code=".$row["tec_code"]."&dep=".$row["tec_dep"]."&tl=".$td."\"><img src=\"../img/detail.gif\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\" align=\"absmiddle\"></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=".$td."\"><img src=\"../img/del.gif\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\" align=\"absmiddle\"></a>";
		}
	
		$lst_imp = TRUE;
		 echo " ";
		 $urlimp = "tec_maji.php?code=".$row["tec_code"];
		 echo "<a href=\"javascript:;\" onclick=\"lanceimp('".$urlimp."');\")><img src=\"../img/print.gif\" title=\"Imprimer la fiche\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" 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);
	
	if ($locked==TRUE)
	{
		echo " <img src=\"../img/locked.gif\" title=\"Compte d&eacute;sactiv&eacute;\" alt=\"Compte d&eacute;sactiv&eacute;\" width=\"22\" height=\"22\" border=\"0\" align=\"absmiddle\">";
		echo " : Compte d&eacute;sactiv&eacute;";
	}

	// *** Pagination de pied
	echo "<table width=\"100%\" border=\"0\">
	<tr>
	<td align=\"center\">\n";
		
	if (!empty($_GET['page']) && $_GET['page'] > 0)
	{
	   $back_page = $_GET['page'] - $limit;
	   $url = $_SERVER["PHP_SELF"]."?page=$back_page";
	
		if(!empty($_GET['search']))
			$url .= "&search=".$_GET['search']; // CREATION de 'search'
		if(!empty($_GET['rech']))
			$url .= "&rech=".$_GET['rech']; // CREATION de 'rech'
		if(!empty($_GET['ord']))
			$url .= "&ord=".$_GET['ord']; // CREATION de 'ord'
		if(!empty($_GET['tri']))
			$url .= "&tri=".$_GET['tri']; // CREATION de 'tri'
		if(!empty($_GET['ta']))
			$url .= "&ta=".$_GET['ta']; // CREATION de 'ta'
		if(!empty($_GET['td']))
			$url .= "&td=".$_GET['td']; // CREATION de 'td'
		if(!empty($_GET['cc']))
			$url .= "&cc=".$_GET['cc']; // CREATION de 'cc'
		if(!empty($_GET['ci']))
			$url .= "&ci=".$_GET['ci']; // CREATION de 'ci'
	   
	   
	   echo "<a href=\"$url\"><img src=\"../img/prec.png\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\" align=\"absmiddle\"></a>    \n";
	}
	 
	// Boucle sur chaque page et CREATION d'un lien sur celle-ci
	// Pas de page s'il n'y a seulement qu'une page
	if($pages > 1)
	{
	 for ($i=1; $i <= $pages; $i++) 
	 {
	   $ppage = $limit*($i - 1);
	   if ($ppage == $_GET['page'])
		  echo("<span class=\"psel\">$i</span> \n");
	   else
	   {
		  $url = $_SERVER["PHP_SELF"]."?page=$ppage";
						  
		if(!empty($_GET['search']))
			$url .= "&search=".$_GET['search']; // CREATION de 'search'
		if(!empty($_GET['rech']))
			$url .= "&rech=".$_GET['rech']; // CREATION de 'rech'
		if(!empty($_GET['ord']))
			$url .= "&ord=".$_GET['ord']; // CREATION de 'ord'
		if(!empty($_GET['tri']))
			$url .= "&tri=".$_GET['tri']; // CREATION de 'tri'
		if(!empty($_GET['ta']))
			$url .= "&ta=".$_GET['ta']; // CREATION de 'ta'
		if(!empty($_GET['td']))
			$url .= "&td=".$_GET['td']; // CREATION de 'td'
		if(!empty($_GET['cc']))
			$url .= "&cc=".$_GET['cc']; // CREATION de 'cc'
		if(!empty($_GET['ci']))
			$url .= "&ci=".$_GET['ci']; // CREATION de 'ci'
						  
		  echo("<span class=\"pnsel\"><a href=\"$url\">$i</a></span> \n");
	   }
	 }
	}
	
	if(((($_GET['page']+$limit) / $limit) < $pages) && $pages != 1) 
	{   
	   $next_page = $_GET['page'] + $limit; // Si c'est la dernière page, pas de page suivante
	   $url = $_SERVER["PHP_SELF"]."?page=$next_page";
		
		if(!empty($_GET['search']))
			$url .= "&search=".$_GET['search']; // CREATION de 'search'
		if(!empty($_GET['rech']))
			$url .= "&rech=".$_GET['rech']; // CREATION de 'rech'
		if(!empty($_GET['ord']))
			$url .= "&ord=".$_GET['ord']; // CREATION de 'ord'
		if(!empty($_GET['tri']))
			$url .= "&tri=".$_GET['tri']; // CREATION de 'tri'
		if(!empty($_GET['ta']))
			$url .= "&ta=".$_GET['ta']; // CREATION de 'ta'
		if(!empty($_GET['td']))
			$url .= "&td=".$_GET['td']; // CREATION de 'td'
		if(!empty($_GET['cc']))
			$url .= "&cc=".$_GET['cc']; // CREATION de 'cc'
		if(!empty($_GET['ci']))
			$url .= "&ci=".$_GET['ci']; // CREATION de 'ci'
	   
	   echo "    <a href=\"$url\"><img src=\"../img/suiv.png\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\" align=\"absmiddle\"></a>\n";
	}
	 
	echo "</td>
		 </tr>
		 </table>"; 
	
	// *** Fin de pagination de pied	
	
	mysql_close($conn);  
	
	$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");
?>
