<?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_cli.inc.php");
include_once("../inc/fic_do.inc.php");
include_once("../inc/fic_hum.inc.php");
include_once("../inc/fic_ope.inc.php");
include_once("../inc/fic_st.inc.php");
include_once("../inc/fic_tec.inc.php");
include_once("../inc/fic_txt.inc.php");
include_once("../inc/fic_zc.inc.php");
include_once("../inc/fic_zoc.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_mail.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/func_txtcm.inc.php");
include_once("../inc/lst.inc.php");
include_once("../classes/phpmailer/class.phpmailer.php");
include_once("../inc/mail.inc.php");
include_once("../classes/fckeditor/fckeditor.php") ;
Archivelog(@$_SESSION["code_log"]);

$td = strip_tags(trim(@$_GET['td'])); // On récupère le type en ligne de commande

if ($td == "") // Si vide, on récupère le type en post du formulaire (si c'est toujours vide, c'est une erreur ou un hack...)
	$td = strip_tags(trim($_POST['td']));

$email_ok = TRUE;
$email_envoye = FALSE;
$retourliste = TRUE;
$nbsel=0;

$msg1_err_type=$ajx_nodeppays;
$msg2_err_type=$ajx_nodepcpays;
$msg3_err_type=$ajx_noagact;
$msg4_err_type=$ajx_nodoa;
$msg5_err_type=$ajx_nosta;

// Vérification du mode du connecté (pour éviter les hacks)
if ((@$_SESSION["niv_log"] <= 3) OR (@$_SESSION["niv_log"] == 7) OR (@$_SESSION["niv_log"] == 11))
	$email_ok = FALSE;

// Les agences n'ont droit qu'aux emailings clients et techniciens
if (@$_SESSION["niv_log"] == 4)
{
	if (($td <> "cli") AND ($td <> "tec"))
		$email_ok = FALSE;
	else
	{
		$row=lit_enr_age(@$_SESSION["code_age"],TRUE);
		if (is_array($row))
		{
			extract($row);
			$age=$age_code;
			$pays=$age_codepays;
		}
	}
}

// Les donneurs d'ordres n'ont droit qu'aux emailings techniciens donneurs d'ordres et de leurs clients
if (@$_SESSION["niv_log"] == 6)
{
	if (($td <> "tecd") AND ($td <> "cli"))
		$email_ok = FALSE;
	else
	{
		$row=lit_enr_do(@$_SESSION["code_do"]);
		if (is_array($row))
		{
			extract($row);
			$age=$do_code;
			$pays=$do_codepays;
		}
	}
}
// Les sous-traitants n'ont droit qu'aux emailings techniciens sous-traitants
if (@$_SESSION["niv_log"] == 10)
{
	if ($td <> "tecs")
		$email_ok = FALSE;
	else
	{
		$row=lit_enr_st(@$_SESSION["code_st"]);
		if (is_array($row))
		{
			extract($row);
			$age=$st_code;
			$pays=$st_codepays;
		}
	}
}

$validp=FALSE;
if (strip_tags(trim(@$_POST["OK"])) == html_entity_decode($but_valprm))
	$validp=TRUE;
// $initall=FALSE;
// if (strip_tags(trim(@$_POST["RAZ"])) == html_entity_decode($but_reinit))
//	$initall=TRUE;
$exped=FALSE;
$typeexp="";
if (strip_tags(trim(@$_POST["envoi"])) == html_entity_decode($but_exped))
{
	$exped=TRUE;
	set_time_limit(0); // On demande à PHP de ne pas interrrompre le script pendant les envois
	// Détermination de l'expéditeur
	switch (@$_SESSION["niv_log"])
	{
		case 9 : 
			$typeexp = "adm";
			break;
		case 5 : 
			$typeexp = "cdg";
			break;
		case 4 : 
			$typeexp = "age";
			break;
		case 6 : 
			$typeexp = "do";
			break;
		case 10 : 
			$typeexp = "st";
			break;
		default : 
			break;
	}
}

$cv="N";

switch ($td)
{
	case "age" :
		$titre = "EMAILING AGENCES";
		
		if ($initall==TRUE)
		{
			$cat = "";
			$pays="";
			$dep = "";
			$zone = "";
			$sujet = "";
			$txt = "Merci de saisir le texte de votre email";
			unset($_POST["type_dest"]);
		}

		if (($validp==TRUE) OR ($exped==TRUE))
		{
			$cat = strip_tags(trim(@$_POST["cat"]));
			$pays = @$_POST["pays"];
			$dep = @$_POST["deptxt"];
			$zone = @$_POST["zonetxt"];
			$sujet = strip_tags(trim(stripslashes(@$_POST["sujet"])));
			$cv = @$_POST["cv"];
			$txt = stripslashes($_POST['FCKeditor1']);
			for ($i = 0; $i < count($_POST["type_dest"]); $i++)
			{
				$type_mail[$_POST["type_dest"][$i]-1] = 1;
			}
			
			if ($exped==TRUE)
			{
				if ($txt <> "") // Le texte envoyé doit exister
				{
					if (count($_POST["type_dest"]) <> 0) // Il doit y avoir un type de destinataire
					{
						if (count($_POST["age_choisie"]) <> 0) // Il doit y avoir au moins une agence sélectionnée
						{
							for ($i = 0; $i < count($_POST["age_choisie"]); $i++)
							{
								$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
								mysql_select_db(DBNAME);
			
								$rech = "SELECT * FROM `" .TBAGE. "` WHERE `age_id`= '".$_POST["age_choisie"][$i]."'";
								$rs = mysql_query($rech) or die(mysql_error());
								if (mysql_num_rows($rs) == 1) // Il ne peut y avoir qu'un seul résultat
								{
									if ($row = mysql_fetch_array($rs))
									{
										extract ($row);
										$email_envoye = envoi_emailing("age",$type_mail,$age_code,$typeexp,(@$_SESSION["code_log"]),$txt,$sujet);
										if ($email_envoye == false)
										{
											$msg = "Problème lors de l'envoi de l'emailing.";
											$retourliste = FALSE;
											break;
										}
										sleep($smtp_pausem);
									}
								}
								else
								{
									mysql_close($conn);
									mysql_free_result($rs);
								}
							}
						}
						else
						{
							$msg = "Vous n'avez choisi aucune agence.";
							$retourliste = FALSE;
							break;
						}
					}
					else
					{
						$msg = "Vous n'avez choisi aucun type de destinataire.";
						$retourliste = FALSE;
						break;
					}
				}
				else
				{
					$msg = "Le texte de votre email est vide.";
					$retourliste = FALSE;
					break;
				}
			}
		}


		break;

	case "cli" :
		$titre = "EMAILING CLIENTS";
/*
		if ($initall==TRUE)
		{
			$cat = "";
			switch (@$_SESSION["niv_log"])
			{
				case 4 :
					$age = $age_code;
					$pays = $age_codepays;
					break;
				case 6 :
					$age = $do_code;
					$pays = $do_codepays;
					break;
				default :
					$age = "";
					$pays = "";
					break;
			}
			$dep = "";
			$sujet = "";
			$txt = "Merci de saisir le texte de votre email";
			unset($_POST["type_dest"]);
		}
*/
		if (($validp==TRUE) OR ($exped==TRUE))
		{
			$cat = strip_tags(trim(@$_POST["cat"]));
			$pays = strip_tags(trim(@$_POST["pays"]));
			$age = strip_tags(trim(@$_POST["age"]));
			$dep = @$_POST["deptxt"];
			$sujet = strip_tags(trim(stripslashes(@$_POST["sujet"])));
			$txt = stripslashes($_POST['FCKeditor1']);
			for ($i = 0; $i < count($_POST["type_dest"]); $i++)
			{
				$type_mail[$_POST["type_dest"][$i]-1] = 1;
			}

			if ($exped==TRUE)
			{
				if ($txt <> "") // Le texte envoyé doit exister
				{
					if (count($_POST["type_dest"]) <> 0) // Il doit y avoir au moins un type de destinataire
					{
						if (count($_POST["cli_choisi"]) <> 0) // Il doit y avoir au moins un client de choisi
						{
							for ($i = 0; $i < count($_POST["cli_choisi"]); $i++)
							{
								$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
								mysql_select_db(DBNAME);
			
								$rech = "SELECT * FROM `" .TBCLI. "` WHERE `cli_id`= '".$_POST["cli_choisi"][$i]."'";
								$rs = mysql_query($rech) or die(mysql_error());
								if (mysql_num_rows($rs) == 1) // Il ne peut y avoir qu'un seul résultat
								{
									if ($row = mysql_fetch_array($rs))
									{
										extract ($row);
										$email_envoye = envoi_emailing("cli",$type_mail,$cli_code,$typeexp,(@$_SESSION["code_log"]),$txt,$sujet);
										if ($email_envoye == false)
										{
											$msg = "Problème lors de l'envoi de l'emailing.";
											$retourliste = FALSE;
											break;
										}
										sleep($smtp_pausem);
									}
								}
								else
								{
									mysql_close($conn);
									mysql_free_result($rs);
								}
							}
						}
						else
						{
							$msg = "Vous n'avez choisi aucun client.";
							$retourliste = FALSE;
							break;
						}
					}
					else
					{
						$msg = "Vous n'avez choisi aucun type de destinataire.";
						$retourliste = FALSE;
						break;
					}
				}
				else
				{

					$msg = "Le texte de votre email est vide.";
					$retourliste = FALSE;
					break;
				}
			}
		}
		break;

	case "do" :
		$titre = "EMAILING DONNEURS D'ORDRES";
		
		if ($initall==TRUE)
		{
			$pays = "";
			$dep = "";
			$sujet = "";
			$txt = "Merci de saisir le texte de votre email";
			unset($_POST["type_dest"]);
		}

		if (($validp==TRUE) OR ($exped==TRUE))
		{
			$pays = @$_POST["pays"];
			$dep = @$_POST["deptxt"];
			$sujet = strip_tags(trim(stripslashes(@$_POST["sujet"])));
			$txt = stripslashes($_POST['FCKeditor1']);
			$cv = $_POST['cv'];
			for ($i = 0; $i < count($_POST["type_dest"]); $i++)
			{
				$type_mail[$_POST["type_dest"][$i]-1] = 1;
			}
			
			if ($exped==TRUE)
			{
				if ($txt <> "") // Le texte envoyé doit exister
				{
					if (count($_POST["type_dest"]) <> 0) // Il doit y avoir un type de destinataire
					{
						if (count($_POST["do_choisi"]) <> 0) // Il doit y avoir au moins un donneur d'ordre sélectionné
						{
							for ($i = 0; $i < count($_POST["do_choisi"]); $i++)
							{
								$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
								mysql_select_db(DBNAME);
			
								$rech = "SELECT * FROM `" .TBDO. "` WHERE `do_id`= '".$_POST["do_choisi"][$i]."'";
								$rs = mysql_query($rech) or die(mysql_error());
								if (mysql_num_rows($rs) == 1) // Il ne peut y avoir qu'un seul résultat
								{
									if ($row = mysql_fetch_array($rs))
									{
										extract ($row);
										$email_envoye = envoi_emailing("do",$type_mail,$do_code,$typeexp,(@$_SESSION["code_log"]),$txt,$sujet);
										if ($email_envoye == false)
										{
											$msg = "Problème lors de l'envoi de l'emailing.";
											$retourliste = FALSE;
											break;
										}
										sleep($smtp_pausem);
									}
								}
								else
								{
									mysql_close($conn);
									mysql_free_result($rs);
								}
							}
						}
						else
						{
							$msg = "Vous n'avez choisi aucun donneur d'ordres.";
							$retourliste = FALSE;
							break;
						}
					}
					else
					{
						$msg = "Vous n'avez choisi aucun type de destinataire.";
						$retourliste = FALSE;
						break;
					}
				}
				else
				{
					$msg = "Le texte de votre email est vide.";
					$retourliste = FALSE;
					break;
				}
			}
		}


		break;

	case "ope" :
		$titre = "EMAILING OPERATEURS";

		if ($initall==TRUE)
		{
			$pays="";
			$dep = "";
			$sujet = "";
			$txt = "Merci de saisir le texte de votre email";
		}

		if (($validp==TRUE) OR ($exped==TRUE))
		{
			$pays = @$_POST["pays"];
			$dep = @$_POST["deptxt"];
			$sujet = strip_tags(trim(stripslashes(@$_POST["sujet"])));
			$txt = stripslashes($_POST['FCKeditor1']);
	
			if ($exped==TRUE)
			{
				if ($txt <> "") // Le texte envoyé doit exister
				{
					if (count($_POST["ope_choisi"]) <> 0) // Il doit y avoir au moins un opérateur de choisi
					{
						for ($i = 0; $i < count($_POST["ope_choisi"]); $i++)
						{
							$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
							mysql_select_db(DBNAME);
		
							$rech = "SELECT * FROM `" .TBOPE. "` WHERE `ope_id`= '".$_POST["ope_choisi"][$i]."'";
							$rs = mysql_query($rech) or die(mysql_error());
							if (mysql_num_rows($rs) == 1) // Il ne peut y avoir qu'un seul résultat
							{
								if ($row = mysql_fetch_array($rs))
								{
									extract ($row);
									$email_envoye = envoi_emailing("ope","",$ope_code,$typeexp,(@$_SESSION["code_log"]),$txt,$sujet);
									if ($email_envoye == false)
									{
										$msg = "Problème lors de l'envoi de l'emailing.";
										$retourliste = FALSE;
										break;
									}
									sleep($smtp_pausem);
								}
							}
							else
							{
								mysql_close($conn);
								mysql_free_result($rs);
							}
						}
					}
					else
					{
						$msg = "Vous n'avez choisi aucun opérateur.";
						$retourliste = FALSE;
						break;
					}
				}
				else
				{
					$msg = "Le texte de votre email est vide.";
					$retourliste = FALSE;
					break;
				}
			}
		}
		break;

	case "st" :
		$titre = "EMAILING SOUS-TRAITANTS";
		
		if ($initall==TRUE)
		{
			$cat = "";
			$pays="";
			$dep = "";
			$zone = "";
			$sujet = "";
			$txt = "Merci de saisir le texte de votre email";
			unset($_POST["type_dest"]);
		}

		if (($validp==TRUE) OR ($exped==TRUE))
		{
			$cat = strip_tags(trim(@$_POST["cat"]));
			$pays = @$_POST["pays"];
			$dep = @$_POST["deptxt"];
			$zone = @$_POST["zonetxt"];
			$sujet = strip_tags(trim(stripslashes(@$_POST["sujet"])));
			$cv = @$_POST["cv"];
			$txt = stripslashes($_POST['FCKeditor1']);
			for ($i = 0; $i < count($_POST["type_dest"]); $i++)
			{
				$type_mail[$_POST["type_dest"][$i]-1] = 1;
			}
			
			if ($exped==TRUE)
			{
				if ($txt <> "") // Le texte envoyé doit exister
				{
					if (count($_POST["type_dest"]) <> 0) // Il doit y avoir un type de destinataire
					{
						if (count($_POST["st_choisi"]) <> 0) // Il doit y avoir au moins un sous-traitant sélectionné
						{
							for ($i = 0; $i < count($_POST["st_choisi"]); $i++)
							{
								$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
								mysql_select_db(DBNAME);
			
								$rech = "SELECT * FROM `" .TBST. "` WHERE `st_id`= '".$_POST["st_choisi"][$i]."'";
								$rs = mysql_query($rech) or die(mysql_error());
								if (mysql_num_rows($rs) == 1) // Il ne peut y avoir qu'un seul résultat
								{
									if ($row = mysql_fetch_array($rs))
									{
										extract ($row);
										$email_envoye = envoi_emailing("st",$type_mail,$st_code,$typeexp,(@$_SESSION["code_log"]),$txt,$sujet);
										if ($email_envoye == false)
										{
											$msg = "Problème lors de l'envoi de l'emailing.";
											$retourliste = FALSE;
											break;
										}
										sleep($smtp_pausem);
									}
								}
								else
								{
									mysql_close($conn);
									mysql_free_result($rs);
								}
							}
						}
						else
						{
							$msg = "Vous n'avez choisi aucun sous-traitant.";
							$retourliste = FALSE;
							break;
						}
					}
					else
					{
						$msg = "Vous n'avez choisi aucun type de destinataire.";
						$retourliste = FALSE;
						break;
					}
				}
				else
				{
					$msg = "Le texte de votre email est vide.";
					$retourliste = FALSE;
					break;
				}
			}
		}


		break;

	case "tec" :
	case "tecd" :
	case "tecs" :
		$titre = "EMAILING TECHNICIENS";

		if ($initall==TRUE)
		{
			switch(@$_SESSION["niv_log"])
			{
				case 4 :
					$age = $age_code;
					$pays = $age_codepays;
					break;
				case 6 :
					$age = $do_code;
					$pays = $do_codepays;
					break;
				case 10 :
					$age = $st_code;
					$pays = $st_codepays;
					break;
				default :
					$age = "";
					$pays = "";
					break;
			}
			$dep = "";
			$sujet = "";
			$txt = "Merci de saisir le texte de votre email";
		}

		if (($validp==TRUE) OR ($exped==TRUE))
		{
			$age = strip_tags(trim(@$_POST["age"]));
			$pays = @$_POST["pays"];
			$dep = @$_POST["deptxt"];
			$sujet = strip_tags(trim(stripslashes(@$_POST["sujet"])));
			$txt = stripslashes($_POST['FCKeditor1']);

			if ($exped==TRUE)
			{
				if ($txt <> "") // Le texte envoyé doit exister
				{
					if (count($_POST["tec_choisi"]) <> 0) // Il doit y avoir au moins un technicien de choisi
					{
						for ($i = 0; $i < count($_POST["tec_choisi"]); $i++)
						{
							$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
							mysql_select_db(DBNAME);
		
							$rech = "SELECT * FROM `" .TBTEC. "` WHERE `tec_id`= '".$_POST["tec_choisi"][$i]."'";
							$rs = mysql_query($rech) or die(mysql_error());
							if (mysql_num_rows($rs) == 1) // Il ne peut y avoir qu'un seul résultat
							{
								if ($row = mysql_fetch_array($rs))
								{
									extract ($row);
									$email_envoye = envoi_emailing($td,"",$tec_code,$typeexp,(@$_SESSION["code_log"]),$txt,$sujet);
									if ($email_envoye == false)
									{
										$msg = "Problème lors de l'envoi de l'emailing.";
										$retourliste = FALSE;
										break;
									}
									sleep($smtp_pausem);
								}
							}
							else
							{
								mysql_close($conn);
								mysql_free_result($rs);
							}
						}
					}
					else
					{
						$msg = "Vous n'avez choisi aucun technicien.";
						$retourliste = FALSE;
						break;
					}
				}
				else
				{
					$msg = "Le texte de votre email est vide.";
					$retourliste = FALSE;
					break;
				}
			}
		}
		break;
	default :
		$email_ok = FALSE;
		break;
}

