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

Revision 7931, 3.2 KB checked in by alexandrecorreia, 11 years ago (diff)

Ticket #2507 - Adicionado o cadastro dos seguintes campos datanascimento,st,city e sexo no ldap

  • 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 mascaraBirthDate($param)
19        {
20                $bDate = trim(preg_replace("/[^0-9]/", "", $param));
21
22                $bDate = preg_replace('/(\d{2})(\d{2})(\d{4})/','$1/$2/$3',$bDate);
23
24                if( preg_match("#/#", $bDate) === 1 )
25                        $strDate = implode("-",array_reverse(explode('/',$bDate)));
26
27                return $strDate;
28        }
29
30        public function mascaraCPF($param)
31        {
32                $cpf = trim(preg_replace("/[^0-9]/", "", $param));
33
34                return preg_replace('/(\d{3})(\d{3})(\d{3})/','$1.$2.$3-',$cpf);
35        }
36
37        public function mascaraPhone($param)
38        {
39                $phone = trim(preg_replace("/[^0-9]/", "", $param));
40
41                return preg_replace('/(\d{2})(\d{4})(\d{4})/','($1)$2-$3',$phone);
42        }
43
44        public function validatePassword($param)
45        {
46                $sizePassword = strlen(trim($param));
47               
48                $numbers = strlen(preg_replace("/[^0-9]/", "", trim($param)));
49
50                $return['status'] = true;
51
52                if( (int)$sizePassword < 8 )
53                {
54                        $return["status"] = false;
55                        $return["msg"] = "you need a minimum of 8 characters for the password";
56                }
57                else
58                {
59                        if( (int)$numbers < 2 )
60                        {
61                                $return["status"] = false;
62                                $return["msg"] = "must have 2 numbers in the password";
63                        }
64                }       
65
66                return $return;
67        }
68
69        public function validateCharacters( $params, $field = false)   
70        {
71                if( $field && $field === "accountLogin" )
72                {
73                        $search = trim(preg_replace("/[^a-z_0-9_A-Z_-_.]/", "", $params));
74                }
75                else
76                {
77                        if( $field && $field == "accountMailQuota" )
78                                $search = trim(preg_replace("/[^0-9_.]/", "", $params));
79                        else   
80                                $search = trim(preg_replace("/[^a-z_0-9_A-Z_-_._@\\s]/", "", $params));
81                }
82               
83                $return['status'] = true;
84
85                if( strtolower($search) != strtolower(trim($params)) )
86                {
87                        $return['status'] = false;
88                        $return['msg'] = "Field contains characters not allowed";
89                }
90
91                return $return;
92        }
93
94        public function validateCPF( $cpf )
95        {
96                $seqInvalid = array('11111111111','22222222222','33333333333',
97                                                        '44444444444','55555555555','66666666666',
98                                                        '77777777777','88888888888','99999999999',
99                                                        '00000000000', '12345678909');
100               
101                $cpf = trim(preg_replace("/[^0-9]/", "", $cpf));
102
103                if( strlen($cpf) != 11 )
104                        return False;
105
106                if( in_array( $cpf, $seqInvalid ) )
107                {
108                        return False;
109                }
110
111                $a = 0;
112               
113                for( $i = 0 ; $i < 9 ; $i++ )
114                {
115                        $a += ($cpf[$i]*(10 - $i));
116                }
117
118                $b = ($a % 11);
119               
120                $a = ( ($b > 1) ? (11 - $b) : 0);
121               
122                if( $a != $cpf[9] )
123                {
124                        return False;
125                }
126               
127                $a = 0;
128
129                for ( $i=0; $i < 10; $i++ )
130                {
131                        $a += ($cpf[$i]*(11 - $i));
132                }
133
134                $b = ($a % 11);
135
136                $a = (($b > 1) ? (11 - $b) : 0);
137               
138                if( $a != $cpf[10] )
139                {
140                        return False;
141                }
142
143                return True;
144        }
145}
146
147?>
Note: See TracBrowser for help on using the repository browser.