[Mapbender-commits] r1776 - in trunk/mapbender/http: javascripts php
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Mon Oct 29 12:01:09 EDT 2007
Author: christoph
Date: 2007-10-29 12:01:09 -0400 (Mon, 29 Oct 2007)
New Revision: 1776
Added:
trunk/mapbender/http/javascripts/mod_wfs_client.html
trunk/mapbender/http/php/mod_wfs_server.php
Log:
new wfs admin tool
Added: trunk/mapbender/http/javascripts/mod_wfs_client.html
===================================================================
--- trunk/mapbender/http/javascripts/mod_wfs_client.html (rev 0)
+++ trunk/mapbender/http/javascripts/mod_wfs_client.html 2007-10-29 16:01:09 UTC (rev 1776)
@@ -0,0 +1,416 @@
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html;CHARSET=iso-8859-1">
+
+<link rel="stylesheet" type="text/css" media="screen,projection" href="../css/admin.screen.css" title="screen" />
+
+<script src='../extensions/json.js'></script>
+<script type='text/javascript'>
+
+
+/*
+ * services['action']: instructs the servercomponent
+ * services['services']: infos about the services (wfs)
+ * services['services']['id']: a list of ids
+ * services['service']['title']: a corresponding list of titles
+ *
+ */
+var services = {};
+/*
+ * wfsConf['action']: instructs the servercomponent
+ * wfsConf['wfs']: the ID of the selected wfs
+ * wfsConf['wfsConf']: infos about the wfs configurations
+ * wfsConf['wfsConf']['id']: a list of ids
+ * wfsConf['wfsConf']['abstract']: a corresponding list of descriptions
+ */
+var wfsConf = {};
+
+/*
+ * guis['action']: instructs the servercomponent
+ * guis['id']: a list of gui-IDs where the current user is owner
+ * guis['selectedGui']: the selected Gui
+ */
+var guis = {};
+
+/*
+ * handleAssignment['action']: instructs the servercomponent
+ * handleAssignment['selectedConf']: a list of wfs-conf Ids
+ * handleAssignment['selectedGui']: the selected Gui
+ */
+var handleAssignment = {}
+
+/*
+ * vupdateWfs['action']: instructs the servercomponent
+ * vupdateWfs['wfs']: id of wfs to update
+ * vupdateWfs['url']: capabilities url
+ */
+var vupdateWfs = {};
+
+/*
+ * geturl['action']: instructs the servercomponent
+ * geturl['wfs']: id of wfs to get the url for
+ * geturl['column']: column of the url to get in table wfs
+ */
+var geturl = {}
+
+var owsproxy = {}
+
+
+
+
+function getWfsList(){
+ services['action'] = 'getServices';
+ getData(services);
+}
+function getGuis(){
+ guis['action'] = 'getGuis';
+ getData(guis);
+}
+function getWfsConfData(){
+ wfsConf['action'] = 'getWfsConfData';
+ wfsConf['wfs'] = getSelectedWfs();
+ getData(wfsConf);
+}
+function getSelectedWfs(){
+ var w = document.wfsForm.wfsList;
+ var ind = w.selectedIndex;
+ if(ind == -1){
+ return false;
+ }
+ if(ind == w.options.length-1)
+ return "gui_confs";
+ return w.options[ind].value;
+}
+function getGuiConfs(){
+ guis['action'] = 'getAssignedConfs';
+ var g = document.wfsForm.guiList;
+ var ind = g.selectedIndex;
+ if(ind == -1){
+ return false;
+ }
+ guis['selectedGui'] = g.options[ind].value;
+ guis['selectedWfs'] = wfsConf['wfs'];
+ getData(guis);
+}
+/**
+ * Sends an request to get the url to the capabilities doc of selected wfs
+ *
+ */
+
+function getUpdateUrl(column){
+ geturl['action'] = 'getUpdateUrl';
+ var w = document.wfsForm.wfsList;
+ var ind = w.selectedIndex;
+ if(ind == -1){
+ alert("please select an WFS");
+ return;
+ }
+ geturl['wfs'] = w.options[ind].value;
+ geturl['column'] = column;
+ getData(geturl);
+}
+
+function addConfsToGui(){
+ handleAssignment['action'] = 'add';
+ handleAssignment['confs'] = getSelectedConfs();
+ handleAssignment['gui'] = getSelectedGui();
+ getData(handleAssignment);
+}
+function removeConfsFromGui(){
+ handleAssignment['action'] = 'remove';
+ handleAssignment['confs'] = getSelectedAssignedConfs();
+ handleAssignment['gui'] = getSelectedGui();
+ getData(handleAssignment);
+}
+/**
+ * Sends an update request to update the capabilities of selected wfs
+ *
+ * @return success
+ * @type boolean
+ */
+
+function updateWfs(){
+ vupdateWfs['action'] = 'updateWfs';
+ var w = document.wfsForm.wfsList;
+ var ind = w.selectedIndex;
+ if(ind == -1){
+ alert("please select an WFS");
+ return false;
+ }
+ vupdateWfs['wfs'] = w.options[ind].value;
+ vupdateWfs['url'] = document.getElementById("updateUrl").value;
+ getData(vupdateWfs);
+ return true;
+}
+
+function deleteWfs(){
+ deleteWfs['action'] = 'deleteWfs';
+ deleteWfs['wfs'] = getSelectedWfs();
+ if(deleteWfs['wfs']&&deleteWfs['wfs']!="gui_confs"){
+ if(confirm("Do you really want to delete the Wfs with Wfs-id:"+deleteWfs['wfs']+"?")){
+ getData(deleteWfs);
+ }
+ return true;
+ }
+ return false;
+}
+
+function setIndicator(){
+ var str = "<img src='../img/indicator_wheel.gif'>";
+ document.getElementById("indicator").innerHTML = str;
+}
+function removeIndicator(){
+ document.getElementById("indicator").innerHTML = "";
+}
+function getOwsproxy(){
+ owsproxy['action'] = 'getOwsproxy';
+ owsproxy['wfs'] = getSelectedWfs();
+ getData(owsproxy);
+}
+function setOwsproxy(obj){
+ if(obj.checked == true){
+ owsproxy['action'] = 'setOwsproxy';
+ }
+ else{
+ owsproxy['action'] = 'removeOwsproxy';
+ }
+ owsproxy['wfs'] = getSelectedWfs();
+ if(owsproxy['wfs']){
+ getData(owsproxy);
+ }
+ else{
+ obj.checked = false;
+ }
+}
+/*
+ * Ajax-function to get data from the server
+ */
+function getData(obj){
+ setIndicator();
+ var obj2json = obj.toJSONString();
+ parent.mb_ajax_post("../php/mod_wfs_server.php",{"obj":obj2json}, function (json,status){
+ if(status == 'success'){
+ var dsJson = eval('(' + json + ')');
+ switch(obj['action']){
+ case "getServices":
+ appendServices(dsJson);
+ break;
+ case "getWfsConfData":
+ getOwsproxy();
+ appendWfsConfData(dsJson);
+ break;
+ case "getGuis":
+ appendGuis(dsJson);
+ break;
+ case "getAssignedConfs":
+ appendGuiConfs(dsJson);
+ break;
+ case "getUpdateUrl":
+ setUpdateUrl(dsJson)
+ break;
+ case "add":
+ getGuiConfs();
+ break;
+ case "remove":
+ getGuiConfs();
+ break;
+ case "updateWfs":
+ if(dsJson['success'])
+ alert("Update performed.");
+ else
+ alert("An error occured, see log for details.");
+ break;
+ case "deleteWfs":
+ if(dsJson['success']){
+ getWfsList();
+ getGuis();
+ alert("WFS deleted.");
+ }
+ break;
+ case "setOwsproxy":
+ displayOwsproxy(dsJson);
+ break;
+ case "removeOwsproxy":
+ displayOwsproxy(dsJson);
+ break;
+ case "getOwsproxy":
+ displayOwsproxy(dsJson);
+ break;
+ default:
+ alert("No action specified.....");
+ break;
+ }
+ }
+ else{
+ alert("An error occured!");
+ }
+ removeIndicator();
+ });
+}
+
+/**
+ * Sets the update url comming from db in the html form
+ *
+ */
+
+function setUpdateUrl(dsJson){
+ document.getElementById("updateUrl").value = dsJson['url'];
+}
+
+/*
+ *
+ */
+function displayOwsproxy(dsJson){
+ if(dsJson.string == "" || dsJson.string == false){
+ document.wfsForm.owsproxy.checked = false;
+ }
+ else{
+ document.wfsForm.owsproxy.checked = true;
+ }
+}
+
+function appendServices(dsJson){
+ services['services'] = dsJson.services;
+ var o = services['services'];
+ for(var i=0; i<o.id.length; i++){
+ appendOption(document.forms[0].wfsList, o.title[i], o.id[i], false);
+ }
+ appendOption(document.forms[0].wfsList, "WFS Configurations", "-1", false);
+}
+
+function appendWfsConfData(dsJson){
+ wfsConf['wfsConf'] = {};
+ wfsConf['wfsConf'] = dsJson.wfsConf;
+ var o = wfsConf['wfsConf'];
+ document.forms[0].wfsConfList.innerHTML = '';
+ for(var i=0; i<o.id.length; i++){
+ appendOption(document.forms[0].wfsConfList, o.abstract[i], o.id[i], false);
+ }
+}
+
+function appendGuis(dsJson){
+ guis['id'] = {};
+ guis['id'] = dsJson.id;
+ var o = guis['id'];
+ for(var i=0; i<o.length; i++){
+ appendOption(document.forms[0].guiList, o[i], o[i], false);
+ }
+}
+function appendGuiConfs(dsJson){
+ var list = document.forms[0].guiConfList;
+ list.innerHTML = '';
+ for(var i=0; i<dsJson.assignedConfs.length; i++){
+ var confAbstract = getConfAbstract(dsJson.assignedConfs[i]);
+ appendOption(list, confAbstract, dsJson.assignedConfs[i], false);
+ }
+}
+function appendOption(boxObject, optionText, optionValue, selected){
+ var newOption = new Option(optionText,optionValue,false,selected);
+ boxObject.options[boxObject.length] = newOption;
+}
+/*
+ * returns id and abstract from a wfs configuration
+ */
+function getConfAbstract(confId){
+ var c = wfsConf['wfsConf'];
+ for(var i=0; i < c['id'].length; i++){
+ if(c['id'][i] == confId){
+ return c['abstract'][i];
+ }
+ }
+}
+function getSelectedConfs(){
+ var list = document.forms[0].wfsConfList;
+ var confs = [];
+ for(var i=0; i<list.length; i++){
+ if(list.options[i].selected === true){
+ confs.push(list.options[i].value);
+ }
+ }
+ return confs;
+}
+function getSelectedAssignedConfs(){
+ var list = document.forms[0].guiConfList;
+ var confs = [];
+ for(var i=0; i<list.length; i++){
+ if(list.options[i].selected === true){
+ confs.push(list.options[i].value);
+ }
+ }
+ return confs;
+}
+function getSelectedGui(){
+ var ind = document.forms[0].guiList.selectedIndex;
+ return document.forms[0].guiList.options[ind].value;
+}
+</script>
+</head>
+<body onload='getWfsList();getGuis();'>
+
+<h1>Edit WFS</h1>
+<form name='wfsForm'>
+ <div id='indicator'>ahh</div>
+
+ <fieldset class="leftContainer">
+ <legend>WFS List</legend>
+ <p>
+ <select size='4' name='wfsList' class='wfsList' onchange='getWfsConfData();getGuiConfs();'></select>
+ </p>
+ </fieldset>
+
+ <fieldset class="rightContainer">
+ <legend>Options</legend>
+ <p>
+ <input type='checkbox' name='owsproxy' id='owsproxy' onclick='setOwsproxy(this)' />
+ <label for="owsproxy">OWSProxy</label>
+ <br />
+ <label for="updateUrl">
+ Link to new WFS Capabilities URL:
+ <br />
+ (<a href='javascript:getUpdateUrl("wfs_getcapabilities")'>wfs_getcapabilities</a>, <a href='javascript:getUpdateUrl("wfs_upload_url")'>wfs_upload_url</a>)
+ </label>
+ <input id='updateUrl' type='text' value='' name='updateUrl' class='updateUrl' />
+ <br />
+ <input type='button' value='Update WFS' name='update' id='updateButton' onclick='updateWfs()' />
+ <input type='button' value='Delete WFS' name='delete' id='deleteButton' onclick='deleteWfs()' />
+ </p>
+ </fieldset>
+
+ <hr />
+
+ <fieldset class="rightContainer">
+ <legend>GUI List</legend>
+ <p>
+ <select size='4' name='guiList' class='guiList' onchange='getGuiConfs()'></select>
+ </p>
+ </fieldset>
+
+ <hr />
+
+ <fieldset class="leftContainer">
+ <legend>WFS Configuration List</legend>
+ <p>
+ <select size='4' name='wfsConfList' class='wfsConfList' onchange='' multiple="multiple"></select>
+ </p>
+ </fieldset>
+
+ <fieldset class="centerContainer">
+ <legend>Action</legend>
+ <p>
+ <input type='button' value='>' name ='add' id ='add' class='add' onclick='addConfsToGui()'><br />
+ <input type='button' value='<' name ='remove' id ='remove' class='remove' onclick='removeConfsFromGui()'>
+ </p>
+ </fieldset>
+
+ <fieldset class="rightContainer">
+ <legend>GUI Configuration List</legend>
+ <p>
+ <select size='4' name='guiConfList' class='guiConfList' onchange='' multiple="multiple"></select>
+ </p>
+ </fieldset>
+
+ <hr />
+</form>
+
+</body>
+</html>
\ No newline at end of file
Added: trunk/mapbender/http/php/mod_wfs_server.php
===================================================================
--- trunk/mapbender/http/php/mod_wfs_server.php (rev 0)
+++ trunk/mapbender/http/php/mod_wfs_server.php 2007-10-29 16:01:09 UTC (rev 1776)
@@ -0,0 +1,302 @@
+<?php
+session_start();
+include_once(dirname(__FILE__)."/../../conf/mapbender.conf");
+require_once(dirname(__FILE__)."/../classes/class_administration.php");
+require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
+require_once(dirname(__FILE__)."/../classes/class_wfs.php");
+include_once("../extensions/JSON.php");
+
+//db connection
+$con = db_connect(DBSERVER,OWNER,PW);
+db_select_db(DB,$con);
+
+$json = new Services_JSON();
+$obj = $json->decode(stripslashes($_REQUEST['obj']));
+
+//workflow:
+switch($obj->action){
+ case 'getServices':
+ $obj->services = getServices($obj);
+ sendOutput($obj);
+ break;
+ case 'getWfsConfData':
+ $obj->wfsConf = getWfsConfData($obj->wfs);
+ sendOutput($obj);
+ break;
+ case 'getGuis':
+ $obj->id = getGuis($obj);
+ sendOutput($obj);
+ break;
+ case 'getAssignedConfs':
+ $obj->assignedConfs = getAssignedConfs($obj);
+ sendOutput($obj);
+ break;
+ case 'getUpdateUrl':
+ $obj->url = getUpdateUrl($obj);
+ sendOutput($obj);
+ break;
+ case 'add':
+ addConfsToGui($obj);
+ sendOutput($obj);
+ break;
+ case 'remove':
+ removeConfsFromGui($obj);
+ sendOutput($obj);
+ break;
+ case 'updateWfs':
+ updateWfs($obj);
+ sendOutput($obj);
+ break;
+ case 'deleteWfs':
+ deleteWfs($obj);
+ sendOutput($obj);
+ break;
+ case 'setOwsproxy':
+ $ows = array();
+ $ows['string'] = setOwsproxy($obj);
+ $ows['action'] = "owsproxy";
+ sendOutput($ows);
+ break;
+ case 'removeOwsproxy':
+ $ows = array();
+ $ows['string'] = removeOwsproxy($obj);
+ $ows['action'] = "owsproxy";
+ sendOutput($ows);
+ break;
+ case 'getOwsproxy':
+ $ows = array();
+ $ows['string'] = getOwsproxy($obj);
+ $ows['action'] = "owsproxy";
+ sendOutput($ows);
+ break;
+ default:
+ sendOutput("no action specified...");
+}
+
+
+/*
+ * Get all services (ids and titles) where the current user is owner
+ *
+ * @return mixed[] services the ids and titles of the services
+ */
+function getServices(){
+ global $con;
+ $services = array();
+ $services['id'] = array();
+ $services['title'] = array();
+ $adm = new administration();
+ $serviceList = $adm->getWfsByOwner($_SESSION['mb_user_id']);
+ if(count($serviceList) == 0){
+ return false;
+ }
+ $sql = "SELECT * FROM wfs WHERE wfs_id IN(".join(",",$serviceList).") ORDER BY wfs_title";
+ $res = db_query($sql);
+ while($row = db_fetch_array($res)){
+ array_push($services['id'], $row['wfs_id']);
+ array_push($services['title'], $row['wfs_title']);
+ }
+ return $services;
+}
+
+/*
+ * Get all configurations of the selcted wfs if the current user is owner
+ *
+ * @return mixed[]
+ */
+function getWfsConfData($wfsID){
+ global $con;
+ // re-check permission
+ $adm = new administration();
+ $serviceList = $adm->getWfsByOwner($_SESSION['mb_user_id']);
+ if(in_array($wfsID, $serviceList)){
+ $wfsConf = array();
+ $wfsConf['id'] = array();
+ $wfsConf['abstract'] = array();
+ $sql = "SELECT * FROM wfs_conf WHERE fkey_wfs_id = $1 ORDER BY wfs_conf_abstract";
+ $v = array($wfsID);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ $cnt = 0;
+ while($row = db_fetch_array($res)){
+ array_push($wfsConf['id'], $row['wfs_conf_id']);
+ array_push($wfsConf['abstract'], $row['wfs_conf_abstract']);
+ $cnt++;
+ }
+ if($cnt == 0){
+ return false;
+ }
+ else{
+ return $wfsConf;
+ }
+ }
+ else if($wfsID==="gui_confs"){
+ $wfsConf = array();
+ $wfsConf['id'] = array();
+ $wfsConf['abstract'] = array();
+ $wfsConf['id'] = $adm->getWfsConfByPermission($_SESSION['mb_user_id']);
+ $cnt = 0;
+ foreach($wfsConf['id'] as $wfscid){
+ $sql = "SELECT wfs_conf_abstract FROM wfs_conf WHERE wfs_conf_id = $1";
+ $v = array($wfscid);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ while($row = db_fetch_array($res)){
+ array_push($wfsConf['abstract'], $row['wfs_conf_abstract']);
+ }
+ $cnt++;
+ }
+ if($cnt == 0){
+ return false;
+ }
+ else{
+ return $wfsConf;
+ }
+ }
+}
+/*
+ * Get all GUIs where the current user is owner. This are the GUIs where the user could publish his
+ * wfs configurations
+ *
+ * @return mixed[]
+ */
+function getGuis(){
+ $adm = new administration();
+ $guiList = $adm->getGuisByOwner($_SESSION['mb_user_id'],1);
+ if(count($guiList) > 0){
+ return $guiList;
+ }
+ return false;
+}
+
+
+/*
+ * get all wfs_confs of the selected WFS which are assigned to the selected gui
+ * @param
+ * @return mixed[]
+ */
+function getAssignedConfs($obj){
+ global $con;
+ $assignedConfs = array();
+ $confs = getWfsConfData($obj->selectedWfs);
+ if($confs === false){
+ return false;
+ }
+ $sql = "SELECT * FROM gui_wfs_conf WHERE fkey_gui_id = $1 AND fkey_wfs_conf_id IN (".join(",",$confs['id']).")";
+ $v = array($obj->selectedGui);
+ $t = array('s');
+ $res = db_prep_query($sql,$v,$t);
+ if(!$res){
+ $e = new mb_exception("Error: SQL: " . $sql . " -> Gui: " .$obj->selectedGui);
+ }
+ while($row = db_fetch_array($res)){
+ array_push($assignedConfs, $row['fkey_wfs_conf_id']);
+ }
+ return $assignedConfs;
+}
+
+
+function addConfsToGui($obj){
+ global $con;
+ for($i=0; $i<count($obj->confs); $i++){
+ $sql = "SELECT * FROM gui_wfs_conf WHERE fkey_gui_id = $1 AND fkey_wfs_conf_id = $2";
+ $v = array($obj->gui,$obj->confs[$i]);
+ $t = array('s','i');
+ $res = db_prep_query($sql,$v,$t);
+ if(!$row = db_fetch_array($res)){
+ $sql1 = "INSERT INTO gui_wfs_conf (fkey_gui_id,fkey_wfs_conf_id) VALUES ($1,$2)";
+ $v1 = array($obj->gui, $obj->confs[$i]);
+ $t1 = array('s', 'i');
+ $res1 = db_prep_query($sql1,$v1,$t1);
+ }
+ }
+}
+
+function removeConfsFromGui($obj){
+ global $con;
+ for($i=0; $i<count($obj->confs); $i++){
+ $sql = "DELETE FROM gui_wfs_conf WHERE fkey_gui_id = $1 AND fkey_wfs_conf_id = $2";
+ $v = array($obj->gui, $obj->confs[$i]);
+ $t = array('s', 'i');
+ $res = db_prep_query($sql,$v,$t);
+ }
+}
+/*
+ * updates an WFS
+ *
+ * @param object the un-encoded object
+ * @return boolean success
+ */
+function updateWfs($obj){
+ $obj->success = false;
+ $mywfs = new wfs();
+ $mywfs->createObjFromDB($obj->wfs);
+ if(!$mywfs->updateObjFromXML($obj->url)){
+ return false;
+ }
+ if(!$mywfs->wfs2db("")){
+ return false;
+ }
+ $obj->success = true;
+ return true;
+}
+/*
+ * deletes an WFS
+ *
+ * @param object the un-encoded object
+ * @return boolean success
+ */
+function deleteWfs($obj){
+ //$obj->success = false;
+ $sql = "DELETE FROM wfs WHERE wfs_id = $1";
+ $v = array($obj->wfs);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ $obj->success = true;
+ return true;
+}
+
+/*
+ * gets the specified url column from db
+ *
+ * @param object the un-encoded object
+ * @return string requested url
+ */
+
+function getUpdateUrl($obj){
+ global $con;
+ $sql = "SELECT * FROM wfs WHERE wfs_id = $1;";
+ $v = array($obj->wfs);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ while($row = db_fetch_array($res)){
+ return $row[$obj->column];
+ }
+ return "";
+}
+
+function getOwsproxy($obj){
+ $n = new administration();
+ return $n->getWfsOwsproxyString($obj->wfs);
+}
+function setOwsproxy($obj){
+ $n = new administration();
+ return $n->setWfsOwsproxyString($obj->wfs,true);
+}
+function removeOwsproxy($obj){
+ $n = new administration();
+ return $n->setWfsOwsproxyString($obj->wfs,false);
+}
+/*
+ * encodes and delivers the data
+ *
+ * @param object the un-encoded object
+ */
+function sendOutput($out){
+ global $json;
+ $output = $json->encode($out);
+ header("Content-Type: text/x-json");
+ echo $output;
+}
+
+
+?>
\ No newline at end of file
More information about the Mapbender_commits
mailing list