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;
 }
     $sql .= " mb_metadata.metadata_id = relation.fkey_metadata_id AND mb_metadata.origin = 'capabilities')";
     $v = array($wmsList);
     $t = array('i');
     $res = db_prep_query($sql, $v, $t);
     //***
     $sql = "DELETE FROM wms WHERE wms_id = \$1";
     $v = array($wmsList);
     $t = array('i');
     $res = db_prep_query($sql, $v, $t);
     if ($res) {
         //
         // update GeoRSS feed
         //
         $geoRssFactory = new GeoRssFactory();
         $geoRss = $geoRssFactory->loadOrCreate(GEO_RSS_FILE);
         $geoRssItem = new GeoRssItem();
         $geoRssItem->setTitle("DELETED WMS: " . $wms_title . " (" . $wmsList . ")");
         $geoRssItem->setDescription($wms_abstract);
         $geoRssItem->setUrl(getWMSMetadataUrl($wmsList));
         //$timestamp = ($timestamp==null) ? time() : $timestamp;
         $timestamp = date(DATE_RSS, time());
         $geoRssItem->setPubDate($timestamp);
         $geoRss->appendTop($geoRssItem);
         $geoRss->saveAsFile();
     }
 }
 // display WMS List
 $wms_id_own = $admin->getWmsByOwner(Mapbender::session()->get("mb_user_id"), true);
 if (count($wms_id_own) > 0) {
     $v = array();
     $t = array();