Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 9
CRAP
0.00% covered (danger)
0.00%
0 / 44
THelpBox
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 9
306
0.00% covered (danger)
0.00%
0 / 44
 __construct
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 7
 show
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 4
 getValue
0.00% covered (danger)
0.00%
0 / 1
42
0.00% covered (danger)
0.00%
0 / 19
 setImage
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 3
 getImage
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setDataType
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getDataType
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setFileName
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 6
 getFileName
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 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* Classe para implementação de caixas on-line de apresentação de texto e imágem
44*
45* <code>
46* $frm->addBoxField('campo_1','Informe o nome completo',$this->getBase().'imagens/folder.gif',null,null,null,null,null,null,'Ajuda');
47* $frm->addBoxField('campo_2',null,$this->getBase().'exemplos/ajuda.html','ajax',null,null,null,null,null,'Ver arquivo de ajuda');
48* $frm->addBoxField('campo_3','Este é o texto de ajuda que será exibido quando o usuário clicar na imagem',null,null,null,null,null,null,null,'Exibir ajuda');
49* $frm->addBoxField('campo_y',null,$this->getBase()."js/jquery/facebox/stairs.jpg",'jpg','Visualizar Foto:','folder.gif',true,null,null,'Imagem');
50* </code>
51*/
52class THelpBox extends TControl
53{
54    private $image;
55    private $fileName;
56    private $dataType; // image, ajax
57    public function __construct($strName, $strValue=null, $strFileName=null, $strDataType=null, $strImage=null,$strHint=null)
58    {
59        parent::__construct('div',$strName,$strValue);
60        $this->setFieldType('helpbox');
61        $this->setHint($strHint);
62        $this->setFileName($strFileName);
63        $this->setDataType($strDataType);
64        $this->setImage($strImage);
65    }
66    //--------------------------------------------------------------------
67    public function show($print=true)
68    {
69        $this->clearChildren();
70
71        $this->add($this->getValue());
72        $this->setValue(null);
73        return parent::show($print);
74    }
75    //----------------------------------------------------------------------
76    public function getValue()
77    {
78        $e = new TButton('btn_help_box_'.$this->getId());
79        $e->setImage($this->image);
80        $value = $this->value;
81        $isImage=false;
82        // verificar so texto ou o nome do arquivo é uma imagem
83        if( FormDinHelper::pregMatch('/\.(jpe?g|gif|bmp|png)$/i',$value.$this->getFileName()))
84        {
85            $isImage=true;
86            $this->setDataType('image');
87        }
88        if( $this->getFileName())
89        {
90            $value=$this->getFileName();
91            $this->setValue('');
92            if(!$this->getDataType())
93            {
94                $this->setDataType('ajax');
95            }
96        }
97        /*
98        if($this->getDataType())
99        {
100            $value = '{"'.$this->getDataType().'":"'.$value.'"}';
101        }
102        else
103        {
104            $value ="'".$value."'";
105        }
106        */
107        //$value = preg_replace("/".chr(10)."/",'',$value);
108        $value = str_replace( chr(10),'<br\>' ,$value );
109        if( $this->getDataType() == 'ajax')
110        {
111            $e->setOnClick('fwFaceBox("'.$value.'",true)');
112        }
113        else
114        {
115            if( $isImage )
116            {
117                $e->setOnClick('fwFaceBox("'.$value.'",true)');
118            }
119            else
120            {
121                $e->setOnClick('fwFaceBox("'.$value.'",false)');
122            }
123        }
124        return $e;
125    }
126    public function setImage($strImage=null)
127    {
128        $strImage = is_Null($strImage) ? 'icon_help-16x16.png' : $strImage;
129        $this->image = $strImage;
130    }
131    public function getImage($strImage=null)
132    {
133        return $this->image;
134    }
135    public function setDataType($strNewValue=null)
136    {
137        $this->dataType = $strNewValue;
138    }
139    public function getDataType()
140    {
141        return $this->dataType;
142    }
143    public function setFileName($strFileName=null)
144    {
145        $this->fileName = $strFileName;
146        if( $this->fileName)
147        {
148            if( !$this->getHint())
149            {
150                $this->setHint( parent::getValue() );
151            }
152            $this->setValue('');
153        }
154    }
155    public function getFileName()
156    {
157        return $this->fileName;
158    }
159
160}
161//$val = new THelpBox('hlpTeste','Ajuda texto de exemplo');
162//$val->show();
163?>