function verif_choix_dest($choix)
{
	for ($i = 0; $i < count($_POST["type_dest"]); $i++)
		if($choix == $_POST["type_dest"][$i])
			 return true;
}

function verif_choix_age($choix)
{
	for ($i = 0; $i < count($_POST["age_choisie"]); $i++)
		if($choix == $_POST["age_choisie"][$i])
			 return true;
}

function verif_choix_do($choix)
{
	for ($i = 0; $i < count($_POST["do_choisi"]); $i++)
		if($choix == $_POST["do_choisi"][$i])
			 return true;
}

function verif_choix_st($choix)
{
	for ($i = 0; $i < count($_POST["st_choisi"]); $i++)
		if($choix == $_POST["st_choisi"][$i])
			 return true;
}

function verif_choix_cli($choix)
{
	for ($i = 0; $i < count($_POST["cli_choisi"]); $i++)
		if($choix == $_POST["cli_choisi"][$i])
			 return true;
}

function verif_choix_ope($choix)
{
	for ($i = 0; $i < count($_POST["ope_choisi"]); $i++)
		if($choix == $_POST["ope_choisi"][$i])
			 return true;
}

function verif_choix_tec($choix)
{
	for ($i = 0; $i < count($_POST["tec_choisi"]); $i++)
		if($choix == $_POST["tec_choisi"][$i])
			 return true;
}
?>	
<!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; ?> : Emailing</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 pour vérifications des champs -->
<script language="JavaScript" src="../jscript/verif_field.js"></script>

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

<!-- Scripts Ajax -->
<script type="text/javascript" src="../ajax/util.js"></script>
<script type="text/javascript" src="../ajax/SelectUpdater.js"></script>

<?PHP if (($email_ok==TRUE) AND ($validp==FALSE)) { ?>
<script type="text/javascript">
<!--
<?PHP if ($td == "age") { ?>
function updateDep()
{
	depUpdater = new SelectUpdater("dep", "<?PHP echo $rep_appli.'/ajax/'; ?>recupdep2.php?pays=", "attn1", "msg1", "<?PHP echo $msg1_err_type; ?>");
	ZCUpdater = new SelectUpdater("zone", "<?PHP echo $rep_appli.'/ajax/'; ?>recupdepzc.php?pays=", "attn2", "msg2", "<?PHP echo $msg2_err_type; ?>");
	anciencodepays = "";
	anciendep = "";
	document.getElementById("pays").onchange = function() {
		var listepays = document.getElementById("pays");
		var codepays = listepays.options[listepays.selectedIndex].value;
		if (codepays.length > 0)
		{
			if (codepays != anciencodepays)
			{
				// Faire l'appel Ajax
				depUpdater.run(codepays);
				ZCUpdater.run(codepays);
				anciencodepays = codepays;
			}
		}
		else
		{
			// Remettre la liste a vide et annuler l'appel eventuel
			depUpdater.reset();
			ZCUpdater.reset();
			anciencodepays = "";
		}
	}
}
<?PHP }

if ($td == "st") { ?>
function updateDep()
{
	depUpdater = new SelectUpdater("dep", "<?PHP echo $rep_appli.'/ajax/'; ?>recupdep2.php?pays=", "attn1", "msg1", "<?PHP echo $msg1_err_type; ?>");
	ZCUpdater = new SelectUpdater("zone", "<?PHP echo $rep_appli.'/ajax/'; ?>recupdepzc2.php?pays=", "attn2", "msg2", "<?PHP echo $msg2_err_type; ?>");
	anciencodepays = "";
	anciendep = "";
	document.getElementById("pays").onchange = function() {
		var listepays = document.getElementById("pays");
		var codepays = listepays.options[listepays.selectedIndex].value;
		if (codepays.length > 0)
		{
			if (codepays != anciencodepays)
			{
				// Faire l'appel Ajax
				depUpdater.run(codepays);
				ZCUpdater.run(codepays);
				anciencodepays = codepays;
			}
		}
		else
		{
			// Remettre la liste a vide et annuler l'appel eventuel
			depUpdater.reset();
			ZCUpdater.reset();
			anciencodepays = "";
		}
	}
}
<?PHP }

if (($td == "cli") AND ($typeexp<>"do")) { ?>
function updateDep()
{
	depUpdater = new SelectUpdater("dep", "<?PHP echo $rep_appli.'/ajax/'; ?>recupdep2.php?pays=", "attn1", "msg1", "<?PHP echo $msg1_err_type; ?>");
	ageUpdater = new SelectUpdater("age", "<?PHP echo $rep_appli.'/ajax/'; ?>recupage.php?pays=", "attn3", "msg3", "<?PHP echo $msg3_err_type; ?>");
	anciencodepays = "";
	anciendep = "";
	document.getElementById("pays").onchange = function() {
		var listepays = document.getElementById("pays");
		var codepays = listepays.options[listepays.selectedIndex].value;
		if (codepays.length > 0)
		{
			if (codepays != anciencodepays)
			{
				// Faire l'appel Ajax
				depUpdater.run(codepays);
				ageUpdater.run(codepays);
				anciencodepays = codepays;
			}
		}
		else
		{
			// Remettre la liste a vide et annuler l'appel eventuel
			depUpdater.reset();
			ageUpdater.reset();
			var txthtml = "<option><?PHP echo $sel_lst_makechx; ?></option>\n";
			document.getElementById("dep").innerHTML=txthtml;
			document.getElementById("attn1").innerHTML = "";
			document.getElementById("msg1").innerHTML = "";
			var txthtml = "<option><?PHP echo $sel_lst_makechx; ?></option>\n";
			document.getElementById("age").innerHTML=txthtml;
			document.getElementById("attn3").innerHTML = "";
			document.getElementById("msg3").innerHTML = "";
			anciencodepays = "";
		}
	}
}
<?PHP }

if (($td=="tec") OR ($td=="tecd") OR ($td=="tecs") OR ($td=="ope") OR ($td=="do")) {
?>
function updateDep()
{
	depUpdater = new SelectUpdater("dep", "<?PHP echo $rep_appli.'/ajax/'; ?>recupdep2.php?pays=", "attn1", "msg1", "<?PHP echo $msg1_err_type; ?>");
	anciencodepays = "";
	anciendep = "";
	document.getElementById("pays").onchange = function() {
		var listepays = document.getElementById("pays");
		var codepays = listepays.options[listepays.selectedIndex].value;
		if (codepays.length > 0)
		{
			if (codepays != anciencodepays)
			{
				// Faire l'appel Ajax
				depUpdater.run(codepays);
				anciencodepays = codepays;
			}
		}
		else
		{
			// Remettre la liste a vide et annuler l'appel eventuel
			depUpdater.reset();
			var txthtml = "<option><?PHP echo $sel_lst_makechx; ?></option>\n";
			document.getElementById("dep").innerHTML=txthtml;
			document.getElementById("attn1").innerHTML = "";
			document.getElementById("msg1").innerHTML = "";
			anciencodepays = "";
		}
	}
}
<?PHP } ?>
//-->
</script>
<?PHP } ?>

