ソースを参照

Merge branch 'master' of bn.git:plabudda/se

Piotr Labudda 8 年 前
コミット
c7e7300a1f

+ 2 - 0
SE/schema/WPS_Functions/folders_interface/build_folders_interface.xml

@@ -48,6 +48,8 @@
       <echo>#46 test if ok $p5build_SE.build_procesy5_config.folders.root_points.mount_point = ${p5build_SE.build_procesy5_config.folders.root_points.mount_point}
          $p5xmli.NamespaceObjectInstanceTable.local = ${p5xmli.NamespaceObjectInstanceTable.local}
          $p5xmli.TypeName.local = ${p5xmli.TypeName.local}
+         $p5fi.primaryKey.local = ${p5fi.primaryKey.local}
+         $p5fi.primaryKeyField.local = ${p5fi.primaryKeyField.local}
          $p5xmli.NamespaceDatabaseStorageDefinitionOptSuffix = ${p5xmli.NamespaceDatabaseStorageDefinitionOptSuffix}
          test eval p5build_SE.build_procesy5_config.folders.IN7_DZIENNIK_KORESP_COLUMN.mount_point = ${p5build_SE.build_procesy5_config.folders.IN7_DZIENNIK_KORESP_COLUMN.mount_point}
       </echo>

+ 18 - 0
SE/se-lib/Response.php

