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 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 23
TCaptcha
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 3
132
0.00% covered (danger)
0.00%
0 / 23
 __construct
0.00% covered (danger)
0.00%
0 / 1
56
0.00% covered (danger)
0.00%
0 / 17
 getInput
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 validate
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 5
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 */
41class TCaptcha extends TButton
42{
43    private $input;
44    public function __construct($strName,$strHint=null,$intCaracters=null)
45    {
46        $intCaracters = is_null($intCaracters) ? 6 : $intCaracters;
47        $intCaracters = $intCaracters > 10 ? 10 : $intCaracters;
48        $strName = isset($strName) ? $strName : null;
49        $strValue = isset($strValue) ? $strValue : null;
50        
51        $url = $this->getBase().'classes/captcha/CaptchaSecurityImages.class.php?field='.$this->removeIllegalChars($strName).( is_null( $intCaracters ) ? '' : '&characters='.$intCaracters);
52        parent::__construct($strName.'_img',$strValue,null,"javascript:this.src='".$url."&'+ Math.random()",null,null,null,'Código de Segurança - Digite no campo ao lado os caracteres que estão impressos nesta imagem!');
53        //parent::__construct($strName.'_img',$strValue,null,"javascript:document.getElementById('".$strName."_img').src = '".$url."&'+ Math.random()",null,null,null,'Clique aqui para atualizar a imagem!');
54        $this->setFieldType('captcha');
55        $this->setImage($url);
56        $this->input = new TEdit($strName,null,6,true,6);
57        $this->input->setHeight(25);
58        $this->input->setCss('font-size','14px');
59        $this->input->setCss('font-weight','bold');
60        $this->input->setProperty('autocomplete','off');
61        //$this->input->setValue('');
62        if(!is_null($strHint) )
63        {
64            $this->setHint($strHint);
65        }
66        $this->add($this->input);
67    }
68    public function getInput()
69    {
70        return $this->input;
71    }
72    public function validate()
73    {
74        if( strtolower($this->removeIllegalChars($this->getInput()->getValue())) != strtolower($this->removeIllegalChars($_SESSION[$this->getInput()->getId().'_code'])) )
75        {
76            /*$this->setError(strtolower($this->removeIllegalChars($this->getInput()->getValue())) .' e '.
77            strtolower($this->removeIllegalChars($_SESSION[$this->getInput()->getId().'_code'])) );
78            //'Códigos de segurança não foi digitado corretamente!');
79            */
80            if( $this->getInput()->getValue() != '' )
81            {
82                $this->setError('digitado incorretamente!');
83            }
84            else
85            {
86                $this->setError('obrigat&oacute;rio!');
87            }
88        }
89
90        return ( (string)$this->getError()==="" );
91    }
92}
93/*$f = new TCaptcha('des_captcha',null,6,true);
94$f->show();
95*/
96?>