[Mapbender-commits] r8509 - in trunk/mapbender/http: classes img php
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Nov 21 23:23:03 PST 2012
Author: verenadiewald
Date: 2012-11-21 23:23:03 -0800 (Wed, 21 Nov 2012)
New Revision: 8509
Added:
trunk/mapbender/http/img/link_edit.png
trunk/mapbender/http/php/mb_getWmsData.php
Modified:
trunk/mapbender/http/classes/class_wms.php
trunk/mapbender/http/php/mod_updateWMS.php
Log:
new "compare layer names" function for module updateWMS
Modified: trunk/mapbender/http/classes/class_wms.php
===================================================================
--- trunk/mapbender/http/classes/class_wms.php 2012-11-20 15:09:00 UTC (rev 8508)
+++ trunk/mapbender/http/classes/class_wms.php 2012-11-22 07:23:03 UTC (rev 8509)
@@ -1019,6 +1019,20 @@
return true;
}
}
+
+ function getLayerInfo() {
+ $resultArray = array();
+ for($i=0; $i<count($this->objLayer); $i++){
+ $resultArray[] = array (
+ //"id" => $this->objLayer[$i]->layer_id,
+ "pos" => $this->objLayer[$i]->layer_pos,
+ //"parent" => $this->objLayer[$i]->layer_parent,
+ "name" => $this->objLayer[$i]->layer_name
+ //"title" => $this->objLayer[$i]->layer_title
+ );
+ }
+ return $resultArray;
+ }
/**
* private function
*/
@@ -2480,9 +2494,9 @@
}
}
- function updateObjInDB($myWMS,$updateMetadataOnly=false){ //TODO give return true or false to allow feedback to user!!!
+ function updateObjInDB($myWMS,$updateMetadataOnly=false,$changedLayers=null){ //TODO give return true or false to allow feedback to user!!!
-
+ $this->wms_id = $myWMS;
//get some things out from database if not already given thru metadata editor: wms_network_access, wms_max_imagesize, inspire_download (on layer level)
//they don't come from the capabilities!
if (!$updateMetadataOnly) {
@@ -2536,7 +2550,7 @@
$res = db_prep_query($sql,$v,$t);
if(!$res){
- db_rollback();
+ db_rollback();
}
if($this->overwrite == true){
@@ -2608,6 +2622,24 @@
# update gui_wms
$this->update_gui_wms($myWMS);
}
+
+
+ //NEW 2012-11: Check for changed layer names with options $changedLayersObj
+ for($i=0; $i<count($changedLayers); $i++){
+ if(trim($changedLayers[$i]["oldLayerName"]) != trim($changedLayers[$i]["newLayerName"])) {
+ $sql = "UPDATE layer SET layer_name = $1 WHERE fkey_wms_id = $2 AND layer_name = $3";
+ $v = array(trim($changedLayers[$i]["newLayerName"]), $myWMS, trim($changedLayers[$i]["oldLayerName"]));
+ $t = array('s','i','s');
+ $res = db_prep_query($sql,$v,$t);
+ new mb_notice("update oldLayerName to newLayerName :". $changedLayers[$i]["oldLayerName"]."----->".$changedLayers[$i]["newLayerName"]);
+ if(!$res){
+ db_rollback();
+ }
+ }
+ #new mb_notice("oldLayerName ==================". $changedLayers[$i]["oldLayerName"]);
+ #new mb_notice("newLayerName ==================". $changedLayers[$i]["newLayerName"]);
+ }
+
# update TABLE layer
$oldLayerNameArray = array();
$v = array($myWMS);
Added: trunk/mapbender/http/img/link_edit.png
===================================================================
(Binary files differ)
Property changes on: trunk/mapbender/http/img/link_edit.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/mapbender/http/php/mb_getWmsData.php
===================================================================
--- trunk/mapbender/http/php/mb_getWmsData.php (rev 0)
+++ trunk/mapbender/http/php/mb_getWmsData.php 2012-11-22 07:23:03 UTC (rev 8509)
@@ -0,0 +1,128 @@
+<?php
+require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+require_once(dirname(__FILE__)."/../classes/class_wms.php");
+require_once(dirname(__FILE__)."/../classes/class_administration.php");
+
+$command = $_REQUEST["command"];
+
+if ($command == "getWmsData") {
+ $wms = $_POST["wmsId"];
+ $url = $_POST["wmsUrl"];
+
+ //get existing DB wms information
+ $sql = "SELECT * from layer WHERE fkey_wms_id = $1 ORDER BY layer_id";
+ $v = array ($wms);
+ $t = array ('i');
+ $res = db_prep_query($sql, $v, $t);
+
+ $dbObj = array();
+
+ while ($row = db_fetch_array($res)) {
+ $dbObj[] = array (
+ //"id" => $row["layer_id"],
+ "pos" => $row["layer_pos"],
+ "parent" => $row["layer_parent"],
+ "name" => $row["layer_name"]
+ //"title" => $row["layer_title"]
+ );
+ }
+
+ //get xml wms information
+ $updateWms = new wms();
+ $xml = $updateWms->createObjFromXML($url);
+ if($xml == "") {
+ echo "WMS could not be loaded, no valid XML. Please check WMS GetCapabilities";
+ die();
+ }
+
+ $updateWms->optimizeWMS();
+ $xmlObj = $updateWms->getLayerInfo();
+
+ $resultObj = array(
+ "dbObj" => $dbObj,
+ "xmlObj" => $xmlObj
+ );
+
+ $layerJson = json_encode($resultObj);
+
+ header("Content-type:application/json; charset=utf-8");
+ echo $layerJson;
+}
+else if($command == "updateWMS") {
+ $myWMS = $_POST["wmsId"];
+ $url = $_POST["wmsUrl"];
+
+ $changedLayerArray = array();
+ for ($i=0; $i<count($_POST['dbOldNames']); $i++) {
+ $changedLayerArray[] = array(
+ "oldLayerName" => $_POST['dbOldNames'][$i],
+ "newLayerName" => $_POST['dbCurrentNames'][$i]
+ );
+ }
+
+ #$changedLayerObj = json_encode($changedLayerArray);
+
+ $mywms = new wms();
+ $mywms->createObjFromXML($url);
+ $mywms->optimizeWMS();
+ echo "<br />";
+ if (!MD_OVERWRITE) {
+ $mywms->overwrite=false;
+ }
+ //possibility to see update information in georss and/or twitter channel
+ if(empty($_POST['twitter_news'])) {
+ $mywms->twitterNews = false;
+ }
+ if(empty($_POST['rss_news'])) {
+ $mywms->setGeoRss = false;
+ }
+ $mywms->updateObjInDB($myWMS,false, $changedLayerArray);
+ $mywms->displayWMS();
+
+ // start (owners of the updated wms will be notified by email)
+ if ($use_php_mailing) {
+ $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 . "');";
+ echo "</script>";
+ }
+ }
+ }
+ // end (owners of the updated wms will be notified by email)
+}
+else {
+ echo "please enter a valid command.";
+}
+?>
\ No newline at end of file
Modified: trunk/mapbender/http/php/mod_updateWMS.php
===================================================================
--- trunk/mapbender/http/php/mod_updateWMS.php 2012-11-20 15:09:00 UTC (rev 8508)
+++ trunk/mapbender/http/php/mod_updateWMS.php 2012-11-22 07:23:03 UTC (rev 8509)
@@ -38,18 +38,237 @@
echo '<meta http-equiv="Content-Type" content="text/html; charset='.CHARSET.'">';
?>
<title>updateWMS</title>
+<style type="text/css">
+ <!--
+ body{
+ background-color: #ffffff;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size : 12px;
+ color: #808080
+ }
+ .list_guis{
+ font-family: Arial, Helvetica, sans-serif;
+ font-size : 12px;
+ color: #808080;
+ }
+ a:link{
+ font-family: Arial, Helvetica, sans-serif;
+ font-size : 12px;
+ text-decoration : none;
+ color: #808080;
+ }
+ a:visited {
+ font-family: Arial, Helvetica, sans-serif;
+ text-decoration : none;
+ color: #808080;
+ font-size : 12px;
+ }
+ a:active {
+ font-family: Arial, Helvetica, sans-serif;
+ text-decoration : none;
+ color: #808080;
+ font-size : 12px;
+ }
+ table {
+ font-family: Arial, Helvetica, sans-serif;
+ color: #000000;
+ font-size : 12px;
+ }
+ table.layerNames{
+ font-family: Arial, Helvetica, sans-serif;
+ font-size : 14px;
+ color: #000000;
+ }
+ #updateResult{
+ font-family: Arial, Helvetica, sans-serif;
+ color: #000000;
+ }
+ -->
+</style>
+<link rel="stylesheet" href="../extensions/jquery-ui-1.7.2.custom/css/smoothness/jquery-ui-1.7.2.custom.css" />
<?php
include '../include/dyn_css.php';
?>
+<script type='text/javascript' src='../extensions/jquery-ui-1.8.1.custom/js/jquery-1.4.2.min.js'></script>
+<script type='text/javascript' src='../extensions/jquery-ui-1.8.16.custom/js/jquery-ui-1.8.16.custom.min.js'></script>
<script type='text/javascript'>
+
+function updateWms() {
+ $("#updateResult").remove();
+ var dbOldNameArray = [];
+ var dbCurrentNameArray = [];
+ $(".dbOldName").each(function(index) {
+ dbOldNameArray.push($(this).val());
+ });
+ $(".dbCurrentName").each(function(index) {
+ dbCurrentNameArray.push($(this).val());
+ });
+ var updateParams = {
+ "command": "updateWMS",
+ "wmsId": $("#myWMS").val(),
+ "wmsUrl" : $("#myURL").val(),
+ "publishRss" : $("#rss_news").attr("checked"),
+ "publishTwitter" : $("#twitter_news").attr("checked"),
+ "dbOldNames": dbOldNameArray,
+ "dbCurrentNames": dbCurrentNameArray
+ };
+ $.post("../php/mb_getWmsData.php", updateParams, function (jscode, status) {
+ if (status == 'success') {
+ if(jscode == "") {
+ alert("Error updating WMS.");
+ }
+
+ //$("select[name='selWMS'] option:selected").removeAttr("selected");
+ $("select[name='selWMS']").attr('selectedIndex', '-1').find("option:selected").removeAttr("selected");
+ $("input[name='capURL']").val("");
+ $("input[name='myURL']").val("");
+ $("#compare_dialog").removeAttr("checked");
+ $("#metadatalink").attr("href", "");
+ $("#metadatatext").html("no WMS selected");
+ $("#form1").append("<div id='updateResult'>" + jscode + "</div>");
+ return true;
+ }
+ else {
+ alert("Error updating WMS.");
+ return false;
+ }
+ });
+}
+
function validate(){
var ind = document.form1.selWMS.selectedIndex;
if(ind < 0){
alert("No WMS selected!");
return;
}
+ else if($("#myURL").val() == ""){
+ alert("No link to WMS Capabilities URL given.");
+ return;
+ }
else{
- document.form1.submit();
+ if($("#compare_dialog").attr("checked")) {
+ if (typeof $compareDialog == 'object') {
+ $compareDialog.dialog("destroy");
+ }
+
+ var params = {
+ command:"getWmsData",
+ "wmsId": $("#myWMS").val(),
+ "wmsUrl" : $("#myURL").val()
+ };
+ $.post("../php/mb_getWmsData.php", params, function (json, status) {
+ if (status == 'success') {
+ if(json) {
+ if(typeof json == "object") {
+ var xmlWmsHtml = "<fieldset style='float:left;width:45%;'>";
+ xmlWmsHtml += "<legend>XML WMS</legend>";
+ xmlWmsHtml += "<table class='layerNames'>";
+ xmlWmsHtml += "<tr>";
+ //xmlWmsHtml += "<th>ID</th>";
+ xmlWmsHtml += "<th>Pos</th>";
+ xmlWmsHtml += "<th>Layer Name</th>";
+ //xmlWmsHtml += "<th>Title</th>";
+ xmlWmsHtml += "</tr>";
+
+ var selectboxOptions = "<option value=''>---</option>";
+ for (var i = 0; i < json.xmlObj.length; i++) {
+ xmlWmsHtml += "<tr>";
+ //xmlWmsHtml += "<td>" + json.xmlObj[i].id + "</td>";
+ xmlWmsHtml += "<td>" + json.xmlObj[i].pos + "</td>";
+ xmlWmsHtml += "<td>";
+ xmlWmsHtml += "<input type='text' readonly id='xmlCurrentName' value='"+ json.xmlObj[i].name +"'>";
+ xmlWmsHtml += "</td>";
+ //xmlWmsHtml += "<td>" + json.xmlObj[i].title + "</td>";
+ xmlWmsHtml += "</tr>";
+
+ selectboxOptions += '<option value=\"' + json.xmlObj[i].name + '\">' + json.xmlObj[i].name + '</option>';
+ }
+ xmlWmsHtml += "</table>";
+ xmlWmsHtml += "</fieldset>";
+
+ var dbWmsHtml = "<fieldset style='float:left;width:45%;'>";
+ dbWmsHtml += "<legend>DB WMS</legend>";
+ dbWmsHtml += "<table class='layerNames'>";
+ dbWmsHtml += "<tr>";
+ //dbWmsHtml += "<th>ID</th>";
+ dbWmsHtml += "<th>Pos</th>";
+ dbWmsHtml += "<th>Layer Name</th>";
+ //bWmsHtml += "<th>Title</th>";
+ dbWmsHtml += "</tr>";
+ for (var i = 0; i < json.dbObj.length; i++) {
+ dbWmsHtml += "<tr>";
+ //dbWmsHtml += "<td>" + json.dbObj[i].id + "</td>";
+ dbWmsHtml += "<td>" + json.dbObj[i].pos + "</td>";
+ dbWmsHtml += "<td>";
+ dbWmsHtml += "<input class='dbCurrentName' type='text' readonly id='dbCurrentName_"+i+"' value='" + json.dbObj[i].name + "'>";
+ dbWmsHtml += "<input class='dbOldName' type='hidden' id='dbOldName_"+i+"' value='" + json.dbObj[i].name + "'>";
+ dbWmsHtml += "<img title='select matching layer from XML' class='linkDialog' id='linkDialog_"+i+"' style='cursor:pointer;width:16px;height:16px;' src='../img/link_edit.png'/>";
+ dbWmsHtml += "</td>";
+ //dbWmsHtml += "<td>" + json.dbObj[i].title + "</td>";
+ dbWmsHtml += "</tr>";
+
+ }
+ dbWmsHtml += "</table>";
+ dbWmsHtml += "</fieldset>";
+
+ var dialogHtml = "<div id='compareDialog'>" + xmlWmsHtml + dbWmsHtml + "</div>";
+ $compareDialog = $(dialogHtml).dialog({
+ title : "Compare WMS XML layers with DB layers",
+ width : "600px",
+ buttons: {
+ "Close": function() {
+ $(this).dialog("destroy").remove();
+ },
+ "Update WMS": function() {
+ updateWms();
+
+ $(this).dialog("destroy").remove();
+ }
+ }
+ });
+
+ $(".linkDialog").click(function () {
+ var fieldId = $(this).attr("id");
+ $selectLayerDialog = $("<div><select id='xmlLayerSelect'>" + selectboxOptions + "</select></div>").dialog({
+ title : "Select layer",
+ buttons: {
+ "Close": function() {
+ $(this).dialog("destroy").remove();
+ },
+ "Select": function() {
+ if($("#xmlLayerSelect").val() != "") {
+ var cntArray = fieldId.split('_');
+ $("#dbCurrentName_"+cntArray[1]).val($("#xmlLayerSelect").val());
+ if($("#dbCurrentName_"+cntArray[1]).val() != $("#dbOldName_"+cntArray[1]).val()) {
+ $("#dbCurrentName_"+cntArray[1]).css("background-color","orange");
+ }
+ else {
+ $("#dbCurrentName_"+cntArray[1]).css("background-color","");
+ }
+ }
+ $(this).dialog("destroy").remove();
+ }
+ }
+ });
+ });
+ }
+ else {
+ alert(json);
+ }
+ }
+ else {
+ alert("Error getting layer information.");
+ }
+ }
+ else {
+ alert("Error getting layer information.");
+ }
+ });
+
+ }
+ else {
+ document.form1.submit();
+ }
}
}
function sel(){
@@ -66,7 +285,7 @@
</script>
</head>
<body>
-<form name='form1' action='<?php echo $self; ?>' method='POST'>
+<form name='form1' id='form1' action='<?php echo $self; ?>' method='POST'>
<?php
@@ -112,19 +331,20 @@
<?php
echo "Link to the last uploaded Online Resource URL:<br><input type='text' size='120' name='capURL'><br />";
- echo "<input type='hidden' name='myWMS' value=''><br>";
+ echo "<input type='hidden' name='myWMS' id='myWMS' value=''><br>";
echo "Add the following REQUEST to the Online Resource URL to obtain the Capabilities document:<br>";
echo "<i>(Triple click to select and copy)</i><br>";
echo "REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.1.1<br>";
echo "REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.1.0<br>";
echo "REQUEST=capabilities&WMTVER=1.0.0<br><br>";
- echo "Link to new WMS Capabilities URL:<br><input size='120' type='text' name='myURL'><br>";
+ echo "Link to new WMS Capabilities URL:<br><input size='120' type='text' name='myURL' id='myURL'><br>";
if (defined("TWITTER_NEWS") && TWITTER_NEWS == true) {
- echo"<input type='checkbox' name='twitter_news' checked='checked'>Publish via Twitter<br>";
+ echo"<input type='checkbox' name='twitter_news' id='twitter_news' checked='checked'>Publish via Twitter<br>";
}
if (defined("GEO_RSS_FILE") && GEO_RSS_FILE != "") {
- echo"<input type='checkbox' name='rss_news' checked='checked'>Publish via RSS<br>";
+ echo"<input type='checkbox' name='rss_news' id='rss_news' checked='checked'>Publish via RSS<br>";
}
+ echo"<input type='checkbox' name='compare_dialog' id='compare_dialog'><label for='compare_dialog'>Use compare dialog</label><br>";
echo "<input type='button' value='Preview Capabilities' onclick='window.open(this.form.myURL.value,\"\",\"\")'> ";
echo "<input type='button' value='Upload Capabilities' onclick='validate()'><br>";
@@ -132,7 +352,13 @@
if(isset($myURL) && $myURL != ''){
$mywms = new wms();
- $mywms->createObjFromXML($myURL);
+ $xml = $mywms->createObjFromXML($myURL);
+
+ if($xml == "") {
+ echo "<br>WMS could not be loaded, no valid XML. Please check WMS GetCapabilities";
+ die();
+ }
+
$mywms->optimizeWMS();
echo "<br />";
if (!MD_OVERWRITE) {
@@ -145,9 +371,12 @@
if(empty($_POST['rss_news'])) {
$mywms->setGeoRss = false;
}
- $mywms->updateObjInDB($myWMS);
+ $updateObj = $mywms->updateObjInDB($myWMS);
+
+ echo "<div id='updateResult'>";
$mywms->displayWMS();
-
+ echo "</div>";
+
// start (owners of the updated wms will be notified by email)
if ($use_php_mailing) {
$owner_ids = $admin->getOwnerByWms($myWMS);
More information about the Mapbender_commits
mailing list