$img = "wait.bmp";
 } elseif ($status[$k] == 1) {
     $img = "go.bmp";
 }
 if ($updated[$k] == "0" && $status[$k] == 0) {
     $fill = "checked";
 } else {
     $fill = "disabled";
 }
 if (fmod($cnt, 2) == 1) {
     $str .= "\n\t\t<tr bgcolor='#e6e6e6'>";
 } else {
     $str .= "\n\t\t<tr bgcolor='#f0f0f0'>";
 }
 $str .= "\n\t\t\t<td><input name='cb" . $cnt . "' value='" . $wms_id[$k] . "' type=checkbox " . $fill . " /><input type=hidden name='upl_id" . $cnt . "' value='" . $upload_id[$k] . "'></td>";
 $str .= "\n\t\t\t<td valign='top'><b>" . $wms_id[$k] . "</b><br>" . $admin->getWmsTitleByWmsId($wms_id[$k]) . "</td>";
 $str .= "\n\t\t\t<td valign='top'><a href='" . $upload_url[$k] . "' target=_blank><img title='Connect to service' border=0 src = '../img/trafficlights/" . $img . "'></a></td>";
 $str .= "\n\t\t\t<td valign='top'>" . $comment[$k] . "<br><div style='font-size:12'>" . date("F j, Y, G:i:s", $upload_id[$k]) . "</div></td>";
 $str .= "\n\t\t\t<td valign='top'>";
 $str .= "<table bgcolor='black' border=1 cellspacing=1 cellpadding=0><tr><td height=20 width=20 align=center valign=middle bgcolor='";
 if ($image[$k] == -1) {
     $str .= "red";
 } elseif ($image[$k] == 0) {
     $str .= "yellow";
 } elseif ($image[$k] == 1) {
     $str .= "green";
 }
 if ($image[$k] != -1) {
     $str .= "'><a href='" . $mapurl[$k] . "'>o</a></td></tr></table></td>";
 } else {
     $str .= "'><a href='" . $mapurl[$k] . "'>x</a></td></tr></table></td>";
 $owner_ids = $admin->getOwnerByWms($myWMS);
 if ($owner_ids && count($owner_ids) > 0) {
     $owner_mail_addresses = array();
     $j = 0;
     for ($i = 0; $i < count($owner_ids); $i++) {
         $adr_tmp = $admin->getEmailByUserId($owner_ids[$i]);
         if (!in_array($adr_tmp, $owner_mail_addresses) && $adr_tmp) {
             $owner_mail_addresses[$j] = $adr_tmp;
             $j++;
         }
     }
     $replyto = $admin->getEmailByUserId(Mapbender::session()->get("mb_user_id"));
     $from = $replyto;
     $pathArray = explode("http/php/", $_SERVER["PATH_TRANSLATED"]);
     $path = $pathArray[0];
     $body = "WMS '" . $admin->getWmsTitleByWmsId($myWMS) . "' has been updated. \n\nServer name:  " . $_SERVER["SERVER_NAME"] . "\nInstallation Path: " . $path . "\n\nYou may want to check the changes as you are an owner of this WMS.";
     $error_msg = "";
     for ($i = 0; $i < count($owner_mail_addresses); $i++) {
         if (!$admin->sendEmail($replyto, $from, $owner_mail_addresses[$i], $owner_mail_addresses[$i], "[Mapbender] A user has updated one of your WMS", $body, $error)) {
             if ($error) {
                 $error_msg .= $error . " ";
             }
         }
     }
     if (!$error_msg) {
         echo "<script language='javascript'>";
         echo "alert('Other owners of this WMS have been informed about the changes!');";
         echo "</script>";
     } else {
         echo "<script language='javascript'>";
         echo "alert('When notifying the owners of this WMS about your changes, an error occured: ' + '" . $error_msg . "');";
 } else {
     $status_price = 0;
 }
 $auth = $admin->getAuthInfoOfWMS($ownwms[$i]);
 if ($auth['auth_type'] == '') {
     $status_auth = 0;
 } else {
     $status_auth = 1;
 }
 echo "<tr>";
 echo "<td>" . $ownwms[$i] . "</td>";
 echo "<td";
 if ($status_auth == 1) {
     echo " bgcolor=\"#FF0000\"";
 }
 echo ">" . $admin->getWmsTitleByWmsId($ownwms[$i]);
 echo "<td>";
 #for owsproxy
 echo "<input type='checkbox' id='wms_" . $ownwms[$i] . "_proxy' name='wms_" . $ownwms[$i] . "_proxy' onclick='if(this.checked){document.getElementById(\"wms_\"+" . $ownwms[$i] . "+\"_log\").disabled=false;document.getElementById(\"wms_\"+" . $ownwms[$i] . "+\"_price\").disabled=true;document.getElementById(\"status_\"+" . $ownwms[$i] . "+\"_proxy\").value=\"1\"}else{document.getElementById(\"wms_\"+" . $ownwms[$i] . "+\"_log\").checked=false;document.getElementById(\"wms_\"+" . $ownwms[$i] . "+\"_log\").disabled=true;document.getElementById(\"wms_\"+" . $ownwms[$i] . "+\"_price\").disabled=true;document.getElementById(\"wms_\"+" . $ownwms[$i] . "+\"_price\").value=\"0\";document.getElementById(\"status_\"+" . $ownwms[$i] . "+\"_proxy\").value=\"0\";document.getElementById(\"status_\"+" . $ownwms[$i] . "+\"_log\").value=\"0\"}'";
 #default
 if ($status_proxy == 1) {
     echo " checked";
 } else {
     echo " unchecked";
 }
 //if a proxy string is set
 if ($status_auth == 1) {
     echo " disabled";
 }
 echo ">";
 #initialize hidden field for status proxy:
    $upload_id[$cnt] = db_result($res, $cnt, "upload_id");
    $status[$cnt] = intval(db_result($res, $cnt, "status"));
    $comment[$cnt] = db_result($res, $cnt, "status_comment");
    $timestamp_begin = db_result($res, $cnt, "timestamp_begin");
    $timestamp_end = db_result($res, $cnt, "timestamp_end");
    $upload_url[$cnt] = db_result($res, $cnt, "upload_url");
    if ($status[$cnt] == '0' || $status[$cnt] == '1') {
        $response_time[$cnt] = strval($timestamp_end - $timestamp_begin) . " s";
    } else {
        $response_time[$cnt] = "n/a";
    }
    $cnt++;
}
$str = "<span style='font-size:30'>" . _mb("Monitoring results") . "</span><hr><br>\n";
//Monitoring Ergebnisse
$str .= "<b>" . $wms_id . "</b><br>" . $admin->getWmsTitleByWmsId($wms_id) . "<br><br><br>\n";
$str .= "<table cellpadding=10 cellspacing=0 border=0>";
$str .= "<tr bgcolor='#dddddd'><th align='left'>date</th><th align='left' colspan = 2>" . _mb("Status") . "</th><th align='center'>" . _mb("Response time") . "</th></tr>";
//Status Antwortzeit
for ($k = 0; $k < count($upload_id); $k++) {
    $img = "stop.png";
    if ($status[$k] == 0) {
        $img = "wait.png";
    } elseif ($status[$k] == 1) {
        $img = "go.png";
    }
    if (fmod($k, 2) == 1) {
        $str .= "\n\t\t<tr bgcolor='#e6e6e6'>";
    } else {
        $str .= "\n\t\t<tr bgcolor='#f0f0f0'>";
    }
    if (!in_array($row["md_topic_category_id"], $topic_id_layer)) {
        array_push($topic_id, $row["md_topic_category_id"]);
        array_push($topic_name, $row["md_topic_category_code_" . $language_suffix]);
    }
}
/*INSERT HTML*/
echo "<form name='form1' action='" . $self . "' method='post'>";
/*insert wms in selectbox*************************************************************************/
echo "<div class='text1'>WMS: </div>";
echo "<select style='background:#ffffff' class='select1' name='selected_wms' onChange='submit()' size='10'>";
for ($i = 0; $i < count($own_wms_id_array); $i++) {
    echo "<option value='" . $own_wms_id_array[$i] . "' ";
    if ($selected_wms && $selected_wms == $own_wms_id_array[$i]) {
        echo "selected";
    }
    echo ">" . $admin->getWmsTitleByWmsId($own_wms_id_array[$i]) . "</option>";
}
echo "</select>";
/*insert wms in selectbox*************************************************************************/
echo "<div class='text2'>Layer: </div>";
echo "<select style='background:#ffffff' class='select2' name='selected_layer' onChange='submit()' size='10'>";
for ($i = 0; $i < count($own_layer_id_array); $i++) {
    echo "<option value='" . $own_layer_id_array[$i] . "' ";
    if ($selected_layer && $selected_layer == $own_layer_id_array[$i]) {
        echo "selected";
    }
    echo ">" . $admin->getLayerTitleByLayerId($own_layer_id_array[$i]) . "</option>";
}
echo "</select>";
/*insert all groups in selectbox*******************************************************************/
echo "<div class='text3'>TOPICS:</div><br>";
     // push into problematic array
     if ($status == '-1' or $status == '-2') {
         $status_comment = "Monitoring process timed out.";
         $status = '-1';
         array_push($problemOWS, $wms_id_own[$k]);
         array_push($commentProblemOWS, $status_comment);
     }
     $v = array('0', intval($status), intval($image), $status_comment, (string) intval($timestamp_end), $map_url, (string) intval($timestamp_begin), $cap_diff, (string) $time, $wms_id_own[$k]);
     $t = array('s', 'i', 'i', 's', 's', 's', 's', 's', 's', 's');
     $res = db_prep_query($sql, $v, $t);
 }
 $body = "";
 echo "\nmonitoring info in db for user: "******"\n";
 //loop for single monitor requests that has problems
 for ($i = 0; $i < count($problemOWS); $i++) {
     $body .= $br . $admin->getWmsTitleByWmsId($problemOWS[$i]) . " (" . $problemOWS[$i] . "): " . $commentProblemOWS[$i] . $br;
 }
 unset($problemOWS);
 unset($commentProblemOWS);
 //end of loop for single monitor requests
 // Send an email to the user if body string exists
 if ($body) {
     $error_msg = "";
     if ($admin->getEmailByUserId($userid)) {
         $admin->sendEmail(MAILADMIN, MAILADMINNAME, $admin->getEmailByUserId($userid), $user, "Mapbender monitoring report " . date("F j, Y, G:i:s", $time), utf8_decode($body), &$error_msg);
     } else {
         $error_msg = "Email address of user '" . $admin->getUserNameByUserId($userid) . "' unknown!\n";
     }
     if ($error_msg) {
         echo "\n ERROR: " . $error_msg;
     }
     $img = "go.png";
 }
 if ($image[$k] == 1) {
     $img_map = "picture.png";
 }
 if ($updated[$k] == "0" && $status[$k] == 0) {
     $fill = "checked";
 } else {
     $fill = "disabled";
 }
 if (fmod($cnt, 2) == 1) {
     $str .= "\n\t\t<tr bgcolor='#e6e6e6'>";
 } else {
     $str .= "\n\t\t<tr bgcolor='#f0f0f0'>";
 }
 $str .= "\n\t\t\t<td valign='top'><a href='../php/mod_showMetadata.php?resource=layer&id=" . $layer_id[$k] . "&subscribe=1' onclick='var metadataWindow=window.open(this.href,'" . _mb("Metadata") . "','width=500,height=600,left=100,top=200,scrollbars=yes ,dependent=yes'); metadataWindow.focus();newWindow.href.location='test.php';  >" . _mb("Service ID") . ": " . $wms_id[$k] . "</a><br>" . $admin->getWmsTitleByWmsId($wms_id[$k]) . "</td>";
 $str .= "\n\t\t\t<td valign='top'><a href='" . $upload_url[$k] . "' target=_blank><img title='" . _mb("Request GetCapabilities") . "' border=0 src = '../img/trafficlights/" . $img . "'></a></td>";
 //Aufruf des Capabilities Dokument
 $str .= "\n\t\t\t<td valign='top'>" . $comment[$k] . "<br><div style='font-size:12'>" . date("F j, Y, G:i:s", $upload_id[$k]) . "</div></td>";
 $str .= "\n\t\t\t<td valign='top' align = 'left'>";
 if ($avg_response_time[$k] == NULL) {
     $str .= "n/a";
 } else {
     if ($avg_response_time[$k] == 0) {
         $str .= "< 1 s";
     } else {
         $str .= $avg_response_time[$k] . " s";
     }
 }
 $str .= "</td>";
 $str .= "\n\t\t\t<td valign='top'>";
 if ($status[$k] == 0) {
     $img = "wait.bmp";
 } elseif ($status[$k] == 1) {
     $img = "go.bmp";
 }
 #if ($updated[$k] == "0" && $status[$k] == 0) $fill = "checked"; else $fill = "disabled";
 if (fmod($cnt, 2) == 1) {
     $str .= "\n\t\t<tr bgcolor='#e6e6e6'>";
 } else {
     $str .= "\n\t\t<tr bgcolor='#f0f0f0'>";
 }
 #generieren der checkboxen für jeden wms namen: cb123, wert 123, der andere input fuer upl_id123 mit wert des upload_ids aus der monitor tabelle - unnoetig
 $str .= "\n\t\t\t<td><input name='cb" . $cnt . "' value='" . $wms_id[$k] . "' type=checkbox  />";
 #<input type=hidden name='upl_id".$cnt."' value='".$upload_id[$k]."'>
 $str .= "</td>";
 $str .= "\n\t\t\t<td valign='top'><a href='../php/mod_showMetadata.php?resource=layer&id=" . $layer_id[$k] . "' onclick='window.open(this.href,'Metadaten','width=500,height=600,left=100,top=200,scrollbars=yes ,dependent=yes'); return false' target='_blank' >Dienst ID: " . $wms_id[$k] . "</a><br>" . $admin->getWmsTitleByWmsId($wms_id[$k]) . "</td>";
 #$str .= "\n\t\t\t<td valign='top'><b>" . $wms_id[$k] . "</b><br>" . $admin->getWmsTitleByWmsId($wms_id[$k]) . "</td>";
 $str .= "\n\t\t\t<td valign='top'><a href='" . $upload_url[$k] . "' target=_blank><img title='Connect to service' border=0 src = '../img/trafficlights/" . $img . "'></a></td>";
 $str .= "\n\t\t\t<td valign='top'>" . $comment[$k] . "<br><div style='font-size:12'>" . date("F j, Y, G:i:s", $upload_id[$k]) . "</div></td>";
 $str .= "\n\t\t\t<td valign='top' align = 'left'>";
 if ($avg_response_time[$k] == NULL) {
     $str .= "n/a";
 } else {
     $str .= $avg_response_time[$k] . " s";
 }
 $str .= "</td>";
 $str .= "\n\t\t\t<td valign='top'><b>" . $percentage[$k] . " %</b>&nbsp;&nbsp;<span style='font-size:12'>(" . $total[$k] . " cycles)</span><br>";
 $str .= "<table bgcolor='black' border=1 cellspacing=1 cellpadding=0><tr>";
 $val = $percentage[$k];
 for ($i = 0; $i < 10; $i++) {
     if ($val >= 10) {