1 |
<?php |
---|
2 |
/** |
---|
3 |
* WMSBrowser Widget class |
---|
4 |
* |
---|
5 |
* @project CWC2 |
---|
6 |
* @revision $Id: WMSBrowser.widget.php,v 1.13 2004/11/11 21:29:32 pspencer Exp $ |
---|
7 |
* @purpose WMSBrowser Popup Widget class |
---|
8 |
* @author DM Solutions Group (sfournier@dmsolutions.ca) |
---|
9 |
* @copyright |
---|
10 |
* <b>Copyright (c) 2002, DM Solutions Group Inc.</b> |
---|
11 |
* Permission is hereby granted, free of charge, to any person obtaining a |
---|
12 |
* copy of this software and associated documentation files (the "Software"), |
---|
13 |
* to deal in the Software without restriction, including without limitation |
---|
14 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
---|
15 |
* and/or sell copies of the Software, and to permit persons to whom the |
---|
16 |
* Software is furnished to do so, subject to the following conditions: |
---|
17 |
* |
---|
18 |
* The above copyright notice and this permission notice shall be included |
---|
19 |
* in all copies or substantial portions of the Software. |
---|
20 |
* |
---|
21 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
22 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
23 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
---|
24 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
25 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
---|
26 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
27 |
* DEALINGS IN THE SOFTWARE. |
---|
28 |
*/ |
---|
29 |
include_once(dirname(__FILE__)."/../Widget.php"); |
---|
30 |
include_once(dirname(__FILE__)."/../Button.php"); |
---|
31 |
include_once(dirname(__FILE__)."/../Popup.php"); |
---|
32 |
|
---|
33 |
include_once( COMMON."/phpwms/dbf.php"); |
---|
34 |
include_once( COMMON."/phpwms/server_data_manager.php"); |
---|
35 |
|
---|
36 |
/** |
---|
37 |
* a simple widget to link to another page |
---|
38 |
*/ |
---|
39 |
class WMSBrowser extends CWCWidget |
---|
40 |
{ |
---|
41 |
var $mszWMSCacheDirectory; |
---|
42 |
var $mbUseUserSession = false; |
---|
43 |
var $moButton; |
---|
44 |
var $moPopup; |
---|
45 |
|
---|
46 |
/** |
---|
47 |
* construct a new WMSBrowser widget |
---|
48 |
*/ |
---|
49 |
function WMSBrowser() |
---|
50 |
{ |
---|
51 |
// invoke constructor of parent |
---|
52 |
parent::CWCWidget(); |
---|
53 |
|
---|
54 |
$this->maAttributes["WMSCACHEDIRECTORY"] = new StringAttribute( "WMSCACHEDIRECTORY", false); |
---|
55 |
$this->maAttributes["USEUSERSESSION"] = new BooleanAttribute( "USEUSERSESSION", false); |
---|
56 |
$this->maAttributes["PREVIEWEXTENTS"] = new StringAttribute( "PREVIEWEXTENTS", false); |
---|
57 |
$this->maAttributes["PREVIEWSRS"] = new StringAttribute( "PREVIEWSRS", false); |
---|
58 |
|
---|
59 |
|
---|
60 |
$this->moButton = new CWCButton( $this ); |
---|
61 |
$this->moPopup = new CWCPopup( $this ); |
---|
62 |
|
---|
63 |
$this->mnPriority = PRIORITY_SUPER; |
---|
64 |
|
---|
65 |
// set the description for this widget |
---|
66 |
$this->szWidgetDescription = <<<EOT |
---|
67 |
The WMSBrowser widget allows ..... |
---|
68 |
EOT; |
---|
69 |
$this->mnMaturityLevel = MATURITY_BETA; |
---|
70 |
} |
---|
71 |
|
---|
72 |
function InitDefaults() |
---|
73 |
{ |
---|
74 |
$oApp = GetChameleonApplication(); |
---|
75 |
|
---|
76 |
parent::InitDefaults(); |
---|
77 |
|
---|
78 |
$this->moButton->InitDefaults(); |
---|
79 |
//this widget should never belong to a toolset |
---|
80 |
$this->maParams["TOOLSET"] = ""; |
---|
81 |
$this->moButton->SetOnClick( 'clickWMSBrowser' ); |
---|
82 |
$this->moPopup->mszLink = $_SESSION['gszCoreWebPath']."/widgets/WMSBrowser/WMSBrowser.php?"; |
---|
83 |
|
---|
84 |
if (isset($this->maParams["USEUSERSESSION"])) |
---|
85 |
$this->mbUseUserSession = (strtoupper($this->maParams["USEUSERSESSION"]) == "TRUE") ? true : false; |
---|
86 |
if (isset($this->maParams["PREVIEWEXTENTS"])) |
---|
87 |
$_SESSION['WMSBROWSER_PREVIEWEXTENTS'] = $this->maParams['PREVIEWEXTENTS']; |
---|
88 |
|
---|
89 |
if (isset($this->maParams["PREVIEWSRS"])) |
---|
90 |
$_SESSION['WMSBROWSER_PREVIEWSRS'] = $this->maParams['PREVIEWSRS']; |
---|
91 |
|
---|
92 |
if (isset($this->maParams["WMSCACHEDIRECTORY"])) |
---|
93 |
{ |
---|
94 |
$this->mszWMSCacheDirectory = $oApp->resolvePath2($this->maParams["WMSCACHEDIRECTORY"], $_SESSION['gszAppPath']); |
---|
95 |
} |
---|
96 |
else |
---|
97 |
{ |
---|
98 |
$this->mszWMSCacheDirectory = realpath($_SESSION['gszCorePath']."/../data"); |
---|
99 |
} |
---|
100 |
|
---|
101 |
if (!isset($_SESSION['gszServerDataPath'])) |
---|
102 |
{ |
---|
103 |
if ($this->mbUseUserSession) |
---|
104 |
{ |
---|
105 |
$szDir = str_replace("\\", "/", getSessionSavePath()."/data/"); |
---|
106 |
|
---|
107 |
// Check if data exist in user dir |
---|
108 |
if (!is_dir($szDir)) |
---|
109 |
mkdir($szDir); |
---|
110 |
|
---|
111 |
// copy content of WMS cache dir to user directory |
---|
112 |
$hDir = opendir($this->mszWMSCacheDirectory); |
---|
113 |
while ($szFile = readdir($hDir)) |
---|
114 |
{ |
---|
115 |
if (is_file($this->mszWMSCacheDirectory."/".$szFile)) |
---|
116 |
copy($this->mszWMSCacheDirectory."/".$szFile, $szDir."/".$szFile); |
---|
117 |
} |
---|
118 |
|
---|
119 |
$_SESSION["gszServerDataPath"] = $szDir; |
---|
120 |
} |
---|
121 |
else |
---|
122 |
$_SESSION["gszServerDataPath"] = $this->mszWMSCacheDirectory; |
---|
123 |
} |
---|
124 |
|
---|
125 |
} |
---|
126 |
|
---|
127 |
/** |
---|
128 |
* Add WMS layer if any specified |
---|
129 |
*/ |
---|
130 |
function ParseURL() |
---|
131 |
{ |
---|
132 |
$this->moButton->ParseURL(); |
---|
133 |
|
---|
134 |
if ($this->isVarSet( "WMS_LAYERS_TOADD" ) && |
---|
135 |
$this->getVar( "WMS_LAYERS_TOADD" ) != "") |
---|
136 |
{ |
---|
137 |
$szSelectedLayers = $this->getVar( "WMS_LAYERS_TOADD" ); |
---|
138 |
|
---|
139 |
//check the projection attribute before adding WMS layers |
---|
140 |
$szProj = $this->moMapObject->oMap->getProjection(); |
---|
141 |
|
---|
142 |
//initialize the layers array; |
---|
143 |
$aszLayers = array(); |
---|
144 |
|
---|
145 |
if ( $szProj == "" ) |
---|
146 |
{ |
---|
147 |
$_SESSION['gErrorManager']->setError(ERR_WARNING, |
---|
148 |
"Projection must be set in map file to add WMS layers!" ); |
---|
149 |
$bWMSProjectionWarning = 1; |
---|
150 |
} |
---|
151 |
else |
---|
152 |
{ |
---|
153 |
$aszLayers = explode (',',$szSelectedLayers); |
---|
154 |
|
---|
155 |
foreach($aszLayers as $szLayer) |
---|
156 |
{ |
---|
157 |
// add the layer to the map |
---|
158 |
if (is_numeric($szLayer)); |
---|
159 |
{ |
---|
160 |
$oWMSDatabase = new WMSDatabase( $_SESSION["gszServerDataPath"] ); |
---|
161 |
$oServerDataManager = new ServerDataManager( $oWMSDatabase ); |
---|
162 |
$oWMSLayer = $oServerDataManager->getLayerObj( $szLayer ); |
---|
163 |
if ($oWMSLayer == null) |
---|
164 |
{ |
---|
165 |
$_SESSION['gErrorManager']->setError(ERR_WARNING, |
---|
166 |
"ERROR: could not add layer $szLayer to map!" ); |
---|
167 |
return false; |
---|
168 |
|
---|
169 |
} |
---|
170 |
$oLayer = ms_newLayerObj( $this->moMapObject->oMap, $oWMSLayer ); |
---|
171 |
|
---|
172 |
// get the current map projection |
---|
173 |
$szTempMapProj = $this->moMapObject->oMap->getprojection(); |
---|
174 |
|
---|
175 |
// only set the projection if it's set in the map |
---|
176 |
if ( strlen( trim( $szTempMapProj ) ) > 0 ) |
---|
177 |
{ |
---|
178 |
// set layer projection |
---|
179 |
$oLayer->setprojection( $szTempMapProj ); |
---|
180 |
} |
---|
181 |
|
---|
182 |
$_SESSION['gszCurrentState'] = $this->moMapObject->saveState(); |
---|
183 |
} |
---|
184 |
} |
---|
185 |
} |
---|
186 |
} |
---|
187 |
return true; |
---|
188 |
} |
---|
189 |
|
---|
190 |
function GetJavascriptFunctions() |
---|
191 |
{ |
---|
192 |
$aReturn = $this->moButton->GetJavascriptFunctions(); |
---|
193 |
|
---|
194 |
$szJsFunctionName = "BrowseWMSCallBack"; |
---|
195 |
$szFunction = <<<EOT |
---|
196 |
function {$szJsFunctionName}( actionId, wh ) |
---|
197 |
{ |
---|
198 |
if ( actionId == 0) //Clicked Apply |
---|
199 |
{ |
---|
200 |
var szSelectedLayers = wh.document.forms[0].selectedLayers.value; |
---|
201 |
{$this->mszHTMLForm}.WMS_LAYERS_TOADD.value = szSelectedLayers; |
---|
202 |
{$this->mszHTMLForm}.submit(); |
---|
203 |
} |
---|
204 |
else if ( actionId == 1) // cancel |
---|
205 |
{ |
---|
206 |
if (!wh.closed) |
---|
207 |
wh.close(); |
---|
208 |
} |
---|
209 |
else if ( actionId == 2) // submit only |
---|
210 |
{ |
---|
211 |
{$this->mszHTMLForm}.submit(); |
---|
212 |
} |
---|
213 |
return; |
---|
214 |
} |
---|
215 |
EOT; |
---|
216 |
|
---|
217 |
$aReturn[$szJsFunctionName] = $szFunction; |
---|
218 |
|
---|
219 |
$szPopup = $this->moPopup->DrawPublish(); |
---|
220 |
$szJsFunctionName = "clickWMSBrowser"; |
---|
221 |
$szFunction = <<<EOT |
---|
222 |
function {$szJsFunctionName}() |
---|
223 |
{ |
---|
224 |
{$szPopup} |
---|
225 |
} |
---|
226 |
EOT; |
---|
227 |
$aReturn[$szJsFunctionName] = $szFunction; |
---|
228 |
|
---|
229 |
return $aReturn; |
---|
230 |
} |
---|
231 |
|
---|
232 |
/** |
---|
233 |
* return hidden variables |
---|
234 |
*/ |
---|
235 |
function GetHTMLHiddenVariables() |
---|
236 |
{ |
---|
237 |
$aReturn = $this->moButton->GetHTMLHiddenVariables(); |
---|
238 |
|
---|
239 |
$szVariable = "WMS_LAYERS_TOADD"; |
---|
240 |
$szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"\">"; |
---|
241 |
$aReturn[$szVariable] = $szValue; |
---|
242 |
|
---|
243 |
return $aReturn; |
---|
244 |
} |
---|
245 |
|
---|
246 |
function GetJavascriptInitFunctions() |
---|
247 |
{ |
---|
248 |
return $this->moButton->GetJavascriptInitFunctions(); |
---|
249 |
} |
---|
250 |
|
---|
251 |
function GetJavascriptVariables() |
---|
252 |
{ |
---|
253 |
return $this->moButton->GetJavascriptVariables(); |
---|
254 |
} |
---|
255 |
|
---|
256 |
function GetJavascriptOnLoadFunctions() |
---|
257 |
{ |
---|
258 |
return $this->moButton->GetJavascriptOnLoadFunctions(); |
---|
259 |
} |
---|
260 |
|
---|
261 |
function GetJavascriptIncludeFunctions() |
---|
262 |
{ |
---|
263 |
return $this->moButton->GetJavascriptIncludeFunctions(); |
---|
264 |
} |
---|
265 |
|
---|
266 |
/** |
---|
267 |
* DrawPublish |
---|
268 |
* |
---|
269 |
* Return the HTML code using the name in the map file and the |
---|
270 |
* parameters of the CWC tag. |
---|
271 |
*/ |
---|
272 |
function DrawPublish() |
---|
273 |
{ |
---|
274 |
if (!$this->mbVisible) |
---|
275 |
return "<!-- WMSBrowser popup widget hidden -->"; |
---|
276 |
|
---|
277 |
$szResult = $this->moButton->DrawPublish(); |
---|
278 |
|
---|
279 |
return $szResult; |
---|
280 |
} |
---|
281 |
|
---|
282 |
|
---|
283 |
} |
---|
284 |
?> |
---|