1 |
<?php |
---|
2 |
//set the language resource file |
---|
3 |
$szLanguageResource = str_replace("\\","/",dirname(__FILE__))."/UploadSLD.dbf"; |
---|
4 |
|
---|
5 |
//if (isset($http_form_vars['bSendFile']) || is_uploaded_file($HTTP_POST_FILES['oFile']['tmp_name'])) |
---|
6 |
//{ |
---|
7 |
define("LOAD_MAPSESSION", 1); |
---|
8 |
//} |
---|
9 |
|
---|
10 |
include("../session.inc.php"); |
---|
11 |
include_once("../CWC2ButtonCache.php"); |
---|
12 |
|
---|
13 |
$bFirst = true; |
---|
14 |
$bError = false; |
---|
15 |
$szLastTitle = ""; |
---|
16 |
$aSLDCollection = array(); |
---|
17 |
|
---|
18 |
// Check SLD collection if any |
---|
19 |
//if (isset($_SESSION['SLDCollection']) && |
---|
20 |
// $_SESSION['SLDCollection'] != "") |
---|
21 |
//{ |
---|
22 |
// $xml_parser = xml_parser_create(); |
---|
23 |
// xml_set_element_handler($xml_parser, "startElement", "endElement"); |
---|
24 |
// xml_set_character_data_handler($xml_parser, "characterData"); |
---|
25 |
// if (!($fp = fopen($_SESSION['SLDCollection'], "r"))) |
---|
26 |
// { |
---|
27 |
// die("could not open XML input"); |
---|
28 |
// } |
---|
29 |
// |
---|
30 |
// while ($data = fread($fp, 4096)) |
---|
31 |
// { |
---|
32 |
// if (!xml_parse($xml_parser, $data, feof($fp))) |
---|
33 |
// { |
---|
34 |
// die(sprintf("XML error: %s at line %d", |
---|
35 |
// xml_error_string(xml_get_error_code($xml_parser)), |
---|
36 |
// xml_get_current_line_number($xml_parser))); |
---|
37 |
// } |
---|
38 |
// } |
---|
39 |
// xml_parser_free($xml_parser); |
---|
40 |
//} |
---|
41 |
?> |
---|
42 |
<html> |
---|
43 |
<head> |
---|
44 |
<title><?php echo trim($oMLT->get("0", "Open SLD")); ?></title> |
---|
45 |
<link href="<?php echo $szCSSFile; ?>" rel="stylesheet" type="text/css"> |
---|
46 |
</head> |
---|
47 |
<script language="JavaScript" src="<?php echo $_SESSION['gszCoreWebPath']; ?>/widgets/js/cwc_dhtml.js" type="text/javascript"></script> |
---|
48 |
<script language="JavaScript" src="<?php echo $_SESSION['gszCoreWebPath']; ?>/widgets/js/cwc_button.js" type="text/javascript"></script> |
---|
49 |
<script language="JavaScript" type="text/javascript"> |
---|
50 |
var szSLDFileName = ""; |
---|
51 |
var sid = "<?php echo SID; ?>"; |
---|
52 |
function CallBackFunc(actionId) |
---|
53 |
{ |
---|
54 |
<?php |
---|
55 |
if (!isset($http_form_vars['szCallbackFunc'])) |
---|
56 |
{ |
---|
57 |
$_SESSION['gErrorManager']->setError(ERR_WARNING, trim($oCommonMLT->get("CBNotSet", "Callback function not set in "))."UploadSLD.phtml"); |
---|
58 |
exit; |
---|
59 |
// echo "window.close();\n"; |
---|
60 |
} |
---|
61 |
else |
---|
62 |
echo "opener.".$http_form_vars['szCallbackFunc']."(actionId, self);\n"; |
---|
63 |
?> |
---|
64 |
} |
---|
65 |
|
---|
66 |
function CloseWindow() |
---|
67 |
{ |
---|
68 |
CallBackFunc(2); |
---|
69 |
} |
---|
70 |
|
---|
71 |
function OpenWindow() |
---|
72 |
{ |
---|
73 |
CallBackFunc(3); |
---|
74 |
|
---|
75 |
self.focus(); |
---|
76 |
} |
---|
77 |
|
---|
78 |
function SubmitForm() |
---|
79 |
{ |
---|
80 |
document.forms[0].submit(); |
---|
81 |
} |
---|
82 |
|
---|
83 |
/* |
---|
84 |
* php errors will appear here is something goes wrong |
---|
85 |
* |
---|
86 |
<?php |
---|
87 |
$szOutput = ""; |
---|
88 |
if (isset($http_form_vars['bSendFile'])) |
---|
89 |
{ |
---|
90 |
$szSLDName = ""; |
---|
91 |
$bLoadSLD = false; |
---|
92 |
$szSLD = ""; |
---|
93 |
if (isset($http_form_vars['szURL']) && $http_form_vars['szURL'] != "") |
---|
94 |
{ |
---|
95 |
$aszFile = file($http_form_vars['szURL']); |
---|
96 |
$szSLD = tempnam($_SESSION['gszTmpPath'], "SLD").".xml"; |
---|
97 |
|
---|
98 |
$fh = fopen($szSLD, "w"); |
---|
99 |
|
---|
100 |
$nbLine = count($aszFile); |
---|
101 |
|
---|
102 |
for($i=0; $i<$nbLine; $i++) |
---|
103 |
{ |
---|
104 |
fwrite($fh, $aszFile[$i]); |
---|
105 |
} |
---|
106 |
fclose($fh); |
---|
107 |
|
---|
108 |
$szOutput .= "szSLDFileName = '".$szSLD."';\n"; |
---|
109 |
$szOutput .= "CallBackFunc(0);\n"; |
---|
110 |
$bLoadSLD = true; |
---|
111 |
$szSLDName = $http_form_vars['szURL']; |
---|
112 |
} |
---|
113 |
else |
---|
114 |
if (is_uploaded_file($HTTP_POST_FILES['oFile']['tmp_name'])) |
---|
115 |
{ |
---|
116 |
//note if upload_tmp_dir is not set properly in php.ini, there could be a bug (at least on windows) |
---|
117 |
$szSLD = $_SESSION['gszTmpPath'].basename($HTTP_POST_FILES['oFile']['tmp_name'].".xml"); |
---|
118 |
copy($HTTP_POST_FILES['oFile']['tmp_name'], $szSLD); |
---|
119 |
|
---|
120 |
$szOutput .= "szSLDFileName = '$szSLD';\n"; |
---|
121 |
$szOutput .= "CallBackFunc(0);\n"; |
---|
122 |
$bLoadSLD = true; |
---|
123 |
$szSLDName = $HTTP_POST_FILES['oFile']['name']; |
---|
124 |
} |
---|
125 |
else |
---|
126 |
echo "alert(\"Fatal error: Error while sending file to server. Maybe file is too big.\");\n"; |
---|
127 |
|
---|
128 |
if ($bLoadSLD) |
---|
129 |
{ |
---|
130 |
if (strcmp( $szSLD, "") != 0) |
---|
131 |
{ |
---|
132 |
// don't check extension when come from web |
---|
133 |
$szNewSLD = ""; |
---|
134 |
if (strtoupper(substr($szSLD, 0, 7)) == "HTTP://") |
---|
135 |
{ |
---|
136 |
$szNewSLD = $szSLD; |
---|
137 |
} |
---|
138 |
else |
---|
139 |
{ |
---|
140 |
if ($szSLD != "" && |
---|
141 |
strtoupper(substr($szSLD, -3)) != "XML") |
---|
142 |
{ |
---|
143 |
// error dont have acces to that path |
---|
144 |
if (is_object($_SESSION["gErrorManager"])) |
---|
145 |
{ |
---|
146 |
$_SESSION["gErrorManager"]->setError(ERR_WARNING, trim($oMLT->get("2", "ERROR: Invalid or no access to SLD"))." (".$szSLD.")"); |
---|
147 |
} |
---|
148 |
else |
---|
149 |
{ |
---|
150 |
$szOutput = "alert('ERROR: unable to load SLD $szSLD');\n"; |
---|
151 |
} |
---|
152 |
} |
---|
153 |
else |
---|
154 |
{ |
---|
155 |
$szNewSLD = $szSLD; |
---|
156 |
} |
---|
157 |
} |
---|
158 |
if ($szNewSLD != "") |
---|
159 |
{ |
---|
160 |
$oMap = &$oMapSession->oMap; |
---|
161 |
if (function_exists( 'file_get_contents' )) |
---|
162 |
{ |
---|
163 |
$szSLDFile = file_get_contents($szNewSLD); |
---|
164 |
} |
---|
165 |
else |
---|
166 |
{ |
---|
167 |
$szSLDFile = implode( "\n", file( $szNewSLD ) ); |
---|
168 |
} |
---|
169 |
//apply sld to one layer or all. |
---|
170 |
if (isset($http_form_vars['nlayerindex'])) |
---|
171 |
{ |
---|
172 |
$oLayer = $oMap->getlayer($http_form_vars['nlayerindex']); |
---|
173 |
$bResult = $oLayer->applySLD( $szSLDFile ); |
---|
174 |
} |
---|
175 |
else |
---|
176 |
{ |
---|
177 |
$bResult = $oMap->applySLD( $szSLDFile ); |
---|
178 |
} |
---|
179 |
|
---|
180 |
if ($oMap->numlayers == 0) |
---|
181 |
{ |
---|
182 |
$aszName = array(); |
---|
183 |
array_push( $aszName, $szSLDName ); |
---|
184 |
$szText = $oMLT->get( "9", "%1\$s does not appear to be a valid SLD.", $aszName ); |
---|
185 |
$szOutput = "alert('$szText');\n"; |
---|
186 |
//echo "alert('".$aszName[0]."');\n"; |
---|
187 |
} |
---|
188 |
else |
---|
189 |
{ |
---|
190 |
// Get mapserver error stack |
---|
191 |
$oError = ms_GetErrorObj(); |
---|
192 |
while($oError && $oError->code > 0) |
---|
193 |
{ |
---|
194 |
if (is_object($_SESSION["gErrorManager"])) |
---|
195 |
{ |
---|
196 |
$_SESSION["gErrorManager"]->setError(ERR_WARNING, $oError->message); |
---|
197 |
} |
---|
198 |
else |
---|
199 |
{ |
---|
200 |
$szOutput = "alert('MAPSERVER ERROR: ".($oError->message)."');\n"; |
---|
201 |
} |
---|
202 |
$oError = $oError->next(); |
---|
203 |
} |
---|
204 |
|
---|
205 |
$_SESSION["gszCurrentState"] = $oMapSession->saveState(); |
---|
206 |
} |
---|
207 |
} |
---|
208 |
} |
---|
209 |
} |
---|
210 |
} |
---|
211 |
?> |
---|
212 |
*/ |
---|
213 |
<?php echo $szOutput; ?> |
---|
214 |
</script> |
---|
215 |
<body class="page" onLoad="OpenWindow()"> |
---|
216 |
|
---|
217 |
<form enctype="multipart/form-data" method="POST" action="UploadSLD.phtml?<?php echo SID; ?>"> |
---|
218 |
<input type="hidden" name="bSendFile" value="1"> |
---|
219 |
<input type="hidden" name="szCallbackFunc" value="<?php echo $http_form_vars['szCallbackFunc']; ?>"> |
---|
220 |
|
---|
221 |
<table width="400" border="0" cellspacing="10" cellpadding="1"> |
---|
222 |
<tr> |
---|
223 |
<td class="layoutTable"> |
---|
224 |
<table class="titleArea" width="100%" border="0" cellpadding="4" cellspacing="0"> |
---|
225 |
<tr> |
---|
226 |
<td><img src="title_open.gif" width="22" height="22" align="texttop"> <span class="title"><?php echo trim($oMLT->get("0", "Open SLD")); ?></span></td> |
---|
227 |
</tr> |
---|
228 |
</table> |
---|
229 |
<table class="contentArea" width="100%" border="0" cellpadding="4" cellspacing="0"> |
---|
230 |
<tr> |
---|
231 |
<td align="center"><p class="helpArea"><?php echo trim($oMLT->get("1", "Please select the local SLD file to be uploaded from your computer, or provide the URL of an SLD.")); ?></p></td> |
---|
232 |
</tr> |
---|
233 |
</table> |
---|
234 |
<table class="contentArea" border="0" cellspacing="0" cellpadding="4" width="100%"> |
---|
235 |
<tr> |
---|
236 |
<td> |
---|
237 |
<table border="0" cellspacing="0" cellpadding="0"> |
---|
238 |
<tr> |
---|
239 |
<td><span class="label"><?php echo trim($oMLT->get("2", "Upload SLD")); ?>: </span></td> |
---|
240 |
<td> |
---|
241 |
<input type="hidden" name="MAX_FILE_SIZE" value="100000"> |
---|
242 |
<input class="inputBox" type="FILE" name="oFile"> |
---|
243 |
</td> |
---|
244 |
</tr> |
---|
245 |
<tr> |
---|
246 |
<td colspan="2"><hr noshade size="1"></td> |
---|
247 |
</tr> |
---|
248 |
<tr> |
---|
249 |
<td><span class="label"><?php echo trim($oMLT->get("3", "SLD URL")); ?>: </span></td> |
---|
250 |
<td> |
---|
251 |
<input class="inputBox" type="text" size=40 name="szURL"> |
---|
252 |
</td> |
---|
253 |
</tr> |
---|
254 |
<?php |
---|
255 |
if (isset($aSLDCollection) && is_array($aSLDCollection) && |
---|
256 |
count($aSLDCollection)) |
---|
257 |
{ |
---|
258 |
?> |
---|
259 |
<tr> |
---|
260 |
<td colspan="2"><hr noshade size="1"></td> |
---|
261 |
</tr> |
---|
262 |
<td><span class="label"><?php echo trim($oMLT->get("5", "SLD List")); ?>: </span></td> |
---|
263 |
<td> |
---|
264 |
<span class="nnInputWrap"><select class="inputList" name="select" onChange="document.forms[0].szURL.value=this[this.selectedIndex].value"> |
---|
265 |
<option class="inputList" value=""><?php echo trim($oMLT->get("6", "Select SLD")); ?></option> |
---|
266 |
<option class="inputList" value="">--------------</option> |
---|
267 |
<?php |
---|
268 |
foreach ($aSLDCollection as $szSLDName => $aSLD) |
---|
269 |
{ |
---|
270 |
echo "<option class=\"inputList\" value=\"".$aSLD['XLINK:HREF']."\">$szSLDName</option>"; |
---|
271 |
} |
---|
272 |
?> |
---|
273 |
</select></span> |
---|
274 |
</td> |
---|
275 |
</tr> |
---|
276 |
<?php |
---|
277 |
} |
---|
278 |
?> |
---|
279 |
</table> |
---|
280 |
</td> |
---|
281 |
</tr> |
---|
282 |
</table> |
---|
283 |
</td> |
---|
284 |
</tr> |
---|
285 |
<tr> |
---|
286 |
<td align=right> |
---|
287 |
<table border="0" cellspacing="0" cellpadding="0"> |
---|
288 |
<tr> |
---|
289 |
<td><?php echo makeButton( 'SubmitForm', '', 'UploadSLD', "icons/icon_ok.png", trim($oCommonMLT->get("Ok", "Ok")), trim($oCommonMLT->get("OkTip", "Apply and Close")), array( 'width' => 75 ) ); ?></td |
---|
290 |
<td> </td> |
---|
291 |
<td><?php echo makeButton( 'CloseWindow', '', 'UploadSLD', "icons/icon_cancel.png", trim($oCommonMLT->get("Cancel", "Cancel")), trim($oCommonMLT->get("CloseTip", "Close Dialog")), array( 'width' => 75 ) ); ?></td> |
---|
292 |
</tr> |
---|
293 |
</table> |
---|
294 |
</td> |
---|
295 |
</tr> |
---|
296 |
</table> |
---|
297 |
|
---|
298 |
</form> |
---|
299 |
|
---|
300 |
</body> |
---|
301 |
</html> |
---|