Просмотр исходного кода

Map: get additional layers config from Zasoby (closes #129)

Piotr Labudda 10 лет назад
Родитель
Сommit
55d05118db
2 измененных файлов с 102 добавлено и 54 удалено
  1. 12 26
      SE/se-lib/TableAjax.php
  2. 90 28
      SE/se-lib/TableAjaxMap.php

+ 12 - 26
SE/se-lib/TableAjax.php

@@ -1,6 +1,12 @@
 <?php
 
 Lib::loadClass('ViewAjax');
+Lib::loadClass('TableAjaxMap');
+Lib::loadClass('Typespecial');
+Lib::loadClass('SE_Layout');
+Lib::loadClass('FoldersConfig');
+Lib::loadClass('FileUploader');
+Lib::loadClass('UserProfile');
 
 class TableAjax extends ViewAjax {
 
@@ -248,7 +254,6 @@ class TableAjax extends ViewAjax {
 
 		$tblAjaxMap = null;
 		if ($hasGeomFlds) {
-			Lib::loadClass('TableAjaxMap');
 			$tblAjaxMap = new TableAjaxMap($this->_acl, 512, 400);
 		}
 
@@ -1900,7 +1905,7 @@ class TableAjax extends ViewAjax {
 				//debug: true,
 				wpsUrl: 'http://biuro.biall-net.pl/wps',
 				wfsUrl: 'http://biuro.biall-net.pl/wps',
-				showAddLayerWidget: <?php echo ($this->_tbl == 'BUILDINGS')? 'true' : 'false'; ?>,
+				showAddLayerWidget: <?php echo ($this->hasAdditionalLayers())? 'true' : 'false'; ?>,
 				zoomStrategyActivate: 14,
 				layerName: '<?php echo $this->getLabelHtml(); ?>',
 				addBtn: {
@@ -2945,6 +2950,11 @@ function hidePopover() {
 		return $out;
 	}
 
+	public function hasAdditionalLayers() {
+		$layers = TableAjaxMap::getAdditionalLayers($this->_zasobID);
+		return !empty($layers);
+	}
+
 	public function ajaxTask($task) {
 		switch ($task) {
 			case 'EDIT': {
@@ -3128,7 +3138,6 @@ function hidePopover() {
 		$vCol['label'] = (!empty($vCol['label']))? $vCol['label'] : $vCol['name'];
 
 		$tsValues = array();
-		Lib::loadClass('Typespecial');
 		$typeSpecial = Typespecial::getInstance($fieldID, $vCol['name']);
 		if ($typeSpecial) {
 			if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Typespecial('.$fieldID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecial);echo'</pre>';}
@@ -3139,7 +3148,6 @@ function hidePopover() {
 			}
 		}
 
-		Lib::loadClass('SE_Layout');
 		?>
 		<label for="<?php echo "f{$fieldID}"; ?>" class="AjaxTableEdit-label">
 			<strong title="<?php echo "[{$fieldID}] {$fieldName}"; ?>"><?php echo "{$vCol['label']}"; ?></strong>
@@ -3245,7 +3253,6 @@ function hidePopover() {
 		$tsValues = array();
 		if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">fieldsList (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($fieldsList);echo'</pre>';}
 		if (!empty($fieldsList)) {
-			Lib::loadClass('Typespecial');
 			foreach ($fieldsList as $vColID => $vCol) {
 				$typeSpecial = Typespecial::getInstance($vColID, $vCol['name']);
 				if ($typeSpecial) {
@@ -3264,7 +3271,6 @@ function hidePopover() {
 
 		$rowFunctionsOut = $this->_showRowFunctions($record->ID, array('edit', 'cp'), true);
 
-		Lib::loadClass('SE_Layout');
 		?>
 		<div class="container AjaxFrmHorizontalEdit" style="max-width:940px">
 		<form class="form-horizontal" action="" method="post" id="EDIT_FRM_<?php echo $this->_htmlID; ?>">
@@ -3521,7 +3527,6 @@ jQuery(document).ready(function(){
 			$fieldsList[$kID]['label'] = (!empty($vCol['label']))? $vCol['label'] : $vCol['name'];
 		}
 
-		Lib::loadClass('SE_Layout');
 		?>
 		<div class="container AjaxFrmHorizontalEdit">
 		<form class="form-horizontal" action="" method="post" id="CREATE_FRM_<?php echo $this->_htmlID; ?>">
@@ -3872,7 +3877,6 @@ jQuery(document).ready(function(){
 
 		$tblName = $this->_acl->getName();
 		$confTblName = "{$tblName}_COLUMN";
-		Lib::loadClass('FoldersConfig');
 		$folderConfAll = FoldersConfig::getRawData();
 		if (!FoldersConfig::hasConfig($confTblName)) {
 			header('HTTP/1.0 404 Not Found');
@@ -3882,7 +3886,6 @@ jQuery(document).ready(function(){
 
 		$folderConf = FoldersConfig::getAll($confTblName);
 
-		Lib::loadClass('FileUploader');
 		$uploader = new FileUploader($confTblName, $record);
 		$errMsg = '';
 		if (!$uploader->setConfig($folderConf, $errMsg)) {
@@ -3947,7 +3950,6 @@ jQuery(document).ready(function(){
 
 		$tblName = $this->_acl->getName();
 		$confTblName = "{$tblName}_COLUMN";
-		Lib::loadClass('FoldersConfig');
 		$folderConfAll = FoldersConfig::getRawData();
 		if (!FoldersConfig::hasConfig($confTblName)) {
 			header('HTTP/1.0 404 Not Found');
@@ -3957,7 +3959,6 @@ jQuery(document).ready(function(){
 
 		$folderConf = FoldersConfig::getAll($confTblName);
 
-		Lib::loadClass('FileUploader');
 		$uploader = new FileUploader($confTblName, $record);
 		if (!$uploader->setConfig($folderConf)) {
 			header('HTTP/1.0 404 Not Found');
@@ -3996,7 +3997,6 @@ jQuery(document).ready(function(){
 
 		$tblName = $this->_acl->getName();
 		$confTblName = "{$tblName}_COLUMN";
-		Lib::loadClass('FoldersConfig');
 		$folderConfAll = FoldersConfig::getRawData();
 		if (!FoldersConfig::hasConfig($confTblName)) {
 			header('HTTP/1.0 404 Not Found');
@@ -4006,7 +4006,6 @@ jQuery(document).ready(function(){
 
 		$folderConf = FoldersConfig::getAll($confTblName);
 
-		Lib::loadClass('FileUploader');
 		$uploader = new FileUploader($confTblName, $record);
 		if (!$uploader->setConfig($folderConf)) {
 			header('HTTP/1.0 404 Not Found');
@@ -4109,7 +4108,6 @@ jQuery(document).ready(function(){
 		//}
 
 		$confTblName = "{$tblName}_COLUMN";
-		Lib::loadClass('FoldersConfig');
 		$folderConfAll = FoldersConfig::getRawData();
 		if (!FoldersConfig::hasConfig($confTblName)) {
 			throw new Exception("Brak danych konfiguracyjnych ({$tblName})", 404);
@@ -4117,7 +4115,6 @@ jQuery(document).ready(function(){
 
 		$folderConf = FoldersConfig::getAll($confTblName);
 
-		Lib::loadClass('FileUploader');
 		$uploader = new FileUploader($confTblName, $record);
 		if (!$uploader->setConfig($folderConf)) {
 			throw new Exception("Błąd danych konfiguracyjnych ({$tblName})", 404);
@@ -4181,7 +4178,6 @@ jQuery(document).ready(function(){
 
 		$tblName = $this->_acl->getName();
 		$confTblName = "{$tblName}_COLUMN";
-		Lib::loadClass('FoldersConfig');
 		$folderConfAll = FoldersConfig::getRawData();
 		if (!FoldersConfig::hasConfig($confTblName)) {
 			header('HTTP/1.0 404 Not Found');
@@ -4191,7 +4187,6 @@ jQuery(document).ready(function(){
 
 		$folderConf = FoldersConfig::getAll($confTblName);
 
-		Lib::loadClass('FileUploader');
 		$uploader = new FileUploader($confTblName, $record);
 		if (!$uploader->setConfig($folderConf)) {
 			header('HTTP/1.0 404 Not Found');
@@ -4242,7 +4237,6 @@ jQuery(document).ready(function(){
 
 		$fields = $this->_acl->getVisibleFieldList();
 		if (!empty($fields)) {
-			Lib::loadClass('Typespecial');
 			foreach ($fields as $vColID => $vCol) {
 				$typeSpecial = Typespecial::getInstance($vColID);
 				if ($typeSpecial) {
@@ -4264,7 +4258,6 @@ jQuery(document).ready(function(){
 
 		$fields = $this->_acl->getVisibleFieldList();
 		if (!empty($fields)) {
-			Lib::loadClass('Typespecial');
 			foreach ($fields as $vColID => $vCol) {
 				$typeSpecial = Typespecial::getInstance($vColID);
 				if ($typeSpecial) {
@@ -4307,7 +4300,6 @@ jQuery(document).ready(function(){
 
 		$tblName = $this->_acl->getName();
 		$confTblName = "{$tblName}_COLUMN";
-		Lib::loadClass('FoldersConfig');
 		$folderConfAll = FoldersConfig::getRawData();
 		if (!FoldersConfig::hasConfig($confTblName)) {
 			header('HTTP/1.0 404 Not Found');
@@ -4318,7 +4310,6 @@ jQuery(document).ready(function(){
 		$folderConf = FoldersConfig::getAll($confTblName);
 		//echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">$folderConf (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($folderConf);echo'</pre>';
 
-		Lib::loadClass('FileUploader');
 		$uploader = new FileUploader($confTblName, $record);
 		$errMsg = '';
 		if (!$uploader->setConfig($folderConf, $errMsg)) {
@@ -4854,7 +4845,6 @@ jQuery(document).ready(function(){
 		}
 
 		$jsonData = array();
-		Lib::loadClass('Typespecial');
 		$typeSpecial = Typespecial::getInstance($fldID, $fldName);
 		if ($typeSpecial) {
 			$query = V::get('q', '', $_REQUEST);
@@ -4907,7 +4897,6 @@ jQuery(document).ready(function(){
 			exit;
 		}
 
-		Lib::loadClass('Typespecial');
 		$typeSpecial = Typespecial::getInstance($fldID, $fldName);
 		if ($typeSpecial) {
 			$jsonData->data = $typeSpecial->getReturnData($this->_zasobID, $id, $fldName, '');
@@ -4959,8 +4948,6 @@ jQuery(document).ready(function(){
 			if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">vCols (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($vCols);echo'</pre>';}
 		}
 
-		Lib::loadClass('Typespecial');
-
 		$total = $this->_acl->getTotal($params);
 		if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">get_total (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($total);echo'</pre>';}
 		$items = $this->_acl->getItems($params);
@@ -5108,7 +5095,6 @@ jQuery(document).ready(function(){
 			return $response;
 		}
 
-		Lib::loadClass('UserProfile');
 		UserProfile::load();
 
 		// clean up old, wrong values

+ 90 - 28
SE/se-lib/TableAjaxMap.php

@@ -60,6 +60,8 @@ class TableAjaxMap {
 	}
 
 	public function printJS() {
+		$layers = TableAjaxMap::getAdditionalLayers($this->_zasobID);
+		$testFirstLayer = (count($layers))? $layers[0] : array();
 		?>
 <script src="stuff/open-layers/OpenLayers.js"></script>
 <script>
@@ -146,6 +148,7 @@ var myOpenLayers_Control_ManageLayers = OpenLayers.Class(OpenLayers.Control, {
 	layers: [],
 
 	draw: function() {
+		<?php if (!empty($layers)) : ?>
 		OpenLayers.Control.prototype.draw.apply(this, arguments);
 		if (!this.msgNode) {
 			this.msgNode = document.createElement("span");
@@ -154,19 +157,20 @@ var myOpenLayers_Control_ManageLayers = OpenLayers.Class(OpenLayers.Control, {
 		}
 		if (!this.testBtn) {
 			this.testBtn = document.createElement("span");
-			this.testBtn.title = "Dodaj warstwę - test babidol";
+			this.testBtn.title = "Dodaj warstwę";
 			this.testBtn.className = this.displayClass + "Btn";
 			this.testBtn.className += ' glyphicon glyphicon-plus';
 			var that = this;
 			jQuery(this.testBtn).on('click', function(e) {
 				e.stopPropagation();
 				e.preventDefault();
-				that.testAddLayerBabidol();
+				that.testAddAdditionalLayer();// TODO: show window with additional layers to choose
 				return false;
 			});
 			this.div.appendChild(this.testBtn);
 		}
 		this.updateView();
+		<?php endif; ?>
 		return this.div;
 	},
 
@@ -174,13 +178,13 @@ var myOpenLayers_Control_ManageLayers = OpenLayers.Class(OpenLayers.Control, {
 		this.mapWidget = mapWidget;
 	},
 
-	testAddLayerBabidol: function() {
-		if (this.layers.length > 0) {
+	testAddAdditionalLayer: function() {
+		if (this.layers.length > 0) {// TODO: already loaded
 			return false;
 		}
-		var layerName = 'Dodatkowy podkład z pliku dxf';
+		var layerName = '<?php echo V::get('DESC_PL', $testFirstLayer->ID, $testFirstLayer); ?>';
 		var wfsUrl = 'http://biuro.biall-net.pl/wps';
-		wfsUrl += '/21176/BUILDINGS_PODKLAD_DXF_SHP';// TODO: user choice by perms/item links
+		wfsUrl += '/<?php echo $testFirstLayer->TABLE_ID; ?>/<?php echo $testFirstLayer->TABLE_DESC; ?>';
 		var _styleMap = new OpenLayers.StyleMap({
 			'default': new OpenLayers.Style(null, {
 				rules: [
@@ -196,7 +200,7 @@ var myOpenLayers_Control_ManageLayers = OpenLayers.Class(OpenLayers.Control, {
 				]
 			})
 		});
-		var testLayerBabidol = new OpenLayers.Layer.Vector(layerName, {
+		var testAdditionalLayer = new OpenLayers.Layer.Vector(layerName, {
 			strategies: [new OpenLayers.Strategy.BBOX()],//, new OpenLayers.Strategy.Cluster({distance:20, threshold:16})
 			projection: new OpenLayers.Projection("EPSG:4326"),
 			protocol: new OpenLayers.Protocol.WFS({
@@ -210,13 +214,13 @@ var myOpenLayers_Control_ManageLayers = OpenLayers.Class(OpenLayers.Control, {
 			}),
 			styleMap: _styleMap
 		});
-		this.layers.push(testLayerBabidol);
+		this.layers.push(testAdditionalLayer);
 		this.map.addLayers(this.layers);
 		this.updateView();
 	},
 
 	updateView: function() {
-		this.msgNode.innerHTML = 'Warstwy ' + this.layers.length + ' ';
+		this.msgNode.innerHTML = 'Dodatkowe warstwy ' + this.layers.length + ' ';
 	},
 
 	CLASS_NAME: "OpenLayers.Control.ManageLayers"
@@ -1206,14 +1210,22 @@ var myOpenLayers_Control_ManageLayers = OpenLayers.Class(OpenLayers.Control, {
 	}
 
 	public function ajaxTask($task) {
-		switch ($task) {
-			case 'PROXY': {
-				$this->sendAjaxProxy($_REQUEST);
-				break;
+		try {
+			switch ($task) {
+				case 'PROXY': {
+					$this->sendAjaxProxy($_REQUEST);
+					break;
+				}
 			}
-			default:
-				//$this->sendAjaxData($_REQUEST);
 		}
+		catch (HttpException $e) {
+			Http::sendHeaderByCode($e->getCode());
+			echo $e->getMessage();
+		}
+		catch (Exception $e) {
+			echo $e->getMessage();
+		}
+		exit;
 	}
 
 	public function sendAjaxProxy($args) {
@@ -1229,24 +1241,33 @@ var myOpenLayers_Control_ManageLayers = OpenLayers.Class(OpenLayers.Control, {
 		$urlQueryTmp = explode('&', $urlQueryTmp);
 		foreach ($urlQueryTmp as $vQuery) {
 			$parts = explode('=', $vQuery, 2);
-			$urlQuery[$parts[0]] = $parts[1];
+			$urlQuery[$parts[0]] = (count($parts) > 1)? $parts[1] : '';
 		}
 		$urlPath = explode('/', trim($urlPath, "/ \n\t\r\0\x0B"));
 		if (count($urlPath) > 2) {// /wps/21176/BUILDINGS_PODKLAD_DXF_SHP
-			if ($urlPath[1] == '21176' && $urlPath[2] == 'BUILDINGS_PODKLAD_DXF_SHP') {
-				$tableId = $urlPath[1];
-				$userAcl = User::getAcl();
-				$userAcl->fetchGroups();
-				if (!$userAcl->hasTableAcl($tableId)) {
-					die('403 Forbidden');
+			$tableId = $urlPath[1];
+			$layers = TableAjaxMap::getAdditionalLayers($this->_zasobID);
+			$hasLayer = false;
+			foreach ($layers as $layer) {
+				if ($layer->TABLE_ID == $tableId) {
+					$hasLayer = true;
+					break;
 				}
-				$tblAcl = $userAcl->getTableAcl($tableId);
-				if (!$tblAcl) {
-					die('404 Not Found');
-				}
-				$tblAcl->init();
-				$wpsServer = new TableAjaxMapWpsServer($tblAcl);
 			}
+			if (!$hasLayer) {
+				throw new HttpException("Layer not found", 404);
+			}
+			$userAcl = User::getAcl();
+			$userAcl->fetchGroups();
+			if (!$userAcl->hasTableAcl($tableId)) {
+				throw new HttpException("Forbidden", 403);
+			}
+			$tblAcl = $userAcl->getTableAcl($tableId);
+			if (!$tblAcl) {
+				throw new HttpException("Forbidden", 403);
+			}
+			$tblAcl->init();
+			$wpsServer = new TableAjaxMapWpsServer($tblAcl);
 		}
 
 		if (!$wpsServer) {
@@ -1265,6 +1286,47 @@ var myOpenLayers_Control_ManageLayers = OpenLayers.Class(OpenLayers.Control, {
 		exit;
 	}
 
+	/**
+	 * usage: TableAjaxMap::getAdditionalLayers($idTable);
+	 */
+	public static function getAdditionalLayers($idTable) {
+		static $_cache;
+		if (!is_array($_cache)) $_cache = array();
+
+		if (!array_key_exists($idTable, $_cache)) {
+			$layers = array();
+			$db = DB::getDB();
+			$sql = "select layer.`ID`
+					, layer.`DESC`
+					, layer.`DESC_PL`
+					, layer.`OPIS`
+					, layer.`ALIAS_ID`
+					, tbl.`ID` as TABLE_ID
+					, tbl.`DESC` as TABLE_DESC
+					, tbl.`DESC_PL` as TABLE_DESC_PL
+				from `CRM_LISTA_ZASOBOW` as layers
+					join `CRM_LISTA_ZASOBOW` as layer on(
+						layer.`PARENT_ID`=layers.`ID`
+						and layer.`A_STATUS` in('WAITING', 'NORMAL')
+						and layer.`ALIAS_ID`>0
+						and layer.`DESC`='MAP_ADDITIONAL_LAYER'
+					)
+					join `CRM_LISTA_ZASOBOW` as tbl on(tbl.`ID`=layer.`ALIAS_ID` and tbl.`A_STATUS` in('WAITING', 'NORMAL'))
+				where layers.`PARENT_ID`='{$idTable}'
+					and layers.`A_STATUS` in('WAITING', 'NORMAL')
+					and layers.`DESC`='MAP_ADDITIONAL_LAYERS'
+				order by layer.`SORT_PRIO`
+			";
+			//echo '<pre>L.' . __LINE__ . ' $sql:'."\n";print_r($sql);echo '</pre>';
+			$res = $db->query($sql);
+			while ($r = $db->fetch($res)) {
+				$layers[] = $r;
+			}
+			$_cache[$idTable] = $layers;
+		}
+		return $_cache[$idTable];
+	}
+
 }