1 |
<?php |
---|
2 |
/** |
---|
3 |
* Link Widget class |
---|
4 |
* |
---|
5 |
* @project CWC2 |
---|
6 |
* @revision $Id: |
---|
7 |
* @purpose Link 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 |
|
---|
32 |
/** |
---|
33 |
* a simple widget to link to another page |
---|
34 |
*/ |
---|
35 |
class Link extends CWCWidget |
---|
36 |
{ |
---|
37 |
var $moButton; |
---|
38 |
var $mbPopup = false; |
---|
39 |
var $mszHref = null; |
---|
40 |
var $mszLinkType = "HREF"; |
---|
41 |
var $maszJSFunctions = array(); |
---|
42 |
|
---|
43 |
/** |
---|
44 |
* construct a new link widget |
---|
45 |
*/ |
---|
46 |
function Link() |
---|
47 |
{ |
---|
48 |
// invoke constructor of parent |
---|
49 |
parent::CWCWidget(); |
---|
50 |
|
---|
51 |
// set the description for this widget |
---|
52 |
$this->szWidgetDescription = <<<EOT |
---|
53 |
The Link widget allows the template to display a button that will open an |
---|
54 |
arbitrary URL such as a help page for an application. |
---|
55 |
EOT; |
---|
56 |
|
---|
57 |
$this->moButton = new CWCButton($this); |
---|
58 |
$this->maAttributes["APPENDGET"] = new BooleanAttribute( |
---|
59 |
"APPENDGET", false ); |
---|
60 |
$this->maAttributes["APPENDSID"] = new BooleanAttribute("APPENDSID", false ); |
---|
61 |
$this->maAttributes["HREF"] = new StringAttribute( "HREF", false ); |
---|
62 |
$this->maAttributes["JSFUNCTION"] = new StringAttribute( "JSFUNCTION", false ); |
---|
63 |
$this->maAttributes["JSPARAMS"] = new StringAttribute( "JSPARAMS", false ); |
---|
64 |
$this->maAttributes["LINKTYPE"] = new StringAttribute( "LINKTYPE", true, array( "HREF", "JAVASCRIPT" ) ); |
---|
65 |
$this->maAttributes["TARGET"] = new StringAttribute("TARGET", false ); |
---|
66 |
|
---|
67 |
$this->maAttributes['DIV'] = new StringAttribute( "DIV", false ); |
---|
68 |
$this->mnMaturityLevel = MATURITY_TECHNICALRELEASE; |
---|
69 |
} |
---|
70 |
|
---|
71 |
/** |
---|
72 |
* initialize default values |
---|
73 |
*/ |
---|
74 |
function InitDefaults() |
---|
75 |
{ |
---|
76 |
parent::InitDefaults(); |
---|
77 |
if ($this->mbVisible) |
---|
78 |
{ |
---|
79 |
$this->moButton->InitDefaults(); |
---|
80 |
if (isset($this->maParams['LINKTYPE'])) |
---|
81 |
{ |
---|
82 |
$this->mszLinkType = strtoupper($this->maParams['LINKTYPE']); |
---|
83 |
} |
---|
84 |
|
---|
85 |
if ($this->mszLinkType == "HREF") |
---|
86 |
{ |
---|
87 |
$szHref = $this->maParams["HREF"]; |
---|
88 |
|
---|
89 |
$aszHrefParams = array(); |
---|
90 |
if (strpos($szHref, "?") !== false) |
---|
91 |
$aszHrefParams = explode("&",substr(strstr($szHref, "?"), 1)); |
---|
92 |
|
---|
93 |
if (isset($this->maParams["APPENDGET"]) && |
---|
94 |
strcasecmp($this->maParams["APPENDGET"],"true") == 0) |
---|
95 |
{ |
---|
96 |
$szGET = ""; |
---|
97 |
foreach($GLOBALS["_GET"] as $szKey => $szVal) |
---|
98 |
{ |
---|
99 |
// Check all get var if it was set in user link |
---|
100 |
// dont overwrite it. |
---|
101 |
$bFound=false; |
---|
102 |
foreach($aszHrefParams as $szParams) |
---|
103 |
{ |
---|
104 |
$aszParams = explode("=", $szParams); |
---|
105 |
if ($aszParams[0] == $szKey) |
---|
106 |
$bFound = true; |
---|
107 |
} |
---|
108 |
|
---|
109 |
if (!$bFound) |
---|
110 |
$szGET .= "$szKey=".urlencode($szVal)."&"; |
---|
111 |
} |
---|
112 |
|
---|
113 |
if (substr($szHref, -1) == "?" || |
---|
114 |
substr($szHref, -1) == "&") |
---|
115 |
$szHref .= $szGET; |
---|
116 |
else |
---|
117 |
if (strpos($szHref, "?") !== false) |
---|
118 |
{ |
---|
119 |
$szHref .= "&$szGET"; |
---|
120 |
} |
---|
121 |
else |
---|
122 |
$szHref .= "?$szGET"; |
---|
123 |
} |
---|
124 |
|
---|
125 |
if (isset($this->maParams["APPENDSID"]) && |
---|
126 |
strcasecmp($this->maParams["APPENDSID"],"true") == 0) |
---|
127 |
{ |
---|
128 |
if (substr($szHref, -1) == "?" || |
---|
129 |
substr($szHref, -1) == "&") |
---|
130 |
$szHref .= SID; |
---|
131 |
else |
---|
132 |
if (strpos($szHref, "?") !== false) |
---|
133 |
$szHref .= "&".SID; |
---|
134 |
else |
---|
135 |
$szHref .= "?".SID; |
---|
136 |
} |
---|
137 |
|
---|
138 |
$szTarget = ""; |
---|
139 |
if (isset($this->maParams["TARGET"])) |
---|
140 |
$szTarget = $this->maParams["TARGET"]; |
---|
141 |
|
---|
142 |
$szJS = "var wh = window.open( '$szHref', '$szTarget' );\n"; |
---|
143 |
$szJS .= "wh.focus();\n"; |
---|
144 |
|
---|
145 |
$szJSName = 'linkWidget'.$this->mnId; |
---|
146 |
$this->maszJSFunctions[$szJSName] = <<<EOT |
---|
147 |
|
---|
148 |
function {$szJSName}() |
---|
149 |
{ |
---|
150 |
{$szJS}; |
---|
151 |
} |
---|
152 |
EOT; |
---|
153 |
$this->moButton->SetOnClick( 'linkWidget'.$this->mnId ); |
---|
154 |
} |
---|
155 |
elseif ($this->mszLinkType == "JAVASCRIPT") |
---|
156 |
{ |
---|
157 |
if (isset($this->maParams['JSFUNCTION'])) |
---|
158 |
{ |
---|
159 |
$szJS = "void"; |
---|
160 |
$szJSParams = "0"; |
---|
161 |
if ($this->maParams["JSFUNCTION"] != "") |
---|
162 |
{ |
---|
163 |
$szJS = $this->maParams["JSFUNCTION"]; |
---|
164 |
$szJSParams = ""; |
---|
165 |
} |
---|
166 |
if (isset($this->maParams["JSPARAMS"])) |
---|
167 |
{ |
---|
168 |
$szJSParams = $this->maParams["JSPARAMS"]; |
---|
169 |
} |
---|
170 |
$this->moButton->SetOnClick( $szJS, $szJSParams ); |
---|
171 |
} |
---|
172 |
} |
---|
173 |
} |
---|
174 |
} |
---|
175 |
|
---|
176 |
function ParseURL() |
---|
177 |
{ |
---|
178 |
if ($this->mbVisible) |
---|
179 |
return $this->moButton->ParseURL(); |
---|
180 |
else |
---|
181 |
return true; |
---|
182 |
} |
---|
183 |
|
---|
184 |
/** |
---|
185 |
* return javascript functions |
---|
186 |
*/ |
---|
187 |
function GetJavascriptFunctions() |
---|
188 |
{ |
---|
189 |
$aReturn = array(); |
---|
190 |
if ($this->mbVisible) |
---|
191 |
$aReturn = array_merge($this->moButton->GetJavascriptFunctions(), $this->maszJSFunctions); |
---|
192 |
return $aReturn; |
---|
193 |
} |
---|
194 |
|
---|
195 |
/** |
---|
196 |
* return javascript functions |
---|
197 |
*/ |
---|
198 |
function GetJavascriptIncludeFunctions() |
---|
199 |
{ |
---|
200 |
$aResult = array(); |
---|
201 |
if ($this->mbVisible) |
---|
202 |
$aResult = $this->moButton->GetJavascriptIncludeFunctions(); |
---|
203 |
return $aResult; |
---|
204 |
} |
---|
205 |
|
---|
206 |
/** |
---|
207 |
* return javascript variables |
---|
208 |
*/ |
---|
209 |
function GetJavascriptVariables() |
---|
210 |
{ |
---|
211 |
$aResult = array(); |
---|
212 |
if ($this->mbVisible) |
---|
213 |
$aResult = $this->moButton->GetJavascriptVariables(); |
---|
214 |
return $aResult; |
---|
215 |
} |
---|
216 |
|
---|
217 |
/** |
---|
218 |
* return javascript onload functions |
---|
219 |
*/ |
---|
220 |
function GetJavascriptOnLoadFunctions() |
---|
221 |
{ |
---|
222 |
$aResult = array(); |
---|
223 |
if ($this->mbVisible) |
---|
224 |
$aResult = $this->moButton->GetJavascriptOnLoadFunctions(); |
---|
225 |
return $aResult; |
---|
226 |
} |
---|
227 |
|
---|
228 |
/** |
---|
229 |
* return javascript initialization funcitons |
---|
230 |
*/ |
---|
231 |
function GetJavascriptInitFunctions() |
---|
232 |
{ |
---|
233 |
$aResult = array(); |
---|
234 |
if ($this->mbVisible) |
---|
235 |
$aResult = $this->moButton->GetJavascriptInitFunctions(); |
---|
236 |
return $aResult; |
---|
237 |
} |
---|
238 |
|
---|
239 |
function GetHTMLHiddenVariables() |
---|
240 |
{ |
---|
241 |
$aResult = array(); |
---|
242 |
if ($this->mbVisible) |
---|
243 |
$aResult = $this->moButton->GetHTMLHiddenVariables(); |
---|
244 |
|
---|
245 |
return $aResult; |
---|
246 |
} |
---|
247 |
|
---|
248 |
/** |
---|
249 |
* draw the link widget |
---|
250 |
*/ |
---|
251 |
function DrawPublish() |
---|
252 |
{ |
---|
253 |
if (!$this->mbVisible) |
---|
254 |
return "<!-- LinkWidget is hidden -->"; |
---|
255 |
|
---|
256 |
|
---|
257 |
$szReturn = $this->moButton->DrawPublish(); |
---|
258 |
|
---|
259 |
return $szReturn; |
---|
260 |
} |
---|
261 |
} |
---|
262 |
?> |
---|