[fusion-commits] r1854 - in trunk: layers/Generic/php widgets
widgets/Redline
svn_fusion at osgeo.org
svn_fusion at osgeo.org
Tue May 19 14:05:08 EDT 2009
Author: aboudreault
Date: 2009-05-19 14:05:08 -0400 (Tue, 19 May 2009)
New Revision: 1854
Removed:
trunk/layers/Generic/php/upload.php
Modified:
trunk/widgets/Redline.js
trunk/widgets/Redline/Redline.php
Log:
Modified the Redline widget upload capability
Deleted: trunk/layers/Generic/php/upload.php
===================================================================
--- trunk/layers/Generic/php/upload.php 2009-05-17 20:14:38 UTC (rev 1853)
+++ trunk/layers/Generic/php/upload.php 2009-05-19 18:05:08 UTC (rev 1854)
@@ -1,50 +0,0 @@
-<?php
-/**
- * Upload
- *
- * $Id: upload.php 1421 2008-06-25 10:59:01Z aboudreault $
- *
- * Copyright (c) 2007, DM Solutions Group Inc.
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-/*****************************************************************************
- * Purpose: Allow a user to upload a file on the server.
- The max file size should be setted in the php5.ini.
- *****************************************************************************/
-
-// the page that this php script should redirect after the upload
-$page = $_POST['page'];
-
-if (!isset($page)) {
- die('page not set');
-}
-
-$target_path = "/home/aboudreault/opt/fgs/www/htdocs/uploads/";
-
-$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
-
-if(!move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
- echo "There was an error uploading the file.";
- exit;
-}
-
-header( "Location: $page" ) ;
-
-?>
\ No newline at end of file
Modified: trunk/widgets/Redline/Redline.php
===================================================================
--- trunk/widgets/Redline/Redline.php 2009-05-17 20:14:38 UTC (rev 1853)
+++ trunk/widgets/Redline/Redline.php 2009-05-19 18:05:08 UTC (rev 1854)
@@ -23,6 +23,38 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
+
+/*****************************************************************************
+ * Redline panel. It also allows a user to upload a file on the server.
+ * The max file size should be setted in the php5.ini.
+ *****************************************************************************/
+
+
+$fileUpload = false;
+
+$action = $_POST['action'];
+$file = $_GET['file'];
+
+if (isset($file)) { // it's a uploaded file request
+ returnFile($file);
+}
+else {
+ if (isset($action) && ($action == 'upload') && ($_FILES['uploadedfile']['error'] == UPLOAD_ERR_OK)) {
+ $fileUpload = true;
+
+ $target_path = tempnam(sys_get_temp_dir(), preg_replace("/\.[^\.]+$/", "", basename( $_FILES['uploadedfile']['name'])).'_');
+
+ if (file_exists($target_path)) {
+ unlink($target_path);
+ }
+ $target_path = $target_path.'.gml';
+ $uploadedFilename = basename($target_path);
+ if ((!move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))) {
+ $fileUpload = false;
+ }
+ }
+}
+
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
@@ -41,6 +73,11 @@
div = document.createElement("div");
div.innerHTML = "<div id=\"panelIsLoaded\"/>";
document.body.appendChild(div);
+ <? if ($fileUpload) { ?>
+ div = document.createElement("div");
+ div.innerHTML = "<div id=\"uploadedFileName\" value=\"<?= $uploadedFilename ?>\"/>";
+ document.body.appendChild(div);
+ <? } ?>
}
</script>
@@ -108,3 +145,22 @@
</body>
</html>
+
+
+<?php
+
+function returnFile($filename) {
+
+header("Content-type: text/xml");
+header("Content-Disposition: attachment; filename=$filename");
+
+$filename = sys_get_temp_dir().'/'.$filename;
+$handle = fopen($filename, "r");
+$contents = fread($handle, filesize($filename));
+fclose($handle);
+
+echo $contents;
+exit;
+}
+
+?>
Modified: trunk/widgets/Redline.js
===================================================================
--- trunk/widgets/Redline.js 2009-05-17 20:14:38 UTC (rev 1853)
+++ trunk/widgets/Redline.js 2009-05-19 18:05:08 UTC (rev 1854)
@@ -72,9 +72,6 @@
saveForm: null,
uploadForm: null,
- // The upload directory
- uploadDirectory: '/uploads/',
-
initializeWidget: function(widgetTag) {
var json = widgetTag.extension;
this.mapWidget = Fusion.getWidgetById('Map');
@@ -82,7 +79,6 @@
// register Redline specific events
this.registerEventID(Fusion.Event.REDLINE_FEATURE_ADDED);
- this.uploadDirectory = json.UploadDirectory ? json.UploadDirectory[0] : '/uploads/';
this.sTarget = json.Target ? json.Target[0] : "";
if (this.sTarget)
this.taskPane = new Fusion.Widget.Redline.DefaultTaskPane(this, widgetTag.location);
@@ -124,45 +120,45 @@
createDrawControls: function() {
this.drawControls = {
point: new OpenLayers.Control.DrawFeature(this.vectorLayers[0],
- OpenLayers.Handler.Point, {
- handlerOptions: {
- layerOptions: {
- styleMap: this.styleMap
- }
- }
- }),
+ OpenLayers.Handler.Point, {
+ handlerOptions: {
+ layerOptions: {
+ styleMap: this.styleMap
+ }
+ }
+ }),
line: new OpenLayers.Control.DrawFeature(this.vectorLayers[0],
- OpenLayers.Handler.Path, {
- handlerOptions: {
- freehandToggle: null,
- freehand: false,
- style: "default", // this forces default render intent
- layerOptions: {
- styleMap: this.styleMap
- }
- }
- }),
- rectangle: new OpenLayers.Control.DrawFeature(this.vectorLayers[0],
- OpenLayers.Handler.RegularPolygon, {
- handlerOptions: {
- sides: 4,
- irregular: true,
- style: "default", // this forces default render intent
- layerOptions: {
- styleMap: this.styleMap
- }
- }
- }),
+ OpenLayers.Handler.Path, {
+ handlerOptions: {
+ freehandToggle: null,
+ freehand: false,
+ style: "default", // this forces default render intent
+ layerOptions: {
+ styleMap: this.styleMap
+ }
+ }
+ }),
+ rectangle: new OpenLayers.Control.DrawFeature(this.vectorLayers[0],
+ OpenLayers.Handler.RegularPolygon, {
+ handlerOptions: {
+ sides: 4,
+ irregular: true,
+ style: "default", // this forces default render intent
+ layerOptions: {
+ styleMap: this.styleMap
+ }
+ }
+ }),
polygon: new OpenLayers.Control.DrawFeature(this.vectorLayers[0],
- OpenLayers.Handler.Polygon, {
- handlerOptions: {
- freehand: false,
- style: "default", // this forces default render intent
- layerOptions: {
- styleMap: this.styleMap
- }
- }
- })
+ OpenLayers.Handler.Polygon, {
+ handlerOptions: {
+ freehand: false,
+ style: "default", // this forces default render intent
+ layerOptions: {
+ styleMap: this.styleMap
+ }
+ }
+ })
};
for(var key in this.drawControls) {
@@ -208,24 +204,25 @@
/* Create a hidden form for the Upload action ,
this form will be placed the the TaskPane manager */
var sl = Fusion.getScriptLanguage();
- var scriptURL = Fusion.getFusionURL() + 'layers/Generic/' + sl + '/upload.' + sl;
+ var scriptURL = Fusion.getFusionURL() + 'widgets/Redline/Redline.php';
var file = document.createElement("input");
var submit = document.createElement("input");
- var page = document.createElement("input");
+ var action = document.createElement("input");
this.uploadForm = document.createElement("form");
submit.type="submit";
submit.name="submit_element";
submit.value="Upload";
- page.type = "hidden";
- page.name = "page";
+ action.type = "hidden";
+ action.name = "action";
+ action.value = "upload";
this.uploadForm.enctype = "multipart/form-data";
this.uploadForm.action = scriptURL;
this.uploadForm.method = "POST";
file.name="uploadedfile";
file.type="file";
this.uploadForm.appendChild(file);
- this.uploadForm.appendChild(page);
+ this.uploadForm.appendChild(action);
this.uploadForm.appendChild(document.createElement("br"));
this.uploadForm.appendChild(submit);
},
@@ -272,7 +269,7 @@
var fileContent = gmlParser.write(this.activeLayer.features);
this.saveForm.elements[0].value = "text/xml";
this.saveForm.elements[1].value = escape(fileContent);
- this.saveForm.elements[2].value = this.activeLayer.name + ".gml";
+ this.saveForm.elements[2].value = this.activeLayer.name + '.gml';
this.saveForm.submit();
},
@@ -287,7 +284,7 @@
this.vectorLayers[i] = new OpenLayers.Layer.Vector("Digitizing layer "+this.vectorLayers.length, {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
- url: this.uploadDirectory+"/"+fileName,
+ url: Fusion.getFusionURL() +"widgets/Redline/Redline.php?"+"file="+fileName,
format: new OpenLayers.Format.GML()
}),
styleMap: this.styleMap
@@ -322,10 +319,6 @@
// the panel CSS
panelCss: 'Redline/Redline.css',
- // determine if a file has been uploaded... and should be added to the redline widget
- fileUploaded: false,
- fileUploadedName: '',
-
initialize: function(widget,widgetLocation) {
this.widget = widget;
this.widget.registerForEvent(Fusion.Event.REDLINE_FEATURE_ADDED, OpenLayers.Function.bind(this.featureAdded, this));
@@ -346,15 +339,16 @@
}
outputWin.parent = window;
this.taskPaneWin = outputWin;
- this.timeoutID = setTimeout(OpenLayers.Function.bind(this.initPanel, this),300);
+ var initFunction = OpenLayers.Function.bind(this.initPanel, this);
+ this.intervalID = setInterval(initFunction,300);
},
// when the panel is loaded....
initPanel: function() {
- if (!this.taskPaneWin.document.getElementById("panelIsLoaded")) {
- this.timeoutID = setTimeout(OpenLayers.Function.bind(this.initPanel, this), 300);
- return;
- }
+ if (!this.taskPaneWin.document.getElementById("panelIsLoaded"))
+ return;
+ clearInterval(this.intervalID);
+ this.intervalID = null;
// select the default control
var radioName = this.widget.defaultControl.charAt(0).toUpperCase() + this.widget.defaultControl.substr(1);
@@ -366,11 +360,10 @@
this.widget.uploadForm.elements[2].style.display = "none";
this.taskPaneWin.document.getElementById("RedlineWidgetUploadTd").appendChild(this.widget.uploadForm);
this.taskPaneWin.document.getElementById("RedlineWidgetUploadTd").appendChild(uploadButton);
- if (this.fileUploaded) {
+ // do we have an uploaded file ?
+ if (this.taskPaneWin.document.getElementById("uploadedFileName")) {
this.widget.activateControl(this.widget.defaultControl,0); //hack to reset the right control/radio
- this.widget.newLayerFromFile(this.fileUploadedName);
- this.fileUploaded = false;
- this.fileUploadedName = '';
+ this.widget.newLayerFromFile(this.taskPaneWin.document.getElementById("uploadedFileName").getAttribute("value"));
}
this.bindEvents();
this.updateLayerList();
@@ -432,11 +425,7 @@
},
uploadFile: function() {
- var page = Fusion.getFusionURL() + this.panelUrl;
- this.widget.uploadForm.elements[1].value = page;
- this.fileUploadedName = this.widget.uploadForm.elements[0].value;
this.widget.uploadForm.submit();
- this.fileUploaded = true;
var initFunction = OpenLayers.Function.bind(this.initPanel, this);
this.intervalID = setInterval(initFunction,300);
},
More information about the fusion-commits
mailing list