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

root/Chameleon/trunk/Chameleon/XMLThemeLegend/XMLThemeLegend.widget.php

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

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * XML Theme Legend
4  *
5  * @project     CWC2
6  * @revision    $Id: XMLThemeLegend.widget.php,v 1.9 2004/12/03 03:31:57 pspencer Exp $
7  * @purpose     Create legends with themes from an xml template
8  * @author      DM Solutions Group (spencer@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("XMLThemeParser.php");
30 include_once(dirname(__FILE__)."/../Widget.php");
31 include_once(dirname(__FILE__)."/../Popup.php");
32
33 if (!defined("CHAMELEON_PATH"))
34 {
35     define( "CHAMELEON_PATH", realpath(str_replace("\\","/",dirname(__FILE__))."/..") );
36 }
37 include_once( CHAMELEON_PATH."/TemplateProcessor.php" );
38
39
40 class XMLThemeLegend extends CWCWidget
41 {
42     var $moPopup = "";
43     var $mszContextFile= "";
44     var $mszThemeFile= "";
45     var $mszRendererFile = "";
46     var $moThemeParser = "";
47     var $moTemplateProcessor = "";
48     var $maSelections = array();
49     var $mszInputBase = "CWC2_CS";
50
51     function XMLThemeLegend()
52     {
53         $this->mszLanguageResource = str_replace("\\","/",dirname(__FILE__))."/XMLThemeLegend.dbf";
54
55         // invoke constructor of parent
56         parent::CWCWidget();
57
58         $this->moTemplateProcessor = new TemplateProcessor();
59
60         // set the description for this widget
61         $this->szWidgetDescription = <<<EOT
62 The XMLThemeLegend widget provides generic legend control capabilities
63 for Chameleon applications.  The widget is controlled by a template file and a theme
64 file that describe how layers in the current context should be presented to the
65 user.
66 EOT;
67
68         $this->moPopup = new CWCPopup( $this );
69         $this->mnPriority =  PRIORITY_MEDIUM;
70         $this->mnMaturityLevel = MATURITY_BETA;
71     }
72
73     /**
74      * per-widget initialization to initialize default values from
75      * attributes etc.
76      */
77     function InitDefaults()
78     {
79         parent::InitDefaults();
80         $oApp = GetChameleonApplication();
81        
82         //$this->mszContextFile = $this->GetCurrentContext();
83         //process selections from tag.
84         if (isset($this->maszContents["SELECTION"]))
85         {
86             for($i=0; $i<count($this->maszContents["SELECTION"]); $i++)
87             {
88                 $aSel = $this->maszContents["SELECTION"][$i];
89                 $aNewSel = array();
90
91                 $aNewSel["selection_selected"] = "1";
92                 $aNewSel["selection_name"] = $aSel["NAME"];
93                 $aNewSel["selection_contextfile"] = $aSel["CONTEXTFILE"];
94                 $aNewSel["selection_templatefile"] = $aSel["TEMPLATE"];
95                 $aNewSel["selection_rendererfile"] = $aSel["RENDERERFILE"];
96                 $aNewSel["selection_themefile"] = $aSel["THEMEFILE"];
97                 $aNewSel["selection_url"] = "javascript:ContextSelected( '".$aSel["TEMPLATE"]."', '".$aSel["CONTEXTFILE"]."')";
98                 $szFile = $aNewSel['selection_rendererfile'];
99                 if (!(substr($szFile, 0, 1) == "/" ||
100                       substr($szFile, 0, 1) == "\\" ||
101                       substr($szFile, 1, 1) == ":" ||
102                       strcasecmp(substr($szFile, 0, 4), "http") == 0))
103                 {
104                     $szFile = realpath( $_SESSION['gszAppPath']."/".$szFile );
105                 }
106                 $this->mszRendererFile = $oApp->getRemoteFile($szFile);
107                 $this->mszThemeFile = $oApp->getRemoteFile($aNewSel["selection_themefile"]);
108                 array_push( $this->maSelections, $aNewSel );
109             }
110         }
111         //print_r($this->maSelections);
112         $this->moPopup->InitDefaults();
113
114     }
115
116     /**
117      * GetJavascriptVariables
118      *
119      * Return JS global variables and global code.
120      */
121     function GetJavascriptVariables()
122     {
123
124         $aReturn = array();
125         if (!is_object( $this->moThemeParser ))
126         {
127             $aReturn["gContextSelectorManager"] = "";
128             return $aReturn;
129         }
130
131         $nThemes = $this->moThemeParser->GetNumberOfThemes();
132         $szVariable = "gContextSelectorManager";
133         $szValue = " var $szVariable = \"0\";\n";
134         $aReturn[$szVariable] = $szValue;
135
136         return $aReturn;
137     }
138
139     /**
140      * GetJavascriptOnloadFunctions()
141      */
142     function GetJavascriptOnLoadFunctions()
143     {
144         $aReturn = array();
145
146         $szJsName = "ContextSelector_initialize";
147         $szJs = "ContextSelector_initialize();";
148         $aReturn[$szJsName] = $szJs;
149
150         return $aReturn;
151     }
152
153
154     /**
155      * GetJavascriptIncludeFunctions
156      *
157      *
158      */
159     function GetJavascriptIncludeFunctions()
160     {
161         $aReturn = array();
162
163         $szJsIncludeName = $_SESSION['gszCoreWebPath'] ."/widgets/js/cwc_cs.js";
164         $szInclude = "<script language=\"JavaScript\" src=\"$szJsIncludeName\" type=\"text/javascript\"></script>";
165         $aReturn[$szJsIncludeName] = $szInclude;
166
167         return $aReturn;
168     }
169
170
171     /**
172      * GetHTMLHiddenVariables
173      *
174      */
175     function GetHTMLHiddenVariables()
176     {
177 /* -------------------------------------------------------------------- */
178 /*       CONTEXTSELECTOR is used to see if it is the first       */
179 /*       time that the page loads so we don't setlayer on/off.          */
180 /* -------------------------------------------------------------------- */
181
182         $szVariable = "CONTEXTSELECTOR";
183         $szValue = "<INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"1\">";
184         $aReturn[$szVariable] = $szValue;
185
186         $szVariable = "CONTEXT";
187         $szValue = "<INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"\">";
188         $aReturn[$szVariable] = $szValue;
189
190         $szVariable = "TEMPLATE";
191         $szValue = "<INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"\">";
192         $aReturn[$szVariable] = $szValue;
193
194         $szVariable = "CONTEXTSELECTOR_CONTEXT_CHANGED";
195         $szValue = "<INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"\">";
196         $aReturn[$szVariable] = $szValue;
197
198         $szLayersOn = "";
199         $szAllLayers = "";
200
201         $oMap = $this->moMapObject->oMap;
202         $nLayers = $oMap->numlayers;
203         $szSep0 = "";
204         $szSep1 = "";
205
206         for ($i=0; $i<$nLayers; $i++)
207         {
208             $oLayer = $oMap->getLayer($i);
209
210             //get name from wms metadata or mapfile tags
211             $szName = $oLayer->getMetadata("WMS_NAME");
212
213             //handle non-wms layers
214             if ($szName == "")
215             {
216                 $szName = $oLayer->name;
217             }
218
219
220             if (isset($this->moThemeParser->maLayers[$szName]) ||
221                 ($this->moThemeParser->maGlobals["gThemeExtendContext"] == "true") )
222             {
223                 if ($oLayer->status == MS_ON)
224                 {
225                     $szLayersOn .= $szSep1 . $szName;
226                     $szSep1 = "|";
227                 }
228                 $szAllLayers .= $szSep0 . $szName;
229                 $szSep0 = "|";
230             }
231         }
232
233         //used to contain the name of the layers set to on
234         $szVariable = "CONTEXTSELECTOR_LAYERS_ON";
235         $szValue = "<INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"$szLayersOn\">";
236         $aReturn[$szVariable] = $szValue;
237
238         //used to contain the name of the layers set to on
239         $szVariable = "CONTEXTSELECTOR_ALL_LAYERS";
240         $szValue = "<INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"$szAllLayers\">";
241         $aReturn[$szVariable] = $szValue;
242
243        //used to test if the template has changed
244         $szVariable = "CONTEXTSELECTOR_TEMPLATE";
245         $szTemplate = "";
246         if (isset($_SESSION["gszTemplate"]))
247             $szTemplate = $_SESSION["gszTemplate"];
248         $szValue = "<INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"$szTemplate\">";
249         $aReturn[$szVariable] = $szValue;
250
251
252         $aReturn[$szVariable] = $szValue;
253
254         return $aReturn;
255     }
256
257
258     /**
259      * GetJavascriptFunctions
260      *
261      */
262     function GetJavascriptFunctions()
263     {
264         $aReturn = array();
265         $oMap = $this->moMapObject->oMap;
266
267         $aszContextLayers = array();
268         for ($i=0; $i<$oMap->numlayers; $i++)
269         {
270             $oLayer = $oMap->GetLayer( $i );
271            
272             //set name based on WMS_NAME or mapfile name
273             $szName = $oLayer->getmetadata("WMS_NAME");
274             if ($szName == "")
275             {
276                 $szName = $oLayer->name;
277             }
278             $aszContextLayers[$szName] = ($oLayer->status == MS_ON) ? true : false;
279         }
280
281         $szInit = "    gContextSelectorManager = new CWC2_CS_Manager();\n";
282         $szInit .= "    gContextSelectorManager.form = ".$this->mszHTMLForm.";\n";
283
284         if (is_array($this->moThemeParser->maThemes) &&
285             count($this->moThemeParser->maThemes) > 0)
286         {
287             foreach($this->moThemeParser->maThemes as $szThemeName => $aGroups)
288             {
289                 $szInit .= "    oTheme = new CWC2_CS_Theme( \"".$szThemeName."\" );\n";
290                 $szInit .= "    gContextSelectorManager.AddTheme( oTheme );\n";
291
292                 $szType = $this->moThemeParser->GetThemeAttribute( $szThemeName, "theme_type" );
293
294                 $szInit .= "    oTheme.SetType( \"".$szType."\" );\n";
295
296                 $bThemeOn = ($szType == "checkbox");
297                 foreach ($aGroups as $szGroupName => $aLayersInGroup)
298                 {
299                     $szInit .= "    oGroup = new CWC2_CS_Group( \"".$szGroupName."\" );\n";
300                     if ($this->moThemeParser->GetGroupAttribute( $szThemeName, $szGroupName, "group_visible" ) == "false")
301                     {
302                         $szInit .= "    oGroup.SetVisible( false );\n";
303                     }
304                     $szInit .= "    oTheme.AddGroup( oGroup );\n";
305                     $bOn = false;
306                     $nGroupLayers = 0;
307                     foreach( $aLayersInGroup as $szLayerName )
308                     {
309                         if (array_key_exists( $szLayerName, $aszContextLayers ))
310                         {
311                             ++$nGroupLayers;
312
313                             $szInit .= "    oGroup.AddLayer( new CWC2_CS_Layer( \"".$szLayerName."\" ) );\n";
314                             $bOn |= $aszContextLayers[$szLayerName];
315                         }
316                     }
317
318                     if ($szType == "checkbox" && $nGroupLayers > 0)
319                         $bThemeOn &= $bOn;
320                     else
321                         $bThemeOn |= $bOn;
322
323                     if ($bOn && $nGroupLayers > 0)
324                         $szInit .= "    oGroup.SetStatus( true );\n";
325                     if ($nGroupLayers == 0)
326                         $szInit .= "    oGroup.SetVisible( false );\n";
327                 }
328                 if ($bThemeOn)
329                     $szInit .= "    oTheme.SetStatus( true );\n";
330
331             }
332         }
333
334         //process the layers in the map file and see if they are all supported
335         for ($i=0; $i<$oMap->numlayers; $i++)
336         {
337             $oLayer = $oMap->GetLayer( $i );
338
339             //get name from wms metadata or mapfile tags
340             $szLayer = $oLayer->getMetaData( "WMS_NAME" );
341             //handle non-wms layers
342             if ($szLayer == "")
343             {
344                 $szLayer = $oLayer->name;
345             }
346
347             if (!array_key_exists( $szLayer, $this->moThemeParser->maLayers ) )
348             {
349                 if ($this->moThemeParser->maGlobals["gThemeExtendContext"] == "true")
350                 {
351                     $szInit .= "    oTheme = new CWC2_CS_Theme( \"".$szLayer."\" );\n";
352                     $szInit .= "    gContextSelectorManager.AddTheme( oTheme );\n";
353                     //$szInit .= "    oTheme.SetType( 'checkbox' );\n";
354                     $szInit .= "    oTheme.SetType( \"".$szType."\" );\n";
355                     $szInit .= "    oGroup = new CWC2_CS_Group( \"".$szLayer."\" );\n";
356                     $szInit .= "    oTheme.AddGroup( oGroup );\n";
357                     $szInit .= "    oGroup.SetVisible( false );\n";
358                     $szInit .= "    oGroup.SetStatus( true );\n";
359                     $szInit .= "    oGroup.AddLayer( new CWC2_CS_Layer( \"".$szLayer."\" ) );\n";
360                     if ($oLayer->status == MS_ON)
361                         $szInit .= "    oTheme.SetStatus( true );\n";
362
363                 }
364             }
365         }
366
367         $szInit .= "    gContextSelectorManager.UpdateStatus();\n";
368
369         $szJsFunctionName = "ContextSelector_initialize";
370         $szFunction = <<<EOT
371 /**
372  * {$szJsFunctionName}
373  * called during OnLoad event to initialize the Context Selector manager
374  */
375 function {$szJsFunctionName}()
376 {
377 {$szInit}
378 }
379 EOT;
380        $aReturn[$szJsFunctionName] = $szFunction;
381
382        $this->moPopup->mszLink = $_SESSION['gszCoreWebPath']."/widgets/XMLThemeLegend/XMLThemeLegendInfo.phtml";
383        $this->moPopup->mszParam = "&groups='+groupName+'&groups_abstracts='+groupAbstract+'&groups_layers='+szGroupLayers+'";
384        $szPopupURL = $this->moPopup->DrawPublish();
385        $szJsFunctionName = "ContextSelector_openGroupInfo";
386        $sCommon = COMMON;
387        $sWebPath = $_SESSION['gszCoreWebPath'];
388        $sSID = SID;
389        $szFunction = <<<EOT
390 /**
391 * {$szJsFunctionName}
392 * called when a Group is clicked in the ContextSelector widget
393 */
394 function {$szJsFunctionName}(groupName, groupAbstract, groupLayers)
395 {
396     var i;
397     //calculate the URL options
398     szGroupLayers = "";
399     szSep = "";
400     for (i=0; i<groupLayers.length; i++)
401     {
402         szGroupLayers += szSep + groupLayers[i];
403         szSep = ";";
404     }
405     {$szPopupURL}
406 }
407
408 EOT;
409         $aReturn[$szJsFunctionName] = $szFunction;
410
411
412        $this->moPopup->mszLink = $_SESSION['gszCoreWebPath']."/widgets/XMLThemeLegend/XMLThemeLegendInfo.phtml";
413        $this->moPopup->mszParam = "&theme='+themeName+'&theme_abstract='+themeAbstract+'&groups='+szGroups+'&groups_abstracts='+groupAbstract+'&groups_layers='+szGroupLayers+'";
414        $szJsFunctionName = "ContextSelector_openThemeInfo";
415        $sCommon = COMMON;
416        $sWebPath = $_SESSION['gszCoreWebPath'];
417        $sSID = SID;
418        $szFunction = <<<EOT
419 /**
420 * {$szJsFunctionName}
421 * called when a Theme is clicked in the ContextSelector widget
422 */
423 function {$szJsFunctionName}(themeName, themeAbstract, themeGroups)
424 {
425     var i, j;
426    
427     //calculate the URL options
428
429     var szThemeLayers = "";
430     var szThemeSep = "";
431     var szGroups = "";
432     var szGroupAbstracts = "";
433     for (i=0; i<themeGroups.length; i++)
434     {
435         var szGroupLayers = "";
436         var szGroupSep = "";
437         var group = themeGroups[i];
438         szGroups += szThemeSep + group[0];
439         szGroupAbstracts += szThemeSep + group[1];
440         groupLayers = group[2];
441         for (j=0; j<groupLayers.length; j++)
442         {
443             szGroupLayers += szGroupSep + groupLayers[j];
444             szGroupSep = ";";
445         }
446
447         szThemeLayers += szThemeSep + szGroupLayers;
448         szThemeSep = "|";
449     }
450     {$szPopupURL}
451 }
452
453 EOT;
454         $aReturn[$szJsFunctionName] = $szFunction;
455
456         $szJsFunctionName = "ContextSelector_SetThemeStatus";
457         $szFunction = <<<EOT
458 /*
459  * {$szJsFunctionName}
460  */
461 function {$szJsFunctionName}( nTheme, bStatus )
462 {
463     //alert( "set theme status for theme " + nTheme + " to " + bStatus );
464     gContextSelectorManager.SetThemeStatus( nTheme, bStatus );
465     {$this->mszHTMLForm}.CONTEXTSELECTOR_LAYERS_ON.value = gContextSelectorManager.GetVisibleLayerNames();
466 }
467 EOT;
468
469         $aReturn[$szJsFunctionName] = $szFunction;
470
471         $szJsFunctionName = "ContextSelector_SetGroupStatus";
472         $szFunction = <<<EOT
473 /*
474  * {$szJsFunctionName}
475  */
476 function {$szJsFunctionName}( nTheme, nGroup, bStatus )
477 {
478     //alert( "set group status for theme " + nTheme + ", group " + nGroup + " to " + bStatus );
479     gContextSelectorManager.SetGroupStatus( nTheme, nGroup, bStatus );
480     {$this->mszHTMLForm}.CONTEXTSELECTOR_LAYERS_ON.value = gContextSelectorManager.GetVisibleLayerNames();
481 }
482 EOT;
483
484         $aReturn[$szJsFunctionName] = $szFunction;
485
486         $szJsFunctionName = "ContextSelected";
487         $szFunction = <<<EOT
488 /**
489 * {$szJsFunctionName}
490 * called when a conext is selected in ContextSelector widget
491 */
492 function {$szJsFunctionName}(szTemplate, szContext)
493 {
494         {$this->mszHTMLForm}.CONTEXT.value = szContext;
495         {$this->mszHTMLForm}.TEMPLATE.value = szTemplate;
496         {$this->mszHTMLForm}.CONTEXTSELECTOR_CONTEXT_CHANGED.value = "1";
497         {$this->mszHTMLForm}.submit();
498 }
499 EOT;
500        $aReturn[$szJsFunctionName] = $szFunction;
501
502
503         return $aReturn;
504     }
505
506
507
508     /**
509      * ParseURL
510      *
511      * Loop trough all layers and set them to on/off if found in
512      * the URL.
513      */
514     function  ParseURL()
515     {
516        
517         if ( $this->isVarSet( "THEMEFILE" ) )
518             $this->mszThemeFile = $this->getVar( "THEMEFILE" );
519
520         $this->moThemeParser =  new ThemeParser($this->mszThemeFile);
521
522         //handle unthemed layers
523         //this is part of widget initialization but is done here because it needs
524         //the map object.
525         $this->moThemeParser->ProcessExtraLayers($this->moMapObject->oMap);
526
527         if ($this->isVarSet( "CONTEXTSELECTOR" ))
528         {
529             $szAllLayers = $this->getVar( "CONTEXTSELECTOR_ALL_LAYERS" );
530             $aszAllLayers = explode("|", $szAllLayers);
531             $szLayersOn = $this->getVar( "CONTEXTSELECTOR_LAYERS_ON" );
532             $aszLayersOn = explode("|", $szLayersOn);
533             $oMap = $this->moMapObject->oMap;
534             $nLayers = $oMap->numlayers;
535             for ($i=0; $i<$nLayers; $i++)
536             {
537                 $oLayer = $oMap->getLayer($i);
538
539                 $szName = $oLayer->getMetadata("WMS_NAME");
540                 if ($szName == "")
541                 {
542                     $szName = $oLayer->name;
543                 }
544                 if (in_array($szName, $aszAllLayers))
545                 {
546                     if (in_array( $szName, $aszLayersOn ))
547                     {
548                         $oLayer->set("status", MS_ON);
549                     }
550                     else
551                     {
552                         $oLayer->set("status", MS_OFF);
553                     }
554                 }
555             }
556         }
557     }
558
559     /**
560      * CheckThemeOn
561      *
562      * Utility function to set on/off theme checkbox.
563      */
564     function CheckThemeOn($szThemeName)
565     {
566         $oMap = $this->moMapObject->oMap;
567         $aszGroups = $this->moThemeParser->GetGroups($szThemeName);
568         $szType = $this->moThemeParser->GetThemeAttribute( $szThemeName, "theme_type" );
569         $bOn = ($szType == "checkbox");
570         foreach( $aszGroups as $aszLayers )
571         {
572             foreach( $aszLayers as $szLayerName )
573             {
574                 $oLayer = $this->GetLayerByName($szLayerName);
575                 if ($oLayer->status == MS_OFF && $szType == "checkbox")
576                 {
577                     return false;
578                 }
579                 else if ($oLayer->status == MS_ON && $szType == "radio")
580                 {
581                     return true;
582                 }
583            }
584         }
585
586         return $bOn;
587     }
588
589     /**
590      * GetLayerByName
591      *
592      * Return a layer if it's wms_name or layer name corresponds to the
593      * szTestName passed as argument
594      */
595     function GetLayerByName( $szTestName )
596     {
597         $poMap = $this->moMapObject->oMap;
598         for ($i=0;$i<$poMap->numlayers;$i++)
599         {
600             $oLayer = $poMap->getLayer( $i );
601            
602             $szName = $oLayer->getmetadata( "WMS_NAME" );
603             //handle non-wms layers
604             if ($szName == "")
605             {
606                 $szName = $oLayer->name;
607             }
608            
609             if (strcasecmp(trim($szName), $szTestName) == 0)
610             {
611                 return $oLayer;
612             }
613         }
614         return false;
615     }
616
617     /**
618      * return the status of a group of layers.  Assume that if any one
619      * layer is 'on' then they are all on
620      */
621     function CheckGroupOn( $szThemeName, $szGroupName )
622     {
623         $aszLayers = $this->moThemeParser->maThemes[$szThemeName][$szGroupName];
624         foreach( $aszLayers as $layer )
625         {
626             $oLayer = $this->GetLayerByName($layer);
627             if ($oLayer->status == MS_ON || $oLayer->status == MS_DEFAULT)
628             {
629                 return true;
630             }
631         }
632         return false;
633     }
634
635     /**
636      * GetCurrentContext
637      *
638      * Get the current context used.
639      */
640     function GetCurrentContext()
641     {
642         $szContext= trim(basename($_SESSION["gszCurrentContext"]));
643
644         return $szContext;
645     }
646
647     /**
648      * DrawPublish
649      *
650      * Build layerconrol corresponding to the context and the theme
651      * file associated.
652      * The CWC tag looks like :
653      * <cwc2 type="contextselector">
654      *  <selection contextfile="path-to-context"
655      *  themefile="path-to-theme" default="[true|false]"/>
656      *  <selection .... />
657      * </cwc>
658      */
659     function DrawPublish()
660     {
661         $oMap = $this->moMapObject->oMap;
662
663         $szHTML="";
664
665         $aVals = $this->moThemeParser->maVals;
666
667         $aExtraLayers = array();
668         $aActiveLayers = array();
669
670         //pre-process the layers in the map file and see if they are all supported
671         for ($i=0; $i<$oMap->numlayers; $i++)
672         {
673             $oLayer = $oMap->GetLayer( $i );
674            
675             //removed wms layer check.
676             $szLayer = $oLayer->getMetaData( "WMS_NAME" );
677
678             //handle non-wms layers
679             if ($szLayer == "")
680             {
681                 $szLayer = $oLayer->name;
682             }
683
684             if (array_key_exists( $szLayer, $this->moThemeParser->maLayers ) )
685             {
686                 $aActiveLayers[$szLayer] =
687                         ($oLayer->status == MS_ON) ? " CHECKED" : "";
688             }
689             else
690             {
691                 if ($this->moThemeParser->maGlobals["gThemeExtendContext"] == "true")
692                 {
693                     $aExtraLayers[$szLayer] =
694                                ($oLayer->status == MS_ON) ? " CHECKED" : "";
695                 }
696             }
697            
698         }
699
700         //need to update the inputs and urls for themes and groups now
701         $i = 0; //track theme id
702         $nLastThemeId = 0;
703         $nLastGroupId = 0;
704         foreach($this->moThemeParser->maThemes as $szThemeName => $aGroups)
705         {
706             $nThemeGroups = count($aGroups);
707
708             $szAThemeGroups = "new Array(";
709             $szThemeSep = "";
710             $nThemeLayers = 0;
711
712             //if there is a group in the theme
713             if ($nThemeGroups > 0)
714             {
715                 $theme_idx = $this->moThemeParser->GetThemeIndex( $szThemeName );
716                 $szThemeChecked = ($this->CheckThemeOn($szThemeName)) ? " CHECKED" : "";
717                 $szThemeAbstract = $this->moThemeParser->GetThemeAttribute( $szThemeName, "theme_abstract" );
718                 $szExtendThemeAbstract = $this->moThemeParser->GetThemeAttribute( $szThemeName, "theme_extendabstract" );
719                 $aVals["theme"][$theme_idx]["theme_input"] = "<input name=\"".$szThemeName.
720                                      "\" type=\"checkbox\" value=\"".
721                                      $szThemeName."\" onClick=\"".
722                                      "ContextSelector_SetThemeStatus('".
723                                      $i."', this.checked)\" ". $szThemeChecked.">";
724
725                 $j = 0; //track current group id
726                 foreach ($aGroups as $szGroupName => $aLayersInGroup)
727                 {
728                     $szChecked = ($this->CheckGroupOn($szThemeName, $szGroupName)) ? " CHECKED" : "";
729                     //if ($nThemeGroups > 1)
730                     //{
731                         $szOnClick = "onClick=\"ContextSelector_SetGroupStatus('$i', '$j', this.checked)\"";
732                     //}
733                     //else
734                     //  $szOnClick ="onClick=\"ContextSelector_UpdateGroupsOn()\"";
735
736                     $nGroupLayers = 0;
737                     $szLayers = "";
738                     $szSep = "";
739                     foreach($aLayersInGroup as $szLayer)
740                     {
741                         if (array_key_exists( $szLayer, $aActiveLayers) || array_key_exists( $szLayer, $aExtraLayers ))
742                         {
743                             $szLayers .= $szSep."'".$szLayer."'";
744                             $szSep = ",";
745                             ++$nGroupLayers;
746                         }
747                     }
748
749                     $szExtendGroupAbstract = $this->moThemeParser->GetGroupAttribute( $szThemeName, $szGroupName, "group_extendabstract" );
750                     $szAGroupLayers = "new Array(";
751                     if ($szExtendGroupAbstract == "true" && $nGroupLayers > 0)
752                         $szAGroupLayers .= $szLayers;
753                     $szAGroupLayers .= ")";
754
755                     $szGroupAbstract = $this->moThemeParser->GetGroupAttribute( $szThemeName, $szGroupName, "group_abstract" );
756
757                     $szGroupInfo = "'".$szGroupName."', '".$szGroupAbstract."', ".$szAGroupLayers;
758
759                     $group_idx = $this->moThemeParser->GetGroupIndex( $szThemeName, $szGroupName );
760                     $szInputType = $aVals["theme"][$theme_idx]["theme_type"];
761                     $aVals["group"][$group_idx]["group_input"] = "<input name=\"".$szGroupName.
762                           "\" type=\"".$szInputType."\" value=\"".$szGroupName."\" ".$szOnClick." ".$szChecked.">";
763                     $aVals["group"][$group_idx]["group_url"] =
764                               "javascript:ContextSelector_openGroupInfo(".$szGroupInfo.")";
765                     $aVals["group"][$group_idx]["group_numlayers"] = "$nGroupLayers";
766
767                     ++$j;
768                     ++$nLastGroupId;
769
770                     if ( $szExtendThemeAbstract == "true" )
771                     {
772                         $szAThemeGroups .= $szThemeSep."new Array(".$szGroupInfo.")";
773                         $szThemeSep = ",";
774                     }
775
776                     $nThemeLayers += $nGroupLayers;
777                 }
778             }
779             $szAThemeGroups .= ")";
780             $aVals["theme"][$theme_idx]["theme_url"] =
781                           "javascript:ContextSelector_openThemeInfo('".
782                           $szThemeName."', '".$szThemeAbstract."', ".
783                           $szAThemeGroups.");";
784             $aVals["theme"][$theme_idx]["theme_numlayers"] = "$nThemeLayers";
785             ++$i;
786             ++$nLastThemeId;
787        }
788  
789         $aVals["selection"] = $this->maSelections;
790
791         /*
792          * TODO:
793          * This widget should be able to load from a URL.
794          */
795         if (file_exists( $this->mszRendererFile ))
796         {
797              $szHTML .= $this->moTemplateProcessor->ProcessTemplate( $this->mszRendererFile,  $aVals );
798         }
799         return $szHTML;
800     }
801 }//end of class
802 ?>
803
Note: See TracBrowser for help on using the browser.