<?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_pdt.inc.php");
include_once("../inc/fic_zc.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
Archivelog(@$_SESSION["code_log"]);

$export_ok = TRUE;
$retour_idx=FALSE;

$msg1_err_type=$ajx_noagact;

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

// Vérification du mode du connecté (pour éviter les hacks)
switch ($td)
{
	case "cli" :
	case "scli" :
		if (@$_SESSION["niv_log"] <= 3)
			$export_ok = FALSE;
		break;
	case "art" :
		// Les agences n'ont droit qu'aux exports clients et interventions
		if (@$_SESSION["niv_log"] <= 4)
			$export_ok = FALSE;
		break;
	default :
		$export_ok = FALSE;
		break;
}


if ($export_ok == TRUE)
{
	switch ($td)
	{
		case "cli" :
			$titre = "EXPORTATION CLIENTS";
			break;
		case "scli" :
			$titre = "EXPORTATION SITES CLIENTS";
			break;
		case "art" :
			$titre = "EXPORTATION ARTICLES";
			break;
		case "int" :
			$titre = "EXPORTATION INTERVENTIONS";
			break;
		default :
			$export_ok = FALSE;
			break;
	}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>SMI - <?PHP echo $title_esp_prive; ?> : Exportation</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 pour vérifications des formulaires -->
<script language="JavaScript" src="../jscript/verif_form.js"></script>

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

<?PHP if ((@$_SESSION["niv_log"] ==5) OR (@$_SESSION["niv_log"] ==9)) { ?>
<!-- Scripts Ajax -->
<script type="text/javascript" src="../ajax/util.js"></script>
<script type="text/javascript" src="../ajax/SelectUpdater.js"></script>

<script type="text/javascript">
<!--
function updateDep()
{
	ZCUpdater2 = new SelectUpdater("dep", "<?PHP echo $rep_appli.'/ajax/'; ?>recupdepzc.php?pays=", "attn1", "msg1", "<?PHP echo $msg1_err_type; ?>");
	anciencodepays = "";
	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
				ZCUpdater2.run(codepays);
				anciencodepays = codepays;
			}
		}
		else
		{
			// Remettre la liste a vide et annuler l'appel eventuel
			ZCUpdater2.reset();
			anciencodepays = "";
		}
	}
}
//-->
</script>
<?PHP } ?>

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

<?PHP
switch ($td)
{
	case "cli" :
	case "scli" :
?>
		<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 if (@$_SESSION["niv_log"] <> 4)
{
?>
			"nom:age ; format:liste ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_age); ?> ; 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",
<?PHP
}
else
{
?>
			"nom:age ; format:alphanum ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_age); ?> ; stok:frmok ; stbad:frmbad",
			"nom:pays ; format:alphanum ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_pays); ?> ; stok:frmok ; stbad:frmbad",
<?PHP
}
?>
			"nom:dep[] ; format:listem ; req:Y ; txt:Départements ; vmn:1 ; stok:frmok ; stbad:frmbad",
			"nom:champs[] ; format:checkbox ; req:Y ; txt:Champs ; stok:frmok ; stbad:frmbad");
		//-->
		</script>
<?PHP
		break;
	case "art" :
?>
		<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:fam[] ; format:listem ; req:N ; txt:Familles ; vmn:1 ; stok:frmok ; stbad:frmbad",
			"nom:champs[] ; format:checkbox ; req:Y ; txt:Champs ; stok:frmok ; stbad:frmbad");
		//-->
		</script>
<?PHP
		break;		
}
?>
</head>
<?PHP
switch (@$_SESSION["niv_log"])
{
	case 5 :
	case 9 :
		switch ($td)
		{
			case "cli" :
			case "scli" :
				echo '<body onLoad="metFocus();updateDep();">';
				break;
			default :
				echo '<body onLoad="metFocus();">';
				break;
		}
		break;
	default :
		echo '<body onLoad="metFocus();">';
		break;
}

