$kml_id = md5(uniqid(rand(), true));
 //dbselect for generate KML
 $sql_kml = "select wms.wms_getmap, wms.wms_version, layer.layer_name,layer.layer_title, layer_epsg.minx,layer_epsg.miny,layer_epsg.maxx,layer_epsg.maxy from wms, layer, layer_epsg, wms_format where layer.layer_id=\$1 and layer.fkey_wms_id=wms.wms_id and layer.layer_id=layer_epsg.fkey_layer_id and layer_epsg.epsg='EPSG:4326' and wms.wms_id=wms_format.fkey_wms_id and wms_format.data_format like '%image/png%' LIMIT 1";
 $v_kml = array($layer_id);
 $t_kml = array('i');
 $res_kml = db_prep_query($sql_kml, $v_kml, $t_kml);
 $row_kml = db_fetch_array($res_kml);
 generateKML($kml_id, $resdir, $row_kml['wms_getmap'], $row_kml['wms_version'], $row_kml['layer_name'], $row_kml['layer_title'], $row_kml['maxy'], $row_kml['miny'], $row_kml['maxx'], $row_kml['minx']);
 //export KML
 $metadataStr .= "<tr><th>Weitere Schnittstellen</th><td>";
 $metadataStr .= "<a href='kmldownload.php?download=" . $kml_id . ".kml'>KML (Keyhole Markup Language)</a>";
 $user = new User();
 //
 // Monitoring is only available if the user is allowed to access this service
 //
 if ($user->isLayerAccessible($layer['ID'])) {
     if ($subscribe === 1) {
         $user->addSubscription($layer['WMS ID']);
     } else {
         if ($subscribe === 0) {
             $user = new User();
             $user->cancelSubscription($layer['WMS ID']);
         }
     }
     $currentUser = new User();
     $is_subscribed = $currentUser->hasSubscription($wms_id);
     $is_public = $currentUser->isPublic();
     //show abo function to registred and authorized users
     if ($is_subscribed && !$is_public) {
         $metadataStr .= "<tr><th>Abo</th><td><img src = '../img/mail_delete.png'>" . "<a href = '../php/mod_layerMetadata.php?id=" . $layer_id . "&user_id=" . $currentUser->id . "&subscribe=0'>" . _mb("Monitoring Abo l&ouml;schen") . "</a></td></tr>";
     } else {
#$html .= "<br>".$resourceMetadata['contentpos']."<br>";
#$html .= "<br>".$resource."<br>";
if ($resource == 'layer' & $resourceMetadata['contentpos'] == 0) {
    $resourceSymbol = "<img src='../img/osgeo_graphics/geosilk/server_map.png' alt='" . $translation['wms'] . " - picture' title='" . $translation['wms'] . "'> - " . $translation['wms'];
}
if ($metadataContactGroup['metadatapointofcontactorglogo'] != '') {
    $html .= $t_a . $translation['contactOrganization'] . $t_b . "<img src='" . $metadataContactGroup['metadatapointofcontactorglogo'] . "'  height='30'>";
}
$html .= displayText($metadataContactGroup['metadatacontactorganization']) . $t_c;
if ($resourceMetadata['contentabstract'] != '') {
    $html .= $t_a . $translation['resourceAbstract'] . $t_b . displayText($resourceMetadata['contentabstract']) . $t_c;
} else {
    $html .= $t_a . $translation['resourceAbstract'] . $t_b . displayText($resourceMetadata['serviceabstract']) . $t_c;
}
$user = new User();
$layerAccessibility = $user->isLayerAccessible($layerId);
//
//
// Monitoring is only available if the user is allowed to access this service
//
if ($resource == 'wms' or $resource == 'layer') {
    if ($layerAccessibility) {
        $is_public = $user->isPublic();
        //show abo function to registred and authorized users
        if (!$is_public) {
            if ($subscribe == 1) {
                $user->addSubscription($resourceMetadata['serviceid']);
            } else {
                if ($subscribe == 0) {
                    $user->cancelSubscription($resourceMetadata['serviceid']);
                }