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

root/Chameleon/trunk/Chameleon/SECTPopup/SECTPopup.widget.php

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

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * SECTPopup Widget Class
4  *
5  * @project     CWC2
6  * @revision    $Id: SECTPopup.widget.php,v 1.7 2005/05/26 14:28:10 jlacroix Exp $
7  * @purpose     Display the sect tool to classify a layer
8  * @author      DM Solutions Group (zjames dev@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 include_once(dirname(__FILE__)."/../Widget.php");
32 include_once(dirname(__FILE__)."/../Label.php");
33 include_once(dirname(__FILE__)."/../Button.php");
34 include_once(dirname(__FILE__)."/../Popup.php");
35
36 /**
37  * SECTPopup
38  *
39  * @desc Display the classification tool in a popup window.
40  */
41 class SECTPopup extends CWCWidget
42 {
43     var $moLabel;
44     var $moButton;
45     var $moPopup;
46
47     /**
48      * SECTPopup
49      *
50      * Constctor method for the SECTPopup
51      */
52     function SECTPopup()
53     {
54         parent::CWCWidget();
55
56         $this->moLabel = new CWCLabel( $this );
57
58         $this->moButton = new CWCButton( $this );
59
60         $this->moPopup = new CWCPopup( $this );
61        
62         //optional relative path to studio install
63         //defaults to use parallel install
64         $this->maAttributes["STUDIOPATH"] = new StringAttribute( "STUDIOPATH", false );
65         $this->maAttributes["STUDIOURL"] = new StringAttribute( "STUDIOURL", false );
66
67         // set the description for this widget
68         $this->szWidgetDescription = <<<EOT
69 The SECTPopupWidget displays the SECT tool that allows the user
70 to classify a layer selected by the LayerSelectionWidget
71 EOT;
72         $this->mnMaturityLevel = MATURITY_BETA;
73
74     }
75
76     function InitDefaults()
77     {
78         parent::InitDefaults();
79         //this widget should never belong to a toolset
80         $this->maParams["TOOLSET"] = "";
81         $this->moButton->InitDefaults();
82         $this->moButton->SetOnClick('Classify');
83         $this->mszStudioPath = $_SESSION["gszCorePath"]."../../studio";
84         if (isset($this->maParams["STUDIOPATH"]))
85         {
86            $this->mszStudioPath = $this->maParams["STUDIOPATH"];
87         }
88         $_SESSION['STUDIOPATH'] = $this->mszStudioPath;
89        
90         $this->mszStudioWebPath = "/studio/";
91         if (isset($this->maParams["STUDIOURL"]))
92         {
93            $this->mszStudioWebPath = $this->maParams["STUDIOURL"];
94         }
95         //use the application font file or sect's internal font file if
96         //there isn't one.
97         if (!($this->moMapObject->oMap->fontsetfilename == ''))
98         {
99             //figure out the actual font file path
100             $szFontFile = $this->moMapObject->oMap->fontsetfilename;
101             if (substr($szFontFile, 0, 1) != "/" && substr($szFontFile, 1, 1) != ":")
102             {
103                 if (substr($_SESSION['gszMapPath'], -1) != "/" &&
104                     substr($_SESSION['gszMapPath'], -1) != "\\")
105                 {
106                     $sep = "/";
107                 }
108                 else
109                 {
110                     $sep = "";
111                 }
112                 $szFontFile = realpath( $_SESSION['gszMapPath'].$sep.$szFontFile );
113             }
114             else
115             {
116                 $szFontFile = realpath( $szFontFile );
117             }
118            $_SESSION['gszFontFile'] = $szFontFile;
119         }
120         else
121         {
122            $_SESSION['gszFontFile'] = $this->mszStudioPath . '/etc/sectfonts.txt';
123            $this->moMapObject->oMap->setfontset($_SESSION['gszFontFile']);
124         }
125     }
126
127
128     function GetJavascriptInitFunctions()
129     {
130         return $this->moButton->GetJavascriptInitFunctions();
131     }
132
133     /**
134      * GetJavascriptFunctions
135      *
136      * Return the Javacriptfunctions needed by the widget.
137      *
138      * @return Javacriptfunctions needed by the widget.
139      */
140     function GetJavascriptFunctions()
141     {
142         if (isset($this->maSharedResourceWidgets["CWCJSAPI"]))
143           $bCWCJSAPI = 1;
144         else
145           $bCWCJSAPI = 0;
146
147         $aReturn = $this->moButton->GetJavascriptFunctions();//array();
148 //        $this->moPopup->mszLink = "widgets/SECTPopup.phtml";
149         $szButtonJS = $this->moPopup->DrawPublish();
150
151         $szStudioURL = $this->mszStudioWebPath;
152         $szSID = SID;
153        
154         //Launch SECT
155         $szJsFunctionName = "Classify";
156         $szFunction = <<<EOT
157 function {$szJsFunctionName}()
158 {
159      if ({$this->mszHTMLForm}.SELECTED_LAYERS == null ||
160          {$this->mszHTMLForm}.SELECTED_LAYERS.value == null ||
161          {$this->mszHTMLForm}.SELECTED_LAYERS.value == "" )
162      {
163          alert( "no layer selected!" );
164          return;
165      }
166    
167      var szTemplate = "&template=sect_classifier_template.html";
168      var szLayer = "&initlayername=" + {$this->mszHTMLForm}.SELECTED_LAYERS.value;
169      var szCallback = "&szCallback=SECTCallback";
170      var szURL = "{$szStudioURL}index.phtml?{$szSID}";
171      szURL = szURL + szTemplate + szLayer + szCallback;
172 //     alert( szURL );
173      wh = window.open(szURL, 'SECT', 'scrollbars=yes,resizable=yes,location=no,width=720,height=640');
174      wh.focus();
175 }
176
177 EOT;
178         $aReturn[$szJsFunctionName] = $szFunction;
179
180         //SECT callback
181         $szJsFunctionName = "SECTCallback";
182         $szFunction = <<<EOT
183 function {$szJsFunctionName}( actionId, wh )
184 {
185     if ( actionId == 0) //Clicked OK
186     {
187       wh.close();
188     }
189     else
190     if ( actionId == 1) // cancel
191     {
192       if (!wh.closed)
193           wh.close();
194     }
195     else if (actionId == 2) //apply
196     {
197       {$this->mszHTMLForm}.SLD_TABLE_COMMAND.value = 'RETURN';
198       {$this->mszHTMLForm}.submit();
199     }
200     return;
201 }
202 EOT;
203         $aReturn[$szJsFunctionName] = $szFunction;
204
205         return $aReturn;
206     }
207
208     function GetJavascriptVariables()
209     {
210         return $this->moButton->GetJavascriptVariables();
211     }
212
213     function GetJavascriptOnLoadFunctions()
214     {
215         return $this->moButton->GetJavascriptOnLoadFunctions();
216     }
217
218     function GetJavascriptIncludeFunctions()
219     {
220         return $this->moButton->GetJavascriptIncludeFunctions();
221     }
222
223     /**
224      * GetHTMLHiddenVariables
225      *
226      * return the NAV_CMD varaiable.
227      */
228     function GetHTMLHiddenVariables()
229     {
230         $aReturn = $this->moButton->GetHTMLHiddenVariables();
231
232         $szVariable = 'SLD_TABLE_COMMAND';
233         $aReturn[$szVariable] = '<INPUT TYPE="HIDDEN" NAME="'.$szVariable. '" VALUE="">';
234
235         return $aReturn;
236     }
237
238     /**
239      * return the current layer to the mapsession
240      */
241     function ReturnLayer()
242     {
243         $oSrcLayer = $this->moSLDSession->oMap->getLayer( 0 );
244         if ($oSrcLayer == null)
245         {
246             echo "ERROR: source layer not set in ReturnLayer<BR>";
247             return false;
248         }
249
250         $oDstLayer = $this->moMapObject->oMap->getLayerByName( $this->getVar( 'SELECTED_LAYERS' ) );
251         if ($oDstLayer == null)
252         {
253             echo "ERROR: destination layer not set in ReturnLayer<BR>";
254             return false;
255         }
256        
257         //remove existing classes
258         for( $i=0; $i<$oDstLayer->numclasses; $i++)
259         {
260             $oClass = $oDstLayer->getClass( $i );
261             $oClass->set( "status",  MS_DELETE );
262         }
263        
264         //copy over classes from the local mapsession layer
265         for ($i=0; $i<$oSrcLayer->numclasses; $i++)
266         {
267             $oSrcClass = $oSrcLayer->getClass( $i );
268             $oDstClass = ms_newClassObj( $oDstLayer, $oSrcClass );
269         }
270        
271         //copy classitem, labelitem, layer type
272
273         if ((strlen($oSrcLayer->classitem) > 0) &&
274             ($oSrcLayer->classitem != "")&&
275             ($oSrcLayer->classitem != NULL))
276         {
277             $oDstLayer->set( 'classitem', $oSrcLayer->classitem );
278         }
279         else
280         {
281             $oDstLayer->set( 'classitem', NULL );
282         }
283         if ((strlen($oSrcLayer->labelitem) > 0) &&
284             ($oSrcLayer->labelitem != "") &&
285             ($oSrcLayer->labelitem != NULL))
286         {
287             $oDstLayer->set( 'labelitem', $oSrcLayer->labelitem );
288         }
289         else
290         {
291             $oDstLayer->set( 'labelitem', NULL );
292         }
293         $oDstLayer->set( 'type', $oSrcLayer->type );
294         $oDstLayer->setMetaData( 'wms_sld_body', 'auto' );
295
296         $this->moMapObject->saveState();       
297 //        $this->mbUpdateOpener = true;
298 //        $this->mbDirty = false;
299        
300         return true;
301     }
302     /**
303      * ParseURL
304      *
305      * Look for the COMPASS_POINT command and if found, recenter
306      * the image in the appropriate direction.
307      * according to the other NAV paramaters.
308      */
309     function  ParseURL()
310     {
311         if ($this->isVarSet( 'SLD_TABLE_COMMAND' ))
312         {
313             if ($this->getVar( 'SLD_TABLE_COMMAND' ) == 'RETURN')
314             {
315                 $this->mszSLDMapFile = getSessionSavePath()."/SLDCache".$this->mnId.".map";
316                    
317                 $oMap = ms_newMapObj( "" );
318                 $oMap->set( 'width', 1 );
319                 $oMap->set( 'height', 1 );
320                 $oMap->extent->setextent( -1, -1, 1, 1 );
321                 //this shouldn't be needed, assefa to fix a bug related to this
322                 //$oMap->setsymbolset( realpath($GLOBALS['gszAppPath']."/../etc/sectsym.sym"));
323                 $this->moSLDSession = new MapSession_RW();
324                 $this->moSLDSession->szMapFile = $this->mszSLDMapFile;
325                 $this->moSLDSession->szTempDir = getSessionSavePath();
326                 $this->moSLDSession->oMap = $oMap;
327                
328                 if (isset($_SESSION['SLDCACHESTATE']) && $_SESSION['SLDCACHESTATE'] != "" )
329                 {
330                     $this->moSLDSession->restoreState( $_SESSION['SLDCACHESTATE'], $this->mszSLDMapFile );
331                 }
332
333                 $this->ReturnLayer();
334             }
335         }
336        
337         // return success
338         return true;
339     }
340
341
342     /**
343      * DrawPublish
344      *
345      * Return the HTML code using the name in the map file and the
346      * parameters of the CWC tag.
347      */
348     function DrawPublish()
349     {
350         if (!$this->mbVisible)
351             return "<!-- SECT popup widget hidden -->";
352
353         $szResult = $this->moButton->DrawPublish();
354
355         return $szResult;
356     }
357 }
358 ?>
Note: See TracBrowser for help on using the browser.