</head>
<?PHP 
if ($validp==FALSE) {
	if ((@$_SESSION["niv_log"]<>4) AND (@$_SESSION["niv_log"]<>6)AND (@$_SESSION["niv_log"]<>10))
	{
?>
	<body onLoad="metFocus();updateDep();">
<?PHP 
	} else {
?>
	<body onLoad="metFocus();">
<?PHP
	}
} else { 
?>
<body>
<?PHP }
include_once("../inc/entete.inc.php"); 
?>
<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<p>&nbsp;</p>
<?PHP
if ($email_ok == TRUE)
{
	if ($email_envoye == FALSE)
	{
	if ($retourliste == FALSE)
	{
?>
		<script type="text/javascript">
		<!--
		alert ("<?PHP echo $msg; ?>");
		//-->
		</script>
<?PHP
	}

	$url_link = "email_maj.php?td=".$td;
	
	switch ($td)
	{
	/******************************************************/
	/**                    AGENCES                       **/
	/******************************************************/

	case "age" :
		if ($validp==FALSE)
		{
?>
		<!-- Scripts Javascript pour contrôle de formulaire -->
		<script	type="text/javascript" src="../jscript/vform/vform.js"></script>
		
		<script language="javascript">
<!--
		var tab1_champ=new Array(
			"nom:cat ; format:liste ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_cat); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
			"nom:pays ; format:liste ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_pays); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
			"nom:dep[] ; format:listem ; req:Y ; txt:Départements ; vmn:1 ; stok:frmok ; stbad:frmbad",
			"nom:zone[] ; format:listem ; req:N ; txt:Départements zone de chalandise; stok:frmok ; stbad:frmbad",
			"nom:sujet ; format:txt ; req:Y ; txt:Sujet ; lmx:50 ; stok:frmok ; stbad:frmbad");
		//-->
		</script>
		
		<!-- Formulaire permettant la sélection des destinataires et l'envoi -->
		<form name="email_maj" id="email_maj" method="post" action="email_maj.php" onSubmit="javascript:; return (VForm(this,tab1_champ,'','<?PHP echo $_SESSION["lng"]; ?>'));">
		<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
		<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
		
		<!-- Liste des catégories -->
		<table width="100%"  border="0">
		<tr>
		  <td width="160" class="rubfrm" id="f_cat" align="right">Cat&eacute;gorie</td>
		  <td>
				<select name="cat" size="1" id="cat">
				<?PHP
				echo "<option>-- Choisissez une catégorie --</option>";
				
				echo "<option value=\"*\"";
				if ($cat == "*")
					echo " selected";
				echo ">-- TOUTES LES CATEGORIES --</option>";
	
				// Création de la liste des catégories
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
				$rs = mysql_query("SELECT * FROM ".TBACAT." ORDER BY acat_desc");
				
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
		
					if ($cat == $acat_code)
					{
						echo '<option value="'.$acat_code.'" selected>'.$acat_desc.'</option>';
					}
					else
					{
						echo '<option value="'.$acat_code.'">'.$acat_desc.'</option>';
					}
				}
				mysql_free_result($rs);
				mysql_close($conn);
				?>
				</select>
				  <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
				<br>
				<span class="annot_petit_it">(Ne s'afficheront que les agences actives)</span>
			</td>
		</tr>
		<tr>
			<td class="rubfrm" id="f_pays" align="right"><?PHP echo $txt_chp_pays; ?></td>
			<td>
			<?PHP
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rs = mysql_query("SELECT * FROM ".TBPAYS." ORDER BY pays_nom");
			?>			
				<select name="pays" id="pays">
			<?PHP
				echo "<option value=\"\">".$sel_lst_pays."</option>";
		
				// Création de la liste des pays
				
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
					if ($pays==$pays_code)
						echo '<option value="'.$pays_code.'" selected>'.$pays_nom.'</option>';
					else
						echo '<option value="'.$pays_code.'">'.$pays_nom.'</option>';
				}
			?>
				</select>
				<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			<?PHP
			mysql_free_result($rs);
			mysql_close($conn);
			?>
			</td>
		</tr>
		<tr>
		<td class="rubfrm" id="f_dep" align="right"><?PHP echo $txt_chp_dep; ?></td>
		<td>
		<select name="dep[]" size="5" id="dep" multiple="multiple" onChange="utxtfromselm(this.id,'deptxt');">
		<option><?PHP echo $sel_lst_makechx; ?></option>
		<?PHP
		// Création de la liste des départements
		$nbdep=0;
		
		if ($pays<>"")
		{		
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBDEP." WHERE dep_codepays='".str_majuscules($pays)."' ORDER BY dep_code";
			$rs = mysql_query($rech) or die(mysql_error());
			$nbdep=mysql_num_rows($rs);

			if ($nbdep>0)
			{		
				$tab_dep=explode("_",$dep);
				while ($row = mysql_fetch_array($rs)) 
				{
					extract($row);
					$chaine_dep = $dep_code." (".$dep_nom.")";
					if (in_array($dep_code,$tab_dep))
						echo "<option value=\"".$dep_code."\" selected>".$chaine_dep."</option>";
					else
						echo "<option value=\"".$dep_code."\">".$chaine_dep."</option>";
				}
			}
			mysql_free_result($rs);
			mysql_close($conn);
		}
		?>
		</select>
		 <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			<span class="annot_petit_it">
			(S&eacute;lectionnez avec Ctrl + clic gauche)
		 <br><span id="attn1"></span><span id="msg1" class="ptitre_std_gras_jaune_frouge"><?PHP if ($nbdep==0) echo htmlspecialchars($msg1_err_type)?></span>
			<input name="deptxt" type="hidden" id="deptxt" value="<?PHP echo $dep ?>" size="50" readonly="1">
			</span>
		</td>
		</tr>
		<tr>
		<td class="rubfrm" id="f_zone" align="right">Zone de chalandise</td>
		<td>
		<select name="zone[]" size="5" id="zone" multiple="multiple" onChange="utxtfromselm(this.id,'zonetxt');">
		<option><?PHP echo $sel_lst_makechx; ?></option>
		<?PHP
		// Création de la liste des zones couvertes
		$nbzone=0;
		
		if ($pays<>"")
		{		
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBZCC.", ".TBDEP;
			$rech.= " WHERE ".TBZCC.".zcc_codepays='".str_majuscules($pays)."' AND ".TBZCC.".zcc_codedep=".TBDEP.".dep_code ORDER BY ".TBDEP.".dep_code";
			$rs = mysql_query($rech) or die(mysql_error());
			$nbzone=mysql_num_rows($rs);

			if ($nbzone>0)
			{		
				$tab_zone=explode("_",$zone);
				while ($row = mysql_fetch_array($rs)) 
				{
					extract($row);
					// On recupere les enregistrements
					$rech2 = "SELECT dep_nom FROM ".TBDEP." WHERE dep_code='".$zcc_codedep."' AND dep_codepays='".$pays."'";
					$rs2 = mysql_query($rech2) or die(mysql_error());
					if ($row2 = mysql_fetch_array($rs2))
					{
						extract($row2);
						$chaine_dep = $dep_code." (".$dep_nom.")";
						if (in_array($dep_code,$tab_zone))
							echo "<option value=\"".$dep_code."\" selected>".$chaine_dep."</option>";
						else
							echo "<option value=\"".$dep_code."\">".$chaine_dep."</option>";
					}
				}
			}
			mysql_free_result($rs);
			mysql_close($conn);
		}
		?>
		</select>
			<span class="annot_petit_it">
			(S&eacute;lectionnez avec Ctrl + clic gauche)
		 <br><span id="attn2"></span><span id="msg2" class="ptitre_std_gras_jaune_frouge"><?PHP if ($nbzone==0) echo htmlspecialchars($msg2_err_type)?></span>
			<input name="zonetxt" type="hidden" id="zonetxt" value="<?PHP echo $zone ?>" size="50" readonly="1">
			</span>
		</tr>
		<tr>
		<td width="160" class="rubfrm" id="f_sujet" align="right">Sujet du message</td>
		<td>
			<input name="sujet" type="text" id="sujet" size="50" maxlength="50" value="<?PHP echo $sujet; ?>">
				  <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		</td>
		</tr>
		<tr>
		<td width="160" class="rubfrm" id="f_sujet" align="right">Inclus comptes verrouill&eacute;s ?</td>
		<td>
			<input type="radio" name="cv" style="background : #FFFFFF;" value="O" <?PHP if ($cv=="O") echo 'checked="checked"'?>> Oui / 
			<input type="radio" name="cv" style="background : #FFFFFF;" value="N" <?PHP if ($cv=="N") echo 'checked="checked"'?>> Non
		</td>
		</tr>
		<tr>
		<td colspan="2" align="center">
			 <input name="OK" type="submit" class="bton_std" id="OK" value="<?PHP echo $but_valprm; ?>">
		</td>
		</tr>
		</table>
		</form>
<?PHP
		} else {
?>		
		<form name="email_maj" id="email_maj" method="post" action="email_maj.php">
		<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
		<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
		<input name="cat" type="hidden" id="cat" value="<?PHP echo $cat; ?>">
		<input name="pays" type="hidden" id="pays" value="<?PHP echo $pays; ?>">
		<input name="deptxt" type="hidden" id="deptxt" value="<?PHP echo $dep; ?>">
		<input name="zonetxt" type="hidden" id="deptxt" value="<?PHP echo $zone; ?>">
		<input name="sujet" type="hidden" id="sujet" value="<?PHP echo $sujet; ?>">
		<input name="cv" type="hidden" id="cv" value="<?PHP echo $cv; ?>">
		<p align="center" class="titre_gras_soul">Listes des agences s&eacute;lectionn&eacute;es</p>
<?PHP
		// *** Affichage de la table
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech = "SELECT * FROM " .TBAGE;
		if ($cv=="N")
			$rech.=", ".TBPW;
		if ($cat <> "*")
			 $rech.=" WHERE ".TBAGE.".age_cat = '".$cat."' AND ".TBAGE.".age_ouvert = '1'";
		else
			$rech.= " WHERE ".TBAGE.".age_ouvert = '1'";
		if ($dep <> "") 
		{
			$tab_dep = explode("_",$dep);
			
			$rech .= " AND (";
				
			foreach($tab_dep as $idx=>$value)
			{
				$rech .= TBAGE.".age_dep ='".$value."' OR ";
			}
			$rech = substr($rech,0,strlen($rech)-4);
			$rech .= ")";
		}
		if ($cv=="N")
		{
			$rech.=" AND ".TBAGE.".age_code=".TBPW.".pw_code";
			$rech.=" AND ".TBPW.".pw_actif='1'";
		}
		$rs = mysql_query($rech) or die(mysql_error());
		$nbsel=	mysql_num_rows($rs);
		if ($nbsel >0)
		{
?>
			<table width="100%"  border="0">
			<tr>
				<td class="annot_std_gras" id="f_dest" valign="bottom" align="right">Services destinataires : </td>
				<td>
					G&eacute;n&eacute;ral : 
					<input type="checkbox" name="type_dest[]" style="background : #FFFFFF;" <?PHP if(verif_choix_dest("1")) echo 'checked="checked"'; ?> value="1">
					
					Direction : 
					<input type="checkbox" name="type_dest[]" style="background : #FFFFFF;" <?PHP if(verif_choix_dest("2")) echo 'checked="checked"'; ?> value="2">
					
					Comptabilit&eacute; : 
					<input type="checkbox" name="type_dest[]" style="background : #FFFFFF;" <?PHP if(verif_choix_dest("3")) echo 'checked="checked"'; ?> value="3">

					Technique : 
					<input type="checkbox" name="type_dest[]" style="background : #FFFFFF;" <?PHP if(verif_choix_dest("4")) echo 'checked="checked"'; ?> value="4">
				  <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
				</td>
			</tr>
			</table>
<?PHP
			echo "<p align=\"center\">";
			echo "<input type=\"button\" name=\"sel\" id=\"sel\" value=\"Tous\" class=\"bton_fgris_petit\" onclick=\"this.value=checkall(this.value,this.form);\">";
			echo "</p>";

			echo "<div id=\"Layer1\" class=\"lst_fen\">";
			
			// Définition et entête de la table
			echo "<table class=\"Mtable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";

			echo "<th>";
			echo "Code";
			echo "</th>\n";
			echo "<th>";
			echo "Nom";
			echo "</th>\n";
			echo "<th>";
			echo "Téléphone";
			echo "</th>\n";
			echo "<th>";
			echo "CP";
			echo "</th>\n";
			echo "<th>";
			echo "Choisir";
			echo "</th>\n";
	
			$i = 0;
			$tab_zone = explode("_",$zone);
	
			while ($row = mysql_fetch_assoc($rs)) 
			{
				if ($zone <> "") 
				{
					$aff_ligne = FALSE; // On part du principe que l'agence n'est pas dans la zone recherchée
					foreach($tab_zone as $idx=>$value)
					{
						if (dep_in_zcc_age_open($value,$row["age_codepays"],$row["age_code"],FALSE)==TRUE)
							$aff_ligne = TRUE; // On a trouvé une correspondance, on valide l'affichage
					}
				}
				else
					$aff_ligne = TRUE;	

				if ($aff_ligne == TRUE)
				{
					// Création de l'entête de ligne (TR)
					creetrlst($i);
	
					echo "<td>".$row["age_code"];
					echo "</td>\n";
					echo "<td>".$row["age_nom"]."</td>\n";
					echo "<td>".$row["age_telf"]."</td>\n";
					echo "<td>".Retournecp_openId($row["age_ville"],FALSE)."</td>\n";
					echo "<td align=\"center\">\n";
					if (strip_tags(trim(@$_POST["OK"])) == html_entity_decode($but_rech)) // On vient de demander une recherche : on active pas défaut
					{
						echo "<input type=\"checkbox\" name=\"age_choisie[]\" value=\"".$row["age_id"]."\"";
						if($i%2 == 0)
							echo " style=\"background : #32CD32;\"";
						else
							echo " style=\"background : #00FF00;\"";
						echo" checked>";
					}
					else // Sinon on reprend en fonction de ce qui a été coché
					{
						echo "<input type=\"checkbox\" name=\"age_choisie[]\"";
						if(verif_choix_age($row["age_id"])) 
							echo "checked ";
						if($i%2 == 0)
							echo " style=\"background : #32CD32;\"";
						else
							echo " style=\"background : #00FF00;\"";
						echo "value=\"".$row["age_id"]."\">";
					}
					echo "</td>\n";
					echo "</tr>\n";
					
					$i++;
				}
			}  
			echo "</table>\n";
			// *** Fin affichage de la table

			echo "</div>";
?>
		<!-- Message à envoyer-->
		<table width="100%"  border="0">
		<tr>
			<td align="center">
			<span class="titre_gras_soul">Message &agrave; envoyer
			 <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			</span>
			<span class="annot_std_it"><br>(Sujet : <?PHP echo $sujet; ?>)</span>
			</td>
		</tr>
		<tr>
			<td>
			<?PHP
				$sBasePath = $_SERVER['PHP_SELF'] ;
				$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "admin" ) ).'classes/fckeditor/' ;
			
				$oFCKeditor = new FCKeditor('FCKeditor1') ;
				$oFCKeditor->BasePath	= $sBasePath;
				$oFCKeditor->Value		= $txt;
				$oFCKeditor->Height 	= '400';
				$oFCKeditor->ToolbarSet = 'SMI';
				$oFCKeditor->Create();
			
			?>
		 </td>
		 </tr>
		 </table>
<?PHP
		}
		else
		{
			echo "Aucune agence sur ces crit&egrave;res.";
		}
?>
		<p align="center">
		<?PHP if ($nbsel>0) { ?>
		<input name="envoi" type="submit" class="bton_std" id="envoi" value="<?PHP echo $but_exped; ?>">
		 <input name="RAZ" type="button" class="bton_std" id="RAZ" value="<?PHP echo $but_reinit; ?>" onClick="document.getElementById('sel').value=uncheckall(this.form);">
		<?PHP } ?>
		 <input name="init" type="button" class="bton_std" id="init" value="<?PHP echo $but_recomm; ?>" onClick="javascript:; self.location.href=('<?PHP echo $url_link; ?>');">
		 </p>
		</form>
		<!-- Fin du formulaire -->
<?PHP
		}
		break;

	/******************************************************/
	/**                SOUS-TRAITANTS                    **/
	/******************************************************/

	case "st" :
		if ($validp==FALSE)
		{
?>
		<!-- Scripts Javascript pour contrôle de formulaire -->
		<script	type="text/javascript" src="../jscript/vform/vform.js"></script>
		
		<script language="javascript">
<!--
		var tab1_champ=new Array(
			"nom:cat ; format:liste ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_cat); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
			"nom:pays ; format:liste ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_pays); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
			"nom:dep[] ; format:listem ; req:Y ; txt:Départements ; vmn:1 ; stok:frmok ; stbad:frmbad",
			"nom:zone[] ; format:listem ; req:N ; txt:Départements zone de chalandise; stok:frmok ; stbad:frmbad",
			"nom:sujet ; format:txt ; req:Y ; txt:Sujet ; lmx:50 ; stok:frmok ; stbad:frmbad");
		//-->
		</script>
		
		<!-- Formulaire permettant la sélection des destinataires et l'envoi -->
		<form name="email_maj" id="email_maj" method="post" action="email_maj.php" onSubmit="javascript:; return (VForm(this,tab1_champ,'','<?PHP echo $_SESSION["lng"]; ?>'));">
		<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
		<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
		
		<!-- Liste des spécialités -->
		<table width="100%"  border="0">
		<tr>
		  <td width="160" class="rubfrm" id="f_cat" align="right">Sp&eacute;cialit&eacute;</td>
		  <td>
				<select name="cat" size="1" id="cat">
				<?PHP
				echo "<option>-- Choisissez une spécialité --</option>";
				
				echo "<option value=\"*\"";
				if ($cat == "*")
					echo " selected";
				echo ">-- TOUTES LES SPECIALITES --</option>";
	
				// Création de la liste des catégories
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
				$rs = mysql_query("SELECT * FROM ".TBSP." ORDER BY sp_desc");
				
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
		
					if ($cat == $sp_code)
					{
						echo '<option value="'.$so_code.'" selected>'.$sp_desc.'</option>';
					}
					else
					{
						echo '<option value="'.$sp_code.'">'.$sp_desc.'</option>';
					}
				}
				mysql_free_result($rs);
				mysql_close($conn);
				?>
				</select>
				  <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
				<br>
				<span class="annot_petit_it">(Ne s'afficheront que les sous-traitants actifs)</span>
			</td>
		</tr>
		<tr>
			<td class="rubfrm" id="f_pays" align="right"><?PHP echo $txt_chp_pays; ?></td>
			<td>
			<?PHP
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rs = mysql_query("SELECT * FROM ".TBPAYS." ORDER BY pays_nom");
			?>			
				<select name="pays" id="pays">
			<?PHP
				echo "<option value=\"\">".$sel_lst_pays."</option>";
		
				// Création de la liste des pays
				
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
					if ($pays==$pays_code)
						echo '<option value="'.$pays_code.'" selected>'.$pays_nom.'</option>';
					else
						echo '<option value="'.$pays_code.'">'.$pays_nom.'</option>';
				}
			?>
				</select>
				<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			<?PHP
			mysql_free_result($rs);
			mysql_close($conn);
			?>
			</td>
		</tr>
		<tr>
		<td class="rubfrm" id="f_dep" align="right"><?PHP echo $txt_chp_dep; ?></td>
		<td>
		<select name="dep[]" size="5" id="dep" multiple="multiple" onChange="utxtfromselm(this.id,'deptxt');">
		<option><?PHP echo $sel_lst_makechx; ?></option>
		<?PHP
		// Création de la liste des départements
		$nbdep=0;
		
		if ($pays<>"")
		{		
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBDEP." WHERE dep_codepays='".str_majuscules($pays)."' ORDER BY dep_code";
			$rs = mysql_query($rech) or die(mysql_error());
			$nbdep=mysql_num_rows($rs);

			if ($nbdep>0)
			{		
				$tab_dep=explode("_",$dep);
				while ($row = mysql_fetch_array($rs)) 
				{
					extract($row);
					$chaine_dep = $dep_code." (".$dep_nom.")";
					if (in_array($dep_code,$tab_dep))
						echo "<option value=\"".$dep_code."\" selected>".$chaine_dep."</option>";
					else
						echo "<option value=\"".$dep_code."\">".$chaine_dep."</option>";
				}
			}
			mysql_free_result($rs);
			mysql_close($conn);
		}
		?>
		</select>
		 <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			<span class="annot_petit_it">
			(S&eacute;lectionnez avec Ctrl + clic gauche)
		 <br><span id="attn1"></span><span id="msg1" class="ptitre_std_gras_jaune_frouge"><?PHP if ($nbdep==0) echo htmlspecialchars($msg1_err_type)?></span>
			<input name="deptxt" type="hidden" id="deptxt" value="<?PHP echo $dep ?>" size="50" readonly="1">
			</span>
		</td>
		</tr>
		<tr>
		<td class="rubfrm" id="f_zone" align="right">Zone de chalandise</td>
		<td>
		<select name="zone[]" size="5" id="zone" multiple="multiple" onChange="utxtfromselm(this.id,'zonetxt');">
		<option><?PHP echo $sel_lst_makechx; ?></option>
		<?PHP
		// Création de la liste des zones couvertes
		$nbzone=0;
		
		if ($pays<>"")
		{		
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBZOC.", ".TBDEP;
			$rech.= " WHERE ".TBZOC.".zoc_codepays='".str_majuscules($pays)."' AND ".TBZOC.".zoc_codedep=".TBDEP.".dep_code ORDER BY ".TBDEP.".dep_code";
			$rs = mysql_query($rech) or die(mysql_error());
			$nbzone=mysql_num_rows($rs);

			if ($nbzone>0)
			{		
				$tab_zone=explode("_",$zone);
				while ($row = mysql_fetch_array($rs)) 
				{
					extract($row);
					// On recupere les enregistrements
					$rech2 = "SELECT dep_nom FROM ".TBDEP." WHERE dep_code='".$zoc_codedep."' AND dep_codepays='".$pays."'";
					$rs2 = mysql_query($rech2) or die(mysql_error());
					if ($row2 = mysql_fetch_array($rs2))
					{
						extract($row2);
						$chaine_dep = $dep_code." (".$dep_nom.")";
						if (in_array($dep_code,$tab_zone))
							echo "<option value=\"".$dep_code."\" selected>".$chaine_dep."</option>";
						else
							echo "<option value=\"".$dep_code."\">".$chaine_dep."</option>";
					}
				}
			}
			mysql_free_result($rs);
			mysql_close($conn);
		}
		?>
		</select>
			<span class="annot_petit_it">
			(S&eacute;lectionnez avec Ctrl + clic gauche)
		 <br><span id="attn2"></span><span id="msg2" class="ptitre_std_gras_jaune_frouge"><?PHP if ($nbzone==0) echo htmlspecialchars($msg2_err_type)?></span>
			<input name="zonetxt" type="hidden" id="zonetxt" value="<?PHP echo $zone ?>" size="50" readonly="1">
			</span>
		</tr>
		<tr>
		<td width="160" class="rubfrm" id="f_sujet" align="right">Sujet du message</td>
		<td>
			<input name="sujet" type="text" id="sujet" size="50" maxlength="50" value="<?PHP echo $sujet; ?>">
				  <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		</td>
		</tr>
		<tr>
		<td width="160" class="rubfrm" id="f_sujet" align="right">Inclus comptes verrouill&eacute;s ?</td>
		<td>
			<input type="radio" name="cv" style="background : #FFFFFF;" value="O" <?PHP if ($cv=="O") echo 'checked="checked"'?>> Oui / 
			<input type="radio" name="cv" style="background : #FFFFFF;" value="N" <?PHP if ($cv=="N") echo 'checked="checked"'?>> Non
		</td>
		</tr>
		<tr>
		<td colspan="2" align="center">
			 <input name="OK" type="submit" class="bton_std" id="OK" value="<?PHP echo $but_valprm; ?>">
		</td>
		</tr>
		</table>
		</form>
