<?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_age.inc.php");
include_once("../inc/fic_pw.inc.php");
include_once("../inc/fic_zc.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"]);
?>
<!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; ?> : <?PHP echo $title_age_lst; ?></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 $titlein_age_lst; ?></span></p>
<?PHP
if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
{
	$fic_imp = "age_lsti.php";
	$url_add = "age_maj.php?td=add&code=";
}
else
{
	echo "<p align=\"center\"><span class=\"annot_gras_it\">";
	echo "Pour location";
	echo "</span></p>";
	$fic_imp = "";
	$url_add = "";
}
$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
mysql_select_db(DBNAME);

$rech = cree_strrechlstage();
if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
{
	if(!stristr($rech,"WHERE "))
		$rech .= " WHERE ".TBAGE.".age_code<>'".@$_SESSION["code_age"]."'";
	else
		$rech .= " AND ".TBAGE.".age_code<>'".@$_SESSION["code_age"]."'";
}
$rech .= crestr_triord($age_titre_col,"age_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("../inc/formr.inc.php"); 

	$rech = cree_strrechlstage();
	if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
	{
		if(!stristr($rech,"WHERE "))
			$rech .= " WHERE ".TBAGE.".age_code<>'".@$_SESSION["code_age"]."'";
		else
			$rech .= " AND ".TBAGE.".age_code<>'".@$_SESSION["code_age"]."'";
	}
	$rech .= crestr_triord($age_titre_col,"age_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
	if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
		titlst($age_titre_col);	
	else
		titlst($age_titre_col2);	
	echo "<th>".ucfirst($txt_ent_lst_clic)."</th>\n";
	
	$i = 0;
		
	while ($row = mysql_fetch_assoc($rs)) 
	{         
		$affok=TRUE;
		$verrou=FALSE;
		if (account_locked($row["age_code"],FALSE)==TRUE)
		{
			$verrou=TRUE;
			if (@$_SESSION["niv_log"] == 4)
				$affok=FALSE;
		}
		else
		{
			if ((@$_SESSION["niv_log"] == 4) AND ($row["age_ouvert"] == FALSE))
				$affok=FALSE;
		}

		if ($affok==TRUE)
		{
			// Création de l'entête de ligne (TR)
			creetrlst($i);
	
			echo "<td>".$row["age_code"];
		
			if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
			{
				$rech2 = "SELECT * FROM " .TBST. " WHERE st_codeage = '".$row["age_code"]."'";
				$rs2 = mysql_query($rech2)or die(mysql_error());
				if (mysql_num_rows($rs2)>0)
					echo " <a href=\"#\" class=\"popa\"><img src=\"../img/otlink.png\" alt=\"Egalement sous-traitant\" border=\"0\" align=\"absmiddle\"><span>Egalement sous-traitant</span></a>";

				// CREATION d'icône si manque prix de revient
				$txtalert="";
				if (!file_exists($chemin_logos."/log".strtolower($row["age_code"]).".png"))
					$txtalert="Manque le logo";
				if (nb_agepr($row["age_code"],FALSE)==0)
				{
					if (trim($txtalert)<>"")
						$txtalert.="<br />";
					$txtalert.="Manque prix de revient";
				}
				if (trim($txtalert)<>"")
					echo " <a href=\"#\" class=\"popw\"><img src=\"../img/warn.png\" alt=\"pbm\" border=\"0\" align=\"absmiddle\"><span>".formatetxtbr($txtalert)."</span></a>";

		
				// CREATION d'icône si l'agence est fermée
				 if ($row["age_ouvert"] == FALSE)
				 {
					$txtalert=$alt_fermee.formatedate($row["age_datec"]);
					echo " <a href=\"#\" class=\"popw\"><img src=\"../img/out.png\" alt=\"ferm&eacute;\" border=\"0\" align=\"absmiddle\"><span>".formatetxtbr($txtalert)."</span></a>";
					$lst_ferm = TRUE;
				}
		
				 // Verrouillé ?
				if ($verrou==TRUE)
				{
					$txtalert=$cnx_comptedes;
					echo " <a href=\"#\" class=\"popw\"><img src=\"../img/locked.png\" alt=\"".$cnx_comptedes."\" border=\"0\" align=\"absmiddle\"><span>".formatetxtbr($txtalert)."</span></a>";
					$locked=TRUE;
				}
			}
			echo "</td>\n";
			echo "<td>";
			echo htmlspecialchars($row["age_nom"]);
	
			if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
			{
				 // Type agence
				 echo "<br>";
				 echo "<span class=\"annot_petit_it\">";
				 $txt = formatetxt($row["acat_desc"]);
				 echo "(".htmlspecialchars($txt,ENT_NOQUOTES).")";
				 echo "</span>";
			}
	
			echo "</td>\n";
			echo "<td>".$row["age_telf"]."</td>\n";
			echo "<td>".Retournecp_openId($row["age_ville"],FALSE)."</td>\n";
			echo "<td>".Retournepays_open($row["age_codepays"],FALSE)."</td>\n";
			if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
			{
				echo "<td>";
				$detzone1="";
				$detzone2="";
				$tab_zone = tab_zcc_age_open($row["age_code"],FALSE);
				foreach ($tab_zone as $idx=>$value)
				{
					$rech2 = "SELECT * FROM ".TBDEP." WHERE dep_code = '$value' AND dep_codepays = '".$row["age_codepays"]."'";
					$rs2 = mysql_query($rech2) or die(mysql_error());
					if (mysql_num_rows($rs2) <> 0)
					{
						if ($row2 = mysql_fetch_array($rs2)) 
						{
							extract ($row2);
							if ($idx<5)
							{
								if ($idx>0)
								{
									$detzone1.="<br />";
									$detzone2.="<br />";
								}
								$detzone1.=$dep_code." (".$dep_nom.")";
								$detzone2.=$dep_code." (".$dep_nom.")";
							}
							else
							{
								$detzone2.="<br>".$dep_code." (".$dep_nom.")";
							}
						}
					}
				}
				if ($idx>=5)
				{
					$detzone1.="<div align=\"right\"><a href=\"#\" class=\"popa\"><img src=\"../img/expand.png\" alt=\"D&eacute;tail\" border=\"0\" align=\"absmiddle\" onclick=\"display('".$row["age_code"]."_z1','none');display('".$row["age_code"]."_z2','block');\"><span>D&eacute;tail</span></a></div>";
					$detzone2="<div align=\"right\"><a href=\"#\" class=\"popa\"><img src=\"../img/reduce.png\" alt=\"R&eacute;duire\" border=\"0\" align=\"absmiddle\" onclick=\"display('".$row["age_code"]."_z1','block');display('".$row["age_code"]."_z2','none');\"><span>R&eacute;duire</span></a></div>".$detzone2;
					$detzone2.="<div align=\"right\"><a href=\"#\" class=\"popa\"><img src=\"../img/reduce.png\" alt=\"R&eacute;duire\" border=\"0\" align=\"absmiddle\" onclick=\"display('".$row["age_code"]."_z1','block');display('".$row["age_code"]."_z2','none');\"><span>R&eacute;duire</span></a></div>";
					echo "<div id=\"".$row["age_code"]."_z1\" style=\"display:block;\">";
					echo $detzone1;
					echo "</div>";
					echo "<div id=\"".$row["age_code"]."_z2\" style=\"display:none;\">";
					echo $detzone2;
					echo "</div>";
				}
				else
					echo $detzone1;
				echo "</td>\n";
	
				// CREATION lien dynamique sur email
				 echo "<td>";
				 echo "<a href=\"mailto:".$row["age_email"]."\">".$row["age_email"]."</a>";
				 echo "</td>\n";
			}
			
			// CREATION lien dynamique sur icône (édition, suppression, etc...)
			echo "<td>";
			echo "<div align=\"center\">";
			if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
			{
				if ($row["age_ouvert"] == TRUE)
				{
					$lst_maj = TRUE;
					echo "<a href=\"age_maj.php?td=edit&code=".$row["age_code"]."&dep=".$row["age_dep"]."\"><img src=\"../img/edit.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_edit."\"></a>";
					echo " ";
					echo "<a href=\"age_maj.php?td=del&code=".$row["age_code"]."&dep=".$row["age_dep"]."\"><img src=\"../img/del.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_del."\"></a>";
					$lst_del = TRUE;
				}
				else
				{
					$lst_voir = TRUE;
					echo "<a href=\"age_maj.php?td=view&code=".$row["age_code"]."&dep=".$row["age_dep"]."\"><img src=\"../img/eye.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_voir."\"></a>";
				}
			}
			$lst_coloc = TRUE;
			echo " ";
			echo "<a href=\"coloc_maj.php?td=add&tc=1&co=&cc=".$row["age_code"]."&ca=\"><img src=\"../img/coloc.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_addcoloc."\"></a>";
			if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
			{
				echo " ";
				$urlimp = "age_maji.php?ca=".$row["age_code"];
				$lst_imp = TRUE;
				echo "<a href=\"javascript:;\" onclick=\"lanceimp('".$urlimp."');\")><img src=\"../img/print.png\" title=\"".$alt_impfic."\" border=\"0\" align=\"absmiddle\" title=\"".$alt_impfic."\"></a>";
			}
			echo "</div>";
			echo "</td>\n";
		
			echo "</tr>\n";
			
			$i++;
		}
	}  
	echo "</table>\n";
	// *** Fin affichage de la table
	
	mysql_free_result($rs);
	mysql_close();  
	
	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"); 
}
include_once("pied.php")
?>