include_once("../inc/entete.inc.php"); 
?>
<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<p>&nbsp;</p>
<?PHP
if ($export_ok == TRUE)
{
?>
	<!-- Formulaire permettant la sélection l'exportation -->
	<form name="exp_maj" id="exp_maj" method="post" action="export.php" onSubmit="javascript:; return (verif_exp(this,tab1_champ,'',''));">
		<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
		<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">

<?PHP				
	switch ($td)
	{
		/******************************************************/
		/**                    CLIENTS                       **/
		/******************************************************/
	
		case "cli" :
			if (nb_cli(""))
			{
			$url_link="exp_data.php?td=cli";
?>
			<!-- 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 width="160" class="rubfrm" id="f_age" align="right">Agence</td>
			  <td>
					<?PHP if (@$_SESSION["niv_log"] <> 4)
					{
					?>
						<select name="age" size="1" id="age">
						<?PHP
						
						echo "<option value=\"\">".$sel_lst_age."</option>";
	
						if ($age <> "*")
							echo "<option value=\"*\">-- TOUTES LES AGENCES --</option>";
						else
							echo "<option value=\"*\" selected>-- TOUTES LES AGENCES --</option>";
			
						// Création de la liste des agences
						$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
						mysql_select_db(DBNAME);
						$rs = mysql_query("SELECT * FROM ".TBAGE." WHERE `age_ouvert` = '1' ORDER BY age_nom");
						
						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>';
							}
				
							$i++;
						}
						mysql_free_result($rs);
						mysql_close($conn);
						?>
						</select>
					<?PHP
					}
					else
					{
						$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
					}
					?>
					  <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)
				{
					$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 ($cli_codepays == $pays_code)
							echo '<option value="'.$pays_code.'" selected>'.$pays_nom.'</option>\n';
						else
							echo '<option value="'.$pays_code.'">'.$pays_nom.'</option>\n';
					}
				?>
				</select>
				<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
				<?PHP
					mysql_close($conn);
				}
				else
				{
					$row=lit_enr_age(@$_SESSION["code_age"],TRUE);
					if (is_array($row))
						extract($row);
				?>
				<input name="pays" type="hidden" id="pays" value="<?PHP echo $age_codepays ?>">
				<input name="npays" type="text" id="npays" value="<?PHP echo str_majuscules(Retournepays_open($age_codepays,TRUE)); ?>" size="50" readonly="1">
				<?PHP
				}
				?>
				</td>
			</tr>
			<tr>
			<td width="160" class="rubfrm" id="f_dep" align="right">D&eacute;partement/R&eacute;gion</td>
			<td>
				<select name="dep[]" size="5" id="dep" multiple="multiple" onChange="aff_depex();">
			
				<?PHP
				echo "<option>".$sel_lst_makechx."</option>";
	
				// Création de la liste des départements
				if (@$_SESSION["niv_log"]==4)
				{
					$tab_zc=tab_zcc_age_open($_SESSION["code_age"],TRUE);
				
					if (count($tab_zc)>0)
					{
						$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
						mysql_select_db(DBNAME);
						foreach ($tab_zc as $idx=>$value)
						{
							$rs = mysql_query("SELECT * FROM ".TBDEP." WHERE `dep_code` = '".$value."'");
							if ($resultat = mysql_fetch_array($rs)) 
							{
								extract($resultat);
								$chaine_dep = $dep_code." (".$dep_nom.")";
								echo "<option value=\"".$dep_code."\">".$chaine_dep."</option>";
							}
						}
						mysql_free_result($rs);
						mysql_close($conn);
					}
				}
				?>
				</select>
				<span class="annot_petit_it">
				<?PHP
					if (@$_SESSION["niv_log"] == 4)
						echo "(D&eacute;partements couverts par votre agence)";
					else
						echo "(D&eacute;partements couverts par les agences)"; 
				?>
				</span>
				<?PHP if (@$_SESSION["niv_log"]<>4) { ?>
				<br>
				 <span id="attn1"></span><span id="msg1" style="background-color:#FF0000; color:#FFFF00; font-weight:bold"><?PHP echo htmlspecialchars($msg1_err_type); ?></span>
				 <?PHP } ?>
				 <span class="annot_petit_it">
				 <br>
				  (S&eacute;lectionnez les d&eacute;partements avec Ctrl + clic gauche)
				 <br>
				 D&eacute;partement(s) choisi(s) 
				 <input name="deptxt" type="text" id="deptxt" value="<?PHP echo $dep ?>" size="50" readonly="1" style="background : #FFFFFF;" onFocus="window.document.exp_maj.ligtitre.focus();">
				 </span>
				<br>
				<span class="annot_petit_it">(Num&eacute;ros de d&eacute;partements, s&eacute;par&eacute;s par des '_')</span>				</td>
			</tr>
			</table>
			<br>