<?PHP
		} else {
?>		
		<form name="email_maj" id="email_maj" method="post" action="email_maj.php">
		<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
		<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
		<input name="cat" type="hidden" id="cat" value="<?PHP echo $cat; ?>">
		<input name="pays" type="hidden" id="pays" value="<?PHP echo $pays; ?>">
		<input name="deptxt" type="hidden" id="deptxt" value="<?PHP echo $dep; ?>">
		<input name="zonetxt" type="hidden" id="deptxt" value="<?PHP echo $zone; ?>">
		<input name="sujet" type="hidden" id="sujet" value="<?PHP echo $sujet; ?>">
		<input name="cv" type="hidden" id="cv" value="<?PHP echo $cv; ?>">
		<p align="center" class="titre_gras_soul">Listes des sous-traitants s&eacute;lectionn&eacute;s</p>
<?PHP
		// *** Affichage de la table
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech = "SELECT * FROM " .TBST;
		if ($cv=="N")
			$rech.=", ".TBPW;
		if ($cat <> "*")
			 $rech.=" WHERE ".TBST.".st_spe = '".$cat."' AND ".TBST.".st_ouvert = '1'";
		else
			$rech.= " WHERE ".TBST.".st_ouvert = '1'";
		if ($dep <> "") 
		{
			$tab_dep = explode("_",$dep);
			
			$rech .= " AND (";
				
			foreach($tab_dep as $idx=>$value)
			{
				$rech .= TBST.".st_dep ='".$value."' OR ";
			}
			$rech = substr($rech,0,strlen($rech)-4);
			$rech .= ")";
		}
		if ($cv=="N")
		{
			$rech.=" AND ".TBST.".st_code=".TBPW.".pw_code";
			$rech.=" AND ".TBPW.".pw_actif='1'";
		}
		$rs = mysql_query($rech) or die(mysql_error());
		$nbsel=	mysql_num_rows($rs);
		if ($nbsel >0)
		{
?>
			<table width="100%"  border="0">
			<tr>
				<td class="annot_std_gras" id="f_dest" valign="bottom" align="right">Services destinataires : </td>
				<td>
					G&eacute;n&eacute;ral : 
					<input type="checkbox" name="type_dest[]" style="background : #FFFFFF;" <?PHP if(verif_choix_dest("1")) echo 'checked="checked"'; ?> value="1">
					
					Direction : 
					<input type="checkbox" name="type_dest[]" style="background : #FFFFFF;" <?PHP if(verif_choix_dest("2")) echo 'checked="checked"'; ?> value="2">
					
					Comptabilit&eacute; : 
					<input type="checkbox" name="type_dest[]" style="background : #FFFFFF;" <?PHP if(verif_choix_dest("3")) echo 'checked="checked"'; ?> value="3">

					Technique : 
					<input type="checkbox" name="type_dest[]" style="background : #FFFFFF;" <?PHP if(verif_choix_dest("4")) echo 'checked="checked"'; ?> value="4">
				  <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
				</td>
			</tr>
			</table>
<?PHP
			echo "<p align=\"center\">";
			echo "<input type=\"button\" name=\"sel\" id=\"sel\" value=\"Tous\" class=\"bton_fgris_petit\" onclick=\"this.value=checkall(this.value,this.form);\">";
			echo "</p>";

			echo "<div id=\"Layer1\" class=\"lst_fen\">";
			
			// Définition et entête de la table
			echo "<table class=\"Mtable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";

			echo "<th>";
			echo "Code";
			echo "</th>\n";
			echo "<th>";
			echo "Nom";
			echo "</th>\n";
			echo "<th>";
			echo "Téléphone";
			echo "</th>\n";
			echo "<th>";
			echo "CP";
			echo "</th>\n";
			echo "<th>";
			echo "Zone Chalandise";
			echo "</th>\n";
			echo "<th>";
			echo "Choisir";
			echo "</th>\n";
	
			$i = 0;
			$tab_zone = explode("_",$zone);
	
			while ($row = mysql_fetch_assoc($rs)) 
			{
				if ($zone <> "") 
				{
					$aff_ligne = FALSE; // On part du principe que l'agence n'est pas dans la zone recherchée
					foreach($tab_zone as $idx=>$value)
					{
						if (dep_in_zoc_st_open($value,$row["st_codepays"],$row["st_code"],FALSE)==TRUE)
							$aff_ligne = TRUE; // On a trouvé une correspondance, on valide l'affichage
					}
				}
				else
					$aff_ligne = TRUE;	

				if ($aff_ligne == TRUE)
				{
					// Création de l'entête de ligne (TR)
					creetrlst($i);
	
					echo "<td>".$row["st_code"];
					echo "</td>\n";
					echo "<td>".$row["st_nom"]."</td>\n";
					echo "<td>".$row["st_telf"]."</td>\n";
					echo "<td>".Retournecp_openId($row["st_ville"],FALSE)."</td>\n";
					echo "<td>";
					$tab_zoneopen = tab_zoc_st_open($row["st_code"],FALSE);
					foreach ($tab_zoneopen as $idx=>$value)
					{
						$rech2 = "SELECT * FROM ".TBDEP." WHERE dep_code = '$value' AND dep_codepays = '".$row["st_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>0) echo "<br>";
								echo $dep_code." (".$dep_nom.")";
							}
						}
					}
					echo "</td>\n";
					echo "<td align=\"center\">\n";
					if (strip_tags(trim(@$_POST["OK"])) == html_entity_decode($but_rech)) // On vient de demander une recherche : on active pas défaut
					{
						echo "<input type=\"checkbox\" name=\"st_choisi[]\" value=\"".$row["st_id"]."\"";
						if($i%2 == 0)
							echo " style=\"background : #32CD32;\"";
						else
							echo " style=\"background : #00FF00;\"";
						echo" checked>";
					}
					else // Sinon on reprend en fonction de ce qui a été coché
					{
						echo "<input type=\"checkbox\" name=\"st_choisi[]\"";
						if(verif_choix_st($row["st_id"])) 
							echo "checked ";
						if($i%2 == 0)
							echo " style=\"background : #32CD32;\"";
						else
							echo " style=\"background : #00FF00;\"";
						echo "value=\"".$row["st_id"]."\">";
					}
					echo "</td>\n";
					echo "</tr>\n";
					
					$i++;
				}
			}  
			echo "</table>\n";
			// *** Fin affichage de la table

			echo "</div>";
?>
		<!-- Message à envoyer-->
		<table width="100%"  border="0">
		<tr>
			<td align="center">
			<span class="titre_gras_soul">Message &agrave; envoyer
			 <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			</span>
			<span class="annot_std_it"><br>(Sujet : <?PHP echo $sujet; ?>)</span>
			</td>
		</tr>
		<tr>
			<td>
			<?PHP
				$sBasePath = $_SERVER['PHP_SELF'] ;
				$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "admin" ) ).'classes/fckeditor/' ;
			
				$oFCKeditor = new FCKeditor('FCKeditor1') ;
				$oFCKeditor->BasePath	= $sBasePath;
				$oFCKeditor->Value		= $txt;
				$oFCKeditor->Height 	= '400';
				$oFCKeditor->ToolbarSet = 'SMI';
				$oFCKeditor->Create();
			
			?>
		 </td>
		 </tr>
		 </table>
<?PHP
		}
		else
		{
			echo "Aucun sous-traitant  sur ces crit&egrave;res.";
		}
?>
		<p align="center">
		<?PHP if ($nbsel>0) { ?>
		<input name="envoi" type="submit" class="bton_std" id="envoi" value="<?PHP echo $but_exped; ?>">
		 <input name="RAZ" type="button" class="bton_std" id="RAZ" value="<?PHP echo $but_reinit; ?>" onClick="document.getElementById('sel').value=uncheckall(this.form);">
		<?PHP } ?>
		 <input name="init" type="button" class="bton_std" id="init" value="<?PHP echo $but_recomm; ?>" onClick="javascript:; self.location.href=('<?PHP echo $url_link; ?>');">
		 </p>
		</form>
		<!-- Fin du formulaire -->
