<?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 couvertes (Ss-Traitants)  */
/*************************************/

// Vérifie si un département fait partie d'une zone couverte dans un pays donné
function dep_in_zoc_pays_open($dep,$pays,$openfic)
{
	$est_ok = FALSE;
	if ($openfic==TRUE)
	{
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	}
	$rdep="SELECT * FROM ".TBZOC." WHERE `zoc_codepays`='".$pays."' AND `zoc_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 couverte d'un sous-traitant
function dep_in_zoc_st_open($dep,$pays,$st,$openfic)
{
	$est_ok = FALSE;
	if ($openfic==TRUE)
	{
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	}
	$rdep="SELECT * FROM ".TBZOC." WHERE `zoc_codepays`='".$pays."' AND `zoc_codedep`='".$dep."' AND `zoc_code`='".$st."'";
	$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 couvertes d'un sous-traitant
function str_zoc_st_open($st,$openfic)
{
	$str_zoc = "";
	if ($openfic==TRUE)
	{
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	}
	$rech="SELECT * FROM ".TBZOC." WHERE `zoc_code`='".$st."' ORDER BY zoc_codedep";
	$rs = mysql_query($rech) or die(mysql_error());
	if (mysql_num_rows($rs) >0)
	{
		while ($row = mysql_fetch_assoc($rs)) 
		{
			$str_zoc.=$row["zoc_codedep"]."_";
		}
	}
	if ($openfic==TRUE)
		mysql_close($conn2);  
	if ($str_zoc!="")
		$str_zoc = substr($str_zoc,0,strlen($str_zoc)-1);
	return $str_zoc;
}

// Crée un tableau des départements couverts par un sous-traitant
function tab_zoc_st_open($st,$openfic)
{
	$tab_zoc = array();;
	if ($openfic==TRUE)
	{
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	}
	$rech="SELECT DISTINCT zoc_codedep FROM ".TBZOC." WHERE `zoc_code`='".$st."' ORDER BY zoc_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["zoc_codedep"]),$tab_zoc))
				$tab_zoc[]=$row["zoc_codedep"];
		}
	}
	if ($openfic==TRUE)
		mysql_close($conn2);
	return $tab_zoc;
}

// Crée un tableau des départements couverts sur un sous-traitant
function tab_zoc_pays_open($pays,$openfic)
{
	$tab_zoc = array();;
	if ($openfic==TRUE)
	{
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	}
	$rech="SELECT DISTINCT zoc_codedep FROM ".TBZOC." WHERE `zoc_codepays`='".$pays."' ORDER BY zoc_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["zoc_codedep"]),$tab_zoc))
				$tab_zoc[]=$row["zoc_codedep"];
		}
	}
	if ($openfic==TRUE)
		mysql_close($conn2);
	return $tab_zoc;
}

?>