<?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/fic_tac.inc.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"]);
$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 Dossiers</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");
if (@$_SESSION["niv_log"] >= 5)
{
?>
<p align="center"><span class="titrepage">LISTE DES DOSSIERS</span></p>
<?PHP
}
else
{
?>
<p align="center"><span class="titrepage">VOS DOSSIERS</span></p>
<?PHP
}
$fic_imp = "dos_lsti.php";
if ((@$_SESSION["niv_log"] <> 1) AND (@$_SESSION["niv_log"] <> 11) AND (@$_SESSION["niv_log"] <> 10))
	$url_add = "cli_lst.php?td=dos";
if (@$_SESSION["niv_log"] == 9)
	$url_rss = $rep_appli."/rss/rss.php?log=".$admin_code."&pw=".md5($admin_mdp)."&trss=dos";
$tab_fi[]="Tous les dossiers";
$tab_fi[]="Dossiers en cours";
$tab_fi[]="Dossiers clos";

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

$rech = cree_strrechlstdos($niv_urgence);
if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
{
	if(!stristr($rech,"WHERE "))
		$rech .= " WHERE ".TBDOS.".dos_codeage='".@$_SESSION["code_age"]."'";
	else
		$rech .= " AND ".TBDOS.".dos_codeage='".@$_SESSION["code_age"]."'";
}

