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