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

session_start(); 
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/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_do.inc.php");
include_once("../inc/lst.inc.php");

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

$txt_stat_do = array(
	$sel_stat_type,
	$sel_stat_crecli,
	$sel_stat_creint);

$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 :
		case 2 :
			$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 :
			case 2 :
				// Les dates sont remplies sur un formulaire validé, donc on peut afficher les statistiques
				if ((isset($_POST['date1f'])) AND (isset($_POST['date2f'])))
				{
					$do_select = "";
					for ($i = 0; $i < count($_POST["do"]); $i++)
					{
						$do_select.=$_POST["do"][$i]."-";
					}
					$do_select_tab = explode("-",substr($do_select,0,strlen($do_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 créations de clients 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_cli_crees_total = 0;
			$nb_cli_prospects_crees_total = 0;
			$nb_cli_ddeint_crees_total = 0;
			$nb_cli_inter_crees_total = 0;
			
			/* Calcul des totaux généraux */

			$rech = "SELECT do_code FROM ".TBDO;
			$rech.= " ORDER BY do_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 de clients créés par les donneurs d'ordres sur la période
					$rech2 = "SELECT * FROM ".TBCLI;
					$rech2.= " WHERE cli_codecrea='".$do_code."'";
					$rech2.= " AND cli_datecrea>='".$date1."' AND cli_datecrea<='".$date2."'";

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

					// Détermination du nombre de clients encore prospects et créés par les donneurs d'ordres sur la période
					$rech2 = "SELECT * FROM ".TBCLI;
					$rech2.= " WHERE cli_codecrea='".$do_code."'";
					$rech2.= " AND cli_type=0";
					$rech2.= " AND cli_datecrea>='".$date1."' AND cli_datecrea<='".$date2."'";
				
					$rs2 = mysql_query($rech2) or die(mysql_error());
					$nb_cli_prospects_crees_total = $nb_cli_prospects_crees_total + mysql_num_rows($rs2);

					mysql_free_result($rs2);
				
					// Détermination du nombre de client ayant demandé une intervention (non effectuée) et créés par les donneurs d'ordres sur la période
					$rech2 = "SELECT * FROM ".TBCLI;
					$rech2.= " WHERE cli_codecrea='".$do_code."'";
					$rech2.= " AND cli_type=1";
					$rech2.= " AND cli_datecrea>='".$date1."' AND cli_datecrea<='".$date2."'";
				
					$rs2 = mysql_query($rech2) or die(mysql_error());						
					$nb_cli_ddeint_crees_total = $nb_cli_ddeint_crees_total + mysql_num_rows($rs2);
					
					mysql_free_result($rs2);

					// Détermination du nombre total de clients ayant demandé une intervention (effectuée) et créés par les donneurs d'ordres sur la période
					$nb_cli_inter_crees_total = $nb_cli_crees_total - $nb_cli_prospects_crees_total - $nb_cli_ddeint_crees_total;
				}
			}
	
			/* Traitement par donneur d'ordres */
			$rech = "SELECT * FROM ".TBDO;
			
			// Traitement de multiples
			if (!in_array("*",$do_select_tab))
			{
				for ($i=0; $i<count($do_select_tab); $i++)
				{
					if(!stristr($rech,"WHERE "))
						$rech.= " WHERE do_code='".$do_select_tab[$i]."'";
					else
						$rech.= " OR do_code='".$do_select_tab[$i]."'";
				}
			}
			$rech.= " ORDER BY do_nom";
		
			$rs = mysql_query($rech) or die(mysql_error());
			$nb_do_select = mysql_num_rows($rs);

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

					// Récupération du code donneur d'ordres
					$code_donneur_ordres[$i] = $do_code;

					// Détermination du nombre de clients créés par l'donneur d'ordres sur la période
					$rech2 = "SELECT * FROM ".TBCLI;
					$rech2.= " WHERE cli_codecrea='".$do_code."'";
					$rech2.= " AND cli_datecrea>='".$date1."' AND cli_datecrea<='".$date2."'";

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

					// Détermination du nombre de clients encore prospects et créés par l'donneur d'ordres sur la période
					$rech2 = "SELECT * FROM ".TBCLI;
					$rech2.= " WHERE cli_codecrea='".$do_code."'";
					$rech2.= " AND cli_type=0";
					$rech2.= " AND cli_datecrea>='".$date1."' AND cli_datecrea<='".$date2."'";
				
					$rs2 = mysql_query($rech2) or die(mysql_error());
					$nb_cli_prospects_crees_do[$i] = mysql_num_rows($rs2);
					mysql_free_result($rs2);
				
					// Détermination du nombre de client ayant demandé une intervention (non effectuée) et créés par les donneurs d'ordres sur la période
					$rech2 = "SELECT * FROM ".TBCLI;
					$rech2.= " WHERE cli_codecrea='".$do_code."'";
					$rech2.= " AND cli_type=1";
					$rech2.= " AND cli_datecrea>='".$date1."' AND cli_datecrea<='".$date2."'";
				
					$rs2 = mysql_query($rech2) or die(mysql_error());
					$nb_cli_ddeint_crees_do[$i] = mysql_num_rows($rs2);
					mysql_free_result($rs2);

					// Détermination du nombre total de clients ayant demandé une intervention (effectuée) et créés par les donneurs d'ordres sur la période
					$nb_cli_inter_crees_do[$i] = $nb_cli_crees_do[$i] - $nb_cli_prospects_crees_do[$i] - $nb_cli_ddeint_crees_do[$i];

					$i++;
				}
			}
			mysql_close($conn);  
			
			$aff_stat = TRUE;
			
			break;
		
		/* Nombre de créations d'interventions sur une période donnée */
		case 2 :
			// Analyse des données et traitements statistiques
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
		
			/* Initialisation des totaux généraux */
		
			$nb_int_crees_total = 0;
			$nb_int_ouv_crees_total = 0;
			$nb_int_prev_crees_total = 0;
			$nb_int_clos_crees_total = 0;
			
			/* Calcul des totaux généraux */

			$rech = "SELECT do_code FROM ".TBDO;
			$rech.= " ORDER BY do_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 donneurs d'ordres sur la période
					$rech2 = "SELECT * FROM ".TBINT;
					$rech2.= " WHERE int_codecrea='".$do_code."'";
					$rech2.= " AND int_datecrea>='".$date1."' AND int_datecrea<='".$date2."'";

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

					// Détermination du nombre d'interventions encore ouvertes et créées par les donneurs d'ordres sur la période
					$rech2 = "SELECT * FROM ".TBINT;
					$rech2.= " WHERE int_codecrea='".$do_code."'";
					$rech2.= " AND int_dateprev='0000-00-00'";
					$rech2.= " AND int_datecrea>='".$date1."' AND int_datecrea<='".$date2."'";
				
					$rs2 = mysql_query($rech2) or die(mysql_error());
					$nb_int_ouv_crees_total = $nb_int_ouv_crees_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 donneurs d'ordres sur la période
					$rech2 = "SELECT * FROM ".TBINT;
					$rech2.= " WHERE int_codecrea='".$do_code."'";
					$rech2.= " AND int_dateprev<>'0000-00-00'";
					$rech2.= " AND int_datefin='0000-00-00'";
					$rech2.= " AND int_datecrea>='".$date1."' AND int_datecrea<='".$date2."'";
				
					$rs2 = mysql_query($rech2) or die(mysql_error());						
					$nb_int_prev_crees_total = $nb_int_prev_crees_total + mysql_num_rows($rs2);
					
					mysql_free_result($rs2);

					// Détermination du nombre total d'interventions closes et créés par les donneurs d'ordres sur la période
					$nb_int_clos_crees_total = $nb_int_crees_total - $nb_int_ouv_crees_total - $nb_int_prev_crees_total;
				}
			}
	
			/* Traitement par donneur d'ordres */
			$rech = "SELECT * FROM ".TBDO;
			
			// Traitement de multiples
			if (!in_array("*",$do_select_tab))
			{
				for ($i=0; $i<count($do_select_tab); $i++)
				{
					if(!stristr($rech,"WHERE "))
						$rech.= " WHERE do_code='".$do_select_tab[$i]."'";
					else
						$rech.= " OR do_code='".$do_select_tab[$i]."'";
				}
			}
			$rech.= " ORDER BY do_nom";
		
			$rs = mysql_query($rech) or die(mysql_error());
			$nb_do_select = mysql_num_rows($rs);

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

					// Récupération du code donneur d'ordres
					$code_donneur_ordres[$i] = $do_code;

					// Détermination du nombre d'interventions créées par l'donneur d'ordres sur la période
					$rech2 = "SELECT * FROM ".TBINT;
					$rech2.= " WHERE int_codecrea='".$do_code."'";
					$rech2.= " AND int_datecrea>='".$date1."' AND int_datecrea<='".$date2."'";

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

					// Détermination du nombre d'interventions encore ouvertes et créées par l'donneur d'ordres sur la période
					$rech2 = "SELECT * FROM ".TBINT;
					$rech2.= " WHERE int_codecrea='".$do_code."'";
					$rech2.= " AND int_dateprev='0000-00-00'";
					$rech2.= " AND int_datecrea>='".$date1."' AND int_datecrea<='".$date2."'";
				
					$rs2 = mysql_query($rech2) or die(mysql_error());
					$nb_int_ouv_crees_do[$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 donneurs d'ordres sur la période
					$rech2 = "SELECT * FROM ".TBINT;
					$rech2.= " WHERE int_codecrea='".$do_code."'";
					$rech2.= " AND int_dateprev<>'0000-00-00'";
					$rech2.= " AND int_datefin='0000-00-00'";
					$rech2.= " AND int_datecrea>='".$date1."' AND int_datecrea<='".$date2."'";
				
					$rs2 = mysql_query($rech2) or die(mysql_error());
					$nb_int_prev_crees_do[$i] = mysql_num_rows($rs2);
					mysql_free_result($rs2);

					// Détermination du nombre total d'interventions closes et créées par les donneurs d'ordres sur la période
					$nb_int_clos_crees_do[$i] = $nb_int_crees_do[$i] - $nb_int_ouv_crees_do[$i] - $nb_int_prev_crees_do[$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 - <?PHP echo $title_esp_prive; ?> : <?PHP echo $title_do_stat; ?></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-<?PHP echo $_SESSION["lng"]; ?>.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"><?PHP echo $titlein_do_stat; ?></span></p>
<?PHP
if ($pbm_stat==FALSE)
{
	if (nb_do() >0)
	{
?>
	<div align="center">
	<?PHP
	if ($ts_ok==FALSE)
	{
	?>
	<form name="ts" method="post" action="do_stat.php">
	<br>
		<select name="ts" id="ts">
		<?PHP
		for ($i=0; $i<count($txt_stat_do); $i++)
		{
		?>
		<option value="<?PHP echo $i; ?>" <?PHP if ($ts==$i) echo "selected=\"selected\""; ?>><?PHP echo $txt_stat_do[$i]; ?></option>
		<?PHP
		}
		?>					
		</select>
		<input type="submit" class="bton_std" name="Submit" value="<?PHP echo $but_ok; ?>">
	</form>
	<?PHP
	}
	else
	{
	?>
		<br>
		<span class="titre_gras_soul">
		<?PHP echo $txt_stat_do[$ts]; ?>
		</span>
		<br><br><br>
	<?PHP
		if (count($do_select_tab) <> "")
		{
			switch ($ts)
			{
			/* Nombre de créations de clients sur une période donnée */
			case 1 :
			/* Nombre de créations d'interventions sur une période donnée */
			case 2 :
				echo "<span class=\"annot_std_it\">";
				if ((in_array("*",$do_select_tab)) AND (count($do_select_tab) == 1))
					echo $txt_div_tsdo;
				else
				{
					$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
					mysql_select_db(DBNAME);
					if (!in_array("*",$do_select_tab))
						if (count($do_select_tab) == 1) // Une seule donneur d'ordres choisie
							$liste_do = $txt_div_pourdo;
						else
							$liste_do = $txt_div_pourdos;
					for ($i=0; $i<count($do_select_tab); $i++)
					{
						$rs = mysql_query("SELECT * FROM ".TBDO." WHERE `do_code` = '".$do_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_do .=$do_nom.", ";
							}
						}
					}
					echo substr($liste_do,0,strlen($liste_do)-2);
					mysql_free_result($rs);
					mysql_close($conn);
				}
				echo "<br>";
				echo $txt_div_perdu.$_POST['date1f'].$txt_div_to.$_POST['date2f']."<br>";
				echo "</span>";
				break;
				
			default : 
				break;
			}
		}
	}
	?>
	</div>
	<br>
	<?PHP	
	if ($aff_stat == TRUE)
	{
	?>
		<a href="javascript:;" onclick="self.location.href=('do_stat.php');")><img src="../img/stat.png" title="<?PHP echo $alt_autrestat; ?>" border="0" align="absmiddle"></a>
		<a href="javascript:;" onclick="self.location.href=('do_stat.php');")> <?PHP echo $alt_autrestat; ?> </a>
		<br>
	<?PHP
	}
	if ($ts_ok == TRUE)
	{
		switch ($ts)
		{
			/* Nombre de créations de clients 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:do[] ; format:listem ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_do); ?>; vmn:0 ; stok:frmok ; stbad:frmbad",
					"nom:date1f ; format:date ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_dtedeb); ?>; masque:<?PHP echo $datemsql; ?> ; stok:frmok ; stbad:frmbad",
					"nom:date2f ; format:date ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_dtefin); ?> ; masque:<?PHP echo $datemsql; ?> ; stok:frmok ; stbad:frmbad");
				//-->
				</script>
				
				<form name="clients" class="form_pointilles" method="post" action="do_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 /><?PHP echo $txt_div_chxdo; ?>
						<br /><span class="annot_petit_it"><?PHP echo $txt_div_chxdositous; ?></span>
					</td>
                    <td align="center">&nbsp;
					
					</td>
				</tr>
				<tr>
                    <td width="50%" align="center">
						<select name="do[]" id="do" size="5" multiple="multiple">
						<option value="*" selected="selected"><?PHP echo $sel_lst_tous; ?></option>
		
						<?PHP
						// Création de la liste des donneurs d'ordres actives
						
						$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
						mysql_select_db(DBNAME);
						$rs = mysql_query("SELECT * FROM ".TBDO." WHERE `do_ouvert` = '1' ORDER BY do_nom");
						while ($resultat = mysql_fetch_array($rs)) 
						{
							extract($resultat);
							$txt_do = $do_nom." (".$do_code.")";
							echo '<option value="'.$do_code.'">'.$txt_do.'</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" align="right"><?PHP echo $txt_div_fromMAJ; ?>...</td>
					<td>
						<input name="date1f" type="text" id="date1f" size="10" maxlength="10" readonly="1">
						<img src="../img/calendar.png" align="absmiddle" id="f_img_date1f" title="<?PHP echo $alt_chxdate; ?>">
						<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
					</td>
					<td width="30" class="rubfrm" id="f_date2f" align="right"><?PHP echo $txt_div_toMAJ; ?>...</td>
					<td>
						<input name="date2f" type="text" id="date2f" size="10" maxlength="10" readonly="1">
						<img src="../img/calendar.png" align="absmiddle" id="f_img_date2f" title="<?PHP echo $alt_chxdate; ?>">
						<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
					</td>
				</tr>
				</table>
				<p align="center">
					<input name="Submit" type="button" class="bton_std" id="Submit" value="<?PHP echo $but_calc; ?>" onClick="verif_stats_do(clients,tab_champ,'','',this.value);">
					<input name="init" type="reset" class="bton_std" id="init" value="<?PHP echo $but_reinit; ?>">
				</p>
			</form>
			
			  <script type="text/javascript">
			  <!--
				Calendar.setup({
					inputField     :    "date1f",     // id of the input field
					ifFormat       :    "<?PHP echo $datefmtc; ?>",      // 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       :    "<?PHP echo $datefmtc; ?>",      // 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 $tab_ent_age;
				echo "</th>\n";
				echo "<th>";
				echo $tab_ent_totcrees;
				echo "</th>\n";
				echo "<th>";
				echo $tab_ent_encprosp;
				echo "</th>\n";
				echo "<th>";
				echo $tab_ent_attint;
				echo "</th>\n";
				echo "<th>";
				echo $tab_ent_int;
				echo "</th>\n";

				$i = 0;

				/* Données pour tous les donneurs d'ordres */

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

				echo "<td>";
				echo "<span class=\"annot_std_it\">";
				echo $txt_div_tsdo;
				echo "</span>";
				echo "</td>\n";
				echo "<td align=\"center\">";
				if ($nb_cli_crees_total <> 0)
				{
					echo "<span class=\"annot_std_it\">";
					echo $nb_cli_crees_total;
					echo "</span>";
				}
				else
					echo "-";
				echo "</td>\n";
				echo "<td align=\"center\">";
				if ($nb_cli_prospects_crees_total <> 0)
				{
					echo "<span class=\"annot_std_it\">";
					echo $nb_cli_prospects_crees_total;
					echo "</span>";
					if ($nb_cli_crees_total <> 0)
					{
						echo"<span class=\"annot_petit_it\">";
						echo " (".round((($nb_cli_prospects_crees_total/$nb_cli_crees_total)*100),2)."%)";
						echo "</span>";
					}
				}
				else
					echo "-";
				echo "</td>\n";
				echo "<td align=\"center\">";
				if ($nb_cli_ddeint_crees_total <> 0)
				{
					echo "<span class=\"annot_std_it\">";
					echo $nb_cli_ddeint_crees_total;
					echo "</span>";
					if ($nb_cli_crees_total <> 0)
					{
						echo"<span class=\"annot_petit_it\">";
						echo " (".round((($nb_cli_ddeint_crees_total/$nb_cli_crees_total)*100),2)."%)";
						echo "</span>";
					}
				}
				else
					echo "-";
				echo "</td>\n";
				echo "<td align=\"center\">";
				if ($nb_cli_inter_crees_total <> 0)
				{
					echo "<span class=\"annot_std_it\">";
					echo $nb_cli_inter_crees_total;
					echo "</span>";
					if ($nb_cli_crees_total <> 0)
					{
						echo"<span class=\"annot_petit_it\">";
						echo " (".round((($nb_cli_inter_crees_total/$nb_cli_crees_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_do_select > 0)
				{
					for ($j=0; $j<$nb_do_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 ".TBDO." WHERE `do_code` = '".$code_donneur_ordres[$j]."'");
						if ($row = mysql_fetch_array($rs))
						{
							extract($row);
							$txt_do = $do_nom;
						}
						mysql_free_result($rs);
						mysql_close($conn);
						echo "<span class=\"annot_std_gras\">";
						echo $txt_do." (".$code_donneur_ordres[$j].")";
						echo "</span>";
						if ($do_ouvert == 0)
						{
							echo "<span class=\"annot_petit_it\">";
							echo " ".$txt_div_ferm;
							echo "</span>";
						}
						echo "<br>";
						if ($nb_cli_crees_do[$j] <> 0)
						{
							echo "<span class=\"annot_petit_it\">";
							echo "<div align=\"right\">";
							echo $txt_div_rapdo;
							echo "<br>".$txt_div_raptot." : ";
							echo "</div>";
							echo "</span>";
						}
						echo "</td>\n";
						echo "<td align=\"center\">";
						if ($nb_cli_crees_do[$j] <> 0)
						{
							echo "<span class=\"annot_std_gras\">";
							echo $nb_cli_crees_do[$j];
							echo "</span>";
							if ($nb_cli_crees_total <> 0)
							{
								echo"<span class=\"annot_petit_it\">";
								echo "<br>-<br>(".round((($nb_cli_crees_do[$j]/$nb_cli_crees_total)*100),2)."%)";
								echo "</span>";
							}							
						}
						else
							echo "-";
						echo "</td>\n";
						echo "<td align=\"center\">";
						if ($nb_cli_prospects_crees_do[$j] <> 0)
						{
							echo "<span class=\"annot_std_gras\">";
							echo $nb_cli_prospects_crees_do[$j];
							echo "</span>";
							echo "<br>";
							if ($nb_cli_crees_do[$j] <> 0)
							{
								echo"<span class=\"annot_petit_it\">";
								echo "(".round((($nb_cli_prospects_crees_do[$j]/$nb_cli_crees_do[$j])*100),2)."%)";
								echo "</span>";
							}
							else
								echo "-";
							echo "<br>";
							if ($nb_cli_prospects_crees_total <> 0)
							{
								echo"<span class=\"annot_petit_it\">";
								echo "(".round((($nb_cli_prospects_crees_do[$j]/$nb_cli_prospects_crees_total)*100),2)."%)";
								echo "</span>";
							}							
							else
								echo "-";
						}
						else
							echo "-";
						echo "</td>\n";
						echo "<td align=\"center\">";
						if ($nb_cli_ddeint_crees_do[$j] <> 0)
						{
							echo "<span class=\"annot_std_gras\">";
							echo $nb_cli_ddeint_crees_do[$j];
							echo "</span>";
							echo "<br>";
							if ($nb_cli_crees_do[$j] <> 0)
							{
								echo"<span class=\"annot_petit_it\">";
								echo " (".round((($nb_cli_ddeint_crees_do[$j]/$nb_cli_crees_do[$j])*100),2)."%)";
								echo "</span>";
							}
							else
								echo "-";
							echo "<br>";
							if ($nb_cli_ddeint_crees_total <> 0)
							{
								echo"<span class=\"annot_petit_it\">";
								echo "(".round((($nb_cli_ddeint_crees_do[$j]/$nb_cli_ddeint_crees_total)*100),2)."%)";
								echo "</span>";
							}							
							else
								echo "-";
						}
						else
							echo "-";
						echo "</td>\n";
						echo "<td align=\"center\">";
						if ($nb_cli_inter_crees_do[$j] <> 0)
						{
							echo "<span class=\"annot_std_gras\">";
							echo $nb_cli_inter_crees_do[$j];
							echo "</span>";
							echo "<br>";
							if ($nb_cli_crees_do[$j] <> 0)
							{
								echo"<span class=\"annot_petit_it\">";
								echo " (".round((($nb_cli_inter_crees_do[$j]/$nb_cli_crees_do[$j])*100),2)."%)";
								echo "</span>";
							}							
							echo "<br>";
							if ($nb_cli_inter_crees_total <> 0)
							{
								echo"<span class=\"annot_petit_it\">";
								echo "(".round((($nb_cli_inter_crees_do[$j]/$nb_cli_inter_crees_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 $txt_div_noresdde.".";
					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;

			/* Nombre de créations d'interventions sur une période donnée */
			case 2 :
				if ($aff_stat == FALSE) // On est en mode "paramètres"
				{
		?>
				<script language="javascript">
				<!--
				var tab_champ=new Array(
					"nom:do[] ; format:listem ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_do); ?>; vmn:0 ; stok:frmok ; stbad:frmbad",
					"nom:date1f ; format:date ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_dtedeb); ?>; masque:<?PHP echo $datemsql; ?> ; stok:frmok ; stbad:frmbad",
					"nom:date2f ; format:date ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_dtefin); ?> ; masque:<?PHP echo $datemsql; ?> ; stok:frmok ; stbad:frmbad");
				//-->
				</script>
				
				<form name="inter" class="form_pointilles" method="post" action="do_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>
						<?PHp echo $txt_div_chxdo; ?>
						<br>
						<span class="annot_petit_it"><?PHP echo $txt_div_chxdositous; ?></span>
					</td>
                    <td align="center">&nbsp;
					
					</td>
				</tr>
				<tr>
                    <td width="50%" align="center">
						<select name="do[]" id="do" size="5" multiple="multiple">
						<option value="*" selected="selected"><?PHP echo $sel_lst_tous; ?></option>
		
						<?PHP
						// Création de la liste des donneurs d'ordres actives
						
						$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
						mysql_select_db(DBNAME);
						$rs = mysql_query("SELECT * FROM ".TBDO." WHERE `do_ouvert` = '1' ORDER BY do_nom");
						while ($resultat = mysql_fetch_array($rs)) 
						{
							extract($resultat);
							$txt_do = $do_nom." (".$do_code.")";
							echo '<option value="'.$do_code.'">'.$txt_do.'</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" align="right"><?PHP echo $txt_div_fromMAJ; ?>...</td>
					<td>
						<input name="date1f" type="text" id="date1f" size="10" maxlength="10" readonly="1">
						<img src="../img/calendar.png" align="absmiddle" id="f_img_date1f" title="<?PHP echo $alt_chxdate; ?>">
						<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
					</td>
					<td width="30" class="rubfrm" id="f_date2f" align="right"><?PHP echo $txt_div_toMAJ; ?>...</td>
					<td>
						<input name="date2f" type="text" id="date2f" size="10" maxlength="10" readonly="1">
						<img src="../img/calendar.png" align="absmiddle" id="f_img_date2f" title="<?PHP echo $alt_chxdate; ?>">
						<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
					</td>
				</tr>
				</table>
				<p align="center">
					<input name="Submit" type="button" class="bton_std" id="Submit" value="<?PHP echo $but_calc; ?>" onClick="verif_stats_do(inter,tab_champ,'','',this.value);">
					<input name="init" type="reset" class="bton_std" id="init" value="<?PHP echo $but_reinit; ?>">
				</p>
			</form>
			
			<script type="text/javascript">
			<!--
				Calendar.setup({
					inputField     :    "date1f",     // id of the input field
					ifFormat       :    "<?PHP echo $datefmtc; ?>",      // 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       :    "<?PHP echo $datefmtc; ?>",      // 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 $tab_ent_age;
				echo "</th>\n";
				echo "<th>";
				echo $tab_ent_totcreees;
				echo "</th>\n";
				echo "<th>";
				echo $tab_ent_ouvertes;
				echo "</th>\n";
				echo "<th>";
				echo $tab_ent_cliprev;
				echo "</th>\n";
				echo "<th>";
				echo $tab_ent_closes;
				echo "</th>\n";

				$i = 0;

				/* Données pour toutes les donneurs d'ordres */

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

				echo "<td>";
				echo "<span class=\"annot_std_it\">";
				echo $txt_div_tsdo;
				echo "</span>";
				echo "</td>\n";
				echo "<td align=\"center\">";
				if ($nb_int_crees_total <> 0)
				{
					echo "<span class=\"annot_std_it\">";
					echo $nb_int_crees_total;
					echo "</span>";
				}
				else
					echo "-";
				echo "</td>\n";
				echo "<td align=\"center\">";
				if ($nb_int_ouv_crees_total <> 0)
				{
					echo "<span class=\"annot_std_it\">";
					echo $nb_int_ouv_crees_total;
					echo "</span>";
					if ($nb_int_crees_total <> 0)
					{
						echo"<span class=\"annot_petit_it\">";
						echo " (".round((($nb_int_ouv_crees_total/$nb_int_crees_total)*100),2)."%)";
						echo "</span>";
					}
				}
				else
					echo "-";
				echo "</td>\n";
				echo "<td align=\"center\">";
				if ($nb_int_prev_crees_total <> 0)
				{
					echo "<span class=\"annot_std_it\">";
					echo $nb_int_prev_crees_total;
					echo "</span>";
					if ($nb_int_crees_total <> 0)
					{
						echo"<span class=\"annot_petit_it\">";
						echo " (".round((($nb_int_prev_crees_total/$nb_int_crees_total)*100),2)."%)";
						echo "</span>";
					}
				}
				else
					echo "-";
				echo "</td>\n";
				echo "<td align=\"center\">";
				if ($nb_int_clos_crees_total <> 0)
				{
					echo "<span class=\"annot_std_it\">";
					echo $nb_int_clos_crees_total;
					echo "</span>";
					if ($nb_int_crees_total <> 0)
					{
						echo"<span class=\"annot_petit_it\">";
						echo " (".round((($nb_int_clos_crees_total/$nb_int_crees_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_do_select > 0)
				{
					for ($j=0; $j<$nb_do_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 ".TBDO." WHERE `do_code` = '".$code_donneur_ordres[$j]."'");
						if ($row = mysql_fetch_array($rs))
						{
							extract($row);
							$txt_do = $do_nom;
						}
						mysql_free_result($rs);
						mysql_close($conn);
						echo "<span class=\"annot_std_gras\">";
						echo $txt_do." (".$code_donneur_ordres[$j].")";
						echo "</span>";
						if ($do_ouvert == 0)
						{
							echo "<span class=\"annot_petit_it\">";
							echo " ".$txt_div_ferm;
							echo "</span>";
						}
						echo "<br>";
						if ($nb_int_crees_do[$j] <> 0)
						{
							echo "<span class=\"annot_petit_it\">";
							echo "<div align=\"right\">";
							echo $txt_div_rapdo;
							echo "<br>".$txt_div_raptot." : ";
							echo "</div>";
							echo "</span>";
						}
						echo "</td>\n";
						echo "<td align=\"center\">";
						if ($nb_int_crees_do[$j] <> 0)
						{
							echo "<span class=\"annot_std_gras\">";
							echo $nb_int_crees_do[$j];
							echo "</span>";
							if ($nb_int_crees_total <> 0)
							{
								echo"<span class=\"annot_petit_it\">";
								echo "<br>-<br>(".round((($nb_int_crees_do[$j]/$nb_int_crees_total)*100),2)."%)";
								echo "</span>";
							}							
						}
						else
							echo "-";
						echo "</td>\n";
						echo "<td align=\"center\">";
						if ($nb_int_ouv_crees_do[$j] <> 0)
						{
							echo "<span class=\"annot_std_gras\">";
							echo $nb_int_ouv_crees_do[$j];
							echo "</span>";
							echo "<br>";
							if ($nb_int_crees_do[$j] <> 0)
							{
								echo"<span class=\"annot_petit_it\">";
								echo "(".round((($nb_int_ouv_crees_do[$j]/$nb_int_crees_do[$j])*100),2)."%)";
								echo "</span>";
							}
							else
								echo "-";
							echo "<br>";
							if ($nb_int_ouv_crees_total <> 0)
							{
								echo"<span class=\"annot_petit_it\">";
								echo "(".round((($nb_int_ouv_crees_do[$j]/$nb_int_ouv_crees_total)*100),2)."%)";
								echo "</span>";
							}							
							else
								echo "-";
						}
						else
							echo "-";
						echo "</td>\n";
						echo "<td align=\"center\">";
						if ($nb_int_prev_crees_do[$j] <> 0)
						{
							echo "<span class=\"annot_std_gras\">";
							echo $nb_int_prev_crees_do[$j];
							echo "</span>";
							echo "<br>";
							if ($nb_int_crees_do[$j] <> 0)
							{
								echo"<span class=\"annot_petit_it\">";
								echo " (".round((($nb_int_prev_crees_do[$j]/$nb_int_crees_do[$j])*100),2)."%)";
								echo "</span>";
							}
							else
								echo "-";
							echo "<br>";
							if ($nb_int_prev_crees_total <> 0)
							{
								echo"<span class=\"annot_petit_it\">";
								echo "(".round((($nb_int_prev_crees_do[$j]/$nb_int_prev_crees_total)*100),2)."%)";
								echo "</span>";
							}							
							else
								echo "-";
						}
						else
							echo "-";
						echo "</td>\n";
						echo "<td align=\"center\">";
						if ($nb_int_clos_crees_do[$j] <> 0)
						{
							echo "<span class=\"annot_std_gras\">";
							echo $nb_int_clos_crees_do[$j];
							echo "</span>";
							echo "<br>";
							if ($nb_int_crees_do[$j] <> 0)
							{
								echo"<span class=\"annot_petit_it\">";
								echo " (".round((($nb_int_clos_crees_do[$j]/$nb_int_crees_do[$j])*100),2)."%)";
								echo "</span>";
							}							
							echo "<br>";
							if ($nb_int_clos_crees_total <> 0)
							{
								echo"<span class=\"annot_petit_it\">";
								echo "(".round((($nb_int_clos_crees_do[$j]/$nb_int_clos_crees_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 $txt_div_noresdde.".";
					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
	{
		echo '<p align="center" class="annot_std_it">'.$alert_nodo.'...</p>';
		aff_ret_idx_auto("index.php",2000);
	}
}
else
{
?>
	<script type="text/javascript">
	<!--
	setTimeout("self.location.href=('index.php');",2000)
	//-->
	</script>
	<p align="center" class="annot_std_it"><?PHP echo $alert_prm; ?>...</p>
<?PHP
}
include_once("pied.php");
?>
