1 |
<?php |
---|
2 |
define("LOAD_MAPSESSION", "1"); |
---|
3 |
|
---|
4 |
//set the language resource file |
---|
5 |
$szLanguageResource = str_replace("\\","/",dirname(__FILE__))."/DownloadSLD.dbf"; |
---|
6 |
|
---|
7 |
|
---|
8 |
include("../session.inc.php"); |
---|
9 |
include_once("../CWC2ButtonCache.php"); |
---|
10 |
|
---|
11 |
$oMap = $oMapSession->oMap; |
---|
12 |
$bHasClasses = false; |
---|
13 |
$bSaveResult = true; |
---|
14 |
|
---|
15 |
for ($i=0; $i<$oMap->numlayers; $i++) |
---|
16 |
{ |
---|
17 |
$oLayer = $oMap->getlayer( $i ); |
---|
18 |
if ($oLayer->numclasses) |
---|
19 |
{ |
---|
20 |
$bHasClasses = true; |
---|
21 |
break; |
---|
22 |
} |
---|
23 |
} |
---|
24 |
if (isset($http_form_vars['bDownload']) && $bHasClasses) |
---|
25 |
{ |
---|
26 |
$szFileName = tempnam($_SESSION['gszTmpImgPath'], "SLD").".xml"; |
---|
27 |
|
---|
28 |
// Set OWS_SCHEMAS_LOCATION before saving |
---|
29 |
// if (isset($_SESSION['gszSchemasLocation'])) |
---|
30 |
// { |
---|
31 |
// $oMapSession->oMap->setMetadata("ows_schemas_location", |
---|
32 |
// $_SESSION['gszSchemasLocation']); |
---|
33 |
// } |
---|
34 |
// |
---|
35 |
// Set SLD version before saving |
---|
36 |
// if (isset($http_form_vars['szVersion'])) |
---|
37 |
// { |
---|
38 |
// $oMapSession->oMap->setMetadata("wms_SLD_version", |
---|
39 |
// $http_form_vars['szVersion']); |
---|
40 |
// } |
---|
41 |
|
---|
42 |
/** |
---|
43 |
* generate sld and then write to the temp filename for |
---|
44 |
* processing by download.phtml. |
---|
45 |
*/ |
---|
46 |
$szSLDContents = null; |
---|
47 |
|
---|
48 |
if (isset($http_form_vars['nlayerindex'])) |
---|
49 |
{ |
---|
50 |
$poLayer = $oMapSession->oMap->getlayer($http_form_vars['nlayerindex']); |
---|
51 |
$szSLDContents = $poLayer->generateSLD(); |
---|
52 |
} |
---|
53 |
else |
---|
54 |
{ |
---|
55 |
$szSLDContents = $oMapSession->oMap->generateSLD(); |
---|
56 |
} |
---|
57 |
|
---|
58 |
if (strlen($szSLDContents)) |
---|
59 |
{ |
---|
60 |
$fp = @fopen( $szFileName, "w+" ); |
---|
61 |
if($fp === false) |
---|
62 |
{ |
---|
63 |
$bSaveResult = false; |
---|
64 |
} |
---|
65 |
else |
---|
66 |
{ |
---|
67 |
fwrite( $fp, $szSLDContents ); |
---|
68 |
fclose( $fp ); |
---|
69 |
} |
---|
70 |
} |
---|
71 |
else |
---|
72 |
{ |
---|
73 |
$bSaveResult = false; |
---|
74 |
} |
---|
75 |
$_SESSION['DOWNLOADFILE'] = $_SESSION['gszTmpWebPath']."/".basename($szFileName); |
---|
76 |
$_SESSION['DOWNLOADFILE_SAVEAS'] = 'sld.xml'; |
---|
77 |
if (stristr($_SESSION['DOWNLOADFILE'], 'http://') == false ) |
---|
78 |
$_SESSION['DOWNLOADFILE'] = 'http://'.$_SERVER['HTTP_HOST'].'/'.$_SESSION['DOWNLOADFILE']; |
---|
79 |
session_write_close(); |
---|
80 |
header("Location: ".$_SESSION['gszCoreWebPath']."widgets/download.phtml?".SID); |
---|
81 |
} |
---|
82 |
?> |
---|
83 |
<html> |
---|
84 |
<head> |
---|
85 |
<title><?php echo trim($oMLT->get("0", "Save SLD")); ?></title> |
---|
86 |
<link href="<?php echo $szCSSFile; ?>" rel="stylesheet" type="text/css"> |
---|
87 |
</head> |
---|
88 |
<script language="JavaScript" src="<?php echo $_SESSION['gszCoreWebPath']; ?>/widgets/js/cwc_dhtml.js" type="text/javascript"></script> |
---|
89 |
<script language="JavaScript" src="<?php echo $_SESSION['gszCoreWebPath']; ?>/widgets/js/cwc_button.js" type="text/javascript"></script> |
---|
90 |
<script language="JavaScript" type="text/javascript"> |
---|
91 |
function CloseWindow() |
---|
92 |
{ |
---|
93 |
window.close(); |
---|
94 |
} |
---|
95 |
</script> |
---|
96 |
<body class="page" onLoad="self.focus()"> |
---|
97 |
<form method=post> |
---|
98 |
<table width="400" border="0" cellspacing="10" cellpadding="1"> |
---|
99 |
<tr> |
---|
100 |
<td class="layoutTable"> |
---|
101 |
<table class="titleArea" width="100%" border="0" cellpadding="4" cellspacing="0"> |
---|
102 |
<tr> |
---|
103 |
<td><img src="title_save.gif" width="22" height="22" align="texttop"> <span class="title"><?php echo trim($oMLT->get("1", "Save SLD")); ?></span></td> |
---|
104 |
</tr> |
---|
105 |
</table> |
---|
106 |
<table class="contentArea" width="100%" border="0" cellpadding="4" cellspacing="0"> |
---|
107 |
<tr> |
---|
108 |
<td align="center"><p class="helpArea"><?php echo trim($oMLT->get("2", "Click the button below to begin saving the layer(s) to an SLD file.")); ?></p></td> |
---|
109 |
</tr> |
---|
110 |
</table> |
---|
111 |
<table class="contentArea" border="0" cellspacing="0" cellpadding="4" width="100%"> |
---|
112 |
<tr> |
---|
113 |
<td align="center"> |
---|
114 |
|
---|
115 |
<?php if (!$bHasClasses) { ?> |
---|
116 |
<span class="label"><?php echo trim($oMLT->get("6", "There are no layers or classes to export.")); ?></span> |
---|
117 |
<?php } else { ?> |
---|
118 |
<input type=submit name=bDownload value="<?php echo trim($oMLT->get("5", "Save SLD")); ?>"> |
---|
119 |
<?php } ?> |
---|
120 |
</td> |
---|
121 |
</tr> |
---|
122 |
</table> |
---|
123 |
</td> |
---|
124 |
</tr> |
---|
125 |
<tr> |
---|
126 |
<td align="right"><?php echo makeButton( 'CloseWindow', '', 'DownloadSLD', "icons/icon_close.png", trim($oCommonMLT->get("Close", "Close")), trim($oCommonMLT->get("CancelTip", "Close Dialog")), array( 'width' => 75) ); ?></td> |
---|
127 |
</tr> |
---|
128 |
</table> |
---|
129 |
<input type=hidden name=sid value="<?php echo $http_form_vars['sid']; ?>"> |
---|
130 |
</form> |
---|
131 |
</body> |
---|
132 |
<?php if (!$bSaveResult) { ?> |
---|
133 |
<?php echo "<SCRIPT language=\"JavaScript\" type=\"text/javascript\"> alert('The generated SLD file was empty or couldn't be created.');</SCRIPT>" ?> |
---|
134 |
<?php } ?> |
---|
135 |
|
---|
136 |
</html> |
---|