Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
29.03% covered (danger)
29.03%
9 / 31
CRAP
14.60% covered (danger)
14.60%
20 / 137
TControl
0.00% covered (danger)
0.00%
0 / 1
29.03% covered (danger)
29.03%
9 / 31
3867.53
14.60% covered (danger)
14.60%
20 / 137
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
7 / 7
 show
0.00% covered (danger)
0.00%
0 / 1
650
0.00% covered (danger)
0.00%
0 / 59
 setFieldType
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getFieldType
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setTop
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getTop
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setLeft
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getLeft
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setFontColor
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getFontColor
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setWidth
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getWidth
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 3
 setHeight
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getHeight
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 3
 setVisible
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 4
 getVisible
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getRequired
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setError
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 addError
0.00% covered (danger)
0.00%
0 / 1
30
0.00% covered (danger)
0.00%
0 / 7
 getError
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setEnabled
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
3 / 3
 getEnabled
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 clear
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setHint
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getHint
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setHelpOnLine
0.00% covered (danger)
0.00%
0 / 1
132
0.00% covered (danger)
0.00%
0 / 15
 getHelpOnLine
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 8
 setTooltip
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 3
 getTooltip
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setReadOnly
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getReadOnly
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
1<?php
2/*
3 * Formdin Framework
4 * Copyright (C) 2012 Ministério do Planejamento
5 * Criado por Luís Eugênio Barbosa
6 * Essa versão é um Fork https://github.com/bjverde/formDin
7 *
8 * ----------------------------------------------------------------------------
9 * This file is part of Formdin Framework.
10 *
11 * Formdin Framework is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License version 3
13 * as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License version 3
21 * along with this program; if not,  see <http://www.gnu.org/licenses/>
22 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
23 * Fifth Floor, Boston, MA  02110-1301, USA.
24 * ----------------------------------------------------------------------------
25 * Este arquivo é parte do Framework Formdin.
26 *
27 * O Framework Formdin é um software livre; você pode redistribuí-lo e/ou
28 * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
29 * do Software Livre (FSF).
30 *
31 * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
32 * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
33 * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
34 * para maiores detalhes.
35 *
36 * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
37 * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
38 * ou escreva para a Fundação do Software Livre (FSF) Inc.,
39 * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
40 */
41
42
43/**
44* classe raiz de todos os controles que podem ser inseridos em um TForm
45* Possui as propriedades:
46* type, name, value, height, width, top, left, fontColor e visible
47*/
48abstract class TControl extends TElement
49{
50    protected $fldType;
51    private $error;
52    private $enabled;
53    private $helpFile;
54    private $tooltip;
55    private $readOnly;
56
57    public function __construct( $tagType, $strName, $strValue = null )
58    {
59        parent::__construct( $tagType );
60        $this->setClass( 'fwField' );
61        $this->setFieldType( 'edit' );
62        $this->setName( $strName );
63        $this->setValue( $strValue );
64        $this->setEnabled( true );
65    }
66
67    public function show( $print = true )
68    {
69
70        // se tiver top ou left a posicao sera absoluta
71        if ( (string)$this->getTop() != "" || (string)$this->getLeft() != "" )
72        { $this->setCss( 'position', 'absolute' ); }
73        else
74        { $this->setCss( 'position', 'relative' ); }
75
76        // colocar o tipo do campo na propriedade
77        $this->setProperty( 'fieldtype', $this->getFieldType() );
78
79        // propriedades que o campo oculto nao precisa
80        if ( $this->getFieldType() == 'hidden' )
81        {
82            $this->setProperty( 'size', null );
83            $this->setProperty( 'maxlength', null );
84            $this->clearCss();
85        }
86
87        if($this->getReadOnly())
88        {
89            $this->setProperty('readonly' ,'true');
90            if( $this->getClass() == 'fwField' || $this->getClass() == ''  )
91            {
92                $this->setClass('fwField fwFieldReadonly'.($this->getClass()=='fwField'?'':' '.$this->getClass()),false);
93            }
94        }
95        if ( !$this->getEnabled() )
96        { $this->setProperty( 'disabled', 'true' ); }
97
98        // como os campos desabilitados, não são postados,
99        // criar os campos ocultos para nao perder os valores quando o form for postado
100        $disableHtml=null;
101
102        if ( $this->getEnabled() == false )
103        {
104            if ( $this->getTagType() == 'img' )
105            {
106            // ainda não tenho o que fazer com uma imagem desabilitada
107            }
108            else
109            {
110
111                /*
112                if ( !$this->getCss( 'color' ) )
113                {
114                       $this->setcss( 'color', '#52A100' );
115                   }
116                if( $this->getFieldType() != 'link' &&  $this->getFieldType() != 'tag' )
117                {
118                    if( ! $this->getcss( 'background-color') )
119                    {
120                        $this->setcss( 'background-color', '#F3F3F3' );
121                    }
122                    if( ! $this->getcss( 'border') )
123                    {
124                        $this->setcss( 'border', '1px solid silver' );
125                    }
126                }
127                */
128                $this->setClass($this->getClass().' fwFieldDisabled',false);
129                $this->setEvent( null );
130                $value=$this->getValue();
131
132                // campo memo é uma tag textarea então não pode ter um campo oculto relacionado a ele, basta colocar readonly
133                if ( $this->getFieldType() == 'memo' )
134                {
135                    $this->setProperty( 'disabled', null );
136                    $this->setProperty( 'readonly', 'true' );
137                    $this->setEnabled( true );
138                }
139                else if( $this->getFieldType() === "select" )
140                {
141                    $h=new THidden( $this->getName() );
142                    if( $this->getRequired() )
143                    {
144                           $h->setProperty('needed','true');
145                    }
146                    // se o campo estiver em um gride ele é um array então fazer a jogada com o neme e id conforma abaixo
147                    $h->setId( $this->getId() );
148                    $this->setName( $this->getId() );
149                    $h->clearCss();
150
151                    if ( isset( $value ) )
152                    { $h->setValue( $value ); }
153
154                    //$this->add($h);
155                    $disableHtml=$h->show( false );
156                }
157                else if( $this->getFieldType() === 'multiselect' )
158                {
159                    forEach( $value as $k => $v )
160                    {
161                        $h = new THidden( $this->getId().'[]' );
162                        $h->clearCss();
163                        $h->setValue( $v );
164                        if( $this->getRequired() )
165                        {
166                               $h->setProperty('needed','true');
167                        }
168                           //$h->setProperty('required',($this->getRequired()?'true':'false'));
169                        $disableHtml .= $h->show( false );
170                    //$this->add($h);
171                    }
172                }
173                else if( !is_array( $this->getValue() ) )
174                {
175                    if( $this->getTagType() != 'button' )
176                    {
177                        $h=new THidden( $this->getName() );
178                        // se o campo estiver em um gride ele é um array então fazer a jogada com o neme e id conforma abaixo
179                        $h->setId( $this->getId() );
180                        $this->setName( $this->getId() );
181
182                        $h->clearCss();
183                        $h->setValue( $this->getValue() );
184                        if( $this->getRequired() )
185                        {
186                               $h->setProperty('needed','true');
187                        }
188                        //$this->add($h);
189                        $disableHtml=$h->show( false );
190                    }
191                }
192
193                // acrecentar disabled ao id para diferenciar do campo oculto criado automaticamente para os campos desabilitados
194                if ( strpos( $this->getId(), '_disabled' ) === false && !$this->getEnabled() )
195                {
196                    if( $this->getTagType() != 'button' )
197                    {
198                        $this->setId( $this->getId().'_disabled' );
199                    }
200                }
201            }
202        }
203
204           // se o campo tiver erro, ajustar a cor da borda para vermelha
205        if($this->getError()){
206            $this->setCss( 'border',  '1px solid #ff0000' ); //#176 relacionado com FormDin4.js
207            //$this->setClass('fwFieldRequiredBoard');
208        }
209        return parent::show( $print ).$disableHtml.$this->getHelpOnLine();
210    }
211
212    //-------------------------------------------------------------------------
213    public function setFieldType( $newFieldType )
214    {
215        $this->fldType=$newFieldType;
216        return $this;
217    }
218
219    public function getFieldType()
220    { return strtolower( $this->fldType ); }
221    /*public function setValue($newValue)
222    {
223        $this->value=$newValue;
224    }
225    //------------------------------------------------------------------------
226    public function getValue()
227    {
228        return $this->value;
229    }
230    */
231    public function setTop( $newTop = null )
232    { $this->setCss( 'top', $newTop ); return $this;}
233
234    public function getTop()
235    { return $this->getCss( 'top' ); }
236
237    public function setLeft( $newLeft = null )
238    { $this->setCss( 'left', $newLeft ); return $this;}
239
240    public function getLeft()
241    { return (string)$this->getCss( 'left' ); }
242
243    //-------------------------------------------------------------------------
244    public function setFontColor( $newFontColor = null )
245    { $this->setCss( 'color', $newFontColor ); return $this;}
246
247    public function getFontColor()
248    { return (string)$this->getCss( 'color' ); }
249
250    //-------------------------------------------------------------------------
251    public function setWidth( $newWidth = null )
252    { $this->setCss( 'width', $newWidth ); return $this; }
253
254    public function getWidth( $strMinWidth = null )
255    {
256        if ( (string)$this->getCss( 'width' ) == "" )
257        { return $strMinWidth; }
258
259        return (string)$this->getCss( 'width' );
260    }
261
262    //-------------------------------------------------------------------------
263    public function setHeight( $newHeight = null )
264    { $this->setCss( 'height', $newHeight ); return $this;}
265
266    public function getHeight( $strMinHeight = null )
267    {
268        if ( (string)$this->getCss( 'height' ) == "" )
269        { return $strMinHeight; }
270
271        return (string)$this->getCss( 'height' );
272    }
273
274    //-------------------------------------------------------------------------
275    public function setVisible( $boolNewValue = true )
276    {
277        if ( (bool)$boolNewValue === true )
278        { $this->setCss( 'display', 'inline' ); }
279        else
280        { $this->setCss( 'display', 'none' ); }
281        return $this;
282    }
283
284    //-------------------------------------------------------------------------
285    public function getVisible()
286    { return ($this->getCss( 'display' ) != 'none'); }
287
288    //-------------------------------------------------------------------------
289    /**
290    * Metodo adicionado apenas para não dar conflito com a função de validação do TForm
291    *
292    */
293    public function getRequired()
294    { return false; }
295    /**
296    * Define o erro encontrado no controle
297    *
298    * @param mixed $strNewError
299    */
300    public function setError( $strNewError = null )
301    {
302        $this->error=$strNewError;
303        return $this;
304    }
305    /**
306    * Acrescenta o erro no final da string error com quebra de linha
307    *
308    * @param mixed $strNewError
309    */
310    public function addError( $strNewError = null )
311    {
312        if ( is_array( $strNewError ) )
313        { $strNewError = implode( '\n', $strNewError ); }
314
315        if ( !is_null( $strNewError ) && $strNewError != "" )
316        {
317            $this->error .= isset( $this->error ) ? '\n' : "";
318            $this->error .= $strNewError;
319            return true;
320        }
321
322        return false;
323    }
324
325    public function getError() { return $this->error; }
326
327    public function setEnabled( $newBoolValue = null )  {
328        //print $this->getFieldType();
329        if ( !strpos( '(hidden,html)', $this->getFieldType() ) )
330        {
331        //print ' desabilitei<br>';
332        $this->enabled = $newBoolValue === null ? true : (bool)$newBoolValue; }
333        return $this;
334    }
335
336    public function getEnabled() { return $this->enabled; }
337
338    public function clear() { $this->setValue( null ); }
339
340    public function setHint( $strNewHint = null ){ 
341        $this->setProperty( 'title', $strNewHint );
342        return $this;
343    }
344
345    public function getHint() { return $this->getProperty( 'title' ); }
346
347    //-----------------------------------------------------------------------------
348    /**
349    * Método para criar ajuda on-line em um form ou campo. Para ajuda de campo pode utilizar tambem 
350    * addBoxField
351    * O parametro $strHelpFile recebe o nome de um arquivo com conteudo html para ser exibido.
352    * O arquivo deverá estar no diretório ajuda/ na raiz da aplicação.
353    *  
354    * Poder ser informada tambem o endereço (url) da pagina de help
355    * 
356    * <code> 
357    * Exemplo01: $nom->setHelpFile('Nome da Pessoa',200,500,'ajuda_form01.html');
358    * Exemplo02: $nom->setHelpFile('Nome da Pessoa',200,500,'http://localhost/sistema/texto_ajuda.html');
359    * Exemplo03: $nom->setHelpFile('Nome da Pessoa',200,500,'Meu texto de ajuda', null, null, false);
360    * </code>
361    * 
362    * @param mixed $strWindowHeader
363    * @param mixed $intShowHeight
364    * @param mixed $intShowWidth
365    * @param mixed $strHelpFile    - nome do arquivo que será carregado dentro do box
366    * @param mixed $strButtonImage - imagem que aparecerá na frente do label
367    * @param boolean $boolReadOnly
368    * @param boolean $showFile     - true mostra o conteudo de um arquivo, FALSE mostra a mensagem de texto informada no $strHelpFile
369    */
370    public function setHelpOnLine( $strWindowHeader = null
371                                 , $intShowHeight = null
372                                 , $intShowWidth = null
373                                 , $strHelpFile = null
374                                 , $strButtonImage = null
375                                 , $boolReadOnly = null
376                                 , $showFile = true)
377    {
378        $strHelpFile      =is_null( $strHelpFile ) ? $this->getId() : $strHelpFile;
379        $this->helpFile[0]=$strHelpFile;
380
381        if ( $strHelpFile )
382        {
383            $this->helpFile[1]=is_null( $strWindowHeader ) ? "Ajuda on-line" : $strWindowHeader;
384            $this->helpFile[2]=is_null( $intShowHeight ) ? 600 : $intShowHeight;
385            $this->helpFile[3]=is_null( $intShowWidth ) ? 800 : $intShowWidth;
386            $this->helpFile[4]=is_null( $strButtonImage ) ? $this->getBase().'imagens/icon_help-16x16.png' : $strButtonImage;
387            $this->helpFile[5]=is_null( $boolReadOnly ) ? false : $boolReadOnly;
388               $this->helpFile[6]='';
389               $this->helpFile[7]=is_null( $showFile ) ? true : $showFile;
390            if( preg_match('/\.\.\//',$this->getBase()) > 0 ) {
391                $this->helpFile[6]=APLICATIVO;
392            }
393            if ( strpos( $this->helpFile[4], '/' ) === false ) {
394                $this->helpFile[4] = $this->getBase().'imagens/'.$this->helpFile[4];
395            }
396        }
397        return $this;
398    }
399
400    //-----------------------------------------------------------------------------
401    public function getHelpOnLine() {
402        if ( is_array( $this->helpFile ) ) {
403               //style="float:right;width:28px; height:15px;vertical-align:top;margin-right:2px;" title="Fechar"
404            //return "<a id=\"".$this->getId()."_help_file_a\" href=\"#\" title=\"{$this->helpFile[1]}\" onClick=\"top.app_modalBox('{$this->helpFile[1]}','".$this->getBase()."callbacks/helpOnLineLoad.php?file={$this->helpFile[0]}&readonly={$this->helpFile[5]}&aplicativo={$this->helpFile[6]}',{$this->helpFile[2]},{$this->helpFile[3]})\"><img style=\"vertical-align:middle;border:none;cursor:pointer;width:16px;height:16px;\" title=\"Ajuda\" src=\"{$this->helpFile[4]}\"></a>";
405
406            if( $this->helpFile[7] == true ){
407                $onClick = "onClick=\"fwModalBox('".$this->helpFile[1]."','".$this->helpFile[0]."','".$this->helpFile[2]."','".$this->helpFile[3]."')";
408            }else{
409                $onClick = "onClick=\"fwFaceBox('".$this->helpFile[0]."')";
410            }            
411            $img = "<img style=\"vertical-align:middle;border:none;cursor:pointer;width:16px;height:16px;\" title=\"Ajuda\" src=\"{$this->helpFile[4]}\">"; 
412            $url = "<a id=\"".$this->getId()."_help_file_a\" href=\"#\" title=\"{$this->helpFile[1]}\" ".$onClick." \">".$img."</a>";
413            return $url;
414        }
415    }
416    //------------------------------------------------------------------------------
417    /**
418     * Set um Toolpit em um determinado campo pode ser usado com
419     * @param string $strTitle - Titulo
420     * @param string $strText - Texto que irá aparecer
421     * @param string $strImagem
422     * @return TControl
423     */
424    public function setTooltip($strTitle=null,$strText=null,$strImagem=null)
425    {
426        $strText = isset($strText)?str_replace(chr(10),'<br/>',$strText):null;
427        //$strTittle = str_replace(chr(10),'',$strText);
428        $this->tooltip = new TTooltip($strTitle,$strText,$strImagem);
429        return $this;
430    }
431    //------------------------------------------------------------------------------
432    public function getTooltip()
433    {
434        return $this->tooltip;
435    }
436    public function setReadOnly($boolNewValue=null)
437    {
438        $this->readOnly = $boolNewValue;
439        return $this;
440    }
441    public function getReadOnly()
442    {
443        return ( $this->readOnly === true) ? true : false;
444    }
445}
446?>