[Mapbender-commits] r3466 - in branches/print_dev/http/print: . classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Jan 20 09:53:02 EST 2009


Author: mschulz
Date: 2009-01-20 09:53:02 -0500 (Tue, 20 Jan 2009)
New Revision: 3466

Added:
   branches/print_dev/http/print/printPDF_download.php
Modified:
   branches/print_dev/http/print/classes/mbPdf.php
   branches/print_dev/http/print/mod_printPDF_div.php
   branches/print_dev/http/print/testConfigTemplate.json
   branches/print_dev/http/print/testfactories.php
Log:
div gui module with one-click download

Modified: branches/print_dev/http/print/classes/mbPdf.php
===================================================================
--- branches/print_dev/http/print/classes/mbPdf.php	2009-01-20 12:16:44 UTC (rev 3465)
+++ branches/print_dev/http/print/classes/mbPdf.php	2009-01-20 14:53:02 UTC (rev 3466)
@@ -22,15 +22,31 @@
 
 	public function returnPDF() {
 		if ($this->isSaved) {
-		    header('Content-Type:application/pdf');
-		    header('Content-Disposition:attachment;filename="'.$this->outputFileName.'"');
-			$this->objPdf->Output($this->outputFileName,'D');
+		    header('Content-Type: application/octet-stream');
+		    header('Content-Disposition: attachment; filename="'.$this->outputFileName.'"');
+		    header('Pragma: public');
+		    ob_end_flush();
+			$this->objPdf->Output($this->outputFileName,'S');
 		}
 		else
 			die("PDF output not rendered yet.");
 	}	
+
+	public function returnAbsoluteUrl() {
+		$mbjson = new Mapbender_JSON();
+		if ($this->isSaved) {
+			if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on")
+				$prot = "https://";
+			else
+				$prot = "http://";
+			$absoluteUrlToPdf = $prot.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/printPDF_download.php?f=".$this->outputFileName."&".SID;
+			return $mbjson->encode(array("outputFileName"=>$absoluteUrlToPdf));
+		}
+		else
+		    return $mbjson->encode(array("error"=>"Possibly no map urls delivered."));
+	}	
 	
