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

root/Chameleon/trunk/Chameleon/Button.php

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

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * Button Class
4  *
5  * @project     CWC2
6  * @revision    $Id: Button.php,v 1.61 2005/06/06 18:34:35 jlacroix Exp $
7  * @purpose     Helper class to manage button 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  * the button types.
32  */
33 define ("CWCBUTTONTYPE_CLICK", 0);
34 define( "CWCBUTTONTYPE_TOGGLE", 1);
35 define( "CWCBUTTONTYPE_RADIO", 2);
36
37 include_once(COMMON."buttonizer/buttonizer.php" );
38
39 /**
40  * CWCButton
41  *
42  * @desc CWCButton manages button attributes for other classes.
43  */
44 class CWCButton
45 {
46     var $mszOnClick = null;
47     var $mxParams = null;
48     var $mszToolSet = "null";
49     var $mbCurrentTool = false;
50     var $mszStyleResource = "";
51     var $mnImageWidth = -1;
52     var $mnImageHeight = -1;
53     var $mszImageTip = "";
54     var $mszImageName = "cwcimage_";
55     var $maszImages = array();
56     var $mszLabel = '';
57     var $mszLabelAlign = "";
58     var $mnType = CWCBUTTONTYPE_CLICK;
59     var $moParent = null;
60     var $mszDiv = '';
61     var $mbEnabled = true;
62    
63     /**
64      * CWCButton
65      *
66      * @param oParent - the parent widget that contains the parsed
67      * attribute info.
68      */
69     function CWCButton( &$oParent )
70     {
71         $this->moParent =& $oParent;
72         $oParent->maAttributes["TOOLSET"] = new StringAttribute( "TOOLSET", false );
73         $oParent->maAttributes["DEFAULT"] = new BooleanAttribute( "DEFAULT", false );
74         $oParent->maAttributes["STYLERESOURCE"] = new StringAttribute( "STYLERESOURCE", false );
75         $oParent->maAttributes["LABEL"] = new StringAttribute( "LABEL", false);
76         $oParent->maAttributes["LABELALIGN"] = new StringAttribute( "LABELALIGN", false, array( "LEFT", "CENTER", "RIGHT" ) );
77         $oParent->maAttributes["IMAGE"] = new StringAttribute( "IMAGE", false );
78         $oParent->maAttributes["IMAGEWIDTH"] = new IntegerAttribute( "IMAGEWIDTH", false, 1 );
79         $oParent->maAttributes["IMAGEHEIGHT"] = new IntegerAttribute( "IMAGEHEIGHT", false, 1 );
80         $oParent->maAttributes["IMAGETIP"] = new StringAttribute( "IMAGETIP", false );
81         $oParent->maAttributes["ONCLICK"] = new StringAttribute( "ONCLICK", false );
82         $this->maszImages['normal'] = null;
83         $this->maszImages['selected'] = null;
84         $this->maszImages['hover'] = null;
85         $this->maszImages['disabled'] = null;
86        
87         //hidden for this version
88         //$this->maAttributes['DIV'] = new StringAttribute( "DIV", false );
89     }
90
91     /**
92      * Set the onclick event of this button.  This can be provided in the widget tag
93      * also, using the ONCLICK attribute
94      *
95      * @param szOnClick - the name of the javascript function to call.  It cannot
96      * include the function parameter list or parentheses.
97      */
98     function SetOnClick( $szOnClick, $mxParams=null )
99     {
100         if ($szOnClick != "")
101         {
102             $this->mszOnClick = $szOnClick;
103             if ($mxParams != null)
104             {
105                 $this->mxParams = $mxParams;
106             }
107         }
108         else
109         {
110             $this->mszOnClick = null;
111             $this->mxParams = null;
112         }
113     }
114    
115     function SetType( $nType )
116     {
117         $this->mnType = $nType;
118     }
119
120     /**
121      * initialize the default values from the parameters of the widget tag if
122      * provided
123      */
124     function InitDefaults()
125     {
126         $oApp = GetChameleonApplication();
127        
128         if (isset($this->moParent->maParams["TOOLSET"]) &&
129             $this->moParent->maParams["TOOLSET"] != "")
130         {
131             $this->mszToolSet = $this->moParent->maParams["TOOLSET"];
132             if ($this->mnType == CWCBUTTONTYPE_CLICK)
133                 $this->mnType = CWCBUTTONTYPE_RADIO;
134         }
135        
136         if (isset($this->moParent->maParams['DEFAULT']))
137         {
138             $this->mbCurrentTool = strcasecmp($this->moParent->maParams['DEFAULT'], 'true') == 0 ? true : false;
139         }
140         if (isset($this->moParent->maParams["STYLERESOURCE"]))
141             $this->mszStyleResource = $this->moParent->maParams["STYLERESOURCE"];
142            
143         if (isset($this->moParent->maParams["LABELALIGN"]))
144             $this->mszLabelAlign = strtolower( $this->moParent->maParams["LABELALIGN"] );
145
146         if (isset($this->moParent->maParams["LABEL"]))
147             $this->mszLabel = $this->moParent->maParams["LABEL"];
148
149         if (isset($this->moParent->maParams["IMAGEWIDTH"]))
150             $this->mnImageWidth = $this->moParent->maParams["IMAGEWIDTH"];
151
152         if (isset($this->moParent->maParams["IMAGEHEIGHT"]))
153             $this->mnImageHeight = $this->moParent->maParams["IMAGEHEIGHT"];
154
155         if (isset($this->moParent->maParams["IMAGETIP"]))
156             $this->mszImageTip = $this->moParent->maParams["IMAGETIP"];
157
158         if (isset($this->moParent->maParams["ONCLICK"]))
159             $this->mszOnClick = $this->moParent->maParams["ONCLICK"];
160        
161             if (isset($this->moParent->maParams["DIV"]))
162             $this->mszDiv = $this->moParent->maParams["DIV"];
163            
164         $this->mszImageName .= $this->moParent->mnId;
165
166         if (isset($this->moParent->maszContents['IMAGE']))
167         {
168             $nImages = count($this->moParent->maszContents['IMAGE']);
169             for ($i=0; $i<$nImages; $i++)
170             {
171                 $aImage = $this->moParent->maszContents['IMAGE'][$i];
172                 if (!isset($aImage['IMAGE']) && isset($this->moParent->maParams['IMAGE']))
173                 {
174                     $aImage['IMAGE'] = $oApp->findFile( $this->moParent->maParams['IMAGE'] );
175                     if ($aImage['IMAGE'] == '')
176                     {
177                         $aImage['IMAGE'] = $this->moParent->maParams['IMAGE'];
178                         $_SESSION['gErrorManager']->setError(ERR_WARNING,
179                                            "ERROR: Button.php was unable to find the image '".$aImage['IMAGE']."' in any of the registered or default skins.");
180                     }
181                
182                 }
183                 else if (isset($aImage['IMAGE']))
184                 {
185                     $aImage['IMAGE'] = $oApp->findFile( $aImage['IMAGE'] );
186                 }
187                    
188                
189                 $szState = (isset($aImage['STATE'])) ? strtolower($aImage['STATE']) : 'normal';
190                
191                 if ($this->mszStyleResource != "") //use buttonizer to generate image
192                 {
193                     $this->maszImages[$szState] = $this->GetImage( $szState, array_change_key_case( $aImage ) );
194                 }
195                 elseif( isset($aImage['IMAGE']) ) //assume a normal image URL
196                 {
197                     $this->maszImages[$szState] = $oApp->fileSystemToURL($aImage['IMAGE']);
198                 }
199             }
200         }
201         else if (isset($this->moParent->maParams['IMAGE']))
202         {
203             //only a 'normal' state for this image
204             $szState = 'normal';
205             $szImage = $oApp->findFile( $this->moParent->maParams['IMAGE'] );
206            
207             if ($this->mszStyleResource != "" )
208             {
209                 $this->maszImages[$szState] = $this->GetImage( $szState, array( "image" => $szImage ) );
210             }
211             else
212             {
213                 $this->maszImages[$szState] = $oApp->fileSystemToURL( $szImage );
214             }
215         }
216     }
217    
218     /**
219      * parse the URL and retrieve button states for groups if possible
220      */
221     function ParseURL()
222     {
223         if ($this->mszToolSet != "" && $this->mszToolSet != "null")
224         {           
225             if ($this->moParent->moFormVars->isVarSet('BUTTON_TOOLSET_'.$this->mszToolSet) &&
226                 $this->moParent->moFormVars->getVar('BUTTON_TOOLSET_'.$this->mszToolSet) != '')
227             {
228                 if ($this->moParent->moFormVars->getVar('BUTTON_TOOLSET_'.$this->mszToolSet) == $this->mszImageName)
229                 {
230                     $this->mbCurrentTool = true;
231                 }
232                 else
233                 {
234                     $this->mbCurrentTool = false;
235                 }
236             }
237         }
238         return true;
239     }
240    
241     /**
242      * return an array of javascript functions used by the CWCButton,
243      * currently none are required since everything has been moved to
244      * cwc_button.js
245      */
246     function GetJavascriptFunctions()
247     {
248         return array();
249     }
250    
251     /**
252      * return an array of functions to be called when the page has finished
253      * loading, currently none are required.
254      *
255      */
256     function GetJavascriptOnLoadFunctions()
257     {
258         $aReturn = array();
259        
260         if ($this->mbCurrentTool)
261         {
262             $szFunction = 'CWCButtonInit_'.$this->moParent->mnId;
263             if ($this->maszImages['normal'] != null &&
264                 ( $this->maszImages['selected'] != null ||
265                   $this->maszImages['hover'] != null ||
266                   $this->maszImages['disabled'] != null ) )
267             {
268
269                 $szCode  = 'var '.$szFunction.' = goCWCButtonManager.GetButton( "'.$this->mszImageName.'" );'."\n";
270                 $szCode .= <<<EOT
271 {$szFunction}.bActive = true;
272 {$szFunction}.SetState( CWCBUTTONSTATE_SELECTED );
273 if ({$szFunction}.onClick != null)
274 {
275     {$szFunction}.onClick( {$szFunction}, {$szFunction}.xValues );
276 }
277 if ({$szFunction}.oGroup != null)
278 {
279     {$szFunction}.oGroup.ActivateButton( {$szFunction} );
280 }
281 EOT;
282                
283             }
284             else
285             {
286                 if (is_array($this->mxParams))
287                 {
288                     $szParams = 'null, new Array(';
289                     $szSep = '';
290                     foreach ($this->mxParams as $szVal)
291                     {
292                         $szParams .= $szSep.'"'.$szVal.'"';
293                         $szSep = ',';
294                     }
295                     $szParams .= ')';
296                 }
297                 else
298                 {
299                     if(isset($this->mxParams) && $this->mxParams != "")
300                         $szParams = 'null, "'.$this->mxParams.'"';
301                     else
302                         $szParams = "null, \"\"";
303                 }
304                 $szCode = $this->mszOnClick.'('.$szParams.');';
305             }
306             $aReturn[$szFunction] = $szCode;
307         }
308        
309         return $aReturn;
310     }
311
312     /**
313      * return an array of files to include.  Currently, just cwc_button.js is
314      * required
315      */
316     function GetJavascriptIncludeFunctions()
317     {
318         $aReturn = array();
319        
320         if ($this->maszImages['normal'] != null &&
321             ( $this->maszImages['selected'] != null ||
322               $this->maszImages['hover'] != null ||
323               $this->maszImages['disabled'] != null ) )
324         {
325             $szVar = 'cwc_dhtml.js';
326             $aReturn[$szVar] = '<script language="JavaScript" src="'.$_SESSION['gszCoreWebPath'].
327                             '/widgets/js/cwc_dhtml.js" type="text/javascript"></script>';
328             $szVar = 'cwc_button.js';
329             $aReturn[$szVar] = '<script language="JavaScript" src="'.$_SESSION['gszCoreWebPath'].
330                             '/widgets/js/cwc_button.js" type="text/javascript"></script>';
331
332             }
333        
334         return $aReturn;
335     }
336     /**
337      * return an array of functions to call as the page loads.  Currently, this registers
338      * the button with the button manager if necessary.
339      *
340      */
341     function GetJavascriptInitFunctions()
342     {
343         $aReturn = array();
344        
345         if ($this->maszImages['normal'] != null &&
346             ( $this->maszImages['selected'] != null ||
347               $this->maszImages['hover'] != null ||
348               $this->maszImages['disabled'] != null ) )
349         {
350             $szSelected = ($this->maszImages['selected'] != null) ? '"'.$this->maszImages['selected'].'"' : 'null';
351             $szHover = ($this->maszImages['hover'] != null) ? '"'.$this->maszImages['hover'].'"' : 'null';
352             $szDisabled = ($this->maszImages['disabled'] != null) ? '"'.$this->maszImages['disabled'].'"' : 'null';
353            
354             $szOnClick = ($this->mszOnClick != null) ? $this->mszOnClick : 'null';
355             if ($this->mxParams != null)
356             {
357                 if (is_array($this->mxParams))
358                 {
359                     $szParams = 'new Array(';
360                     $szSep = '';
361                     foreach ($this->mxParams as $szVal)
362                     {
363                         $szParams .= $szSep.'"'.$szVal.'"';
364                         $szSep = ',';
365                     }
366                     $szParams .= ')';
367                 }
368                 else
369                 {
370                     $szParams = '"'.$this->mxParams.'"';
371                 }
372             }
373             else
374             {
375                 $szParams = 'null';
376             }
377            
378              $szCode = 'oButton =  new CWCButton('.
379                 '"'.$this->mszImageName.'", '.
380                 $this->mnType. ', '.
381                 '"'.$this->mszToolSet.'", '.
382                 $szOnClick . ', ' . $szParams . ', "'.
383                 $this->maszImages['normal'] . '", '.$szHover.', '.$szSelected .
384                 ', '. $szDisabled . ");\n";
385              $szCode .= 'oButton.oForm = '.$this->moParent->mszHTMLForm.";\n";
386              $szCode .= 'oButton.szDivName = "'.$this->mszDiv.'"'."\n;";
387              
388              if (!$this->mbEnabled)
389                 $szCode .= 'oButton.SetState( CWCBUTTONSTATE_DISABLED );'."\n";
390
391              $szCode .= 'goCWCButtonManager.AddButton( oButton );'."\n";
392             $aReturn[$this->mszImageName] = $szCode;
393         }
394
395         return $aReturn;
396     }
397
398     /**
399      * return an array of javascript variables to register in global scope,
400      * currently none are required.
401      */
402     function GetJavascriptVariables()
403     {
404         return array();
405     }
406    
407     function GetHTMLHiddenVariables()
408     {
409         $aReturn = array();
410        
411         if ($this->mszToolSet != "" && strcasecmp($this->mszToolSet, "null") != 0 &&
412             $this->maszImages['normal'] != null &&
413             ( $this->maszImages['selected'] != null ||
414               $this->maszImages['hover'] != null ||
415               $this->maszImages['disabled'] != null ))
416         {
417             $szVariable = "BUTTON_TOOLSET_".$this->mszToolSet;
418             $szTool="";
419             if ($this->moParent->moFormVars->isVarSet($szVariable))
420               $szTool = $this->moParent->moFormVars->getVar($szVariable);
421             $szValue = "<INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"$szTool\">";
422             $aReturn[$szVariable] = $szValue;
423
424         }
425         return $aReturn;
426     }
427
428     /**
429      * DrawPublish
430      *
431      * Return the HTML code for this button. 
432      */
433     function DrawPublish( )
434     {
435        
436         if (//$this->maszImages['normal'] != null &&
437             ( $this->maszImages['selected'] == null &&
438               $this->maszImages['hover'] == null &&
439               $this->maszImages['disabled'] == null ) )
440         {
441             $bNeedAnchor = true;
442         }
443         else
444             $bNeedAnchor = false;
445         $szResult = "";
446        
447         if ($bNeedAnchor)
448         {
449             if (is_array($this->mxParams))
450             {
451                 $szParams = 'null, new Array(';
452                 $szSep = '';
453                 foreach ($this->mxParams as $szVal)
454                 {
455                     $szParams .= $szSep.'"'.$szVal.'"';
456                     $szSep = ',';
457                 }
458                 $szParams .= ')';
459             }
460             else
461             {
462                 if(isset($this->mxParams) && $this->mxParams != "")
463                     $szParams = 'null, "'.$this->mxParams.'"';
464                 else
465                     $szParams = "null, \"\"";
466             }
467            
468             if ($this->mszToolSet == "" || $this->mszToolSet == null || $this->mszToolSet == "null")
469             {
470                 $szResult .= '<a href="#" onclick=\''.$this->mszOnClick.'('. $szParams .')\'>';
471             }
472             else
473             {
474                 if ($this->mbCurrentTool)
475                     $szChecked = " CHECKED";
476                 else
477                     $szChecked = "";
478                    
479                 if (isset($this->moParent->mszCmd))
480                 {
481                     $szCmd = ' value="'.$this->mszImageName.'"';
482                 }
483                 else
484                 {
485                     $szCmd = ' value="'.$this->mszImageName.'"';
486                 }
487                 $szResult .= '<input type="radio" name="BUTTON_TOOLSET_'.$this->mszToolSet.'" '.$szCmd.' onclick=\''.$this->mszOnClick.'('. $szParams .')\''.$szChecked.'>';
488                 /*
489                  * TODO: I'd like to enable the following line and remove
490                  * $bNeedAnchor=false so that the user could click on the
491                  * image to set the radio button but that turns out to be
492                  * somewhat problematic.  You need to access the radio
493                  * buttons as an array and search it for a radio button with
494                  * the right value.  This can be difficult because in IE
495                  * radio buttons that aren't grouped (i.e. there is only
496                  * one of them) are not represented as arrays ... or at
497                  * least, that was our experience from programming Studio.
498                  */
499                 //$szResult .= '<a href="#" onclick=\''.$this->moParent->mszHTMLForm.'.BUTTON_TOOLSET_'.$this->mszToolSet.'.click(); '.$this->mszOnClick.'('. $szParams .');\'>';
500                 $bNeedAnchor = false;
501             }
502            
503         }
504        
505         if ($this->maszImages['selected'] != '' && $this->mbCurrentTool)
506         {
507             $szResult .= '<IMG NAME="'.$this->mszImageName.'" ID="'.$this->mszImageName.
508                         '" SRC="'.$this->maszImages['selected'].'" ALT="'.
509                         $this->mszImageTip.'" TITLE="'.$this->mszImageTip.
510                         '" BORDER="0" WIDTH="'.$this->mnImageWidth.'" '.
511                         'HEIGHT="'.$this->mnImageHeight.'">';
512         }
513         else if ($this->maszImages['normal'] != '')
514         {
515             $szResult .= '<IMG NAME="'.$this->mszImageName.'" ID="'.$this->mszImageName.
516                         '" SRC="'.$this->maszImages['normal'].'" ALT="'.
517                         $this->mszImageTip.'" TITLE="'.$this->mszImageTip.
518                         '" BORDER="0" WIDTH="'.$this->mnImageWidth.'" '.
519                         'HEIGHT="'.$this->mnImageHeight.'">';
520         }
521         else if ($this->mszLabel != '')
522         {
523             $szResult .= $this->mszLabel;
524         }
525         else
526         {
527             $szResult .= $this->mszImageName;
528         }
529                    
530         if ($bNeedAnchor)
531         {
532             $szResult .= "</a>";
533         }
534        
535         return $szResult;
536     }
537    
538     /**
539      * functions for making images from shared resources
540      */
541      
542     /**
543      * this function takes an image name and returns a URL.  If the image
544      * is a SharedResource image then it will create a buttonized image
545      * from the SharedResource settings and then cache the result.
546      * @param szState the state of the image.  One of 'normal', 'selected', 'hover',
547      *        or 'disabled'.  The image will get all the default settings from
548      *        the shared resource, plus any state-specific settings from the
549      *        appropriate 'state' entries.
550      * @aImage an array of image settings.
551      */
552     function GetImage( $szState, $aImage )
553     {
554        
555         //handle the simple cases first, if the image is in the session then
556         //just use that value.  Side effect is that you will need to restart
557         //your session to see changes ;)
558        
559         //turns out that multiple chameleon apps sharing the same session can
560         //get confused about which button is which in the session.  To make
561         //sure that we get the right button, use the template name as well
562        
563         $oApp = GetChameleonApplication();
564         $szTemplate = $oApp->mszTemplateName;
565        
566         $szCacheName = $szTemplate.'_'.$this->mszImageName.'_'.$szState;
567         if (isset($_SESSION[$szCacheName]))
568         {
569             if ($this->mnImageHeight == -1)
570             {
571                 $this->mnImageHeight = $_SESSION[$this->mszStyleResource.$szTemplate][$szState]['height'];
572             }
573             if ($this->mnImageWidth == -1)
574             {
575                 $this->mnImageWidth = $_SESSION[$this->mszStyleResource.$szTemplate][$szState]['width'];
576             }
577             return $_SESSION[$szCacheName];
578         }
579        
580         $params = $this->moParent->maParams;
581        
582         //gather info about this SharedResource image, use session copy if available.
583         if (isset($_SESSION[$this->mszStyleResource.$szTemplate][$szState]))
584         {
585             $aParams = $_SESSION[$this->mszStyleResource.$szTemplate][$szState];
586         }
587         else
588         {
589             if (isset($this->moParent->maSharedResourceWidgets[$this->mszStyleResource]))
590             {
591                 $share = $this->moParent->maSharedResourceWidgets[$this->mszStyleResource]->maszContents;
592                 $aParams = $this->LoadSharedResource( $share, array(), $szState );
593                 if (!isset($_SESSION[$this->mszStyleResource.$szTemplate]))
594                 {
595                     $_SESSION[$this->mszStyleResource.$szTemplate] = array();
596                 }
597                 $_SESSION[$this->mszStyleResource.$szTemplate][$szState] = $aParams; //make a copy in the session.
598             }
599             else
600             {
601                 //error ... no shared resource of this name
602                 $_SESSION['gErrorManager']->setError(ERR_WARNING,
603                    "ERROR: Button.php was unable to find a shared resource named ".
604                    $this->mszStyleResource." for widget ".get_class($this->moParent));
605                 return;            }
606         }
607        
608         $aParams = array_merge( $aParams, $aImage );
609        
610         //these values override the sharedresource
611         if ($this->mnImageHeight != -1)
612         {
613             $aParams['height'] = $this->mnImageHeight;
614         }
615         else
616         {
617             $this->mnImageHeight = $aParams['height'];
618         }
619        
620         if ($this->mnImageWidth != -1)
621         {
622             $aParams['width'] = $this->mnImageWidth;
623         }
624         else
625         {
626             $this->mnImageWidth = $aParams['width'];
627         }
628        
629         if ($this->mszLabelAlign != "")
630         {
631             $aParams['labelalign'] = $this->mszLabelAlign;
632         }
633        
634         //the image parameter needs to be 'graphic' for the buttonizer
635         if (isset($aParams['image']))
636         {
637             $aParams['graphic'] = $oApp->findFile( $aParams['image'] );
638         }
639         //these values don't have entries in the shared resource.
640         /*
641         if (!isset($aParams['label']))
642         {
643             if (isset( $params["LABEL"] ))
644                 $aParams["label"] = $params["LABEL"];
645             else
646                 $aParams["label"] = "";
647         }
648         */
649         $aParams['label'] = $this->mszLabel;
650        
651         //load platform specific behaviours
652         $aParams["gd_module"] = "gd2";
653         $aParams["freetype"] = "FreeType";
654        
655         //generate the cached image.
656         $szImageFile = "b".md5( implode( "", $aParams ) ).".png";
657        
658         $szImagePath = $_SESSION['gszButtonCachePath'].$szImageFile;
659
660         $szImageWebPath = $_SESSION['gszButtonCacheWebPath'].$szImageFile;
661        
662         //print_r($aParams);
663
664         //cache the URL and generate the image, if required.
665         if (!isset($aParams['usecache']) || (isset($aParams['usecache']) && $aParams['usecache']))
666         {
667             $_SESSION[$szCacheName] = $szImageWebPath;
668             if (!is_file( $szImagePath ))
669             {
670                 buttonize( $szImagePath, $aParams );
671             }
672         }
673         else
674         {
675             buttonize( $szImagePath, $aParams );
676         }
677        
678         return $szImageWebPath;
679     }
680    
681     /**
682      * load a shared resource into an array that contains buttonizer values
683      * return the loaded array
684      */
685     function LoadSharedResource( $share, $aParams = array(), $szState )
686     {
687         $oApp = GetChameleonApplication();
688        
689         if (isset($share["IMAGEWIDTH"][0]["VALUE"]))
690             $aParams["width"] = $share["IMAGEWIDTH"][0]["VALUE"];
691        
692         if (isset($share["IMAGEHEIGHT"][0]["VALUE"]))
693             $aParams["height"] = $share["IMAGEHEIGHT"][0]["VALUE"];
694        
695         if (isset($share["TEXTBUTTONCOLOR"][0]["VALUE"]))
696             $aParams["backgroundcolor"] = $share["TEXTBUTTONCOLOR"][0]["VALUE"];
697        
698         if (isset($share["BACKGROUNDIMAGE"][0]["VALUE"]))
699             $aParams["backgroundgraphic"] = $oApp->findFile( $share["BACKGROUNDIMAGE"][0]["VALUE"] );
700
701         if (isset($share["TEXTBUTTONBORDER_TOPLEFT_IMAGE"][0]["VALUE"]))
702             $aParams["border_tl_image"] = $oApp->findFile( $share["TEXTBUTTONBORDER_TOPLEFT_IMAGE"][0]["VALUE"] );
703        
704         if (isset($share["TEXTBUTTONBORDER_TOP_IMAGE"][0]["VALUE"]))
705             $aParams["border_t_image"] = $oApp->findFile( $share["TEXTBUTTONBORDER_TOP_IMAGE"][0]["VALUE"] );
706
707         if (isset($share["TEXTBUTTONBORDER_TOPRIGHT_IMAGE"][0]["VALUE"]))
708             $aParams["border_tr_image"] = $oApp->findFile( $share["TEXTBUTTONBORDER_TOPRIGHT_IMAGE"][0]["VALUE"] );
709
710         if (isset($share["TEXTBUTTONBORDER_RIGHT_IMAGE"][0]["VALUE"]))
711             $aParams["border_r_image"] = $oApp->findFile( $share["TEXTBUTTONBORDER_RIGHT_IMAGE"][0]["VALUE"] );
712
713         if (isset($share["TEXTBUTTONBORDER_BOTTOMRIGHT_IMAGE"][0]["VALUE"]))
714             $aParams["border_br_image"] = $oApp->findFile( $share["TEXTBUTTONBORDER_BOTTOMRIGHT_IMAGE"][0]["VALUE"] );
715
716         if (isset($share["TEXTBUTTONBORDER_BOTTOM_IMAGE"][0]["VALUE"]))
717             $aParams["border_b_image"] = $oApp->findFile( $share["TEXTBUTTONBORDER_BOTTOM_IMAGE"][0]["VALUE"] );
718
719         if (isset($share["TEXTBUTTONBORDER_BOTTOMLEFT_IMAGE"][0]["VALUE"]))
720             $aParams["border_bl_image"] =$oApp->findFile(  $share["TEXTBUTTONBORDER_BOTTOMLEFT_IMAGE"][0]["VALUE"] );
721
722         if (isset($share["TEXTBUTTONBORDER_LEFT_IMAGE"][0]["VALUE"]))
723             $aParams["border_l_image"] = $oApp->findFile( $share["TEXTBUTTONBORDER_LEFT_IMAGE"][0]["VALUE"] );
724
725         if (isset($share["TEXTBUTTONNUDGE"][0]["VALUE"]))
726             $aParams["nudge"] = $share["TEXTBUTTONNUDGE"][0]["VALUE"];
727        
728         if (isset($share["TEXTBUTTONPADDING"][0]["VALUE"]))
729             $aParams["padding"] = $share["TEXTBUTTONPADDING"][0]["VALUE"];
730        
731         if (isset($share["LABELFONT"][0]["VALUE"]))
732         {
733             $szFont = $oApp->findFile( $share["LABELFONT"][0]["VALUE"] );
734             if (!$szFont)
735             {
736                 $aParams["labelfont"] = $share["LABELFONT"][0]["VALUE"];
737                 $_SESSION['gErrorManager']->setError(ERR_WARNING,
738                     "ERROR: Button.php was unable to find the font '".$aParams["labelfont"]."' in any of the registered or default skins.");
739             }
740             else
741             {
742                 $aParams["labelfont"] = $szFont;
743             }
744         }
745        
746         if (isset($share["LABELFONTSIZE"][0]["VALUE"]))
747             $aParams["labelsize"] = $share["LABELFONTSIZE"][0]["VALUE"];
748        
749         if (isset($share["LABELCOLOR"][0]["VALUE"]))
750             $aParams["labelcolor"] = $share["LABELCOLOR"][0]["VALUE"];
751        
752         if (isset($share["LABELALIGN"][0]["VALUE"]))
753             $aParams["labelalign"] = $share["LABELALIGN"][0]["VALUE"];
754        
755         if (isset($share["LABELANTIALIAS"][0]["VALUE"]))
756             $aParams["antialias"] = ($share["LABELANTIALIAS"][0]["VALUE"] == "true" )? true : false;
757            
758         if (isset($share["IMAGE"]))
759         {
760             $aParams["graphic"] = $oApp->findFile( $share["IMAGE"][0]['VALUE'] );
761         }
762         if (isset($share["USETEXTBUTTONCACHE"][0]["VALUE"]))
763             $aParams['usecache'] = ($share["USETEXTBUTTONCACHE"][0]["VALUE"] == "true" )? true : false;
764        
765         //process states last
766         if (isset($share['STATE']))
767         {
768             foreach( $share["STATE"] as $aszSR )
769             {
770                 if($aszSR["VALUE"] == $szState)
771                 {
772                     $aParams = $this->LoadSharedResource($aszSR["CHILDREN"][0], $aParams, $szState);
773                 }
774             }
775         }
776        
777         return $aParams;
778     }
779 }
780 ?>
Note: See TracBrowser for help on using the browser.