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

session_start(); 
include_once("../inc/config.inc.php");
include_once("../inc/func_log.inc.php");
if (CheckURLLog(FALSE)==FALSE) header("Location: ../index.php");
if (CheckNivLog("5-9")==FALSE) header("Location: ../index.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/fic_st.inc.php");
include_once("../inc/lst.inc.php");

Archivelog(@$_SESSION["code_log"]);

$txt_stat_st = array(
	"--- Merci de choisir un type d'analyse statistique ---",
	"Nombre de traitements d'ordres sur une période donnée");

$pbm_stat = FALSE;
$aff_stat = FALSE;
$ts_ok=FALSE;

// On a choisi le type de statistique
if (strip_tags(trim(@$_POST["Submit"])) == "OK")
{
	$ts = strip_tags(trim($_POST['ts']));
	switch ($ts)
	{
		case 1 :
			$ts_ok=TRUE;
			break;
		default :
			$pbm_stat=TRUE;
			break;
	}
}
else
{
	if (isset($_POST['ts']))
	{
		$ts = strip_tags(trim($_POST['ts']));
		$ts_ok=TRUE;

		switch ($ts)
		{
			case 1 :
				// Les dates sont remplies sur un formulaire validé, donc on peut afficher les statistiques
				if ((isset($_POST['date1f'])) AND (isset($_POST['date2f'])))
				{
					$st_select = "";
					for ($i = 0; $i < count($_POST["st"]); $i++)
					{
						$st_select.=$_POST["st"][$i]."-";
					}
					$st_select_tab = explode("-",substr($st_select,0,strlen($st_select)-1));
						
					$date1=datefrang($_POST['date1f']);
					$date2=datefrang($_POST['date2f']);
			
					$aff_stat=TRUE;
				}
				break;
			default :
				$pbm_stat=TRUE;
				break;
		}
	}
}