<?PHP
			}
			else
				$retouridx=TRUE;
			break;

		/******************************************************/
		/**                 SITES CLIENTS                    **/
		/******************************************************/
	
		case "scli" :
			if (nb_scli("","",TRUE))
			{
			$url_link="exp_data.php?td=scli";
?>
			<!-- 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 width="160" class="rubfrm" id="f_age" align="right">Agence</td>
			  <td>
					<?PHP if (@$_SESSION["niv_log"] <> 4)
					{
					?>
						<select name="age" size="1" id="age">
						<?PHP
						
						echo "<option value=\"\">".$sel_lst_age."</option>";
	
						if ($age <> "*")
							echo "<option value=\"*\">-- TOUTES LES AGENCES --</option>";
						else
							echo "<option value=\"*\" selected>-- TOUTES LES AGENCES --</option>";
			
						// Création de la liste des agences
						$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
						mysql_select_db(DBNAME);
						$rs = mysql_query("SELECT * FROM ".TBAGE." WHERE `age_ouvert` = '1' ORDER BY age_nom");
						
						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>';
							}
				
							$i++;
						}
						mysql_free_result($rs);
						mysql_close($conn);
						?>
						</select>
					<?PHP
					}
					else
					{
						$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
					}
					?>
					  <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)
				{
					$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 ($cli_codepays == $pays_code)
							echo '<option value="'.$pays_code.'" selected>'.$pays_nom.'</option>\n';
						else
							echo '<option value="'.$pays_code.'">'.$pays_nom.'</option>\n';
					}
				?>
				</select>
				<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
				<?PHP
					mysql_close($conn);
				}
				else
				{
					$row=lit_enr_age(@$_SESSION["code_age"],TRUE);
					if (is_array($row))
						extract($row);
				?>
				<input name="pays" type="hidden" id="pays" value="<?PHP echo $age_codepays ?>">
				<input name="npays" type="text" id="npays" value="<?PHP echo str_majuscules(Retournepays_open($age_codepays,TRUE)); ?>" size="50" readonly="1">
				<?PHP
				}
				?>
				</td>
			</tr>
			<tr>
			<td width="160" class="rubfrm" id="f_dep" align="right">D&eacute;partement/R&eacute;gion</td>
			<td>
				<select name="dep[]" size="5" id="dep" multiple="multiple" onChange="aff_depex();">
			
				<?PHP
				echo "<option>".$sel_lst_makechx."</option>";
	
				// Création de la liste des départements
				if (@$_SESSION["niv_log"]==4)
				{
					$tab_zc=tab_zcc_age_open($_SESSION["code_age"],TRUE);
				
					if (count($tab_zc)>0)
					{
						$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
						mysql_select_db(DBNAME);
						foreach ($tab_zc as $idx=>$value)
						{
							$rs = mysql_query("SELECT * FROM ".TBDEP." WHERE `dep_code` = '".$value."'");
							if ($resultat = mysql_fetch_array($rs)) 
							{
								extract($resultat);
								$chaine_dep = $dep_code." (".$dep_nom.")";
								echo "<option value=\"".$dep_code."\">".$chaine_dep."</option>";
							}
						}
						mysql_free_result($rs);
						mysql_close($conn);
					}
				}
				?>
				</select>
				<span class="annot_petit_it">
				<?PHP
					if (@$_SESSION["niv_log"] == 4)
						echo "(D&eacute;partements couverts par votre agence)";
					else
						echo "(D&eacute;partements couverts par les agences)"; 
				?>
				</span>
				<?PHP if (@$_SESSION["niv_log"]<>4) { ?>
				<br>
				 <span id="attn1"></span><span id="msg1" style="background-color:#FF0000; color:#FFFF00; font-weight:bold"><?PHP echo htmlspecialchars($msg1_err_type); ?></span>
				 <?PHP } ?>
				 <span class="annot_petit_it">
				 <br>
				  (S&eacute;lectionnez les d&eacute;partements avec Ctrl + clic gauche)
				 <br>
				 D&eacute;partement(s) choisi(s) 
				 <input name="deptxt" type="text" id="deptxt" value="<?PHP echo $dep ?>" size="50" readonly="1" style="background : #FFFFFF;" onFocus="window.document.exp_maj.ligtitre.focus();">
				 </span>
				<br>
				<span class="annot_petit_it">(Num&eacute;ros de d&eacute;partements, s&eacute;par&eacute;s par des '_')</span>				</td>
			</tr>
			</table>
			<br>