-	public function returnURL() {
+	public function returnUrl() {
 		$mbjson = new Mapbender_JSON();
 		if ($this->isSaved) {
 			return $mbjson->encode(array("outputFileName"=>TMPDIR."/".$this->outputFileName));

Modified: branches/print_dev/http/print/mod_printPDF_div.php
===================================================================
--- branches/print_dev/http/print/mod_printPDF_div.php	2009-01-20 12:16:44 UTC (rev 3465)
+++ branches/print_dev/http/print/mod_printPDF_div.php	2009-01-20 14:53:02 UTC (rev 3466)
@@ -24,7 +24,6 @@
 echo "var myTarget = '".$e_target[0]."';";
 echo "var myId = '".$e_id."';";
 ?>
-var exists = false;
 
 eventInit.register(function () {
 	mod_printPDF_init();
@@ -41,16 +40,35 @@
 
 function hookForm() {
 	var options = { 
-   		url:        '../print/testfactories.php', 
-   		beforeSubmit: validate,
-   		success:    showResult
+   		url:			'../print/testfactories.php', 
+   		type:			'post',
+   		dataType:		'json',
+   		beforeSubmit: 	validate,
+   		success:    	showResult
 	};
 	$("#"+myId+"_form").ajaxForm(options);	
 }
 
+/**
+ * Change status of the working elements. These should begin with "$myId_working" 
+ *
+ * @param {String} newStatus either "hide or "show"
+ */
+function showHideWorking(newStatus) {
+	if (newStatus=="hide")
+    	$("[id^='"+myId+"_working']").hide();
+    else
+    	$("[id^='"+myId+"_working']").show();	
+}
+
+/**
+ * Validates and updates form data values.
+ * Adds the elements before the submit button.
+ *
+ * @see jquery.forms#beforeSubmitHandler
+ */
 function validate(formData, jqForm, options) {
-	$('#printPDF_working_bg').show();
-	$('#printPDF_working').show();
+	showHideWorking("show");
 	var ind = getMapObjIndexByName(myTarget);
 	var f = jqForm[0];
 	f.map_url.value = '';
@@ -61,7 +79,6 @@
 				if(f.map_url.value != ""){
 					f.map_url.value += '___';
 				}      
-				//alert(f.map_url.value);
 				f.map_url.value += mb_mapObj[ind].wms[i].mapURL;
 			}
 		}
@@ -77,7 +94,6 @@
 	var ind_overview = getMapObjIndexByName('overview');
 	
 	if(mb_mapObj[ind_overview].mapURL != false ){
-		//f.overview_url.value = mb_mapObj[ind_overview].mapURL;
 		for(var j=0; j < formData.length; j++){
 			if (formData[j].name == "overview_url") {
 				formData[j].value = mb_mapObj[ind_overview].mapURL;
@@ -89,28 +105,30 @@
 	if (f.map_url.value!="") {
 		return true;
 	} else {
-		$('#printPDF_working_bg').hide();
-		$('#printPDF_working').hide();
+	    showHideWorking("hide");
 		return false;
 	}
 		
 }
 
-function showResult(res) {
-	$('#printPDF_working_bg').hide();
-	$('#printPDF_working').hide();
-	/*
-	if (res.outputFileName)
-		window.location = res.outputFileName;
-	else
-		$('#printPDF_result').html(text);
-	*/
+function showResult(res, text) {
+	if (text == 'success') {
+		window.location = stripslashes(res.outputFileName);
+		showHideWorking("hide");	
+	}
+	else {
+		/* something went wrong */
+		$("#"+myId+"_result").html(text);
+	}
 }
 
+/**
+ * Generates form elements as specified in the config controls object.
+ * Adds the elements before the submit button.
+ * 
+ * @param {Object} json the config object in json
+ */
 function buildForm(json) {
-	/* first let's build some defaults then the stuff from config */
-	
-	/* this creates form elements from the json config */
 	var str = "";
 	for (var item in json.controls) {
 		var element = json.controls[item];
@@ -125,7 +143,7 @@
 				str += '<textarea id="'+element_id+'" name="'+element_id+'" size="'+element.size+'"></textarea><br>\n';
 				break;				
 			case "select":
-				str += '<select id="'+element_id+'" name="'+element_id+'" size="1" width="'+element.size+'">\n';
+				str += '<select id="'+element_id+'" name="'+element_id+'" size="1">\n';
 				for (var option_index in element.options) {
 					option = element.options[option_index];
 					str += '<option value="'+option.value+'">'+option.label+'</option>\n';
@@ -135,5 +153,9 @@
 		}
 		str += '</div>\n';
 	}
-	$("#formsubmit").before(str);
+	if (str) $("#"+myId+"_formsubmit").before(str);
+}
+
+function stripslashes( str ) {
+    return (str+'').replace(/\0/g, '0').replace(/\\([\\'"])/g, '$1');
 }
\ No newline at end of file

Added: branches/print_dev/http/print/printPDF_download.php
===================================================================
--- branches/print_dev/http/print/printPDF_download.php	                        (rev 0)
+++ branches/print_dev/http/print/printPDF_download.php	2009-01-20 14:53:02 UTC (rev 3466)
@@ -0,0 +1,17 @@
+<?php
+require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
+
+if (isset($_REQUEST["f"]) && $_REQUEST["f"]!="" && file_exists(TMPDIR."/".$_REQUEST["f"])) {
+	$filename = TMPDIR."/".$_REQUEST["f"];
+    header('Content-Type: application/octet-stream');
+    header('Content-Disposition: attachment; filename="'.basename($filename).'"');
+    header('Pragma: public');
+    ob_clean();
+    flush();
+    readfile($filename);
+    exit;
+}
+else {
+	echo "not found";
+}
+?>
\ No newline at end of file

Modified: branches/print_dev/http/print/testConfigTemplate.json
===================================================================
--- branches/print_dev/http/print/testConfigTemplate.json	2009-01-20 12:16:44 UTC (rev 3465)
+++ branches/print_dev/http/print/testConfigTemplate.json	2009-01-20 14:53:02 UTC (rev 3466)
@@ -8,23 +8,25 @@
     		"id" : "title",
     		"label" : "Titel",
     		"type" : "text",
-    		"size" : 20
+    		"size" : 20,
+    		"pageElementsLink" : "title:value"
     	},
     	{
     		"id" : "dpi",
     		"label" : "DPI",
     		"type" : "select",
     		"size" : 20,
+    		"pageElementsLink" : "map:res_dpi",
     		"options" : [
     			{
-    			"value" : "val1",
-    			"label" : "label1"
+    			"value" : "56",
+    			"label" : "niedrig (56)"
     			},{
-    			"value" : "val2",
-    			"label" : "label2"
+    			"value" : "72",
+    			"label" : "normal (72)"
     			},{
-    			"value" : "val3",
-    			"label" : "label3"
+    			"value" : "144",
+    			"label" : "hoch (dpi)"
     			}
     		]
     	},
@@ -32,7 +34,8 @@
     		"id" : "comment",
     		"label" : "Kommentar",
     		"type" : "textarea",
-    		"size" : 5
+    		"size" : 5,
+    		"pageElementsLink" : "map:res_dpi"
     	}    	    		
     ],
     "pages" : [

Modified: branches/print_dev/http/print/testfactories.php
===================================================================
--- branches/print_dev/http/print/testfactories.php	2009-01-20 12:16:44 UTC (rev 3465)
+++ branches/print_dev/http/print/testfactories.php	2009-01-20 14:53:02 UTC (rev 3466)
@@ -7,6 +7,6 @@
 
 $pdf->render();
 $pdf->save();
-$pdf->returnPDF();
-//print $pdf->returnURL();
+
+print $pdf->returnAbsoluteUrl();
 ?>
\ No newline at end of file



More information about the Mapbender_commits mailing list