Supprimer des fichiers inutiles.
[auf_paf.git] / includes / functions_utf8.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
13 //-------Select box------------------------\r
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&ccedil;aise"=>"Fran&ccedil;aise",\r
24 "Fran&ccedil;ais"=>"Fran&ccedil;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&eacute;ologie"=>"Arch&eacute;ologie",\r
45 "Architecture"=>"Architecture",\r
46 "Biologie"=>"Biologie",\r
47 "Chimie"=>"Chimie",\r
48 "Commerce"=>"Commerce",\r
49 "Droit"=>"Droit",\r
50 "Fran&ccedil;ais"=>"Fran&ccedil;ais",\r
51 "G&eacute;nie Civil"=>"G&eacute;nie Civil",\r
52 "G&eacute;nie Electrique"=>"G&eacute;nie Electrique",\r
53 "G&eacute;nie Industriel"=>"G&eacute;nie Industriel",\r
54 "G&eacute;ographie"=>"G&eacute;ographie",\r
55 "G&eacute;ologie"=>"G&eacute;ologie",\r
56 "Gestion"=>"Gestion",\r
57 "Histoire"=>"Histoire",\r
58 "Hydraulique"=>"Hydraulique",\r
59 "Informatique"=>"Informatique",\r
60 "Ing&eacute;nieur"=>"Ing&eacute;nieur",\r
61 "Litt&eacute;rature"=>"Litt&eacute;rature",\r
62 "Linguistique"=>"Linguistique",\r
63 "Math&eacute;matique"=>"Math&eacute;matique",\r
64 "M&eacute;decine"=>"M&eacute;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&eacute;e"=>"Lyc&eacute;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&eacute;"=>"Univ. des Sciences de la Sant&eacute;",\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
116 }\r
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
144 //----------------------One more to work with---------------------------------------------\r
145 //--Veuillez m'aider pour améliorer cette fonction--et envoyer à tclyit@gmail.com\r
146 //--------Vos critiques sont bienvenues!!----------------------------------------\r
147 //----------Encrypt----------------------------\r
148 \r
149 function encrptPwd($string, $key) {\r
150 $result = '';\r
151 for($i=0; $i<strlen($string); $i++){\r
152 $char = substr($string, $i, 1);\r
153 $keychar = substr($key, ($i % strlen($key))-1, 1);\r
154 $char = chr(ord($char)+ord($keychar));\r
155 $result.=$char;\r
156 }\r
157 return base64_encode($result);\r
158 }\r
159\r
160 //----------Decrypt----------------------------\r
161 function decrptPwd($string, $key) {\r
162 $result = '';\r
163 $string = base64_decode($string);\r
164 \r
165 for($i=0; $i<strlen($string); $i++){\r
166 $char = substr($string, $i, 1);\r
167 $keychar = substr($key, ($i % strlen($key))-1, 1);\r
168 $char = chr(ord($char)-ord($keychar));\r
169 $result.=$char;\r
170 }\r
171 return $result;\r
172 }\r
173 //--------------Check Mail----------------------\r
174 \r
175 function check_email($email){\r
176 // First, we check that there's one @ symbol, and that the lengths are right\r
177 if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)){\r
178 return false;\r
179 }\r
180 // Split it into sections\r
181 $email_array = explode("@", $email);\r
182 $local_array = explode(".", $email_array[0]);\r
183 for ($i = 0; $i < sizeof($local_array); $i++){\r
184 if (!ereg("^(([A-Za-z0-9!#$%&#038;'*+/=?^_`{|}~-][A-Za-z0-9!#$%&#038;'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])){\r
185 return false;\r
186 }\r
187 }\r
188// Check if domain is IP. If not, it should be valid domain name\r
189 if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])){\r
190 $domain_array = explode(".", $email_array[1]);\r
191 if (sizeof($domain_array) < 2) {\r
192 return false; // Not enough parts to domain\r
193 }\r
194 for ($i = 0; $i < sizeof($domain_array); $i++){\r
195 if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])){\r
196 return false;\r
197 }\r
198 }\r
199 }\r
200 return true;\r
201}\r
202\r
203//----------------------------Change Date Value---------------------------------\r
204 //===========From DD/MM/YYYY to YYYY/MM/DD==================================\r
205 function ChangeDateValueInsert($Date){\r
206 if($Date != ""){\r
207 $DateChange=split('[-]',$Date);\r
208 $Str="$DateChange[2]/$DateChange[1]/$DateChange[0]";\r
209 return $Str;\r
210 }\r
211 }\r
212 //===========From YYYY/MM/DD to DD/MM/YYYY==================================\r
213 function ChangeDateValueSelect($DateSe){\r
214 if($DateSe != ""){\r
215 $DateChangeSe=split('[-]',$DateSe);\r
216 $StrSe="$DateChangeSe[2]/$DateChangeSe[1]/$DateChangeSe[0]";\r
217 return $StrSe;\r
218 }\r
219 }\r
220 //===========From YYYY/MM/DD to DD/MM/YYYY==================================\r
221?>