<?PHP
		}
		break;

	/******************************************************/
	/**               DONNEURS D'ORDRES                  **/
	/******************************************************/

	case "do" :
		if ($validp==FALSE)
		{
?>
		<!-- Scripts Javascript pour contrôle de formulaire -->
		<script	type="text/javascript" src="../jscript/vform/vform.js"></script>
		
		<script language="javascript">
<!--
		var tab1_champ=new Array(
			"nom:pays ; format:liste ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_pays); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
			"nom:dep[] ; format:listem ; req:Y ; txt:Départements ; vmn:1 ; stok:frmok ; stbad:frmbad",
			"nom:sujet ; format:txt ; req:Y ; txt:Sujet ; lmx:50 ; stok:frmok ; stbad:frmbad");
		//-->
		</script>
		
		<!-- Formulaire permettant la sélection des destinataires et l'envoi -->
		<form name="email_maj" id="email_maj" method="post" action="email_maj.php" onSubmit="javascript:; return (VForm(this,tab1_champ,'','<?PHP echo $_SESSION["lng"]; ?>'));">
		<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
		<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
		
		<!-- Liste des catégories -->
		<table width="100%"  border="0">
		<tr>
			<td class="rubfrm" id="f_pays" align="right"><?PHP echo $txt_chp_pays; ?></td>
			<td>
			<?PHP
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rs = mysql_query("SELECT * FROM ".TBPAYS." ORDER BY pays_nom");
			?>			
				<select name="pays" id="pays">
			<?PHP
				echo "<option value=\"\">".$sel_lst_pays."</option>";
		
				// Création de la liste des pays
				
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
					if ($pays==$pays_code)
						echo '<option value="'.$pays_code.'" selected>'.$pays_nom.'</option>';
					else
						echo '<option value="'.$pays_code.'">'.$pays_nom.'</option>';
				}
			?>
				</select>
				<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			<?PHP
			mysql_free_result($rs);
			mysql_close($conn);
			?>
			</td>
		</tr>
		<tr>
		<td class="rubfrm" id="f_dep" align="right"><?PHP echo $txt_chp_dep; ?></td>
		<td>
		<select name="dep[]" size="5" id="dep" multiple="multiple" onChange="utxtfromselm(this.id,'deptxt');">
		<option><?PHP echo $sel_lst_makechx; ?></option>
		<?PHP
		// Création de la liste des départements
		$nbdep=0;
		
		if ($pays<>"")
		{		
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBDEP." WHERE dep_codepays='".str_majuscules($pays)."' ORDER BY dep_code";
			$rs = mysql_query($rech) or die(mysql_error());
			$nbdep=mysql_num_rows($rs);

			if ($nbdep>0)
			{		
				$tab_dep=explode("_",$dep);
				while ($row = mysql_fetch_array($rs)) 
				{
					extract($row);
					$chaine_dep = $dep_code." (".$dep_nom.")";
					if (in_array($dep_code,$tab_dep))
						echo "<option value=\"".$dep_code."\" selected>".$chaine_dep."</option>";
					else
						echo "<option value=\"".$dep_code."\">".$chaine_dep."</option>";
				}
			}
			mysql_free_result($rs);
			mysql_close($conn);
		}
		?>
		</select>
		 <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			<span class="annot_petit_it">
			(S&eacute;lectionnez avec Ctrl + clic gauche)
		 <br><span id="attn1"></span><span id="msg1" class="ptitre_std_gras_jaune_frouge"><?PHP if ($nbdep==0) echo htmlspecialchars($msg1_err_type)?></span>
			<input name="deptxt" type="hidden" id="deptxt" value="<?PHP echo $dep ?>" size="50" readonly="1">
			</span>
		</td>
		</tr>
		<tr>
		<td width="160" class="rubfrm" id="f_sujet" align="right">Sujet du message</td>
		<td>
			<input name="sujet" type="text" id="sujet" size="50" maxlength="50" value="<?PHP echo $sujet; ?>">
				  <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		</td>
		</tr>
		<tr>
		<td width="160" class="rubfrm" id="f_sujet" align="right">Inclus comptes verrouill&eacute;s ?</td>
		<td>
			<input type="radio" name="cv" style="background : #FFFFFF;" value="O" <?PHP if ($cv=="O") echo 'checked="checked"'?>> Oui / 
			<input type="radio" name="cv" style="background : #FFFFFF;" value="N" <?PHP if ($cv=="N") echo 'checked="checked"'?>> Non
		</td>
		</tr>
		<tr>
		<td colspan="2" align="center">
			 <input name="OK" type="submit" class="bton_std" id="OK" value="<?PHP echo $but_valprm; ?>">
		</td>
		</tr>
		</table>
		</form>
<?PHP
		} else {
?>		
		<form name="email_maj" id="email_maj" method="post" action="email_maj.php">
		<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
		<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
		<input name="pays" type="hidden" id="pays" value="<?PHP echo $pays; ?>">
		<input name="deptxt" type="hidden" id="deptxt" value="<?PHP echo $dep; ?>">
		<input name="sujet" type="hidden" id="sujet" value="<?PHP echo $sujet; ?>">
		<input name="cv" type="hidden" id="cv" value="<?PHP echo $cv; ?>">
		<p align="center" class="titre_gras_soul">Listes des donneurs d'ordres s&eacute;lectionn&eacute;s</p>
<?PHP
		// *** Affichage de la table
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech = "SELECT * FROM " .TBDO;
		if ($cv=="N")
			$rech.=", ".TBPW;
		$rech.= " WHERE ".TBDO.".do_ouvert = '1'";
		if ($dep <> "") 
		{
			$tab_dep = explode("_",$dep);
			
			$rech .= " AND (";
				
			foreach($tab_dep as $idx=>$value)
			{
				$rech .= TBDO.".do_dep ='".$value."' OR ";
			}
			$rech = substr($rech,0,strlen($rech)-4);
			$rech .= ")";
		}
		if ($cv=="N")
		{
			$rech.=" AND ".TBDO.".do_code=".TBPW.".pw_code";
			$rech.=" AND ".TBPW.".pw_actif='1'";
		}
		$rs = mysql_query($rech) or die(mysql_error());
		$nbsel=	mysql_num_rows($rs);
		if ($nbsel >0)
		{
?>
			<table width="100%"  border="0">
			<tr>
				<td class="annot_std_gras" id="f_dest" valign="bottom" align="right">Services destinataires : </td>
				<td>
					G&eacute;n&eacute;ral : 
					<input type="checkbox" name="type_dest[]" style="background : #FFFFFF;" <?PHP if(verif_choix_dest("1")) echo 'checked="checked"'; ?> value="1">
					
					Direction : 
					<input type="checkbox" name="type_dest[]" style="background : #FFFFFF;" <?PHP if(verif_choix_dest("2")) echo 'checked="checked"'; ?> value="2">
					
					Comptabilit&eacute; : 
					<input type="checkbox" name="type_dest[]" style="background : #FFFFFF;" <?PHP if(verif_choix_dest("3")) echo 'checked="checked"'; ?> value="3">

					Technique : 
					<input type="checkbox" name="type_dest[]" style="background : #FFFFFF;" <?PHP if(verif_choix_dest("4")) echo 'checked="checked"'; ?> value="4">
				  <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
				</td>
			</tr>
			</table>
<?PHP
			echo "<p align=\"center\">";
			echo "<input type=\"button\" name=\"sel\" id=\"sel\" value=\"Tous\" class=\"bton_fgris_petit\" onclick=\"this.value=checkall(this.value,this.form);\">";
			echo "</p>";

			echo "<div id=\"Layer1\" class=\"lst_fen\">";
			
			// Définition et entête de la table
			echo "<table class=\"Mtable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";

			echo "<th>";
			echo "Code";
			echo "</th>\n";
			echo "<th>";
			echo "Nom";
			echo "</th>\n";
			echo "<th>";
			echo "Téléphone";
			echo "</th>\n";
			echo "<th>";
			echo "CP";
			echo "</th>\n";
			echo "<th>";
			echo "Choisir";
			echo "</th>\n";
	
			$i = 0;
	
			while ($row = mysql_fetch_assoc($rs)) 
			{
				// Création de l'entête de ligne (TR)
				creetrlst($i);

				echo "<td>".$row["do_code"];
				echo "</td>\n";
				echo "<td>".$row["do_nom"]."</td>\n";
				echo "<td>".$row["do_telf"]."</td>\n";
				echo "<td>".Retournecp_openId($row["do_ville"],FALSE)."</td>\n";
				echo "<td align=\"center\">\n";
				if (strip_tags(trim(@$_POST["OK"])) == html_entity_decode($but_rech)) // On vient de demander une recherche : on active pas défaut
				{
					echo "<input type=\"checkbox\" name=\"do_choisi[]\" value=\"".$row["do_id"]."\"";
					if($i%2 == 0)
						echo " style=\"background : #32CD32;\"";
					else
						echo " style=\"background : #00FF00;\"";
					echo" checked>";
				}
				else // Sinon on reprend en fonction de ce qui a été coché
				{
					echo "<input type=\"checkbox\" name=\"do_choisi[]\"";
					if(verif_choix_do($row["do_id"])) 
						echo "checked ";
					if($i%2 == 0)
						echo " style=\"background : #32CD32;\"";
					else
						echo " style=\"background : #00FF00;\"";
					echo "value=\"".$row["do_id"]."\">";
				}
				echo "</td>\n";
				echo "</tr>\n";
				
				$i++;
			}  
			echo "</table>\n";
			// *** Fin affichage de la table

			echo "</div>";
?>
		<!-- Message à envoyer-->
		<table width="100%"  border="0">
		<tr>
			<td align="center">
			<span class="titre_gras_soul">Message &agrave; envoyer
			 <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			</span>
			<span class="annot_std_it"><br>(Sujet : <?PHP echo $sujet; ?>)</span>
			</td>
		</tr>
		<tr>
			<td>
			<?PHP
				$sBasePath = $_SERVER['PHP_SELF'] ;
				$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "admin" ) ).'classes/fckeditor/' ;
			
				$oFCKeditor = new FCKeditor('FCKeditor1') ;
				$oFCKeditor->BasePath	= $sBasePath;
				$oFCKeditor->Value		= $txt;
				$oFCKeditor->Height 	= '400';
				$oFCKeditor->ToolbarSet = 'SMI';
				$oFCKeditor->Create();
			
			?>
		 </td>
		 </tr>
		 </table>
<?PHP
		}
		else
		{
			echo "Aucun donneur d'ordres sur ces crit&egrave;res.";
		}
?>
		<p align="center">
		<?PHP if ($nbsel>0) { ?>
		<input name="envoi" type="submit" class="bton_std" id="envoi" value="<?PHP echo $but_exped; ?>">
		 <input name="RAZ" type="button" class="bton_std" id="RAZ" value="<?PHP echo $but_reinit; ?>" onClick="document.getElementById('sel').value=uncheckall(this.form);">
		<?PHP } ?>
		 <input name="init" type="button" class="bton_std" id="init" value="<?PHP echo $but_recomm; ?>" onClick="javascript:; self.location.href=('<?PHP echo $url_link; ?>');">
		 </p>
		</form>
		<!-- Fin du formulaire -->
