function createObjFromDBNoGui($wms_id, $withProxyUrls = true)
 {
     $sql = "Select * from wms where wms_id = \$1 ";
     $v = array($wms_id);
     $t = array('i');
     $res_wms = db_prep_query($sql, $v, $t);
     $count_wms = 0;
     while ($row2 = db_fetch_array($res_wms)) {
         $this->wms_id = $row2["wms_id"];
         $this->wms_version = $row2["wms_version"];
         $this->wms_title = administration::convertIncomingString($this->stripEndlineAndCarriageReturn($row2["wms_title"]));
         $this->wms_abstract = administration::convertIncomingString($this->stripEndlineAndCarriageReturn($row2["wms_abstract"]));
         $wmsowsproxy = $row2["wms_owsproxy"];
         #$wmsowsproxy = "test";
         //exchange the method urls with owsproxy urls if needed - default is to do it, but sometimes this is not usefull!
         if ($wmsowsproxy != "" && $withProxyUrls) {
             $owsproxyurl = OWSPROXY . "/" . session_id() . "/" . $wmsowsproxy . "?";
             $this->wms_getmap = $owsproxyurl;
             $this->wms_getcapabilities = $owsproxyurl;
             $this->wms_getfeatureinfo = $owsproxyurl;
             $this->wms_getlegendurl = $owsproxyurl;
         } else {
             $this->wms_getmap = $row2["wms_getmap"];
             $this->wms_getcapabilities = $row2["wms_getcapabilities"];
             $this->wms_getfeatureinfo = $row2["wms_getfeatureinfo"];
             $this->wms_getlegendurl = $row2["wms_getlegendurl"];
         }
         // TO DO: Capabilities document needs to
         // be encoded to the original encoding
         // if different from the database encoding
         $this->wms_getcapabilities_doc = $row2["wms_getcapabilities_doc"];
         $this->wms_upload_url = $row2["wms_upload_url"];
         $this->wms_filter = $row2["wms_filter"];
         $this->wms_supportsld = $row2["wms_supportsld"];
         $this->wms_userlayer = $row2["wms_userlayer"];
         $this->wms_userstyle = $row2["wms_userstyle"];
         $this->wms_remotewfs = $row2["wms_remotewfs"];
         $this->wms_timestamp = $row2["wms_timestamp"];
         $this->wms_timestamp_create = $row2["wms_timestamp_create"];
         $this->fees = $row2["fees"];
         $this->accessconstraints = $row2["accessconstraints"];
         $this->contactperson = $row2["contactperson"];
         $this->contactposition = $row2["contactposition"];
         $this->contactvoicetelephone = $row2["contactvoicetelephone"];
         $this->contactfacsimiletelephone = $row2["contactfacsimiletelephone"];
         $this->contactorganization = $row2["contactorganization"];
         $this->address = $row2["address"];
         $this->city = $row2["city"];
         $this->stateorprovince = $row2["stateorprovince"];
         $this->postcode = $row2["postcode"];
         $this->country = $row2["country"];
         $this->contactelectronicmailaddress = $row2["contactelectronicmailaddress"];
         $this->wms_network_access = $row2["wms_network_access"];
         $this->fkey_mb_group_id = $row2["fkey_mb_group_id"];
         $this->uuid = $row2["uuid"];
         #some default
         $this->gui_wms_visible = 1;
         $this->gui_wms_opacity = 100;
         $this->gui_wms_epsg = $row["gui_wms_epsg"];
         $this->gui_wms_sldurl = $row["gui_wms_sldurl"];
         if ($this->wms_version == "1.0.0") {
             $this->gui_wms_mapformat = "PNG";
             $this->gui_wms_featureinfoformat = "MIME";
             $this->gui_wms_exceptionformat = "INIMAGE";
         } else {
             $this->gui_wms_mapformat = "image/png";
             $this->gui_wms_featureinfoformat = "text/html";
             $this->gui_wms_exceptionformat = "application/vnd.ogc.se_inimage";
         }
         $count_wms++;
     }
     ### formats
     $sql = "SELECT * FROM wms_format WHERE fkey_wms_id = \$1 ";
     $v = array($wms_id);
     $t = array('i');
     $res_wms = db_prep_query($sql, $v, $t);
     $count_format = 0;
     while ($row3 = db_fetch_array($res_wms)) {
         $this->data_type[$count_format] = $row3["data_type"];
         $this->data_format[$count_format] = $row3["data_format"];
         $count_format++;
     }
     $sql = "Select * from layer where fkey_wms_id = \$1 ORDER BY layer_pos";
     $v = array($wms_id);
     $t = array('i');
     $res_layer = db_prep_query($sql, $v, $t);
     $count_layer = 0;
     while ($row2 = db_fetch_array($res_layer)) {
         $this->addLayer($row2["layer_pos"], $row2["layer_parent"]);
         $layer_cnt = count($this->objLayer) - 1;
         $this->objLayer[$layer_cnt]->layer_uid = $row2["layer_id"];
         $this->objLayer[$layer_cnt]->layer_name = administration::convertIncomingString($row2["layer_name"]);
         $this->objLayer[$layer_cnt]->layer_title = administration::convertIncomingString($row2["layer_title"]);
         $this->objLayer[$layer_cnt]->layer_abstract = administration::convertIncomingString($row2["layer_abstract"]);
         $this->objLayer[$layer_cnt]->gui_layer_title = $this->objLayer[$layer_cnt]->layer_title;
         $this->objLayer[$layer_cnt]->layer_dataurl[0]->href = $row2["layer_dataurl"];
         //load all metadataUrl elements from mb_metadata
         $sql = "SELECT metadata_id, link, linktype, md_format FROM mb_metadata INNER JOIN (SELECT * from ows_relation_metadata WHERE fkey_layer_id = \$1) as relation ON  mb_metadata.metadata_id = relation.fkey_metadata_id AND mb_metadata.origin = 'capabilities'";
         $v = array($this->objLayer[$layer_cnt]->layer_uid);
         $t = array('i');
         $res_metadataUrl = db_prep_query($sql, $v, $t);
         $count_metadataUrl = 0;
         while ($row4 = db_fetch_array($res_metadataUrl)) {
             $this->objLayer[$layer_cnt]->layer_metadataurl[$count_metadataUrl]->href = $row4["link"];
             $e = new mb_notice("nogui layer_metadataurl: " . $row4["link"]);
             $this->objLayer[$layer_cnt]->layer_metadataurl[$count_metadataUrl]->type = $row4["linktype"];
             $this->objLayer[$layer_cnt]->layer_metadataurl[$count_metadataUrl]->format = $row4["md_format"];
             $count_metadataUrl++;
         }
         //old one:
         //$this->objLayer[$layer_cnt]->layer_metadataurl[0]->href = $row2["layer_metadataurl"];
         $this->objLayer[$layer_cnt]->layer_searchable = $row2["layer_searchable"];
         $this->objLayer[$layer_cnt]->layer_pos = $row2["layer_pos"];
         $this->objLayer[$layer_cnt]->layer_queryable = $row2["layer_queryable"];
         $this->objLayer[$layer_cnt]->layer_minscale = $row2["layer_minscale"];
         $this->objLayer[$layer_cnt]->layer_maxscale = $row2["layer_maxscale"];
         $this->objLayer[$layer_cnt]->uuid = $row2["uuid"];
         if ($this->objLayer[$layer_cnt]->layer_minscale == "") {
             $this->objLayer[$layer_cnt]->layer_minscale = 0;
         }
         if ($this->objLayer[$layer_cnt]->layer_maxscale == "") {
             $this->objLayer[$layer_cnt]->layer_maxscale = 0;
         }
         $this->objLayer[$layer_cnt]->gui_layer_minscale = $this->objLayer[$layer_cnt]->layer_minscale;
         $this->objLayer[$layer_cnt]->gui_layer_maxscale = $this->objLayer[$layer_cnt]->layer_maxscale;
         $this->objLayer[$layer_cnt]->gui_layer_queryable = $this->objLayer[$layer_cnt]->layer_queryable;
         $this->objLayer[$layer_cnt]->gui_layer_wms_id = $this->wms_id;
         $sql = "Select * from layer_epsg where fkey_layer_id = \$1 ORDER BY fkey_layer_id";
         $v = array($this->objLayer[$layer_cnt]->layer_uid);
         $t = array('i');
         $res_layer_epsg = db_prep_query($sql, $v, $t);
         $count_layer_epsg = 0;
         while ($row2 = db_fetch_array($res_layer_epsg)) {
             $this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["epsg"] = $row2["epsg"];
             $this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["minx"] = $row2["minx"];
             $this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["miny"] = $row2["miny"];
             $this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["maxx"] = $row2["maxx"];
             $this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["maxy"] = $row2["maxy"];
             $count_layer_epsg++;
         }
         ### read out keywords
         $sql = "SELECT keyword FROM keyword, layer_keyword \nWHERE keyword_id = fkey_keyword_id AND fkey_layer_id = \$1";
         $v = array($this->objLayer[$layer_cnt]->layer_uid);
         $t = array('i');
         $res_layer_keywords = db_prep_query($sql, $v, $t);
         $count_layer_keywords = 0;
         while ($row2 = db_fetch_array($res_layer_keywords)) {
             $this->objLayer[$layer_cnt]->layer_keyword[$count_layer_keywords] = $row2["keyword"];
             $count_layer_keywords++;
         }
         ### read out layer_md_topic_category_id
         $sql = "SELECT fkey_md_topic_category_id FROM layer_md_topic_category WHERE fkey_layer_id =  \$1";
         $v = array($this->objLayer[$layer_cnt]->layer_uid);
         $t = array('i');
         $res_layer_md_topic_category = db_prep_query($sql, $v, $t);
         $count_layer_md_topic_category = 0;
         while ($row2 = db_fetch_array($res_layer_md_topic_category)) {
             $this->objLayer[$layer_cnt]->layer_md_topic_category_id[$count_layer_md_topic_category] = $row2["fkey_md_topic_category_id"];
             $count_layer_md_topic_category++;
         }
         ### read out layer_inspire_category_id
         $sql = "SELECT fkey_inspire_category_id FROM layer_inspire_category WHERE fkey_layer_id =  \$1";
         $v = array($this->objLayer[$layer_cnt]->layer_uid);
         $t = array('i');
         $res_layer_inspire_category = db_prep_query($sql, $v, $t);
         $count_layer_inspire_category = 0;
         while ($row2 = db_fetch_array($res_layer_inspire_category)) {
             $this->objLayer[$layer_cnt]->layer_inspire_category_id[$count_layer_inspire_category] = $row2["fkey_inspire_category_id"];
             $count_layer_inspire_category++;
         }
         ### read out layer_custom_category_id
         $sql = "SELECT fkey_custom_category_id FROM layer_custom_category WHERE fkey_layer_id =  \$1";
         $v = array($this->objLayer[$layer_cnt]->layer_uid);
         $t = array('i');
         $res_layer_custom_category = db_prep_query($sql, $v, $t);
         $count_layer_custom_category = 0;
         while ($row2 = db_fetch_array($res_layer_custom_category)) {
             $this->objLayer[$layer_cnt]->layer_custom_category_id[$count_layer_custom_category] = $row2["fkey_custom_category_id"];
             $count_layer_custom_category++;
         }
         ### handle styles
         $sql = "SELECT * FROM layer_style WHERE fkey_layer_id = \$1 ";
         $v = array($this->objLayer[$layer_cnt]->layer_uid);
         $t = array('i');
         $res_style = db_prep_query($sql, $v, $t);
         $count_layer_style = 0;
         while ($row2 = db_fetch_array($res_style)) {
             $this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["name"] = $row2["name"];
             $this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["title"] = $row2["title"];
             if ($wmsowsproxy != "") {
                 if ($row2["legendurl"] != '') {
                     $this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["legendurl"] = $owsproxyurl . "REQUEST=getlegendgraphic&VERSION=" . $this->wms_version . "&LAYER=" . $this->objLayer[$layer_cnt]->layer_name . "&FORMAT=" . $row2["legendurlformat"] . "&STYLE=" . $row2["name"];
                 }
             } else {
                 if ($row2["legendurl"] != '') {
                     $this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["legendurl"] = $row2["legendurl"];
                     #$e = new mb_exception("legendurl = ".$this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["legendurl"]);
                 }
             }
             $this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["legendurlformat"] = $row2["legendurlformat"];
             $count_layer_style++;
         }
         $count_layer++;
     }
 }
 if ($command == "getSearchResults") {
     $wfs_conf_id = $_REQUEST["wfs_conf_id"];
     $backlink = $_REQUEST["backlink"];
     $frame = $_REQUEST["frame"];
     $filter = $_REQUEST["filter"];
     $url = $_REQUEST["url"];
     $typename = $_REQUEST["typename"];
     $destSrs = $_REQUEST["destSrs"];
     $wfsConf = WfsConfiguration::createFromDb($wfs_conf_id);
     if (is_null($wfsConf)) {
         sendErrorMessage("Invalid WFS conf: " . $wfs_conf_id);
     }
     // append authorisation condition to filter
     $filter = checkAccessConstraint($filter, $wfs_conf_id);
     $admin = new administration();
     $filter = administration::convertIncomingString($filter);
     $wfsId = $wfsConf->wfsId;
     $myWfsFactory = new UniversalWfsFactory();
     $myWfs = $myWfsFactory->createFromDb($wfsId);
     $data = $myWfs->getFeature($typename, $filter, $destSrs);
     if ($data === null) {
         die('{}');
     }
     if (defined("WFS_RESPONSE_SIZE_LIMIT") && WFS_RESPONSE_SIZE_LIMIT < strlen($data)) {
         die("Too many results, please restrict your search.");
     }
     //	$geomColumn = WfsConf::getGeomColumnNameByConfId($wfs_conf_id);
     $gmlFactory = new UniversalGmlFactory();
     $myGml = $gmlFactory->createFromXml($data, $wfsConf);
     if (!is_null($myGml)) {
         $geoJson = $myGml->toGeoJSON();
 /**
  * Get catalog object from DB
  * @param $cat_id
  * @return unknown_type
  */
 public function createCatObjFromDB($cat_id)
 {
     $sql = "select * from cat where cat_id = \$1";
     $v = array($cat_id);
     $t = array('i');
     $res = db_prep_query($sql, $v, $t);
     while ($row = db_fetch_array($res)) {
         $this->cat_id = $row['cat_id'];
         $this->cat_version = $row['cat_version'];
         $this->cat_abstract = administration::convertIncomingString($this->stripEndlineAndCarriageReturn($row['cat_abstract']));
         $this->cat_title = administration::convertIncomingString($this->stripEndlineAndCarriageReturn($row['cat_title']));
         $this->cat_upload_url = $row['cat_upload_url'];
         $this->cat_getcapabilities_doc = $row['cat_getcapabilities_doc'];
         $this->cat_id = $row['cat_id'];
         //Get op values
         $sql = "select * from cat_op_conf where fk_cat_id=\$1";
         $v = array($cat_id);
         $t = array('i');
         $res = db_prep_query($sql, $v, $t);
         while ($subrow = db_fetch_array($res)) {
             $this->cat_op_values[$subrow['param_type']][$subrow['param_name']] = $subrow['param_value'];
         }
     }
 }
 public function selectByUser($user, $showPublic = 0)
 {
     $wmcArray = array();
     // get WMC ids
     $wmcOwnerArray = $user->getWmcByOwner();
     if ($showPublic == 1) {
         $publicWmcIdArray = self::getPublicWmcIds();
         $wmcIdArray = array_keys(array_flip(array_merge($wmcOwnerArray, $publicWmcIdArray)));
     } else {
         $publicWmcIdArray = array();
         $wmcIdArray = $wmcOwnerArray;
     }
     // get WMC data
     $v = array();
     $t = array();
     $wmcIdList = "";
     for ($i = 0; $i < count($wmcIdArray); $i++) {
         if ($i > 0) {
             $wmcIdList .= ",";
         }
         $wmcIdList .= "\$" . ($i + 1);
         array_push($v, $wmcIdArray[$i]);
         array_push($t, 's');
     }
     if ($wmcIdList !== "") {
         $sql = "SELECT DISTINCT wmc_serial_id, wmc_title, wmc_timestamp, wmc_timestamp_create, wmc_public, abstract FROM mb_user_wmc ";
         $sql .= "WHERE wmc_serial_id IN (" . $wmcIdList . ") ";
         $sql .= "ORDER BY wmc_timestamp DESC";
         $res = db_prep_query($sql, $v, $t);
         while ($row = db_fetch_assoc($res)) {
             $currentResult = array();
             $currentResult["id"] = $row["wmc_serial_id"];
             $currentResult["abstract"] = $row["abstract"];
             $currentResult["title"] = administration::convertIncomingString($row["wmc_title"]);
             $currentResult["timestamp"] = date("M d Y H:i:s", $row["wmc_timestamp"]);
             $currentResult["timestamp_create"] = date("M d Y H:i:s", $row["wmc_timestamp_create"]);
             $currentResult["isPublic"] = $row["wmc_public"] == 1 ? true : false;
             $currentResult["disabled"] = in_array($currentResult["id"], $publicWmcIdArray) && !in_array($currentResult["id"], $wmcOwnerArray) || $user->isPublic() ? true : false;
             // get categories
             $currentResult["categories"] = $this->getCategoriesById($currentResult["id"], $user);
             $currentResult["keywords"] = $this->getKeywordsById($currentResult["id"], $user);
             array_push($wmcArray, $currentResult);
         }
     }
     return $wmcArray;
 }