/usr/local/miolo2/classes/ui/controls/mtoolbar.class

Go to the documentation of this file.
00001 <?php
00034 class MToolBarButton extends MControl
00035 {
00036     public  $name;
00037     public  $caption;
00038     public  $enabled;
00039 
00040     private $url;
00041     private $hint;
00042     private $enabledImage;
00043     private $disabledImage;
00044     private $button;
00045     private $method='';
00046 
00047     public function __construct($name, $caption, $url, $hint, $enabled, $enabledImage, $disabledImage, $method='')
00048     {
00049         $this->name    = $name;
00050         $this->caption = $caption;
00051         $this->url     = $url;
00052         $this->hint    = $hint;
00053         $this->enabled = $enabled;
00054         $this->method  = $method;
00055         $this->enabledImage  = $enabledImage;
00056         $this->disabledImage = $disabledImage;
00057 
00058         if ( $enabled )
00059         {
00060             $this->enable();
00061         }
00062         else
00063         {
00064             $this->disable();
00065         }
00066     }
00067 
00068     public function setMethod($method='post')
00069     {
00070         $this->method = $method;
00071     }
00072 
00073     public function getButton()
00074     {
00075         return $this->button;
00076     }
00077 
00078     public function show()
00079     {
00080         $this->enable();
00081     }
00082 
00083     public function hide()
00084     {
00085         unset($this->button);
00086     }
00087 
00088     public function enable()
00089     {
00090         if( $this->method == 'post')
00091         {
00092             $this->button = new MImageButton($this->name, $this->caption, $this->url, $this->enabledImage);
00093         }
00094         else
00095         {
00096             $this->button = new MImageLink($this->name, $this->caption, $this->url, $this->enabledImage);
00097         }
00098         $this->button->setJSHint( $this->hint );
00099     }
00100 
00101     public function disable()
00102     {
00103         $this->button = new MImage($this->name, $this->caption, $this->disabledImage);
00104         $this->button->setJSHint( $this->hint );
00105     }
00106 
00107 }
00108 
00109 class MToolBar extends MBaseGroup
00110 {
00111     const BUTTON_BACK   = 'tbBtnBack';
00112     const BUTTON_NEW    = 'tbBtnNew';
00113     const BUTTON_SAVE   = 'tbBtnSave';
00114     const BUTTON_DELETE = 'tbBtnDelete';
00115     const BUTTON_SEARCH = 'tbBtnSearch';
00116     const BUTTON_PRINT  = 'tbBtnPrint';
00117     const BUTTON_EXIT   = 'tbBtnExit';
00118     const BUTTON_RESET  = 'tbBtnReset';
00119 
00120     private $toolBarButtons;
00121 
00126     public function __construct($name='ToolBar',  $url='' )
00127     {
00128         parent::__construct($name, '');
00129 
00130         $this->name = $name;
00131 
00132         $MIOLO  = MIOLO::getInstance();
00133         if( ! $url )
00134         {
00135             $url = $MIOLO->getCurrentURL();
00136         }
00137 
00138         $enabledImage  = $MIOLO->getUI()->GetImageTheme($MIOLO->theme->id, 'new-20x20.png');
00139         $disabledImage = $MIOLO->getUI()->GetImageTheme($MIOLO->theme->id, 'new-disabled-20x20.png');
00140         $newUrl        = $url . '&function=insert&event=tbBtnNew:click';
00141         $this->toolBarButtons['tbBtnNew'] = new MToolBarButton( 'tbBtnNew', _M('New'), $newUrl, _M('New'), true, $enabledImage, $disabledImage);
00142 
00143         $enabledImage  = $MIOLO->getUI()->GetImageTheme($MIOLO->theme->id, 'save-20x20.png' );
00144         $disabledImage = $MIOLO->getUI()->GetImageTheme($MIOLO->theme->id,  'save-disabled-20x20.png' );
00145         $newUrl        = $url . '&function=' . MIOLO::_REQUEST('function').'&event=tbBtnSave:click';
00146         $this->toolBarButtons['tbBtnSave'] = new MToolBarButton('tbBtnSave', _M('Save'), $newUrl, _M('Save'), true, $enabledImage, $disabledImage,'post');
00147 
00148         $enabledImage  = $MIOLO->getUI()->GetImageTheme($MIOLO->theme->id, 'delete-20x20.png');
00149         $disabledImage = $MIOLO->getUI()->GetImageTheme($MIOLO->theme->id, 'delete-disabled-20x20.png');
00150         $newUrl        = $url . '&function=delete&event=tbBtnDelete:click';
00151         $this->toolBarButtons['tbBtnDelete'] = new MToolBarButton('tbBtnDelete', _M('Delete'), $newUrl, _M('Delete'), true, $enabledImage, $disabledImage,'post');
00152 
00153         $enabledImage  = $MIOLO->getUI()->GetImageTheme($MIOLO->theme->id, 'search-20x20.png');
00154         $disabledImage = $MIOLO->getUI()->GetImageTheme($MIOLO->theme->id, 'search-disabled-20x20.png');
00155         $newUrl        = $url . '&function=search&event=tbBtnSearch:click';
00156         $this->toolBarButtons['tbBtnSearch'] = new MToolBarButton('tbBtnSearch', _M('Search'), $newUrl, _M('Search'), true, $enabledImage, $disabledImage);
00157 
00158         $enabledImage  = $MIOLO->getUI()->GetImageTheme($MIOLO->theme->id, 'print-20x20.png');
00159         $disabledImage = $MIOLO->getUI()->GetImageTheme($MIOLO->theme->id, 'print-disabled-20x20.png');
00160         $newUrl        = $url . '&function=print&event=tbBtnPrint:click';
00161         $this->toolBarButtons['tbBtnPrint'] = new MToolBarButton('tbBtnPrint', _M('Print'), $newUrl, _M('Print'), true, $enabledImage, $disabledImage, 'post');
00162 
00163         $enabledImage  = $MIOLO->getUI()->GetImageTheme($MIOLO->theme->id, 'reset-20x20.png');
00164         $disabledImage = $MIOLO->getUI()->GetImageTheme($MIOLO->theme->id, 'reset-disabled-20x20.png');
00165         $this->toolBarButtons['tbBtnReset'] = new MToolBarButton( 'tbBtnReset', _M('Reset'), 'javascript:document.forms[0].reset();', _M('Reset'), true, $enabledImage, $disabledImage, 'javaScript');
00166         
00167         //begin stack
00168         $refererFunction = MIOLO::_REQUEST('refererFunction');
00169         $headers         = getallheaders();
00170         $newUrl          = str_replace('&refererFunction=back','',$headers['Referer']);
00171         $session         = $MIOLO->session;
00172         $mioloPromptEvent= ( $session->GetValue('mioloPromptEvent') == 'true' ) ? true : false;
00173         $mioloStack      = $session->IsRegistered('mioloStack') ? 
00174                            unserialize($session->GetValue('mioloStack')) : 
00175                            null;
00176         
00177         if ( $refererFunction == 'back' )
00178         {
00179             if ( $mioloPromptEvent == true )
00180             {
00181                 unset($mioloStack[(count($mioloStack)-1)]);
00182                 $session->SetValue('mioloPromptEvent','false');
00183             }
00184             $newUrl = $mioloStack[(count($mioloStack)-2)];
00185             unset($mioloStack[(count($mioloStack)-1)]);
00186         }
00187         else
00188         {
00189             $pn_page       = MIOLO::_REQUEST('pn_page');
00190             $__filter      = MIOLO::_REQUEST('__filter');
00191             $pn_page       = strlen($pn_page)>0 ? $pn_page : 1;
00192             $__filter      = strlen($__filter)>0 ? $__filter : 0;
00193             $mioloStackPost= $session->GetValue('mioloStackPost');
00194             
00195             if ( count($_POST)>0 )
00196             {
00197                 $string = $this->getArrayAsUrl($_POST);
00198                 $session->SetValue('mioloStackPost','&pn_page=' . $pn_page . '&__filter=' . $__filter . str_replace('&pn_page=1&__filter=0','',$string));
00199             }
00200             else
00201             {
00202                 $session->SetValue('mioloStackPost',null);
00203             }
00204             
00205             if ( strstr($mioloStackPost,'pn_page') )
00206             {
00207                 $mioloStack[count($mioloStack)] = str_replace('&pn_page=1&__filter=0','',$newUrl) . $mioloStackPost;
00208             }
00209             else
00210             {
00211                 $mioloStack[count($mioloStack)] = str_replace('&pn_page=1&__filter=0','',$newUrl) . "&pn_page=$pn_page&__filter=$__filter$mioloStackPost";
00212             }
00213             if ( $mioloPromptEvent == true )
00214             {
00215                 unset($mioloStack[(count($mioloStack)-1)]);
00216                 $session->SetValue('mioloPromptEvent','false');
00217             }
00218             $newUrl = $mioloStack[(count($mioloStack)-1)];
00219         }
00220         $session->SetValue('mioloStack',serialize($mioloStack));
00221         //finish stack
00222         
00223         $enabledImage  = $MIOLO->getUI()->GetImageTheme($MIOLO->theme->id, 'back-20x20.png');
00224         $disabledImage = $MIOLO->getUI()->GetImageTheme($MIOLO->theme->id, 'back-disabled-20x20.png');
00225         $this->toolBarButtons['tbBtnBack'] = new MToolBarButton('tbBtnBack', _M('Back'), $newUrl . '&refererFunction=back', _M('Back'), count($mioloStack)>0, $enabledImage, $disabledImage);
00226         
00227         $enabledImage  = $MIOLO->getUI()->GetImageTheme($MIOLO->theme->id, 'exit-20x20.png');
00228         $disabledImage = $MIOLO->getUI()->GetImageTheme($MIOLO->theme->id, 'exit-disabled-20x20.png');
00229         
00230         $newUrl = $MIOLO->getPreviousURL();
00231         $this->toolBarButtons['tbBtnExit'] = new MToolBarButton('tbBtnExit', _M('Exit'), $newUrl, _M('Exit'), true, $enabledImage, $disabledImage);
00232 
00233         $this->setShowChildLabel(false);
00234     }
00235 
00236     public function getArrayAsUrl( $var )
00237     {
00238         $string = '';
00239         foreach ( $var as $key => $value )
00240         {
00241             if ( is_array($value) )
00242             {
00243                 $string .= '&' . $key . '=' . $this->getArrayAsUrl($value);
00244             }
00245             else
00246             {
00247                 $string .= '&' . $key . '=' . urlencode($value);
00248             }
00249         }
00250         return $string;
00251     }
00252 
00253     public function getButtons()
00254     {
00255         foreach ( $this->toolBarButtons as $b )
00256         {
00257             if( method_exists($b,'getButton') )
00258             {
00259                 $buttons[] = $b->getButton();
00260             }
00261             else
00262             {
00263                 $buttons[] = $b;
00264             }
00265         }
00266 
00267         return $buttons;
00268     }
00269 
00270     public function addButton($name, $caption, $url, $hint, $enabled, $enabledImage, $disabledImage)
00271     {
00272         $this->toolBarButtons[$name] = new MToolBarButton($name, $caption, $url, $hint, $enabled, $enabledImage, $disabledImage);
00273     }
00274 
00275     public function showButton($name)
00276     {
00277         $this->toolBarButtons[$name]->show();
00278     }
00279 
00280     public function hideButton($name)
00281     {
00282         $this->toolBarButtons[$name]->hide();
00283     }
00284 
00285     public function enableButton($name)
00286     {
00287         $this->toolBarButtons[$name]->enable();
00288     }
00289 
00290     public function disableButton($name)
00291     {
00292         $this->toolBarButtons[$name]->disable();
00293     }
00294 
00295     public function setIsPost($name,$post=true)
00296     {
00297         $this->toolBarButtons[$name]->setMethod( $post ? 'post' : '' );
00298     }
00299 
00300     public function generateInner()
00301     {
00302         parent::__construct( $this->name, '', $this->getButtons() );
00303         parent::generateInner();
00304     }
00305 }
00306 
00307 ?>
CopyLeft (L) 2001-2006 - [MIOLO Development Team] SOLIS - Cooperativa de Soluções Livres - Lajeado/RS - Brasil