[Mapbender-commits] r7693 - trunk/mapbender/http/php
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Thu Mar 10 15:11:11 EST 2011
Author: armin11
Date: 2011-03-10 12:11:11 -0800 (Thu, 10 Mar 2011)
New Revision: 7693
Modified:
trunk/mapbender/http/php/mod_layerISOMetadata.php
trunk/mapbender/http/php/mod_wmc2ol.php
Log:
Remove redundant getGuisByPermission functions from source. They should all be removed and exchanged with admin->getGuisByPermission which controls the user/group access for the mapbender authorization component.
Modified: trunk/mapbender/http/php/mod_layerISOMetadata.php
===================================================================
--- trunk/mapbender/http/php/mod_layerISOMetadata.php 2011-03-10 17:08:43 UTC (rev 7692)
+++ trunk/mapbender/http/php/mod_layerISOMetadata.php 2011-03-10 20:11:11 UTC (rev 7693)
@@ -21,10 +21,13 @@
require_once(dirname(__FILE__) . "/../../core/globalSettings.php");
require_once(dirname(__FILE__) . "/../classes/class_connector.php");
+require_once(dirname(__FILE__) . "/../classes/class_administration.php");
$con = db_connect(DBSERVER,OWNER,PW);
db_select_db(DB,$con);
+$admin = new administration();
+
//define the view or table to use as input for metadata generation
$wmsView = "wms_search_table";
$wmsView = '';
@@ -66,6 +69,7 @@
function fillISO19139($iso19139, $recordId) {
global $wmsView;
+ global $admin;
//read out relevant information from mapbender database:
if ($wmsView != '') {
$sql = "SELECT * ";
@@ -110,7 +114,7 @@
$res = db_prep_query($sql,$v,$t);
$userMetadata = db_fetch_array($res);
//check if resource is freely available to anonymous user - which are all users who search thru metadata catalogues:
- $hasPermission=getLayerPermission($mapbenderMetadata['wms_id'],$mapbenderMetadata['layer_id'],ANONYMOUS_USER);
+ $hasPermission=$admin->getLayerPermission($mapbenderMetadata['wms_id'],$mapbenderMetadata['layer_name'],ANONYMOUS_USER);
//Creating the "MD_Metadata" node
$MD_Metadata = $iso19139->createElementNS('http://www.isotc211.org/2005/gmd', 'gmd:MD_Metadata');
//$MD_Metadata=$iso19139->registerNamespace('srv','http://www.iso211.org/2005/srv');
@@ -896,88 +900,6 @@
die();
}
- function user_authorization($wms_id,$layer_name,$user_id){
- $n = new administration();
- $this->n = $n;
- $permission=$this->n->getLayerPermission($wms_id, $layer_name, $user_id);
- return $permission;
- }
-
-//functions necessary to decide if service url should be displayed
- function getLayerPermission($wms_id, $layer_id, $user_id){
- //$layer_id = $this->getLayerIdByLayerName($wms_id,$layer_name);
- $array_guis = getGuisByPermission($user_id,true);
- $v = array();
- $t = array();
- $sql = "SELECT * FROM gui_layer WHERE fkey_gui_id IN (";
- $c = 1;
- //generate guilist assigned to specific user
- for($i=0; $i<count($array_guis); $i++){
- if($i>0){ $sql .= ",";}
- $sql .= "$".$c;
- $c++;
- array_push($v, $array_guis[$i]);
- array_push($t, 's');
- }
- $sql .= ") AND fkey_layer_id = $".$c." AND gui_layer_status = 1"; //Status must be 1
- array_push($v,$layer_id);
- array_push($t,'i');
- $res = db_prep_query($sql,$v,$t);
- if($row = db_fetch_array($res)){
- return true;
- }
- else{
- return false;
- }
- }
- function getGuisByPermission($mb_user_id,$ignoreublic){
- $arrayGuis = array();
- $mb_user_groups = array();
- $sql_groups = "SELECT fkey_mb_group_id FROM mb_user_mb_group WHERE fkey_mb_user_id = $1 ";
- $v = array($mb_user_id);
- $t = array("i");
- $res_groups = db_prep_query($sql_groups,$v,$t);
- $cnt_groups = 0;
- while($row = db_fetch_array($res_groups)){
- $mb_user_groups[$cnt_groups] = $row["fkey_mb_group_id"];
- $cnt_groups++;
- }
- if($cnt_groups > 0){
- $v = array();
- $t = array();
- $sql_g = "SELECT gui.gui_id FROM gui JOIN gui_mb_group ";
- $sql_g .= " ON gui.gui_id = gui_mb_group.fkey_gui_id WHERE gui_mb_group.fkey_mb_group_id IN (";
- for($i=0; $i<count($mb_user_groups);$i++){
- if($i > 0){$sql_g .= ",";}
- $sql_g .= "$".strval($i+1);
- array_push($v,$mb_user_groups[$i]);
- array_push($t,"i");
- }
- $sql_g .= ") GROUP BY gui.gui_id";
- $res_g = db_prep_query($sql_g,$v,$t);
- while($row = db_fetch_array($res_g)){
- array_push($arrayGuis,$row["gui_id"]);
- }
- }
- $sql_guis = "SELECT gui.gui_id FROM gui JOIN gui_mb_user ON gui.gui_id = gui_mb_user.fkey_gui_id";
- $sql_guis .= " WHERE (gui_mb_user.fkey_mb_user_id = $1) ";
- if (!isset($ignore_public) OR $ignore_public== false){
- $sql_guis .= " AND gui.gui_public = 1 ";
- }
- $sql_guis .= " GROUP BY gui.gui_id";
- $v = array($mb_user_id);
- $t = array("i");
- $res_guis = db_prep_query($sql_guis,$v,$t);
- $guis = array();
- while($row = db_fetch_array($res_guis)){
- if(!in_array($row['gui_id'],$arrayGuis)){
- array_push($arrayGuis,$row["gui_id"]);
- }
- }
- return $arrayGuis;
- }
-
-
function getEpsgByLayerId ($layer_id) { // from merge_layer.php
$epsg_list = "";
$sql = "SELECT DISTINCT epsg FROM layer_epsg WHERE fkey_layer_id = $1";
Modified: trunk/mapbender/http/php/mod_wmc2ol.php
===================================================================
--- trunk/mapbender/http/php/mod_wmc2ol.php 2011-03-10 17:08:43 UTC (rev 7692)
+++ trunk/mapbender/http/php/mod_wmc2ol.php 2011-03-10 20:11:11 UTC (rev 7693)
@@ -16,13 +16,11 @@
#http://www.geoportal.rlp.de/mapbender/php/mod_wmc2ol.php?wmc_id=45_1291218568&GEORSS=1&LayerSwitcher=1
require_once(dirname(__FILE__)."/../../core/globalSettings.php");
-//require_once(dirname(__FILE__)."/../classes/class_wmc.php");
require_once(dirname(__FILE__)."/../classes/class_user.php");
-//require_once(dirname(__FILE__)."/../classes/class_json.php");
-//require_once(dirname(__FILE__)."/../classes/class_administration.php");
-//require_once(dirname(__FILE__)."/../classes/class_wmcToXml.php");
-//$userId = Mapbender::session()->get("mb_user_id");
+require_once(dirname(__FILE__)."/../classes/class_administration.php");
+
$user = new User();
+$admin = new administration();
$userId = $user->id;
//check for parameter wmc_id
if(!isset($_GET["wmc_id"])){
@@ -98,39 +96,8 @@
$testMatch = NULL;
}
-
-
-
-
-
-//the next functions should come from class administration, but they are not included as they are needed
-//TODO
-function getLayerPermission($wms_id, $layer_id, $user_id){
- //$layer_id = $this->getLayerIdByLayerName($wms_id,$layer_name);
- $array_guis = getGuisByPermission($user_id,true);
- $v = array();
- $t = array();
- $sql = "SELECT * FROM gui_layer WHERE fkey_gui_id IN (";
- $c = 1;
- //generate guilist assigned to specific user
- for($i=0; $i<count($array_guis); $i++){
- if($i>0){ $sql .= ",";}
- $sql .= "$".$c;
- $c++;
- array_push($v, $array_guis[$i]);
- array_push($t, 's');
- }
- $sql .= ") AND fkey_layer_id = $".$c." AND gui_layer_status = 1"; //status 1 must be
- array_push($v,$layer_id);
- array_push($t,'i');
- $res = db_prep_query($sql,$v,$t);
- if($row = db_fetch_array($res)){
- return true;
- }
- else{
- return false;
- }
- }
+//**************************************************************************
+//functions which may be integrated from class_administration
function getWmsGetMapUrl($wmsId){
$sql = "SELECT wms_getmap FROM wms WHERE wms_id =$1";
$v = array($wmsId);
@@ -142,58 +109,14 @@
return false;
}
}
-function getGuisByPermission($mb_user_id,$ignoreublic){
- $arrayGuis = array();
- $mb_user_groups = array();
- $sql_groups = "SELECT fkey_mb_group_id FROM mb_user_mb_group WHERE fkey_mb_user_id = $1 ";
- $v = array($mb_user_id);
- $t = array("i");
- $res_groups = db_prep_query($sql_groups,$v,$t);
- $cnt_groups = 0;
- while($row = db_fetch_array($res_groups)){
- $mb_user_groups[$cnt_groups] = $row["fkey_mb_group_id"];
- $cnt_groups++;
- }
- if($cnt_groups > 0){
- $v = array();
- $t = array();
- $sql_g = "SELECT gui.gui_id FROM gui JOIN gui_mb_group ";
- $sql_g .= " ON gui.gui_id = gui_mb_group.fkey_gui_id WHERE gui_mb_group.fkey_mb_group_id IN (";
- for($i=0; $i<count($mb_user_groups);$i++){
- if($i > 0){$sql_g .= ",";}
- $sql_g .= "$".strval($i+1);
- array_push($v,$mb_user_groups[$i]);
- array_push($t,"i");
- }
- $sql_g .= ") GROUP BY gui.gui_id";
- $res_g = db_prep_query($sql_g,$v,$t);
- while($row = db_fetch_array($res_g)){
- array_push($arrayGuis,$row["gui_id"]);
- }
- }
- $sql_guis = "SELECT gui.gui_id FROM gui JOIN gui_mb_user ON gui.gui_id = gui_mb_user.fkey_gui_id";
- $sql_guis .= " WHERE (gui_mb_user.fkey_mb_user_id = $1) ";
- if (!isset($ignore_public) OR $ignore_public== false){
- $sql_guis .= " AND gui.gui_public = 1 ";
- }
- $sql_guis .= " GROUP BY gui.gui_id";
- $v = array($mb_user_id);
- $t = array("i");
- $res_guis = db_prep_query($sql_guis,$v,$t);
- $guis = array();
- while($row = db_fetch_array($res_guis)){
- if(!in_array($row['gui_id'],$arrayGuis)){
- array_push($arrayGuis,$row["gui_id"]);
- }
- }
- return $arrayGuis;
-}
-//end of functions which m,ay be included from class_administration in next versions
-#**************************************************************************
+//end of functions which may be included from class_administration in next versions
+//**************************************************************************
//Function to create an OpenLayers Javascript from a mapbender wmc document
function createOlFromWMC_id($wmc_id, $pointRadius, $fillColor){
//$myWmc = new wmc();
+ global $user;
global $userId;
+ global $admin;
//Get WMC out of mb Database
$sql = "SELECT wmc, wmc_serial_id FROM mb_user_wmc WHERE wmc_serial_id = $1";
$res = db_prep_query($sql, array($wmc_id), array("s"));
@@ -406,9 +329,9 @@
$html.=" layer0 = new OpenLayers.Layer.WMS( \"".$xml->LayerList->Layer[$i]->Title."\",\n";
$extensions=$xml->LayerList->Layer[$i]->Extension->children('http://www.mapbender.org/context');
$layer_id=dom_import_simplexml($extensions->layer_id)->nodeValue;
+ $layer_name=$xml->LayerList->Layer[$i]->Name;
$wms_id=dom_import_simplexml($extensions->wms_id)->nodeValue;
- $has_permission=getLayerPermission($wms_id,$layer_id,$userId);//problem: guest user must have fix id
- //echo $layer_id."<br>";
+ $has_permission=$admin->getLayerPermission($wms_id, $layer_name, $userId);
if ($has_permission || $layer_id==''){
$getMapUrl = $xml->LayerList->Layer[$i]->Server->OnlineResource->attributes('http://www.w3.org/1999/xlink')->href;
if (getWmsGetMapUrl($wms_id) != false) {
@@ -462,8 +385,9 @@
#$layer_id=$extensions->layer_id;
$wms_id=$extensions->wms_id;
$layer_id=dom_import_simplexml($extensions->layer_id)->nodeValue;
+ $layer_name=$xml->LayerList->Layer[$i]->Name;
$wms_id=dom_import_simplexml($extensions->wms_id)->nodeValue;
- $has_permission=getLayerPermission($wms_id,$layer_id,$userId);//problem: guest user must have fix id TODO
+ $has_permission=$admin->getLayerPermission($wms_id, $layer_name, $userId);
if (($xml->LayerList->Layer[$i]->attributes()->hidden=='0' && $has_permission) ||
($layer_id=='' && $xml->LayerList->Layer[$i]->attributes()->hidden=='0')){
$html.=" layer".$i." = new OpenLayers.Layer.WMS( \"".$xml->LayerList->Layer[$i]->Title."\",\n";
More information about the Mapbender_commits
mailing list