if (($aff_stat==TRUE) AND ($pbm_stat==FALSE))
{
	switch ($ts)
	{
		/* Nombre de traitements d'interventions sur une période donnée */
		case 1 :
			// Analyse des données et traitements statistiques
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
		
			/* Initialisation des totaux généraux */
		
			$nb_ot_trait_total = 0;
			$nb_ot_ouv_trait_total = 0;
			$nb_ot_prev_trait_total = 0;
			$nb_ot_clos_trait_total = 0;
			
			/* Calcul des totaux généraux */

			$rech = "SELECT st_code FROM ".TBST;
			$rech.= " ORDER BY st_code";
		
			$rs = mysql_query($rech) or die(mysql_error());
				
			if (mysql_num_rows($rs) >0)
			{
				while ($row = mysql_fetch_assoc($rs)) 
				{
					extract($row);

					// Détermination du nombre d'interventions créées par les agences sur la période
					$rech2 = "SELECT * FROM ".TBOT;
					$rech2.= " WHERE ot_codest='".$st_code."'";
					$rech2.= " AND ot_datecrea>='".$date1."' AND ot_datecrea<='".$date2."'";

					$rs2 = mysql_query($rech2) or die(mysql_error());
					$nb_ot_trait_total = $nb_ot_trait_total + mysql_num_rows($rs2);
					
					mysql_free_result($rs2);

					// Détermination du nombre d'interventions encore ouvertes et créées par les agences sur la période
					$rech2 = "SELECT * FROM ".TBOT;
					$rech2.= " WHERE ot_codest='".$st_code."'";
					$rech2.= " AND ot_dateprev='0000-00-00'";
					$rech2.= " AND ot_datecrea>='".$date1."' AND ot_datecrea<='".$date2."'";
				
					$rs2 = mysql_query($rech2) or die(mysql_error());
					$nb_ot_ouv_trait_total = $nb_ot_ouv_trait_total + mysql_num_rows($rs2);

					mysql_free_result($rs2);
				
					// Détermination du nombre d'interventions, où le client a été prévenu, et créées par les agences sur la période
					$rech2 = "SELECT * FROM ".TBOT;
					$rech2.= " WHERE ot_codest='".$st_code."'";
					$rech2.= " AND ot_dateprev<>'0000-00-00'";
					$rech2.= " AND ot_datefin='0000-00-00'";
					$rech2.= " AND ot_datecrea>='".$date1."' AND ot_datecrea<='".$date2."'";
				
					$rs2 = mysql_query($rech2) or die(mysql_error());						
					$nb_ot_prev_trait_total = $nb_ot_prev_trait_total + mysql_num_rows($rs2);
					
					mysql_free_result($rs2);

					// Détermination du nombre total d'interventions closes et créés par les agences sur la période
					$nb_ot_clos_trait_total = $nb_ot_trait_total - $nb_ot_ouv_trait_total - $nb_ot_prev_trait_total;
				}
			}
	
			/* Traitement par agence */
			$rech = "SELECT * FROM ".TBST;
			
			// Traitement de multiples
			if (!in_array("*",$st_select_tab))
			{
				for ($i=0; $i<count($st_select_tab); $i++)
				{
					if(!stristr($rech,"WHERE "))
						$rech.= " WHERE st_code='".$st_select_tab[$i]."'";
					else
						$rech.= " OR st_code='".$st_select_tab[$i]."'";
				}
			}
			$rech.= " ORDER BY st_nom";
		
			$rs = mysql_query($rech) or die(mysql_error());
			$nb_st_select = mysql_num_rows($rs);

			$i = 0;
					
			if ($nb_st_select >0)
			{
				while ($row = mysql_fetch_assoc($rs)) 
				{
					extract($row);

					// Récupération du code agence
					$code_stnce[$i] = $st_code;

					// Détermination du nombre d'interventions créées par l'agence sur la période
					$rech2 = "SELECT * FROM ".TBOT;
					$rech2.= " WHERE ot_codest='".$st_code."'";
					$rech2.= " AND ot_datecrea>='".$date1."' AND ot_datecrea<='".$date2."'";

					$rs2 = mysql_query($rech2) or die(mysql_error());
					$nb_ot_trait_st[$i] = mysql_num_rows($rs2);
					mysql_free_result($rs2);

					// Détermination du nombre d'interventions encore ouvertes et créées par l'agence sur la période
					$rech2 = "SELECT * FROM ".TBOT;
					$rech2.= " WHERE ot_codest='".$st_code."'";
					$rech2.= " AND ot_dateprev='0000-00-00'";
					$rech2.= " AND ot_datecrea>='".$date1."' AND ot_datecrea<='".$date2."'";
				
					$rs2 = mysql_query($rech2) or die(mysql_error());
					$nb_ot_ouv_trait_st[$i] = mysql_num_rows($rs2);
					mysql_free_result($rs2);
				
					// Détermination du nombre d'interventions, oùle client a été prévenu, et créées par les agences sur la période
					$rech2 = "SELECT * FROM ".TBOT;
					$rech2.= " WHERE ot_codest='".$st_code."'";
					$rech2.= " AND ot_dateprev<>'0000-00-00'";
					$rech2.= " AND ot_datefin='0000-00-00'";
					$rech2.= " AND ot_datecrea>='".$date1."' AND ot_datecrea<='".$date2."'";
				
					$rs2 = mysql_query($rech2) or die(mysql_error());
					$nb_ot_prev_trait_st[$i] = mysql_num_rows($rs2);
					mysql_free_result($rs2);

					// Détermination du nombre total d'interventions closes et créées par les agences sur la période
					$nb_ot_clos_trait_st[$i] = $nb_ot_trait_st[$i] - $nb_ot_ouv_trait_st[$i] - $nb_ot_clos_trait_st[$i];

					$i++;
				}
			}
			mysql_close($conn);  
			
			$aff_stat = TRUE;
			
			break;

		default :
			$pbm_stat=TRUE;
			break;
	}
}
?>
<!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 : Statistiques Sous-traitants</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>

<!-- Définition Javascript pour calendrier popup -->
  <!-- Feuille de Style -->
  <link rel="stylesheet" type="text/css" media="all" href="../jscript/jscal/skins/aqua/theme.css" title="Aqua" />

  <!-- Script Javascript Principal -->
  <script type="text/javascript" src="../jscript/jscal/calendar.js"></script>

  <!-- Choix du langage -->
  <script type="text/javascript" src="../jscript/jscal/lang/calendar-fr.js"></script>

  <!-- the following script defines the Calendar.setup helper function, which makes
       adding a calendar a matter of 1 or 2 lines of code. -->
  <script type="text/javascript" src="../jscript/jscal/calendar-setup.js"></script>
