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