<?PHP
		}
		break;

	/******************************************************/
	/**                    CLIENTS                       **/
	/******************************************************/

	case "cli" :
		if ($validp==FALSE)
		{
?>
		<!-- Scripts Javascript pour contrôle de formulaire -->
		<script	type="text/javascript" src="../jscript/vform/vform.js"></script>
		
		<script language="javascript">
<!--
		var tab1_champ=new Array(
			"nom:cat ; format:liste ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_cat); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
		<?PHP 
		switch (@$_SESSION["niv_log"])
		{
			case 4 :
		?>
				"nom:age ; format:alphanum ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_age); ?> ; stok:frmok ; stbad:frmbad",
		<?PHP
				break;
			case 4 :
		?>
				"nom:do ; format:alphanum ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_do); ?> ; stok:frmok ; stbad:frmbad",
		<?PHP
				break;
			default :
		?>
				"nom:age ; format:liste ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_age); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
		<?PHP
				break;
		}
		?>
			"nom:pays ; format:liste ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_pays); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
			"nom:dep[] ; format:listem ; req:N ; txt:Départements ; vmn:1 ; stok:frmok ; stbad:frmbad",
			"nom:sujet ; format:txt ; req:Y ; txt:Sujet ; lmx:50 ; stok:frmok ; stbad:frmbad");
		//-->
		</script>
		
		<!-- Formulaire permettant la sélection des destinataires et l'envoi -->
		<form name="email_maj" id="email_maj" method="post" action="email_maj.php" onSubmit="javascript:; return (VForm(this,tab1_champ,'','<?PHP echo $_SESSION["lng"]; ?>'));">
		<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
		<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
		
		<!-- Liste des catégories -->
		<table width="100%"  border="0">
		<tr>
		  <td width="160" class="rubfrm" id="f_cat" align="right">Cat&eacute;gorie</td>
		  <td>
				<select name="cat" size="1" id="cat">
				<?PHP
				
				echo "<option>-- Choisissez une catégorie --</option>";

				if ($cat <> "*")
					echo "<option value=\"*\">-- TOUTES LES CATEGORIES --</option>";
				else
					echo "<option value=\"*\" selected>-- TOUTES LES CATEGORIES --</option>";
	
				// Création de la liste des catégories
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
				$rs = mysql_query("SELECT * FROM ".TBCCAT." ORDER BY cat_desc");
				
				$i=0;
				
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
		
					if ($cat == $cat_code)
					{
						echo '<option value="'.$cat_code.'" selected>'.$cat_desc.'</option>';
					}
					else
					{
						echo '<option value="'.$cat_code.'">'.$cat_desc.'</option>';
					}
		
					$i++;
				}
				mysql_free_result($rs);
				mysql_close($conn);
				?>
				</select>
				  <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			</td>
		</tr>
		<tr>
			<td class="rubfrm" id="f_pays" align="right"><?PHP echo $txt_chp_pays; ?></td>
			<td>
			<?PHP
			switch (@$_SESSION["niv_log"])
			{
				case 4 :
				case 6 :
			?>
					<input name="pays" type="hidden" id="pays" value="<?PHP echo $pays; ?>">
					<input name="npays" type="text" id="npays" value="<?PHP echo Retournepays_open($pays,TRUE); ?>" size="50" maxlength="50" readonly="1">
			<?PHP
					break;
				default :
					$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
					mysql_select_db(DBNAME);
					$rs = mysql_query("SELECT * FROM ".TBPAYS." ORDER BY pays_nom");
			?>			
				<select name="pays" id="pays">
			<?PHP
				echo "<option value=\"\">".$sel_lst_pays."</option>";
		
				// Création de la liste des pays
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
					echo '<option value="'.$pays_code.'"';
					if (str_majuscules($pays)==$pays_code)
						echo ' selected';
					echo '>'.$pays_nom.'</option>';
				}
			?>
				</select>
				<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			<?PHP
					mysql_free_result($rs);
					mysql_close($conn);
					break;
			}
			?>
			</td>
		</tr>
		<tr>
		  <td width="160" class="rubfrm" id="f_age" align="right">Agence</td>
		  <td>
				<?PHP
				switch (@$_SESSION["niv_log"])
				{
					case 4 :
						$row = lit_enr_age($_SESSION["code_age"],TRUE);
						extract ($row);
				?>
					<input name="age" type="hidden" id="age" value="<?PHP echo $_SESSION["code_age"]; ?>">
					<input name="nagence" type="text" id="nagence" value="<?PHP echo $age_nom; ?>" size="50" maxlength="50" readonly="1">
				<?PHP
						break;

					case 6 :
						$row = lit_enr_do($_SESSION["code_log"]);
						extract ($row);
				?>
					<input name="age" type="hidden" id="age" value="<?PHP echo $_SESSION["code_do"]; ?>">
					<input name="nagence" type="text" id="nagence" value="<?PHP echo $do_nom; ?>" size="50" maxlength="50" readonly="1">
				<?PHP
						break;
					default :
				?>
					<select name="age" size="1" id="age">
					<option><?PHP echo $sel_lst_makechx; ?></option>
					<?PHP
					// Création de la liste des agences
					$nbage=0;
					
					if ($pays<>"")
					{
						$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
						mysql_select_db(DBNAME);
						$rs = mysql_query("SELECT * FROM ".TBAGE." WHERE `age_ouvert` = '1' AND `age_codepays` = '".str_majuscules($pays)."' ORDER BY age_nom");
						$nbage=mysql_num_rows($rs);
						if ($nbage>0)
						{		
							echo "<option value=\"*\"";
							if ($age == "*")
								echo "selected";
							echo ">-- TOUTES LES AGENCES --</option>";
				
							while ($resultat = mysql_fetch_array($rs)) 
							{
								extract($resultat);
					
								if ($age == $age_code)
									echo '<option value="'.$age_code.'" selected>'.$age_nom.'</option>';
								else
									echo '<option value="'.$age_code.'">'.$age_nom.'</option>';
							}
						}
						mysql_free_result($rs);
						mysql_close($conn);
					}
					?>
					</select>
					 <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
					 <br><span id="attn3"></span><span id="msg3" class="ptitre_std_gras_jaune_frouge"><?PHP if ($nbage==0) echo htmlspecialchars($msg3_err_type); ?></span>
				<?PHP
						break;
				}
				?>
			</td>
		</tr>
		<tr>
		<td class="rubfrm" id="f_dep" align="right"><?PHP echo $txt_chp_dep; ?></td>
		<td>
		<select name="dep[]" size="5" id="dep" multiple="multiple" onChange="utxtfromselm(this.id,'deptxt');">
		<option><?PHP echo $sel_lst_makechx; ?></option>
		<?PHP
		// Création de la liste des départements
		$nbdep=0;
		
		if ($pays<>"")
		{		
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			switch (@$_SESSION["niv_log"])
			{
				case 4 :
					$rech = "SELECT * FROM ".TBZCC.", ".TBDEP;
					$rech.= " WHERE ".TBZCC.".zcc_codepays='".str_majuscules($pays)."' AND ".TBZCC.".zcc_code='".$age."'";
					$rech.= " AND ".TBZCC.".zcc_codedep=".TBDEP.".dep_code ORDER BY ".TBDEP.".dep_code";
					break;
				default :
					$rech = "SELECT * FROM ".TBDEP." WHERE dep_codepays='".str_majuscules($pays)."' ORDER BY dep_code";
					break;
			}

			$rs = mysql_query($rech) or die(mysql_error());
			$nbdep=mysql_num_rows($rs);

			if ($nbdep>0)
			{		
				$tab_dep=explode("_",$dep);
				while ($row = mysql_fetch_array($rs)) 
				{
					extract($row);
					$chaine_dep = $dep_code." (".$dep_nom.")";
					if (in_array($dep_code,$tab_dep))
						echo "<option value=\"".$dep_code."\" selected>".$chaine_dep."</option>";
					else
						echo "<option value=\"".$dep_code."\">".$chaine_dep."</option>";
				}
			}
			mysql_free_result($rs);
			mysql_close($conn);
		}
		?>
		</select>
		 <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			<span class="annot_petit_it">
			(S&eacute;lectionnez avec Ctrl + clic gauche)
		 <br><span id="attn1"></span><span id="msg1" class="ptitre_std_gras_jaune_frouge"><?PHP if ($nbdep==0) echo htmlspecialchars($msg1_err_type)?></span>
			<input name="deptxt" type="hidden" id="deptxt" value="<?PHP echo $dep ?>" size="50" readonly="1">
			</span>
		</td>
		</tr>
		<tr>
		<td width="160" class="rubfrm" id="f_sujet" align="right">Sujet du message</td>
		<td>
			<input name="sujet" type="text" id="sujet" size="50" maxlength="50" value="<?PHP echo $sujet; ?>">
				  <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		</td>
		</tr>
		<tr>
		<td width="160" class="rubfrm" id="f_sujet" align="right">Inclus comptes verrouill&eacute;s ?</td>
		<td>
			<input type="radio" name="cv" style="background : #FFFFFF;" value="O" <?PHP if ($cv=="O") echo 'checked="checked"'?>> Oui / 
			<input type="radio" name="cv" style="background : #FFFFFF;" value="N" <?PHP if ($cv=="N") echo 'checked="checked"'?>> Non
		</td>
		</tr>
		<tr>
		<td colspan="2" align="center">
			 <input name="OK" type="submit" class="bton_std" id="OK" value="<?PHP echo $but_valprm; ?>">
		</td>
		</tr>
		</table>
		</form>
<?PHP
		} else {
?>		
		<form name="email_maj" id="email_maj" method="post" action="email_maj.php">
		<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
		<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
		<input name="cat" type="hidden" id="cat" value="<?PHP echo $cat; ?>">
		<input name="age" type="hidden" id="age" value="<?PHP echo $age; ?>">
		<input name="pays" type="hidden" id="pays" value="<?PHP echo $pays; ?>">
		<input name="deptxt" type="hidden" id="deptxt" value="<?PHP echo $dep; ?>">
		<input name="sujet" type="hidden" id="sujet" value="<?PHP echo $sujet; ?>">
		<input name="cv" type="hidden" id="cv" value="<?PHP echo $cv; ?>">
		<p align="center" class="titre_gras_soul">Listes des clients s&eacute;lectionn&eacute;s</p>
<?PHP
		// *** Affichage de la table

		// Si agence choisie, on récupère les infos de cette agence
		if ($age <> "*")
		{
			$row2 = lit_enr_age($age,TRUE);
			if (is_array($row2))
				extract($row2);
		}

		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech = "SELECT * FROM " .TBCLI;
		if ($cv=="N")
			$rech.=", ".TBPW;
		if ($cat <> "*")
			 $rech.=" WHERE ".TBCLI.".cli_cat = '".$cat."'";
		if ($age <> "*")
		{
			switch (@$_SESSION["niv_log"])
			{
				case 6 :
					if(!stristr($rech,"WHERE "))
						$rech .= " WHERE ".TBCLI.".cli_codedo = '".$age."'";
					else
						$rech .= " AND ".TBCLI.".cli_codedo = '".$age."'";
					break;
				default :
					if(!stristr($rech,"WHERE "))
						$rech .= " WHERE (".TBCLI.".cli_prop = '".$age."' OR ".TBCLI.".cli_prop IS NULL)";
					else
						$rech .= " AND (".TBCLI.".cli_prop = '".$age."' OR ".TBCLI.".cli_prop IS NULL)";
					break;
			}
		}
		if ($dep <> "") 
		{
			$tab_dep = explode("_",$dep);
			
			// WHERE existe ?
			if(!stristr($rech,"WHERE "))
			 $rech .= " WHERE (";
			else
			 $rech .= " AND (";
				
			foreach($tab_dep as $idx=>$value)
			{
				$rech .= TBCLI.".cli_dep ='".$value."' OR ";
			}
			$rech = substr($rech,0,strlen($rech)-4);
			$rech .= ")";
		}
		if ($cv=="N")
		{
			if(!stristr($rech,"WHERE "))
			 $rech .= " WHERE ";
			else
			 $rech .= " AND ";
			$rech.=TBCLI.".cli_code=".TBPW.".pw_code";
			$rech.=" AND ".TBPW.".pw_actif='1'";
		}
		$rech .= " ORDER BY ".TBCLI.".cli_code";
		$rs = mysql_query($rech) or die(mysql_error());
		$nbsel=	mysql_num_rows($rs);
		if ($nbsel >0)
		{
?>
		<table width="100%"  border="0">
		<tr>
			<td class="annot_std_gras" id="f_dest" valign="bottom" align="right">Services destinataires : </td>
			<td>
				G&eacute;n&eacute;ral : 
				<input type="checkbox" name="type_dest[]" style="background : #FFFFFF;" <?PHP if(verif_choix_dest("1")) echo 'checked="checked"'; ?> value="1">
				
				Direction : 
				<input type="checkbox" name="type_dest[]" style="background : #FFFFFF;" <?PHP if(verif_choix_dest("2")) echo 'checked="checked"'; ?> value="2">
				
				Comptabilit&eacute; : 
				<input type="checkbox" name="type_dest[]" style="background : #FFFFFF;" <?PHP if(verif_choix_dest("3")) echo 'checked="checked"'; ?> value="3">

				Technique : 
				<input type="checkbox" name="type_dest[]" style="background : #FFFFFF;"<?PHP if(verif_choix_dest("4")) echo 'checked="checked"'; ?> value="4">
			  <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			</td>
		</tr>
		</table>
<?PHP
			echo "<p align=\"center\">";
			echo "<input type=\"button\" name=\"sel\" id=\"sel\" value=\"Tous\" class=\"bton_fgris_petit\" onclick=\"this.value=checkall(this.value,this.form);\">";
			echo "</p>";

			echo "<div id=\"Layer1\" class=\"lst_fen\">";
			
			// Définition et entête de la table
			echo "<table class=\"Mtable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";

			echo "<th>";
			echo "Code";
			echo "</th>\n";
			echo "<th>";
			echo "Nom";
			echo "</th>\n";
			echo "<th>";
			echo "Téléphone";
			echo "</th>\n";
			echo "<th>";
			echo "CP";
			echo "</th>\n";
			echo "<th>";
			echo "Choisir";
			echo "</th>\n";
	
			$i = 0;
	
			while ($row = mysql_fetch_assoc($rs)) 
			{
				$aff_ligne=TRUE;
				
				if (($age <> "*") AND (@$_SESSION["niv_log"]<>6)) // Tests si une agence a été choisie (uniquement si pas en mode donneur d'ordres)
				{
					// Vérifie que le département du client est dans la zone de chalandise de l'agence
					if (dep_in_zcc_age_open($row["cli_dep"],$row["cli_codepays"],$age,FALSE) == FALSE)
					{
						// Si pas dans la zone de chalandise, on affiche pas
						$aff_ligne = FALSE;
					}
				}

				if ($aff_ligne == TRUE)
				{
					// Création de l'entête de ligne (TR)
					creetrlst($i);
	
					echo "<td>".$row["cli_code"];
					echo "</td>\n";
					echo "<td>";
					if ($row["cli_ste"] <> "")
						$txt_cli = $row["cli_ste"].", ".$row["cli_civilite"]." ".$row["cli_nom"]." ".$row["cli_prenom"];
					else
						$txt_cli = $row["cli_civilite"]." ".$row["cli_nom"]." ".$row["cli_prenom"];
					echo $txt_cli;
					echo "</td>\n";
					echo "<td>".$row["cli_telf"]."</td>\n";
					echo "<td>".Retournecp_openId($row["cli_ville"],FALSE)."</td>\n";
					echo "<td align=\"center\">\n";
					// On vient de demander une recherche ou c'est la 1ère fois : on active pas défaut
					if ((strip_tags(trim(@$_POST["OK"])) == html_entity_decode($but_rech)) OR (strip_tags(trim(@$_GET['td'])) == "cli"))
					{
						echo "<input type=\"checkbox\" name=\"cli_choisi[]\" value=\"".$row["cli_id"]."\"";
						if($i%2 == 0)
							echo " style=\"background : #32CD32;\"";
						else
							echo " style=\"background : #00FF00;\"";
						echo " onclick=\"document.email_maj.sel.value=valbouton(document.email_maj);\"";
						echo " checked>";
					}
					else // Sinon on reprend en fonction de ce qui a été coché
					{
						echo "<input type=\"checkbox\" name=\"cli_choisi[]\"";
						if(verif_choix_cli($row["cli_id"])) 
							echo "checked ";
						if($i%2 == 0)  
							echo " style=\"background : #32CD32;\"";
						else
							echo " style=\"background : #00FF00;\"";
						echo " onclick=\"document.email_maj.sel.value=valbouton(document.email_maj);\"";
						echo "value=\"".$row["cli_id"]."\">";
					}
					echo "</td>\n";
					echo "</tr>\n";
					
					$i++;
				}
			}  
			echo "</table>\n";
			// *** Fin affichage de la table

			echo "</div>";
?>
		<!-- Message à envoyer-->
		<table width="100%"  border="0">
		<tr>
			<td align="center">
			<span class="titre_gras_soul">Message &agrave; envoyer
			 <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			</span>
			<span class="annot_std_it"><br>(Sujet : <?PHP echo $sujet; ?>)</span>
			</td>
		</tr>
		<tr>
			<td>
			<?PHP
				$sBasePath = $_SERVER['PHP_SELF'] ;
				switch (@$_SESSION["niv_log"])
				{
					case 4 :
						$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "age" ) ).'classes/fckeditor/' ;
						break;
					case 6 :
						$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "do" ) ).'classes/fckeditor/' ;
						break;
					default :
						$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "admin" ) ).'classes/fckeditor/' ;
						break;
				}
				$oFCKeditor = new FCKeditor('FCKeditor1') ;
				$oFCKeditor->BasePath	= $sBasePath;
				$oFCKeditor->Value		= $txt;
				$oFCKeditor->Height 	= '400';
				$oFCKeditor->ToolbarSet = 'SMI';
				$oFCKeditor->Create();
			
			?>
		 </td>
		 </tr>
		 </table>
