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 | switch($typemail) |
---|
18 | { |
---|
19 | case 1: |
---|
20 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Add of %s', $username)); |
---|
21 | $password = $password <> '' ? $password : l10n('UserAdvManager_empty_pwd'); |
---|
22 | |
---|
23 | if ( function_exists('get_user_language_desc') and isset($conf_nbc_UserAdvManager[10]) and $conf_nbc_UserAdvManager[10] <> '' ) |
---|
24 | $infos1_perso = get_user_language_desc($conf_nbc_UserAdvManager[10])."\n\n"; |
---|
25 | |
---|
26 | break; |
---|
27 | |
---|
28 | case 2: |
---|
29 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Update of %s', $username)); |
---|
30 | $password = $password <> '' ? $password : l10n('UserAdvManager_empty_pwd'); |
---|
31 | |
---|
32 | break; |
---|
33 | |
---|
34 | case 3: |
---|
35 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Update of %s', $username)); |
---|
36 | $password = $password <> '' ? $password : l10n('UserAdvManager_no_update_pwd'); |
---|
37 | |
---|
38 | break; |
---|
39 | } |
---|
40 | |
---|
41 | if ( isset($conf_nbc_UserAdvManager[0]) and $conf_nbc_UserAdvManager[0] == 'true' ) |
---|
42 | { |
---|
43 | $infos1 = array( |
---|
44 | get_l10n_args('infos_mail %s', $username), |
---|
45 | get_l10n_args('User: %s', $username), |
---|
46 | get_l10n_args('Password: %s', $password), |
---|
47 | get_l10n_args('Email: %s', $email), |
---|
48 | get_l10n_args('', ''), |
---|
49 | ); |
---|
50 | } |
---|
51 | |
---|
52 | |
---|
53 | if ( isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2] == 'true' and $confirm) |
---|
54 | { |
---|
55 | $infos2 = array |
---|
56 | ( |
---|
57 | get_l10n_args('Link: %s', AddConfirmMail($id, $email)), |
---|
58 | get_l10n_args('', ''), |
---|
59 | ); |
---|
60 | |
---|
61 | if ( function_exists('get_user_language_desc') and isset($conf_nbc_UserAdvManager[11]) and $conf_nbc_UserAdvManager[11] <> '' ) |
---|
62 | $infos2_perso = get_user_language_desc($conf_nbc_UserAdvManager[11])."\n\n"; |
---|
63 | } |
---|
64 | |
---|
65 | pwg_mail($email, array( |
---|
66 | 'subject' => $subject, |
---|
67 | 'content' => (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "").get_absolute_root_url(), |
---|
68 | )); |
---|
69 | |
---|
70 | /* ********************** */ |
---|
71 | /* Email sending debugger */ |
---|
72 | /* This is only to trace */ |
---|
73 | /* the send of emails for */ |
---|
74 | /* debugging */ |
---|
75 | /* ********************** */ |
---|
76 | // MailLog($email,$subject); |
---|
77 | /* ********************** */ |
---|
78 | } |
---|
79 | |
---|
80 | |
---|
81 | /* Email sending debugger function */ |
---|
82 | //function MailLog ($to, $subject) |
---|
83 | //{ |
---|
84 | // $fo=fopen (NBC_UserAdvManager_PATH.'admin/maillog.txt','a') ; |
---|
85 | // fwrite($fo,"======================\n") ; |
---|
86 | // fwrite($fo,'le ' . date('D, d M Y H:i:s') . "\r\n"); |
---|
87 | // fwrite($fo,$to . "\n" . $subject . "\r\n") ; |
---|
88 | // fclose($fo) ; |
---|
89 | //return mail ($to,$subject) ; |
---|
90 | //} |
---|
91 | |
---|
92 | |
---|
93 | /* Function called from UserAdvManager_admin.php to resend validation email with or without new validation key */ |
---|
94 | function ResendMail2User($typemail, $user_id, $username, $email, $confirm) |
---|
95 | { |
---|
96 | global $conf; |
---|
97 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
98 | $conf_nbc_UserAdvManager_ConfirmMail = isset($conf['nbc_UserAdvManager_ConfirmMail']) ? explode(";" , $conf['nbc_UserAdvManager_ConfirmMail']) : array(); |
---|
99 | |
---|
100 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
101 | |
---|
102 | $infos1_perso = ""; |
---|
103 | $infos2_perso = ""; |
---|
104 | |
---|
105 | switch($typemail) |
---|
106 | { |
---|
107 | case 1: |
---|
108 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Reminder_with_key_of_%s', $username)); |
---|
109 | |
---|
110 | if (function_exists('get_user_language_desc') and 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) |
---|
111 | { |
---|
112 | $infos1 = get_user_language_desc($conf_nbc_UserAdvManager_ConfirmMail[2])."\n\n"; |
---|
113 | |
---|
114 | $infos2 = array |
---|
115 | ( |
---|
116 | get_l10n_args('Link: %s', ResetConfirmMail($user_id)), |
---|
117 | get_l10n_args('', ''), |
---|
118 | ); |
---|
119 | } |
---|
120 | break; |
---|
121 | |
---|
122 | case 2: |
---|
123 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Reminder_without_key_of_%s', $username)); |
---|
124 | |
---|
125 | if (function_exists('get_user_language_desc') and 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) |
---|
126 | { |
---|
127 | $infos1 = get_user_language_desc($conf_nbc_UserAdvManager_ConfirmMail[2])."\n\n"; |
---|
128 | } |
---|
129 | break; |
---|
130 | } |
---|
131 | pwg_mail($email, array( |
---|
132 | 'subject' => $subject, |
---|
133 | 'content' => ($infos1."\n\n").(isset($infos2) ? l10n_args($infos2)."\n\n" : "").get_absolute_root_url(), |
---|
134 | )); |
---|
135 | |
---|
136 | /* ********************** */ |
---|
137 | /* Email sending debugger */ |
---|
138 | /* This is only to trace */ |
---|
139 | /* the send of emails for */ |
---|
140 | /* debugging */ |
---|
141 | /* ********************** */ |
---|
142 | // MailLog($email,$subject); |
---|
143 | /* ********************** */ |
---|
144 | } |
---|
145 | |
---|
146 | |
---|
147 | /* Function called from functions AddConfirmMail and ResetConfirmMail for validation key generation */ |
---|
148 | function FindAvailableConfirmMailID() |
---|
149 | { |
---|
150 | while (true) |
---|
151 | { |
---|
152 | $id = generate_key(16); |
---|
153 | $query = " |
---|
154 | SELECT COUNT(*) |
---|
155 | FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
156 | WHERE id = '".$id."' |
---|
157 | ;"; |
---|
158 | list($count) = mysql_fetch_row(pwg_query($query)); |
---|
159 | |
---|
160 | if ($count == 0) |
---|
161 | return $id; |
---|
162 | } |
---|
163 | } |
---|
164 | |
---|
165 | |
---|
166 | /* Function called from functions SendMail2User to process unvalidated users and generate validation key link */ |
---|
167 | function AddConfirmMail($user_id, $email) |
---|
168 | { |
---|
169 | global $conf; |
---|
170 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
171 | $Confirm_Mail_ID = FindAvailableConfirmMailID(); |
---|
172 | |
---|
173 | list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); |
---|
174 | |
---|
175 | if (isset($Confirm_Mail_ID)) |
---|
176 | { |
---|
177 | $query = " |
---|
178 | SELECT status |
---|
179 | FROM ".USER_INFOS_TABLE." |
---|
180 | WHERE user_id = '".$user_id."' |
---|
181 | ;"; |
---|
182 | list($status) = mysql_fetch_row(pwg_query($query)); |
---|
183 | |
---|
184 | $query = " |
---|
185 | INSERT INTO ".USER_CONFIRM_MAIL_TABLE." |
---|
186 | (id, user_id, mail_address, status, date_check) |
---|
187 | VALUES |
---|
188 | ('".$Confirm_Mail_ID."', '".$user_id."', '".$email."', '".$status."', null) |
---|
189 | ;"; |
---|
190 | pwg_query($query); |
---|
191 | |
---|
192 | $query = " |
---|
193 | DELETE FROM ".USER_GROUP_TABLE." |
---|
194 | WHERE user_id = '".$user_id."' |
---|
195 | AND ( |
---|
196 | group_id = '".$conf_nbc_UserAdvManager[3]."' |
---|
197 | OR |
---|
198 | group_id = '".$conf_nbc_UserAdvManager[4]."' |
---|
199 | ) |
---|
200 | ;"; |
---|
201 | pwg_query($query); |
---|
202 | |
---|
203 | if (!is_admin() and $conf_nbc_UserAdvManager[9] <> -1) |
---|
204 | { |
---|
205 | $query = " |
---|
206 | UPDATE ".USER_INFOS_TABLE." |
---|
207 | SET status = '".$conf_nbc_UserAdvManager[9]."' |
---|
208 | WHERE user_id = '".$user_id."' |
---|
209 | ;"; |
---|
210 | pwg_query($query); |
---|
211 | } |
---|
212 | |
---|
213 | if ( $conf_nbc_UserAdvManager[3] <> -1 ) |
---|
214 | { |
---|
215 | $query = " |
---|
216 | INSERT INTO ".USER_GROUP_TABLE." |
---|
217 | (user_id, group_id) |
---|
218 | VALUES |
---|
219 | ('".$user_id."', '".$conf_nbc_UserAdvManager[3]."') |
---|
220 | ;"; |
---|
221 | pwg_query($query); |
---|
222 | } |
---|
223 | |
---|
224 | return get_absolute_root_url().NBC_UserAdvManager_PATH.'ConfirmMail.php?key='.$Confirm_Mail_ID; |
---|
225 | } |
---|
226 | } |
---|
227 | |
---|
228 | |
---|
229 | /* Function called from UserAdvManager_admin.php to reset validation key */ |
---|
230 | function ResetConfirmMail($user_id) |
---|
231 | { |
---|
232 | global $conf; |
---|
233 | |
---|
234 | $Confirm_Mail_ID = FindAvailableConfirmMailID(); |
---|
235 | |
---|
236 | list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); |
---|
237 | |
---|
238 | if (isset($Confirm_Mail_ID)) |
---|
239 | { |
---|
240 | $query = " |
---|
241 | UPDATE ".USER_CONFIRM_MAIL_TABLE." |
---|
242 | SET id = '".$Confirm_Mail_ID."' |
---|
243 | WHERE user_id = '".$user_id."' |
---|
244 | ;"; |
---|
245 | pwg_query($query); |
---|
246 | |
---|
247 | $query = " |
---|
248 | UPDATE ".USER_INFOS_TABLE." |
---|
249 | SET registration_date = '".$dbnow."' |
---|
250 | WHERE user_id = '".$user_id."' |
---|
251 | ;"; |
---|
252 | pwg_query($query); |
---|
253 | |
---|
254 | return get_absolute_root_url().NBC_UserAdvManager_PATH.'ConfirmMail.php?key='.$Confirm_Mail_ID; |
---|
255 | } |
---|
256 | } |
---|
257 | |
---|
258 | |
---|
259 | /* Function called from main.inc.php - Triggered on user deletion */ |
---|
260 | function DeleteConfirmMail($user_id) |
---|
261 | { |
---|
262 | $query = " |
---|
263 | DELETE FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
264 | WHERE user_id = '".$user_id."' |
---|
265 | ;"; |
---|
266 | pwg_query($query); |
---|
267 | } |
---|
268 | |
---|
269 | |
---|
270 | /* Function called from ConfirmMail.php to verify validation key used by user according time limit */ |
---|
271 | function VerifyConfirmMail($id) |
---|
272 | { |
---|
273 | global $conf; |
---|
274 | |
---|
275 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
276 | |
---|
277 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
278 | $conf_nbc_UserAdvManager_ConfirmMail = isset($conf['nbc_UserAdvManager_ConfirmMail']) ? explode(";" , $conf['nbc_UserAdvManager_ConfirmMail']) : array(); |
---|
279 | |
---|
280 | $query = " |
---|
281 | SELECT COUNT(*) |
---|
282 | FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
283 | WHERE id = '".$id."' |
---|
284 | ;"; |
---|
285 | list($count) = mysql_fetch_row(pwg_query($query)); |
---|
286 | |
---|
287 | if ($count == 1) |
---|
288 | { |
---|
289 | $query = " |
---|
290 | SELECT user_id, status, date_check |
---|
291 | FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
292 | WHERE id = '".$id."' |
---|
293 | ;"; |
---|
294 | $data = mysql_fetch_array(pwg_query($query)); |
---|
295 | |
---|
296 | if (!empty($data) and isset($data['user_id']) and !isset($data['date_check'])) |
---|
297 | { |
---|
298 | $query = " |
---|
299 | SELECT registration_date |
---|
300 | FROM ".USER_INFOS_TABLE." |
---|
301 | WHERE user_id = '".$data['user_id']."' |
---|
302 | ;"; |
---|
303 | list($registration_date) = mysql_fetch_row(pwg_query($query)); |
---|
304 | |
---|
305 | /* Time limit process */ |
---|
306 | /* ****************** begin ******************* */ |
---|
307 | if (!empty($registration_date)) |
---|
308 | { |
---|
309 | // Verify Confirmmail with time limit ON |
---|
310 | if (isset ($conf_nbc_UserAdvManager_ConfirmMail[1])) |
---|
311 | { |
---|
312 | // dates formating and compare |
---|
313 | $today = date("d-m-Y"); // Get today's date |
---|
314 | list($day, $month, $year) = explode('-', $today); // explode date of today |
---|
315 | $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp |
---|
316 | |
---|
317 | list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date |
---|
318 | list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date |
---|
319 | $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp |
---|
320 | |
---|
321 | $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps |
---|
322 | $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days |
---|
323 | |
---|
324 | // Condition with the value set for time limit |
---|
325 | if ($deltadays <= $conf_nbc_UserAdvManager_ConfirmMail[1]) // If Nb of days is less than the limit set |
---|
326 | { |
---|
327 | list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); |
---|
328 | |
---|
329 | $query = ' |
---|
330 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
331 | SET date_check="'.$dbnow.'" |
---|
332 | WHERE id = "'.$id.'" |
---|
333 | ;'; |
---|
334 | pwg_query($query); |
---|
335 | |
---|
336 | if ($conf_nbc_UserAdvManager[3] <> -1) // Delete user from unvalidated users group |
---|
337 | { |
---|
338 | $query = " |
---|
339 | DELETE FROM ".USER_GROUP_TABLE." |
---|
340 | WHERE user_id = '".$data['user_id']."' |
---|
341 | AND group_id = '".$conf_nbc_UserAdvManager[3]."' |
---|
342 | ;"; |
---|
343 | pwg_query($query); |
---|
344 | } |
---|
345 | |
---|
346 | if ($conf_nbc_UserAdvManager[4] <> -1) // Add user to validated users group |
---|
347 | { |
---|
348 | $query = " |
---|
349 | INSERT INTO ".USER_GROUP_TABLE." |
---|
350 | (user_id, group_id) |
---|
351 | VALUES |
---|
352 | ('".$data['user_id']."', '".$conf_nbc_UserAdvManager[4]."') |
---|
353 | ;"; |
---|
354 | pwg_query($query); |
---|
355 | } |
---|
356 | |
---|
357 | if (($conf_nbc_UserAdvManager[5] <> -1 or isset($data['status']))) // Change user's status |
---|
358 | { |
---|
359 | $query = " |
---|
360 | UPDATE ".USER_INFOS_TABLE." |
---|
361 | SET status = '".(isset($data['status']) ? $data['status'] : $conf_nbc_UserAdvManager[5])."' |
---|
362 | WHERE user_id = '".$data['user_id']."' |
---|
363 | ;"; |
---|
364 | pwg_query($query); |
---|
365 | } |
---|
366 | // Refresh user's category cache |
---|
367 | invalidate_user_cache(); |
---|
368 | |
---|
369 | return true; |
---|
370 | } |
---|
371 | elseif ($deltadays > $conf_nbc_UserAdvManager_ConfirmMail[1]) // If timelimit exeeds |
---|
372 | { |
---|
373 | return false; |
---|
374 | } |
---|
375 | } |
---|
376 | // Verify Confirmmail with time limit OFF |
---|
377 | else |
---|
378 | { |
---|
379 | list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); |
---|
380 | |
---|
381 | $query = ' |
---|
382 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
383 | SET date_check="'.$dbnow.'" |
---|
384 | WHERE id = "'.$id.'" |
---|
385 | ;'; |
---|
386 | pwg_query($query); |
---|
387 | |
---|
388 | if ($conf_nbc_UserAdvManager[3] <> -1) |
---|
389 | { |
---|
390 | $query = " |
---|
391 | DELETE FROM ".USER_GROUP_TABLE." |
---|
392 | WHERE user_id = '".$data['user_id']."' |
---|
393 | AND group_id = '".$conf_nbc_UserAdvManager[3]."' |
---|
394 | ;"; |
---|
395 | pwg_query($query); |
---|
396 | } |
---|
397 | |
---|
398 | if ($conf_nbc_UserAdvManager[4] <> -1) |
---|
399 | { |
---|
400 | $query = " |
---|
401 | DELETE FROM ".USER_GROUP_TABLE." |
---|
402 | WHERE user_id = '".$data['user_id']."' |
---|
403 | AND group_id = '".$conf_nbc_UserAdvManager[4]."' |
---|
404 | ;"; |
---|
405 | pwg_query($query); |
---|
406 | |
---|
407 | $query = " |
---|
408 | INSERT INTO ".USER_GROUP_TABLE." |
---|
409 | (user_id, group_id) |
---|
410 | VALUES |
---|
411 | ('".$data['user_id']."', '".$conf_nbc_UserAdvManager[4]."') |
---|
412 | ;"; |
---|
413 | pwg_query($query); |
---|
414 | } |
---|
415 | |
---|
416 | if (($conf_nbc_UserAdvManager[5] <> -1 or isset($data['status']))) |
---|
417 | { |
---|
418 | $query = " |
---|
419 | UPDATE ".USER_INFOS_TABLE." |
---|
420 | SET status = '".(isset($data['status']) ? $data['status'] : $conf_nbc_UserAdvManager[5])."' |
---|
421 | WHERE user_id = '".$data['user_id']."' |
---|
422 | ;"; |
---|
423 | pwg_query($query); |
---|
424 | } |
---|
425 | // Refresh user's category cache |
---|
426 | invalidate_user_cache(); |
---|
427 | |
---|
428 | return true; |
---|
429 | } |
---|
430 | } |
---|
431 | } |
---|
432 | } |
---|
433 | else |
---|
434 | return false; |
---|
435 | } |
---|
436 | |
---|
437 | /* Function called from UserAdvManager_admin.php to force users validation by admin */ |
---|
438 | function ForceValidation($id) |
---|
439 | { |
---|
440 | global $conf; |
---|
441 | |
---|
442 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
443 | |
---|
444 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
445 | |
---|
446 | $query = " |
---|
447 | SELECT COUNT(*) |
---|
448 | FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
449 | WHERE user_id = '".$id."' |
---|
450 | ;"; |
---|
451 | list($count) = mysql_fetch_row(pwg_query($query)); |
---|
452 | |
---|
453 | if ($count == 1) |
---|
454 | { |
---|
455 | $query = " |
---|
456 | SELECT user_id, status, date_check |
---|
457 | FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
458 | WHERE user_id = '".$id."' |
---|
459 | ;"; |
---|
460 | $data = mysql_fetch_array(pwg_query($query)); |
---|
461 | |
---|
462 | if (!empty($data) and isset($data['user_id']) and !isset($data['date_check'])) |
---|
463 | { |
---|
464 | list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); |
---|
465 | |
---|
466 | $query = " |
---|
467 | UPDATE ".USER_CONFIRM_MAIL_TABLE." |
---|
468 | SET date_check='".$dbnow."' |
---|
469 | WHERE user_id = '".$data['user_id']."' |
---|
470 | ;"; |
---|
471 | pwg_query($query); |
---|
472 | |
---|
473 | if ($conf_nbc_UserAdvManager[3] <> -1) |
---|
474 | { |
---|
475 | $query = " |
---|
476 | DELETE FROM ".USER_GROUP_TABLE." |
---|
477 | WHERE user_id = '".$data['user_id']."' |
---|
478 | AND group_id = '".$conf_nbc_UserAdvManager[3]."' |
---|
479 | ;"; |
---|
480 | pwg_query($query); |
---|
481 | } |
---|
482 | |
---|
483 | if ($conf_nbc_UserAdvManager[4] <> -1) |
---|
484 | { |
---|
485 | $query = " |
---|
486 | DELETE FROM ".USER_GROUP_TABLE." |
---|
487 | WHERE user_id = '".$data['user_id']."' |
---|
488 | AND group_id = '".$conf_nbc_UserAdvManager[4]."' |
---|
489 | ;"; |
---|
490 | pwg_query($query); |
---|
491 | |
---|
492 | $query = " |
---|
493 | INSERT INTO ".USER_GROUP_TABLE." |
---|
494 | (user_id, group_id) |
---|
495 | VALUES |
---|
496 | ('".$data['user_id']."', '".$conf_nbc_UserAdvManager[4]."') |
---|
497 | ;"; |
---|
498 | pwg_query($query); |
---|
499 | } |
---|
500 | |
---|
501 | if (($conf_nbc_UserAdvManager[5] <> -1 or isset($data['status']))) |
---|
502 | { |
---|
503 | $query = " |
---|
504 | UPDATE ".USER_INFOS_TABLE." |
---|
505 | SET status = '".(isset($data['status']) ? $data['status'] : $conf_nbc_UserAdvManager[5])."' |
---|
506 | WHERE user_id = '".$data['user_id']."' |
---|
507 | ;"; |
---|
508 | pwg_query($query); |
---|
509 | } |
---|
510 | // Refresh user's category cache |
---|
511 | invalidate_user_cache(); |
---|
512 | return true; |
---|
513 | } |
---|
514 | } |
---|
515 | } |
---|
516 | |
---|
517 | /* Function called from main.inc.php - Get username case insensitive */ |
---|
518 | function NotSensibleSearchUsername($username) |
---|
519 | { |
---|
520 | global $conf; |
---|
521 | |
---|
522 | if (isset($username)) |
---|
523 | { |
---|
524 | $query = " |
---|
525 | SELECT ".$conf['user_fields']['username']." |
---|
526 | FROM ".USERS_TABLE." |
---|
527 | WHERE LOWER(".$conf['user_fields']['username'].") = '".strtolower($username)."' |
---|
528 | ;"; |
---|
529 | list($username) = mysql_fetch_row(pwg_query($query)); |
---|
530 | |
---|
531 | return isset($username) ? $username : ''; |
---|
532 | } |
---|
533 | } |
---|
534 | |
---|
535 | |
---|
536 | /* Obsolete function - Check for single email in database */ |
---|
537 | function SearchMail($email) |
---|
538 | { |
---|
539 | global $conf, $lang; |
---|
540 | |
---|
541 | if (isset($email)) |
---|
542 | { |
---|
543 | $query = " |
---|
544 | SELECT COUNT(*) |
---|
545 | FROM ".USERS_TABLE." |
---|
546 | WHERE ".$conf['user_fields']['email']." = '".$email."' |
---|
547 | ;"; |
---|
548 | list($nbr_mail) = mysql_fetch_row(pwg_query($query)); |
---|
549 | |
---|
550 | return isset($nbr_mail) ? $nbr_mail : 0; |
---|
551 | } |
---|
552 | } |
---|
553 | |
---|
554 | |
---|
555 | /* Function called from main.inc.php - Check if username matches forbidden caracters */ |
---|
556 | function ValidateUsername($login) |
---|
557 | { |
---|
558 | global $conf; |
---|
559 | |
---|
560 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
561 | |
---|
562 | if (isset($login) and isset($conf_nbc_UserAdvManager[8]) and $conf_nbc_UserAdvManager[8] <> '') |
---|
563 | { |
---|
564 | $pattern = '/'.$conf_nbc_UserAdvManager[8].'/'; |
---|
565 | if ( preg_match($pattern, $login) ) |
---|
566 | return false; |
---|
567 | else |
---|
568 | return true; |
---|
569 | } |
---|
570 | else |
---|
571 | { |
---|
572 | return true; |
---|
573 | } |
---|
574 | } |
---|
575 | |
---|
576 | |
---|
577 | /* Obsolete function - Check for no forbidden email provider */ |
---|
578 | /* This don't work on function call */ |
---|
579 | function ValidateEmailProvider($email) |
---|
580 | { |
---|
581 | global $conf; |
---|
582 | |
---|
583 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
584 | if (isset($conf_nbc_UserAdvManager[12])) |
---|
585 | { |
---|
586 | $ncsemail = strtolower($email); |
---|
587 | $conf_nbc_MailExclusion = preg_split('/,/',$conf_nbc_UserAdvManager[13]); |
---|
588 | for ($i = 0 ; $i < count($conf_nbc_MailExclusion) ; $i++) |
---|
589 | { |
---|
590 | $pattern = '/'.$conf_nbc_MailExclusion[$i].'/'; |
---|
591 | if (preg_match($pattern, $ncsemail)) |
---|
592 | return false; |
---|
593 | else |
---|
594 | return true; |
---|
595 | } |
---|
596 | } |
---|
597 | } |
---|
598 | |
---|
599 | |
---|
600 | /* Function called from UserAdvManager.php - Get unvalidated users according time limit */ |
---|
601 | function get_unvalid_user_list() |
---|
602 | { |
---|
603 | global $conf, $page; |
---|
604 | |
---|
605 | /* Get ConfirmMail configuration */ |
---|
606 | $conf_nbc_UserAdvManager_ConfirmMail = isset($conf['nbc_UserAdvManager_ConfirmMail']) ? explode(";" , $conf['nbc_UserAdvManager_ConfirmMail']) : array(); |
---|
607 | |
---|
608 | /* Get UserAdvManager configuration */ |
---|
609 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
610 | |
---|
611 | $users = array(); |
---|
612 | |
---|
613 | /* search users depending expiration date */ |
---|
614 | $query = ' |
---|
615 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
616 | u.'.$conf['user_fields']['username'].' AS username, |
---|
617 | u.'.$conf['user_fields']['email'].' AS email, |
---|
618 | ui.status, |
---|
619 | ui.adviser, |
---|
620 | ui.enabled_high, |
---|
621 | ui.level, |
---|
622 | ui.registration_date |
---|
623 | FROM '.USERS_TABLE.' AS u |
---|
624 | INNER JOIN '.USER_INFOS_TABLE.' AS ui |
---|
625 | ON u.'.$conf['user_fields']['id'].' = ui.user_id |
---|
626 | LEFT JOIN '.USER_GROUP_TABLE.' AS ug |
---|
627 | ON u.'.$conf['user_fields']['id'].' = ug.user_id |
---|
628 | WHERE u.'.$conf['user_fields']['id'].' >= 3 |
---|
629 | AND (TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) >= "'.$conf_nbc_UserAdvManager_ConfirmMail[1].'" |
---|
630 | OR TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) < "'.$conf_nbc_UserAdvManager_ConfirmMail[1].'")'; |
---|
631 | |
---|
632 | if ($conf_nbc_UserAdvManager[3] <> '-1' and $conf_nbc_UserAdvManager[9] == '-1') |
---|
633 | { |
---|
634 | $query.= ' |
---|
635 | AND ug.group_id = '.$conf_nbc_UserAdvManager[3]; |
---|
636 | } |
---|
637 | if ($conf_nbc_UserAdvManager[3] == '-1' and $conf_nbc_UserAdvManager[9] <> '-1') |
---|
638 | { |
---|
639 | $query.= ' |
---|
640 | AND ui.status = \''.$conf_nbc_UserAdvManager[9]."'"; |
---|
641 | } |
---|
642 | if ($conf_nbc_UserAdvManager[3] <> '-1' and $conf_nbc_UserAdvManager[9] <> '-1') |
---|
643 | { |
---|
644 | $query.= ' |
---|
645 | AND ug.group_id = \''.$conf_nbc_UserAdvManager[3]."'"; |
---|
646 | } |
---|
647 | $query.= ' |
---|
648 | ORDER BY id ASC |
---|
649 | ;'; |
---|
650 | |
---|
651 | $result = pwg_query($query); |
---|
652 | |
---|
653 | while ($row = mysql_fetch_array($result)) |
---|
654 | { |
---|
655 | $user = $row; |
---|
656 | $user['groups'] = array(); |
---|
657 | |
---|
658 | array_push($users, $user); |
---|
659 | } |
---|
660 | |
---|
661 | /* add group lists */ |
---|
662 | $user_ids = array(); |
---|
663 | foreach ($users as $i => $user) |
---|
664 | { |
---|
665 | $user_ids[$i] = $user['id']; |
---|
666 | } |
---|
667 | |
---|
668 | $user_nums = array_flip($user_ids); |
---|
669 | |
---|
670 | if (count($user_ids) > 0) |
---|
671 | { |
---|
672 | $query = ' |
---|
673 | SELECT user_id, group_id |
---|
674 | FROM '.USER_GROUP_TABLE.' |
---|
675 | WHERE user_id IN ('.implode(',', $user_ids).') |
---|
676 | ;'; |
---|
677 | |
---|
678 | $result = pwg_query($query); |
---|
679 | |
---|
680 | while ($row = mysql_fetch_array($result)) |
---|
681 | { |
---|
682 | array_push( |
---|
683 | $users[$user_nums[$row['user_id']]]['groups'], |
---|
684 | $row['group_id'] |
---|
685 | ); |
---|
686 | } |
---|
687 | } |
---|
688 | |
---|
689 | return $users; |
---|
690 | } |
---|
691 | |
---|
692 | /* Function called from UserAdvManager.php - to determine who is expired or not and giving a different display color */ |
---|
693 | function expiration($id) |
---|
694 | { |
---|
695 | global $conf, $page; |
---|
696 | |
---|
697 | /* Get ConfirmMail configuration */ |
---|
698 | $conf_nbc_UserAdvManager_ConfirmMail = isset($conf['nbc_UserAdvManager_ConfirmMail']) ? explode(";" , $conf['nbc_UserAdvManager_ConfirmMail']) : array(); |
---|
699 | |
---|
700 | /* Get UserAdvManager configuration */ |
---|
701 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
702 | |
---|
703 | $query = " |
---|
704 | SELECT registration_date |
---|
705 | FROM ".USER_INFOS_TABLE." |
---|
706 | WHERE user_id = '".$id."' |
---|
707 | ;"; |
---|
708 | list($registration_date) = mysql_fetch_row(pwg_query($query)); |
---|
709 | |
---|
710 | /* Time limit process */ |
---|
711 | /* ****************** begin ******************* */ |
---|
712 | if (!empty($registration_date)) |
---|
713 | { |
---|
714 | // dates formating and compare |
---|
715 | $today = date("d-m-Y"); // Get today's date |
---|
716 | list($day, $month, $year) = explode('-', $today); // explode date of today |
---|
717 | $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp |
---|
718 | |
---|
719 | list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date |
---|
720 | list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date |
---|
721 | $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp |
---|
722 | |
---|
723 | $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps |
---|
724 | $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days |
---|
725 | |
---|
726 | // Condition with the value set for time limit |
---|
727 | if ($deltadays <= $conf_nbc_UserAdvManager_ConfirmMail[1]) // If Nb of days is less than the limit set |
---|
728 | { |
---|
729 | return false; |
---|
730 | } |
---|
731 | else |
---|
732 | { |
---|
733 | return True; |
---|
734 | } |
---|
735 | } |
---|
736 | } |
---|
737 | ?> |
---|