<?php

sleep(1);
if (array_key_exists("pays", $_REQUEST))
{
	$tomorrow = 0;//60*60*24; // en nb de secondes
	header("Cache-Control: max-age=$tomorrow");
	print_plain();
}
else
{
	print "Usage : $_SERVER[PHP_SELF]?pays=un-code-pays";
}

/** Récupération des départements couverts par les agences dans un pays donné **/

function print_plain()
{
	header("Content-type: text/html; charset=windows-1252");
	$dep = get_depzc($_REQUEST["pays"]);
	$result = array();
	// On se connecte a la base
	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	foreach ($dep as $row)
	{
		// On recupere les enregistrements
		$rech2 = "SELECT dep_nom FROM ".TBDEP." WHERE dep_code='".$row["zcc_codedep"]."' AND dep_codepays='".$row["zcc_codepays"]."'";
		$rs2 = mysql_query($rech2) or die(mysql_error());
		if ($row2 = mysql_fetch_array($rs2))
		{
			$result[] = $row["zcc_codedep"]."=".$row["zcc_codedep"]." (".$row2["dep_nom"].")";
		}
	}
	mysql_close();
	print implode(";", $result);
}

function get_depzc($pays)
{
	include_once("../inc/config.inc.php");
	include_once("../inc/func_txt.inc.php");
	// On se connecte a la base
	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	// On recupere les enregistrements
	$rech="SELECT DISTINCT zcc_codedep,zcc_codepays FROM ".TBZCC." WHERE `zcc_codepays`='".$pays."' ORDER BY zcc_codedep";
	$rs = mysql_query($rech) or die(mysql_error());
	// On cree le resultat
	$result = array();
	while($row = mysql_fetch_array($rs))
	{
		$result[] = $row;
	}
	mysql_close();
	return $result;
}

?>