\n";
//**************************overview part begin******************************
//generate div tags for the content - the divs are defined in the array
if ($layout == 'accordion') {
$html .= '
';//element
//***************************************************************************
//**************************properties part begin******************************
//generate div tags for the content - the divs are defined in the array
if ($layout == 'accordion') {
$html .= '
';//element
//***************************************************************************
//**************************contact part begin******************************
//generate div tags for the content - the divs are defined in the array
if ($layout == 'accordion') {
$html .= '
';//element
//***************************************************************************
//**************************terms of use part begin******************************
//generate div tags for the content - the divs are defined in the array
if ($layout == 'accordion') {
$html .= '
';//element
//***************************************************************************
//**************************quality part begin******************************
//generate div tags for the content - the divs are defined in the array
if ($layout == 'accordion') {
$html .= '
';//element
//***************************************************************************
//**************************Interfaces part begin******************************
//generate div tags for the content - the divs are defined in the array
if ($layout == 'accordion') {
$html .= '
';
if ($iso19139Hash[3]['value'] == 'service' && $iso19139Hash[10]['value'] == 'download') {
//show link to own atom feed download client
//push ATOM Service feed url to client
if (defined("MAPBENDER_PATH") && MAPBENDER_PATH != '' && parse_url($iso19139Hash[7]['value'])) {
$html .= $t_a.""._mb("ATOM Feed client").": "._mb("Download")."".$t_c;
}
}
$html .= '
'; //demo
$html .= '';
$html .= '';
return $html;
}
}
public function createFromDBInternalId($metadataId){
$sql = "SELECT * from mb_metadata WHERE metadata_id = $1";
$v = array($metadataId);
$t = array('i');
$res = db_prep_query($sql,$v,$t);
if ($res) {
$row = db_fetch_assoc($res);
//fill object with information from mb_metadata table
//initialize empty iso19139 object
$this->fileIdentifier = $row['uuid'];
$this->title = $row['title'];
$this->abstract = $row['abstract'];
$this->createDate = $row['createdate'];//"1900-01-01";
$this->changeDate = $row['changedate'];//"1900-01-01";
$this->metadata = $row['data'];
//some possibilities:
$this->datasetId = $row['datasetid'];
$this->datasetIdCodeSpace = $row['datasetid_codespace'];
//fill keywords and categories later cause they are stored in relations!
/*$this->keywords = array();
$this->keywordsThesaurusName = array();
$this->isoCategoryKeys = array();
//following information is specific to mapbender information model - they are identified by id!
$this->isoCategories = array();
$this->inspireCategories = array();
$this->customCategories = array();
//*/
$this->hierachyLevel = $row['type'];
$this->tmpExtentBegin = $row['tmp_reference_1'];//"1900-01-01";
$this->tmpExtentEnd = $row['tmp_reference_2'];//"1900-01-01";
$this->randomId = $row['randomid'];
$this->owner = $row['fkey_mb_user_id']; //dummy entry for metadata owner - in case of metadataURL entries the owner of the corresponding service
$this->href = $row['link'];// "";
$this->format = $row['md_format'];//"";
$this->type = $row['linktype'];//"";
$this->origin = $row['origin'];//"";
$this->refSystem = $row['ref_system'];//"";
$this->harvestResult = $row['harvestresult'];//;0;
$this->harvestException = $row['harvestexception'];//"";
$this->lineage = $row['lineage'];//"";
$this->inspireTopConsistence = $row['inspire_top_consistance'];//"f";
$this->spatialResType = $row['spatial_res_type'];//"";
$this->spatialResValue = $row['spatial_res_value'];//"";
$this->export2Csw = $row['export2csw'];//"t";
$this->updateFrequency = $row['update_frequency'];//"";
$this->dataFormat = $row['format'];//"";
$this->inspireCharset = $row['inspire_charset'];//"";
//
//$this->linkAlreadyInDB = false;
//$this->fileIdentifierAlreadyInDB = false;
//get relations from other tables:
//get categories and keywords
//get isoCategories
$sql = <<isoCategories[] = (string)$row['md_topic_category_id'];
$this->isoCategoriesKeys[] = $row['md_topic_category_code_en'];
}
//get custom categories
$sql = <<customCategories[] = (string)$row['custom_category_id'];
//generate one keyword entry with special thesaurus
$this->keywords[] = $row['fkey_custom_category_id'];
if (defined("METADATA_DEFAULT_CODESPACE") && METADATA_DEFAULT_CODESPACE != '') {
$this->keywordsThesaurusName[] = METADATA_DEFAULT_CODESPACE;
} else {
$this->keywordsThesaurusName[] = "http://www.mapbender.org";
}
}
//get inspire categories
$sql = <<inspireCategories[] = (string)$row['inspire_category_id'];
$this->keywords[] = $row['inspire_category_key'];
$this->keywordsThesaurusName[] = "GEMET - INSPIRE themes, version 1.0";
}
//get other keywords from keyword table - only fill in, if not already in keywords!
$sql = <<keywords)) {
$this->keywords[] = $row['keyword'];
$this->keywordsThesaurusName[] = "";
}
}
} else {
$e = new mb_exception("Could not get metadata with id ".$metadataId." from DB!");
return false;
}
return true;
}
//the following functions are only for the simple metadata editor
public function createMetadataAddonFromDB() {
}
public function updateMetadataAddonInDB() {
}
//TODO: following 2 functions are not used til now - check plugins mb_metadata_server scripts to exchange handling
public function deleteMetadataRelation($resourceType, $resourceId, $relationType){
//delete all relations which are defined from capabilities - this don't delete the metadata entries themself!
//all other relations stay alive
$sql = "DELETE FROM ows_relation_metadata WHERE fkey_".$resourceType."_id = $1 AND relation_type = '".$relationType."'";
$v = array($resourceId);
$t = array('i');
$res = db_prep_query($sql,$v,$t);
if(!$res){
$e = new mb_exception("class_Iso19139:"."Cannot delete metadata relations for resource ".$resourceType." with id: ".$resourceId);
return false;
} else {
return true;
}
}
public function insertMetadataRelation($resourceType, $resourceId, $relationType){
//delete all relations which are defined from capabilities - this don't delete the metadata entries themself!
//all other relations stay alive
$sql = "DELETE FROM ows_relation_metadata WHERE fkey_".$resourceType."_id = $1 AND relation_type = '".$relationType."'";
$v = array($resourceId);
$t = array('i');
$res = db_prep_query($sql,$v,$t);
if(!$res){
$e = new mb_exception("class_Iso19139:"."Cannot delete metadata relations for resource ".$resourceType." with id: ".$resourceId);
return false;
} else {
return true;
}
}
public function checkMetadataRelation($resourceType, $resourceId, $metadataId){
//check if one relation already exists - if so no new one should be generated!!!
$sql = "SELECT count(fkey_metadata_id) FROM ows_relation_metadata WHERE fkey_".$resourceType."_id = $1 AND fkey_metadata_id = $2 AND relation_type = $3";
$v = array($resourceId, $metadataId, $this->origin);
$t = array('i','i','s');
$res = db_prep_query($sql,$v,$t);
while ($row = db_fetch_array($res)){
$numberOfRelations = $row['count'];
}
if ($numberOfRelations > 0) {
return true;
} else {
return false;
}
}
public function deleteInternalMetadataLinkage($resourceType, $resourceId, $metadataId){
$returnObject = array();
$sql = "DELETE FROM ows_relation_metadata WHERE fkey_metadata_id = $1 and fkey_".$resourceType."_id = $2 and relation_type = 'internal'";
$v = array($metadataId, $resourceId);
$t = array('i','i');
try {
$res = db_prep_query($sql,$v,$t);
}
catch (Exception $E){
$returnObject['success'] = false;
$returnObject['message'] = _mb("Could not delete internal metadata linkage from database!");
return $returnObject;
}
$returnObject['success'] = true;
$returnObject['message'] = _mb("Internal metadata linkage deleted!");
return $returnObject;
}
public function deleteMetadataAddon($resourceType, $resourceId, $metadataId){
$returnObject = array();
$sql = "SELECT count(*) as count FROM ows_relation_metadata WHERE fkey_metadata_id = $1";
$v = array($metadataId);
$t = array('i');
try {
$res = db_prep_query($sql,$v,$t);
}
catch (Exception $e){
$returnObject['success'] = false;
$returnObject['message'] = _mb("Could not determine a count of metadata relations!");
return $returnObject;
}
while ($row = db_fetch_assoc($res)) {
$countMetadataLinkage = (integer)$row['count']; //integer
}
if ($countMetadataLinkage == 1) {
$e = new mb_exception("Metadata has only one reference and will be deleted from database if it was created by upload or link!");
//delete the metadata itself cause it has no other reference - really - not right for metador files !!!
$sql = << '' ORDER BY lastchanged DESC
SQL;
$v = array(
$this->href
);
$t = array('s');
$res = db_prep_query($sql,$v,$t);
while ($row = db_fetch_array($res)){
$metadataId[] = $row['metadata_id'];
}
if (count($metadataId) > 0) {
return $metadataId;
} else {
return false;
}
}
public function isFileIdentifierAlreadyInDB(){
$sql = << '' ORDER BY lastchanged DESC
SQL;
if (!isset($this->fileIdentifier) || $this->fileIdentifier == '') {
$e = new mb_exception("class_Iso19139:"."Empty or no fileIdentifier found in the metadata! No metadataset will be updated");
return false;
}
$v = array(
$this->fileIdentifier
);
$t = array('s');
$res = db_prep_query($sql,$v,$t);
$metadataId = array();
while ($row = db_fetch_array($res)){
$metadataId[] = $row['metadata_id'];
}
if (count($metadataId) > 0) {
return $metadataId;
} else {
return false;
}
}
public function insertKeywordsAndCategoriesIntoDB($metadataId){
//first delete old classifications - after that create new ones
$this->deleteKeywordsAndCategoriesFromDB($metadataId);
//insert keywords and categories into tables!
//parse keywords and isoCategories
//INSERT INTO films (code, title, did, date_prod, kind) VALUES
//('B6717', 'Tampopo', 110, '1985-02-10', 'Comedy'),
//('HG120', 'The Dinner Game', 140, DEFAULT, 'Comedy');
//use category name instead of id's!
//map category name to id before insert them into db!
//read maptable from db
//iso - code in xml
//map keys into relevant ids
$sqlInsert = "";
if (count($this->isoCategories) > 0) {
if (count($this->isoCategories) == 1) {
$sqlInsert .= "(".(integer)$metadataId.",".(integer)$this->isoCategories.")";
} else {
foreach ($this->isoCategories as $isoCategory) {
$sqlInsert .= "(".(integer)$metadataId.",".(integer)$isoCategory."),";
}
}
$sqlInsert = rtrim($sqlInsert,",");
$sql = "INSERT INTO mb_metadata_md_topic_category (fkey_metadata_id, fkey_md_topic_category_id) VALUES ".$sqlInsert;
$res = db_query($sql);
if (!$res) {
$e = new mb_exception("class_Iso19139:"._mb("Cannot insert iso categories for this metadata!"));
}
}
$sqlInsert = "";
if (count($this->inspireCategories) > 0) {
if (count($this->inspireCategories) == 1) {
$sqlInsert .= "(".(integer)$metadataId.",".(integer)$this->inspireCategories.")";
} else {
foreach ($this->inspireCategories as $inspireCategory) {
$sqlInsert .= "(".(integer)$metadataId.",".(integer)$inspireCategory."),";
}
}
$sqlInsert = rtrim($sqlInsert,",");
$sql = "INSERT INTO mb_metadata_inspire_category (fkey_metadata_id, fkey_inspire_category_id) VALUES ".$sqlInsert;
$res = db_query($sql);
if (!$res) {
$e = new mb_exception("class_Iso19139:"._mb("Cannot insert inspire categories for this metadata!"));
}
}
$sqlInsert = "";
if (count($this->customCategories) > 0) {
if (count($this->customCategories) == 1) {
$sqlInsert .= "(".(integer)$metadataId.",".(integer)$this->customCategories.")";
} else {
foreach ($this->customCategories as $customCategory) {
$sqlInsert .= "(".(integer)$metadataId.",".(integer)$customCategory."),";
}
}
$sqlInsert = rtrim($sqlInsert,",");
$sql = "INSERT INTO mb_metadata_custom_category (fkey_metadata_id, fkey_custom_category_id) VALUES ".$sqlInsert;
$res = db_query($sql);
if (!$res) {
$e = new mb_exception("class_Iso19139:"._mb("Cannot insert custom categories for this metadata!"));
}
}
$sqlInsert = "";
//insert keywords into keyword table
//foreach keyword look for an id or create it newly - made for postgres > 8.2 with returning option for insert statement
$keyword = "'";
$keyword .= implode('\',\'',$this->keywords);
$keyword .= "'";
$existingKeywords = array();
$sql = "SELECT keyword, keyword_id from keyword WHERE keyword in ($keyword);";
$res = db_query($sql);
if (!$res) {
$e = new mb_exception("class_Iso19139.php: cannot get keywords from database!");
} else {
$countExistingKeywords = 0;
while ($row = db_fetch_assoc($res)) {
$existingKeywords[$countExistingKeywords]['keyword'] = $row['keyword'];
$e = new mb_exception("existing keyword: ".$row['keyword']);
$existingKeywords[$countExistingKeywords]['id'] = $row['keyword_id'];
$existingKeywordsArray[$countExistingKeywords] = $row['keyword'];
$countExistingKeywords++;
}
}
/*foreach ($existingKeywords as $test) {
$e = new mb_exception("exists: ".$test['keyword']);
}*/
//for each existing keyword add a new relation into relation table
if ($countExistingKeywords > 0) {
if ($countexistingKeywords == 1) {
$sqlInsert .= "(".(integer)$metadataId.",".(integer)$existingKeywords[0]['id'].")";
} else {
foreach ($existingKeywords as $existingKeyword) {
$sqlInsert .= "(".(integer)$metadataId.",".(integer)$existingKeyword['id']."),";
}
}
$sqlInsert = rtrim($sqlInsert,",");
$sql = "INSERT INTO mb_metadata_keyword (fkey_metadata_id, fkey_keyword_id) VALUES ".$sqlInsert;
$e = new mb_exception("class_Iso19139.php: sql for keywords: ".$sql);
$res = db_query($sql);
if (!$res) {
$e = new mb_exception("class_Iso19139:"._mb("Cannot insert keyword relations for this metadata!"));
} else {
$e = new mb_exception("class_Iso19139:"._mb("Inserted keyword relations for existing keywords!"));
}
}
//insert those keywords, that are not already in the keyword table
//$this->keywords
/*$array1 = array("a" => "grün", "rot", "blau", "rot");
$array2 = array("b" => "grün", "gelb", "rot");
$result = array_diff($array1, $array2);
Array
(
[1] => blau
)
*/
$sqlInsert = "";
//test if $existingKeywordsArray is array!
if (is_array($existingKeywordsArray)) {
$otherKeywords = array_values(array_diff($this->keywords,$existingKeywordsArray));
} else {
$otherKeywords = $this->keywords;
}
//debug
foreach ($otherKeywords as $test) {
$e = new mb_exception("otherKeywords: ".$test);
}
$e = new mb_exception("otherKeywords: ".$otherKeywords);
if (count($otherKeywords) > 0) {
if (count($otherKeywords) == 1) {
$e = new mb_exception("Only one new keyword found: ".$otherKeywords[0]);
//keyword table
$sqlInsert .= "('".$otherKeywords[0]."')";
} else {
foreach ($otherKeywords as $otherKeyword) {
$sqlInsert .= "('".$otherKeyword."'),";
}
}
$sqlInsert = rtrim($sqlInsert,",");
$sql = "INSERT INTO keyword (keyword) VALUES ".$sqlInsert." RETURNING keyword_id" ;
$e = new mb_exception("class_Iso19139.php: sql for keywords: ".$sql);
$res = db_query($sql);
if (!$res) {
$e = new mb_exception("class_Iso19139:"._mb("Cannot insert new keywords into keyword table!"));
} else {
//insert relations for keywords
$sqlInsert = "";
$insertedKeywords = array();
while ($row = db_fetch_assoc($res)) {
$insertedKeywordIds[] = $row['keyword_id'];
}
if (count($insertedKeywordIds) == 1) {
//keyword relation table
$sqlInsert .= "(".(integer)$metadataId.",".$insertedKeywordIds[0].")";
} else {
foreach ($insertedKeywordIds as $insertedKeywordId) {
$sqlInsert .= "(".(integer)$metadataId.",".(integer)$insertedKeywordId."),";
}
}
$sqlInsert = rtrim($sqlInsert,",");
$sql = "INSERT INTO mb_metadata_keyword (fkey_metadata_id, fkey_keyword_id) VALUES ".$sqlInsert;
$e = new mb_notice("class_Iso19139.php: sql for keyword relation: ".$sql);
$res = db_query($sql);
if (!$res) {
$e = new mb_exception("class_Iso19139:"._mb("Cannot insert metadata keyword relations into db!"));
}
}
}
}
public function deleteKeywordsAndCategoriesFromDB($metadataId) {
$sql = "DELETE FROM mb_metadata_md_topic_category where fkey_metadata_id = $1 ";
$v = array($metadataId);
$t = array('i');
$res = db_prep_query($sql,$v,$t);
if (!$res) {
$e = new mb_exception("class_Iso19139:"._mb("Cannot delete topic category relations for metadata with id ".$metadataId));
} else {
$e = new mb_exception("class_Iso19139: topic category relations deleted from database!");
}
$sql = "DELETE FROM mb_metadata_inspire_category where fkey_metadata_id = $1 ";
$v = array($metadataId);
$t = array('i');
$res = db_prep_query($sql,$v,$t);
if (!$res) {
$e = new mb_exception("class_Iso19139:"._mb("Cannot delete inspire category relations for metadata with id ".$metadataId));
} else {
$e = new mb_exception("class_Iso19139: inspire category relations deleted from database!");
}
$sql = "DELETE FROM mb_metadata_custom_category where fkey_metadata_id = $1 ";
$v = array($metadataId);
$t = array('i');
$res = db_prep_query($sql,$v,$t);
if (!$res) {
$e = new mb_exception("class_Iso19139:"._mb("Cannot delete custom category relations for metadata with id ".$metadataId));
} else {
$e = new mb_exception("class_Iso19139: custom category relations deleted from database!");
}
//delete keyword relations - problem, that keywords are referenced from more than one table. We can only delete the relations but there may be orphaned keywords, which have to be deleted by cronjob - maybe - TODO
$sql = "DELETE FROM mb_metadata_keyword where fkey_metadata_id = $1 ";
$v = array($metadataId);
$t = array('i');
$res = db_prep_query($sql,$v,$t);
if (!$res) {
$e = new mb_exception("class_Iso19139:"._mb("Cannot delete keyword relations for metadata with id ".$metadataId));
} else {
$e = new mb_exception("class_Iso19139: keyword relations deleted from database!");
}
}
public function insertMetadataIntoDB() {
//insert an instance for iso19139 into mapbenders database
$sql = <<href,
$this->format,
$this->metadata,
$this->type,
$this->fileIdentifier,
$this->title,
$this->createDate,
$this->changeDate,
$this->abstract,
$this->keywords[0],
$this->hierachyLevel,
$this->tmpExtentBegin,
$this->tmpExtentEnd,
$this->export2Csw,
$this->datasetId,
$this->datasetIdCodeSpace,
$this->randomId,
$this->origin,
$this->owner,
$this->harvestResult,
$this->harvestException,
$this->lineage,
$this->inspireTopConsistence,
$this->spatialResType,
$this->spatialResValue,
$this->updateFrequency,
$this->dataFormat,
$this->inspireCharset,
$this->refSystem
);
$t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','b','s','s','s','s','i','i','s','s','b','s','s','s','s','s','s');
$res = db_prep_query($sql,$v,$t);
return $res;
}
public function updateMetadataById($metadataId) {
//check if the timestamp of an existing metadata element is not newer than the timestamp of the current metadata object!!!!
//TODO
//problem: <<href,
$this->format,
$this->metadata,
$this->type,
$this->fileIdentifier, // is the old one! or not?
$this->title,
$this->createDate,
$this->changeDate,
$this->abstract,
$this->keywords[0],
$this->hierachyLevel,
$this->tmpExtentBegin,
$this->tmpExtentEnd,
$this->export2Csw,
$this->datasetId,
$this->datasetIdCodeSpace,
$this->randomId,
$this->origin,
//$this->owner, //owner is the old one - maybe here we have something TODO!
$metadataId, //The first metadataId which was found will be selected!
$this->harvestResult,
$this->harvestException,
$this->lineage,
$this->inspireTopConsistence,
$this->spatialResType,
$this->spatialResValue,
$this->updateFrequency,
$this->dataFormat,
$this->inspireCharset,
$this->refSystem
);
$t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','b','s','s','s','s','i','i','s','s','b','s','s','s','s','s','s');
$res = db_prep_query($sql,$v,$t);
return $res;
}
public function insertMetadataUrlToDB($resourceType, $resourceId){
//check if metadata record already exists, if not create a new one else insert relation only!
$metadataId = $this->isLinkAlreadyInDB();
if ($metadataId != false) {
//update the metadataURL entry
$e = new mb_exception("class_Iso19139:"."existing metadata link(s) found: ".$metadataId[0]." - update will be performed");
$sql = "UPDATE mb_metadata SET link = $1, origin = $2, md_format = $3, linktype = $4, changedate = now(), export2csw = $5, randomid = $6, harvestresult = $8, harvestexception = $9 WHERE metadata_id = $7";
$v = array(
$this->href,
$this->origin,
$this->format,
$this->type,
'f',
$this->randomId,
$metadataId[0],
$this->harvestResult,
$this->harvestException
);
$t = array('s','s','s','s','b','s','i','i','s');
} else {
$sql = "INSERT INTO mb_metadata (link, origin, md_format, linktype, createdate, changedate, export2csw, randomid, fkey_mb_user_id, harvestresult, harvestexception) ";
$sql .= "VALUES($1, $2, $3, $4, now(), now(), $5, $6, $7, $8, $9)";
$v = array(
$this->href,
$this->origin,
$this->format,
$this->type,
'f',
$this->randomId,
$this->owner,
$this->harvestresult,
$this->harvestexception
);
$t = array('s','s','s','s','b','s','i','i','s');
}
$res = db_prep_query($sql,$v,$t);
if(!$res){
db_rollback();
$e = new mb_exception("class_Iso19139:"._mb("Cannot insert or update metadataUrl in database!"));
return false;
} else {
//insert relation into db
//get inserted metadata_id
$sql = <<randomId);
$t = array('s');
try {
$res = db_prep_query($sql,$v,$t);
}
catch (Exception $e){
$e = new mb_exception("class_Iso19139:"._mb("Cannot get metadata record with following random id from database: ".$this->randomId));
}
if (!$res) {
//do nothing
$e = new mb_exception("class_Iso19139:"._mb("Cannot find inserted metadata entry to store relation."));
return false;
} else {
//insert relation
$row = db_fetch_assoc($res);
$metadataId = $row['metadata_id'];
//insert relation to layer/featuretype
$sql = "INSERT INTO ows_relation_metadata (fkey_".$resourceType."_id, fkey_metadata_id, relation_type) values ($1, $2, $3);";
$v = array($resourceId, $metadataId, $this->origin);
$t = array('i','i', 's');
$res = db_prep_query($sql,$v,$t);
if(!$res){
db_rollback();
$e = new mb_exception("class_Iso19139:"._mb("Cannot insert metadata relation!"));
return false;
} else {
$sql = "UPDATE mb_metadata SET harvestresult = 0, harvestexception = 'Linked metadata could not be interpreted, only linkage is stored to mb_metadata!' where metadata_id = $1";
$v = array($metadataId);
$t = array('i');
$res = db_prep_query($sql,$v,$t);
if(!$res){
db_rollback();
$e = new mb_exception("class_Iso19139:"._mb("Cannot update mb_metadata table!"));
return false;
}
}
}
return true;
}
return true;
}
private function getExtentGraphic($layer_4326_box) {
$rlp_4326_box = array(6.05,48.9,8.6,50.96);
if ($layer_4326_box[0] <= $rlp_4326_box[0] || $layer_4326_box[2] >= $rlp_4326_box[2] || $layer_4326_box[1] <= $rlp_4326_box[1] || $layer_4326_box[3] >= $rlp_4326_box[3]) {
if ($layer_4326_box[0] < $rlp_4326_box[0]) {
$rlp_4326_box[0] = $layer_4326_box[0];
}
if ($layer_4326_box[2] > $rlp_4326_box[2]) {
$rlp_4326_box[2] = $layer_4326_box[2];
}
if ($layer_4326_box[1] < $rlp_4326_box[1]) {
$rlp_4326_box[1] = $layer_4326_box[1];
}
if ($layer_4326_box[3] > $rlp_4326_box[3]) {
$rlp_4326_box[3] = $layer_4326_box[3];
}
$d_x = $rlp_4326_box[2] - $rlp_4326_box[0];
$d_y = $rlp_4326_box[3] - $rlp_4326_box[1];
$new_minx = $rlp_4326_box[0] - 0.05*($d_x);
$new_maxx = $rlp_4326_box[2] + 0.05*($d_x);
$new_miny = $rlp_4326_box[1] - 0.05*($d_y);
$new_maxy = $rlp_4326_box[3] + 0.05*($d_y);
if ($new_minx < -180) $rlp_4326_box[0] = -180; else $rlp_4326_box[0] = $new_minx;
if ($new_maxx > 180) $rlp_4326_box[2] = 180; else $rlp_4326_box[2] = $new_maxx;
if ($new_miny < -90) $rlp_4326_box[1] = -90; else $rlp_4326_box[1] = $new_miny;
if ($new_maxy > 90) $rlp_4326_box[3] = 90; else $rlp_4326_box[3] = $new_maxy;
}
$getMapUrl = EXTENTSERVICEURL."VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&LAYERS=".EXTENTSERVICELAYER."&STYLES=&SRS=EPSG:4326&BBOX=".$rlp_4326_box[0].",".$rlp_4326_box[1].",".$rlp_4326_box[2].",".$rlp_4326_box[3]."&WIDTH=120&HEIGHT=120&FORMAT=image/png&BGCOLOR=0xffffff&TRANSPARENT=TRUE&EXCEPTIONS=application/vnd.ogc.se_inimage&minx=".$layer_4326_box[0]."&miny=".$layer_4326_box[1]."&maxx=".$layer_4326_box[2]."&maxy=".$layer_4326_box[3];
return $getMapUrl;
}
public function insertToDB($resourceType, $resourceId){
$result = array(); //value/message
switch ($this->origin) {
case "capabilities":
//check if href is given and resource can be parsed
//following information must be given:
//randomId, href, format, type, origin, owner
//TODO: that empty identifier not identified - see comparing linkage
if ((($this->type == 'ISO19115:2003' || $this->type == 'ISO 19115:2003') && $this->format =='text/xml') || ($this->type == 'TC211' && $this->format =='text/xml') || (($this->type == 'ISO19115:2003' || $this->type == 'ISO 19115:2003') && ($this->format =='application/vnd.iso.19139+xml' || $this->format =='application/xml'))) {
$e = new mb_notice("class_Iso19139:"."try to parse: ".$this->href);
$metadata = $this->createFromUrl($this->href); //will alter object itself
$e = new mb_notice("class_Iso19139:"."Metadata found: ".$this->metadata);
if ($metadata == false) {
//try to insert only MetadataURL elements
if (!$this->insertMetadataUrlToDB($resourceType, $resourceId)) {
$e = new mb_exception("class_Iso19139:"."Problem while storing MetadataURL entry from wms capabilities to mb_metadata table!");
$result['value'] = false;
$result['message'] = "Problem while storing MetadataURL entry from wms capabilities to mb_metadata table!";
return $result;
} else {
$e = new mb_exception("class_Iso19139:"."Storing only MetadataURL ".$metadata->href." from capabilities to mb database cause the target could not be accessed or parsed!");
$result['value'] = true;
$result['message'] = "Storing only MetadataURL ".$metadata->href." from capabilities to mb database cause the target could not be accessed or parsed!";
return $result;
}
}
} else {
$e = new mb_exception("class_Iso19139:"."MetadataURL format or type of following url is not supported: Format: ".$this->format." | type: ".$this->type);
}
break;
case "external":
//don't check format and type -cause they are not given. Otherwise the same as in case of capabilities
$metadata = $this->createFromUrl($this->href); //will alter object itself
if ($metadata == false) {
//try to insert only MetadataURL elements
if (!$this->insertMetadataUrlToDB($resourceType, $resourceId)) {
$e = new mb_exception("class_Iso19139:"."Problem while storing MetadataURL entry from wms capabilities to mb_metadata table!");
$result['value'] = false;
$result['message'] = "Problem while storing MetadataURL entry from wms capabilities to mb_metadata table!";
return $result;
} else {
$e = new mb_exception("class_Iso19139:"."Storing only MetadataURL ".$metadata->href." from capabilities to mb database cause the target could not be accessed or parsed!");
$result['value'] = true;
$result['message'] = "Storing only MetadataURL ".$metadata->href." from capabilities to mb database cause the target could not be accessed or parsed!";
return $result;
}
}
break;
case "metador":
//nothing to do at all?
break;
case "upload":
//nothing to do at all?
$e = new mb_exception("class_Iso19139:"."upload found");
//$e = new mb_exception($this->metadata);
$metadata = $this->createMapbenderMetadataFromXML($this->metadata);
if ($metadata == false) {
//xml could not be parsed
$result['value'] = false;
$result['message'] = "Metadata object could not be created!";
return $result;
}
//else save it into database
break;
/*case "internal":
//only set relation to existing record - return true;
//is actually handled thru plugins/mn_metadata_server*
break;*/
default:
$e = new mb_exception("class_Iso19139:"."Metadata origin is not known - please set it before storing values to DB!");
$result['value'] = false;
$result['message'] = "Metadata origin is not known - please set it before storing values to DB!";
return $result;
}
//check if metadata record already exists, if not create a new one, else insert relation only and update the metadata itself!
$metadataId = $this->isFileIdentifierAlreadyInDB();
if ($metadataId != false) {
//update the metadata - new random id set therefor there is no problem when setting the relation afterwards
$e = new mb_exception("existing metadata fileIdentifier found at metadata with id: ".$metadataId[0]." - update will be performed");
//check if the timestamp of an existing metadata element is not newer than the timestamp of the current metadata object!!!!
$res = $this->updateMetadataById($metadataId[0]);
} else {
//check if href already exists
$metadataId = $this->isLinkAlreadyInDB();
//if so, the metadataset will be the same - (same url same metadataset) - update this as before
if ($metadataId != false) {
//the link to an existing metadataset already exists - don't store it again or insert anything
$e = new mb_exception("existing metadata linkage found at metadata with id: ".$metadataId[0]." - update will be performed");
//check if the timestamp of an existing metadata element is not newer than the timestamp of the current metadata object!!!!
$res = $this->updateMetadataById($metadataId[0]);
} else {
//insert new record
$e = new mb_exception("class_Iso19139:"."No existing metadata fileIdentifier found in mapbender metadata table. New record will be inserted with uuid: ".$this->fileIdentifier);
$res = $this->insertMetadataIntoDB();
}
}
if(!$res){
db_rollback();
$e = new mb_exception("class_Iso19139:"._mb("Cannot insert or update metadata record into mapbenders mb_metadata table!"));
$result['value'] = false;
$result['message'] = "Cannot insert or update metadata record into mapbenders mb_metadata table!";
return $result;
} else {
//insert relation into db
//get inserted metadata_id by use the
$sql = <<randomId);
$t = array('s');
try {
$res = db_prep_query($sql,$v,$t);
}
catch (Exception $e){
$e = new mb_exception("class_Iso19139:"._mb("Cannot get metadata record with following uuid from database: ".$this->randomId));
}
if (!$res) {
//do nothing
$e = new mb_exception("class_Iso19139:"._mb("Cannot get metadata record with following uuid from database: ".$this->randomId));
$result['value'] = false;
$result['message'] = "Cannot get metadata record with following uuid from database: ".$uuid;
return $result;
} else {
//insert relation
$row = db_fetch_assoc($res);
$metadataId = $row['metadata_id'];
//check if current relation already exists in case of upload
if ($this->checkMetadataRelation($resourceType, $resourceId, $metadataId)) {
$e = new mb_exception("class_Iso19139:"._mb("Relation already exists - it will not be generated twice!"));
$result['value'] = true;
$result['message'] = "Relation already exists - it will not be generated twice!";
return $result;
}
//insert relation to layer/featuretype
$sql = "INSERT INTO ows_relation_metadata (fkey_".$resourceType."_id, fkey_metadata_id, relation_type) values ($1, $2, $3);";
$v = array($resourceId, $metadataId, $this->origin);
$t = array('i','i','s');
$res = db_prep_query($sql,$v,$t);
if(!$res){
db_rollback();
$e = new mb_exception("class_Iso19139:"._mb("Cannot insert metadata relation!"));
$result['value'] = false;
$result['message'] = "Cannot insert metadata relation!";
return $result;
} else {
$sql = "UPDATE mb_metadata SET harvestresult = 1 where metadata_id = $1";
$v = array($metadataId);
$t = array('i');
$res = db_prep_query($sql,$v,$t);
if(!$res){
db_rollback();
$e = new mb_exception("class_Iso19139:"._mb("Cannot update mb_metadata table to fill in harvest result!"));
$result['value'] = false;
$result['message'] = "Cannot update mb_metadata table to fill in harvest result!";
return $result;
} else {
$this->insertKeywordsAndCategoriesIntoDB($metadataId);
}
}
}
$result['value'] = true;
$result['message'] = "Insert metadata successfully into database!";
return $result;
}
}
}
?>