1 | <?php |
---|
2 | include_once (NBC_UserAdvManager_PATH.'include/constants.php'); |
---|
3 | load_language('plugin.lang', NBC_UserAdvManager_PATH); |
---|
4 | |
---|
5 | /* Function called from main.inc.php to send validation email */ |
---|
6 | function SendMail2User($typemail, $id, $username, $password, $email, $confirm) |
---|
7 | { |
---|
8 | global $conf; |
---|
9 | load_language('plugin.lang', NBC_UserAdvManager_PATH); |
---|
10 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
11 | |
---|
12 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
13 | |
---|
14 | $infos1_perso = ""; |
---|
15 | $infos2_perso = ""; |
---|
16 | |
---|
17 | /* We have to get the user's language in database */ |
---|
18 | $query =' |
---|
19 | SELECT user_id, language |
---|
20 | FROM '.USER_INFOS_TABLE.' |
---|
21 | WHERE user_id = '.$id.' |
---|
22 | ;'; |
---|
23 | $data = mysql_fetch_assoc(pwg_query($query)); |
---|
24 | $language = $data['language']; |
---|
25 | /* And switch gallery to this language before using personalized and multilangual contents */ |
---|
26 | switch_lang_to($data['language']); |
---|
27 | |
---|
28 | switch($typemail) |
---|
29 | { |
---|
30 | case 1: |
---|
31 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Add of %s', stripslashes($username))); |
---|
32 | $password = $password <> '' ? $password : l10n('UserAdvManager_empty_pwd'); |
---|
33 | |
---|
34 | if (isset($conf_nbc_UserAdvManager[10]) and $conf_nbc_UserAdvManager[10] <> '') |
---|
35 | { |
---|
36 | if (function_exists('get_user_language_desc')) |
---|
37 | { |
---|
38 | $infos1_perso = get_user_language_desc($conf_nbc_UserAdvManager[10])."\n\n"; |
---|
39 | } |
---|
40 | else $infos1_perso = l10n($conf_nbc_UserAdvManager[10])."\n\n"; |
---|
41 | } |
---|
42 | |
---|
43 | break; |
---|
44 | |
---|
45 | case 2: |
---|
46 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Update of %s', stripslashes($username))); |
---|
47 | $password = $password <> '' ? $password : l10n('UserAdvManager_empty_pwd'); |
---|
48 | |
---|
49 | break; |
---|
50 | |
---|
51 | case 3: |
---|
52 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Update of %s', stripslashes($username))); |
---|
53 | $password = $password <> '' ? $password : l10n('UserAdvManager_no_update_pwd'); |
---|
54 | |
---|
55 | break; |
---|
56 | } |
---|
57 | |
---|
58 | if (isset($conf_nbc_UserAdvManager[0]) and $conf_nbc_UserAdvManager[0] == 'true') |
---|
59 | { |
---|
60 | $infos1 = array( |
---|
61 | get_l10n_args('infos_mail %s', stripslashes($username)), |
---|
62 | get_l10n_args('User: %s', stripslashes($username)), |
---|
63 | get_l10n_args('Password: %s', $password), |
---|
64 | get_l10n_args('Email: %s', $email), |
---|
65 | get_l10n_args('', ''), |
---|
66 | ); |
---|
67 | } |
---|
68 | |
---|
69 | |
---|
70 | if ( isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2] == 'true' and $confirm) |
---|
71 | { |
---|
72 | $infos2 = array |
---|
73 | ( |
---|
74 | get_l10n_args('Link: %s', AddConfirmMail($id, $email)), |
---|
75 | get_l10n_args('', ''), |
---|
76 | ); |
---|
77 | |
---|
78 | if (isset($conf_nbc_UserAdvManager[11]) and $conf_nbc_UserAdvManager[11] <> '') |
---|
79 | { |
---|
80 | if (function_exists('get_user_language_desc')) |
---|
81 | { |
---|
82 | $infos2_perso = get_user_language_desc($conf_nbc_UserAdvManager[11])."\n\n"; |
---|
83 | } |
---|
84 | else $infos2_perso = l10n($conf_nbc_UserAdvManager[11])."\n\n"; |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | /* Sending the email with subject and contents */ |
---|
89 | pwg_mail($email, array( |
---|
90 | 'subject' => $subject, |
---|
91 | 'content' => (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "").get_absolute_root_url(), |
---|
92 | )); |
---|
93 | |
---|
94 | /* Switching back to default language */ |
---|
95 | switch_lang_back(); |
---|
96 | |
---|
97 | /* ********************** */ |
---|
98 | /* Email sending debugger */ |
---|
99 | /* This is only to trace */ |
---|
100 | /* the send of emails for */ |
---|
101 | /* debugging */ |
---|
102 | /* ********************** */ |
---|
103 | // MailLog($email,$subject, $content); |
---|
104 | /* ********************** */ |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | /* Email sending debugger function */ |
---|
109 | //function MailLog ($to, $subject, $content) |
---|
110 | //{ |
---|
111 | // $fo=fopen (NBC_UserAdvManager_PATH.'admin/maillog.txt','a') ; |
---|
112 | // fwrite($fo,"======================\n") ; |
---|
113 | // fwrite($fo,'le ' . date('D, d M Y H:i:s') . "\r\n"); |
---|
114 | // fwrite($fo,$to . "\n" . $subject . "\r\n") ; |
---|
115 | // fwrite($fo, "\n" . $content . "\r\n") ; |
---|
116 | //fwrite($fo, 'Langue : '."\n" . $language . "\r\n") ; |
---|
117 | // fclose($fo) ; |
---|
118 | //return mail ($to,$subject) ; |
---|
119 | //} |
---|
120 | |
---|
121 | |
---|
122 | /* Function called from UserAdvManager_admin.php to resend validation email with or without new validation key */ |
---|
123 | function ResendMail2User($typemail, $user_id, $username, $email, $confirm) |
---|
124 | { |
---|
125 | global $conf; |
---|
126 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
127 | $conf_nbc_UserAdvManager_ConfirmMail = isset($conf['nbc_UserAdvManager_ConfirmMail']) ? explode(";" , $conf['nbc_UserAdvManager_ConfirmMail']) : array(); |
---|
128 | |
---|
129 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
130 | |
---|
131 | $infos1_perso = ""; |
---|
132 | $infos2_perso = ""; |
---|
133 | |
---|
134 | /* We have to get the user's language in database */ |
---|
135 | $query =' |
---|
136 | SELECT user_id, language |
---|
137 | FROM '.USER_INFOS_TABLE.' |
---|
138 | WHERE user_id = '.$id.' |
---|
139 | ;'; |
---|
140 | $data = mysql_fetch_assoc(pwg_query($query)); |
---|
141 | $language = $data['language']; |
---|
142 | /* And switch gallery to this language before using personalized and multilangual contents */ |
---|
143 | switch_lang_to($data['language']); |
---|
144 | |
---|
145 | switch($typemail) |
---|
146 | { |
---|
147 | case 1: |
---|
148 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Reminder_with_key_of_%s', $username)); |
---|
149 | |
---|
150 | if (isset($conf_nbc_UserAdvManager_ConfirmMail[2]) and $conf_nbc_UserAdvManager_ConfirmMail[2] <> '' and isset($conf_nbc_UserAdvManager_ConfirmMail[3]) and $conf_nbc_UserAdvManager_ConfirmMail[3] == 'true' and $confirm) |
---|
151 | { |
---|
152 | if (function_exists('get_user_language_desc')) |
---|
153 | { |
---|
154 | $infos1 = get_user_language_desc($conf_nbc_UserAdvManager_ConfirmMail[2])."\n\n"; |
---|
155 | } |
---|
156 | else $infos1 = l10n($conf_nbc_UserAdvManager_ConfirmMail[2])."\n\n"; |
---|
157 | |
---|
158 | $infos2 = array |
---|
159 | ( |
---|
160 | get_l10n_args('Link: %s', ResetConfirmMail($user_id)), |
---|
161 | get_l10n_args('', ''), |
---|
162 | ); |
---|
163 | } |
---|
164 | |
---|
165 | /* Set reminder true */ |
---|
166 | $query = " |
---|
167 | UPDATE ".USER_CONFIRM_MAIL_TABLE." |
---|
168 | SET reminder = 'true' |
---|
169 | WHERE user_id = '".$user_id."' |
---|
170 | ;"; |
---|
171 | pwg_query($query); |
---|
172 | |
---|
173 | break; |
---|
174 | |
---|
175 | case 2: |
---|
176 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Reminder_without_key_of_%s',$username)); |
---|
177 | |
---|
178 | if (isset($conf_nbc_UserAdvManager_ConfirmMail[2]) and $conf_nbc_UserAdvManager_ConfirmMail[2] <> '' and isset($conf_nbc_UserAdvManager_ConfirmMail[3]) and $conf_nbc_UserAdvManager_ConfirmMail[3] == 'true' and !$confirm) |
---|
179 | { |
---|
180 | if (function_exists('get_user_language_desc')) |
---|
181 | { |
---|
182 | $infos1 = get_user_language_desc($conf_nbc_UserAdvManager_ConfirmMail[2])."\n\n"; |
---|
183 | } |
---|
184 | else $infos1 = l10n($conf_nbc_UserAdvManager_ConfirmMail[2])."\n\n"; |
---|
185 | } |
---|
186 | |
---|
187 | /* Set reminder true */ |
---|
188 | $query = " |
---|
189 | UPDATE ".USER_CONFIRM_MAIL_TABLE." |
---|
190 | SET reminder = 'true' |
---|
191 | WHERE user_id = '".$user_id."' |
---|
192 | ;"; |
---|
193 | pwg_query($query); |
---|
194 | |
---|
195 | break; |
---|
196 | } |
---|
197 | |
---|
198 | pwg_mail($email, array( |
---|
199 | 'subject' => $subject, |
---|
200 | 'content' => ($infos1."\n\n").(isset($infos2) ? l10n_args($infos2)."\n\n" : "").get_absolute_root_url(), |
---|
201 | )); |
---|
202 | |
---|
203 | /* Switching back to default language */ |
---|
204 | switch_lang_back(); |
---|
205 | /* ********************** */ |
---|
206 | /* Email sending debugger */ |
---|
207 | /* This is only to trace */ |
---|
208 | /* the send of emails for */ |
---|
209 | /* debugging */ |
---|
210 | /* ********************** */ |
---|
211 | // MailLog($email,$subject); |
---|
212 | /* ********************** */ |
---|
213 | } |
---|
214 | |
---|
215 | |
---|
216 | /* Function called from UserAdvManager_admin.php to send a reminder mail for ghost users */ |
---|
217 | function ghostreminder($user_id, $username, $email) |
---|
218 | { |
---|
219 | global $conf; |
---|
220 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
221 | |
---|
222 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
223 | |
---|
224 | $infos1_perso = ""; |
---|
225 | |
---|
226 | /* We have to get the user's language in database */ |
---|
227 | $query =' |
---|
228 | SELECT user_id, language |
---|
229 | FROM '.USER_INFOS_TABLE.' |
---|
230 | WHERE user_id = '.$id.' |
---|
231 | ;'; |
---|
232 | $data = mysql_fetch_assoc(pwg_query($query)); |
---|
233 | $language = $data['language']; |
---|
234 | /* And switch gallery to this language before using personalized and multilangual contents */ |
---|
235 | switch_lang_to($data['language']); |
---|
236 | |
---|
237 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Ghost_remainder_of_%s', $username)); |
---|
238 | |
---|
239 | if (isset($conf_nbc_UserAdvManager[19]) and $conf_nbc_UserAdvManager[19] <> '' and isset($conf_nbc_UserAdvManager[17]) and $conf_nbc_UserAdvManager[17] == 'true') |
---|
240 | { |
---|
241 | if (function_exists('get_user_language_desc')) |
---|
242 | { |
---|
243 | $infos1 = get_user_language_desc($conf_nbc_UserAdvManager[19])."\n\n"; |
---|
244 | } |
---|
245 | else $infos1 = l10n($conf_nbc_UserAdvManager[19])."\n\n"; |
---|
246 | |
---|
247 | resetlastvisit($user_id); |
---|
248 | } |
---|
249 | |
---|
250 | pwg_mail($email, array( |
---|
251 | 'subject' => $subject, |
---|
252 | 'content' => $infos1.get_absolute_root_url(), |
---|
253 | )); |
---|
254 | |
---|
255 | /* Switching back to default language */ |
---|
256 | switch_lang_back(); |
---|
257 | /* ********************** */ |
---|
258 | /* Email sending debugger */ |
---|
259 | /* This is only to trace */ |
---|
260 | /* the send of emails for */ |
---|
261 | /* debugging */ |
---|
262 | /* ********************** */ |
---|
263 | // MailLog($email,$subject); |
---|
264 | /* ********************** */ |
---|
265 | } |
---|
266 | |
---|
267 | |
---|
268 | /* Function called from functions AddConfirmMail and ResetConfirmMail for validation key generation */ |
---|
269 | function FindAvailableConfirmMailID() |
---|
270 | { |
---|
271 | while (true) |
---|
272 | { |
---|
273 | $id = generate_key(16); |
---|
274 | $query = " |
---|
275 | SELECT COUNT(*) |
---|
276 | FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
277 | WHERE id = '".$id."' |
---|
278 | ;"; |
---|
279 | list($count) = mysql_fetch_row(pwg_query($query)); |
---|
280 | |
---|
281 | if ($count == 0) |
---|
282 | return $id; |
---|
283 | } |
---|
284 | } |
---|
285 | |
---|
286 | |
---|
287 | /* Function called from functions SendMail2User to process unvalidated users and generate validation key link */ |
---|
288 | function AddConfirmMail($user_id, $email) |
---|
289 | { |
---|
290 | global $conf; |
---|
291 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
292 | $Confirm_Mail_ID = FindAvailableConfirmMailID(); |
---|
293 | |
---|
294 | list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); |
---|
295 | |
---|
296 | if (isset($Confirm_Mail_ID)) |
---|
297 | { |
---|
298 | $query = " |
---|
299 | SELECT status |
---|
300 | FROM ".USER_INFOS_TABLE." |
---|
301 | WHERE user_id = '".$user_id."' |
---|
302 | ;"; |
---|
303 | list($status) = mysql_fetch_row(pwg_query($query)); |
---|
304 | |
---|
305 | $query = " |
---|
306 | INSERT INTO ".USER_CONFIRM_MAIL_TABLE." |
---|
307 | (id, user_id, mail_address, status, date_check) |
---|
308 | VALUES |
---|
309 | ('".$Confirm_Mail_ID."', '".$user_id."', '".$email."', '".$status."', null) |
---|
310 | ;"; |
---|
311 | pwg_query($query); |
---|
312 | |
---|
313 | $query = " |
---|
314 | DELETE FROM ".USER_GROUP_TABLE." |
---|
315 | WHERE user_id = '".$user_id."' |
---|
316 | AND ( |
---|
317 | group_id = '".$conf_nbc_UserAdvManager[3]."' |
---|
318 | OR |
---|
319 | group_id = '".$conf_nbc_UserAdvManager[4]."' |
---|
320 | ) |
---|
321 | ;"; |
---|
322 | pwg_query($query); |
---|
323 | |
---|
324 | if (!is_admin() and $conf_nbc_UserAdvManager[9] <> -1) |
---|
325 | { |
---|
326 | $query = " |
---|
327 | UPDATE ".USER_INFOS_TABLE." |
---|
328 | SET status = '".$conf_nbc_UserAdvManager[9]."' |
---|
329 | WHERE user_id = '".$user_id."' |
---|
330 | ;"; |
---|
331 | pwg_query($query); |
---|
332 | } |
---|
333 | |
---|
334 | if ( $conf_nbc_UserAdvManager[3] <> -1 ) |
---|
335 | { |
---|
336 | $query = " |
---|
337 | INSERT INTO ".USER_GROUP_TABLE." |
---|
338 | (user_id, group_id) |
---|
339 | VALUES |
---|
340 | ('".$user_id."', '".$conf_nbc_UserAdvManager[3]."') |
---|
341 | ;"; |
---|
342 | pwg_query($query); |
---|
343 | } |
---|
344 | |
---|
345 | return get_absolute_root_url().NBC_UserAdvManager_PATH.'ConfirmMail.php?key='.$Confirm_Mail_ID; |
---|
346 | } |
---|
347 | } |
---|
348 | |
---|
349 | |
---|
350 | /* Function called from UserAdvManager_admin.php to reset validation key */ |
---|
351 | function ResetConfirmMail($user_id) |
---|
352 | { |
---|
353 | global $conf; |
---|
354 | |
---|
355 | $Confirm_Mail_ID = FindAvailableConfirmMailID(); |
---|
356 | |
---|
357 | list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); |
---|
358 | |
---|
359 | if (isset($Confirm_Mail_ID)) |
---|
360 | { |
---|
361 | $query = " |
---|
362 | UPDATE ".USER_CONFIRM_MAIL_TABLE." |
---|
363 | SET id = '".$Confirm_Mail_ID."' |
---|
364 | WHERE user_id = '".$user_id."' |
---|
365 | ;"; |
---|
366 | pwg_query($query); |
---|
367 | |
---|
368 | $query = " |
---|
369 | UPDATE ".USER_INFOS_TABLE." |
---|
370 | SET registration_date = '".$dbnow."' |
---|
371 | WHERE user_id = '".$user_id."' |
---|
372 | ;"; |
---|
373 | pwg_query($query); |
---|
374 | |
---|
375 | return get_absolute_root_url().NBC_UserAdvManager_PATH.'ConfirmMail.php?key='.$Confirm_Mail_ID; |
---|
376 | } |
---|
377 | } |
---|
378 | |
---|
379 | |
---|
380 | /* Function called from function_UserAdvManager.inc.php to reset last visit date after sending a reminder */ |
---|
381 | function resetlastvisit($user_id) |
---|
382 | { |
---|
383 | global $conf; |
---|
384 | |
---|
385 | list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); |
---|
386 | |
---|
387 | $query = " |
---|
388 | UPDATE ".USER_LASTVISIT_TABLE." |
---|
389 | SET lastvisit = '".$dbnow."', reminder = 'true' |
---|
390 | WHERE user_id = '".$user_id."' |
---|
391 | ;"; |
---|
392 | pwg_query($query); |
---|
393 | } |
---|
394 | |
---|
395 | |
---|
396 | /* Function called from main.inc.php - Triggered on user deletion */ |
---|
397 | function DeleteConfirmMail($user_id) |
---|
398 | { |
---|
399 | $query = " |
---|
400 | DELETE FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
401 | WHERE user_id = '".$user_id."' |
---|
402 | ;"; |
---|
403 | pwg_query($query); |
---|
404 | } |
---|
405 | |
---|
406 | /* Function called from main.inc.php - Triggered on user deletion */ |
---|
407 | function DeleteLastVisit($user_id) |
---|
408 | { |
---|
409 | $query = " |
---|
410 | DELETE FROM ".USER_LASTVISIT_TABLE." |
---|
411 | WHERE user_id = '".$user_id."' |
---|
412 | ;"; |
---|
413 | pwg_query($query); |
---|
414 | } |
---|
415 | |
---|
416 | /* Function called from ConfirmMail.php to verify validation key used by user according time limit */ |
---|
417 | function VerifyConfirmMail($id) |
---|
418 | { |
---|
419 | global $conf; |
---|
420 | |
---|
421 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
422 | |
---|
423 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
424 | $conf_nbc_UserAdvManager_ConfirmMail = isset($conf['nbc_UserAdvManager_ConfirmMail']) ? explode(";" , $conf['nbc_UserAdvManager_ConfirmMail']) : array(); |
---|
425 | |
---|
426 | $query = " |
---|
427 | SELECT COUNT(*) |
---|
428 | FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
429 | WHERE id = '".$id."' |
---|
430 | ;"; |
---|
431 | list($count) = mysql_fetch_row(pwg_query($query)); |
---|
432 | |
---|
433 | if ($count == 1) |
---|
434 | { |
---|
435 | $query = " |
---|
436 | SELECT user_id, status, date_check |
---|
437 | FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
438 | WHERE id = '".$id."' |
---|
439 | ;"; |
---|
440 | $data = mysql_fetch_assoc(pwg_query($query)); |
---|
441 | |
---|
442 | if (!empty($data) and isset($data['user_id']) and !isset($data['date_check'])) |
---|
443 | { |
---|
444 | $query = " |
---|
445 | SELECT registration_date |
---|
446 | FROM ".USER_INFOS_TABLE." |
---|
447 | WHERE user_id = '".$data['user_id']."' |
---|
448 | ;"; |
---|
449 | list($registration_date) = mysql_fetch_row(pwg_query($query)); |
---|
450 | |
---|
451 | /* Time limit process */ |
---|
452 | /* ****************** begin ******************* */ |
---|
453 | if (!empty($registration_date)) |
---|
454 | { |
---|
455 | // Verify Confirmmail with time limit ON |
---|
456 | if (isset ($conf_nbc_UserAdvManager_ConfirmMail[1])) |
---|
457 | { |
---|
458 | // dates formating and compare |
---|
459 | $today = date("d-m-Y"); // Get today's date |
---|
460 | list($day, $month, $year) = explode('-', $today); // explode date of today |
---|
461 | $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp |
---|
462 | |
---|
463 | list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date |
---|
464 | list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date |
---|
465 | $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp |
---|
466 | |
---|
467 | $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps |
---|
468 | $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days |
---|
469 | |
---|
470 | // Condition with the value set for time limit |
---|
471 | if ($deltadays <= $conf_nbc_UserAdvManager_ConfirmMail[1]) // If Nb of days is less than the limit set |
---|
472 | { |
---|
473 | list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); |
---|
474 | |
---|
475 | $query = ' |
---|
476 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
477 | SET date_check="'.$dbnow.'" |
---|
478 | WHERE id = "'.$id.'" |
---|
479 | ;'; |
---|
480 | pwg_query($query); |
---|
481 | |
---|
482 | if ($conf_nbc_UserAdvManager[3] <> -1) // Delete user from unvalidated users group |
---|
483 | { |
---|
484 | $query = " |
---|
485 | DELETE FROM ".USER_GROUP_TABLE." |
---|
486 | WHERE user_id = '".$data['user_id']."' |
---|
487 | AND group_id = '".$conf_nbc_UserAdvManager[3]."' |
---|
488 | ;"; |
---|
489 | pwg_query($query); |
---|
490 | } |
---|
491 | |
---|
492 | if ($conf_nbc_UserAdvManager[4] <> -1) // Add user to validated users group |
---|
493 | { |
---|
494 | $query = " |
---|
495 | INSERT INTO ".USER_GROUP_TABLE." |
---|
496 | (user_id, group_id) |
---|
497 | VALUES |
---|
498 | ('".$data['user_id']."', '".$conf_nbc_UserAdvManager[4]."') |
---|
499 | ;"; |
---|
500 | pwg_query($query); |
---|
501 | } |
---|
502 | |
---|
503 | if (($conf_nbc_UserAdvManager[5] <> -1 or isset($data['status']))) // Change user's status |
---|
504 | { |
---|
505 | $query = " |
---|
506 | UPDATE ".USER_INFOS_TABLE." |
---|
507 | SET status = '".(isset($data['status']) ? $data['status'] : $conf_nbc_UserAdvManager[5])."' |
---|
508 | WHERE user_id = '".$data['user_id']."' |
---|
509 | ;"; |
---|
510 | pwg_query($query); |
---|
511 | } |
---|
512 | // Refresh user's category cache |
---|
513 | invalidate_user_cache(); |
---|
514 | |
---|
515 | return true; |
---|
516 | } |
---|
517 | elseif ($deltadays > $conf_nbc_UserAdvManager_ConfirmMail[1]) // If timelimit exeeds |
---|
518 | { |
---|
519 | return false; |
---|
520 | } |
---|
521 | } |
---|
522 | // Verify Confirmmail with time limit OFF |
---|
523 | else |
---|
524 | { |
---|
525 | list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); |
---|
526 | |
---|
527 | $query = ' |
---|
528 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
529 | SET date_check="'.$dbnow.'" |
---|
530 | WHERE id = "'.$id.'" |
---|
531 | ;'; |
---|
532 | pwg_query($query); |
---|
533 | |
---|
534 | if ($conf_nbc_UserAdvManager[3] <> -1) |
---|
535 | { |
---|
536 | $query = " |
---|
537 | DELETE FROM ".USER_GROUP_TABLE." |
---|
538 | WHERE user_id = '".$data['user_id']."' |
---|
539 | AND group_id = '".$conf_nbc_UserAdvManager[3]."' |
---|
540 | ;"; |
---|
541 | pwg_query($query); |
---|
542 | } |
---|
543 | |
---|
544 | if ($conf_nbc_UserAdvManager[4] <> -1) |
---|
545 | { |
---|
546 | $query = " |
---|
547 | DELETE FROM ".USER_GROUP_TABLE." |
---|
548 | WHERE user_id = '".$data['user_id']."' |
---|
549 | AND group_id = '".$conf_nbc_UserAdvManager[4]."' |
---|
550 | ;"; |
---|
551 | pwg_query($query); |
---|
552 | |
---|
553 | $query = " |
---|
554 | INSERT INTO ".USER_GROUP_TABLE." |
---|
555 | (user_id, group_id) |
---|
556 | VALUES |
---|
557 | ('".$data['user_id']."', '".$conf_nbc_UserAdvManager[4]."') |
---|
558 | ;"; |
---|
559 | pwg_query($query); |
---|
560 | } |
---|
561 | |
---|
562 | if (($conf_nbc_UserAdvManager[5] <> -1 or isset($data['status']))) |
---|
563 | { |
---|
564 | $query = " |
---|
565 | UPDATE ".USER_INFOS_TABLE." |
---|
566 | SET status = '".(isset($data['status']) ? $data['status'] : $conf_nbc_UserAdvManager[5])."' |
---|
567 | WHERE user_id = '".$data['user_id']."' |
---|
568 | ;"; |
---|
569 | pwg_query($query); |
---|
570 | } |
---|
571 | // Refresh user's category cache |
---|
572 | invalidate_user_cache(); |
---|
573 | |
---|
574 | return true; |
---|
575 | } |
---|
576 | } |
---|
577 | } |
---|
578 | } |
---|
579 | else |
---|
580 | return false; |
---|
581 | } |
---|
582 | |
---|
583 | /* Function called from UserAdvManager_admin.php to force users validation by admin */ |
---|
584 | function ForceValidation($id) |
---|
585 | { |
---|
586 | global $conf; |
---|
587 | |
---|
588 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
589 | |
---|
590 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
591 | |
---|
592 | $query = " |
---|
593 | SELECT COUNT(*) |
---|
594 | FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
595 | WHERE user_id = '".$id."' |
---|
596 | ;"; |
---|
597 | list($count) = mysql_fetch_row(pwg_query($query)); |
---|
598 | |
---|
599 | if ($count == 1) |
---|
600 | { |
---|
601 | $query = " |
---|
602 | SELECT user_id, status, date_check |
---|
603 | FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
604 | WHERE user_id = '".$id."' |
---|
605 | ;"; |
---|
606 | $data = mysql_fetch_assoc(pwg_query($query)); |
---|
607 | |
---|
608 | if (!empty($data) and isset($data['user_id']) and !isset($data['date_check'])) |
---|
609 | { |
---|
610 | list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); |
---|
611 | |
---|
612 | $query = " |
---|
613 | UPDATE ".USER_CONFIRM_MAIL_TABLE." |
---|
614 | SET date_check='".$dbnow."' |
---|
615 | WHERE user_id = '".$data['user_id']."' |
---|
616 | ;"; |
---|
617 | pwg_query($query); |
---|
618 | |
---|
619 | if ($conf_nbc_UserAdvManager[3] <> -1) |
---|
620 | { |
---|
621 | $query = " |
---|
622 | DELETE FROM ".USER_GROUP_TABLE." |
---|
623 | WHERE user_id = '".$data['user_id']."' |
---|
624 | AND group_id = '".$conf_nbc_UserAdvManager[3]."' |
---|
625 | ;"; |
---|
626 | pwg_query($query); |
---|
627 | } |
---|
628 | |
---|
629 | if ($conf_nbc_UserAdvManager[4] <> -1) |
---|
630 | { |
---|
631 | $query = " |
---|
632 | DELETE FROM ".USER_GROUP_TABLE." |
---|
633 | WHERE user_id = '".$data['user_id']."' |
---|
634 | AND group_id = '".$conf_nbc_UserAdvManager[4]."' |
---|
635 | ;"; |
---|
636 | pwg_query($query); |
---|
637 | |
---|
638 | $query = " |
---|
639 | INSERT INTO ".USER_GROUP_TABLE." |
---|
640 | (user_id, group_id) |
---|
641 | VALUES |
---|
642 | ('".$data['user_id']."', '".$conf_nbc_UserAdvManager[4]."') |
---|
643 | ;"; |
---|
644 | pwg_query($query); |
---|
645 | } |
---|
646 | |
---|
647 | if (($conf_nbc_UserAdvManager[5] <> -1 or isset($data['status']))) |
---|
648 | { |
---|
649 | $query = " |
---|
650 | UPDATE ".USER_INFOS_TABLE." |
---|
651 | SET status = '".(isset($data['status']) ? $data['status'] : $conf_nbc_UserAdvManager[5])."' |
---|
652 | WHERE user_id = '".$data['user_id']."' |
---|
653 | ;"; |
---|
654 | pwg_query($query); |
---|
655 | } |
---|
656 | // Refresh user's category cache |
---|
657 | invalidate_user_cache(); |
---|
658 | return true; |
---|
659 | } |
---|
660 | } |
---|
661 | } |
---|
662 | |
---|
663 | /* Function called from main.inc.php - Get username case insensitive */ |
---|
664 | function NotSensibleSearchUsername($username) |
---|
665 | { |
---|
666 | global $conf; |
---|
667 | |
---|
668 | if (isset($username)) |
---|
669 | { |
---|
670 | $query = " |
---|
671 | SELECT ".$conf['user_fields']['username']." |
---|
672 | FROM ".USERS_TABLE." |
---|
673 | WHERE LOWER(".stripslashes($conf['user_fields']['username']).") = '".strtolower($username)."' |
---|
674 | ;"; |
---|
675 | $users = mysql_num_rows(pwg_query($query)); |
---|
676 | if ($users > 0) |
---|
677 | { |
---|
678 | return true; |
---|
679 | } |
---|
680 | else |
---|
681 | { |
---|
682 | return false; |
---|
683 | } |
---|
684 | } |
---|
685 | } |
---|
686 | |
---|
687 | |
---|
688 | /* Function called from main.inc.php - Check if username matches forbidden caracters */ |
---|
689 | function ValidateUsername($login) |
---|
690 | { |
---|
691 | global $conf; |
---|
692 | |
---|
693 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
694 | |
---|
695 | if (isset($login) and isset($conf_nbc_UserAdvManager[8]) and $conf_nbc_UserAdvManager[8] <> '') |
---|
696 | { |
---|
697 | $conf_nbc_CharExclusion = preg_split("/[\s,]+/",$conf_nbc_UserAdvManager[8]); |
---|
698 | for ($i = 0 ; $i < count($conf_nbc_CharExclusion) ; $i++) |
---|
699 | { |
---|
700 | $pattern = '/'.$conf_nbc_CharExclusion[$i].'/i'; |
---|
701 | if (preg_match($pattern, $login)) |
---|
702 | { |
---|
703 | return true; |
---|
704 | } |
---|
705 | } |
---|
706 | } |
---|
707 | else |
---|
708 | { |
---|
709 | return false; |
---|
710 | } |
---|
711 | } |
---|
712 | |
---|
713 | |
---|
714 | /* Function called from main.inc.php - Check if user's email is in excluded email providers list */ |
---|
715 | /* Doesn't work on call - Must be copied in main.inc.php to work */ |
---|
716 | function ValidateEmailProvider($email) |
---|
717 | { |
---|
718 | global $conf; |
---|
719 | |
---|
720 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
721 | |
---|
722 | if (isset($email) and isset($conf_nbc_UserAdvManager[13]) and $conf_nbc_UserAdvManager[13] <> '') |
---|
723 | { |
---|
724 | //$ncsemail = strtolower($email); |
---|
725 | $conf_nbc_MailExclusion = preg_split("/[\s,]+/",$conf_nbc_UserAdvManager[13]); |
---|
726 | for ($i = 0 ; $i < count($conf_nbc_MailExclusion) ; $i++) |
---|
727 | { |
---|
728 | $pattern = '/'.$conf_nbc_MailExclusion[$i].'/i'; |
---|
729 | if (preg_match($pattern, $email)) |
---|
730 | { |
---|
731 | return true; |
---|
732 | } |
---|
733 | } |
---|
734 | } |
---|
735 | else |
---|
736 | { |
---|
737 | return false; |
---|
738 | } |
---|
739 | } |
---|
740 | |
---|
741 | |
---|
742 | /* Function called from UserAdvManager.php - Get unvalidated users according time limit */ |
---|
743 | function get_unvalid_user_list() |
---|
744 | { |
---|
745 | global $conf, $page; |
---|
746 | |
---|
747 | /* Get ConfirmMail configuration */ |
---|
748 | $conf_nbc_UserAdvManager_ConfirmMail = isset($conf['nbc_UserAdvManager_ConfirmMail']) ? explode(";" , $conf['nbc_UserAdvManager_ConfirmMail']) : array(); |
---|
749 | |
---|
750 | /* Get UserAdvManager configuration */ |
---|
751 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
752 | |
---|
753 | $users = array(); |
---|
754 | |
---|
755 | /* search users depending expiration date */ |
---|
756 | $query = ' |
---|
757 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
758 | u.'.$conf['user_fields']['username'].' AS username, |
---|
759 | u.'.$conf['user_fields']['email'].' AS email, |
---|
760 | ui.status, |
---|
761 | ui.adviser, |
---|
762 | ui.enabled_high, |
---|
763 | ui.level, |
---|
764 | ui.registration_date |
---|
765 | FROM '.USERS_TABLE.' AS u |
---|
766 | INNER JOIN '.USER_INFOS_TABLE.' AS ui |
---|
767 | ON u.'.$conf['user_fields']['id'].' = ui.user_id |
---|
768 | LEFT JOIN '.USER_GROUP_TABLE.' AS ug |
---|
769 | ON u.'.$conf['user_fields']['id'].' = ug.user_id |
---|
770 | WHERE u.'.$conf['user_fields']['id'].' >= 3 |
---|
771 | AND (TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) >= "'.$conf_nbc_UserAdvManager_ConfirmMail[1].'" |
---|
772 | OR TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) < "'.$conf_nbc_UserAdvManager_ConfirmMail[1].'")'; |
---|
773 | |
---|
774 | if ($conf_nbc_UserAdvManager[3] <> '-1' and $conf_nbc_UserAdvManager[9] == '-1') |
---|
775 | { |
---|
776 | $query.= ' |
---|
777 | AND ug.group_id = '.$conf_nbc_UserAdvManager[3]; |
---|
778 | } |
---|
779 | if ($conf_nbc_UserAdvManager[3] == '-1' and $conf_nbc_UserAdvManager[9] <> '-1') |
---|
780 | { |
---|
781 | $query.= ' |
---|
782 | AND ui.status = \''.$conf_nbc_UserAdvManager[9]."'"; |
---|
783 | } |
---|
784 | if ($conf_nbc_UserAdvManager[3] <> '-1' and $conf_nbc_UserAdvManager[9] <> '-1') |
---|
785 | { |
---|
786 | $query.= ' |
---|
787 | AND ug.group_id = \''.$conf_nbc_UserAdvManager[3]."'"; |
---|
788 | } |
---|
789 | $query.= ' |
---|
790 | ORDER BY id ASC |
---|
791 | ;'; |
---|
792 | |
---|
793 | $result = pwg_query($query); |
---|
794 | |
---|
795 | while ($row = mysql_fetch_assoc($result)) |
---|
796 | { |
---|
797 | $user = $row; |
---|
798 | $user['groups'] = array(); |
---|
799 | |
---|
800 | array_push($users, $user); |
---|
801 | } |
---|
802 | |
---|
803 | /* add group lists */ |
---|
804 | $user_ids = array(); |
---|
805 | foreach ($users as $i => $user) |
---|
806 | { |
---|
807 | $user_ids[$i] = $user['id']; |
---|
808 | } |
---|
809 | |
---|
810 | $user_nums = array_flip($user_ids); |
---|
811 | |
---|
812 | if (count($user_ids) > 0) |
---|
813 | { |
---|
814 | $query = ' |
---|
815 | SELECT user_id, group_id |
---|
816 | FROM '.USER_GROUP_TABLE.' |
---|
817 | WHERE user_id IN ('.implode(',', $user_ids).') |
---|
818 | ;'; |
---|
819 | |
---|
820 | $result = pwg_query($query); |
---|
821 | |
---|
822 | while ($row = mysql_fetch_assoc($result)) |
---|
823 | { |
---|
824 | array_push( |
---|
825 | $users[$user_nums[$row['user_id']]]['groups'], |
---|
826 | $row['group_id'] |
---|
827 | ); |
---|
828 | } |
---|
829 | } |
---|
830 | |
---|
831 | return $users; |
---|
832 | } |
---|
833 | |
---|
834 | |
---|
835 | /* Function called from UserAdvManager.php - Get ghost users */ |
---|
836 | function get_ghost_user_list() |
---|
837 | { |
---|
838 | global $conf, $page; |
---|
839 | |
---|
840 | /* Get UserAdvManager configuration */ |
---|
841 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
842 | |
---|
843 | $users = array(); |
---|
844 | |
---|
845 | /* search users depending expiration date */ |
---|
846 | $query = ' |
---|
847 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
848 | u.'.$conf['user_fields']['username'].' AS username, |
---|
849 | u.'.$conf['user_fields']['email'].' AS email, |
---|
850 | lv.lastvisit, |
---|
851 | lv.reminder |
---|
852 | FROM '.USERS_TABLE.' AS u |
---|
853 | INNER JOIN '.USER_LASTVISIT_TABLE.' AS lv |
---|
854 | ON u.'.$conf['user_fields']['id'].' = lv.user_id |
---|
855 | WHERE (TO_DAYS(NOW()) - TO_DAYS(lv.lastvisit) >= "'.$conf_nbc_UserAdvManager[18].'") |
---|
856 | ORDER BY id ASC;'; |
---|
857 | |
---|
858 | $result = pwg_query($query); |
---|
859 | |
---|
860 | while ($row = mysql_fetch_assoc($result)) |
---|
861 | { |
---|
862 | $user = $row; |
---|
863 | $user['groups'] = array(); |
---|
864 | |
---|
865 | array_push($users, $user); |
---|
866 | } |
---|
867 | |
---|
868 | /* add group lists */ |
---|
869 | $user_ids = array(); |
---|
870 | foreach ($users as $i => $user) |
---|
871 | { |
---|
872 | $user_ids[$i] = $user['id']; |
---|
873 | } |
---|
874 | |
---|
875 | return $users; |
---|
876 | } |
---|
877 | |
---|
878 | |
---|
879 | /* Function called from UserAdvManager.php - Get all users to display the number of days since their last visit */ |
---|
880 | function get_user_list() |
---|
881 | { |
---|
882 | global $conf, $page; |
---|
883 | |
---|
884 | $users = array(); |
---|
885 | |
---|
886 | /* search users depending expiration date */ |
---|
887 | $query = ' |
---|
888 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
889 | u.'.$conf['user_fields']['username'].' AS username, |
---|
890 | u.'.$conf['user_fields']['email'].' AS email, |
---|
891 | ug.lastvisit |
---|
892 | FROM '.USERS_TABLE.' AS u |
---|
893 | INNER JOIN '.USER_LASTVISIT_TABLE.' AS ug |
---|
894 | ON u.'.$conf['user_fields']['id'].' = ug.user_id |
---|
895 | WHERE u.'.$conf['user_fields']['id'].' >= 3 |
---|
896 | ORDER BY lastvisit DESC |
---|
897 | ;'; |
---|
898 | |
---|
899 | $result = pwg_query($query); |
---|
900 | |
---|
901 | while ($row = mysql_fetch_assoc($result)) |
---|
902 | { |
---|
903 | $user = $row; |
---|
904 | $user['groups'] = array(); |
---|
905 | |
---|
906 | array_push($users, $user); |
---|
907 | } |
---|
908 | |
---|
909 | /* add group lists */ |
---|
910 | $user_ids = array(); |
---|
911 | foreach ($users as $i => $user) |
---|
912 | { |
---|
913 | $user_ids[$i] = $user['id']; |
---|
914 | } |
---|
915 | |
---|
916 | return $users; |
---|
917 | } |
---|
918 | |
---|
919 | |
---|
920 | /* Function called from UserAdvManager.php - to determine who is expired or not and giving a different display color */ |
---|
921 | function expiration($id) |
---|
922 | { |
---|
923 | global $conf, $page; |
---|
924 | |
---|
925 | /* Get ConfirmMail configuration */ |
---|
926 | $conf_nbc_UserAdvManager_ConfirmMail = isset($conf['nbc_UserAdvManager_ConfirmMail']) ? explode(";" , $conf['nbc_UserAdvManager_ConfirmMail']) : array(); |
---|
927 | |
---|
928 | /* Get UserAdvManager configuration */ |
---|
929 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
930 | |
---|
931 | $query = " |
---|
932 | SELECT registration_date |
---|
933 | FROM ".USER_INFOS_TABLE." |
---|
934 | WHERE user_id = '".$id."' |
---|
935 | ;"; |
---|
936 | list($registration_date) = mysql_fetch_row(pwg_query($query)); |
---|
937 | |
---|
938 | /* Time limit process */ |
---|
939 | /* ****************** begin ******************* */ |
---|
940 | if (!empty($registration_date)) |
---|
941 | { |
---|
942 | // dates formating and compare |
---|
943 | $today = date("d-m-Y"); // Get today's date |
---|
944 | list($day, $month, $year) = explode('-', $today); // explode date of today |
---|
945 | $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp |
---|
946 | |
---|
947 | list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date |
---|
948 | list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date |
---|
949 | $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp |
---|
950 | |
---|
951 | $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps |
---|
952 | $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days |
---|
953 | |
---|
954 | // Condition with the value set for time limit |
---|
955 | if ($deltadays <= $conf_nbc_UserAdvManager_ConfirmMail[1]) // If Nb of days is less than the limit set |
---|
956 | { |
---|
957 | return false; |
---|
958 | } |
---|
959 | else |
---|
960 | { |
---|
961 | return True; |
---|
962 | } |
---|
963 | } |
---|
964 | } |
---|
965 | |
---|
966 | |
---|
967 | /** |
---|
968 | * Returns a password's score for password complexity check |
---|
969 | * |
---|
970 | * @param password filled by user |
---|
971 | * |
---|
972 | * Thanx to MathieuGut from http://m-gut.developpez.com |
---|
973 | */ |
---|
974 | function testpassword($password) // Le mot de passe passé en paramètre - $password given by user |
---|
975 | { |
---|
976 | |
---|
977 | // Initialisation des variables - Variables initiation |
---|
978 | $points = 0; |
---|
979 | $point_lowercase = 0; |
---|
980 | $point_uppercase = 0; |
---|
981 | $point_numbers = 0; |
---|
982 | $point_characters = 0; |
---|
983 | |
---|
984 | // On récupère la longueur du mot de passe - Getting password lengh |
---|
985 | $length = strlen($password); |
---|
986 | |
---|
987 | // On fait une boucle pour lire chaque lettre - Loop to read password characters |
---|
988 | for($i = 0; $i < $length; $i++) |
---|
989 | { |
---|
990 | // On sélectionne une à une chaque lettre - Select each letters |
---|
991 | // $i étant à 0 lors du premier passage de la boucle - $i is 0 at first turn |
---|
992 | $letters = $password[$i]; |
---|
993 | |
---|
994 | if ($letters>='a' && $letters<='z') |
---|
995 | { |
---|
996 | // On ajoute 1 point pour une minuscule - Adding 1 point to score for a lowercase |
---|
997 | $points = $points + 1; |
---|
998 | |
---|
999 | // On rajoute le bonus pour une minuscule - Adding bonus points for lowercase |
---|
1000 | $point_lowercase = 1; |
---|
1001 | } |
---|
1002 | else if ($letters>='A' && $letters <='Z') |
---|
1003 | { |
---|
1004 | // On ajoute 2 points pour une majuscule - Adding 2 points to score for uppercase |
---|
1005 | $points = $points + 2; |
---|
1006 | |
---|
1007 | // On rajoute le bonus pour une majuscule - Adding bonus points for uppercase |
---|
1008 | $point_uppercase = 2; |
---|
1009 | } |
---|
1010 | else if ($letters>='0' && $letters<='9') |
---|
1011 | { |
---|
1012 | // On ajoute 3 points pour un chiffre - Adding 3 points to score for numbers |
---|
1013 | $points = $points + 3; |
---|
1014 | |
---|
1015 | // On rajoute le bonus pour un chiffre - Adding bonus points for numbers |
---|
1016 | $point_numbers = 3; |
---|
1017 | } |
---|
1018 | else |
---|
1019 | { |
---|
1020 | // On ajoute 5 points pour un caractère autre - Adding 5 points to score for special characters |
---|
1021 | $points = $points + 5; |
---|
1022 | |
---|
1023 | // On rajoute le bonus pour un caractère autre - Adding bonus points for special characters |
---|
1024 | $point_characters = 5; |
---|
1025 | } |
---|
1026 | } |
---|
1027 | |
---|
1028 | // Calcul du coefficient points/longueur - calculating the coefficient points / length |
---|
1029 | $step1 = $points / $length; |
---|
1030 | |
---|
1031 | // Calcul du coefficient de la diversité des types de caractères... - Calculation of the diversity of character types... |
---|
1032 | $step2 = $point_lowercase + $point_uppercase + $point_numbers + $point_characters; |
---|
1033 | |
---|
1034 | // Multiplication du coefficient de diversité avec celui de la longueur - Multiplying the coefficient of diversity with that of the length |
---|
1035 | $score = $step1 * $step2; |
---|
1036 | |
---|
1037 | // Multiplication du résultat par la longueur de la chaîne - Multiplying the result by the length of the chain |
---|
1038 | $finalscore = $score * $length; |
---|
1039 | |
---|
1040 | return $finalscore; |
---|
1041 | } |
---|
1042 | |
---|
1043 | /* Function called from maintain.inc.php - to check if database upgrade is needed */ |
---|
1044 | function table_exist($table) |
---|
1045 | { |
---|
1046 | $query = 'DESC '.$table.';'; |
---|
1047 | return (bool)($res=mysql_query($query)); |
---|
1048 | } |
---|
1049 | ?> |
---|