<?PHP
		}
		else
		{
			echo "Aucun client sur ces crit&egrave;res.";
		}
?>
		<p align="center">
		<?PHP if ($nbsel>0) { ?>
		<input name="envoi" type="submit" class="bton_std" id="envoi" value="<?PHP echo $but_exped; ?>">
		 <input name="RAZ" type="button" class="bton_std" id="RAZ" value="<?PHP echo $but_reinit; ?>" onClick="document.getElementById('sel').value=uncheckall(this.form);">
		<?PHP } ?>
		 <input name="init" type="button" class="bton_std" id="init" value="<?PHP echo $but_recomm; ?>" onClick="javascript:; self.location.href=('<?PHP echo $url_link; ?>');">
		 </p>
		</form>
		<!-- Fin du formulaire -->
<?PHP
		}
		break;

	/******************************************************/
	/**                  OPERATEURS                      **/
	/******************************************************/

	case "ope" :
		if ($validp==FALSE)
		{
?>
		<!-- Scripts Javascript pour contrôle de formulaire -->
		<script	type="text/javascript" src="../jscript/vform/vform.js"></script>
		
		<script language="javascript">
<!--
		var tab1_champ=new Array(
			"nom:dep[] ; format:listem ; req:Y ; txt:Départements ; vmn:1 ; stok:frmok ; stbad:frmbad",
			"nom:sujet ; format:txt ; req:Y ; txt:Sujet ; lmx:50 ; stok:frmok ; stbad:frmbad");
		//-->
		</script>
		
		<!-- Formulaire permettant la sélection des destinataires et l'envoi -->
		<form name="email_maj" id="email_maj" method="post" action="email_maj.php" onSubmit="javascript:; return (VForm(this,tab1_champ,'','<?PHP echo $_SESSION["lng"]; ?>'));">
			<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
			<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
		
		<table width="100%"  border="0">
		<tr>
			<td class="rubfrm" id="f_pays" align="right"><?PHP echo $txt_chp_pays; ?></td>
			<td>
			<?PHP
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rs = mysql_query("SELECT * FROM ".TBPAYS." ORDER BY pays_nom");
			?>			
				<select name="pays" id="pays">
			<?PHP
				echo "<option value=\"\">".$sel_lst_pays."</option>";
		
				// Création de la liste des pays
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
					if ($pays==$pays_code)
						echo '<option value="'.$pays_code.'" selected>'.$pays_nom.'</option>';
					else
						echo '<option value="'.$pays_code.'">'.$pays_nom.'</option>';
				}
			?>
				</select>
				<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			<?PHP
			mysql_free_result($rs);
			mysql_close($conn);
			?>
			</td>
		</tr>
		<tr>
		<td class="rubfrm" id="f_dep" align="right"><?PHP echo $txt_chp_dep; ?></td>
		<td>
		<select name="dep[]" size="5" id="dep" multiple="multiple" onChange="utxtfromselm(this.id,'deptxt');">
		<option><?PHP echo $sel_lst_makechx; ?></option>
		<?PHP
		// Création de la liste des départements
		$nbdep=0;
		
		if ($pays<>"")
		{		
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBDEP." WHERE dep_codepays='".str_majuscules($pays)."' ORDER BY dep_code";

			$rs = mysql_query($rech) or die(mysql_error());
			$nbdep=mysql_num_rows($rs);

			if ($nbdep>0)
			{		
				$tab_dep=explode("_",$dep);
				while ($row = mysql_fetch_array($rs)) 
				{
					extract($row);
					$chaine_dep = $dep_code." (".$dep_nom.")";
					if (in_array($dep_code,$tab_dep))
						echo "<option value=\"".$dep_code."\" selected>".$chaine_dep."</option>";
					else
						echo "<option value=\"".$dep_code."\">".$chaine_dep."</option>";
				}
			}
			mysql_free_result($rs);
			mysql_close($conn);
		}
		?>
		</select>
		 <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			<span class="annot_petit_it">
			(S&eacute;lectionnez avec Ctrl + clic gauche)
		 <br><span id="attn1"></span><span id="msg1" class="ptitre_std_gras_jaune_frouge"><?PHP if ($nbdep==0) echo htmlspecialchars($msg1_err_type)?></span>
			<input name="deptxt" type="hidden" id="deptxt" value="<?PHP echo $dep ?>" size="50" readonly="1">
			</span>
		</td>
		</tr>
		<tr>
		<td width="160" class="rubfrm" id="f_sujet" align="right">Sujet du message</td>
		<td>
			<input name="sujet" type="text" id="sujet" size="50" maxlength="50" value="<?PHP echo $sujet; ?>">
			  <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		</td>
		</tr>
		<tr>
		<td width="160" class="rubfrm" id="f_sujet" align="right">Inclus comptes verrouill&eacute;s ?</td>
		<td>
			<input type="radio" name="cv" style="background : #FFFFFF;" value="O" <?PHP if ($cv=="O") echo 'checked="checked"'?>> Oui / 
			<input type="radio" name="cv" style="background : #FFFFFF;" value="N" <?PHP if ($cv=="N") echo 'checked="checked"'?>> Non
		</td>
		</tr>
		<tr>
		<td colspan="2" align="center">
			 <input name="OK" type="submit" class="bton_std" id="OK" value="<?PHP echo $but_valprm; ?>">
		</td>
		</tr>
		</table>
		</form>
<?PHP
		} else {
?>		
		<form name="email_maj" id="email_maj" method="post" action="email_maj.php">
		<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
		<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
		<input name="pays" type="hidden" id="pays" value="<?PHP echo $pays; ?>">
		<input name="deptxt" type="hidden" id="deptxt" value="<?PHP echo $dep; ?>">
		<input name="sujet" type="hidden" id="sujet" value="<?PHP echo $sujet; ?>">
		<p align="center" class="titre_gras_soul">Listes des opérateurs s&eacute;lectionn&eacute;s</p>
<?PHP
		// *** Affichage de la table
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech = "SELECT * FROM " .TBOPE;
		if ($cv=="N")
			$rech.=", ".TBPW;
		if ($dep <> "")
		{
			$tab_dep = explode("_",$dep);
			
			// WHERE existe ?
			if(!stristr($rech,"WHERE "))
			 $rech .= " WHERE (";
			else
			 $rech .= " AND (";
				
			foreach($tab_dep as $idx=>$value)
			{
				$rech .= TBOPE.".ope_dep ='".$value."' OR ";
			}
			$rech = substr($rech,0,strlen($rech)-4);
			$rech .= ")";
		}
		if ($cv=="N")
		{
			if(!stristr($rech,"WHERE "))
			 $rech .= " WHERE ";
			else
			 $rech .= " AND ";
			$rech.=TBOPE.".ope_code=".TBPW.".pw_code";
			$rech.=" AND ".TBPW.".pw_actif='1'";
		}
		$rech .= " ORDER BY ".TBOPE.".ope_code";
		$rs = mysql_query($rech) or die(mysql_error());
		$nbsel=mysql_num_rows($rs);
		if ($nbsel >0)
		{
			echo "<p align=\"center\">";
			echo "<input type=\"button\" name=\"sel\" id=\"sel\" value=\"Tous\" class=\"bton_fgris_petit\" onclick=\"this.value=checkall(this.value,this.form);\">";
			echo "</p>";

			echo "<div id=\"Layer1\" class=\"lst_fen\">";
			
			// Définition et entête de la table
			echo "<table class=\"Mtable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";

			echo "<th>";
			echo "Code";
			echo "</th>\n";
			echo "<th>";
			echo "Nom";
			echo "</th>\n";
			echo "<th>";
			echo "Téléphone";
			echo "</th>\n";
			echo "<th>";
			echo "CP";
			echo "</th>\n";
			echo "<th>";
			echo "Choisir";
			echo "</th>\n";
	
			$i = 0;
	
			while ($row = mysql_fetch_assoc($rs)) 
			{
				if ($dep <> "") 
				{
					$dep_tab = explode("_",$dep);
					
					if (in_array($row["ope_dep"],$dep_tab))
						$aff_ligne = TRUE;
					else
						$aff_ligne = FALSE;
				}
				else
					$aff_ligne = TRUE;	

				if ($aff_ligne == TRUE)
				{
					// Création de l'entête de ligne (TR)
					creetrlst($i);
	
					echo "<td>".$row["ope_code"];
					echo "</td>\n";
					echo "<td>";
					echo $row["ope_civilite"]." ".$row["ope_nom"]." ".$row["ope_prenom"];
					echo"</td>\n";
					echo "<td>".$row["ope_telf"]."</td>\n";
					echo "<td>".Retournecp_openId($row["ope_ville"],FALSE)."</td>\n";
					echo "<td align=\"center\">\n";
					// On vient de demander une recherche ou c'est la 1ère fois : on active pas défaut
					if ((strip_tags(trim(@$_POST["OK"])) == html_entity_decode($but_rech)) OR (strip_tags(trim(@$_GET['td'])) == "ope"))
					{
						echo "<input type=\"checkbox\" name=\"ope_choisi[]\" value=\"".$row["ope_id"]."\"";
						if($i%2 == 0)
							echo " style=\"background : #32CD32;\"";
						else
							echo " style=\"background : #00FF00;\"";
						echo " onclick=\"document.email_maj.sel.value=valbouton(document.email_maj);\"";
						echo" checked>";
					}
					else // Sinon on reprend en fonction de ce qui a été coché
					{
						echo "<input type=\"checkbox\" name=\"ope_choisi[]\"";
						if(verif_choix_ope($row["ope_id"])) 
							echo "checked ";
						if($i%2 == 0)
							echo " style=\"background : #32CD32;\"";
						else
							echo " style=\"background : #00FF00;\"";
						echo " onclick=\"document.email_maj.sel.value=valbouton(document.email_maj);\"";
						echo "value=\"".$row["ope_id"]."\">";
					}
					echo "</td>\n";
					echo "</tr>\n";
					
					$i++;
				}
			}  
			echo "</table>\n";
			// *** Fin affichage de la table

			echo "</div>";
?>
		<!-- Message à envoyer-->
		<table width="100%"  border="0">
		<tr>
			<td align="center">
			<span class="titre_gras_soul">Message &agrave; envoyer
			 <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			</span>
			<span class="annot_std_it"><br>(Sujet : <?PHP echo $sujet; ?>)</span>
			</td>
		</tr>
		<tr>
			<td>
			<?PHP
				$sBasePath = $_SERVER['PHP_SELF'] ;
				$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "admin" ) ).'classes/fckeditor/' ;
			
				$oFCKeditor = new FCKeditor('FCKeditor1') ;
				$oFCKeditor->BasePath	= $sBasePath;
				$oFCKeditor->Value		= $txt;
				$oFCKeditor->Height 	= '400';
				$oFCKeditor->ToolbarSet = 'SMI';
				$oFCKeditor->Create();
			
			?>
		 </td>
		 </tr>
		 </table>
<?PHP
		}
		else
		{
			echo "Aucun opérateur actif sur ce(s) département(s).";
		}
?>
		<p align="center">
		<?PHP if ($nbsel>0) { ?>
		<input name="envoi" type="submit" class="bton_std" id="envoi" value="<?PHP echo $but_exped; ?>">
		 <input name="RAZ" type="reset" class="bton_std" id="RAZ" value="<?PHP echo $but_reinit; ?>">
		<?PHP } ?>
		 <input name="init" type="button" class="bton_std" id="init" value="<?PHP echo $but_recomm; ?>" onClick="javascript:; self.location.href=('<?PHP echo $url_link; ?>');">
		 </p>
		</form>
		<!-- Fin du formulaire -->
