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