@@ -13,6 +13,11 @@ Lib::loadClass('DBG');
  */
 class Response {
 
+	public static function correctFilename($filename, $extension = null) {
+		if (strlen($extension) && (!preg_match("/\.{$extension}$/i", $filename))) $filename .= ".{$extension}";
+		return preg_replace('/[^[:alnum:].-]/', '_', $filename);
+	}
+
 	public static function sendJson($data) {
 		header("Content-type: application/json");
 		echo json_encode($data);
@@ -24,6 +29,14 @@ class Response {
 		echo $data;
 	}
 
+	public static function sendCsv($data, $filename = null) {
+		header("Content-Type: text/csv");
+		if (strlen($filename)) header('Content-Disposition: attachment; filename=' . self::correctFilename($filename, 'csv') . ';');
+		header("Content-Transfer-Encoding: binary");
+		header("Content-Length: ".strlen($data));
+		echo $data;
+	}
+
 
 	public static function sendJsonExit($data) {
 		self::sendJson($data);
@@ -35,6 +48,11 @@ class Response {
 		exit;
 	}
 
+	public static function sendCsvExit($data, $fileName = null) {
+		self::sendCsvExit($data, $fileName);
+		exit;
+	}
+
 	public static function sendTryCatchJson($callback, $args = array()) {// @param callback must return $response object to send as json or throw exception
 		$response = array();
 		try {

+ 39 - 0
SE/se-lib/Route/ViewTableAjax.php

@@ -615,6 +615,45 @@ class Route_ViewTableAjax extends RouteBase {
 		return $response;
 	}
 
+	public function getCsvTheGeomAjaxAction() {
+		try {
+			self::getCsvTheGeomAjax();
+		} catch (Exception $e) {
+			SE_Layout::gora();
+			SE_Layout::menu();
+			SE_Layout::alert('danger', $e->getMessage());
+?>
+<div style="text-align: center;">
+  <a href="<?=$_SERVER['HTTP_REFERER']?>" class="btn btn-primary" style="width: 80px;">Powrót</a>
+</div>
+<?php
+			SE_Layout::dol();
+		}
+	}
+
+	public function getCsvTheGeomAjax() {
+		Lib::loadClass('EpsgConversion');
+		$namespace = V::get('namespace', '', $_GET, 'word');
+		$acl = Core_AclHelper::getAclByNamespace($namespace);
+		$table = $acl->getRootTableName();
+		$id = V::get('id', 0, $_GET, 'int');
+
+		$query = "select st_astext(`the_geom`) as `the_geom` from `{$table}` where `ID` = {$id}";
+		try {
+			$result = DB::getPDO()->fetchValue($query);
+		} catch (Exception $e) {
+			throw new Exception('Błąd zapytania SQL');
+		}
+		if (!preg_match('/^[[:alpha:]]+\((.*)\)$/', $result, $matches)) throw new Exception('Błąd danych georeferencyjnych');
+		$points = explode(',', $matches[1]);
+		$csv = implode("\n", array_map(function ($point, $i) {
+			list($x, $y) = explode(" ", $point, 2);
+			$wgs84 = EpsgConversion::LonLatToPUWGWGS84($x, $y);
+			return $i++ . ',' . round($wgs84->y, 3) . ',' . round($wgs84->x, 3) . ',0,Pikieta';
+		}, $points, range(1, count($points))));
+		Response::sendCsv($csv, "{$table}.{$id}");
+	}
+
 	public function moreFunctionsCellAjaxAction() {
 		Response::sendTryCatchJson(array($this, 'moreFunctionsCell'), $args = $_GET);
 	}

+ 1 - 0
SE/se-lib/TableAjax.php

@@ -588,6 +588,7 @@ class TableAjax extends ViewAjax {
 			'FIRCE_FILTER_INIT' => $forceFilterInit,
 			'PAGE_SIZE' => $pageSize,
 			'PAGE_SIZES' => $pageSizes,
+			'URL_GET_CSV_THE_GEOM_AJAX' => "{$this->syncUrl}&_hash={$this->_htmlID}&_task=getCsvTheGeomAjax",
 			'URL_REMOVE_THE_GEOM_AJAX' => "{$this->syncUrl}&_hash={$this->_htmlID}&_task=removeTheGeomAjax",
 			'URL_MORE_FUNCTIONS_CELL_AJAX' => "{$this->syncUrl}&_hash={$this->_htmlID}&_task=moreFunctionsCellAjax",
 			'URL_EDIT_INLINE_SAVE' => "index-ajax.php?_zasobID={$this->_zasobID}&_cls={$className}&_hash={$this->_htmlID}&_task=EDIT_INLINE_SAVE",

+ 5 - 1
SE/se-lib/TableAjax.php.GeomField.js

@@ -16,9 +16,10 @@
 			linkClassNamePrefix: 'TableAjaxGeomField',
 			linkSelectClassName: 'select',
 			linkSelectAddClassNames: '', // 'glyphicon glyphicon-map-marker'
+			getCsvUrl: '',
+			linkGetCsvAddClassNames: '', // 'glyphicon glyphicon-download'
 			linkRemoveClassName: 'remove',
 			linkRemoveAddClassNames: '', // 'glyphicon glyphicon-remove'
-			removeUrl: '',
 			onSelect: null,
 			onRemove: null,
 			debug: false
@@ -52,6 +53,8 @@
 				}
 			});
 
+			var cellMapGetCsv = jQuery('<a href="'+priv.options.getCsvUrl+'&id='+priv.options.recordID+'"><i title="Pobierz punkty referencyjne w CSV" class="'+priv.options.linkGetCsvAddClassNames+'"></i></a>');
+
 			var node = $(state.id);
 			node.empty();
 			node.addClass(state.linkClassNamePrefix);
@@ -61,6 +64,7 @@
 			}
 
 			node.append(cellMapSelect);
+			if (state.fieldValue) node.append(cellMapGetCsv);
 			node.append(cellMapRemove);
 		};
 

+ 3 - 0
SE/se-lib/TableAjax.php.TableAjax.js

@@ -11,6 +11,7 @@ var TableAjax = function() {
 		namespace: '',
 		url: '', //webservice url
 		urlPost: false, //use POST instead of GET
+		getCsvTheGeomAjaxUrl: '',
 		removeTheGeomAjaxUrl: '',
 		moreFunctionsCellAjaxUrl: '',
 		editInlineSaveUrl: '',
@@ -515,6 +516,8 @@ var TableAjax = function() {
 							linkClassNamePrefix: 'cell-mapfld',
 							linkSelectClassName: 'select',
 							linkSelectAddClassNames: 'glyphicon glyphicon-map-marker',
+							getCsvUrl: priv.options.getCsvTheGeomAjaxUrl,
+							linkGetCsvAddClassNames: 'glyphicon glyphicon-download',
 							linkRemoveClassName: 'remove',
 							linkRemoveAddClassNames: 'glyphicon glyphicon-remove',
 							onSelect: function(recordID, geomShape) {

+ 1 - 0
SE/se-lib/TableAjax.php.init.js

@@ -2,6 +2,7 @@ jQuery(document).ready(function(){
 	jQuery('#' + TABLE_AJAX_NODE_ID).TableAjax({
 		namespace: NAMESPACE,
 		url: URL_LOAD_AJAX_BASE,
+		getCsvTheGeomAjaxUrl: URL_GET_CSV_THE_GEOM_AJAX,
 		removeTheGeomAjaxUrl: URL_REMOVE_THE_GEOM_AJAX,
 		moreFunctionsCellAjaxUrl: URL_MORE_FUNCTIONS_CELL_AJAX,
 		editInlineSaveUrl: URL_EDIT_INLINE_SAVE,