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 / 10
CRAP
0.00% covered (danger)
0.00%
0 / 31
TCpfCnpj
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 10
210
0.00% covered (danger)
0.00%
0 / 31
 __construct
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 9
 show
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 4
 getFormated
0.00% covered (danger)
0.00%
0 / 1
20
0.00% covered (danger)
0.00%
0 / 8
 getValue
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setInvalidMessage
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getInvalidMessage
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setAlwaysValidate
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getAlwaysValidate
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 setCallback
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getCallback
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 entrada de dados tipo CNPJ
44*/
45class TCpfCnpj extends TMask
46{
47    private $invalidMessage;
48    private $alwaysValidate;
49    private $callback;
50    /**
51    * Metódo construtor
52    *
53    * @param string $strName
54    * @param string $strValue
55    * @param boolean $boolRequired
56    * @return TCpfCnpj
57    */
58    public function __construct($strName,$strValue=null,$boolRequired=null,$strInvalidMessage=null, $boolAwaysValidate = null,$strJsCallback=null)
59    {
60        parent::__construct($strName,$strValue,'',$boolRequired);
61        $this->setFieldType('cpfcnpj');
62        $this->setEvent('onkeyup','fwFormataCpfCnpj(this,event)');
63        $this->setEvent('onblur','fwValidarCpfCnpj(this,event)');
64        $this->setSize(19);
65        $this->setInvalidMessage($strInvalidMessage);
66        $this->setAlwaysValidate($boolAwaysValidate);
67        $this->setCallback($strJsCallback);
68    }
69    public function show($print=true)
70    {
71        $this->setAttribute('meta-invalid-message',$this->getInvalidMessage());
72        $this->setAttribute('meta-always-validate',$this->getAlwaysValidate());
73        $this->setAttribute('meta-callback',$this->getCallback());
74        return parent::show($print);
75    }
76    public function getFormated()
77    {
78        if($this->getValue())
79        {
80            $value = @preg_replace("/[^0-9]/","",$this->getValue() );
81            $tamanho = StringHelper::strlen($value);
82            if( $tamanho == 11 ){
83                return substr($value,0,3).".".substr($value,3,3).".".substr($value,6,3)."-".substr($value,9,2);
84            } else if ( $tamanho == 14 ) {
85                return substr($value,0,2).".".substr($value,2,3).".".substr($value,5,3)."/".substr($value,8,4)."-".substr($value,12,2);
86            }
87        }
88        return $this->value();
89    }
90
91    /**
92    * Retorna o CPF CNPJ sem formatação
93    *
94    */
95    public function getValue()
96    {
97        return @preg_replace("/[^0-9]/","",$this->value);
98    }
99
100    public function setInvalidMessage($strNewValue=null)
101    {
102        $this->invalidMessage = $strNewValue;
103    }
104
105    public function getInvalidMessage()
106    {
107        return $this->invalidMessage;
108    }
109    public function setAlwaysValidate($boolNewValue=null)
110    {
111        $this->alwaysValidate = $boolNewValue;
112    }
113
114    public function getAlwaysValidate()
115    {
116        return ($this->alwaysValidate===true) ? 'true' :'false' ;
117    }
118
119    public function setCallback($strJsFunction=null)
120    {
121        $this->callback = $strJsFunction;
122    }
123
124    public function getCallback()
125    {
126        return $this->callback;
127    }
128
129
130}
131/*
132$cpfcnpj = new TCpfCnpjField('num_cpf_cnpj','CPF/CNPJ:',true);
133$cpfcnpj->show();
134*/
135?>