1 |
<?php |
---|
2 |
/** |
---|
3 |
* ContextUpload Widget class |
---|
4 |
* |
---|
5 |
* @project CWC2 |
---|
6 |
* @revision $Id: UploadContext.widget.php,v 1.9 2004/10/14 18:19:22 pspencer Exp $ |
---|
7 |
* @purpose ContextUpload 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 |
/** |
---|
34 |
* ContextUpload |
---|
35 |
* |
---|
36 |
* @desc ContextUpload widget class |
---|
37 |
*/ |
---|
38 |
class UploadContext extends CWCWidget |
---|
39 |
{ |
---|
40 |
var $mszTemplate; // [string] |
---|
41 |
|
---|
42 |
var $moButton; // Button object |
---|
43 |
var $moPopup; // Popup object |
---|
44 |
|
---|
45 |
var $mszLink = ''; |
---|
46 |
var $mszParam = '&szCallbackFunc=OpenContextCB'; |
---|
47 |
var $mbAllowResize = true; |
---|
48 |
|
---|
49 |
/** |
---|
50 |
* ContextUpload |
---|
51 |
* |
---|
52 |
* Constctor method for the ContextUpload widget. |
---|
53 |
*/ |
---|
54 |
function UploadContext() |
---|
55 |
{ |
---|
56 |
// invoke constructor of parent |
---|
57 |
parent::CWCWidget(); |
---|
58 |
|
---|
59 |
// set the description for this widget |
---|
60 |
$this->szWidgetDescription = <<<EOT |
---|
61 |
The ContextUpload widget allows the user to upload a Context file from their |
---|
62 |
local hard drive or from a URL to the current application. This widget |
---|
63 |
does not limit the user from attempting to upload contexts if the CWC2 service |
---|
64 |
instance is configured not to allow it. The user will receive an error message |
---|
65 |
after this widget attempts to upload the context. |
---|
66 |
EOT; |
---|
67 |
|
---|
68 |
$this->moButton = new CWCButton($this); |
---|
69 |
|
---|
70 |
$this->moPopup = new CWCPopup($this); |
---|
71 |
$this->mnPriority = PRIORITY_MAXIMUM; |
---|
72 |
$this->maAttributes['ALLOWRESIZE'] = new BooleanAttribute( 'ALLOWRESIZE', false ); |
---|
73 |
$this->mnMaturityLevel = MATURITY_BETA; |
---|
74 |
} |
---|
75 |
|
---|
76 |
|
---|
77 |
function InitDefaults() |
---|
78 |
{ |
---|
79 |
parent::InitDefaults(); |
---|
80 |
//this widget should never belong to a toolset |
---|
81 |
$this->maParams["TOOLSET"] = ""; |
---|
82 |
$this->moButton->InitDefaults(); |
---|
83 |
$this->moButton->SetOnClick('clickUploadContext'); |
---|
84 |
$this->moPopup->mszLink = $_SESSION['gszCoreWebPath'].'/widgets/UploadContext/UploadContext.phtml'; |
---|
85 |
$this->moPopup->mszParam = $this->mszParam; |
---|
86 |
$this->moPopup->InitDefaults(); |
---|
87 |
if (!isset($_SESSION['UPLOADCONTEXT_OPTIONS'])) |
---|
88 |
{ |
---|
89 |
$_SESSION['UPLOADCONTEXT_OPTIONS'] = array(); |
---|
90 |
if (isset( $this->maszContents["CONTEXT"] )) |
---|
91 |
{ |
---|
92 |
foreach( $this->maszContents["CONTEXT"] as $aSelection ) |
---|
93 |
{ |
---|
94 |
if (isset($aSelection["NAME"]) && isset($aSelection["URL"])) |
---|
95 |
{ |
---|
96 |
$aOption = array( $aSelection["NAME"], $aSelection["URL"], false ); |
---|
97 |
array_push( $_SESSION['UPLOADCONTEXT_OPTIONS'], $aOption ); |
---|
98 |
|
---|
99 |
} |
---|
100 |
else |
---|
101 |
{ |
---|
102 |
$_SESSION['gErrorManager']->setError(ERR_WARNING, |
---|
103 |
trim($this->moMLT->get("9", "ERROR: Invalid CONTEXT tag definition in UploadContext Tag"))); |
---|
104 |
} |
---|
105 |
} |
---|
106 |
} |
---|
107 |
if (isset($this->maszContents["OPTION"])) |
---|
108 |
{ |
---|
109 |
foreach($this->maszContents["OPTION"] as $aSelection) |
---|
110 |
{ |
---|
111 |
$aOption = array(); |
---|
112 |
if (isset($aSelection["LABEL"])) |
---|
113 |
{ |
---|
114 |
array_push($aOption, $aSelection['LABEL']); |
---|
115 |
array_push($aOption, isset( $aSelection['VALUE'] ) ? $aSelection['VALUE'] : "" ); |
---|
116 |
} |
---|
117 |
else if (isset($aSelection['VALUE'])) |
---|
118 |
{ |
---|
119 |
array_push($aOption, $aSelection['VALUE']); |
---|
120 |
array_push($aOption, $aSelection['VALUE']); |
---|
121 |
|
---|
122 |
} |
---|
123 |
if (isset($aSelection["SELECTED"])) |
---|
124 |
{ |
---|
125 |
array_push( $aOption, strcasecmp($aSelection["SELECTED"], "true") == 0 ? true : false ); |
---|
126 |
} |
---|
127 |
array_push( $_SESSION['UPLOADCONTEXT_OPTIONS'], $aOption ); |
---|
128 |
} |
---|
129 |
} |
---|
130 |
} |
---|
131 |
if (isset($this->maParams['ALLOWRESIZE'])) |
---|
132 |
{ |
---|
133 |
$this->mbAllowResize = strcasecmp($this->maParams['ALLOWRESIZE'], "true") == 0 ? true : false; |
---|
134 |
} |
---|
135 |
//NOTE THIS IS NOT MULTIPLE WIDGET SAFE ... to do that, we would need to use $this->mnId AND pass |
---|
136 |
// the widget id to the popup ... not necessarily a bad idea to incorporate into the popup class ... |
---|
137 |
$_SESSION['UPLOADCONTEXT_ALLOWRESIZE'] = $this->mbAllowResize; |
---|
138 |
} |
---|
139 |
|
---|
140 |
function GetJavascriptVariables() |
---|
141 |
{ |
---|
142 |
if ($this->mbVisible) |
---|
143 |
return $this->moButton->GetJavascriptVariables(); |
---|
144 |
else return array(); |
---|
145 |
} |
---|
146 |
|
---|
147 |
function GetJavascriptInitFunctions() |
---|
148 |
{ |
---|
149 |
if ($this->mbVisible) |
---|
150 |
return $this->moButton->GetJavascriptInitFunctions(); |
---|
151 |
else return array(); |
---|
152 |
} |
---|
153 |
|
---|
154 |
function GetJavascriptOnLoadFunctions() |
---|
155 |
{ |
---|
156 |
if ($this->mbVisible) |
---|
157 |
$aReturn = $this->moButton->GetJavascriptOnLoadFunctions(); |
---|
158 |
else |
---|
159 |
$aReturn = array(); |
---|
160 |
return $aReturn; |
---|
161 |
} |
---|
162 |
|
---|
163 |
function GetJavascriptIncludeFunctions() |
---|
164 |
{ |
---|
165 |
if ($this->mbVisible) |
---|
166 |
$aReturn = $this->moButton->GetJavascriptIncludeFunctions(); |
---|
167 |
else |
---|
168 |
$aReturn = array(); |
---|
169 |
return $aReturn; |
---|
170 |
} |
---|
171 |
|
---|
172 |
|
---|
173 |
/** |
---|
174 |
* GetJavascriptFunctions |
---|
175 |
* |
---|
176 |
* Build and return the array of functions needed in the |
---|
177 |
* widget. |
---|
178 |
*/ |
---|
179 |
function GetJavascriptFunctions() |
---|
180 |
{ |
---|
181 |
$aReturn = array(); |
---|
182 |
|
---|
183 |
$szJsFunctionName = "clickUploadContext"; |
---|
184 |
$szFunction = "function $szJsFunctionName()\n" . |
---|
185 |
"{\n". |
---|
186 |
$this->moPopup->DrawPublish()."\n". |
---|
187 |
"return;\n" . |
---|
188 |
"}\n"; |
---|
189 |
$aReturn[$szJsFunctionName] = $szFunction; |
---|
190 |
|
---|
191 |
$szJsFunctionName = "OpenContextCB"; |
---|
192 |
$szFunction = <<<EOF |
---|
193 |
|
---|
194 |
function {$szJsFunctionName}(actionID, wh) |
---|
195 |
{ |
---|
196 |
if (actionID == 0 || actionID == 1) // ok |
---|
197 |
{ |
---|
198 |
// The context has been loaded into the map session, simply reload |
---|
199 |
// the page. First we'll need to clear some previous state, though. |
---|
200 |
if ({$this->mszHTMLForm}.MAP_EXTENTS_MINX.value != null) |
---|
201 |
{$this->mszHTMLForm}.MAP_EXTENTS_MINX.value = ""; |
---|
202 |
if ({$this->mszHTMLForm}.MAP_EXTENTS_MINY.value != null) |
---|
203 |
{$this->mszHTMLForm}.MAP_EXTENTS_MINY.value = ""; |
---|
204 |
if ({$this->mszHTMLForm}.MAP_EXTENTS_MAXX.value != null) |
---|
205 |
{$this->mszHTMLForm}.MAP_EXTENTS_MAXX.value = ""; |
---|
206 |
if ({$this->mszHTMLForm}.MAP_EXTENTS_MAXY.value != null) |
---|
207 |
{$this->mszHTMLForm}.MAP_EXTENTS_MAXY.value = ""; |
---|
208 |
if ({$this->mszHTMLForm}.MAP_WIDTH.value != null) |
---|
209 |
{$this->mszHTMLForm}.MAP_WIDTH.value = ""; |
---|
210 |
if ({$this->mszHTMLForm}.MAP_HEIGHT.value != null) |
---|
211 |
{$this->mszHTMLForm}.MAP_HEIGHT.value = ""; |
---|
212 |
if ({$this->mszHTMLForm}.LEGENDTEMPLATE_RESET != null && {$this->mszHTMLForm}.LEGENDTEMPLATE_RESET.value != null) |
---|
213 |
{$this->mszHTMLForm}.LEGENDTEMPLATE_RESET.value = "1"; |
---|
214 |
wh.close(); |
---|
215 |
{$this->mszHTMLForm}.submit(); |
---|
216 |
} |
---|
217 |
else if (actionID == 2) // cancel |
---|
218 |
{ |
---|
219 |
wh.close(); |
---|
220 |
} |
---|
221 |
|
---|
222 |
return; |
---|
223 |
} |
---|
224 |
|
---|
225 |
EOF; |
---|
226 |
$aReturn[$szJsFunctionName] = $szFunction; |
---|
227 |
|
---|
228 |
return $aReturn; |
---|
229 |
} |
---|
230 |
|
---|
231 |
function GetHTMLHiddenVariables() |
---|
232 |
{ |
---|
233 |
$aReturn = $this->moButton->GetHTMLHiddenVariables(); |
---|
234 |
|
---|
235 |
return $aReturn; |
---|
236 |
} |
---|
237 |
|
---|
238 |
/** |
---|
239 |
* DrawPublish |
---|
240 |
* |
---|
241 |
* Return the HTML code to display the link to the legend popup |
---|
242 |
* |
---|
243 |
* @return HTML Code |
---|
244 |
*/ |
---|
245 |
function DrawPublish() |
---|
246 |
{ |
---|
247 |
if (!$this->mbVisible) |
---|
248 |
return '<!-- Upload Context widget hidden -->'; |
---|
249 |
|
---|
250 |
|
---|
251 |
$szReturn = $this->moButton->DrawPublish(); |
---|
252 |
|
---|
253 |
return $szReturn; |
---|
254 |
} |
---|
255 |
} |
---|
256 |
?> |
---|