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

root/Chameleon/trunk/Chameleon/DDSGUI/DDSGUI.widget.php

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

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * DDSGUI Widget class
4  *
5  * @project     CWC2
6  * @revision    $Id: DDSGUI.widget.php,v 1.8 2004/10/14 18:19:09 pspencer Exp $
7  * @purpose     DDSGUI Popup Widget class
8  * @author      DM Solutions Group (jlacroix@dmsolutions.ca)
9  * @copyright
10  * <b>Copyright (c) 2004, 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 include_once(dirname(__FILE__)."/../Widget.php");
31 include_once(dirname(__FILE__)."/../Label.php");
32 include_once(dirname(__FILE__)."/../Button.php");
33 include_once(dirname(__FILE__)."/../Popup.php");
34
35 /**
36  * DDSGUI
37  *
38  * DDSGUI widget class
39  */
40 class DDSGUI extends CWCWidget
41 {
42     var $szDDSGUIURL = "";
43     var $moLabel;
44     var $moButton;
45     var $moPopup;
46
47     /**
48      * DDSGUI
49      *
50      * Constctor method for the DDSGUI widget.
51      */
52     function DDSGUI()
53     {
54         $this->mszLanguageResource = str_replace("\\","/",dirname(__FILE__))."/DDSGUI.dbf";
55
56         // invoke constructor of parent
57         parent::CWCWidget();
58
59         $this->moLabel = new CWCLabel( $this );
60         $this->moButton = new CWCButton( $this );
61         $this->moPopup = new CWCPopup( $this );
62         $this->moPopup->mszLink = $_SESSION['gszCoreWebPath']."/widgets/DDSGUI/DDSGUI.phtml";
63
64         // set the description for this widget
65         $this->szWidgetDescription = <<<EOT
66 The DDSGUI widget is is used to get the GUI popup of a MainDDS server. It is
67 used in conjonction with the ExtractWFSData widget. Note that the
68 OriginServerURI and OriginServerField are taken from the layer metadatas. The
69 two needed metadatas are called dds_originserveruri and dds_originserverfield.
70 EOT;
71
72         $this->maAttributes["DDSGUIURL"] = new StringAttribute( "DDSGUIURL",
73                                                                  true );
74         $this->mnMaturityLevel = MATURITY_BETA;
75     }
76
77     function InitDefaults()
78     {
79         parent::InitDefaults();
80         //this widget should never belong to a toolset
81         $this->maParams["TOOLSET"] = "";
82         if(isset($this->maParams["DDSGUIURL"]))
83             $this->szDDSGUIURL = $this->maParams["DDSGUIURL"];
84
85         $this->moButton->InitDefaults();
86         $this->moButton->SetOnClick('clickDDSGUI');
87     }
88
89     function GetJavascriptInitFunctions()
90     {
91         return $this->moButton->GetJavascriptInitFunctions();
92     }
93
94     function GetJavascriptVariables()
95     {
96         return $this->moButton->GetJavascriptVariables();
97     }
98
99     function GetJavascriptOnLoadFunctions()
100     {
101         return $this->moButton->GetJavascriptOnLoadFunctions();
102     }
103
104     function GetJavascriptIncludeFunctions()
105     {
106         return $this->moButton->GetJavascriptIncludeFunctions();
107     }
108
109     /**
110      * GetHTMLHiddenVariables
111      */
112     function GetHTMLHiddenVariables()
113     {
114         // initialize return array
115         $aReturn = $this->moButton->GetHTMLHiddenVariables();
116
117         // setup the variables
118         $szVariable = 'REQUEST_BODY';
119         $szValue = "<INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"\">\n";
120         $aReturn[$szVariable] = $szValue;
121        
122         // return array of hidden variables   
123         return $aReturn;
124     }
125
126     /**
127      * GetJavascriptFunctions
128      *
129      * Build and return the array of functions needed in the
130      * widget.
131      */
132     function GetJavascriptFunctions()
133     {
134         if (!isset($this->maSharedResourceWidgets['expressionbuilderresults']->maszContents['RESULT']) ||
135             $this->maSharedResourceWidgets['expressionbuilderresults']->maszContents['RESULT'] == "")
136         {
137             // Error notice
138             $szError = $this->moMLT->get("1","The DDSGUI can only be used in ".
139                                   "conjonction with the expression builder. ".
140                                   "Please build an expression before using ".
141                                   "this button." );
142             $szJsFunctionName = "clickDDSGUI";
143             $szFunction = <<<EOT
144 /**
145  * {$szJsFunctionName}
146  * call the DDSGUI popup
147  */
148 function {$szJsFunctionName}()
149 {
150     alert('{$szError}');
151     return;
152 }
153 EOT;
154         }
155         else
156         {
157             // Set the request to the ddsgui
158             $szRequest = "";
159
160             $szLayerName = array_keys($this->maSharedResourceWidgets['expressionbuilderresults']->maszContents['RESULT']);
161             $szLayerName = $szLayerName[0];
162             $oLayer = $this->moMapObject->oMap->getLayerByName($szLayerName);
163             $szServerURI = $oLayer->getMetadata("dds_originserveruri");
164             $szServerField = $oLayer->getMetadata("dds_originserverfield");
165
166             $szGeolinkIds = "";
167             foreach($this->maSharedResourceWidgets['expressionbuilderresults']->maszContents['RESULT'][$szLayerName] as $aszRecord)
168             {
169               foreach($aszRecord as $aszAttribute)
170               {
171                 if($aszAttribute["attribute"] == $szServerField)
172                 {
173                     $szGeolinkIds .= "<I>".$aszAttribute["value"]."</I>";
174                     break;
175                 }
176               }
177             }
178
179             if (!isset($_SESSION['gszCurrentLanguage']))
180                 $lang = "en-CA";
181             else
182                 $lang = $_SESSION['gszCurrentLanguage'];
183
184             // Build the XML request
185             $szRequest = "<?xml version='1.0' ?><DDSGUIRequest version='0.9.0' lang='$lang'>   <OriginServerURI>$szServerURI</OriginServerURI>   <OriginServerField>$szServerField</OriginServerField>   <GeolinkIds>$szGeolinkIds</GeolinkIds> </DDSGUIRequest>";
186
187             $aReturn = $this->moButton->GetJavascriptFunctions();//array();
188             $szJsFunctionName = "clickDDSGUI";
189             $szButtonJS = $this->moPopup->DrawPublish();
190             $szPopupName = $this->moPopup->GetPopupName();
191             $szPopupOption = $this->moPopup->GetPopupOptions();
192
193             $szFunction = <<<EOT
194 /**
195  * {$szJsFunctionName}
196  * popup a extract wfs data dialog
197  */
198 function {$szJsFunctionName}()
199 {
200     var wh = window.open('', '{$szPopupName}', '{$szPopupOption}');
201
202     var szMethod;
203     szMethod = {$this->mszHTMLForm}.method;
204     {$this->mszHTMLForm}.method = 'POST';
205     {$this->mszHTMLForm}.action = '{$this->szDDSGUIURL}';
206     {$this->mszHTMLForm}.target = '{$szPopupName}';
207
208     // Set the request to the ddsgui
209     {$this->mszHTMLForm}.REQUEST_BODY.value = "$szRequest";
210
211     {$this->mszHTMLForm}.submit();
212
213     wh.focus();
214
215     {$this->mszHTMLForm}.method = szMethod;
216     {$this->mszHTMLForm}.action = '';
217     {$this->mszHTMLForm}.target = '';
218
219     return;
220 }
221 EOT;
222         }
223
224         $aReturn[$szJsFunctionName] = $szFunction;
225        
226         return $aReturn;
227     }
228
229
230     /**
231      * DrawPublish
232      *
233      * Return the HTML code to display the DDSGUI widget
234      */
235     function DrawPublish()
236     {
237         if (!$this->mbVisible)
238             return "<!-- DDSGUI widget hidden -->";
239
240         $szResult = $this->moButton->DrawPublish();
241         $szResult = $this->moLabel->DrawPublish( $szResult );
242         return $szResult;
243     }
244 }
245 ?>
Note: See TracBrowser for help on using the browser.