<?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_cli.inc.php");
include_once("../inc/fic_tac.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"]);
?>
<!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 Relev&eacute;s</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 RELEVES</span></p>
<?PHP
$fic_imp = "";
if (@$_SESSION["niv_log"]<>1)
	$url_add = "cli_lst.php?td=rel";

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

$rech = cree_strrechlstrrel();
switch(@$_SESSION["niv_log"])
{
	case 1 :
		$tab_cli=give_tab_rcli($_SESSION["code_log"],FALSE);
		// 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 .= " ".TBREL.".rel_codecli='".$value."' OR";
		}
		// Suppression du dernier 'OR'
		$rech = substr($rech,0,strlen($rech)-3);
	
		if (count($tab_cli)>1)
			$rech .=")";
		break;
	case 3 :
	case 4 :
		if(!stristr($rech,"WHERE "))
			$rech .= " WHERE ".TBREL.".rel_codeage='".@$_SESSION["code_age"]."'";
		else
			$rech .= " AND ".TBREL.".rel_codeage='".@$_SESSION["code_age"]."'";
		break;
}
$rech .= crestr_triord($rel_titre_col,"rel_code",FALSE,$limit);
	 
$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"); 

	$rech = cree_strrechlstrrel();
	switch(@$_SESSION["niv_log"])
	{
		case 1 :
			$tab_cli=give_tab_rcli($_SESSION["code_log"],FALSE);
			// 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 .= " ".TBREL.".rel_codecli='".$value."' OR";
			}
			// Suppression du dernier 'OR'
			$rech = substr($rech,0,strlen($rech)-3);
		
			if (count($tab_cli)>1)
				$rech .=")";
			break;
		case 3 :
		case 4 :
			if(!stristr($rech,"WHERE "))
				$rech .= " WHERE ".TBREL.".rel_codeage='".@$_SESSION["code_age"]."'";
			else
				$rech .= " AND ".TBREL.".rel_codeage='".@$_SESSION["code_age"]."'";
			break;
	}
	$rech .= crestr_triord($rel_titre_col,"rel_code",TRUE,$limit);

	$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
	titlst($rel_titre_col);
	echo "<th>".ucfirst($txt_ent_lst_clic)."</th>\n";
	
	$i = 0;
	
	while ($row = mysql_fetch_assoc($rs)) 
	{         
	 // Affichage résumé relevé
	
		// Création de l'entête de ligne (TR)
		creetrlst($i);
	
		 echo "<td>";
		 echo $row["rel_code"];
		 
			// Vérification si problème(s) non affecté(s)
			$rexist2 = "SELECT * FROM ".TBRPBM."  WHERE rpbm_codecli = '".$row["cli_code"]."' AND rpbm_codeint IS NULL";
			$rs2 = mysql_query($rexist2) or die(mysql_error());
			if (mysql_num_rows($rs2) > 0)
			{
				echo " <img src=\"../img/pbmna.png\" title =\"Probl&egrave;me(s) non affect&eacute;(s) !\" border=\"0\" align=\"absmiddle\">";
			}
	
		// Icône si tâche rattachée
		$nb_tac_actives=nb_tac_actives(5,$row["rel_code"],FALSE);
		if ($nb_tac_actives>0)
		{
			$url_taclst="tac_lst.php?ord=DES&tri=Code&fi=7&search=".$row["rel_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 relev&eacute;)";
			echo " <a href=\"".$url_taclst."\"><img src=\"../img/tacwarn.png\" title=\"".$txt_tac."\" border=\"0\" align=\"absmiddle\"></a>";
		}
		 echo "</td>\n";
		 echo "<td>".formatedate($row["rel_datecrea"])."</td>\n";
		 echo "<td>".formatedate($row["rel_datemod"])."</td>\n";
		 echo "<td>";
		 echo $row["rel_codecli"];
			$rech2="SELECT cli_dep FROM ".TBCLI." WHERE `cli_code`='".$row["rel_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["rel_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 "<br>";
			 echo "<span class=\"annot_std_it\">";
			 echo htmlspecialchars($detailcli,ENT_NOQUOTES);
			 echo "</span>";
	
		 // Fin affichage détail client
	
		 echo "</td>\n";
		 if ($row["rel_codeage"] <> "")
			echo "<td>".$row["rel_codeage"]."</td>\n";
		 else
			echo "<td>&nbsp;</td>\n";
		 
		// CREATION lien dynamique sur icône (édition, suppression, etc...)
		 echo "<td>";
		 echo "<div align=\"center\">";
	
		$lst_maj = TRUE;
	
		echo "<a href=\"rel_maj.php?td=edit&cr=".$row["rel_code"]."\"><img src=\"../img/edit.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_edit."\"></a>";
		echo " ";
	
		$lst_imp = TRUE;
		
		 $urlimp = "rel_pdf.php?cr=".$row["rel_code"]."&pbm=0";
		 echo "<a href=\"javascript:;\" onclick=\"lanceimp('".$urlimp."');\")><img src=\"../img/print.png\" title=\"".$alt_impdosr."\" border=\"0\" align=\"absmiddle\"></a>";
		 echo " ";
	
		$lst_impp = TRUE;
		
		 $urlimp = "rel_pdf.php?cr=".$row["rel_code"]."&pbm=1";
		 echo "<a href=\"javascript:;\" onclick=\"lanceimp('".$urlimp."');\")><img src=\"../img/printc.png\" title=\"".$alt_impdosrp."\" border=\"0\" align=\"absmiddle\"></a>";
		 echo " ";
	
		$lst_del = TRUE;
	
		echo "<a href=\"rel_maj.php?td=del&cr=".$row["rel_code"]."\"><img src=\"../img/del.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_del."\"></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");
?>
