<?PHP


// 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");


/***************************/
/*   Zones de chalandise   */
/***************************/

// Vérifie si un département fait partie d'une zone de chalandise dans un pays donné
function dep_in_zcc_pays_open($dep,$pays,$openfic)
{
	$est_ok = FALSE;
	if ($openfic==TRUE)
	{
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	}
	$rdep="SELECT * FROM ".TBZCC." WHERE `zcc_codepays`='".$pays."' AND `zcc_codedep`='".$dep."'";
	$rsdep = mysql_query($rdep) or die(mysql_error());
	if (mysql_num_rows($rsdep) >0)
		$est_ok=TRUE;
	if ($openfic==TRUE)
		mysql_close($conn2);  
	return $est_ok;
}

// Vérifie si un département fait partie d'une zone de chalandise d'une agence
function dep_in_zcc_age_open($dep,$pays,$age,$openfic)
{
	$est_ok = FALSE;
	if ($openfic==TRUE)
	{
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	}
	$rdep="SELECT * FROM ".TBZCC." WHERE `zcc_codepays`='".$pays."' AND `zcc_codedep`='".$dep."' AND `zcc_code`='".$age."'";
	$rsdep = mysql_query($rdep) or die(mysql_error());
	if (mysql_num_rows($rsdep) >0)
		$est_ok=TRUE;
	if ($openfic==TRUE)
		mysql_close($conn2);  
	return $est_ok;
}

// Crée le texte des zones de chalandise d'une agence
function str_zcc_age_open($age,$openfic)
{
	$str_zcc = "";
	if ($openfic==TRUE)
	{
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	}
	$rech="SELECT * FROM ".TBZCC." WHERE `zcc_code`='".$age."' ORDER BY zcc_codedep";
	$rs = mysql_query($rech) or die(mysql_error());
	if (mysql_num_rows($rs) >0)
	{
		while ($row = mysql_fetch_assoc($rs)) 
		{
			$str_zcc.=$row["zcc_codedep"]."_";
		}
	}
	if ($openfic==TRUE)
		mysql_close($conn2);  
	if ($str_zcc!="")
		$str_zcc = substr($str_zcc,0,strlen($str_zcc)-1);
	return $str_zcc;
}

// Crée un tableau des départements couverts par une agence
function tab_zcc_age_open($age,$openfic)
{
	$tab_zcc = array();
	if ($openfic==TRUE)
	{
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	}
	$rech="SELECT DISTINCT zcc_codedep FROM ".TBZCC." WHERE `zcc_code`='".$age."' ORDER BY zcc_codedep";
	$rs = mysql_query($rech) or die(mysql_error());
	if (mysql_num_rows($rs) >0)
	{
		while ($row = mysql_fetch_assoc($rs)) 
		{
			if (!in_array(trim($row["zcc_codedep"]),$tab_zcc))
				$tab_zcc[]=$row["zcc_codedep"];
		}
	}
	if ($openfic==TRUE)
		mysql_close($conn2);
	return $tab_zcc;
}

// Crée un tableau des départements couverts sur un pays
function tab_zcc_pays_open($pays,$openfic)
{
	$tab_zcc = array();
	if ($openfic==TRUE)
	{
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	}
	$rech="SELECT DISTINCT zcc_codedep FROM ".TBZCC." WHERE `zcc_codepays`='".$pays."' ORDER BY zcc_codedep";
	$rs = mysql_query($rech) or die(mysql_error());
	if (mysql_num_rows($rs) >0)
	{
		while ($row = mysql_fetch_assoc($rs)) 
		{
			if (!in_array(trim($row["zcc_codedep"]),$tab_zcc))
				$tab_zcc[]=$row["zcc_codedep"];
		}
	}
	if ($openfic==TRUE)
		mysql_close($conn2);
	return $tab_zcc;
}

?>