switch ($fi)
{
	case "1" :
		if(!stristr($rech,"WHERE "))
			$rech .= " WHERE dos_datefin='0000-00-00'";
		else
			$rech .= " AND dos_datefin='0000-00-00'";
		break;
	case "2" :
		if(!stristr($rech,"WHERE "))
			$rech .= " WHERE dos_datefin<>'0000-00-00'";
		else
			$rech .= " AND dos_datefin<>'0000-00-00'";
		break;
	default :
		break;
}
$rech .= crestr_triord($dos_titre_col,"dos_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_strrechlstdos($niv_urgence);
	if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
	{
		if(!stristr($rech,"WHERE "))
			$rech .= " WHERE ".TBDOS.".dos_codeage='".@$_SESSION["code_age"]."'";
		else
			$rech .= " AND ".TBDOS.".dos_codeage='".@$_SESSION["code_age"]."'";
	}

	switch ($fi)
	{
		case "1" :
			if(!stristr($rech,"WHERE "))
				$rech .= " WHERE dos_datefin='0000-00-00'";
			else
				$rech .= " AND dos_datefin='0000-00-00'";
			break;
		case "2" :
			if(!stristr($rech,"WHERE "))
				$rech .= " WHERE dos_datefin<>'0000-00-00'";
			else
				$rech .= " AND dos_datefin<>'0000-00-00'";
			break;
		default :
			break;
	}
	$rech .= crestr_triord($dos_titre_col,"dos_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($dos_titre_col);
	echo "<th>".ucfirst($txt_ent_lst_clic)."</th>\n";
		
	$i = 0;
	
	while ($row = mysql_fetch_assoc($rs)) 
	{         
	 // Affichage résumé dossier

		// Création de l'entête de ligne (TR)
		creetrlst($i);

		echo "<td>";
		echo $row["dos_code"];
		$rech2="SELECT * FROM ".TBDOSC." WHERE `dosc_code`='".$row["dos_codedosc"]."'";
		$rs2 = mysql_query($rech2) or die(mysql_error());
		if ($row2 = mysql_fetch_array($rs2))
		{
			$txtdosc = $alt_typdos." : ".$row2["dosc_desc"]." (".$row2["dosc_code"].")";
			echo " <img src=\"".$row2["dosc_img"]."\" title=\"".$txtdosc."\" height=\"16\" witdh=\"16\" border=\"0\" align=\"absmiddle\">";
		}
								
		// Détail du dossier
		if (trim($row["dos_res"])<>"")
			echo " <a href=\"#\" class=\"pop\"><img src=\"../img/help.png\" alt=\"R&eacute;sum&eacute;\" border=\"0\" align=\"absmiddle\"><span>".htmlspecialchars($row["dos_res"],ENT_QUOTES)."</span></a>";
	
		// Icône si dossier terminé
		if (formatedate($row["dos_datefin"])<>"")
			echo " <img src=\"../img/ok.png\" title =\"Dossier termin&eacute;\" border=\"0\">";
			
		// Icône si tâche rattachée
		$nb_tac_actives=nb_tac_actives(4,$row["dos_code"],FALSE);
		if ($nb_tac_actives>0)
		{
			$url_taclst="tac_lst.php?ord=DES&tri=Code&fi=6&search=".$row["dos_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 dossier)";
			echo " <a href=\"".$url_taclst."\"><img src=\"../img/tacwarn.png\" title=\"".$txt_tac."\" border=\"0\" align=\"absmiddle\"></a>";
		}
		echo "</td>\n";
		echo "<td>";
		echo "<div align=\"center\">";
		echo formatedate($row["dos_datedde"]);
		echo "</div>";
		echo "</td>\n";
		echo "<td>";
		echo "<div align=\"center\">";
		echo formatedate($row["dos_datefinp"]);
		// Icône si date de fin dépassée
		if (formatedate($row["dos_datefin"])=="")
		{
			if (echeance_depassee_date($datea,$row["dos_datefinp"]) == TRUE)
				echo " <img src=\"../img/warn.png\" title =\"".$alt_dtedep."\" border=\"0\">";
		}
		echo "</div>";
		echo "</td>\n";

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

		echo "<td>";
		echo $row["dos_codecli"];
		$rech2="SELECT cli_dep FROM ".TBCLI." WHERE `cli_code`='".$row["dos_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["dos_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 "<div class=\"annot_petit_it\" style=\"margin-left:5px;\">";
		echo $detailcli;
		echo "</div>";
		
		// Fin affichage détail client
		
		echo "</td>\n";
		
		// Technicien / Agence traitants
		echo "<td>";
		if (($row["dos_codesuiv"] <> "") AND ($row["dos_codesuiv"] <> "-1"))
		{
			echo $row["dos_codesuiv"];
			if ((@$_SESSION["niv_log"] <> 4) AND (@$_SESSION["niv_log"] <> 3))
				echo "<br> agence : ".$row["dos_codeage"];
		}
		else
			echo "&nbsp;";
		echo "</td>\n";
		 
		 // Affichage Icône Probabilité
		 echo "<td>";
		 echo "<div align=\"center\">";
		 echo "<img src=\"../img/1pour".$row["dos_proba"].".png\" title=\"".$row["dos_proba"]."%\" border=\"0\" align=\"absmiddle\">";
		 echo "</div>";
		 echo "</td>\n";

		 // Affichage Icône Avancement
		 echo "<td>";
		 echo "<div align=\"center\">";
		 echo "<img src=\"../img/2pour".$row["dos_avance"].".png\" title=\"".$row["dos_avance"]."%\" border=\"0\" align=\"absmiddle\">";
		 echo "</div>";
		 echo "</td>\n";

		 // Affichage Icône Statut
		 echo "<td>";
		 echo "<div align=\"center\">";
		 
		 $rechico = "SELECT * FROM ".TBDOSS." WHERE doss_code = '".$row["dos_codedoss"]."'";
		 
		 $rsico = mysql_query($rechico) or die(mysql_error());
		 
			if (mysql_num_rows($rsico) <> 0)
			{
				 while ($rowico = mysql_fetch_array($rsico)) 
				{
					extract ($rowico);
					if ($rowico["doss_img"] <> "")
					{
						$statint = $rowico["doss_desc"]." (".$row["dos_codedoss"].")";
						echo "<img src=\"".$rowico["doss_img"]."\" title=\"".$statint."\" border=\"0\" align=\"absmiddle\">";
					}
					else
					{
						 echo "<span class=\"annot_std_it\">";
						 echo $row["dos_codedoss"];
						 echo "</span>";
					}
				}
			}
		 
			mysql_free_result($rsico);

		 echo "</div>";
		 echo "</td>\n";

		// CREATION lien dynamique sur icône (édition, suppression, etc...)
		 echo "<td>";
		 echo "<div align=\"center\">";

		$voir=FALSE;
		
		if (formatedate($row["dos_datefin"]) <> "")
			$voir=TRUE;

		if ($voir==FALSE)
		{
			$lst_maj = TRUE;
			echo "<a href=\"dos_maj.php?td=edit&cd=".$row["dos_code"]."&cc=".$row["dos_codecli"]."&ca=".$row["dos_codeage"]."\"><img src=\"../img/edit.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_edit."\"></a>";
			echo " ";
		}
		else
		{
			$lst_voir = TRUE;
			echo "<a href=\"dos_maj.php?td=view&cd=".$row["dos_code"]."&cc=".$row["dos_codecli"]."\"><img src=\"../img/eye.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_voir."\"></a>";
			echo " ";
		}

		$lst_imp = TRUE;
		$urlimp = "dos_pdf.php?cd=".$row["dos_code"];
		echo "<a href=\"javascript:;\" onclick=\"lanceimp('".$urlimp."');\")><img src=\"../img/print.png\" title=\"".$alt_impdoss."\" border=\"0\" align=\"absmiddle\"></a>";
		echo " ";

		if (formatedate($row["dos_datefin"]) == "")
		{
			$lst_del = TRUE;
			echo "<a href=\"dos_maj.php?td=del&cd=".$row["dos_code"]."&cc=".$row["dos_codecli"]."&ca=".$row["dos_codeage"]."\"><img src=\"../img/del.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_del."\"></a>";
			echo " ";
		}
		else
		{
			if (@$_SESSION["niv_log"] == 9)
			{
				$lst_reopen = TRUE;
				echo " ";
				echo "<a href=\"javascript:;\" onclick=\"fen_dos_reopen('".$row["dos_code"]."');\")><img src=\"../img/reopen.png\" title=\"R&eacute;ouvrir\" border=\"0\" align=\"absmiddle\"></a>";
			}
		}
		 echo "</div>";
		 echo "</td>\n";

		 echo "</tr>\n";
	 // Fin affichage résumé Dossier
		
		$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");
?>
