NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/Chameleon/trunk/Chameleon/Popup.php

Revision 13 (checked in by jcleary, 17 years ago)

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * Popup Class
4  *
5  * @project     CWC2
6  * @revision    $Id:
7  * @purpose     Helper class to manage Popup attributes
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
30 /**
31  * helper class for widgets that want to popup another window through a
32  * javascript call
33  */
34 class CWCPopup
35 {
36     var $moParent;
37     var $miWidth = 200;
38     var $miHeight = 200;
39     var $mbToolbar = true;
40     var $mbMenubar = true;
41     var $mbStatus = true;
42     var $mbScrollbars = true;
43     var $mbResizable = true;
44     var $mszPopupStyleResource = "";
45
46     var $mszLink = "";
47     var $mszParam = "";
48
49     /**
50      * construct a new popup widget
51      */
52     function CWCPopup( &$oParent )
53     {
54         $this->moParent =& $oParent;
55         $oParent->maAttributes["POPUPWIDTH"] = new IntegerAttribute( "POPUPWIDTH", true, 0 );
56         $oParent->maAttributes["POPUPHEIGHT"] = new IntegerAttribute( "POPUPHEIGHT", true, 0 );
57         $oParent->maAttributes["TOOLBAR"] = new BooleanAttribute( "TOOLBAR", false );
58         $oParent->maAttributes["MENUBAR"] = new BooleanAttribute( "MENUBAR", false );
59         $oParent->maAttributes["STATUS"] = new BooleanAttribute( "STATUS", false );
60         $oParent->maAttributes["SCROLLBARS"] = new BooleanAttribute( "SCROLLBARS", false );
61         $oParent->maAttributes["RESIZABLE"] = new BooleanAttribute( "RESIZABLE", false );
62         $oParent->maAttributes["POPUPSTYLERESOURCE"] = new StringAttribute( "POPUPSTYLERESOURCE", false );
63     }
64
65     /**
66      * initialize default values
67      */
68     function InitDefaults()
69     {
70         $this->SetStyleResource();
71     }
72
73     /**
74      * construct a URL for the popup
75      */
76     function GetPopupURL()
77     {
78         if ((dirname($this->mszLink) == "widgets" ||
79             dirname($this->mszLink) == "./widgets") &&
80             isset($_SESSION['gszCoreWebPath']))
81         {
82             $this->mszLink = $_SESSION['gszCoreWebPath']."/widgets/".
83                               basename($this->mszLink);
84         }
85
86         if (substr($this->mszLink, -1) != "?")
87         {
88             if (stristr($this->mszLink, "?") === false)
89                 $this->mszLink .= "?";
90             else
91                 $this->mszLink .= "&";
92         }
93         return $this->mszLink.SID.$this->mszParam;
94     }
95
96     /**
97      * get a unique name for this widget to refer to a window by
98      */
99     function GetPopupName()
100     {
101         $szName = "popup";
102         if (isset($this->moParent->maParams["TYPE"]))
103             $szName = $this->moParent->maParams["TYPE"];
104
105         return  $szName."_".
106                 $this->moParent->mnId."_".session_id();
107     }
108
109     /**
110      * get the options to apply to the popup window
111      */
112     function GetPopupOptions()
113     {
114         // Mandatory values
115         if (isset($this->moParent->maParams["POPUPWIDTH"]))
116             $this->miWidth = $this->moParent->maParams["POPUPWIDTH"];
117         if (isset($this->moParent->maParams["POPUPHEIGHT"]))
118             $this->miHeight = $this->moParent->maParams["POPUPHEIGHT"];
119
120         // Optional Values
121         if (isset($this->moParent->maParams["POPUPSTYLERESOURCE"]))
122             $this->mszPopupStyleResource = $this->moParent->maParams["POPUPSTYLERESOURCE"];
123         if (isset($this->moParent->maParams["TOOLBAR"]))
124             $this->mbToolbar = $this->moParent->maParams["TOOLBAR"];
125         if (isset($this->moParent->maParams["MENUBAR"]))
126             $this->mbMenubar = $this->moParent->maParams["MENUBAR"];
127         if (isset($this->moParent->maParams["STATUS"]))
128             $this->mbStatus = $this->moParent->maParams["STATUS"];
129         if (isset($this->moParent->maParams["SCROLLBARS"]))
130             $this->mbScrollbars = $this->moParent->maParams["SCROLLBARS"];
131         if (isset($this->moParent->maParams["RESIZABLE"]))
132             $this->mbResizable = $this->moParent->maParams["RESIZABLE"];
133
134         $szResult = "width=".$this->miWidth.",height=".$this->miHeight.",";
135
136         $szResult .= (($this->mbToolbar == "true") ? "toolbar=yes," : "toolbar=no,");
137         $szResult .= (($this->mbMenubar == "true") ? "menubar=yes," : "menubar=no,");
138         $szResult .= (($this->mbStatus == "true") ? "status=yes," : "status=no,");
139         $szResult .= (($this->mbScrollbars == "true") ? "scrollbars=yes," : "scrollbars=no,");
140         $szResult .= (($this->mbResizable == "true") ? "resizable=yes" : "resizable=no");
141         return $szResult;
142     }
143
144     /**
145      * draw the popup javascript call
146      */
147     function DrawPublish( $szContent = "" )
148     {
149         $oApp = GetChameleonApplication();
150         $this->SetStyleResource();
151         //pass style resource to the popup
152         
153         if (isset($this->moParent->maSharedResourceWidgets['PopupCSS']) && !isset($_SESSION['gszCSSFile']))
154         {
155             $szPopupCSS = $this->moParent->maSharedResourceWidgets['PopupCSS']->getValue("VALUE","popup.css");
156             $szPopupCSS = $oApp->findFile( $szPopupCSS );
157             $szPopupCSS = $oApp->fileSystemToURL( $szPopupCSS, true );
158             $_SESSION['gszCSSFile'] = $szPopupCSS;
159         }
160         
161         $url = $this->GetPopupURL();
162         $name = $this->GetPopupName();
163         $options = $this->GetPopupOptions();
164         
165         $szResult  = <<<EOT
166 var wh = window.open('{$url}', '{$name}', '{$options}');
167 if (!wh)
168 {
169     alert( 'unable to open popup dialog.  Perhaps you have a popup blocker installed?' );
170 }
171 else
172 {
173     wh.focus();
174 }
175 EOT;
176
177         return $szResult;
178     }
179     
180     function SetStyleResource()
181     {
182         $oApp = GetChameleonApplication();
183         $szTemplate = $oApp->mszTemplateName;
184         $szSessionName = strtoupper(get_class( $this->moParent )).'POPUPSTYLERESOURCE';
185         
186         if ( isset( $this->moParent->maParams['POPUPSTYLERESOURCE']) ||
187              isset( $this->moParent->maParams['STYLERESOURCE']) )
188         {
189             if (isset($this->moParent->maParams['POPUPSTYLERESOURCE']) &&
190                 $this->moParent->maParams['POPUPSTYLERESOURCE'] != "" )
191             {
192                 $_SESSION[$szSessionName] = $this->moParent->maParams['POPUPSTYLERESOURCE'].$szTemplate;
193             }
194             elseif (isset($this->moParent->maParams['STYLERESOURCE']))
195             {
196                 $_SESSION[$szSessionName] = $this->moParent->maParams['STYLERESOURCE'].$szTemplate;
197             }
198             else
199             {
200                 $_SESSION[$szSessionName] = "";
201             }
202         }
203         if (isset($_SESSION[$szSessionName]) && $_SESSION[$szSessionName] != "")
204         {
205             if (!isset($_SESSION[$_SESSION[$szSessionName]]) && isset($this->moParent->maSharedResourceWidgets[$_SESSION[$szSessionName]]))
206             {
207                 $share = $this->moParent->maSharedResourceWidgets[$_SESSION[$szSessionName]]->maszContents;
208                 $aszStates = array( "normal", "hover", "selected", "disabled" );
209                 foreach($aszStates as $szState)
210                 {
211                     $aParams = $this->LoadSharedResource( $share, array(), $szState );
212                     $_SESSION[$_SESSION[$szSessionName]][$szState] = $aParams; //make a copy in the session.
213                 }
214             }
215         }       
216     }
217     
218     /**
219      * load a shared resource into an array that contains buttonizer values
220      * return the loaded array
221      */
222     function LoadSharedResource( $share, $aParams = array(), $szState )
223     {
224         $oApp = GetChameleonApplication();
225         //process includes first
226         if (isset($share['STATE']))
227         {
228             foreach( $share["STATE"] as $aszSR )
229             {
230                 if($aszSR["VALUE"] == $szState)
231                 {
232                     $aParams = $this->LoadSharedResource($aszSR["CHILDREN"][0], $aParams, $szState);
233                 }
234             }
235         }
236         
237         if (isset($share["IMAGEWIDTH"][0]["VALUE"]))
238             $aParams["width"] = $share["IMAGEWIDTH"][0]["VALUE"];
239         
240         if (isset($share["IMAGEHEIGHT"][0]["VALUE"]))
241             $aParams["height"] = $share["IMAGEHEIGHT"][0]["VALUE"];
242         
243         if (isset($share["TEXTBUTTONCOLOR"][0]["VALUE"]))
244             $aParams["backgroundcolor"] = $share["TEXTBUTTONCOLOR"][0]["VALUE"];
245         
246         if (isset($share["BACKGROUNDIMAGE"][0]["VALUE"]))
247             $aParams["backgroundgraphic"] = $oApp->findFile( $share["BACKGROUNDIMAGE"][0]["VALUE"] );
248
249         if (isset($share["TEXTBUTTONBORDER_TOPLEFT_IMAGE"][0]["VALUE"]))
250             $aParams["border_tl_image"] = $oApp->findFile( $share["TEXTBUTTONBORDER_TOPLEFT_IMAGE"][0]["VALUE"] );
251         
252         if (isset($share["TEXTBUTTONBORDER_TOP_IMAGE"][0]["VALUE"]))
253             $aParams["border_t_image"] = $oApp->findFile( $share["TEXTBUTTONBORDER_TOP_IMAGE"][0]["VALUE"] );
254
255         if (isset($share["TEXTBUTTONBORDER_TOPRIGHT_IMAGE"][0]["VALUE"]))
256             $aParams["border_tr_image"] = $oApp->findFile( $share["TEXTBUTTONBORDER_TOPRIGHT_IMAGE"][0]["VALUE"] );
257
258         if (isset($share["TEXTBUTTONBORDER_RIGHT_IMAGE"][0]["VALUE"]))
259             $aParams["border_r_image"] = $oApp->findFile( $share["TEXTBUTTONBORDER_RIGHT_IMAGE"][0]["VALUE"] );
260
261         if (isset($share["TEXTBUTTONBORDER_TOPLEFT_IMAGE"][0]["VALUE"]))
262             $aParams["border_br_image"] = $oApp->findFile( $share["TEXTBUTTONBORDER_BOTTOMRIGHT_IMAGE"][0]["VALUE"] );
263
264         if (isset($share["TEXTBUTTONBORDER_BOTTOM_IMAGE"][0]["VALUE"]))
265             $aParams["border_b_image"] = $oApp->findFile( $share["TEXTBUTTONBORDER_BOTTOM_IMAGE"][0]["VALUE"] );
266
267         if (isset($share["TEXTBUTTONBORDER_BOTTOMLEFT_IMAGE"][0]["VALUE"]))
268             $aParams["border_bl_image"] =$oApp->findFile$share["TEXTBUTTONBORDER_BOTTOMLEFT_IMAGE"][0]["VALUE"] );
269
270         if (isset($share["TEXTBUTTONBORDER_LEFT_IMAGE"][0]["VALUE"]))
271             $aParams["border_l_image"] = $oApp->findFile( $share["TEXTBUTTONBORDER_LEFT_IMAGE"][0]["VALUE"] );
272
273         if (isset($share["TEXTBUTTONNUDGE"][0]["VALUE"]))
274             $aParams["nudge"] = $share["TEXTBUTTONNUDGE"][0]["VALUE"];
275         
276         if (isset($share["TEXTBUTTONPADDING"][0]["VALUE"]))
277             $aParams["padding"] = $share["TEXTBUTTONPADDING"][0]["VALUE"];
278         
279         if (isset($share["LABELFONT"][0]["VALUE"]))
280             $aParams["labelfont"] = $oApp->findFile( $share["LABELFONT"][0]["VALUE"] );
281         
282         if (isset($share["LABELFONTSIZE"][0]["VALUE"]))
283             $aParams["labelsize"] = $share["LABELFONTSIZE"][0]["VALUE"];
284         
285         if (isset($share["LABELCOLOR"][0]["VALUE"]))
286             $aParams["labelcolor"] = $share["LABELCOLOR"][0]["VALUE"];
287         
288         if (isset($share["LABELALIGN"][0]["VALUE"]))
289             $aParams["labelalign"] = $share["LABELALIGN"][0]["VALUE"];
290         
291         if (isset($share["LABELANTIALIAS"][0]["VALUE"]))
292             $aParams["antialias"] = ($share["LABELANTIALIAS"][0]["VALUE"] == "true" )? true : false;
293             
294         if (isset($share["IMAGE"]))
295             $aParams["graphic"] = $oApp->findFile( $share["IMAGE"][0]['VALUE'] );
296             
297         if (isset($share["USETEXTBUTTONCACHE"][0]["VALUE"]))
298             $aParams['usecache'] = ($share["USETEXTBUTTONCACHE"][0]["VALUE"] == "true" )? true : false;
299         
300         return $aParams;
301     }
302 }
303 ?>
304
Note: See TracBrowser for help on using the browser.