<?PHP
		}
		break;

	/******************************************************/
	/**                  TECHNICIENS                     **/
	/******************************************************/

	case "tec" :
	case "tecd" :
	case "tecs" :
		if ($validp==FALSE)
		{
?>
		<!-- Scripts Javascript pour contrôle de formulaire -->
		<script	type="text/javascript" src="../jscript/vform/vform.js"></script>
		
		<script language="javascript">
<!--
		var tab1_champ=new Array(
		<?PHP if ((@$_SESSION["niv_log"] <> 4) AND (@$_SESSION["niv_log"] <> 6))
		{
		?>
			"nom:age ; format:liste ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_age); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
		<?PHP
		}
		else
		{
		?>
			"nom:age ; format:alphanum ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_age); ?> ; stok:frmok ; stbad:frmbad",
		<?PHP
		}
		?>
			"nom:dep[] ; format:listem ; req:N ; txt:Départements ; vmn:1 ; stok:frmok ; stbad:frmbad",
			"nom:sujet ; format:txt ; req:Y ; txt:Sujet ; lmx:50 ; stok:frmok ; stbad:frmbad");
		//-->
		</script>
		
		<!-- Formulaire permettant la sélection des destinataires et l'envoi -->
		<form name="email_maj" id="email_maj" method="post" action="email_maj.php" onSubmit="javascript:; return (VForm(this,tab1_champ,'','<?PHP echo $_SESSION["lng"]; ?>'));">
		<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
		<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
		
		<table width="100%"  border="0">
		<tr>
		  <td width="160" class="rubfrm" id="f_age" align="right">
		  <?PHP 
		  switch ($td)
		  {
		  	case "tecs" :
		  		echo "Sous-traitant";
				$tous="TOUS LES SOUS-TRAITANTS";
				break;
		  	case "tecd" :
		  		echo "Donneur d'ordre";
				$tous="TOUS LES DONNEURS D'ORDRES";
				break;
			default :
				echo $tab_ent_age;
				$tous="TOUTES LES AGENCES";
				break;
		  }
		  ?>
		  </td>
		  <td>
			<?PHP if ((@$_SESSION["niv_log"] <> 4) AND (@$_SESSION["niv_log"] <> 6) AND (@$_SESSION["niv_log"] <> 10))
			{
			?>
				<select name="age" size="1" id="age">
				<?PHP
				
				echo "<option>".$sel_lst_makechx."</option>";

				if ($age <> "*")
					echo "<option value=\"*\">-- ".$tous." --</option>";
				else
					echo "<option value=\"*\" selected>-- ".$tous." --</option>";

				// Création de la liste des agences/donneurs d'ordres
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
				  switch ($td)
				  {
					case "tec" :
						$rech="SELECT * FROM ".TBAGE." WHERE `age_ouvert` = '1' ORDER BY age_nom";
						break;
					case "tecd" :
						$rech="SELECT * FROM ".TBDO." WHERE `do_ouvert` = '1' ORDER BY do_nom";
						break;
					case "tecs" :
						$rech="SELECT * FROM ".TBST." WHERE `st_ouvert` = '1' ORDER BY st_nom";
						break;
				  }
				$rs = mysql_query($rech) or die(mysql_error());
				
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
					  switch ($td)
					  {
						case "tec" :
							$code=$age_code;
							$nom=$age_nom;
							break;
						case "tecd" :
							$code=$do_code;
							$nom=$do_nom;
							break;
						case "tecs" :
							$code=$st_code;
							$nom=$st_nom;
							break;
					  }
		
					if ($age == $code)
						echo '<option value="'.$code.'" selected>'.$nom.'</option>';
					else
						echo '<option value="'.$code.'">'.$nom.'</option>';
		
					$i++;
				}
				mysql_free_result($rs);
				mysql_close($conn);
				?>
				</select>
				<br>
				<span class="annot_petit_it">
				(Ne s'afficheront que les techniciens salari&eacute;s)
				</span>
			<?PHP
			}
			else
			{
				switch (@$_SESSION["niv_log"])
				{
					case 4 :
						$row = lit_enr_age($_SESSION["code_age"],TRUE);
						break;
					case 6 :
						$row = lit_enr_do($_SESSION["code_do"]);
						break;
					case 10 :
						$row = lit_enr_st($_SESSION["code_st"]);
						break;
				}
				extract ($row);
				switch (@$_SESSION["niv_log"])
				{
					case 4 :
						echo '<input name="age" type="hidden" id="age" value="'.$_SESSION["code_age"].'">';
						echo '<input name="nagence" type="text" id="nagence" value="'.$age_nom.'" size="50" maxlength="50" readonly="1">';
						break;
					case 6 :
						echo '<input name="age" type="hidden" id="age" value="'.$_SESSION["code_do"].'">';
						echo '<input name="nagence" type="text" id="nagence" value="'.$do_nom.'" size="50" maxlength="50" readonly="1">';
						break;
					case 10 :
						echo '<input name="age" type="hidden" id="age" value="'.$_SESSION["code_st"].'">';
						echo '<input name="nagence" type="text" id="nagence" value="'.$st_nom.'" size="50" maxlength="50" readonly="1">';
						break;
				}
			}
			?>
			  <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			</td>
		</tr>
		<tr>
			<td class="rubfrm" id="f_pays" align="right"><?PHP echo $txt_chp_pays; ?></td>
			<td>
			<?PHP if ((@$_SESSION["niv_log"] <> 4) AND (@$_SESSION["niv_log"] <> 6) AND (@$_SESSION["niv_log"] <> 10))
			{
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
				$rs = mysql_query("SELECT * FROM ".TBPAYS." ORDER BY pays_nom");
			?>			
				<select name="pays" id="pays">
			<?PHP
				echo "<option value=\"\">".$sel_lst_pays."</option>";
		
				// Création de la liste des pays
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
					if ($pays==$pays_code)
						echo '<option value="'.$pays_code.'" selected>'.$pays_nom.'</option>';
					else
						echo '<option value="'.$pays_code.'">'.$pays_nom.'</option>';
				}
			?>
				</select>
				<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			<?PHP
				mysql_free_result($rs);
				mysql_close($conn);
			} else {

			switch (@$_SESSION["niv_log"])
			{
				case 4 :
					echo '<input name="pays" type="hidden" id="pays" value="'.$age_codepays.'">';
					echo '<input name="npays" type="text" id="npays" value="'.Retournepays_open($age_codepays,TRUE).'" size="50" maxlength="50" readonly="1">';
					break;
				case 6 :
					echo '<input name="pays" type="hidden" id="pays" value="'.$do_codepays.'">';
					echo '<input name="npays" type="text" id="npays" value="'.Retournepays_open($do_codepays,TRUE).'" size="50" maxlength="50" readonly="1">';
					break;
				case 10 :
					echo '<input name="pays" type="hidden" id="pays" value="'.$st_codepays.'">';
					echo '<input name="npays" type="text" id="npays" value="'.Retournepays_open($st_codepays,TRUE).'" size="50" maxlength="50" readonly="1">';
					break;
			}
			?>
			<?PHP } ?>
			</td>
		</tr>
		<tr>
		<td class="rubfrm" id="f_dep" align="right"><?PHP echo $txt_chp_dep; ?></td>
		<td>
		<select name="dep[]" size="5" id="dep" multiple="multiple" onChange="utxtfromselm(this.id,'deptxt');">
		<option><?PHP echo $sel_lst_makechx; ?></option>
		<?PHP
		// Création de la liste des départements
		$nbdep=0;
		
		if ($pays<>"")
		{		
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBDEP." WHERE dep_codepays='".str_majuscules($pays)."' ORDER BY dep_code";
			$rs = mysql_query($rech) or die(mysql_error());
			$nbdep=mysql_num_rows($rs);

			if ($nbdep>0)
			{		
				$tab_dep=explode("_",$dep);
				while ($row = mysql_fetch_array($rs)) 
				{
					extract($row);
					$chaine_dep = $dep_code." (".$dep_nom.")";
					if (in_array($dep_code,$tab_dep))
						echo "<option value=\"".$dep_code."\" selected>".$chaine_dep."</option>";
					else
						echo "<option value=\"".$dep_code."\">".$chaine_dep."</option>";
				}
			}
			mysql_free_result($rs);
			mysql_close($conn);
		}
		?>
		</select>
		 <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			<span class="annot_petit_it">
			(S&eacute;lectionnez avec Ctrl + clic gauche)
		 <br><span id="attn1"></span><span id="msg1" class="ptitre_std_gras_jaune_frouge"><?PHP if ($nbdep==0) echo htmlspecialchars($msg1_err_type)?></span>
			<input name="deptxt" type="hidden" id="deptxt" value="<?PHP echo $dep ?>" size="50" readonly="1">
			</span>
		</td>
		</tr>
		<tr>
		<td width="160" class="rubfrm" id="f_sujet" align="right">Sujet du message</td>
		<td>
			<input name="sujet" type="text" id="sujet" size="50" maxlength="50" value="<?PHP echo $sujet; ?>">
			  <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		</td>
		</tr>
		<tr>
		<td width="160" class="rubfrm" id="f_sujet" align="right">Inclus comptes verrouill&eacute;s ?</td>
		<td>
			<input type="radio" name="cv" style="background : #FFFFFF;" value="O" <?PHP if ($cv=="O") echo 'checked="checked"'?>> Oui / 
			<input type="radio" name="cv" style="background : #FFFFFF;" value="N" <?PHP if ($cv=="N") echo 'checked="checked"'?>> Non
		</td>
		</tr>
		<tr>
		<td colspan="2" align="center">
			 <input name="OK" type="submit" class="bton_std" id="OK" value="<?PHP echo $but_valprm; ?>">
		</td>
		</tr>
		</table>
		</form>
<?PHP
		} else {
?>		
		<form name="email_maj" id="email_maj" method="post" action="email_maj.php">
		<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
		<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
		<input name="age" type="hidden" id="age" value="<?PHP echo $age; ?>">
		<input name="pays" type="hidden" id="pays" value="<?PHP echo $pays; ?>">
		<input name="deptxt" type="hidden" id="deptxt" value="<?PHP echo $dep; ?>">
		<input name="sujet" type="hidden" id="sujet" value="<?PHP echo $sujet; ?>">
		<p align="center" class="titre_gras_soul">Listes des techniciens s&eacute;lectionn&eacute;s</p>
<?PHP
		// *** Affichage de la table
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech = "SELECT * FROM " .TBTEC;
		if ($cv=="N")
			$rech.=", ".TBPW;
		if ($age <> "*")
		{
			switch ($td)
			{
				case "tec" :
					$rech.= " WHERE tec_codeage = '".$age."'";
					break;
				case "tecd" :
					$rech.=" WHERE tec_codedo = '".$age."'";
					break;
				case "tecs" :
					$rech.= " WHERE tec_codest = '".$age."'";
					break;
			}
		}
		else
		{
			switch ($td)
			{
				case "tec" :
					$rech.= " WHERE tec_codeage <> ''";
					break;
				case "tecd" :
					$rech.=" WHERE tec_codedo <> ''";
					break;
				case "tecs" :
					$rech.= " WHERE tec_codest <> ''";
					break;
			}
		}
		
		if ($dep <> "")
		{
			$tab_dep = explode("_",$dep);
			
			// WHERE existe ?
			if(!stristr($rech,"WHERE "))
			 $rech .= " WHERE (";
			else
			 $rech .= " AND (";
				
			foreach($tab_dep as $idx=>$value)
			{
				$rech .= TBTEC.".tec_dep ='".$value."' OR ";
			}
			$rech = substr($rech,0,strlen($rech)-4);
			$rech .= ")";
		}
		if ($cv=="N")
		{
			if(!stristr($rech,"WHERE "))
			 $rech .= " WHERE ";
			else
			 $rech .= " AND ";
			$rech.=TBTEC.".tec_code=".TBPW.".pw_code";
			$rech.=" AND ".TBPW.".pw_actif='1'";
		}
		$rech .= " ORDER BY ".TBTEC.".tec_code";

		$rs = mysql_query($rech) or die(mysql_error());
		$nbsel=mysql_num_rows($rs);
		if ($nbsel>0)
		{
			echo "<p align=\"center\">";
			echo "<input type=\"button\" name=\"sel\" id=\"sel\" value=\"Tous\" class=\"bton_fgris_petit\" onclick=\"this.value=checkall(this.value,this.form);\">";
			echo "</p>";

			echo "<div id=\"Layer1\" class=\"lst_fen\">";
			
			// Définition et entête de la table
			echo "<table class=\"Mtable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";

			echo "<th>";
			echo "Code";
			echo "</th>\n";
			echo "<th>";
			echo "Nom";
			echo "</th>\n";
			echo "<th>";
			echo "Téléphone";
			echo "</th>\n";
			echo "<th>";
			echo "CP";
			echo "</th>\n";
			echo "<th>";
			echo "Choisir";
			echo "</th>\n";
	
			$i = 0;
	
			while ($row = mysql_fetch_assoc($rs)) 
			{
				// Création de l'entête de ligne (TR)
				creetrlst($i);

				echo "<td>".$row["tec_code"];
				echo "</td>\n";
				echo "<td>";
				echo $row["tec_civilite"]." ".$row["tec_nom"]." ".$row["tec_prenom"];
				if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
				{
					echo "<br>";
					  switch ($td)
					  {
						case "tec" :
							echo "(Agence : ".$row["tec_codeage"].")";
							break;
						case "tecd" :
							echo "(DO : ".$row["tec_codedo"].")";
							break;
						case "tecs" :
							echo "(ST : ".$row["tec_codest"].")";
							break;
					  }
				}
				echo"</td>\n";
				echo "<td>".$row["tec_telf"]."</td>\n";
				echo "<td>".Retournecp_openId($row["tec_ville"],FALSE)."</td>\n";
				echo "<td align=\"center\">\n";
				// On vient de demander une recherche ou c'est la 1ère fois : on active pas défaut
				if ((strip_tags(trim(@$_POST["OK"])) == html_entity_decode($but_rech)) OR (strip_tags(trim(@$_GET['td'])) == "tec"))
				{
					echo "<input type=\"checkbox\" name=\"tec_choisi[]\" value=\"".$row["tec_id"]."\"";
					if($i%2 == 0)
						echo " style=\"background : #32CD32;\"";
					else
						echo " style=\"background : #00FF00;\"";
					echo " onclick=\"document.email_maj.sel.value=valbouton(document.email_maj);\"";
					echo" checked>";
				}
				else // Sinon on reprend en fonction de ce qui a été coché
				{
					echo "<input type=\"checkbox\" name=\"tec_choisi[]\"";
					if(verif_choix_tec($row["tec_id"])) 
						echo "checked ";
					if($i%2 == 0)
						echo " style=\"background : #32CD32;\"";
					else
						echo " style=\"background : #00FF00;\"";
					echo " onclick=\"document.email_maj.sel.value=valbouton(document.email_maj);\"";
					echo "value=\"".$row["tec_id"]."\">";
				}
				echo "</td>\n";
				echo "</tr>\n";
				
				$i++;
			}  
			echo "</table>\n";
			// *** Fin affichage de la table
			
			echo "</div>";
?>
		<!-- Message à envoyer-->
		<table width="100%"  border="0">
		<tr>
			<td align="center">
			<span class="titre_gras_soul">Message &agrave; envoyer
			 <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			</span>
			<span class="annot_std_it"><br>(Sujet : <?PHP echo $sujet; ?>)</span>
			</td>
		</tr>
		<tr>
			<td>
			<?PHP
				$sBasePath = $_SERVER['PHP_SELF'] ;
				switch (@$_SESSION["niv_log"])
				{
					case 5 :
					case 9 :
						$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "admin" ) ).'classes/fckeditor/' ;
						break;
					case 4 :
						$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "age" ) ).'classes/fckeditor/' ;
						break;
					case 6 :
						$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "do" ) ).'classes/fckeditor/' ;
						break;
					case 10 :
						$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "st" ) ).'classes/fckeditor/' ;
						break;
				}
				$oFCKeditor = new FCKeditor('FCKeditor1') ;
				$oFCKeditor->BasePath	= $sBasePath;
				$oFCKeditor->Value		= $txt;
				$oFCKeditor->Height 	= '400';
				$oFCKeditor->ToolbarSet = 'SMI';
				$oFCKeditor->Create();
			
			?>
		 </td>
		 </tr>
		 </table>
<?PHP
		}
		else
		{
			echo "Aucun technicien actif pour ces param&egrave;tres.";
		}
?>
		<p align="center">
		<?PHP if ($nbsel>0) { ?>
		<input name="envoi" type="submit" class="bton_std" id="envoi" value="<?PHP echo $but_exped; ?>">
		 <input name="RAZ" type="button" class="bton_std" id="RAZ" value="<?PHP echo $but_reinit; ?>" onClick="document.getElementById('sel').value=uncheckall(this.form);">
		<?PHP } ?>
		 <input name="init" type="button" class="bton_std" id="init" value="<?PHP echo $but_recomm; ?>" onClick="javascript:; self.location.href=('<?PHP echo $url_link; ?>');">		</p>
		</form>
		<!-- Fin du formulaire -->
<?PHP
		}
		break;
		default : break;
	}

	}
	else
	{
		if ($retourliste == TRUE)
		{
?>
			<script type="text/javascript">
			<!--
			setTimeout("self.location.href=('<?PHP echo "email_maj.php?td=".$td; ?>');",2000)
			//-->
			</script>
			<p align="center" class="annot_std_it">Email correctement exp&eacute;di&eacute;...</p>
<?PHP
		}
	}
}
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");
?>
