source: sandbox/webservice/api/rest/admin/CommonFunctions.php @ 7878

Revision 7878, 2.8 KB checked in by alexandrecorreia, 11 years ago (diff)

Ticket #2507 - Retira os caracteres especiais dentro do nome e do campo descricao

  • Property svn:executable set to *
Line 
1<?php
2
3class CommonFunctions
4{
5        public function convertChar($param)
6        {
7                $param = mb_convert_encoding( $param ,"UTF8", "ISO_8859-1" );
8
9                $array1 = array( "á", "à", "â", "ã", "À", "é", "Ú", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ÃŽ", "õ", "ö", "ú", "ù", "û", "ÃŒ", "ç"
10                , "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç" );
11               
12                $array2 = array( "a", "a", "a", "a", "a", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u", "c"
13                , "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C" );
14               
15                return str_replace( $array1, $array2, $param);
16        }
17
18        public function mascaraCPF($param)
19        {
20                $cpf = trim(preg_replace("/[^0-9]/", "", $param));
21
22                return preg_replace('/(\d{3})(\d{3})(\d{3})/','$1.$2.$3-',$cpf);
23        }
24
25        public function mascaraPhone($param)
26        {
27                $phone = trim(preg_replace("/[^0-9]/", "", $param));
28
29                return preg_replace('/(\d{2})(\d{4})(\d{4})/','($1)$2-$3',$phone);
30        }
31
32        public function validatePassword($param)
33        {
34                $sizePassword = strlen(trim($param));
35               
36                $numbers = strlen(preg_replace("/[^0-9]/", "", trim($param)));
37
38                $return['status'] = true;
39
40                if( (int)$sizePassword < 8 )
41                {
42                        $return["status"] = false;
43                        $return["msg"] = "you need a minimum of 8 characters for the password";
44                }
45                else
46                {
47                        if( (int)$numbers < 2 )
48                        {
49                                $return["status"] = false;
50                                $return["msg"] = "must have 2 numbers in the password";
51                        }
52                }       
53
54                return $return;
55        }
56
57        public function validateCharacters( $params, $field = false)   
58        {
59                if( $field && $field === "accountLogin" )
60                        $search = trim(preg_replace("/[^a-z_0-9_A-Z_-_.]/", "", $params));
61                else
62                        $search = trim(preg_replace("/[^a-z_0-9_A-Z_-_._@\\s]/", "", $params));
63
64                $return['status'] = true;
65
66                if( strtolower($search) != strtolower(trim($params)) )
67                {
68                        $return['status'] = false;
69                        $return['msg'] = "Field contains characters not allowed";
70                }
71
72                return $return;
73        }
74
75        public function validateCPF( $cpf )
76        {
77                $seqInvalid = array('11111111111','22222222222','33333333333',
78                                                        '44444444444','55555555555','66666666666',
79                                                        '77777777777','88888888888','99999999999',
80                                                        '00000000000', '12345678909');
81               
82                $cpf = trim(preg_replace("/[^0-9]/", "", $cpf));
83
84                if( strlen($cpf) != 11 )
85                        return False;
86
87                if( in_array( $cpf, $seqInvalid ) )
88                {
89                        return False;
90                }
91
92                $a = 0;
93               
94                for( $i = 0 ; $i < 9 ; $i++ )
95                {
96                        $a += ($cpf[$i]*(10 - $i));
97                }
98
99                $b = ($a % 11);
100               
101                $a = ( ($b > 1) ? (11 - $b) : 0);
102               
103                if( $a != $cpf[9] )
104                {
105                        return False;
106                }
107               
108                $a = 0;
109
110                for ( $i=0; $i < 10; $i++ )
111                {
112                        $a += ($cpf[$i]*(11 - $i));
113                }
114
115                $b = ($a % 11);
116
117                $a = (($b > 1) ? (11 - $b) : 0);
118               
119                if( $a != $cpf[10] )
120                {
121                        return False;
122                }
123
124                return True;
125        }
126}
127
128?>
Note: See TracBrowser for help on using the repository browser.