<?php
function connectionBD()
{
mysql_connect("localhost","root","");
mysql_select_db("motscles");
}
function deconnectionBD()
{
mysql_close();
}
// cette fonction sert à afficher un message expliquant l'erreur ou le succès d'une opération, et à rediriger l'utilisateur
function redirection($message,$page,$statut)
{
if ($statut==0)
echo '<span class="msucces">'.$message.' Vous allez être redirigé...</span>';
else
echo '<span class="merreur">'.$message.' Vous allez être redirigé...</span>';
header("Refresh: 3;url=$page");
}
function ajoutMotsClesBD($liste)
{
$i=0;
$tabMotsCles=boucler($liste, "keyword_text");
$ok=true;
if(!is_dir("bd"))
mkdir("bd");
$base = fopen ("bd/motscles.txt", "a+");
fseek ($base, 0);
$tabCmp=array();
while(!feof($base))
{
array_push($tabCmp, fgets($base));
}
foreach($tabMotsCles as $motcle)
{
$ok=true;
if(count($tabCmp)>0)
{
foreach($tabCmp as $comp)
{
$comp=substr($comp,0,strlen($comp)-1);
if(ereg("Firefox/", $_SERVER["HTTP_USER_AGENT"]))
$motcle=htmlentities(utf8_decode($motcle));
else if(ereg("MSIE", $_SERVER["HTTP_USER_AGENT"]))
$motcle=htmlspecialchars_decode(htmlentities($motcle));
// le test de comparaison est different selon le navigateur
if(strcmp($comp, $motcle)==0)
{
$ok=false;
break;
}
}
}
if($ok==true)
{ fputs($base, $motcle);
fputs($base, chr(10));
}
}
fclose ($base);
chmod("bd/motscles.txt", 0777);
//chown("bd/motscles.txt", "info");
}
function recupListe()
{
if(is_dir("bd")) // test si le repertoire "bd" existe, et donc si des mots-cles ont deja ete ajoute a la base
{
if(file_exists("bd/motscles.txt"))
{
$base=fopen("bd/motscles.txt","r");
$tabMotsCles=array();
while(!feof($base))
{
array_push($tabMotsCles,fgets($base));
}
fclose($base);
usort($tabMotsCles, "strcasecmp"); // tri alphabetique
array_shift($tabMotsCles); // supprime la premiere valeur du tableau, qui est nulle apres le tri
foreach($tabMotsCles as $motcle)
{
echo "<option>".$motcle."</option>";
}
}
}
else
{
echo "<optgroup label='(Aucun mots-clés dans la base)'></optgroup>";
}
}
function convertChar($tab)
{
$tabRes=array();
foreach($tab as $int=>$val)
{
$tabRes[$int]=preg_replace("/\\\'/", "'", $val);
}
return $tabRes;
}
/* ********************************************************
*********** ***********
*********** fonctions de construction ***********
*********** de la metadonnee ***********
*********** ***********
******************************************************** */
function buildXML($racine, $nom_fichier, $nom_dossier, $_POST)
{
/* ======== creation du fichier .xml ======== */
$doc = new DomDocument('1.0','UTF-8');
$doc->formatOutput=TRUE;
/* ====== creation de l'element racine ====== */
$metadata=$doc->createElement('gmd:MD_Metadata');
$doc->appendChild($metadata);
$tab_attr_metadata=array(
'xmlns:gmd'=>'http://www.isotc211.org/2005/gmd',
'xmlns:xsi'=>'http://www.w3.org/2001/XMLSchema-instance',
'xmlns:fra'=>'http://www.cnig.gouv.fr/2005/fra',
'xmlns:gco'=>'http://www.isotc211.org/2005/gco',
'xmlns:gts'=>'http://www.isotc211.org/2005/gts',
'xmlns:gml'=>'http://www.opengis.net/gml',
'xmlns:gfc'=>'http://www.isotc211.org/2005/gfc',
'xmlns:gmx'=>'http://www.isotc211.org/2005/gmx',
'xmlns:xlink'=>'http://www.w3.org/1999/xlink',
'xmlns:gmi'=>'http://www.isotc211.org/2005/gmi');
foreach($tab_attr_metadata as $attr=>$valeur)
setAttribut($attr, $valeur, $metadata, $doc);
/* =========================================== */
/* ============= creation du XML ============= */
$fileIdentifier=nouvelElement("gmd:fileIdentifier", $metadata, $doc); // identifiant de la metadonnee
setElement("", "stringVide", $fileIdentifier, $doc);
$language_md=nouvelElement("gmd:language", $metadata, $doc); // langue de la metadonnee
setElement($_POST['gmd:language_metadonnee'], "string", $language_md, $doc);
$characterSet=nouvelElement("gmd:characterSet", $metadata, $doc); // jeu de caractere
$MD_CharacterSetCode=nouvelElement("gmd:MD_CharacterSetCode", $characterSet, $doc);
setCodeList("utf8", "./resources/codeList.xml#MD_CharacterSetCode", $MD_CharacterSetCode, $doc);
$hierarchyLevel=nouvelElement("gmd:hierarchyLevel", $metadata, $doc); // type de donnee
$MD_ScopeCode=nouvelElement("gmd:MD_ScopeCode", $hierarchyLevel, $doc);
$tempo=explode("_",$_POST['gmd:hierarchyLevel']);
setCodeList($tempo[0], "http://www.isotc211.org/2005/resources/codeList.xml#MD_ScopeCode", $MD_ScopeCode, $doc);
$hierarchyLevelName=nouvelElement("gmd:hierarchyLevelName", $metadata, $doc);
setElement(getHierarchy($_POST['gmd:hierarchyLevel']), "string", $hierarchyLevelName, $doc);
setContact($_POST, $metadata, "md", $doc); // contact metadonnee
$dateStamp=nouvelElement("gmd:dateStamp", $metadata, $doc); // date creation metadonnee
setElement(getDateTime($_POST['gmd:dateStamp']), "date", $dateStamp, $doc);
$metadataStandardName=nouvelElement("gmd:metadataStandardName", $metadata, $doc); // on precise le standard
setElement("ISO 19115:2003/19139", "string", $metadataStandardName, $doc);
setTypeGeometrie($_POST, $metadata, $doc); // ajoute le champs "type de geometrie" s'il a lieu d'etre
if(isset($_POST['gmd:denominator']))
{
/* *** systeme de projection pour une metadonnee geographique *** */
$referenceSystemInfo=nouvelElement("gmd:referenceSystemInfo", $metadata, $doc);
$FRA_DirectReferenceSystem=nouvelElement("fra:FRA_DirectReferenceSystem", $referenceSystemInfo, $doc);
setAttribut("gco:isoType", "gmd:MD_ReferenceSystem", $FRA_DirectReferenceSystem, $doc);
$referenceSystemIdentifier=nouvelElement("gmd:referenceSystemIdentifier", $FRA_DirectReferenceSystem, $doc);
$geo_RS_Identifier=nouvelElement("gmd:RS_Identifier", $referenceSystemIdentifier, $doc);
$geo_RS_Code=nouvelElement("gmd:code", $geo_RS_Identifier, $doc);
setElement(getSystemeProj($_POST), "string", $geo_RS_Code, $doc);
$geo_RS_Version=nouvelElement("gmd:version", $geo_RS_Identifier, $doc);
setAttribut("gco:nilReason", "missing", $geo_RS_Version, $doc);
setElement("", "stringVide", $geo_RS_Version, $doc);
}
else
{
/* *** identifiant geographique pour une metadonnee statistique *** */
$referenceSystemInfo=nouvelElement("gmd:referenceSystemInfo", $metadata, $doc);
$MD_ReferenceSystem=nouvelElement("gmd:MD_ReferenceSystem", $referenceSystemInfo, $doc);
$referenceSystemIdentifier=nouvelElement("gmd:referenceSystemIdentifier", $MD_ReferenceSystem, $doc);
$stat_RS_Identifier=nouvelElement("gmd:RS_Identifier", $referenceSystemIdentifier, $doc);
$authority=nouvelElement("gmd:authority", $stat_RS_Identifier, $doc);
$stat_CI_Citation=nouvelElement("gmd:CI_Citation", $authority, $doc);
$stat_title=nouvelElement("gmd:title", $stat_CI_Citation, $doc);
setElement($_POST['gmd:authority_stat'], "string", $stat_title, $doc);
$stat_date=nouvelElement("gmd:date", $stat_CI_Citation, $doc);
$stat_CI_Date=nouvelElement("gmd:CI_Date", $stat_date, $doc);
$stat_sousdate=nouvelElement("gmd:date", $stat_CI_Date, $doc);
setElement(getDateTime("01","01",$_POST['gmd:version_stat']), "date", $stat_sousdate, $doc);
$stat_dateType=nouvelElement("gmd:dateType", $stat_CI_Date, $doc);
$stat_CI_DateTypeCode=nouvelElement("gmd:CI_DateTypeCode", $stat_dateType, $doc);
setCodeList("http://www.isotc211.org/2005/resources/codeList.xml#CI_DateTypeCode", "publication", $stat_CI_DateTypeCode, $doc);
$stat_code=nouvelElement("gmd:code", $stat_RS_Identifier, $doc);
setElement($_POST['gmd:code_stat'], "string", $stat_code, $doc);
$stat_version=nouvelElement("gmd:version", $stat_RS_Identifier, $doc);
setElement($_POST['gmd:version_stat'], "string", $stat_version, $doc);
}
$identificationInfo=nouvelElement("gmd:identificationInfo", $metadata, $doc);
$FRA_DataIdentification=nouvelElement("fra:FRA_DataIdentification", $identificationInfo, $doc);
setAttribut("gco:isoType", "gmd:MD_DataIdentification", $FRA_DataIdentification, $doc);
$citation=nouvelElement("gmd:citation", $FRA_DataIdentification, $doc);
$CI_Citation=nouvelElement("gmd:CI_Citation", $citation, $doc);
$title=nouvelElement("gmd:title", $CI_Citation, $doc); // Intitule
setElement($_POST['gmd:title'], "string", $title, $doc);
setDate($_POST, "creation", $CI_Citation, $doc); // Date de creation de la donnee
setDate($_POST, "revision", $CI_Citation, $doc); // Date de derniere modification
$ident_identifier=nouvelElement("gmd:identifier", $CI_Citation, $doc);
$ident_MD_Identifier=nouvelElement("gmd:MD_Identifier", $ident_identifier, $doc);
$ident_code=nouvelElement("gmd:code", $ident_MD_Identifier, $doc);
setElement($_POST['gmd:title_inspire'], "string", $ident_code, $doc);
// titre conformite
$abstract=nouvelElement("gmd:abstract", $FRA_DataIdentification, $doc); // Description resumee
setElement($_POST['gmd:abstract'], "string", $abstract, $doc);
/* contact(s) "donnee" */
setContact($_POST, $FRA_DataIdentification, "d", $doc);
if(isset($_POST['gmd:individualName_d2']))
setContact($_POST, $FRA_DataIdentification, "d2", $doc);
if(isset($_POST['gmd:individualName_d3']))
setContact($_POST, $FRA_DataIdentification, "d3", $doc);
/* *** */
$resourceMaintenance=nouvelElement("gmd:resourceMaintenance", $FRA_DataIdentification, $doc);
$MD_MaintenanceInformation=nouvelElement("gmd:MD_MaintenanceInformation", $resourceMaintenance, $doc);
$maintenanceAndUpdateFrequency=nouvelElement("gmd:maintenanceAndUpdateFrequency", $MD_MaintenanceInformation, $doc);
$MD_MaintenanceFrequencyCode=nouvelElement("gmd:MD_MaintenanceFrequencyCode", $maintenanceAndUpdateFrequency, $doc);
setCodeList($_POST['gmd:maintenanceAndUpdateFrequency'], "http://www.isotc211.org/2005/resources/codeList.xml#MD_MaintenanceFrequencyCode", $MD_MaintenanceFrequencyCode, $doc);
setMotsCles($_POST, $FRA_DataIdentification, $doc); // Mots Cles
setContraintes($_POST, $FRA_DataIdentification, "metadonnee", $doc);// Contraintes metadonnees
setContraintes($_POST, $FRA_DataIdentification, "donnee", $doc); // Contraintes donnees + diffusion autorisee
$spatialRepresentationType=nouvelElement("gmd:spatialRepresentationType", $FRA_DataIdentification, $doc);
$MD_SpatialRepresentationTypeCode=nouvelElement("gmd:MD_SpatialRepresentationTypeCode", $spatialRepresentationType, $doc); // Representation spatiale
setCodeList($_POST['gmd:spatialRepresentationType'], "http://www.isotc211.org/2005/resources/codeList.xml#MD_SpatialRepresentationTypeCode", $MD_SpatialRepresentationTypeCode, $doc);
if(isset($_POST['gmd:denominator']))
{
$spatialResolution=nouvelElement("gmd:spatialResolution", $FRA_DataIdentification, $doc);
$MD_Resolution=nouvelElement("gmd:MD_Resolution", $spatialResolution, $doc);
$distance=nouvelElement("gmd:distance", $MD_Resolution, $doc); // Precision
$sousdistance=$doc->createElement('gco:Distance');
setAttribut("uom", "metres", $sousdistance, $doc);
$cont=$doc->createTextNode($_POST['gmd:distance']);
$sousdistance->appendChild($cont);
$distance->appendChild($sousdistance);
}
$language_d=nouvelElement("gmd:language", $FRA_DataIdentification, $doc); // Langue donnee
setElement($_POST['gmd:language_donnee'], "string", $language_d, $doc);
setThematiques($_POST, $FRA_DataIdentification, $doc);
$extent=nouvelElement("gmd:extent", $FRA_DataIdentification, $doc);
$EX_Extent=nouvelElement("gmd:EX_Extent", $extent, $doc);
setEmprise($_POST, $EX_Extent, $doc); // Emprise
$distributionInfo=nouvelElement("gmd:distributionInfo", $metadata, $doc);
$MD_Distribution=nouvelElement("gmd:MD_Distribution", $distributionInfo, $doc);
$distributionFormat=nouvelElement("gmd:distributionFormat", $MD_Distribution, $doc);
$MD_Format=nouvelElement("gmd:MD_Format", $distributionFormat, $doc);
/* *** nom, version et format de la donnee *** */
$format_name=nouvelElement("gmd:name", $MD_Format, $doc);
setElement($_POST['gmd:title'], "string", $format_name, $doc);
$format_version=nouvelElement("gmd:version", $MD_Format, $doc);
setElement(
getDateTime($_POST['gmd:date_jour_revision'],
$_POST['gmd:date_mois_revision'],
$_POST['gmd:date_annee_revision']),
"string", $format_version, $doc);
$format_specification=nouvelElement("gmd:specification", $MD_Format, $doc);
setElement(setFormatSpecification($_POST), "string", $format_specification, $doc);
/* *** *** */
$transferOptions=nouvelElement("gmd:transferOptions", $MD_Distribution, $doc);
$MD_DigitalTransferOptions=nouvelElement("gmd:MD_DigitalTransferOptions", $transferOptions, $doc);
setLiens($_POST, $MD_DigitalTransferOptions, $doc);
$dataQualityInfo=nouvelElement("gmd:dataQualityInfo", $metadata, $doc);
$DQ_DataQuality=nouvelElement("gmd:DQ_DataQuality", $dataQualityInfo, $doc);
$scope=nouvelElement("gmd:scope", $DQ_DataQuality, $doc);
$DQ_Scope=nouvelElement("gmd:DQ_Scope", $scope, $doc);
$scope_level=nouvelElement("gmd:level", $DQ_Scope, $doc);
$quality_MD_ScopeCode=nouvelElement("gmd:MD_ScopeCode", $scope_level, $doc);
setCodeList("dataset", "http://www.isotc211.org/2005/resources/codeList.xml#MD_ScopeCode", $quality_MD_ScopeCode, $doc);
$report=nouvelElement("gmd:report", $DQ_DataQuality, $doc);
$DQ_DomainConsistency=nouvelElement("gmd:DQ_DomainConsistency", $report, $doc);
$result=nouvelElement("gmd:result", $DQ_DomainConsistency, $doc);
$DQ_ConformanceResult=nouvelElement("gmd:DQ_ConformanceResult", $result, $doc);
$specification=nouvelElement("gmd:specification", $DQ_ConformanceResult, $doc);
$quality_CI_Citation=nouvelElement("gmd:CI_Citation", $specification, $doc);
$quality_CI_Citation_title=nouvelElement("gmd:title", $quality_CI_Citation, $doc);
setElement("INSPIRE Implementing rules", "string", $quality_CI_Citation_title, $doc);
setDate($_POST, "publication", $quality_CI_Citation, $doc); // date conformite
setConformite($_POST['gmd:pass'], $DQ_ConformanceResult, $doc); // conformite
$lineage=nouvelElement("gmd:lineage", $DQ_DataQuality, $doc);
$LI_Lineage=nouvelElement("gmd:LI_Lineage", $lineage, $doc);
$statement=nouvelElement("gmd:statement", $LI_Lineage, $doc);
setElement($_POST['gmd:statement'], "string", $statement, $doc); // genealogie
$source=nouvelElement("gmd:source", $LI_Lineage, $doc);
$LI_Source=nouvelElement("gmd:LI_Source", $source, $doc);
$LI_Source_description=nouvelElement("gmd:description", $LI_Source, $doc);
setElement($_POST['gmd:abstract'], "string", $LI_Source_description, $doc);
if(isset($_POST['gmd:denominator']))
{
$scaleDenominator=nouvelElement("gmd:scaleDenominator", $LI_Source, $doc);
$MD_RepresentativeFraction=nouvelElement("gmd:MD_RepresentativeFraction", $scaleDenominator, $doc);
$denominator=nouvelElement("gmd:denominator", $MD_RepresentativeFraction, $doc);
setElement($_POST['gmd:denominator'], "integer", $denominator, $doc); // echelle
}
/* =========================================== */
/* ============ sauvegarde du XML ============ */
// on cree le dossier defini comme destination des metadonnees, s'il n'existe pas deja.
if(!is_dir($racine))
{
creerRepertoire($racine);
}
// on sauve le fichier une premiere fois dans le dossier defini comme destination des metadonnees.
$doc->save($racine.$nom_fichier);
$doc->saveXML();
// puis une seconde fois dans un dossier qui lui est propre,
// en vue de creer une archive
mkdir($racine.$nom_dossier.'/metadata');
$doc->save($racine.$nom_dossier.'/metadata/metadata.xml');
$doc->saveXML();
/* =========================================== */
}
/* ******************************************
********** fonctions utilitaires ************
****************************************** */
function nouvelElement($element, $pere, $doc)
{
$nouveau=$doc->createElement($element);
$pere->appendChild($nouveau);
return $nouveau;
}
function setElement($contenu, $cat, $cible, $doc)
{
switch($cat)
{
case 'string':
$champs=$doc->createElement('gco:CharacterString');
$cont=$doc->createTextNode($contenu);
$champs->appendChild($cont);
break;
case 'date':
$champs=$doc->createElement('gco:DateTime');
$cont=$doc->createTextNode($contenu);
$champs->appendChild($cont);
break;
case 'decimal':
$champs=$doc->createElement('gco:Decimal');
$cont=$doc->createTextNode($contenu);
$champs->appendChild($cont);
break;
case 'URL':
$champs=$doc->createElement('gmd:URL');
$cont=$doc->createTextNode($contenu);
$champs->appendChild($cont);
break;
case 'boolean' :
$champs=$doc->createElement('gco:Boolean');
$cont=$doc->createTextNode($contenu);
$champs->appendChild($cont);
break;
case 'integer':
$champs=$doc->createElement('gco:Integer');
$cont=$doc->createTextNode($contenu);
$champs->appendChild($cont);
break;
case 'topic':
$champs=$doc->createElement('gmd:MD_TopicCategoryCode');
$cont=$doc->createTextNode($contenu);
$champs->appendChild($cont);
break;
case 'stringVide':
$champs=$doc->createElement('gco:CharacterString');
break;
/* types presents dans le catalogue */
case 'FC_string':
$champs=$doc->createElement('gco:CharacterString');
setGco($champs, $doc);
$cont=$doc->createTextNode($contenu);
$champs->appendChild($cont);
break;
case 'FC_date':
$champs=$doc->createElement('gco:Date');
setGco($champs, $doc);
setGmd($champs, $doc);
$cont=$doc->createTextNode($contenu);
$champs->appendChild($cont);
break;
case 'FC_stringVide':
$champs=$doc->createElement('gco:CharacterString');
setGco($champs, $doc);
break;
case 'FC_localName':
$champs=$doc->createElement('gco:LocalName');
setGco($champs, $doc);
$cont=$doc->createTextNode($contenu);
$champs->appendChild($cont);
break;
case 'FC_boolean' :
$champs=$doc->createElement('gco:Boolean');
setGco($champs, $doc);
$cont=$doc->createTextNode($contenu);
$champs->appendChild($cont);
break;
case 'FC_localNameVide':
$champs=$doc->createElement('gco:LocalName');
setGco($champs, $doc);
break;
case 'default':
break;
}
$cible->appendChild($champs);
}
function setCodeList($valeur1, $valeur2, $cible, $doc)
{
$codeListValue=$doc->createAttribute("codeListValue");
$cible->appendChild($codeListValue);
$contenu_codeListValue=$doc->createTextNode($valeur1);
$codeListValue->appendChild($contenu_codeListValue);
$codeList=$doc->createAttribute("codeList");
$cible->appendChild($codeList);
$contenu_codeList=$doc->createTextNode($valeur2);
$codeList->appendChild($contenu_codeList);
}
function setAttribut($attribut, $valeur, $cible, $doc)
{
$attr=$doc->createAttribute($attribut);
$cible->appendChild($attr);
$val=$doc->createTextNode($valeur);
$attr->appendChild($val);
}
function boucler($_POST, $champs)
{
$tabRes=array();
$i=0;
foreach($_POST as $nom=>$valeur) // on recopie dans $tabRes tous les champs correspondant a la recherche
{
if(stripos($nom, $champs)!=false)
{
$tabRes[$i]=$valeur;
$i++;
}
}
$tabRes=eliminerDoublons($tabRes);
return $tabRes;
}
function eliminerDoublons($tab)
{
$tabRes=array();
for($i=0; $i<count($tab); $i++) // on elimine les doublons
{
$ok=true;
for($j=$i+1; $j<count($tab); $j++)
{
if(strcmp($tab[$i], $tab[$j])==0)
$ok=false;
}
if($ok)
array_push($tabRes, $tab[$i]);
}
return $tabRes;
}
function formaterCaractere($param)
{
$tab=array('é','Ã','è','Ã','ê','Ã','ë','Ã');
$param=str_replace($tab,"e", $param);
$tab=array('à ','Ã','â','Ã');
$param=str_replace($tab,"a", $param);
$param=str_replace("ô","o", $param);
$tab=array('î','Ã','ï','Ã');
$param=str_replace($tab,"i", $param);
$tab=array('ù','Ã','û','Ã','ü','Ã');
$param=str_replace($tab,"u", $param);
$param=str_replace("ç","c", $param);
$param=strtolower($param);
return $param;
}
function creerRepertoire($chemin)
{
$repertoires=split('/', $chemin);
$prog="";
foreach($repertoires as $repertoire)
{
$prog.=$repertoire."/";
if(!is_dir($prog))
mkdir($prog);
}
}
/* ******************************************
********** fonctions specifiques ************
****************************************** */
function getHierarchy($code)
{
$tab=array(
'serie','Données géographiques',
'dataset','Lot de données géographiques',
'service_g','Serveur de données géographiques',
'attribute','Données statistiques',
'nonGeographicDataset','Lot de données statistiques',
'service_s','Serveur de données statistiques'
);
for($i=0; $i<count($tab); $i=$i+2)
{
if(strcmp($tab[$i],$code)==0)
{
return $tab[$i+1];
}
}
}
function getSystemeProj($_POST)
{
$choix=$_POST['choixSystemeProj'];
if(strcmp($choix,"l93")==0)
$choix="Lambert 93";
else if(strcmp($choix,"autre")==0)
$choix=$_POST['gmd:code_geo'];
return $choix;
}
function setContact($_POST, $cible, $concerne, $doc)
{
if(strcmp($concerne,"md")==0)
$pointOfContact=nouvelElement("gmd:contact", $cible, $doc);
else
$pointOfContact=nouvelElement("gmd:pointOfContact", $cible, $doc);
$CI_ResponsibleParty=nouvelElement("gmd:CI_ResponsibleParty", $pointOfContact, $doc);
$individualName=nouvelElement("gmd:individualName", $CI_ResponsibleParty, $doc);
setElement($_POST['gmd:individualName_'.$concerne], "string", $individualName, $doc);
$organisationName=nouvelElement("gmd:organisationName", $CI_ResponsibleParty, $doc);
setElement($_POST['gmd:organisationName_'.$concerne], "string", $organisationName, $doc);
$positionName=nouvelElement("gmd:positionName", $CI_ResponsibleParty, $doc);
setElement($_POST['gmd:positionName_'.$concerne], "string", $positionName, $doc);
$contactInfo=nouvelElement("gmd:contactInfo", $CI_ResponsibleParty, $doc);
$CI_Contact=nouvelElement("gmd:CI_Contact", $contactInfo, $doc);
$phone=nouvelElement("gmd:phone", $CI_Contact, $doc);
$CI_Telephone=nouvelElement("gmd:CI_Telephone", $phone, $doc);
$voice=nouvelElement("gmd:voice", $CI_Telephone, $doc);
setElement($_POST['gmd:voice_'.$concerne], "string", $voice, $doc);
$address=nouvelElement("gmd:address", $CI_Contact, $doc);
$CI_Address=nouvelElement("gmd:CI_Address", $address, $doc);
$deliveryPoint=nouvelElement("gmd:deliveryPoint", $CI_Address, $doc);
setElement($_POST['gmd:deliveryPoint_'.$concerne], "string", $deliveryPoint, $doc);
$city=nouvelElement("gmd:city", $CI_Address, $doc);
setElement($_POST['gmd:city_'.$concerne], "string", $city, $doc);
$postalCode=nouvelElement("gmd:postalCode", $CI_Address, $doc);
setElement($_POST['gmd:postalCode_'.$concerne], "string", $postalCode, $doc);
$country=nouvelElement("gmd:country", $CI_Address, $doc);
setElement($_POST['gmd:country_'.$concerne], "string", $country, $doc);
$electronicMailAddress=nouvelElement("gmd:electronicMailAddress", $CI_Address, $doc);
setElement($_POST['gmd:electronicMailAddress_'.$concerne], "string", $electronicMailAddress, $doc);
$role=nouvelElement("gmd:role", $CI_ResponsibleParty, $doc);
$CI_RoleCode=nouvelElement("gmd:CI_RoleCode", $role, $doc);
setCodeList($_POST['gmd:CI_RoleCode_'.$concerne], "http://www.isotc211.org/2005/resources/codeList.xml#CI_RoleCode", $CI_RoleCode, $doc);
}
function setTypeGeometrie($_POST, $cible, $doc)
{
if(strcmp($_POST['gmd:spatialRepresentationType'],"vector")==0)
{
$spatialRepresentationInfo=nouvelElement("gmd:spatialRepresentationInfo", $cible, $doc);
$MD_VectorSpatialRepresentation=nouvelElement("gmd:MD_VectorSpatialRepresentation", $spatialRepresentationInfo, $doc);
$geometricObjects=nouvelElement("gmd:geometricObjects", $MD_VectorSpatialRepresentation, $doc);
$MD_GeometricObjects=nouvelElement("gmd:MD_GeometricObjects", $geometricObjects, $doc);
$geometricObjectType=nouvelElement("gmd:geometricObjectType", $MD_GeometricObjects, $doc);
$MD_GeometricObjectTypeCode=nouvelElement("gmd:MD_GeometricObjectTypeCode", $geometricObjectType, $doc);
setCodeList($_POST['gmd:spatialRepresentationType_'], "http://www.isotc211.org/2005/resources/codeList.xml#MD_GeometricObjectTypeCode", $MD_GeometricObjectTypeCode, $doc);
}
}
function setDate($_POST, $typeDate, $cible, $doc)
{
$Date=nouvelElement("gmd:date", $cible, $doc);
$CI_Date=nouvelElement("gmd:CI_Date", $Date, $doc);
if((strcmp($typeDate,"revision")==0) || (strcmp($typeDate,"creation")==0))
$valeur_date=getDateTime($_POST['gmd:date_jour_'.$typeDate], $_POST['gmd:date_mois_'.$typeDate], $_POST['gmd:date_annee_'.$typeDate]);
else if(strcmp($typeDate,"publication")==0)
$valeur_date=getDateTime($_POST['gmd:date_inspire']);
$sousdate=nouvelElement("gmd:date", $CI_Date, $doc);
setElement($valeur_date, "date", $sousdate, $doc);
$dateType=nouvelElement("gmd:dateType", $CI_Date, $doc);
$CI_DateTypeCode=nouvelElement("gmd:CI_DateTypeCode", $dateType, $doc);;
setCodeList($typeDate, "http://www.isotc211.org/2005/resources/codeList.xml#CI_DateTypeCode", $CI_DateTypeCode, $doc);
}
function getDateTime($date, $mois=NULL, $annee=NULL)
{
if((! is_null($mois)) && (! is_null($annee))) // si on a le jour, le mois et l'annee comme arguments
{
$valeur_date=$annee.'-'.$mois.'-'.$date.'T12:00:00';
}
else // si on a la date en un bloc comme argument
{
$tempo=explode("/",$date);
$valeur_date=$tempo[2].'-'.$tempo[1].'-'.$tempo[0].'T12:00:00';
}
return $valeur_date;
}
function setContraintes($_POST, $cible, $concerne, $doc)
{
$resourceConstraints=nouvelElement("gmd:resourceConstraints", $cible, $doc);
if(strcmp($concerne,"metadonnee"))
{
$FRA_Constraints=nouvelElement("fra:FRA_Constraints", $resourceConstraints, $doc);
setAttribut("gco:isoType", "gmd:MD_Constraints", $FRA_Constraints, $doc);
$useLimitation=nouvelElement("gmd:useLimitation", $FRA_Constraints, $doc);
setElement($_POST['gmd:MD_Constraints'], "string", $useLimitation, $doc);
}
else if(strcmp($concerne,"donnee"))
{
$FRA_SecurityConstraints=nouvelElement("fra:FRA_SecurityConstraints", $resourceConstraints, $doc);
setAttribut("gco:isoType", "gmd:MD_SecurityConstraints", $FRA_SecurityConstraints, $doc);
$useLimitation=nouvelElement("gmd:useLimitation", $FRA_SecurityConstraints, $doc);
setElement($_POST['gmd:MD_SecurityConstraints'], "string", $useLimitation, $doc);
$classification=nouvelElement("gmd:classification", $FRA_SecurityConstraints, $doc);
$MD_ClassificationCode=nouvelElement("gmd:MD_ClassificationCode", $classification, $doc);
setCodeList($_POST['gmd:classification'], "http://www.isotc211.org/2005/resources/codeList.xml#MD_ClassificationCode", $MD_ClassificationCode, $doc);
}
}
function setMotsCles($_POST, $cible, $doc)
{
$tabMotsCles=array();
$tabMotsCles=boucler($_POST, "keyword");
foreach($tabMotsCles as $motcle)
{
$descriptiveKeywords=nouvelElement("gmd:descriptiveKeywords", $cible, $doc);
$MD_Keywords=nouvelElement("gmd:MD_Keywords", $descriptiveKeywords, $doc);
$keyword=nouvelElement("gmd:keyword", $MD_Keywords, $doc);
setElement($motcle, "string", $keyword, $doc);
}
}
function setThematiques($_POST, $cible, $doc)
{
$tabThematiques=array();
$tabThematiques=boucler($_POST, "MD_TopicCategoryCode");
for($i=0; $i<count($tabThematiques); $i++)
$tabThematiques[$i]=getValueThematique($tabThematiques[$i]);
$tabThematiques=eliminerDoublons($tabThematiques);
foreach($tabThematiques as $thematique)
{
$topicCategory=nouvelElement("gmd:topicCategory", $cible, $doc);
setElement($thematique, "topic", $topicCategory, $doc);
}
}
function getValueThematique($thematique)
{
$tab_correspondances=array(
"agriculture"=>"farming",
"biote"=>"biota",
"limites"=>"boundaries",
"climatologie"=>"climatologyMeteorologyAtmosphere",
"economie"=>"economy",
"altitude"=>"elevation",
"environnement"=>"environment",
"informations"=>"geoscientificInformation",
"sante"=>"health",
"imagerie"=>"imageryBaseMapsEarthCover",
"renseignement"=>"intelligenceMilitary",
"eaux"=>"inlandWaters",
"localisation"=>"location",
"oceans"=>"oceans",
"planification"=>"planningCadastre",
"societe"=>"society",
"structure"=>"structure",
"transport"=>"transportation",
"service"=>"utilitiesCommunication",
"education"=>"society",
"tic"=>"utilitiesCommunication",
"tourisme"=>"society",
"demographie"=>"society");
$tempo=explode(" ",$thematique);
$thematique=formaterCaractere($tempo[0]);
foreach($tab_correspondances as $vf=>$vo)
{
if(strcmp($vf,$thematique)==0)
$value=$vo;
}
return $value;
}
function setEmprise($_POST, $cible, $doc)
{
$choix=$_POST['gmd:EX_GeographicBoundingBox'];
$tableauTerritoires=getTerritoireByNom($choix);
if(strcmp($choix,"autre")==0)
{
$tabEmprise=array('intitule'=>$_POST['gmd:extent_description'],
'west'=>$_POST['gmd:westBoundLongitude'],
'north'=>$_POST['gmd:northBoundLatitude'],
'east'=>$_POST['gmd:eastBoundLongitude'],
'south'=>$_POST['gmd:southBoundLatitude']);
}
else
{
$tabEmprise=array('intitule'=>$choix,
'west'=>$tableauTerritoires['longOuest'],
'north'=>$tableauTerritoires['latNord'],
'east'=>$tableauTerritoires['longEst'],
'south'=>$tableauTerritoires['latSud']);
}
$extent_description=nouvelElement("gmd:description", $cible, $doc);
setElement($tabEmprise['intitule'], "string", $extent_description, $doc);
$geographicElement=nouvelElement("gmd:geographicElement", $cible, $doc);
$EX_GeographicBoundingBox=nouvelElement("gmd:EX_GeographicBoundingBox", $geographicElement, $doc);
$westBoundLongitude=nouvelElement("gmd:westBoundLongitude", $EX_GeographicBoundingBox, $doc);
setElement($tabEmprise['west'], "decimal", $westBoundLongitude, $doc);
$eastBoundLongitude=nouvelElement("gmd:eastBoundLongitude", $EX_GeographicBoundingBox, $doc);
setElement($tabEmprise['east'], "decimal", $eastBoundLongitude, $doc);
$southBoundLatitude=nouvelElement("gmd:southBoundLatitude", $EX_GeographicBoundingBox, $doc);
setElement($tabEmprise['south'], "decimal", $southBoundLatitude, $doc);
$northBoundLatitude=nouvelElement("gmd:northBoundLatitude", $EX_GeographicBoundingBox, $doc);
setElement($tabEmprise['north'], "decimal", $northBoundLatitude, $doc);
}
function setFormatSpecification($_POST)
{
if(isset($_POST['gmd:denominator']))
$texte="Shape au format shp."; // cas d'une donne geographique
else
$texte="Tableau au format xls ou dbf."; // cas d'une donne statistique
return $texte;
}
function setLiens($_POST, $cible, $doc)
{
$tabLiens=array();
$tabLiens=boucler($_POST, "url");
foreach($tabLiens as $lien)
{
$onLine=nouvelElement("gmd:onLine", $cible, $doc);
$CI_OnlineResource=nouvelElement("gmd:CI_OnlineResource", $onLine, $doc);
$linkage=nouvelElement("gmd:linkage", $CI_OnlineResource, $doc);
setElement($lien, "URL", $linkage, $doc);
}
}
function setConformite($conformite, $cible, $doc)
{
$explanation=nouvelElement("gmd:explanation", $cible, $doc);
$pass=nouvelElement("gmd:pass", $cible, $doc);
if(strcmp($conformite,"nconf")==0)
{
$conformite=0;
$exp_conformite="Non conforme";
}
else if(strcmp($conformite,"neval")==0)
{
$conformite=0;
$exp_conformite="Non evalue";
}
else if(strcmp($conformite,"conf")==0)
{
$conformite=1;
$exp_conformite="Conforme";
}
setElement($conformite, "boolean", $pass, $doc);
setElement($exp_conformite, "string", $explanation, $doc);
}
/* ********************************************************
*********** ***********
*********** fonctions de construction ***********
*********** du catalogue ***********
*********** ***********
******************************************************** */
function buildCatalogue($racine, $nom_fichier, $nom_dossier, $_POST)
{
/* ======== creation du fichier .xml ======== */
$doc = new DomDocument('1.0','UTF-8');
$doc->formatOutput=TRUE;
/* ====== creation de l'element racine ====== */
$FC_root=nouvelElement("gfc:FC_FeatureCatalogue", $doc, $doc);
$tab_attr_FC=array(
"xmlns:gfc"=>"http://www.isotc211.org/2005/gfc",
"xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance",
"xmlns:gco"=>"http://www.isotc211.org/2005/gco",
"xmlns:gmd"=>"http://www.isotc211.org/2005/gmd");
foreach($tab_attr_FC as $attr=>$valeur)
setAttribut($attr, $valeur, $FC_root, $doc);
/* ======= creation de l arborescence ======= */
/* ***********
** entete
*********** */
$FC_name=nouvelElement("gfc:name", $FC_root, $doc);
setGmd($FC_name, $doc);
setGco($FC_name, $doc);
setElement("", "string", $FC_name, $doc);
$FC_scope=nouvelElement("gfc:scope", $FC_root, $doc);
setElement($_POST['gmd:url'], "FC_string", $FC_scope, $doc);
$fieldOfApplication=nouvelElement("gfc:fieldOfApplication", $FC_root, $doc);
setElement("Dictionnaire de donnees pour ".$_POST['gmd:title'], "FC_string", $fieldOfApplication, $doc);
$versionNumber=nouvelElement("gfc:versionNumber", $FC_root, $doc);
setElement("", "FC_stringVide", $versionNumber, $doc);
$versionDate=nouvelElement("gfc:versionDate", $FC_root, $doc);
setElement(getDateTime($_POST['gmd:dateStamp']), "FC_date", $versionDate, $doc);
/* ***********
** intro
*********** */
$featureType=nouvelElement("gfc:featureType", $FC_root, $doc);
$FC_FeatureType=nouvelElement("gfc:FC_FeatureType", $featureType, $doc);
setAttribut("id", "", $FC_FeatureType, $doc);
/* ***********
** infos
*********** */
$typeName=nouvelElement("gfc:typeName", $FC_FeatureType, $doc);
setElement("Nom de la propriete", "FC_localName", $typeName, $doc);
$FC_definition=nouvelElement("gfc:definition", $FC_FeatureType, $doc);
setElement("Definition de la table d attributs", "FC_string", $FC_definition, $doc);
$isAbstract=nouvelElement("gfc:isAbstract", $FC_FeatureType, $doc);
setElement("false", "FC_boolean", $isAbstract, $doc);
$aliases=nouvelElement("gfc:aliases", $FC_FeatureType, $doc);
setElement("", "FC_localNameVide", $aliases, $doc);
/* ***********
** attributs
*********** */
$featureCatalogue=nouvelElement("gfc:featureCatalogue", $FC_FeatureType, $doc);
setAttribut("xmlns:xlink", "http://www.w3.org/1999/xlink", $featureCatalogue, $doc);
setAttribut("xlink:href", "#", $featureCatalogue, $doc);
setCatalogueAttributs($_POST, $FC_FeatureType, $doc);
/* ============ sauvegarde du XML ============ */
// on sauve le fichier une premiere fois dans le dossier defini comme destination des metadonnees.
$doc->save($racine.$nom_fichier);
$doc->saveXML();
// puis une seconde fois dans un dossier qui lui est propre,
// en vue de creer une archive
mkdir($racine.$nom_dossier.'/applschema');
$doc->save($racine.$nom_dossier.'/applschema/metadata.xml');
$doc->saveXML();
}
function setGmd($cible, $doc)
{
setAttribut("xmlns:gmd", "http://www.isotc211.org/2005/gmd", $cible, $doc);
}
function setGco($cible, $doc)
{
setAttribut("xmlns:gco", "http://www.isotc211.org/2005/gco", $cible, $doc);
}
function setCatalogueAttributs($_POST, $cible, $doc)
{
$tabAttributs=array();
$tabAttributs=bouclerFC($_POST);
foreach($tabAttributs as $attribut)
{
$carrierOfCharacteristics=nouvelElement("gfc:carrierOfCharacteristics", $cible, $doc);
$FC_FeatureAttribute=nouvelElement("gfc:FC_FeatureAttribute", $carrierOfCharacteristics, $doc);
$memberName=nouvelElement("gfc:memberName", $FC_FeatureAttribute, $doc);
setElement($attribut['memberName'], "FC_localName", $memberName, $doc);
$definition=nouvelElement("gfc:definition", $FC_FeatureAttribute, $doc);
setElement($attribut['definition'], "FC_string", $definition, $doc);
$cardinality=nouvelElement("gfc:cardinality", $FC_FeatureAttribute, $doc);
setCardinalite($attribut['cardinality'], $cardinality, $doc);
$featureType=nouvelElement("gfc:featureType", $FC_FeatureAttribute, $doc);
$valueMeasurementUnit=nouvelElement("gfc:valueMeasurementUnit", $FC_FeatureAttribute, $doc);
$UnitDefinition=nouvelElement("gml:UnitDefinition", $valueMeasurementUnit, $doc);
setAttribut("xmlns:gml", "http://www.opengis.net/gml", $UnitDefinition, $doc);
setAttribut("gml:id", "unknown", $UnitDefinition, $doc);
$identifier=nouvelElement("gml:identifier", $UnitDefinition, $doc);
setAttribut("codeSpace", "unknown", $identifier, $doc);
if(strcmp("", $attribut['valueMeasurementUnit'])!=0)
{
$value=$doc->createTextNode($attribut['valueMeasurementUnit']);
$identifier->appendChild($value);
}
// la liste des valeurs est vide par defaut,
// mais il faut quand meme la declarer
$listedValue=nouvelElement("gfc:listedValue", $FC_FeatureAttribute, $doc);
$FC_ListedValue=nouvelElement("gfc:FC_ListedValue", $listedValue, $doc);
$LV_label=nouvelElement("gfc:label", $FC_ListedValue, $doc);
setElement("", "FC_stringVide", $LV_label, $doc);
$LV_code=nouvelElement("gfc:code", $FC_ListedValue, $doc);
setElement("", "FC_stringVide", $LV_code, $doc);
$LV_definition=nouvelElement("gfc:definition", $FC_ListedValue, $doc);
setElement("", "FC_stringVide", $LV_definition, $doc);
$valueType=nouvelElement("gfc:valueType", $FC_FeatureAttribute, $doc);
$typeName=nouvelElement("gco:typeName", $valueType, $doc);
setGco($typeName, $doc);
$aName=nouvelElement("gco:aName", $typeName, $doc);
setElement($attribut['valueType'], "string", $aName, $doc);
}
}
function bouclerFC($_POST)
{
$tabRes=array();
foreach($_POST as $nom=>$valeur)
{
if(stripos($nom, "memberName")!=false)
{
$numAttr=substr($nom, strpos($nom, "_")+1);
$tabRes[$numAttr]=array(
"memberName"=>$_POST['gfc:memberName_'.$numAttr],
"definition"=>$_POST['gfc:definition_'.$numAttr],
"cardinality"=>$_POST['gfc:cardinality_'.$numAttr],
"valueType"=>$_POST['gfc:valueType_'.$numAttr],
"valueMeasurementUnit"=>$_POST['gfc:valueMeasurementUnit_'.$numAttr]
);
}
}
return $tabRes;
}
function setCardinalite($valeur, $cible, $doc)
{
$min=substr($valeur, 0, 1);
$max=substr($valeur, 2);
if(strcmp($max,"inf")==0)
$max="n";
$multiplicity=nouvelElement("gco:Multiplicity", $cible, $doc);
setGco($multiplicity, $doc);
$range=nouvelElement("gco:range", $multiplicity, $doc);
$multiplicityRange=nouvelElement("gco:MultiplicityRange", $range, $doc);
$lower=nouvelElement("gco:lower", $multiplicityRange, $doc);
setElement($min, "integer", $lower, $doc);
$upper=nouvelElement("gco:upper", $multiplicityRange, $doc);
$upper_value=nouvelElement("gco:UnlimitedInteger", $upper, $doc);
if(strcmp($max,"n")==0)
{
setAttribut("isInfinite", "true", $upper_value, $doc);
setAttribut("xsi:nil", "true", $upper_value, $doc);
}
else
{
setAttribut("isInfinite", "false", $upper_value, $doc);
setAttribut("xsi:nil", "false", $upper_value, $doc);
}
$value=$doc->createTextNode($max);
$upper_value->appendChild($value);
}
function zippage($racine, $path, $nomzip)
{
require_once("zip.lib.php"); // librairie zip.lib, que l'on trouve avec phpmyadmin
chdir($racine);
$zip= new zipfile;
set_time_limit (100);
function zipDir($path,&$zip)
{
if (!is_dir($path)) return;
if (!($dh = @opendir($path)))
{
echo("<b>ERREUR: Une erreur s'est produite sur ".$path."</b><br />");
return;
}
while ($file = readdir($dh))
{
if ($file == "." || $file == "..") continue; // Permet de ne pas prendre en compte le . et .. (soit le repertoire courant, et le dossier parent)
if (is_dir($path."/".$file))
{ // appel recursif
//zipDir($path."/".$file,$zip,$i);
zipDir($path."/".$file,$zip);
}
elseif (is_file($path."/".$file))
{ // si c'est un fichier, on l'ajoute a l'archive
$zip->addFile(file_get_contents($path."/".$file),$path."/".$file);
}
}
}
zipDir($path,$zip);
$filezipped=$zip->file(); // On recupere le contenu du zip dans la variable $filezipped
$open = fopen($nomzip, "w"); // On la sauvegarde dans le meme repertoire que les fichiers a zipper
fwrite($open, $filezipped);
fclose($open);
}
function supprSuperflu($nom)
{
unlink($nom.".xml");
unlink("catalogue_".$nom.".xml");
supprDir($nom);
}
function supprDir($dossier)
{
$ouverture=@opendir($dossier);
if (!$ouverture)
return;
while($fichier=readdir($ouverture))
{
if ($fichier == '.' || $fichier == '..')
continue;
if (is_dir($dossier."/".$fichier))
{
$r=supprDir($dossier."/".$fichier);
if (!$r)
return false;
}
else
{
$r=@unlink($dossier."/".$fichier);
if (!$r)
return false;
}
}
closedir($ouverture);
$r=@rmdir($dossier);
if (!$r)
return false;
return true;
}
function alertMail($nom)
{
Require_once("phpmailer/class.phpmailer.php");
$infos=getMailInfos(); // permet de recuperer les informations contenues dans lib/data/config.php
foreach($infos as $info)
{ if(strcmp($info,""))
$retour="info manquante";
}
if(!isset($retour))
{
$mail = new PHPmailer();
$mail->IsSMTP();
$mail->Host=$infos['hote_smtp'];
$mail->FromName=$infos['alerte_mail_source'];
$mail->AddAddress($infos['alerte_mail_dest']);
$i=2;
while(isset($infos['alerte_mail_dest_'.$i])) // permet de gerer les eventuels autres destinataires.
{
$mail->AddCC($infos['alerte_mail_dest_'.$i]);
$i=$i+1;
}
$mail->Subject='Nouvelle metadonnee creee via Expire';
$mail->Body="La metadonnee '".$nom."' a ete creee via Expire. ".
"Elle a ete ecrite depuis le poste ".$_SERVER['REMOTE_ADDR'].
" et est enregistree dans le dossier suivant : ".$infos['chemin_serveur'].".
Bonne journee !";
if(!$mail->Send())
$retour=$mail->ErrorInfo; //retourne le message d'erreur en anglais
else
$retour="succes";
$mail->SmtpClose();
unset($mail);
}
return $retour;
}
?>