Suppression des droits d'exécution des fichiers.
[auf_paf.git] / includes / functions.php
CommitLineData
98ff4c8e 1<?php\r
2 function format_date($date){\r
3 //$date = array_shift;\r
4 \r
5 if ($date == -1){ return "&nbsp;"; }\r
6 \r
7 $date *= 24 * 3600;\r
8 list($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($date);\r
9 return ( 1900 + $year ) . "-" . ++$mon . "-" . ++$mday;\r
10 //return date('Y-m-d',$date);\r
11 }\r
12 \r
6aa01cfc 13 /*//-------Select box------------------------\r
98ff4c8e 14 \r
15 $Nationalite = array(\r
16 "Cambodgienne"=>"Cambodgienne",\r
17 "Cambodgien"=>"Cambodgien",\r
18 "Belge"=>"Belge",\r
19 "Canadienne"=>"Canadienne",\r
20 "Canadien"=>"Canadien",\r
21 "Chinoise"=>"Chinoise",\r
22 "Chinois"=>"Chinois",\r
23 "Française"=>"Française",\r
24 "Français"=>"Français",\r
25 "Laotienne"=>"Laotienne",\r
26 "Laotien"=>"Laotien",\r
27 "Suisse"=>"Suisse",\r
28 "Vietnamienne"=>"Vietnamienne",\r
29 "Vietnamien"=>"Vietnamien",\r
30 "Malagasy"=>"Malagasy",\r
31 "Autre"=>"Autre");\r
32 \r
33 $Activite = array(\r
34 "??"=>"??",\r
35 "AUF"=>"AUF",\r
36 "Etudiant"=>"Etudiant",\r
37 "Enseignant"=>"Enseignant",\r
38 "Autre"=>"Autre");\r
39 \r
40 $Domaine = array(\r
41 "??"=>"??",\r
42 "Agronomie"=>"Agronomie",\r
43 "Anglais"=>"Anglais",\r
44 "Archéologie"=>"Archéologie",\r
45 "Architecture"=>"Architecture",\r
46 "Biologie"=>"Biologie",\r
47 "Chimie"=>"Chimie",\r
48 "Commerce"=>"Commerce",\r
49 "Droit"=>"Droit",\r
50 "Français"=>"Français",\r
51 "Génie Civil"=>"Génie Civil",\r
52 "Génie Electrique"=>"Génie Electrique",\r
53 "Génie Industriel"=>"Génie Industriel",\r
54 "Géographie"=>"Géographie",\r
55 "Géologie"=>"Géologie",\r
56 "Gestion"=>"Gestion",\r
57 "Histoire"=>"Histoire",\r
58 "Hydraulique"=>"Hydraulique",\r
59 "Informatique"=>"Informatique",\r
60 "Ingénieur"=>"Ingénieur",\r
61 "Littérature"=>"Littérature",\r
62 "Linguistique"=>"Linguistique",\r
63 "Mathématique"=>"Mathématique",\r
64 "Médecine"=>"Médecine",\r
65 "Odontostomatologie"=>"Odontostomatologie",\r
66 "Pharmacie"=>"Pharmacie",\r
67 "Philosophie"=>"Philosophie",\r
68 "Technicien"=>"Technicien",\r
69 "Touriste"=>"Touriste");\r
70 \r
71 $Etablissement = array(\r
72 "??"=>"??",\r
73 "AUF"=>"AUF",\r
74 "Ecole Royale d'Administration"=>"Ecole Royale d'Administration",\r
75 "Faculty of Business"=>"Faculty of Business",\r
76 "ITC"=>"ITC",\r
77 "Lycée"=>"Lycée",\r
78 "Univ. Royale de Phnom Penh"=>"Univ. Royale de Phnom Penh",\r
79 "Univ. Royale des Beaux-Arts"=>"Univ. Royale des Beaux-Arts",\r
80 "Univ. Royale d'Agronomie"=>"Univ. Royale d'Agronomie",\r
81 "Univ. des Sciences de la Santé"=>"Univ. des Sciences de la Santé",\r
82 "Univ. de Droit et Siences-Eco"=>"Univ. de Droit et Siences-Eco");\r
83 \r
84 $Groupe = array(\r
85 "Usagers"=>"Usagers",\r
86 "CNF"=>"CNF",\r
87 "Admin"=>"Admin");\r
88 \r
89 //================Array to select box================================================\r
90 function ArrayToSelectBox($arr,$sel = '',$usekey=1,$nullvalue='') {\r
91 while (list( $key, $val ) = each($arr)) {\r
92 if($sel && $usekey && ($key == $sel || is_array($sel) && in_array($key,$sel))) {\r
93 $select_v=" selected='selected'";\r
94 } else if ($sel && !$usekey && ($val == $sel || is_array($sel) && in_array($val,$sel))) {\r
95 $select_v=" selected='selected'";\r
96 } else {\r
97 $select_v='';\r
98 }\r
99 \r
100 if($nullvalue != '') {\r
101 if ($key == $nullvalue) {\r
102 $key = ''; \r
103 }\r
104 }\r
105 \r
106 if ($usekey == 1) {\r
107 echo "<option value=\"$key\"$select_v>$val</option>\n";\r
108 } else {\r
109 if(($nullvalue != '') && ($key == '')) {\r
110 echo "<option value=\"$key\"$select_v>$val</option>\n";\r
111 } else {\r
112 echo "<option$select_v>$val</option>\n";\r
113 }\r
114 }\r
115 }\r
6aa01cfc 116 }*/\r
98ff4c8e 117 \r
118 //---------------------Encrypt Password---------------------------------------------------\r
119 \r
120 function EncryptPsWord($password) {\r
121 mt_srand((double)microtime()*1000000);\r
122 $salt = mhash_keygen_s2k(MHASH_SHA1, $password, substr(pack('h*', md5(mt_rand())), 0, 8), 4);\r
123 $hash = "{BBCSR}".base64_encode(mhash(MHASH_SHA1, $password.$salt).$salt);\r
124 return $hash;\r
125 }\r
126 //---------------------Decrypt Password---------------------------------------------------\r
127 function DecryptPsWord($password, $hash) {\r
128 $hash = base64_decode(substr($hash, 6));\r
129 $original_hash = substr($hash, 0, 20);\r
130 $salt = substr($hash, 20);\r
131 $new_hash = mhash(MHASH_SHA1, $password . $salt);\r
132 if (strcmp($original_hash, $new_hash) == 0){\r
133 // ... do something because your password is valid ...\r
134 /*echo"Bravo.......!!<br>";\r
135 echo $original_hash."<br>";\r
136 echo $new_hash;*/\r
137 return 1;\r
138 }else{\r
139 //echo 'Unauthorized: Authorization has been refused for the credentials you provided. Please login with a valid username and password.';\r
140 return 0;\r
141 //... be sure to clear your session data ... \r
142 }\r
143 }\r
6aa01cfc
CT
144 \r
145\r
98ff4c8e 146 //----------Encrypt----------------------------\r
147 \r
148 function encrptPwd($string, $key) {\r
149 $result = '';\r
150 for($i=0; $i<strlen($string); $i++){\r
151 $char = substr($string, $i, 1);\r
152 $keychar = substr($key, ($i % strlen($key))-1, 1);\r
153 $char = chr(ord($char)+ord($keychar));\r
154 $result.=$char;\r
155 }\r
156 return base64_encode($result);\r
157 }\r
158\r
159 //----------Decrypt----------------------------\r
160 function decrptPwd($string, $key) {\r
161 $result = '';\r
162 $string = base64_decode($string);\r
163 \r
164 for($i=0; $i<strlen($string); $i++){\r
165 $char = substr($string, $i, 1);\r
166 $keychar = substr($key, ($i % strlen($key))-1, 1);\r
167 $char = chr(ord($char)-ord($keychar));\r
168 $result.=$char;\r
169 }\r
170 return $result;\r
171 }\r
172 //--------------Check Mail----------------------\r
173 \r
174 function check_email($email){\r
175 // First, we check that there's one @ symbol, and that the lengths are right\r
176 if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)){\r
177 return false;\r
178 }\r
179 // Split it into sections\r
180 $email_array = explode("@", $email);\r
181 $local_array = explode(".", $email_array[0]);\r
182 for ($i = 0; $i < sizeof($local_array); $i++){\r
183 if (!ereg("^(([A-Za-z0-9!#$%&#038;'*+/=?^_`{|}~-][A-Za-z0-9!#$%&#038;'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])){\r
184 return false;\r
185 }\r
186 }\r
187// Check if domain is IP. If not, it should be valid domain name\r
188 if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])){\r
189 $domain_array = explode(".", $email_array[1]);\r
190 if (sizeof($domain_array) < 2) {\r
191 return false; // Not enough parts to domain\r
192 }\r
193 for ($i = 0; $i < sizeof($domain_array); $i++){\r
194 if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])){\r
195 return false;\r
196 }\r
197 }\r
198 }\r
199 return true;\r
200}\r
201\r
202//----------------------------Change Date Value---------------------------------\r
203 //===========From DD/MM/YYYY to YYYY/MM/DD==================================\r
204 function ChangeDateValueInsert($Date){\r
205 if($Date != ""){\r
206 $DateChange=split('[-]',$Date);\r
207 $Str="$DateChange[2]/$DateChange[1]/$DateChange[0]";\r
208 return $Str;\r
209 }\r
210 }\r
211 //===========From YYYY/MM/DD to DD/MM/YYYY==================================\r
212 function ChangeDateValueSelect($DateSe){\r
213 if($DateSe != ""){\r
214 $DateChangeSe=split('[-]',$DateSe);\r
215 $StrSe="$DateChangeSe[2]/$DateChangeSe[1]/$DateChangeSe[0]";\r
216 return $StrSe;\r
217 }\r
218 }\r
219 //===========From YYYY/MM/DD to DD/MM/YYYY==================================\r
6aa01cfc 220?>\r