1 | <?php |
---|
2 | |
---|
3 | class 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 | { |
---|
61 | $search = trim(preg_replace("/[^a-z_0-9_A-Z_-_.]/", "", $params)); |
---|
62 | } |
---|
63 | else |
---|
64 | { |
---|
65 | if( $field && $field == "accountMailQuota" ) |
---|
66 | $search = trim(preg_replace("/[^0-9_.]/", "", $params)); |
---|
67 | else |
---|
68 | $search = trim(preg_replace("/[^a-z_0-9_A-Z_-_._@\\s]/", "", $params)); |
---|
69 | } |
---|
70 | |
---|
71 | $return['status'] = true; |
---|
72 | |
---|
73 | if( strtolower($search) != strtolower(trim($params)) ) |
---|
74 | { |
---|
75 | $return['status'] = false; |
---|
76 | $return['msg'] = "Field contains characters not allowed"; |
---|
77 | } |
---|
78 | |
---|
79 | return $return; |
---|
80 | } |
---|
81 | |
---|
82 | public function validateCPF( $cpf ) |
---|
83 | { |
---|
84 | $seqInvalid = array('11111111111','22222222222','33333333333', |
---|
85 | '44444444444','55555555555','66666666666', |
---|
86 | '77777777777','88888888888','99999999999', |
---|
87 | '00000000000', '12345678909'); |
---|
88 | |
---|
89 | $cpf = trim(preg_replace("/[^0-9]/", "", $cpf)); |
---|
90 | |
---|
91 | if( strlen($cpf) != 11 ) |
---|
92 | return False; |
---|
93 | |
---|
94 | if( in_array( $cpf, $seqInvalid ) ) |
---|
95 | { |
---|
96 | return False; |
---|
97 | } |
---|
98 | |
---|
99 | $a = 0; |
---|
100 | |
---|
101 | for( $i = 0 ; $i < 9 ; $i++ ) |
---|
102 | { |
---|
103 | $a += ($cpf[$i]*(10 - $i)); |
---|
104 | } |
---|
105 | |
---|
106 | $b = ($a % 11); |
---|
107 | |
---|
108 | $a = ( ($b > 1) ? (11 - $b) : 0); |
---|
109 | |
---|
110 | if( $a != $cpf[9] ) |
---|
111 | { |
---|
112 | return False; |
---|
113 | } |
---|
114 | |
---|
115 | $a = 0; |
---|
116 | |
---|
117 | for ( $i=0; $i < 10; $i++ ) |
---|
118 | { |
---|
119 | $a += ($cpf[$i]*(11 - $i)); |
---|
120 | } |
---|
121 | |
---|
122 | $b = ($a % 11); |
---|
123 | |
---|
124 | $a = (($b > 1) ? (11 - $b) : 0); |
---|
125 | |
---|
126 | if( $a != $cpf[10] ) |
---|
127 | { |
---|
128 | return False; |
---|
129 | } |
---|
130 | |
---|
131 | return True; |
---|
132 | } |
---|
133 | } |
---|
134 | |
---|
135 | ?> |
---|