private function readConfig($jsonConfFile)
 {
     $admin = new administration();
     $mbjson = new Mapbender_JSON();
     $jsonStr = file_get_contents(dirname(__FILE__) . "/../" . $jsonConfFile);
     if ($jsonStr == false) {
         $e = new mb_exception("mbPdfFactory: config file could not be read.");
         die("config not found.");
     }
     $jsonConf = $mbjson->decode($admin->char_encode($jsonStr));
     return $jsonConf;
 }
 function updateObjInDB($myWMS)
 {
     if (!isset($this->wms_network_access) || $this->wms_network_access == '') {
         $this->wms_network_access = intval('0');
     }
     $admin = new administration();
     db_begin();
     $sql = "UPDATE wms SET ";
     $sql .= "wms_version = \$1 ,";
     $sql .= "wms_getcapabilities  = \$2 ,";
     $sql .= "wms_getmap  = \$3 ,";
     $sql .= "wms_getfeatureinfo  = \$4 ,";
     $sql .= "wms_getlegendurl  = \$5 ,";
     $sql .= "wms_getcapabilities_doc = \$6 ,";
     $sql .= "wms_upload_url = \$7,  ";
     $sql .= "wms_owner = \$8, ";
     $sql .= "wms_timestamp = \$9, ";
     $sql .= "wms_supportsld = \$10, ";
     $sql .= "wms_userlayer = \$11, ";
     $sql .= "wms_userstyle = \$12, ";
     $sql .= "wms_remotewfs = \$13, ";
     $sql .= "wms_network_access = \$14, ";
     $sql .= "fkey_mb_group_id = \$15, ";
     $sql .= "uuid = \$16 ";
     $sql .= " WHERE wms_id = \$17";
     $v = array($this->wms_version, $this->wms_getcapabilities, $this->wms_getmap, $this->wms_getfeatureinfo, $this->wms_getlegendurl, $admin->char_encode($this->wms_getcapabilities_doc), $this->wms_upload_url, Mapbender::session()->get("mb_user_id"), strtotime("now"), $this->wms_supportsld, $this->wms_userlayer, $this->wms_userstyle, $this->wms_remotewfs, $this->wms_network_access, $this->fkey_mb_group_id, $this->uuid, $myWMS);
     $t = array('s', 's', 's', 's', 's', 's', 's', 'i', 'i', 's', 's', 's', 's', 'i', 'i', 's', 'i');
     $res = db_prep_query($sql, $v, $t);
     if (!$res) {
         db_rollback();
     }
     if ($this->overwrite == true) {
         $sql = "UPDATE wms SET ";
         $sql .= "wms_title  = \$1 ,";
         $sql .= "wms_abstract  = \$2 ,";
         $sql .= "fees = \$3, ";
         $sql .= "accessconstraints = \$4, ";
         $sql .= "contactperson = \$5, ";
         $sql .= "contactposition = \$6, ";
         $sql .= "contactorganization = \$7, ";
         $sql .= "address = \$8, ";
         $sql .= "city = \$9, ";
         $sql .= "stateorprovince = \$10, ";
         $sql .= "postcode = \$11, ";
         $sql .= "country = \$12, ";
         $sql .= "contactvoicetelephone = \$13, ";
         $sql .= "contactfacsimiletelephone = \$14, ";
         $sql .= "contactelectronicmailaddress = \$15, ";
         $sql .= "wms_network_access = \$16, ";
         $sql .= "fkey_mb_group_id = \$17, ";
         $sql .= "uuid = \$18 ";
         $sql .= " WHERE wms_id = \$19";
         $v = array($this->wms_title, $this->wms_abstract, $this->fees, $this->accessconstraints, $this->contactperson, $this->contactposition, $this->contactorganization, $this->address, $this->city, $this->stateorprovince, $this->postcode, $this->country, $this->contactvoicetelephone, $this->contactfacsimiletelephone, $this->contactelectronicmailaddress, $this->wms_network_access, $this->fkey_mb_group_id, $this->uuid, $myWMS);
         $t = array('s', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 'i', 'i', 's', 'i');
         $res = db_prep_query($sql, $v, $t);
         if (!$res) {
             db_rollback();
         }
     }
     # delete and refill wms_termsofuse
     $sql = "DELETE FROM wms_termsofuse WHERE fkey_wms_id = \$1 ";
     $v = array($myWMS);
     $t = array('i');
     $res = db_prep_query($sql, $v, $t);
     if (!$res) {
         db_rollback();
     }
     $this->insertTermsOfUse($myWMS);
     # delete and refill srs and formats
     $sql = "DELETE FROM wms_srs WHERE fkey_wms_id = \$1 ";
     $v = array($myWMS);
     $t = array('i');
     $res = db_prep_query($sql, $v, $t);
     if (!$res) {
         db_rollback();
     }
     $this->insertSRS($myWMS);
     $sql = "DELETE FROM wms_format WHERE fkey_wms_id = \$1 ";
     $v = array($myWMS);
     $t = array('i');
     $res = db_prep_query($sql, $v, $t);
     if (!$res) {
         db_rollback();
     }
     $this->insertFormat($myWMS);
     # update gui_wms
     $this->update_gui_wms($myWMS);
     # update TABLE layer
     $oldLayerNameArray = array();
     $v = array($myWMS);
     $t = array('i');
     $c = 2;
     $sql = "SELECT layer_id, layer_name, layer_title, layer_abstract FROM layer WHERE fkey_wms_id = \$1 AND NOT layer_name IN(";
     for ($i = 0; $i < count($this->objLayer); $i++) {
         if ($i > 0) {
             $sql .= ',';
         }
         $sql .= "\$" . $c;
         array_push($v, $this->objLayer[$i]->layer_name);
         //$e = new mb_exception("class_wms: old layer name added for read: ".$this->objLayer[$i]->layer_name);
         array_push($t, 's');
         $c++;
     }
     $sql .= ")";
     $res = db_prep_query($sql, $v, $t);
     while ($row = db_fetch_array($res)) {
         $oldLayerNameArray[] = array("id" => $row["layer_id"], "name" => $row["layer_name"], "title" => $row["layer_title"], "abstract" => $row["layer_abstract"]);
     }
     # delete all layer which are outdated
     //first delete their metadataUrl entries*****
     $v = array($myWMS);
     $t = array('i');
     $c = 2;
     $sql = "DELETE FROM mb_metadata WHERE metadata_id IN (SELECT metadata_id FROM mb_metadata INNER JOIN (SELECT * from ows_relation_metadata WHERE fkey_layer_id IN ";
     $sql .= "(SELECT layer_id FROM layer WHERE fkey_wms_id = \$1 AND NOT layer_name IN (";
     for ($i = 0; $i < count($this->objLayer); $i++) {
         if ($i > 0) {
             $sql .= ',';
         }
         $sql .= "\$" . $c;
         array_push($v, $this->objLayer[$i]->layer_name);
         array_push($t, 's');
         $c++;
     }
     $sql .= ") ) )";
     $sql .= " as relation ON  mb_metadata.metadata_id = relation.fkey_metadata_id AND mb_metadata.origin = 'capabilities')";
     $res = db_prep_query($sql, $v, $t);
     //*******************************************
     //TODO: is this done for the keywords too? Maybe not, cause they are stored only once! Only the relations have to be deleted!
     //and then the layer entries
     $v = array($myWMS);
     $t = array('i');
     $c = 2;
     $sql = "DELETE FROM layer WHERE fkey_wms_id = \$1 AND NOT layer_name IN(";
     for ($i = 0; $i < count($this->objLayer); $i++) {
         if ($i > 0) {
             $sql .= ',';
         }
         $sql .= "\$" . $c;
         array_push($v, $this->objLayer[$i]->layer_name);
         //$e = new mb_exception("class_wms: old layer name added for delete: ".$this->objLayer[$i]->layer_name);
         array_push($t, 's');
         $c++;
     }
     $sql .= ")";
     $res = db_prep_query($sql, $v, $t);
     if (!$res) {
         db_rollback();
     }
     # update or insert?
     $sql = "SELECT layer_name FROM layer WHERE fkey_wms_id = \$1";
     $v = array($myWMS);
     $t = array('i');
     $res = db_prep_query($sql, $v, $t);
     $exLayer = array();
     while ($row = db_fetch_array($res)) {
         array_push($exLayer, $row["layer_name"]);
     }
     $sql = "SELECT fkey_gui_id FROM gui_wms WHERE fkey_wms_id = \$1";
     $v = array($myWMS);
     $t = array('i');
     $res = db_prep_query($sql, $v, $t);
     $exGui = array();
     while ($row = db_fetch_array($res)) {
         array_push($exGui, $row["fkey_gui_id"]);
     }
     $newLayerArray = array();
     for ($i = 0; $i < count($this->objLayer); $i++) {
         if (in_array($this->objLayer[$i]->layer_name, $exLayer)) {
             //echo "<br>update: ".$this->objLayer[$i]->layer_name;
             $this->updateLayer($i, $myWMS);
             for ($j = 0; $j < count($exGui); $j++) {
                 $this->updateGuiLayer($i, $myWMS, $exGui[$j]);
             }
         } else {
             //echo "<br>append: ".$this->objLayer[$i]->layer_name;
             $this->insertLayer($i, $myWMS);
             $newLayerArray[] = $i;
             for ($j = 0; $j < count($exGui); $j++) {
                 $this->appendGuiLayer($i, $myWMS, $exGui[$j]);
             }
         }
     }
     db_commit();
     //
     // update GeoRSS feed
     //
     $geoRssFactory = new GeoRssFactory();
     $geoRss = $geoRssFactory->loadOrCreate(GEO_RSS_FILE);
     if (!is_null($geoRss)) {
         $geoRssItem = new GeoRssItem();
         $geoRssItem->setTitle("UPDATED WMS: " . $this->wms_title . " (" . $myWMS . ")");
         $geoRssItem->setDescription($this->wms_abstract);
         $geoRssItem->setUrl(self::getWmsMetadataUrl($myWMS));
         $geoRssItem->setPubDate(self::rssDate());
         for ($j = 0; $j < count($this->objLayer[0]->layer_epsg); $j++) {
             $currentEpsg = $this->objLayer[0]->layer_epsg[$j];
             if ($currentEpsg["epsg"] === "EPSG:4326") {
                 $currentBbox = new Mapbender_bbox($currentEpsg["minx"], $currentEpsg["miny"], $currentEpsg["maxx"], $currentEpsg["maxy"], $currentEpsg["epsg"]);
                 $geoRssItem->setBbox($currentBbox);
                 break;
             }
         }
         $geoRss->appendTop($geoRssItem);
         foreach ($newLayerArray as $newLayer) {
             $currentLayer = $this->objLayer[$newLayer];
             $geoRssItemNewLayer = new GeoRssItem();
             $geoRssItemNewLayer->setTitle("NEW LAYER: " . $currentLayer->layer_title . " (" . $currentLayer->layer_id . ")");
             $geoRssItemNewLayer->setDescription($currentLayer->layer_abstract);
             $geoRssItemNewLayer->setUrl(self::getLayerMetadataUrl($currentLayer->layer_id));
             $geoRssItemNewLayer->setPubDate(self::rssDate());
             for ($j = 0; $j < count($currentLayer->layer_epsg); $j++) {
                 $currentEpsg = $currentLayer->layer_epsg[$j];
                 if ($currentEpsg["epsg"] === "EPSG:4326") {
                     $currentBbox = new Mapbender_bbox($currentEpsg["minx"], $currentEpsg["miny"], $currentEpsg["maxx"], $currentEpsg["maxy"], $currentEpsg["epsg"]);
                     $geoRssItemNewLayer->setBbox($currentBbox);
                     break;
                 }
             }
             $geoRss->appendTop($geoRssItemNewLayer);
         }
         foreach ($oldLayerNameArray as $oldLayer) {
             $geoRssItemOldLayer = new GeoRssItem();
             $geoRssItemOldLayer->setTitle("DELETED LAYER: " . $oldLayer['title'] . " (" . $oldLayer['id'] . ")");
             $geoRssItemOldLayer->setUrl(self::getLayerMetadataUrl($oldLayer['id']));
             $geoRssItemOldLayer->setDescription($oldLayer["abstract"]);
             $geoRssItemOldLayer->setPubDate(self::rssDate());
             //				$geoRssItem->setUrl();
             $geoRss->appendTop($geoRssItemOldLayer);
         }
         $geoRss->saveAsFile();
     }
     return;
 }
 /**
 * updateObjFromXML
 *
 * this function regets the information from the xml (update)
 * @return boolean true if successful, false otherwise
 */
 function updateObjFromXML($url)
 {
     $x = new connector($url);
     $data = $x->file;
     #$data = implode("",file($url));
     if (!$data) {
         $e = new mb_exception("Unable to open document: " . $url);
         return false;
     }
     $values = null;
     $tags = null;
     $admin = new administration();
     $this->wfs_getcapabilities_doc = $admin->char_encode($data);
     $this->wfs_featuretype = array();
     $this->wfs_upload_url = $url;
     # for temporary wfs a id has to be created...
     //$this->wfs_id = "id_" . substr(md5(rand()),0,6);
     $parser = xml_parser_create(CHARSET);
     xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
     xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
     xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, CHARSET);
     xml_parse_into_struct($parser, $this->wfs_getcapabilities_doc, $values, $tags);
     //xml_parse_into_struct($parser,$data,$values,$tags);
     xml_parser_free($parser);
     $section = false;
     $request = false;
     $featuretype_name = false;
     $featuretype_title = false;
     $featuretype_abstract = false;
     $featuretype_srs = false;
     foreach ($values as $element) {
         if (strtoupper($element[tag]) == "WFS_CAPABILITIES" && $element[type] == "open") {
             $this->wfs_version = $element[attributes][version];
         }
         if (strtoupper($element[tag]) == "NAME" && $element[level] == '3') {
             $this->wfs_name = $element[value];
         }
         /*		if(strtoupper($element[tag]) == "TITLE"  && $element[level] == '3'){
         			$this->wfs_title = $this->stripEndlineAndCarriageReturn($element[value]);
         		}
         		if(strtoupper($element[tag]) == "ABSTRACT" && $element[level] == '3'){
         			$this->wfs_abstract = $this->stripEndlineAndCarriageReturn($element[value]);
         		}
         		//new WFS 1.0.0 -- SB 2007-08-06
         		if(strtolower($element[tag]) == "fees"){
         			$this->fees = $element[value];
         		}
         		if(strtolower($element[tag]) == "accessconstraints"){
         			$this->accessconstraints = $element[value];
         		}
         */
         /*capability section*/
         if ($this->wfs_version == "1.0.0") {
             # getCapabilities
             if (strtoupper($element[tag]) == "GETCAPABILITIES" && $element[type] == "open") {
                 $section = "getcapabilities";
             }
             if ($section == "getcapabilities" && strtoupper($element[tag]) == "POST") {
                 $this->wfs_getcapabilities = $element[attributes][onlineResource];
             }
             # descriptFeatureType
             if (strtoupper($element[tag]) == "DESCRIBEFEATURETYPE" && $element[type] == "open") {
                 $section = "describefeaturetype";
                 $this->wfs_describefeaturetype = $element[attributes][onlineResource];
             }
             if ($section == "describefeaturetype" && strtoupper($element[tag]) == "POST") {
                 $this->wfs_describefeaturetype = $element[attributes][onlineResource];
             }
             # getFeature
             if (strtoupper($element[tag]) == "GETFEATURE" && $element[type] == "open") {
                 $section = "getfeature";
             }
             if ($section == "getfeature" && strtoupper($element[tag]) == "POST") {
                 $this->wfs_getfeature = $element[attributes][onlineResource];
             }
             if (strtoupper($element[tag]) == "GETFEATURE" && $element[type] == "close") {
                 $section = "";
             }
             # transaction
             if (strtoupper($element[tag]) == "TRANSACTION" && $element[type] == "open") {
                 $section = "transaction";
             }
             if ($section == "transaction" && strtoupper($element[tag]) == "POST") {
                 $this->wfs_transaction = $element[attributes][onlineResource];
             }
             if (strtoupper($element[tag]) == "TRANSACTION" && $element[type] == "close") {
                 $section = "";
             }
         }
         if (strtoupper($element[tag]) == "FEATURETYPE" && $element[type] == "open") {
             $section = "featuretype";
         }
         if ($section == "featuretype" && strtoupper($element[tag]) == "NAME") {
             $featuretype_name = $element[value];
         }
         if ($section == "featuretype" && strtoupper($element[tag]) == "TITLE") {
             $featuretype_title = $this->stripEndlineAndCarriageReturn($element[value]);
         }
         if ($section == "featuretype" && strtoupper($element[tag]) == "ABSTRACT") {
             $featuretype_abstract = $this->{$element}[value];
         }
         if ($section == "featuretype" && strtoupper($element[tag]) == "SRS") {
             $featuretype_srs = $element[value];
             $this->addFeaturetype($featuretype_name, $featuretype_title, $featuretype_abstract, $featuretype_srs, $this->wfs_describefeaturetype, $this->wfs_version);
         }
     }
     return true;
 }
 /**
  * Creates WFS 1.0 objects from a capabilities documents.
  * 
  * @return Wfs_1_0
  * @param $xml String
  */
 public function createFromXml($xml)
 {
     try {
         $myWfs = new Wfs_1_0();
         $admin = new administration();
         $values = $admin->parseXml($xml);
         $myWfs->getCapabilitiesDoc = $admin->char_encode($xml);
         $myWfs->id = $this->createId();
         foreach ($values as $element) {
             $tag = strtoupper($element[tag]);
             if ($tag == "WFS_CAPABILITIES" && $element[type] == "open") {
                 $myWfs->version = $element[attributes][version];
                 if ($myWfs->version !== "1.0.0") {
                     throw new Exception("Not a WFS 1.0.0 capabilities document.");
                 }
             }
             if ($tag == "NAME" && $element[level] == '3') {
                 $myWfs->name = $element[value];
             }
             if ($tag == "TITLE" && $element[level] == '3') {
                 $myWfs->title = $this->stripEndlineAndCarriageReturn($element[value]);
             }
             if ($tag == "ABSTRACT" && $element[level] == '3') {
                 $myWfs->summary = $this->stripEndlineAndCarriageReturn($element[value]);
             }
             if ($tag == "FEES") {
                 $myWfs->fees = $element[value];
             }
             if ($tag == "ACCESSCONSTRAINTS") {
                 $myWfs->accessconstraints = $element[value];
             }
             # getCapabilities
             if ($tag == "GETCAPABILITIES" && $element[type] == "open") {
                 $section = "getcapabilities";
             }
             if ($section == "getcapabilities" && $tag == "GET") {
                 $myWfs->getCapabilities = $element[attributes][onlineResource];
             }
             # descriptFeatureType
             if ($tag == "DESCRIBEFEATURETYPE" && $element[type] == "open") {
                 $section = "describefeaturetype";
                 $myWfs->describeFeatureType = $element[attributes][onlineResource];
             }
             if ($section == "describefeaturetype" && $tag == "POST") {
                 $myWfs->describeFeatureType = $element[attributes][onlineResource];
             }
             # getFeature
             if ($tag == "GETFEATURE" && $element[type] == "open") {
                 $section = "getfeature";
             }
             if ($section == "getfeature" && $tag == "POST") {
                 $myWfs->getFeature = $element[attributes][onlineResource];
             }
             if ($tag == "GETFEATURE" && $element[type] == "close") {
                 $section = "";
             }
             # transaction
             if ($tag == "TRANSACTION" && $element[type] == "open") {
                 $section = "transaction";
             }
             if ($section == "transaction" && $tag == "POST") {
                 $myWfs->transaction = $element[attributes][onlineResource];
             }
             if ($tag == "TRANSACTION" && $element[type] == "close") {
                 $section = "";
             }
             if ($tag == "FEATURETYPE" && $element[type] == "open") {
                 $section = "featuretype";
             }
             if ($section == "featuretype" && $tag == "NAME") {
                 $featuretype_name = $element[value];
             }
             if ($section == "featuretype" && $tag == "TITLE") {
                 $featuretype_title = $this->stripEndlineAndCarriageReturn($element[value]);
             }
             if ($section == "featuretype" && $tag == "ABSTRACT") {
                 $featuretype_abstract = $element[value];
             }
             if ($section == "featuretype" && $tag == "SRS") {
                 $featuretype_srs = $element[value];
                 // Do not add defective featuretypes
                 try {
                     $currentFeatureType = $this->createFeatureTypeFromUrl($myWfs, $featuretype_name);
                     if ($currentFeatureType !== null) {
                         $currentFeatureType->name = $featuretype_name;
                         $currentFeatureType->title = $featuretype_title;
                         $currentFeatureType->summary = $featuretype_abstract;
                         $currentFeatureType->srs = $featuretype_srs;
                         $myWfs->addFeatureType($currentFeatureType);
                     }
                 } catch (Exception $e) {
                     new mb_exception("Failed to load featuretype " . $featuretype_name);
                 }
             }
         }
         return $myWfs;
     } catch (Exception $e) {
         $e = new mb_exception($e);
         return null;
     }
 }
 /**
  * Write catalog object to persistent storage
  * @param $gui
  * @return unknown_type
  */
 public function setCatObjToDB($gui)
 {
     global $con;
     $admin = new administration();
     //to char_encode XML
     db_begin();
     # INSERT INTO TABLE cat - auto insert cat_id
     $sql = "INSERT INTO cat( ";
     $sql .= "cat_version, cat_title, cat_abstract, ";
     $sql .= "cat_upload_url, fees, accessconstraints, providername, providersite, ";
     $sql .= "individualname, positionname, voice, facsimile, deliverypoint, ";
     $sql .= "city, administrativearea, postalcode, country, electronicmailaddress, ";
     $sql .= "cat_getcapabilities_doc, cat_owner, cat_timestamp) ";
     $sql .= "VALUES(\$1,\$2,\$3,\$4,\$5,\$6,\$7,\$8,\$9,\$10,\$11,\$12,\$13,\$14,\$15,\$16,\$17,\$18,\$19,\$20,\$21)";
     $v = array($this->cat_version, $this->cat_title, $this->cat_abstract, $this->cat_upload_url, $this->fees, $this->accessconstraints, $this->providername, $this->providersite, $this->contactperson, $this->contactposition, $this->contactvoicetelephone, $this->contactfacsimiletelephone, $this->delivery, $this->city, $this->address, $this->postcode, $this->country, $this->contactelectronicmailaddress, $admin->char_encode($this->cat_getcapabilities_doc), $_SESSION['mb_user_id'], strtotime("now"));
     $t = array('s', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 'i', 'i');
     $res = db_prep_query($sql, $v, $t);
     if (!$res) {
         db_rollback();
     }
     $cat_insert_id = db_insert_id($con, 'cat', 'cat_id');
     //GUI_CAT
     $sql = "INSERT INTO gui_cat (fkey_gui_id, fkey_cat_id) ";
     $sql .= "VALUES(\$1,\$2)";
     $v = array($gui, $cat_insert_id);
     $t = array('s', 'i');
     $res = db_prep_query($sql, $v, $t);
     if (!$res) {
         db_rollback();
     }
     //Insert operational values into cat_op_conf
     //CAT_OP_CONF
     foreach ($this->cat_op_values as $op_category => $op_name_array) {
         foreach ($op_name_array as $op_type => $op_value_array) {
             foreach ($op_value_array as $op_sub_type => $value) {
                 $op_type_value = $op_type;
                 if ($op_sub_type != 'dflt') {
                     //If not dflt, then it is either soap or xml - store this info as post_xml etc
                     $op_type_value .= '_' . $op_sub_type;
                 }
                 if (!isset($value)) {
                     $value = '';
                 }
                 //Store values
                 $sql = " INSERT INTO cat_op_conf(fk_cat_id, param_type, param_name, param_value) ";
                 $sql .= " VALUES (\$1, \$2, \$3, \$4)";
                 $v = array($cat_insert_id, $op_category, $op_type_value, $value);
                 $t = array('i', 's', 's', 's');
                 $res = db_prep_query($sql, $v, $t);
                 if (!$res) {
                     db_rollback();
                 }
             }
         }
     }
     //Commit Changes
     db_commit();
     $this->cat_id = $cat_insert_id;
 }
 /**
  * Creates WFS 1.0 objects from a capabilities documents.
  *
  * @return Wfs_1_1
  * @param $xml String
  */
 public function createFromXml($xml)
 {
     try {
         $myWfs = new Wfs_1_1();
         $admin = new administration();
         $values = $admin->parseXml($xml);
         $myWfs->getCapabilitiesDoc = $admin->char_encode($xml);
         $myWfs->id = $this->createId();
         foreach ($values as $element) {
             $tag = $this->sepNameSpace(strtoupper($element[tag]));
             if ($tag == "WFS_CAPABILITIES" && $element[type] == "open") {
                 $myWfs->version = $element[attributes][version];
                 if ($myWfs->version !== "1.1.0") {
                     throw new Exception("Not a WFS 1.1.0 capabilities document.");
                 }
             }
             if ($tag == "NAME" && $element[level] == '3') {
                 $myWfs->name = $element[value];
             }
             if ($tag == "TITLE" && $element[level] == '3') {
                 $myWfs->title = $this->stripEndlineAndCarriageReturn($element[value]);
             }
             if ($tag == "ABSTRACT" && $element[level] == '3') {
                 $myWfs->summary = $this->stripEndlineAndCarriageReturn($element[value]);
             }
             if ($tag == "FEES") {
                 $myWfs->fees = $element[value];
             }
             if ($tag == "ACCESSCONSTRAINTS") {
                 $myWfs->accessconstraints = $element[value];
             }
             if ($tag == "OPERATION" && $element[type] == "open") {
                 switch ($element[attributes][name]) {
                     case "GetCapabilities":
                         $section = "getcapabilities";
                         break;
                     case "DescribeFeatureType":
                         $section = "describefeaturetype";
                         break;
                     case "GetFeature":
                         $section = "getfeature";
                         break;
                     case "Transaction":
                         $section = "transaction";
                         break;
                 }
             }
             # getCapabilities
             if ($section == "getcapabilities" && $tag == "GET") {
                 $myWfs->getCapabilities = html_entity_decode($element[attributes]["xlink:href"]);
             }
             # descriptFeatureType
             #				if($section == "describefeaturetype" && $tag == "POST"){
             #					$myWfs->describeFeatureType = html_entity_decode($element[attributes]["xlink:href"]);
             #				}
             # descriptFeatureType
             if ($section == "describefeaturetype" && $tag == "GET") {
                 $myWfs->describeFeatureType = html_entity_decode($element[attributes]["xlink:href"]);
             }
             # getFeature
             if ($section == "getfeature" && $tag == "POST") {
                 $myWfs->getFeature = html_entity_decode($element[attributes]["xlink:href"]);
             }
             # transaction
             if ($section == "transaction" && $tag == "POST") {
                 $myWfs->transaction = html_entity_decode($element[attributes]["xlink:href"]);
             }
             if ($tag == "OPERATION" && $element[type] == "close") {
                 $section = "";
             }
             if ($tag == "FEATURETYPE" && $element[type] == "open") {
                 $section = "featuretype";
                 $featureTypeNsArray = $element[attributes];
             }
             if ($section == "featuretype" && $tag == "NAME") {
                 $featuretype_name = $element[value];
             }
             if ($section == "featuretype" && $tag == "TITLE") {
                 $featuretype_title = $this->stripEndlineAndCarriageReturn($element[value]);
             }
             if ($section == "featuretype" && $tag == "ABSTRACT") {
                 $featuretype_abstract = $element[value];
             }
             if ($section == "featuretype" && $tag == "DEFAULTSRS") {
                 $featuretype_srs = $element[value];
                 // Do not add defective featuretypes
                 try {
                     $currentFeatureType = $this->createFeatureTypeFromUrlGet($myWfs, $featuretype_name, $featureTypeNsArray);
                     if ($currentFeatureType !== null) {
                         $currentFeatureType->name = $featuretype_name;
                         $currentFeatureType->title = $featuretype_title;
                         $currentFeatureType->summary = $featuretype_abstract;
                         $currentFeatureType->srs = $featuretype_srs;
                         $myWfs->addFeatureType($currentFeatureType);
                     }
                 } catch (Exception $e) {
                     new mb_exception("Failed to load featuretype " . $featuretype_name);
                 }
             }
         }
         if (!$myWfs->title) {
             $myWfs->title = "Untitled";
         }
         return $myWfs;
     } catch (Exception $e) {
         $e = new mb_exception($e);
         return null;
     }
 }