<!-- Fin de la définition Javascript pour calendrier popup -->

<!-- Scripts Javascript divers -->
<script language="JavaScript" src="../jscript/divers.js"></script>

<!-- Scripts Javascript pour contrôle de formulaire -->
<script	type="text/javascript" src="../jscript/vform/vform.js"></script>

<!-- Scripts Javascript de validation des formulaires -->
<script	type="text/javascript" src="../jscript/verif_form.js"></script>

</head>

<body onLoad="metFocus();">

<?php 
include_once("../inc/entete.inc.php"); 
?>

<p align="center"> <span class="titrepage">STATISTIQUES SOUS-TRAITANTS</span></p>
<?PHP
if ($pbm_stat==FALSE)
{
	if (nb_st() >0)
	{
?>
	<div align="center">
	<?PHP
	if ($ts_ok==FALSE)
	{
	?>
	<form name="ts" method="post" action="st_stat.php">
	<br>
		<select name="ts" id="ts">
		<?PHP
		for ($i=0; $i<count($txt_stat_st); $i++)
		{
		?>
		<option value="<?PHP echo $i; ?>" <?PHP if ($ts==$i) echo "selected=\"selected\""; ?>><?PHP echo $txt_stat_st[$i]; ?></option>
		<?PHP
		}
		?>					
		</select>
		<input type="submit" class="bton_fmarr_std" name="Submit" value="OK">
	</form>
	<?PHP
	}
	else
	{
	?>
		<br>
		<span class="titre_gras_soul">
		<?PHP echo $txt_stat_st[$ts]; ?>
		</span>
		<br><br><br>
	<?PHP
		if (count($st_select_tab) <> "")
		{
			switch ($ts)
			{
			/* Nombre de traitements d'interventions sur une période donnée */
			case 1 :
				echo "<span class=\"annot_std_it\">";
				if ((in_array("*",$st_select_tab)) AND (count($st_select_tab) == 1))
				{
					echo "Tous les sous-traitants";
				}
				else
				{
					$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
					mysql_select_db(DBNAME);
					if (!in_array("*",$st_select_tab))
						if (count($st_select_tab) == 1) // Un seule sous-traitant choisi
							$liste_st = "Pour le sous-traitant : ";
						else
							$liste_st = "Pour les sous-traitants : ";
					for ($i=0; $i<count($st_select_tab); $i++)
					{
						$rs = mysql_query("SELECT * FROM ".TBST." WHERE `st_code` = '".$st_select_tab[$i]."'");
						if (mysql_num_rows($rs) == 1) // Il ne peut y avoir qu'un seul résultat
						{
							if ($row = mysql_fetch_array($rs))
							{
								extract($row);
								$liste_st .=$st_nom.", ";
							}
						}
					}
					echo substr($liste_st,0,strlen($liste_st)-2);
					mysql_free_result($rs);
					mysql_close($conn);
				}
				echo "<br>";
				echo "Période du ".$_POST['date1f']." au ".$_POST['date2f']."<br>";
				echo "</span>";
				break;
				
			default : 
				break;
			}
		}
	}
	?>
	</div>
	<br>
	<?PHP	
	if ($aff_stat == TRUE)
	{
	?>
		<a href="javascript:;" onclick="self.location.href=('st_stat.php');")><img src="../img/stat.png" title="Autre statistique" width="22" height="22" border="0" align="absmiddle"></a>
		<a href="javascript:;" onclick="self.location.href=('st_stat.php');")> Autre statistique </a>
		<br>
	<?PHP
	}
	if ($ts_ok == TRUE)
	{
		switch ($ts)
		{
			/* Nombre de traitements d'interventions sur une période donnée */
			case 1 :
				if ($aff_stat == FALSE) // On est en mode "paramètres"
				{
		?>
				<script language="javascript">
				var tab_champ=new Array(
					"nom:st[] ; format:listem ; req:Y ; txt:Sous-traitant; vmn:0 ; stok:frmok ; stbad:frmbad",
					"nom:date1f ; format:date ; req:Y ; txt:Date de début; masque:jj-mm-aaaa ; stok:frmok ; stbad:frmbad",
					"nom:date2f ; format:date ; req:Y ; txt:Date de fin ; masque:jj-mm-aaaa ; stok:frmok ; stbad:frmbad");
				</script>
				
				<form name="inter" class="form_pointilles" method="post" action="st_stat.php">
				<input name="ts" type="hidden" id="ts" value="<?PHP echo $ts ?>">
				<table width="100%" border="0">
				<tr>
                    <td width="50%" align="center">
						<br>
						Choisissez un sous-traitant (s&eacute;lections multiples possibles).
						<br>
						<span class="annot_petit_it">(Si 'Tous', les sous-traitants ferm&eacute;s seront aussi analys&eacute;s)</span>
					</td>
                    <td align="center">&nbsp;
					
					</td>
				</tr>
				<tr>
                    <td width="50%" align="center">
						<select name="st[]" id="st" size="5" multiple="multiple">
						<option value="*" selected="selected">---------- Tous ---------- </option>
		
						<?PHP
						// Création de la liste des sous-traitants actifs
						
						$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
						mysql_select_db(DBNAME);
						$rs = mysql_query("SELECT * FROM ".TBST." WHERE `st_ouvert` = '1' ORDER BY st_nom");
						while ($resultat = mysql_fetch_array($rs)) 
						{
							extract($resultat);
							$txt_st = $st_nom." (".$st_code.")";
							echo '<option value="'.$st_code.'">'.$txt_st.'</option>';
						}
						mysql_free_result($rs);
						mysql_close($conn);
						?>
						</select>
					</td>
                    <td align="center">&nbsp;
					
					</td>
                  </tr>
                </table>
				<br>
				<br>
				<br>
				<table width="400"  border="0" align="center">
				<tr>
					<td width="30" class="rubfrm" id="f_date1"><div align="right">Du...</div></td>
					<td>
						<input name="date1f" type="text" id="date1f" size="10" maxlength="10" readonly="1">
						<img src="../img/calendar.png" id="f_img_date1f" title="Choisir votre date" width="16" height="16">
						<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
					</td>
					<td width="30" class="rubfrm" id="f_date2f"><div align="right">Au...</div></td>
					<td>
						<input name="date2f" type="text" id="date2f" size="10" maxlength="10" readonly="1">
						<img src="../img/calendar.png" id="f_img_date2f" title="Choisir votre date" width="16" height="16">
						<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
					</td>
				</tr>
				</table>
				<p align="center">
					<input name="Submit" type="button" class="bton_fmarr_std" id="Submit" value="Calculer" onClick="verif_stats_st(inter,tab_champ,'','',this.value);">
					<input name="init" type="reset" class="bton_fmarr_std" id="init" value="R&eacute;initialiser">
				</p>
			</form>
			
			  <script type="text/javascript">
				Calendar.setup({
					inputField     :    "date1f",     // id of the input field
					ifFormat       :    "%d-%m-%Y",      // format of the input field
					button         :    "f_img_date1f",  // trigger for the calendar (button ID)
					align          :    "Ll",           // alignment (defaults to "Bl")
					electric	   :	false,
					singleClick    :    true
				});
				Calendar.setup({
					inputField     :    "date2f",     // id of the input field
					ifFormat       :    "%d-%m-%Y",      // format of the input field
					button         :    "f_img_date2f",  // trigger for the calendar (button ID)
					align          :    "Ll",           // alignment (defaults to "Bl")
					electric	   :	false,
					singleClick    :    true
				});
			  </script>
			  
	<?PHP
			}
			else // On est en mode "affichage de stats"
			{
				// Définition et entête de la table
				echo "<table class=\"Mtable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";
	
				echo "<th>";
				echo "Sous-traitant";
				echo "</th>\n";
				echo "<th>";
				echo "Total trait&eacute;es";
				echo "</th>\n";
				echo "<th>";
				echo "Ouvertes";
				echo "</th>\n";
				echo "<th>";
				echo "Agences pr&eacute;venues";
				echo "</th>\n";
				echo "<th>";
				echo "Clots";
				echo "</th>\n";

				$i = 0;

				/* Données pour tous les sous-traitants */

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

				echo "<td>";
				echo "<span class=\"annot_std_it\">";
				echo "Tous les sous-traitants";
				echo "</span>";
				echo "</td>\n";
				echo "<td align=\"center\">";
				if ($nb_ot_trait_total <> 0)
				{
					echo "<span class=\"annot_std_it\">";
					echo $nb_ot_trait_total;
					echo "</span>";
				}
				else
					echo "-";
				echo "</td>\n";
				echo "<td align=\"center\">";
				if ($nb_ot_ouv_trait_total <> 0)
				{
					echo "<span class=\"annot_std_it\">";
					echo $nb_ot_ouv_trait_total;
					echo "</span>";
					if ($nb_ot_trait_total <> 0)
					{
						echo"<span class=\"annot_petit_it\">";
						echo " (".round((($nb_ot_ouv_trait_total/$nb_ot_trait_total)*100),2)."%)";
						echo "</span>";
					}
				}
				else
					echo "-";
				echo "</td>\n";
				echo "<td align=\"center\">";
				if ($nb_ot_prev_trait_total <> 0)
				{
					echo "<span class=\"annot_std_it\">";
					echo $nb_ot_prev_trait_total;
					echo "</span>";
					if ($nb_ot_trait_total <> 0)
					{
						echo"<span class=\"annot_petit_it\">";
						echo " (".round((($nb_ot_prev_trait_total/$nb_ot_trait_total)*100),2)."%)";
						echo "</span>";
					}
				}
				else
					echo "-";
				echo "</td>\n";
				echo "<td align=\"center\">";
				if ($nb_ot_clos_trait_total <> 0)
				{
					echo "<span class=\"annot_std_it\">";
					echo $nb_ot_clos_trait_total;
					echo "</span>";
					if ($nb_ot_trait_total <> 0)
					{
						echo"<span class=\"annot_petit_it\">";
						echo " (".round((($nb_ot_clos_trait_total/$nb_ot_trait_total)*100),2)."%)";
						echo "</span>";
					}
				}
				else
					echo "-";
				echo "</td>\n";

				echo "</tr>\n";
				
				$i++;

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

				echo "<td>";
				echo "&nbsp;";
				echo "</td>\n";
				echo "<td>";
				echo "&nbsp;";
				echo "</td>\n";
				echo "<td>";
				echo "&nbsp;";
				echo "</td>\n";
				echo "<td>";
				echo "&nbsp;";
				echo "</td>\n";
				echo "<td>";
				echo "&nbsp;";
				echo "</td>\n";

				echo "</tr>\n";
				
				$i++;

				if ($nb_st_select > 0)
				{
					for ($j=0; $j<$nb_st_select; $j++)
					{
						// Création de l'entête de ligne (TR)
						creetrlst($i);
		
						echo "<td>";
						$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
						mysql_select_db(DBNAME);
						$rs = mysql_query("SELECT * FROM ".TBST." WHERE `st_code` = '".$code_stnce[$j]."'");
						if ($row = mysql_fetch_array($rs))
						{
							extract($row);
							$txt_st = $st_nom;
						}
						mysql_free_result($rs);
						mysql_close($conn);
						echo "<span class=\"annot_std_gras\">";
						echo $txt_st." (".$code_stnce[$j].")";
						echo "</span>";
						if ($st_ouvert == 0)
						{
							echo "<span class=\"annot_petit_it\">";
							echo " Fermée";
							echo "</span>";
						}
						echo "<br>";
						if ($nb_ot_trait_st[$j] <> 0)
						{
							echo "<span class=\"annot_petit_it\">";
							echo "<div align=\"right\">";
							echo "Par rapport agence : ";
							echo "<br>Par rapport total : ";
							echo "</div>";
							echo "</span>";
						}
						echo "</td>\n";
						echo "<td align=\"center\">";
						if ($nb_ot_trait_st[$j] <> 0)
						{
							echo "<span class=\"annot_std_gras\">";
							echo $nb_ot_trait_st[$j];
							echo "</span>";
							if ($nb_ot_trait_total <> 0)
							{
								echo"<span class=\"annot_petit_it\">";
								echo "<br>-<br>(".round((($nb_ot_trait_st[$j]/$nb_ot_trait_total)*100),2)."%)";
								echo "</span>";
							}							
						}
						else
							echo "-";
						echo "</td>\n";
						echo "<td align=\"center\">";
						if ($nb_ot_ouv_trait_st[$j] <> 0)
						{
							echo "<span class=\"annot_std_gras\">";
							echo $nb_ot_ouv_trait_st[$j];
							echo "</span>";
							echo "<br>";
							if ($nb_ot_trait_st[$j] <> 0)
							{
								echo"<span class=\"annot_petit_it\">";
								echo "(".round((($nb_ot_ouv_trait_st[$j]/$nb_ot_trait_st[$j])*100),2)."%)";
								echo "</span>";
							}
							else
								echo "-";
							echo "<br>";
							if ($nb_ot_ouv_trait_total <> 0)
							{
								echo"<span class=\"annot_petit_it\">";
								echo "(".round((($nb_ot_ouv_trait_st[$j]/$nb_ot_ouv_trait_total)*100),2)."%)";
								echo "</span>";
							}							
							else
								echo "-";
						}
						else
							echo "-";
						echo "</td>\n";
						echo "<td align=\"center\">";
						if ($nb_ot_prev_trait_st[$j] <> 0)
						{
							echo "<span class=\"annot_std_gras\">";
							echo $nb_ot_prev_trait_st[$j];
							echo "</span>";
							echo "<br>";
							if ($nb_ot_trait_st[$j] <> 0)
							{
								echo"<span class=\"annot_petit_it\">";
								echo " (".round((($nb_ot_prev_trait_st[$j]/$nb_ot_trait_st[$j])*100),2)."%)";
								echo "</span>";
							}
							else
								echo "-";
							echo "<br>";
							if ($nb_ot_prev_trait_total <> 0)
							{
								echo"<span class=\"annot_petit_it\">";
								echo "(".round((($nb_ot_prev_trait_st[$j]/$nb_ot_prev_trait_total)*100),2)."%)";
								echo "</span>";
							}							
							else
								echo "-";
						}
						else
							echo "-";
						echo "</td>\n";
						echo "<td align=\"center\">";
						if ($nb_ot_clos_trait_st[$j] <> 0)
						{
							echo "<span class=\"annot_std_gras\">";
							echo $nb_ot_clos_trait_st[$j];
							echo "</span>";
							echo "<br>";
							if ($nb_ot_trait_st[$j] <> 0)
							{
								echo"<span class=\"annot_petit_it\">";
								echo " (".round((($nb_ot_clos_trait_st[$j]/$nb_ot_trait_st[$j])*100),2)."%)";
								echo "</span>";
							}							
							echo "<br>";
							if ($nb_ot_clos_trait_total <> 0)
							{
								echo"<span class=\"annot_petit_it\">";
								echo "(".round((($nb_ot_clos_trait_st[$j]/$nb_ot_clos_trait_total)*100),2)."%)";
								echo "</span>";
							}							
							else
								echo "-";
						}
						else
							echo "-";
						echo "</td>\n";
		
						echo "</tr>\n";
						
						$i++;
					}
				}
				else
				{
					// Création de l'entête de ligne (TR)
					creetrlst($i);
	
					echo "<td>";
					echo"<span class=\"annot_petit_it\">";
					echo "Aucun résultat à cette demande.";
					echo "</span>";
					echo "</td>\n";
					echo "<td>";
					echo "&nbsp;";
					echo "</td>\n";
					echo "<td>";
					echo "&nbsp;";
					echo "</td>\n";
					echo "<td>";
					echo "&nbsp;";
					echo "</td>\n";
					echo "<td>";
					echo "&nbsp;";
					echo "</td>\n";
	
					echo "</tr>\n";
				}
				
				echo "</table>\n";
				// *** Fin affichage de la table
			}
		
			break;

		default : 
			break;
		}
	}
	}
	else
	{
?>
		<p align="center" class="annot_std_it">Vous n'avez cr&eacute;&eacute; aucune agence...</p>
		<p align="center" class="annot_std_it">Retour à l'accueil dans 2 secondes...</p>
		<script type="text/javascript">
		window.setTimeout("location=('index.php');",2000)
		</script>
<?PHP
	}
}
else
{
?>
	<script type="text/javascript">
	setTimeout("self.location.href=('index.php');",2000)
	</script>
	<p align="center" class="annot_std_it">Probl&egrave;me sur les param&egrave;tres...</p>
<?PHP
}
include_once("pied.php")
?>