<?PHP
			}
			else
				$retouridx=TRUE;
			break;

		/******************************************************/
		/**                    ARTICLES                      **/
		/******************************************************/
	
		case "art" :
			if (nb_pdt()>0)
			{
			$url_link="exp_data.php?td=art";
?>
			<!-- 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">
					<option>-- Choisissez une catégorie --</option>
					<option value="*">-- TOUS LES ARTICLES --</option>
					<option value="1">Vendus</option>
					<option value="0">Non vendus</option>
					</select>
					  <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
				</td>
			</tr>
			<tr>
			<td width="160" class="rubfrm" id="f_dep" align="right">Famille(s)</td>
			<td>
				<select name="fam[]" size="5" id="fam" multiple="multiple" onChange="aff_famex();">
			
				<?PHP
				echo "<option>-- Choisissez une ou des familles --</option>";
	
				// Création de la liste des familles
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
				$rs = mysql_query("SELECT * FROM ".TBFAM." ORDER BY fam_desc");
				
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
					
					if (exist_chaine_in_seq($fam_code,$fam) == TRUE)
						echo "<option value=\"".$fam_code."\" selected>".$fam_desc."</option>";
					else
						echo "<option value=\"".$fam_code."\">".$fam_desc."</option>";
					
					$i++;
				}
				mysql_free_result($rs);
				mysql_close($conn);
				?>
				</select>
				 <span class="annot_petit_it">
				  (S&eacute;lectionnez les familles avec Ctrl + clic gauche)
				 <br>
				 Famille(s) choisie(s) 
				 <input name="famtxt" type="text" id="famtxt" value="<?PHP echo $fam ?>" size="50" readonly="1" style="background : #FFFFFF;" onFocus="window.document.age_maj.sujet.focus();">
				 </span>
				<br>
				<span class="annot_petit_it">(Codes familles, s&eacute;par&eacute;s par des '-')</span>				</td>
			</tr>
			</table>
			<br>
<?PHP
			}
			else
				$retouridx=TRUE;
		default : break;
	}
	
	if ($retouridx==FALSE)
	{
?>
	<table width="100%"  border="0">
	<tr>
	<td colspan="5">
	  <div align="center" class="titre_std_gras_jaune_frouge">Champs &agrave; exporter </div>
	</td>
	</tr>
	<?PHP
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			switch ($td)
			{
				case "cli" :
					$rech = "SELECT * FROM `" .TBCLI. "`";
					break;
				case "scli" :
					$rech = "SELECT * FROM `" .TBSCLI. "`";
					break;
				case "art" :
					$rech = "SELECT * FROM `" .TBPDT. "`";
					break;
				case "int" :
					$rech = "SELECT * FROM `" .TBINT. "`";
					break;
			}
			$rs = mysql_query($rech)or die(mysql_error());
			$num = mysql_num_fields($rs);
			$i = 0;
			while ($i<$num) 
			{
				echo "<tr>";
				$j=0;
				while (($j<5) AND ($i<$num))
				{
					$nom = mysql_field_name($rs,$i);
					$aexporter=TRUE;
					switch ($td)
					{
						/******************************************************/
						/**                    CLIENTS                       **/
						/******************************************************/
					
						case "cli" :
							if (@$_SESSION["niv_log"] == 5)
							{
								if (($nom=="cli_id") OR ($nom=="cli_pass"))
									$aexporter=FALSE;
							}
							if (@$_SESSION["niv_log"] == 4)
							{
								if (($nom=="cli_id") OR ($nom=="cli_prop") OR ($nom=="cli_codedo") OR ($nom=="cli_codecrea") OR ($nom=="cli_codemod") OR ($nom=="cli_pass") OR ($nom=="cli_notaa"))
									$aexporter=FALSE;
							}
							if ($aexporter==TRUE)
							{
								$id_champ="f_".$nom;
								$nom_champ="cb_".$nom;
								echo "<td width=\"20%\" id=\"".$id_champ."\">";
								echo "<input type=\"checkbox\" name=\"champs[]\" value=\"".$nom."\" style=\"background : #FFFFFF;\" checked>";
								echo $nom;
								if ($nom=="cli_ville")
									echo " (CP + Ville)";
								$j++;
							}
							break;
						/******************************************************/
						/**                 SITES CLIENTS                    **/
						/******************************************************/
					
						case "scli" :
							if (@$_SESSION["niv_log"] == 5)
							{
								if ($nom=="scli_id")
									$aexporter=FALSE;
							}
							if (@$_SESSION["niv_log"] == 4)
							{
								if ($nom=="scli_id")
									$aexporter=FALSE;
							}
							if ($aexporter==TRUE)
							{
								$id_champ="f_".$nom;
								$nom_champ="cb_".$nom;
								echo "<td width=\"20%\" id=\"".$id_champ."\">";
								echo "<input type=\"checkbox\" name=\"champs[]\" value=\"".$nom."\" style=\"background : #FFFFFF;\" checked>";
								echo $nom;
								if ($nom=="scli_ville")
									echo " (CP + Ville)";
								$j++;
							}
							break;
						/******************************************************/
						/**                    ARTICLES                      **/
						/******************************************************/
					
						case "art" :
							if (@$_SESSION["niv_log"] == 5)
							{
								if ($nom=="pdt_id")
									$aexporter=FALSE;
							}
							if ($aexporter==TRUE)
							{
								$id_champ="f_".$nom;
								$nom_champ="cb_".$nom;
								echo "<td width=\"20%\" id=\"".$id_champ."\">";
								echo "<input type=\"checkbox\" name=\"champs[]\" value=\"".$nom."\" style=\"background : #FFFFFF;\" checked>";
								echo $nom;
								$j++;
							}
							break;
					}
					$i++;
					echo "</td>";
				}
				// On ferme la ligne uniquement si dernière colonne atteinte
				if ($j==5)
					echo "</tr>";
			}
			mysql_free_result($rs);
			mysql_close($conn);

			// On fini la ligne si pas sur dernière colonne
			if ($j<5)
			{
				for ($k = $j; $k < 5; $k++) 
				{
					echo "<td width=\"20%\" id=\"\">";
					echo "&nbsp;";
					echo "</td>";
				}
				echo "</tr>";
			}
		?>
	</table>
	<br>
	<table width="100%"  border="0">
	<tr>
	<td colspan="2">
	  <div align="center" class="titre_std_gras_jaune_frouge">Param&egrave;tres d'exportation </div>
	</td>
	</tr>
	<tr>
		<td width="30%" class="rubfrm" id="f_ligtitre" align="right">Nom des champs en 1&egrave;re ligne  </td>
		<td>
			<select name="ligtitre" id="ligtitre">
			  <option value="O" selected="selected"><?PHP echo $sel_lst_oui; ?></option>
			  <option value="N"><?PHP echo $sel_lst_non; ?></option>
			</select>					  
			<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		</td>
	</tr>
	<tr>
		<td width="160" class="rubfrm" id="f_cadre" align="right">Champs encadr&eacute;s par </td>
		<td>
			<select name="cadre" id="cadre">
			  <option value="G" selected="selected">Guillemets (&quot;)</option>
			  <option value="A">Apostrophes (')</option>
			  <option value="R">Rien</option>
			</select>					  
			<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		</td>
	</tr>
	<tr>
		<td width="160" class="rubfrm" id="f_sep" align="right">Champs s&eacute;par&eacute;s par des</td>
		<td>
			<select name="sep" id="sep">
			  <option value="P" selected="selected">Points Virgules (;)</option>
			  <option value="V">Virgules (,)</option>
			</select>					  
			<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		</td>
	</tr>
	<tr>
		<td width="160" class="rubfrm" id="f_sep" align="right">Lignes termin&eacute;es par </td>
		<td>
			<select name="fl" id="fl">
			  <option value="N" selected="selected">\n</option>
			  <option value="R">\r</option>
			  <option value="RN">\r\n</option>
			</select>					  
			<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">	
		</td>
	</tr>
	</table>
	<div align="center" id="boutons" style="display:block">
		<input name="exp" type="submit" class="bton_std" id="exp" value="Exporter">
		<input name="RAZ" type="reset" class="bton_std" id="RAZ" value="<?PHP echo $but_reinit; ?>">
		<input name="quit" type="button" class="bton_std" id="quit" value="<?PHP echo $but_quit; ?>" onClick="javascript:; self.location.href=('index.php');">
	</div>
	<div align="center" id="patience" style="display:none">Merci de patienter...<br>Cliquez <a href="<?PHP echo $url_link;?>">ici</a> pour recommencer.</div>
	</form>
	<!-- Fin du formulaire -->
<?PHP
	}
	else
	{
?>
	<script type="text/javascript">
	<!--
	setTimeout("self.location.href=('index.php');",2000)
	//-->
	</script>
	<p align="center" class="annot_std_it">Pas d'enregistrements...</p>
<?PHP
	}
}
else
{
?>
	<script type="text/javascript">
	<!--
	setTimeout("self.location.href=('index.php');",2000)
	//-->
	</script>
	<p align="center" class="annot_std_it">Type d'exportation incorrect...</p>
<?PHP
}
include_once("pied.php");
?>
