1 | <?php |
---|
2 | include_once (UAM_PATH.'include/constants.php'); |
---|
3 | load_language('plugin.lang', UAM_PATH); |
---|
4 | |
---|
5 | /** |
---|
6 | * Triggered on get_admin_plugin_menu_links |
---|
7 | * |
---|
8 | * Plugin's administration menu |
---|
9 | */ |
---|
10 | function UAM_admin_menu($menu) |
---|
11 | { |
---|
12 | // +-----------------------------------------------------------------------+ |
---|
13 | // | Getting plugin name | |
---|
14 | // +-----------------------------------------------------------------------+ |
---|
15 | $plugin = PluginInfos(UAM_PATH); |
---|
16 | $name = $plugin['name']; |
---|
17 | |
---|
18 | array_push($menu, |
---|
19 | array( |
---|
20 | 'NAME' => $name, |
---|
21 | 'URL' => get_admin_plugin_menu_link(UAM_PATH.'/admin/UAM_admin.php') |
---|
22 | ) |
---|
23 | ); |
---|
24 | |
---|
25 | return $menu; |
---|
26 | } |
---|
27 | |
---|
28 | /** |
---|
29 | * Triggered on loc_begin_index |
---|
30 | * |
---|
31 | * Initiating GhostTracker |
---|
32 | */ |
---|
33 | function UAM_GhostTracker() |
---|
34 | { |
---|
35 | global $conf, $user; |
---|
36 | |
---|
37 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
38 | |
---|
39 | // Admins, Guests and Adult_Content users are not tracked for Ghost Tracker or Users Tracker |
---|
40 | if (!is_admin() and !is_a_guest() and $user['username'] != "16" and $user['username'] != "18") |
---|
41 | { |
---|
42 | if ((isset($conf_UAM[16]) and $conf_UAM[16] == 'true') or (isset($conf_UAM[19]) and $conf_UAM[19] == 'true')) |
---|
43 | { |
---|
44 | |
---|
45 | $userid = get_userid($user['username']); |
---|
46 | |
---|
47 | // Looking for existing entry in last visit table |
---|
48 | $query = ' |
---|
49 | SELECT * |
---|
50 | FROM '.USER_LASTVISIT_TABLE.' |
---|
51 | WHERE user_id = '.$userid.' |
---|
52 | ;'; |
---|
53 | |
---|
54 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
55 | |
---|
56 | if ($count == 0) |
---|
57 | { |
---|
58 | // If not, data are inserted in table |
---|
59 | $query = ' |
---|
60 | INSERT INTO '.USER_LASTVISIT_TABLE.' (user_id, lastvisit, reminder) |
---|
61 | VALUES ('.$userid.', now(), "false") |
---|
62 | ;'; |
---|
63 | pwg_query($query); |
---|
64 | } |
---|
65 | else if ($count > 0) |
---|
66 | { |
---|
67 | // If yes, data are updated in table |
---|
68 | $query = ' |
---|
69 | UPDATE '.USER_LASTVISIT_TABLE.' |
---|
70 | SET lastvisit = now(), reminder = "false" |
---|
71 | WHERE user_id = '.$userid.' |
---|
72 | LIMIT 1 |
---|
73 | ;'; |
---|
74 | pwg_query($query); |
---|
75 | } |
---|
76 | } |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | /** |
---|
81 | * Triggered on register_user |
---|
82 | * |
---|
83 | * Additional controls on user registration |
---|
84 | */ |
---|
85 | function UAM_Adduser($register_user) |
---|
86 | { |
---|
87 | global $conf; |
---|
88 | |
---|
89 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
90 | |
---|
91 | // Exclusion of Adult_Content users |
---|
92 | if ($register_user['username'] != "16" and $register_user['username'] != "18") |
---|
93 | { |
---|
94 | if ((isset($conf_UAM[0]) and $conf_UAM[0] == 'true') and (isset($conf_UAM[1]) and $conf_UAM[1] == 'local')) |
---|
95 | { |
---|
96 | // This is to send an information email and set user to "waiting" group or status until admin validation |
---|
97 | $passwd = (isset($_POST['password'])) ? $_POST['password'] : ''; |
---|
98 | SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], false); |
---|
99 | setgroup($register_user['id']);// Set to "waiting" group or status until admin validation |
---|
100 | } |
---|
101 | elseif ((isset($conf_UAM[0]) and $conf_UAM[0] == 'false') and (isset($conf_UAM[1]) and $conf_UAM[1] == 'local')) |
---|
102 | { |
---|
103 | // This is to set user to "waiting" group or status until admin validation |
---|
104 | setgroup($register_user['id']);// Set to "waiting" group or status until admin validation |
---|
105 | } |
---|
106 | elseif ((isset($conf_UAM[0]) and $conf_UAM[0] == 'true') and (isset($conf_UAM[1]) and $conf_UAM[1] == 'false')) |
---|
107 | { |
---|
108 | // This is to send an information email without validation key |
---|
109 | $passwd = (isset($_POST['password'])) ? $_POST['password'] : ''; |
---|
110 | SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], false); |
---|
111 | } |
---|
112 | // Sending registration confirmation by email |
---|
113 | elseif ((isset($conf_UAM[0]) and $conf_UAM[0] == 'true' or $conf_UAM[0] == 'false') and (isset($conf_UAM[1]) and $conf_UAM[1] == 'true')) |
---|
114 | { |
---|
115 | if (is_admin() and isset($conf_UAM[20]) and $conf_UAM[20] == 'true') |
---|
116 | { |
---|
117 | $passwd = (isset($_POST['password'])) ? $_POST['password'] : ''; |
---|
118 | SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], true); |
---|
119 | } |
---|
120 | elseif (is_admin() and isset($conf_UAM[20]) and $conf_UAM[20] == 'false') |
---|
121 | { |
---|
122 | $passwd = (isset($_POST['password'])) ? $_POST['password'] : ''; |
---|
123 | SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], false); |
---|
124 | } |
---|
125 | elseif (!is_admin()) |
---|
126 | { |
---|
127 | $passwd = (isset($_POST['password'])) ? $_POST['password'] : ''; |
---|
128 | SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], true); |
---|
129 | } |
---|
130 | } |
---|
131 | } |
---|
132 | } |
---|
133 | |
---|
134 | /** |
---|
135 | * Triggered on delete_user |
---|
136 | * |
---|
137 | * Database cleanup on user deletion |
---|
138 | */ |
---|
139 | function UAM_Deluser($user_id) |
---|
140 | { |
---|
141 | // Cleanup for ConfirmMail table |
---|
142 | DeleteConfirmMail($user_id); |
---|
143 | // Cleanup for LastVisit table |
---|
144 | DeleteLastVisit($user_id); |
---|
145 | // Cleanup Redirection settings |
---|
146 | DeleteRedir($user_id); |
---|
147 | } |
---|
148 | |
---|
149 | /** |
---|
150 | * Triggered on register_user_check |
---|
151 | * |
---|
152 | * Additional controls on user registration check |
---|
153 | */ |
---|
154 | function UAM_RegistrationCheck($errors, $user) |
---|
155 | { |
---|
156 | global $conf; |
---|
157 | |
---|
158 | // Exclusion of Adult_Content users |
---|
159 | if ($user['username'] != "16" and $user['username'] != "18") |
---|
160 | { |
---|
161 | load_language('plugin.lang', UAM_PATH); |
---|
162 | |
---|
163 | $PasswordCheck = 0; |
---|
164 | |
---|
165 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
166 | |
---|
167 | // Password enforcement control |
---|
168 | if (isset($conf_UAM[13]) and $conf_UAM[13] == 'true' and !empty($conf_UAM[14])) |
---|
169 | { |
---|
170 | if (!empty($user['password']) and !is_admin()) |
---|
171 | { |
---|
172 | $PasswordCheck = testpassword($user['password']); |
---|
173 | |
---|
174 | if ($PasswordCheck < $conf_UAM[14]) |
---|
175 | { |
---|
176 | $message = get_l10n_args('UAM_reg_err_login4_%s', $PasswordCheck); |
---|
177 | $lang['reg_err_pass'] = l10n_args($message).$conf_UAM[14]; |
---|
178 | array_push($errors, $lang['reg_err_pass']); |
---|
179 | } |
---|
180 | } |
---|
181 | else if (!empty($user['password']) and is_admin() and isset($conf_UAM[15]) and $conf_UAM[15] == 'true') |
---|
182 | { |
---|
183 | $PasswordCheck = testpassword($user['password']); |
---|
184 | |
---|
185 | if ($PasswordCheck < $conf_UAM[14]) |
---|
186 | { |
---|
187 | $message = get_l10n_args('UAM_reg_err_login4_%s', $PasswordCheck); |
---|
188 | $lang['reg_err_pass'] = l10n_args($message).$conf_UAM[14]; |
---|
189 | array_push($errors, $lang['reg_err_pass']); |
---|
190 | } |
---|
191 | } |
---|
192 | } |
---|
193 | |
---|
194 | // Username without forbidden keys |
---|
195 | if (isset($conf_UAM[6]) and $conf_UAM[6] == 'true' and !empty($user['username']) and ValidateUsername($user['username']) and !is_admin()) |
---|
196 | { |
---|
197 | $lang['reg_err_login1'] = l10n('UAM_reg_err_login2')."'".$conf_UAM[7]."'"; |
---|
198 | array_push($errors, $lang['reg_err_login1']); |
---|
199 | } |
---|
200 | |
---|
201 | // Email without forbidden domains |
---|
202 | if (isset($conf_UAM[11]) and $conf_UAM[11] == 'true' and !empty($user['email']) and ValidateEmailProvider($user['email']) and !is_admin()) |
---|
203 | { |
---|
204 | $lang['reg_err_login1'] = l10n('UAM_reg_err_login5')."'".$conf_UAM[12]."'"; |
---|
205 | array_push($errors, $lang['reg_err_login1']); |
---|
206 | } |
---|
207 | return $errors; |
---|
208 | } |
---|
209 | } |
---|
210 | |
---|
211 | /** |
---|
212 | * Triggered on loc_begin_profile |
---|
213 | */ |
---|
214 | function UAM_Profile_Init() |
---|
215 | { |
---|
216 | global $conf, $user, $template; |
---|
217 | |
---|
218 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
219 | |
---|
220 | if ((isset($conf_UAM[21]) and $conf_UAM[21] == 'true')) |
---|
221 | { |
---|
222 | $user_idsOK = array(); |
---|
223 | if (!UAM_check_profile($user['id'], $user_idsOK)) |
---|
224 | { |
---|
225 | $user_idsOK[] = $user['id']; |
---|
226 | |
---|
227 | $query = " |
---|
228 | UPDATE ".CONFIG_TABLE." |
---|
229 | SET value = \"".implode(',', $user_idsOK)."\" |
---|
230 | WHERE param = 'UserAdvManager_Redir';"; |
---|
231 | |
---|
232 | pwg_query($query); |
---|
233 | } |
---|
234 | } |
---|
235 | |
---|
236 | if (isset($_POST['validate']) and !is_admin()) |
---|
237 | { |
---|
238 | // Email without forbidden domains |
---|
239 | if (isset($conf_UAM[11]) and $conf_UAM[11] == 'true' and !empty($_POST['mail_address'])) |
---|
240 | { |
---|
241 | if (ValidateEmailProvider($_POST['mail_address'])) |
---|
242 | { |
---|
243 | $template->append('errors', l10n('UAM_reg_err_login5')."'".$conf_UAM[12]."'"); |
---|
244 | unset($_POST['validate']); |
---|
245 | } |
---|
246 | } |
---|
247 | |
---|
248 | $typemail = 3; |
---|
249 | |
---|
250 | if (!empty($_POST['use_new_pwd'])) |
---|
251 | { |
---|
252 | $typemail = 2; |
---|
253 | |
---|
254 | // Password enforcement control |
---|
255 | if (isset($conf_UAM[13]) and $conf_UAM[13] == 'true' and !empty($conf_UAM[14])) |
---|
256 | { |
---|
257 | $PasswordCheck = testpassword($_POST['use_new_pwd']); |
---|
258 | |
---|
259 | if ($PasswordCheck < $conf_UAM[14]) |
---|
260 | { |
---|
261 | $message = get_l10n_args('UAM_reg_err_login4_%s', $PasswordCheck); |
---|
262 | $template->append('errors', l10n_args($message).$conf_UAM[14]); |
---|
263 | unset($_POST['use_new_pwd']); |
---|
264 | unset($_POST['validate']); |
---|
265 | } |
---|
266 | } |
---|
267 | } |
---|
268 | |
---|
269 | // Sending registration confirmation by email |
---|
270 | if ((isset($conf_UAM[0]) and $conf_UAM[0] == 'true') or (isset($conf_UAM[1]) and $conf_UAM[1] == 'true') or (isset($conf_UAM[1]) and $conf_UAM[1] == 'local')) |
---|
271 | { |
---|
272 | $confirm_mail_need = false; |
---|
273 | |
---|
274 | if (!empty($_POST['mail_address'])) |
---|
275 | { |
---|
276 | $query = ' |
---|
277 | SELECT '.$conf['user_fields']['email'].' AS email |
---|
278 | FROM '.USERS_TABLE.' |
---|
279 | WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\' |
---|
280 | ;'; |
---|
281 | |
---|
282 | list($current_email) = pwg_db_fetch_row(pwg_query($query)); |
---|
283 | |
---|
284 | // This is to send a new validation key |
---|
285 | if ($_POST['mail_address'] != $current_email and (isset($conf_UAM[1]) and $conf_UAM[1] == 'true')) |
---|
286 | |
---|
287 | $confirm_mail_need = true; |
---|
288 | |
---|
289 | // This is to set the user to "waiting" group or status until admin validation |
---|
290 | if ($_POST['mail_address'] != $current_email and (isset($conf_UAM[1]) and $conf_UAM[1] == 'local')) |
---|
291 | |
---|
292 | setgroup($register_user['id']);// Set to "waiting" group or status until admin validation |
---|
293 | $confirm_mail_need = false; |
---|
294 | } |
---|
295 | |
---|
296 | if ((!empty($_POST['use_new_pwd']) and (isset($conf_UAM[0]) and $conf_UAM[0] == 'true') or $confirm_mail_need)) |
---|
297 | { |
---|
298 | $query = ' |
---|
299 | SELECT '.$conf['user_fields']['username'].' |
---|
300 | FROM '.USERS_TABLE.' |
---|
301 | WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\' |
---|
302 | ;'; |
---|
303 | |
---|
304 | list($username) = pwg_db_fetch_row(pwg_query($query)); |
---|
305 | SendMail2User($typemail, $user['id'], $username, $_POST['use_new_pwd'], $_POST['mail_address'], $confirm_mail_need); |
---|
306 | } |
---|
307 | } |
---|
308 | } |
---|
309 | } |
---|
310 | |
---|
311 | /** |
---|
312 | * Triggered on login_success |
---|
313 | * |
---|
314 | * Triggers scheduled tasks at login |
---|
315 | * Redirects a visitor (except for admins, webmasters and generic statuses) to his profile.php page (Thx to LucMorizur) |
---|
316 | * |
---|
317 | */ |
---|
318 | function UAM_LoginTasks() |
---|
319 | { |
---|
320 | global $conf, $user; |
---|
321 | |
---|
322 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
323 | |
---|
324 | // Performing scheduled tasks |
---|
325 | if ((isset($conf_UAM[22]) and $conf_UAM[22] == 'true')) |
---|
326 | { |
---|
327 | UAM_ScheduledTasks(); |
---|
328 | } |
---|
329 | |
---|
330 | if ((isset($conf_UAM[21]) and $conf_UAM[21] == 'true')) |
---|
331 | { |
---|
332 | // Performing redirection |
---|
333 | $query =' |
---|
334 | SELECT user_id, status |
---|
335 | FROM '.USER_INFOS_TABLE.' |
---|
336 | WHERE user_id = '.$user['id'].' |
---|
337 | ;'; |
---|
338 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
339 | |
---|
340 | if ($data['status'] <> "admin" and $data['status'] <> "webmaster" and $data['status'] <> "generic") |
---|
341 | { |
---|
342 | $user_idsOK = array(); |
---|
343 | if (!UAM_check_profile($user['id'], $user_idsOK)) |
---|
344 | redirect(PHPWG_ROOT_PATH.'profile.php'); |
---|
345 | } |
---|
346 | } |
---|
347 | } |
---|
348 | |
---|
349 | /** |
---|
350 | * Triggered on UAM_LoginTasks() |
---|
351 | * |
---|
352 | * Executes optional post-login tasks |
---|
353 | * |
---|
354 | */ |
---|
355 | function UAM_ScheduledTasks() |
---|
356 | { |
---|
357 | global $conf, $user, $page; |
---|
358 | |
---|
359 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
360 | |
---|
361 | $collection = array(); |
---|
362 | $reminder = false; |
---|
363 | |
---|
364 | $page['filtered_users'] = get_ghosts_autotasks(); |
---|
365 | |
---|
366 | foreach($page['filtered_users'] as $listed_user) |
---|
367 | { |
---|
368 | array_push($collection, $listed_user['id']); |
---|
369 | } |
---|
370 | |
---|
371 | // Ghost accounts auto group or status downgrade with or without information email sending and autodeletion if user already reminded |
---|
372 | if ((isset($conf_UAM[22]) and $conf_UAM[22] == 'true') and ((isset($conf_UAM[26]) and $conf_UAM[26] <> -1) or (isset($conf_UAM[27]) and $conf_UAM[27] <> -1))) |
---|
373 | { |
---|
374 | if (count($collection) > 0) |
---|
375 | { |
---|
376 | // Process if a non-admin nor webmaster user is logged |
---|
377 | if (in_array($user['id'], $collection)) |
---|
378 | { |
---|
379 | foreach ($collection as $user_id) |
---|
380 | { |
---|
381 | // Check lastvisit reminder state |
---|
382 | $query = ' |
---|
383 | SELECT reminder |
---|
384 | FROM '.USER_LASTVISIT_TABLE.' |
---|
385 | WHERE user_id = '.$user_id.';'; |
---|
386 | |
---|
387 | $result = pwg_db_fetch_assoc(pwg_query($query)); |
---|
388 | |
---|
389 | if (isset($result['reminder']) and $result['reminder'] == 'true') |
---|
390 | { |
---|
391 | $reminder = true; |
---|
392 | } |
---|
393 | else |
---|
394 | { |
---|
395 | $reminder = false; |
---|
396 | } |
---|
397 | |
---|
398 | // If never reminded before, set reminder True |
---|
399 | if (!$reminder) |
---|
400 | { |
---|
401 | // Reset of lastvisit date |
---|
402 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
403 | |
---|
404 | $query = " |
---|
405 | UPDATE ".USER_LASTVISIT_TABLE." |
---|
406 | SET lastvisit='".$dbnow."' |
---|
407 | WHERE user_id = '".$user_id."' |
---|
408 | ;"; |
---|
409 | pwg_query($query); |
---|
410 | |
---|
411 | // Auto change group and / or status |
---|
412 | // Delete user from all groups |
---|
413 | $query = " |
---|
414 | DELETE FROM ".USER_GROUP_TABLE." |
---|
415 | WHERE user_id = '".$user_id."' |
---|
416 | AND ( |
---|
417 | group_id = '".$conf_UAM[2]."' |
---|
418 | OR |
---|
419 | group_id = '".$conf_UAM[3]."' |
---|
420 | ) |
---|
421 | ;"; |
---|
422 | |
---|
423 | pwg_query($query); |
---|
424 | |
---|
425 | // Change user status |
---|
426 | if ($conf_UAM[27] <> -1) |
---|
427 | { |
---|
428 | $query = " |
---|
429 | UPDATE ".USER_INFOS_TABLE." |
---|
430 | SET status = '".$conf_UAM[27]."' |
---|
431 | WHERE user_id = '".$user_id."' |
---|
432 | ;"; |
---|
433 | pwg_query($query); |
---|
434 | } |
---|
435 | |
---|
436 | // Change user group |
---|
437 | if ($conf_UAM[26] <> -1) |
---|
438 | { |
---|
439 | $query = " |
---|
440 | INSERT INTO ".USER_GROUP_TABLE." |
---|
441 | (user_id, group_id) |
---|
442 | VALUES |
---|
443 | ('".$user_id."', '".$conf_UAM[26]."') |
---|
444 | ;"; |
---|
445 | pwg_query($query); |
---|
446 | } |
---|
447 | |
---|
448 | // Auto send email notification on group / status downgrade only if never reminded before |
---|
449 | if (isset($conf_UAM[23]) and $conf_UAM[23] == 'true') |
---|
450 | { |
---|
451 | // Set reminder true |
---|
452 | $query = " |
---|
453 | UPDATE ".USER_LASTVISIT_TABLE." |
---|
454 | SET reminder = 'true' |
---|
455 | WHERE user_id = '".$user_id."' |
---|
456 | ;"; |
---|
457 | pwg_query($query); |
---|
458 | |
---|
459 | // Reset confirmed user date_check |
---|
460 | $query = ' |
---|
461 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
462 | SET date_check = NULL |
---|
463 | WHERE user_id = "'.$user_id.'" |
---|
464 | ;'; |
---|
465 | pwg_query($query); |
---|
466 | |
---|
467 | // Get users information for email notification |
---|
468 | $query = ' |
---|
469 | SELECT username, mail_address |
---|
470 | FROM '.USERS_TABLE.' |
---|
471 | WHERE id = '.$user_id.' |
---|
472 | ;'; |
---|
473 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
474 | |
---|
475 | demotion_mail($user_id, $data['username'], $data['mail_address']); |
---|
476 | } |
---|
477 | } |
---|
478 | elseif ($reminder) // If user already reminded for ghost account |
---|
479 | { |
---|
480 | // delete account |
---|
481 | delete_user($user_id); |
---|
482 | } |
---|
483 | } |
---|
484 | |
---|
485 | if (!$reminder) // If user never reminded for ghost account |
---|
486 | { |
---|
487 | // Logged-in user cleanup |
---|
488 | invalidate_user_cache(); |
---|
489 | log_user($user['id'], false); |
---|
490 | redirect(make_index_url()); |
---|
491 | } |
---|
492 | elseif ($reminder) // If user already reminded for ghost account |
---|
493 | { |
---|
494 | // Logged-in user cleanup |
---|
495 | invalidate_user_cache(); |
---|
496 | log_user($user['id'], false); |
---|
497 | redirect(UAM_PATH.'del_account.php'); |
---|
498 | } |
---|
499 | } |
---|
500 | else // Process if an admin or webmaster user is logged |
---|
501 | { |
---|
502 | foreach ($collection as $user_id) |
---|
503 | { |
---|
504 | // Check lastvisit reminder state |
---|
505 | $query = ' |
---|
506 | SELECT reminder |
---|
507 | FROM '.USER_LASTVISIT_TABLE.' |
---|
508 | WHERE user_id = '.$user_id.';'; |
---|
509 | |
---|
510 | $result = pwg_db_fetch_assoc(pwg_query($query)); |
---|
511 | |
---|
512 | if (isset($result['reminder']) and $result['reminder'] == 'true') |
---|
513 | { |
---|
514 | $reminder = true; |
---|
515 | } |
---|
516 | else |
---|
517 | { |
---|
518 | $reminder = false; |
---|
519 | } |
---|
520 | |
---|
521 | // If never reminded before |
---|
522 | if (!$reminder) |
---|
523 | { |
---|
524 | // Reset of lastvisit date |
---|
525 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
526 | |
---|
527 | $query = " |
---|
528 | UPDATE ".USER_LASTVISIT_TABLE." |
---|
529 | SET lastvisit='".$dbnow."' |
---|
530 | WHERE user_id = '".$user_id."' |
---|
531 | ;"; |
---|
532 | pwg_query($query); |
---|
533 | |
---|
534 | // Auto change group and / or status |
---|
535 | // Delete user from all groups |
---|
536 | $query = " |
---|
537 | DELETE FROM ".USER_GROUP_TABLE." |
---|
538 | WHERE user_id = '".$user_id."' |
---|
539 | AND ( |
---|
540 | group_id = '".$conf_UAM[2]."' |
---|
541 | OR |
---|
542 | group_id = '".$conf_UAM[3]."' |
---|
543 | ) |
---|
544 | ;"; |
---|
545 | pwg_query($query); |
---|
546 | |
---|
547 | // Change user status |
---|
548 | if ($conf_UAM[27] <> -1) |
---|
549 | { |
---|
550 | $query = " |
---|
551 | UPDATE ".USER_INFOS_TABLE." |
---|
552 | SET status = '".$conf_UAM[27]."' |
---|
553 | WHERE user_id = '".$user_id."' |
---|
554 | ;"; |
---|
555 | pwg_query($query); |
---|
556 | } |
---|
557 | |
---|
558 | // Change user group |
---|
559 | if ($conf_UAM[26] <> -1) |
---|
560 | { |
---|
561 | $query = " |
---|
562 | INSERT INTO ".USER_GROUP_TABLE." |
---|
563 | (user_id, group_id) |
---|
564 | VALUES |
---|
565 | ('".$user_id."', '".$conf_UAM[26]."') |
---|
566 | ;"; |
---|
567 | pwg_query($query); |
---|
568 | } |
---|
569 | |
---|
570 | // Auto send email notification on group / status downgrade |
---|
571 | if (isset($conf_UAM[23]) and $conf_UAM[23] == 'true') |
---|
572 | { |
---|
573 | // Set reminder true |
---|
574 | $query = " |
---|
575 | UPDATE ".USER_LASTVISIT_TABLE." |
---|
576 | SET reminder = 'true' |
---|
577 | WHERE user_id = '".$user_id."' |
---|
578 | ;"; |
---|
579 | pwg_query($query); |
---|
580 | |
---|
581 | // Reset confirmed user status to unvalidated |
---|
582 | $query = ' |
---|
583 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
584 | SET date_check = NULL |
---|
585 | WHERE user_id = "'.$user_id.'" |
---|
586 | ;'; |
---|
587 | pwg_query($query); |
---|
588 | |
---|
589 | // Get users information for email notification |
---|
590 | $query = ' |
---|
591 | SELECT id, username, mail_address |
---|
592 | FROM '.USERS_TABLE.' |
---|
593 | WHERE id = '.$user_id.' |
---|
594 | ;'; |
---|
595 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
596 | |
---|
597 | demotion_mail($user_id, $data['username'], $data['mail_address']); |
---|
598 | } |
---|
599 | } |
---|
600 | elseif ($reminder) // If user already reminded for ghost account |
---|
601 | { |
---|
602 | // delete account |
---|
603 | delete_user($user_id); |
---|
604 | } |
---|
605 | } |
---|
606 | } |
---|
607 | } |
---|
608 | } |
---|
609 | } |
---|
610 | |
---|
611 | /** |
---|
612 | * Triggered on init |
---|
613 | * |
---|
614 | * Check for forbidden email domains in admin's users management panel |
---|
615 | */ |
---|
616 | function UAM_InitPage() |
---|
617 | { |
---|
618 | load_language('plugin.lang', UAM_PATH); |
---|
619 | global $conf, $template, $page, $lang, $errors; |
---|
620 | |
---|
621 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
622 | |
---|
623 | // Admin user management |
---|
624 | if (script_basename() == 'admin' and isset($_GET['page']) and $_GET['page'] == 'user_list') |
---|
625 | { |
---|
626 | if (isset($_POST['submit_add'])) |
---|
627 | { |
---|
628 | // Email without forbidden domains |
---|
629 | if (isset($conf_UAM[11]) and $conf_UAM[11] == 'true' and !empty($_POST['email']) and ValidateEmailProvider($_POST['email'])) |
---|
630 | { |
---|
631 | $template->append('errors', l10n('UAM_reg_err_login5')."'".$conf_UAM[12]."'"); |
---|
632 | unset($_POST['submit_add']); |
---|
633 | } |
---|
634 | } |
---|
635 | } |
---|
636 | } |
---|
637 | |
---|
638 | |
---|
639 | /** |
---|
640 | * Triggered on render_lost_password_mail_content |
---|
641 | * |
---|
642 | * Adds a customized text in lost password email content |
---|
643 | * Added text is inserted before users login name and new password |
---|
644 | * |
---|
645 | * @param : Standard Piwigo email content |
---|
646 | * |
---|
647 | * @return : Customized content added to standard content |
---|
648 | * |
---|
649 | */ |
---|
650 | function UAM_lost_password_mail_content($infos) |
---|
651 | { |
---|
652 | global $conf; |
---|
653 | |
---|
654 | load_language('plugin.lang', UAM_PATH); |
---|
655 | |
---|
656 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
657 | |
---|
658 | if (isset($conf_UAM[29]) and $conf_UAM[29] == 'true') |
---|
659 | { |
---|
660 | // Management of Extension flags ([username], [mygallery], [myurl]) |
---|
661 | $patterns[] = '#\[username\]#i'; |
---|
662 | $replacements[] = stripslashes($row['username']); |
---|
663 | $patterns[] = '#\[mygallery\]#i'; |
---|
664 | $replacements[] = $conf['gallery_title']; |
---|
665 | $patterns[] = '#\[myurl\]#i'; |
---|
666 | $replacements[] = $conf['gallery_url']; |
---|
667 | |
---|
668 | $infos = preg_replace($patterns, $replacements, $conf_UAM[30])."\n"."\n".$infos; |
---|
669 | } |
---|
670 | return $infos; |
---|
671 | } |
---|
672 | |
---|
673 | |
---|
674 | /** |
---|
675 | * Triggered on user_comment_check |
---|
676 | * |
---|
677 | * checks if author is mandatory and set on comments post |
---|
678 | * |
---|
679 | * @param : comment action, comment |
---|
680 | * |
---|
681 | * @return : comment action |
---|
682 | * |
---|
683 | */ |
---|
684 | function UAM_CheckEmptyCommentAuthor($comment_action, $comm) |
---|
685 | { |
---|
686 | load_language('plugin.lang', UAM_PATH); |
---|
687 | global $infos, $conf, $template; |
---|
688 | |
---|
689 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
690 | |
---|
691 | // User creation OR update |
---|
692 | if (isset($conf_UAM[5]) and $conf_UAM[5] == 'true' and $conf['comments_forall'] == 'true' and $comm['author'] == 'guest') |
---|
693 | { |
---|
694 | $comment_action = 'reject'; |
---|
695 | |
---|
696 | array_push($infos, l10n('UAM_Empty Author')); |
---|
697 | } |
---|
698 | |
---|
699 | return $comment_action; |
---|
700 | } |
---|
701 | |
---|
702 | /** |
---|
703 | * Function called from main.inc.php to send validation email |
---|
704 | * |
---|
705 | * @param : Type of email, user id, username, email address, confirmation (optional) |
---|
706 | * |
---|
707 | */ |
---|
708 | function SendMail2User($typemail, $id, $username, $password, $email, $confirm) |
---|
709 | { |
---|
710 | global $conf; |
---|
711 | |
---|
712 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
713 | |
---|
714 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
715 | |
---|
716 | $infos1_perso = ""; |
---|
717 | $infos2_perso = ""; |
---|
718 | |
---|
719 | // We have to get the user's language in database |
---|
720 | $query =' |
---|
721 | SELECT user_id, language |
---|
722 | FROM '.USER_INFOS_TABLE.' |
---|
723 | WHERE user_id = '.$id.' |
---|
724 | ;'; |
---|
725 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
726 | |
---|
727 | // Check if user is already registered (profile changing) - If not (new registration), language is set to current gallery language |
---|
728 | if (empty($data)) |
---|
729 | { |
---|
730 | // And switch gallery to this language before using personalized and multilangual contents |
---|
731 | $language = pwg_get_session_var( 'lang_switch', $user['language'] ); |
---|
732 | switch_lang_to($language); |
---|
733 | } |
---|
734 | else |
---|
735 | { |
---|
736 | // And switch gallery to this language before using personalized and multilangual contents |
---|
737 | $language = $data['language']; // Usefull for debugging |
---|
738 | switch_lang_to($data['language']); |
---|
739 | load_language('plugin.lang', UAM_PATH); |
---|
740 | } |
---|
741 | |
---|
742 | switch($typemail) |
---|
743 | { |
---|
744 | case 1: |
---|
745 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('UAM_Add of %s', stripslashes($username))); |
---|
746 | $password = $password <> '' ? $password : l10n('UAM_empty_pwd'); |
---|
747 | |
---|
748 | if (isset($conf_UAM[9]) and $conf_UAM[9] <> '') |
---|
749 | { |
---|
750 | // Management of Extension flags ([username], [mygallery], [myurl]) |
---|
751 | $patterns[] = '#\[username\]#i'; |
---|
752 | $replacements[] = $username; |
---|
753 | $patterns[] = '#\[mygallery\]#i'; |
---|
754 | $replacements[] = $conf['gallery_title']; |
---|
755 | $patterns[] = '#\[myurl\]#i'; |
---|
756 | $replacements[] = $conf['gallery_url']; |
---|
757 | |
---|
758 | if (function_exists('get_user_language_desc')) |
---|
759 | { |
---|
760 | $infos1_perso = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM[9]))."\n\n"; |
---|
761 | } |
---|
762 | else $infos1_perso = l10n(preg_replace($patterns, $replacements, $conf_UAM[9]))."\n\n"; |
---|
763 | } |
---|
764 | |
---|
765 | break; |
---|
766 | |
---|
767 | case 2: |
---|
768 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('UAM_Update of %s', stripslashes($username))); |
---|
769 | $password = $password <> '' ? $password : l10n('UAM_empty_pwd'); |
---|
770 | |
---|
771 | break; |
---|
772 | |
---|
773 | case 3: |
---|
774 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('UAM_Update of %s', stripslashes($username))); |
---|
775 | $password = $password <> '' ? $password : l10n('UAM_no_update_pwd'); |
---|
776 | |
---|
777 | break; |
---|
778 | } |
---|
779 | |
---|
780 | if (isset($conf_UAM[0]) and $conf_UAM[0] == 'true') |
---|
781 | { |
---|
782 | $infos1 = array( |
---|
783 | get_l10n_args('UAM_infos_mail %s', stripslashes($username)), |
---|
784 | get_l10n_args('UAM_User: %s', stripslashes($username)), |
---|
785 | get_l10n_args('UAM_Password: %s', $password), |
---|
786 | get_l10n_args('Email: %s', $email), |
---|
787 | get_l10n_args('', ''), |
---|
788 | ); |
---|
789 | } |
---|
790 | |
---|
791 | |
---|
792 | if ( isset($conf_UAM[1]) and $conf_UAM[1] == 'true' and $confirm) |
---|
793 | { |
---|
794 | $infos2 = array |
---|
795 | ( |
---|
796 | get_l10n_args('UAM_Link: %s', AddConfirmMail($id, $email)), |
---|
797 | get_l10n_args('', ''), |
---|
798 | ); |
---|
799 | |
---|
800 | if (isset($conf_UAM[10]) and $conf_UAM[10] <> '') |
---|
801 | { |
---|
802 | // Management of Extension flags ([username], [mygallery], [myurl]) |
---|
803 | $patterns[] = '#\[username\]#i'; |
---|
804 | $replacements[] = $username; |
---|
805 | $patterns[] = '#\[mygallery\]#i'; |
---|
806 | $replacements[] = $conf['gallery_title']; |
---|
807 | $patterns[] = '#\[myurl\]#i'; |
---|
808 | $replacements[] = $conf['gallery_url']; |
---|
809 | |
---|
810 | if (function_exists('get_user_language_desc')) |
---|
811 | { |
---|
812 | $infos2_perso = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM[10]))."\n\n"; |
---|
813 | } |
---|
814 | else $infos2_perso = l10n(preg_replace($patterns, $replacements, $conf_UAM[10]))."\n\n"; |
---|
815 | } |
---|
816 | } |
---|
817 | |
---|
818 | // ******************************************************** |
---|
819 | // **** Pending code since to find how to make it work **** |
---|
820 | // ******************************************************** |
---|
821 | // Testing if FCK Editor is used. Then decoding htmlchars to avoid problems with pwg_mail() |
---|
822 | /*$areas = array(); |
---|
823 | array_push( $areas,'UAM_MailInfo_Text','UAM_ConfirmMail_Text'); |
---|
824 | |
---|
825 | if (function_exists('set_fckeditor_instance')) |
---|
826 | { |
---|
827 | $fcke_config = unserialize($conf['FCKEditor']); |
---|
828 | foreach($areas as $area) |
---|
829 | { |
---|
830 | if (isset($fcke_config['UAM_MailInfo_Text']) and $fcke_config['UAM_MailInfo_Text'] = true) |
---|
831 | { |
---|
832 | $infos1_perso = html_entity_decode($infos1_perso,ENT_QUOTES,UTF-8); |
---|
833 | } |
---|
834 | |
---|
835 | if (isset($fcke_config['UAM_ConfirmMail_Text']) and $fcke_config['UAM_ConfirmMail_Text'] = true) |
---|
836 | { |
---|
837 | $infos2_perso = html_entity_decode($infos2_perso,ENT_QUOTES,UTF-8); |
---|
838 | } |
---|
839 | } |
---|
840 | }*/ |
---|
841 | |
---|
842 | |
---|
843 | // Sending the email with subject and contents |
---|
844 | pwg_mail($email, array( |
---|
845 | 'subject' => $subject, |
---|
846 | 'content' => (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "").get_absolute_root_url(), |
---|
847 | )); |
---|
848 | |
---|
849 | // ********************** |
---|
850 | // Email sending debugger |
---|
851 | // This is only to trace |
---|
852 | // the send of emails for |
---|
853 | // debugging |
---|
854 | // ********************** |
---|
855 | //$content = (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "").get_absolute_root_url(); |
---|
856 | //MailLog($email,$subject,$content,$language); |
---|
857 | // ********************** |
---|
858 | |
---|
859 | // Switching back to default language |
---|
860 | switch_lang_back(); |
---|
861 | } |
---|
862 | |
---|
863 | /** |
---|
864 | * Function called from UAM_admin.php to resend validation email with or without new validation key |
---|
865 | * |
---|
866 | * @param : Type of email, user id, username, email address, confirmation (optional) |
---|
867 | * |
---|
868 | */ |
---|
869 | function ResendMail2User($typemail, $user_id, $username, $email, $confirm) |
---|
870 | { |
---|
871 | global $conf; |
---|
872 | |
---|
873 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
874 | |
---|
875 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
---|
876 | |
---|
877 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
878 | |
---|
879 | // We have to get the user's language in database |
---|
880 | $query =' |
---|
881 | SELECT user_id, language |
---|
882 | FROM '.USER_INFOS_TABLE.' |
---|
883 | WHERE user_id = '.$user_id.' |
---|
884 | ;'; |
---|
885 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
886 | $language = $data['language']; |
---|
887 | |
---|
888 | // And switch gallery to this language before using personalized and multilangual contents |
---|
889 | switch_lang_to($data['language']); |
---|
890 | |
---|
891 | load_language('plugin.lang', UAM_PATH); |
---|
892 | |
---|
893 | switch($typemail) |
---|
894 | { |
---|
895 | case 1: |
---|
896 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('UAM_Reminder_with_key_of_%s', $username)); |
---|
897 | |
---|
898 | if (isset($conf_UAM_ConfirmMail[2]) and $conf_UAM_ConfirmMail[2] <> '' and isset($conf_UAM_ConfirmMail[3]) and $conf_UAM_ConfirmMail[3] == 'true' and $confirm) |
---|
899 | { |
---|
900 | // Management of Extension flags ([username], [mygallery], [myurl]) |
---|
901 | $patterns[] = '#\[username\]#i'; |
---|
902 | $replacements[] = $username; |
---|
903 | $patterns[] = '#\[mygallery\]#i'; |
---|
904 | $replacements[] = $conf['gallery_title']; |
---|
905 | $patterns[] = '#\[myurl\]#i'; |
---|
906 | $replacements[] = $conf['gallery_url']; |
---|
907 | |
---|
908 | if (function_exists('get_user_language_desc')) |
---|
909 | { |
---|
910 | $infos1 = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM_ConfirmMail[2]))."\n\n"; |
---|
911 | } |
---|
912 | else $infos1 = l10n(preg_replace($patterns, $replacements, $conf_UAM_ConfirmMail[2]))."\n\n"; |
---|
913 | |
---|
914 | $infos2 = array |
---|
915 | ( |
---|
916 | get_l10n_args('UAM_Link: %s', ResetConfirmMail($user_id)), |
---|
917 | get_l10n_args('', ''), |
---|
918 | ); |
---|
919 | } |
---|
920 | |
---|
921 | // Set reminder true |
---|
922 | $query = " |
---|
923 | UPDATE ".USER_CONFIRM_MAIL_TABLE." |
---|
924 | SET reminder = 'true' |
---|
925 | WHERE user_id = '".$user_id."' |
---|
926 | ;"; |
---|
927 | pwg_query($query); |
---|
928 | |
---|
929 | break; |
---|
930 | |
---|
931 | case 2: |
---|
932 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('UAM_Reminder_without_key_of_%s',$username)); |
---|
933 | |
---|
934 | if (isset($conf_UAM_ConfirmMail[4]) and $conf_UAM_ConfirmMail[4] <> '' and isset($conf_UAM_ConfirmMail[3]) and $conf_UAM_ConfirmMail[3] == 'true' and !$confirm) |
---|
935 | { |
---|
936 | // Management of Extension flags ([username], [mygallery], [myurl]) |
---|
937 | $patterns[] = '#\[username\]#i'; |
---|
938 | $replacements[] = $username; |
---|
939 | $patterns[] = '#\[mygallery\]#i'; |
---|
940 | $replacements[] = $conf['gallery_title']; |
---|
941 | $patterns[] = '#\[myurl\]#i'; |
---|
942 | $replacements[] = $conf['gallery_url']; |
---|
943 | |
---|
944 | if (function_exists('get_user_language_desc')) |
---|
945 | { |
---|
946 | $infos1 = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM_ConfirmMail[4]))."\n\n"; |
---|
947 | } |
---|
948 | else $infos1 = l10n(preg_replace($patterns, $replacements, $conf_UAM_ConfirmMail[4]))."\n\n"; |
---|
949 | } |
---|
950 | |
---|
951 | // Set reminder true |
---|
952 | $query = " |
---|
953 | UPDATE ".USER_CONFIRM_MAIL_TABLE." |
---|
954 | SET reminder = 'true' |
---|
955 | WHERE user_id = '".$user_id."' |
---|
956 | ;"; |
---|
957 | pwg_query($query); |
---|
958 | |
---|
959 | break; |
---|
960 | } |
---|
961 | |
---|
962 | pwg_mail($email, array( |
---|
963 | 'subject' => $subject, |
---|
964 | 'content' => ($infos1."\n\n").(isset($infos2) ? l10n_args($infos2)."\n\n" : "").get_absolute_root_url(), |
---|
965 | )); |
---|
966 | |
---|
967 | // ********************** |
---|
968 | // Email sending debugger |
---|
969 | // This is only to trace |
---|
970 | // the send of emails for |
---|
971 | // debugging |
---|
972 | // ********************** |
---|
973 | //$content = ($infos1."\n\n").(isset($infos2) ? l10n_args($infos2)."\n\n" : "").get_absolute_root_url(); |
---|
974 | //MailLog($email,$subject,$content,$language); |
---|
975 | // ********************** |
---|
976 | |
---|
977 | // Switching back to default language |
---|
978 | switch_lang_back(); |
---|
979 | } |
---|
980 | |
---|
981 | /** |
---|
982 | * Function called from UAM_admin.php to send a reminder mail for ghost users |
---|
983 | * |
---|
984 | * @param : User id, username, email address |
---|
985 | * |
---|
986 | */ |
---|
987 | function ghostreminder($user_id, $username, $email) |
---|
988 | { |
---|
989 | global $conf; |
---|
990 | |
---|
991 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
992 | |
---|
993 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
994 | |
---|
995 | $infos1_perso = ""; |
---|
996 | |
---|
997 | // We have to get the user's language in database |
---|
998 | $query =' |
---|
999 | SELECT user_id, language |
---|
1000 | FROM '.USER_INFOS_TABLE.' |
---|
1001 | WHERE user_id = '.$user_id.' |
---|
1002 | ;'; |
---|
1003 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
1004 | $language = $data['language']; |
---|
1005 | |
---|
1006 | // And switch gallery to this language before using personalized and multilangual contents |
---|
1007 | switch_lang_to($data['language']); |
---|
1008 | |
---|
1009 | load_language('plugin.lang', UAM_PATH); |
---|
1010 | |
---|
1011 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('UAM_Ghost_reminder_of_%s', $username)); |
---|
1012 | |
---|
1013 | if (isset($conf_UAM[18]) and $conf_UAM[18] <> '' and isset($conf_UAM[16]) and $conf_UAM[16] == 'true') |
---|
1014 | { |
---|
1015 | // Management of Extension flags ([username], [mygallery], [myurl]) |
---|
1016 | $patterns[] = '#\[username\]#i'; |
---|
1017 | $replacements[] = $username; |
---|
1018 | $patterns[] = '#\[mygallery\]#i'; |
---|
1019 | $replacements[] = $conf['gallery_title']; |
---|
1020 | $patterns[] = '#\[myurl\]#i'; |
---|
1021 | $replacements[] = $conf['gallery_url']; |
---|
1022 | |
---|
1023 | if (function_exists('get_user_language_desc')) |
---|
1024 | { |
---|
1025 | $infos1 = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM[18]))."\n\n"; |
---|
1026 | } |
---|
1027 | else |
---|
1028 | { |
---|
1029 | $infos1 = l10n(preg_replace($patterns, $replacements, $conf_UAM[18]))."\n\n"; |
---|
1030 | } |
---|
1031 | |
---|
1032 | resetlastvisit($user_id); |
---|
1033 | } |
---|
1034 | |
---|
1035 | pwg_mail($email, array( |
---|
1036 | 'subject' => $subject, |
---|
1037 | 'content' => $infos1.get_absolute_root_url(), |
---|
1038 | )); |
---|
1039 | |
---|
1040 | // ********************** |
---|
1041 | // Email sending debugger |
---|
1042 | // This is only to trace |
---|
1043 | // the send of emails for |
---|
1044 | // debugging |
---|
1045 | // ********************** |
---|
1046 | //$content = $infos1.get_absolute_root_url(); |
---|
1047 | //MailLog($email,$subject,$content,$language); |
---|
1048 | // ********************** |
---|
1049 | |
---|
1050 | // Switching back to default language |
---|
1051 | switch_lang_back(); |
---|
1052 | } |
---|
1053 | |
---|
1054 | /** |
---|
1055 | * Function called from functions.inc.php to send notification email when user have been downgraded |
---|
1056 | * |
---|
1057 | * @param : user id, username, email address |
---|
1058 | * |
---|
1059 | */ |
---|
1060 | function demotion_mail($id, $username, $email) |
---|
1061 | { |
---|
1062 | global $conf; |
---|
1063 | |
---|
1064 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1065 | |
---|
1066 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
1067 | |
---|
1068 | $custom_txt = ""; |
---|
1069 | |
---|
1070 | // We have to get the user's language in database |
---|
1071 | $query =' |
---|
1072 | SELECT user_id, language |
---|
1073 | FROM '.USER_INFOS_TABLE.' |
---|
1074 | WHERE user_id = '.$id.' |
---|
1075 | ;'; |
---|
1076 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
1077 | |
---|
1078 | // Check if user is already registered (profile changing) - If not (new registration), language is set to current gallery language |
---|
1079 | if (empty($data)) |
---|
1080 | { |
---|
1081 | // And switch gallery to this language before using personalized and multilangual contents |
---|
1082 | $language = pwg_get_session_var( 'lang_switch', $user['language'] ); |
---|
1083 | switch_lang_to($language); |
---|
1084 | } |
---|
1085 | else |
---|
1086 | { |
---|
1087 | // And switch gallery to this language before using personalized and multilangual contents |
---|
1088 | $language = $data['language']; // Usefull for debugging |
---|
1089 | switch_lang_to($data['language']); |
---|
1090 | load_language('plugin.lang', UAM_PATH); |
---|
1091 | } |
---|
1092 | |
---|
1093 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('UAM_Demotion of %s', stripslashes($username))); |
---|
1094 | |
---|
1095 | if (isset($conf_UAM[25]) and $conf_UAM[25] <> '') |
---|
1096 | { |
---|
1097 | // Management of Extension flags ([username], [mygallery], [myurl]) |
---|
1098 | $patterns[] = '#\[username\]#i'; |
---|
1099 | $replacements[] = $username; |
---|
1100 | $patterns[] = '#\[mygallery\]#i'; |
---|
1101 | $replacements[] = $conf['gallery_title']; |
---|
1102 | $patterns[] = '#\[myurl\]#i'; |
---|
1103 | $replacements[] = $conf['gallery_url']; |
---|
1104 | |
---|
1105 | if (function_exists('get_user_language_desc')) |
---|
1106 | { |
---|
1107 | $custom_txt = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM[25]))."\n\n"; |
---|
1108 | } |
---|
1109 | else $custom_txt = l10n(preg_replace($patterns, $replacements, $conf_UAM[25]))."\n\n"; |
---|
1110 | } |
---|
1111 | |
---|
1112 | $infos1 = array( |
---|
1113 | get_l10n_args('UAM_User: %s', stripslashes($username)), |
---|
1114 | get_l10n_args('Email: %s', $email), |
---|
1115 | get_l10n_args('', ''), |
---|
1116 | ); |
---|
1117 | |
---|
1118 | $infos2 = array |
---|
1119 | ( |
---|
1120 | get_l10n_args('UAM_Link: %s', ResetConfirmMail($id)), |
---|
1121 | get_l10n_args('', ''), |
---|
1122 | ); |
---|
1123 | |
---|
1124 | |
---|
1125 | // Sending the email with subject and contents |
---|
1126 | pwg_mail($email, array( |
---|
1127 | 'subject' => $subject, |
---|
1128 | 'content' => ($custom_txt.l10n_args($infos1)."\n\n".l10n_args($infos2)."\n\n").get_absolute_root_url(), |
---|
1129 | )); |
---|
1130 | |
---|
1131 | // ********************** |
---|
1132 | // Email sending debugger |
---|
1133 | // This is only to trace |
---|
1134 | // the send of emails for |
---|
1135 | // debugging |
---|
1136 | // ********************** |
---|
1137 | //$content = ($custom_txt.l10n_args($infos1)."\n\n".l10n_args($infos2)."\n\n").get_absolute_root_url(); |
---|
1138 | //MailLog($email,$subject,$content,$language); |
---|
1139 | // ********************** |
---|
1140 | |
---|
1141 | // Switching back to default language |
---|
1142 | switch_lang_back(); |
---|
1143 | } |
---|
1144 | |
---|
1145 | /** |
---|
1146 | * Function called from UAM_admin.php to send notification email when user registration have been manually validated by admin |
---|
1147 | * |
---|
1148 | * @param : user id |
---|
1149 | * |
---|
1150 | */ |
---|
1151 | function validation_mail($id) |
---|
1152 | { |
---|
1153 | global $conf; |
---|
1154 | |
---|
1155 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1156 | |
---|
1157 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
1158 | |
---|
1159 | $custom_txt = ""; |
---|
1160 | |
---|
1161 | // We have to get the user's language in database |
---|
1162 | $query =' |
---|
1163 | SELECT user_id, language |
---|
1164 | FROM '.USER_INFOS_TABLE.' |
---|
1165 | WHERE user_id = '.$id.' |
---|
1166 | ;'; |
---|
1167 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
1168 | |
---|
1169 | // Check if user is already registered (profile changing) - If not (new registration), language is set to current gallery language |
---|
1170 | if (empty($data)) |
---|
1171 | { |
---|
1172 | // And switch gallery to this language before using personalized and multilangual contents |
---|
1173 | $language = pwg_get_session_var( 'lang_switch', $user['language'] ); |
---|
1174 | switch_lang_to($language); |
---|
1175 | } |
---|
1176 | else |
---|
1177 | { |
---|
1178 | // And switch gallery to this language before using personalized and multilangual contents |
---|
1179 | $language = $data['language']; // Usefull for debugging |
---|
1180 | switch_lang_to($data['language']); |
---|
1181 | load_language('plugin.lang', UAM_PATH); |
---|
1182 | } |
---|
1183 | |
---|
1184 | // Retreive users email and user name from id |
---|
1185 | $query =' |
---|
1186 | SELECT id, username, mail_address |
---|
1187 | FROM '.USERS_TABLE.' |
---|
1188 | WHERE id = '.$id.' |
---|
1189 | ;'; |
---|
1190 | $result = pwg_db_fetch_assoc(pwg_query($query)); |
---|
1191 | |
---|
1192 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('UAM_Validation of %s', stripslashes($result['username']))); |
---|
1193 | |
---|
1194 | if (isset($conf_UAM[28]) and $conf_UAM[28] <> '') |
---|
1195 | { |
---|
1196 | // Management of Extension flags ([username], [mygallery], [myurl]) |
---|
1197 | $patterns[] = '#\[username\]#i'; |
---|
1198 | $replacements[] = $username; |
---|
1199 | $patterns[] = '#\[mygallery\]#i'; |
---|
1200 | $replacements[] = $conf['gallery_title']; |
---|
1201 | $patterns[] = '#\[myurl\]#i'; |
---|
1202 | $replacements[] = $conf['gallery_url']; |
---|
1203 | |
---|
1204 | if (function_exists('get_user_language_desc')) |
---|
1205 | { |
---|
1206 | $custom_txt = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM[28]))."\n\n"; |
---|
1207 | } |
---|
1208 | else $custom_txt = l10n(preg_replace($patterns, $replacements, $conf_UAM[28]))."\n\n"; |
---|
1209 | } |
---|
1210 | |
---|
1211 | $infos = array( |
---|
1212 | get_l10n_args('UAM_User: %s', stripslashes($result['username'])), |
---|
1213 | get_l10n_args('Email: %s', $result['mail_address']), |
---|
1214 | get_l10n_args('', ''), |
---|
1215 | ); |
---|
1216 | |
---|
1217 | // Sending the email with subject and contents |
---|
1218 | pwg_mail($result['mail_address'], array( |
---|
1219 | 'subject' => $subject, |
---|
1220 | 'content' => (l10n_args($infos)."\n\n".$custom_txt), |
---|
1221 | )); |
---|
1222 | |
---|
1223 | // ********************** |
---|
1224 | // Email sending debugger |
---|
1225 | // This is only to trace |
---|
1226 | // the send of emails for |
---|
1227 | // debugging |
---|
1228 | // ********************** |
---|
1229 | //$email = $result['mail_address']; |
---|
1230 | //$content = (l10n_args($infos)."\n\n".$custom_txt); |
---|
1231 | //MailLog($email,$subject,$content,$language); |
---|
1232 | // ********************** |
---|
1233 | |
---|
1234 | // Switching back to default language |
---|
1235 | switch_lang_back(); |
---|
1236 | } |
---|
1237 | |
---|
1238 | /** |
---|
1239 | * Function called from functions AddConfirmMail and ResetConfirmMail for validation key generation |
---|
1240 | * |
---|
1241 | * @return : validation key |
---|
1242 | * |
---|
1243 | */ |
---|
1244 | function FindAvailableConfirmMailID() |
---|
1245 | { |
---|
1246 | while (true) |
---|
1247 | { |
---|
1248 | $id = generate_key(16); |
---|
1249 | $query = " |
---|
1250 | SELECT COUNT(*) |
---|
1251 | FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
1252 | WHERE id = '".$id."' |
---|
1253 | ;"; |
---|
1254 | list($count) = pwg_db_fetch_row(pwg_query($query)); |
---|
1255 | |
---|
1256 | if ($count == 0) |
---|
1257 | return $id; |
---|
1258 | } |
---|
1259 | } |
---|
1260 | |
---|
1261 | /** |
---|
1262 | * Function called from functions SendMail2User to process unvalidated users and generate validation key link |
---|
1263 | * |
---|
1264 | * @param : User id, email address |
---|
1265 | * |
---|
1266 | * @return : Build validation key in URL |
---|
1267 | * |
---|
1268 | */ |
---|
1269 | function AddConfirmMail($user_id, $email) |
---|
1270 | { |
---|
1271 | global $conf; |
---|
1272 | |
---|
1273 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1274 | $Confirm_Mail_ID = FindAvailableConfirmMailID(); |
---|
1275 | |
---|
1276 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
1277 | |
---|
1278 | if (isset($Confirm_Mail_ID)) |
---|
1279 | { |
---|
1280 | $query = " |
---|
1281 | SELECT status |
---|
1282 | FROM ".USER_INFOS_TABLE." |
---|
1283 | WHERE user_id = '".$user_id."' |
---|
1284 | ;"; |
---|
1285 | list($status) = pwg_db_fetch_row(pwg_query($query)); |
---|
1286 | |
---|
1287 | $query = " |
---|
1288 | INSERT INTO ".USER_CONFIRM_MAIL_TABLE." |
---|
1289 | (id, user_id, mail_address, status, date_check) |
---|
1290 | VALUES |
---|
1291 | ('".$Confirm_Mail_ID."', '".$user_id."', '".$email."', '".$status."', null) |
---|
1292 | ;"; |
---|
1293 | pwg_query($query); |
---|
1294 | |
---|
1295 | // Delete user from all groups |
---|
1296 | $query = " |
---|
1297 | DELETE FROM ".USER_GROUP_TABLE." |
---|
1298 | WHERE user_id = '".$user_id."' |
---|
1299 | AND ( |
---|
1300 | group_id = '".$conf_UAM[2]."' |
---|
1301 | OR |
---|
1302 | group_id = '".$conf_UAM[3]."' |
---|
1303 | ) |
---|
1304 | ;"; |
---|
1305 | pwg_query($query); |
---|
1306 | |
---|
1307 | // Set user unvalidated status |
---|
1308 | if (!is_admin() and $conf_UAM[8] <> -1) |
---|
1309 | { |
---|
1310 | $query = " |
---|
1311 | UPDATE ".USER_INFOS_TABLE." |
---|
1312 | SET status = '".$conf_UAM[8]."' |
---|
1313 | WHERE user_id = '".$user_id."' |
---|
1314 | ;"; |
---|
1315 | pwg_query($query); |
---|
1316 | } |
---|
1317 | |
---|
1318 | // Set user unvalidated group |
---|
1319 | if (!is_admin() and $conf_UAM[2] <> -1) |
---|
1320 | { |
---|
1321 | $query = " |
---|
1322 | INSERT INTO ".USER_GROUP_TABLE." |
---|
1323 | (user_id, group_id) |
---|
1324 | VALUES |
---|
1325 | ('".$user_id."', '".$conf_UAM[2]."') |
---|
1326 | ;"; |
---|
1327 | pwg_query($query); |
---|
1328 | } |
---|
1329 | |
---|
1330 | return get_absolute_root_url().UAM_PATH.'ConfirmMail.php?key='.$Confirm_Mail_ID.'&userid='.$user_id; |
---|
1331 | } |
---|
1332 | } |
---|
1333 | |
---|
1334 | /** |
---|
1335 | * Function called from main.inc.php to set group to new users if manual validation is set |
---|
1336 | * |
---|
1337 | * @param : User id |
---|
1338 | * |
---|
1339 | * |
---|
1340 | */ |
---|
1341 | function setgroup($user_id) |
---|
1342 | { |
---|
1343 | global $conf; |
---|
1344 | |
---|
1345 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1346 | |
---|
1347 | $query = " |
---|
1348 | DELETE FROM ".USER_GROUP_TABLE." |
---|
1349 | WHERE user_id = '".$user_id."' |
---|
1350 | AND ( |
---|
1351 | group_id = '".$conf_UAM[2]."' |
---|
1352 | OR |
---|
1353 | group_id = '".$conf_UAM[3]."' |
---|
1354 | ) |
---|
1355 | ;"; |
---|
1356 | pwg_query($query); |
---|
1357 | |
---|
1358 | if (!is_admin() and $conf_UAM[8] <> -1) |
---|
1359 | { |
---|
1360 | $query = " |
---|
1361 | UPDATE ".USER_INFOS_TABLE." |
---|
1362 | SET status = '".$conf_UAM[8]."' |
---|
1363 | WHERE user_id = '".$user_id."' |
---|
1364 | ;"; |
---|
1365 | pwg_query($query); |
---|
1366 | } |
---|
1367 | |
---|
1368 | if (!is_admin() and $conf_UAM[2] <> -1) |
---|
1369 | { |
---|
1370 | $query = " |
---|
1371 | INSERT INTO ".USER_GROUP_TABLE." |
---|
1372 | (user_id, group_id) |
---|
1373 | VALUES |
---|
1374 | ('".$user_id."', '".$conf_UAM[2]."') |
---|
1375 | ;"; |
---|
1376 | pwg_query($query); |
---|
1377 | } |
---|
1378 | } |
---|
1379 | |
---|
1380 | /** |
---|
1381 | * Function called from UAM_admin.php to reset validation key |
---|
1382 | * |
---|
1383 | * @param : User id |
---|
1384 | * |
---|
1385 | * @return : Build validation key in URL |
---|
1386 | * |
---|
1387 | */ |
---|
1388 | function ResetConfirmMail($user_id) |
---|
1389 | { |
---|
1390 | global $conf; |
---|
1391 | |
---|
1392 | $Confirm_Mail_ID = FindAvailableConfirmMailID(); |
---|
1393 | |
---|
1394 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
1395 | |
---|
1396 | if (isset($Confirm_Mail_ID)) |
---|
1397 | { |
---|
1398 | $query = " |
---|
1399 | UPDATE ".USER_CONFIRM_MAIL_TABLE." |
---|
1400 | SET id = '".$Confirm_Mail_ID."' |
---|
1401 | WHERE user_id = '".$user_id."' |
---|
1402 | ;"; |
---|
1403 | pwg_query($query); |
---|
1404 | |
---|
1405 | $query = " |
---|
1406 | UPDATE ".USER_INFOS_TABLE." |
---|
1407 | SET registration_date = '".$dbnow."' |
---|
1408 | WHERE user_id = '".$user_id."' |
---|
1409 | ;"; |
---|
1410 | pwg_query($query); |
---|
1411 | |
---|
1412 | return get_absolute_root_url().UAM_PATH.'ConfirmMail.php?key='.$Confirm_Mail_ID.'&userid='.$user_id; |
---|
1413 | } |
---|
1414 | } |
---|
1415 | |
---|
1416 | /** |
---|
1417 | * Function called from functions.inc.php to reset last visit date after sending a reminder |
---|
1418 | * |
---|
1419 | * @param : User id |
---|
1420 | * |
---|
1421 | */ |
---|
1422 | function resetlastvisit($user_id) |
---|
1423 | { |
---|
1424 | global $conf; |
---|
1425 | |
---|
1426 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
1427 | |
---|
1428 | $query = " |
---|
1429 | UPDATE ".USER_LASTVISIT_TABLE." |
---|
1430 | SET lastvisit = '".$dbnow."', reminder = 'true' |
---|
1431 | WHERE user_id = '".$user_id."' |
---|
1432 | ;"; |
---|
1433 | pwg_query($query); |
---|
1434 | } |
---|
1435 | |
---|
1436 | |
---|
1437 | /** |
---|
1438 | * Function called from main.inc.php - Triggered on user deletion |
---|
1439 | * |
---|
1440 | */ |
---|
1441 | function DeleteConfirmMail($user_id) |
---|
1442 | { |
---|
1443 | $query = " |
---|
1444 | DELETE FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
1445 | WHERE user_id = '".$user_id."' |
---|
1446 | ;"; |
---|
1447 | pwg_query($query); |
---|
1448 | } |
---|
1449 | |
---|
1450 | /** |
---|
1451 | * Function called from main.inc.php - Triggered on user deletion |
---|
1452 | * |
---|
1453 | */ |
---|
1454 | function DeleteLastVisit($user_id) |
---|
1455 | { |
---|
1456 | $query = " |
---|
1457 | DELETE FROM ".USER_LASTVISIT_TABLE." |
---|
1458 | WHERE user_id = '".$user_id."' |
---|
1459 | ;"; |
---|
1460 | pwg_query($query); |
---|
1461 | } |
---|
1462 | |
---|
1463 | /** |
---|
1464 | * Function called from main.inc.php - Triggered on user deletion |
---|
1465 | * |
---|
1466 | * @param : User id |
---|
1467 | * |
---|
1468 | */ |
---|
1469 | function DeleteRedir($user_id) |
---|
1470 | { |
---|
1471 | $tab = array(); |
---|
1472 | |
---|
1473 | $query = ' |
---|
1474 | SELECT value |
---|
1475 | FROM '.CONFIG_TABLE.' |
---|
1476 | WHERE param = "UserAdvManager_Redir" |
---|
1477 | ;'; |
---|
1478 | |
---|
1479 | $tab = pwg_db_fetch_row(pwg_query($query)); |
---|
1480 | |
---|
1481 | $values = explode(',', $tab[0]); |
---|
1482 | |
---|
1483 | unset($values[array_search($user_id, $values)]); |
---|
1484 | |
---|
1485 | $query = " |
---|
1486 | UPDATE ".CONFIG_TABLE." |
---|
1487 | SET value = \"".implode(',', $values)."\" |
---|
1488 | WHERE param = 'UserAdvManager_Redir';"; |
---|
1489 | |
---|
1490 | pwg_query($query); |
---|
1491 | } |
---|
1492 | |
---|
1493 | /** |
---|
1494 | * Function called from ConfirmMail.php to verify validation key used by user according time limit |
---|
1495 | * Return true is key validation is OK else return false |
---|
1496 | * |
---|
1497 | * @param : User id |
---|
1498 | * |
---|
1499 | * @return : Bool |
---|
1500 | * |
---|
1501 | */ |
---|
1502 | function VerifyConfirmMail($id) |
---|
1503 | { |
---|
1504 | global $conf; |
---|
1505 | |
---|
1506 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
1507 | |
---|
1508 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1509 | |
---|
1510 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
---|
1511 | |
---|
1512 | $query = " |
---|
1513 | SELECT COUNT(*) |
---|
1514 | FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
1515 | WHERE id = '".$id."' |
---|
1516 | ;"; |
---|
1517 | list($count) = pwg_db_fetch_row(pwg_query($query)); |
---|
1518 | |
---|
1519 | if ($count == 1) |
---|
1520 | { |
---|
1521 | $query = " |
---|
1522 | SELECT user_id, status, date_check |
---|
1523 | FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
1524 | WHERE id = '".$id."' |
---|
1525 | ;"; |
---|
1526 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
1527 | |
---|
1528 | //if (!empty($data) and isset($data['user_id']) and !isset($data['date_check'])) |
---|
1529 | if (!empty($data) and isset($data['user_id'])) |
---|
1530 | { |
---|
1531 | $query = " |
---|
1532 | SELECT registration_date |
---|
1533 | FROM ".USER_INFOS_TABLE." |
---|
1534 | WHERE user_id = '".$data['user_id']."' |
---|
1535 | ;"; |
---|
1536 | list($registration_date) = pwg_db_fetch_row(pwg_query($query)); |
---|
1537 | |
---|
1538 | // Time limit process |
---|
1539 | // ******************************************** |
---|
1540 | if (!empty($registration_date)) |
---|
1541 | { |
---|
1542 | // Verify Confirmmail with time limit ON |
---|
1543 | if (isset ($conf_UAM_ConfirmMail[1])) |
---|
1544 | { |
---|
1545 | // dates formating and compare |
---|
1546 | $today = date("d-m-Y"); // Get today's date |
---|
1547 | list($day, $month, $year) = explode('-', $today); // explode date of today |
---|
1548 | $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp |
---|
1549 | |
---|
1550 | list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date |
---|
1551 | list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date |
---|
1552 | $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp |
---|
1553 | |
---|
1554 | $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps |
---|
1555 | $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days |
---|
1556 | |
---|
1557 | // Condition with the value set for time limit |
---|
1558 | if ($deltadays <= $conf_UAM_ConfirmMail[1]) // If Nb of days is less than the limit set |
---|
1559 | { |
---|
1560 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
1561 | |
---|
1562 | $query = ' |
---|
1563 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
1564 | SET date_check="'.$dbnow.'" |
---|
1565 | WHERE id = "'.$id.'" |
---|
1566 | ;'; |
---|
1567 | pwg_query($query); |
---|
1568 | |
---|
1569 | if ($conf_UAM[2] <> -1) // Delete user from unvalidated users group |
---|
1570 | { |
---|
1571 | $query = " |
---|
1572 | DELETE FROM ".USER_GROUP_TABLE." |
---|
1573 | WHERE user_id = '".$data['user_id']."' |
---|
1574 | AND group_id = '".$conf_UAM[2]."' |
---|
1575 | ;"; |
---|
1576 | pwg_query($query); |
---|
1577 | } |
---|
1578 | |
---|
1579 | if ($conf_UAM[3] <> -1) // Add user to validated users group |
---|
1580 | { |
---|
1581 | $query = " |
---|
1582 | INSERT INTO ".USER_GROUP_TABLE." |
---|
1583 | (user_id, group_id) |
---|
1584 | VALUES |
---|
1585 | ('".$data['user_id']."', '".$conf_UAM[3]."') |
---|
1586 | ;"; |
---|
1587 | pwg_query($query); |
---|
1588 | } |
---|
1589 | |
---|
1590 | if (($conf_UAM[4] <> -1 or isset($data['status']))) // Change user's status |
---|
1591 | { |
---|
1592 | $query = " |
---|
1593 | UPDATE ".USER_INFOS_TABLE." |
---|
1594 | SET status = '".(isset($data['status']) ? $data['status'] : $conf_UAM[4])."' |
---|
1595 | WHERE user_id = '".$data['user_id']."' |
---|
1596 | ;"; |
---|
1597 | pwg_query($query); |
---|
1598 | } |
---|
1599 | // Refresh user's category cache |
---|
1600 | invalidate_user_cache(); |
---|
1601 | |
---|
1602 | return true; |
---|
1603 | } |
---|
1604 | elseif ($deltadays > $conf_UAM_ConfirmMail[1]) // If timelimit exeeds |
---|
1605 | { |
---|
1606 | return false; |
---|
1607 | } |
---|
1608 | } |
---|
1609 | // Verify Confirmmail with time limit OFF |
---|
1610 | else |
---|
1611 | { |
---|
1612 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
1613 | |
---|
1614 | $query = ' |
---|
1615 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
1616 | SET date_check="'.$dbnow.'" |
---|
1617 | WHERE id = "'.$id.'" |
---|
1618 | ;'; |
---|
1619 | pwg_query($query); |
---|
1620 | |
---|
1621 | if ($conf_UAM[2] <> -1) |
---|
1622 | { |
---|
1623 | $query = " |
---|
1624 | DELETE FROM ".USER_GROUP_TABLE." |
---|
1625 | WHERE user_id = '".$data['user_id']."' |
---|
1626 | AND group_id = '".$conf_UAM[2]."' |
---|
1627 | ;"; |
---|
1628 | pwg_query($query); |
---|
1629 | } |
---|
1630 | |
---|
1631 | if ($conf_UAM[3] <> -1) |
---|
1632 | { |
---|
1633 | $query = " |
---|
1634 | DELETE FROM ".USER_GROUP_TABLE." |
---|
1635 | WHERE user_id = '".$data['user_id']."' |
---|
1636 | AND group_id = '".$conf_UAM[3]."' |
---|
1637 | ;"; |
---|
1638 | pwg_query($query); |
---|
1639 | |
---|
1640 | $query = " |
---|
1641 | INSERT INTO ".USER_GROUP_TABLE." |
---|
1642 | (user_id, group_id) |
---|
1643 | VALUES |
---|
1644 | ('".$data['user_id']."', '".$conf_UAM[3]."') |
---|
1645 | ;"; |
---|
1646 | pwg_query($query); |
---|
1647 | } |
---|
1648 | |
---|
1649 | if (($conf_UAM[4] <> -1 or isset($data['status']))) |
---|
1650 | { |
---|
1651 | $query = " |
---|
1652 | UPDATE ".USER_INFOS_TABLE." |
---|
1653 | SET status = '".(isset($data['status']) ? $data['status'] : $conf_UAM[4])."' |
---|
1654 | WHERE user_id = '".$data['user_id']."' |
---|
1655 | ;"; |
---|
1656 | pwg_query($query); |
---|
1657 | } |
---|
1658 | // Refresh user's category cache |
---|
1659 | invalidate_user_cache(); |
---|
1660 | |
---|
1661 | return true; |
---|
1662 | } |
---|
1663 | } |
---|
1664 | } |
---|
1665 | } |
---|
1666 | else |
---|
1667 | return false; |
---|
1668 | } |
---|
1669 | |
---|
1670 | /** |
---|
1671 | * Function called from UAM_admin.php to force users validation by admin |
---|
1672 | * |
---|
1673 | * @param : User id |
---|
1674 | * |
---|
1675 | */ |
---|
1676 | function ForceValidation($id) |
---|
1677 | { |
---|
1678 | global $conf; |
---|
1679 | |
---|
1680 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1681 | |
---|
1682 | if (isset($conf_UAM[1]) and $conf_UAM[1] == 'true') |
---|
1683 | { |
---|
1684 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
1685 | |
---|
1686 | $query = " |
---|
1687 | UPDATE ".USER_CONFIRM_MAIL_TABLE." |
---|
1688 | SET date_check='".$dbnow."' |
---|
1689 | WHERE user_id = '".$id."' |
---|
1690 | ;"; |
---|
1691 | pwg_query($query); |
---|
1692 | |
---|
1693 | if ($conf_UAM[2] <> -1) |
---|
1694 | { |
---|
1695 | $query = " |
---|
1696 | DELETE FROM ".USER_GROUP_TABLE." |
---|
1697 | WHERE user_id = '".$id."' |
---|
1698 | AND group_id = '".$conf_UAM[2]."' |
---|
1699 | ;"; |
---|
1700 | pwg_query($query); |
---|
1701 | } |
---|
1702 | |
---|
1703 | if ($conf_UAM[3] <> -1) |
---|
1704 | { |
---|
1705 | $query = " |
---|
1706 | DELETE FROM ".USER_GROUP_TABLE." |
---|
1707 | WHERE user_id = '".$id."' |
---|
1708 | AND group_id = '".$conf_UAM[3]."' |
---|
1709 | ;"; |
---|
1710 | pwg_query($query); |
---|
1711 | |
---|
1712 | $query = " |
---|
1713 | INSERT INTO ".USER_GROUP_TABLE." |
---|
1714 | (user_id, group_id) |
---|
1715 | VALUES |
---|
1716 | ('".$id."', '".$conf_UAM[3]."') |
---|
1717 | ;"; |
---|
1718 | pwg_query($query); |
---|
1719 | } |
---|
1720 | |
---|
1721 | if ($conf_UAM[4] <> -1) |
---|
1722 | { |
---|
1723 | $query = " |
---|
1724 | UPDATE ".USER_INFOS_TABLE." |
---|
1725 | SET status = '".$conf_UAM[4]."' |
---|
1726 | WHERE user_id = '".$id."' |
---|
1727 | ;"; |
---|
1728 | pwg_query($query); |
---|
1729 | } |
---|
1730 | } |
---|
1731 | elseif (isset($conf_UAM[1]) and $conf_UAM[1] == 'local') |
---|
1732 | { |
---|
1733 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
1734 | |
---|
1735 | if ($conf_UAM[2] <> -1) |
---|
1736 | { |
---|
1737 | $query = " |
---|
1738 | DELETE FROM ".USER_GROUP_TABLE." |
---|
1739 | WHERE user_id = '".$id."' |
---|
1740 | AND group_id = '".$conf_UAM[2]."' |
---|
1741 | ;"; |
---|
1742 | pwg_query($query); |
---|
1743 | } |
---|
1744 | |
---|
1745 | if ($conf_UAM[3] <> -1) |
---|
1746 | { |
---|
1747 | $query = " |
---|
1748 | DELETE FROM ".USER_GROUP_TABLE." |
---|
1749 | WHERE user_id = '".$id."' |
---|
1750 | AND group_id = '".$conf_UAM[3]."' |
---|
1751 | ;"; |
---|
1752 | pwg_query($query); |
---|
1753 | |
---|
1754 | $query = " |
---|
1755 | INSERT INTO ".USER_GROUP_TABLE." |
---|
1756 | (user_id, group_id) |
---|
1757 | VALUES |
---|
1758 | ('".$id."', '".$conf_UAM[3]."') |
---|
1759 | ;"; |
---|
1760 | pwg_query($query); |
---|
1761 | } |
---|
1762 | |
---|
1763 | if ($conf_UAM[4] <> -1) |
---|
1764 | { |
---|
1765 | $query = " |
---|
1766 | UPDATE ".USER_INFOS_TABLE." |
---|
1767 | SET status = '".$conf_UAM[4]."' |
---|
1768 | WHERE user_id = '".$id."' |
---|
1769 | ;"; |
---|
1770 | pwg_query($query); |
---|
1771 | } |
---|
1772 | } |
---|
1773 | } |
---|
1774 | |
---|
1775 | /** |
---|
1776 | * Function called from main.inc.php - Check if username matches forbidden caracters |
---|
1777 | * |
---|
1778 | * @param : User login |
---|
1779 | * |
---|
1780 | * @return : Bool |
---|
1781 | * |
---|
1782 | */ |
---|
1783 | function ValidateUsername($login) |
---|
1784 | { |
---|
1785 | global $conf; |
---|
1786 | |
---|
1787 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1788 | |
---|
1789 | if (isset($login) and isset($conf_UAM[7]) and $conf_UAM[7] <> '') |
---|
1790 | { |
---|
1791 | $conf_CharExclusion = preg_split("/,/",$conf_UAM[7]); |
---|
1792 | for ($i = 0 ; $i < count($conf_CharExclusion) ; $i++) |
---|
1793 | { |
---|
1794 | $pattern = '/'.$conf_CharExclusion[$i].'/i'; |
---|
1795 | if (preg_match($pattern, $login)) |
---|
1796 | { |
---|
1797 | return true; |
---|
1798 | } |
---|
1799 | } |
---|
1800 | } |
---|
1801 | else |
---|
1802 | { |
---|
1803 | return false; |
---|
1804 | } |
---|
1805 | } |
---|
1806 | |
---|
1807 | /** |
---|
1808 | * Function called from main.inc.php - Check if user's email is in excluded email providers list |
---|
1809 | * Doesn't work on call - Must be copied in main.inc.php to work |
---|
1810 | * |
---|
1811 | * @param : Email address |
---|
1812 | * |
---|
1813 | * @return : Bool |
---|
1814 | * |
---|
1815 | */ |
---|
1816 | function ValidateEmailProvider($email) |
---|
1817 | { |
---|
1818 | global $conf; |
---|
1819 | |
---|
1820 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1821 | |
---|
1822 | if (isset($email) and isset($conf_UAM[12]) and $conf_UAM[12] <> '') |
---|
1823 | { |
---|
1824 | $conf_MailExclusion = preg_split("/[\s,]+/",$conf_UAM[12]); |
---|
1825 | for ($i = 0 ; $i < count($conf_MailExclusion) ; $i++) |
---|
1826 | { |
---|
1827 | $pattern = '/'.$conf_MailExclusion[$i].'/i'; |
---|
1828 | if (preg_match($pattern, $email)) |
---|
1829 | { |
---|
1830 | return true; |
---|
1831 | } |
---|
1832 | } |
---|
1833 | } |
---|
1834 | else |
---|
1835 | { |
---|
1836 | return false; |
---|
1837 | } |
---|
1838 | } |
---|
1839 | |
---|
1840 | /** |
---|
1841 | * Function called from UAM_admin.php - Get unvalidated users according time limit |
---|
1842 | * |
---|
1843 | * @return : List of users |
---|
1844 | * |
---|
1845 | */ |
---|
1846 | function get_unvalid_user_list() |
---|
1847 | { |
---|
1848 | global $conf, $page; |
---|
1849 | |
---|
1850 | // Get ConfirmMail configuration |
---|
1851 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
---|
1852 | // Get UAM configuration |
---|
1853 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1854 | |
---|
1855 | $users = array(); |
---|
1856 | |
---|
1857 | // search users depending expiration date |
---|
1858 | $query = ' |
---|
1859 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
1860 | u.'.$conf['user_fields']['username'].' AS username, |
---|
1861 | u.'.$conf['user_fields']['email'].' AS email, |
---|
1862 | ui.status, |
---|
1863 | ui.enabled_high, |
---|
1864 | ui.level, |
---|
1865 | ui.registration_date |
---|
1866 | FROM '.USERS_TABLE.' AS u |
---|
1867 | INNER JOIN '.USER_INFOS_TABLE.' AS ui |
---|
1868 | ON u.'.$conf['user_fields']['id'].' = ui.user_id |
---|
1869 | LEFT JOIN '.USER_GROUP_TABLE.' AS ug |
---|
1870 | ON u.'.$conf['user_fields']['id'].' = ug.user_id |
---|
1871 | WHERE u.'.$conf['user_fields']['id'].' >= 3 |
---|
1872 | AND (TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) >= "'.$conf_UAM_ConfirmMail[1].'" |
---|
1873 | OR TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) < "'.$conf_UAM_ConfirmMail[1].'")'; |
---|
1874 | |
---|
1875 | if ($conf_UAM[2] <> '-1' and $conf_UAM[8] == '-1') |
---|
1876 | { |
---|
1877 | $query.= ' |
---|
1878 | AND ug.group_id = '.$conf_UAM[2]; |
---|
1879 | } |
---|
1880 | if ($conf_UAM[2] == '-1' and $conf_UAM[8] <> '-1') |
---|
1881 | { |
---|
1882 | $query.= ' |
---|
1883 | AND ui.status = \''.$conf_UAM[8]."'"; |
---|
1884 | } |
---|
1885 | if ($conf_UAM[2] <> '-1' and $conf_UAM[8] <> '-1') |
---|
1886 | { |
---|
1887 | $query.= ' |
---|
1888 | AND ug.group_id = \''.$conf_UAM[2]."'"; |
---|
1889 | } |
---|
1890 | $query.= ' |
---|
1891 | ORDER BY ui.registration_date ASC |
---|
1892 | ;'; |
---|
1893 | |
---|
1894 | $result = pwg_query($query); |
---|
1895 | |
---|
1896 | while ($row = pwg_db_fetch_assoc($result)) |
---|
1897 | { |
---|
1898 | $user = $row; |
---|
1899 | $user['groups'] = array(); |
---|
1900 | |
---|
1901 | array_push($users, $user); |
---|
1902 | } |
---|
1903 | |
---|
1904 | // add group lists |
---|
1905 | $user_ids = array(); |
---|
1906 | foreach ($users as $i => $user) |
---|
1907 | { |
---|
1908 | $user_ids[$i] = $user['id']; |
---|
1909 | } |
---|
1910 | |
---|
1911 | $user_nums = array_flip($user_ids); |
---|
1912 | |
---|
1913 | if (count($user_ids) > 0) |
---|
1914 | { |
---|
1915 | $query = ' |
---|
1916 | SELECT user_id, group_id |
---|
1917 | FROM '.USER_GROUP_TABLE.' |
---|
1918 | WHERE user_id IN ('.implode(',', $user_ids).') |
---|
1919 | ;'; |
---|
1920 | |
---|
1921 | $result = pwg_query($query); |
---|
1922 | |
---|
1923 | while ($row = pwg_db_fetch_assoc($result)) |
---|
1924 | { |
---|
1925 | array_push( |
---|
1926 | $users[$user_nums[$row['user_id']]]['groups'], |
---|
1927 | $row['group_id'] |
---|
1928 | ); |
---|
1929 | } |
---|
1930 | } |
---|
1931 | |
---|
1932 | return $users; |
---|
1933 | } |
---|
1934 | |
---|
1935 | /** |
---|
1936 | * Function called from UAM_admin.php - Get ghost users |
---|
1937 | * |
---|
1938 | * @return : List of users |
---|
1939 | * |
---|
1940 | */ |
---|
1941 | function get_ghost_user_list() |
---|
1942 | { |
---|
1943 | global $conf, $page; |
---|
1944 | |
---|
1945 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1946 | |
---|
1947 | $users = array(); |
---|
1948 | |
---|
1949 | // search users depending expiration date |
---|
1950 | $query = ' |
---|
1951 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
1952 | u.'.$conf['user_fields']['username'].' AS username, |
---|
1953 | u.'.$conf['user_fields']['email'].' AS email, |
---|
1954 | lv.lastvisit, |
---|
1955 | lv.reminder |
---|
1956 | FROM '.USERS_TABLE.' AS u |
---|
1957 | INNER JOIN '.USER_LASTVISIT_TABLE.' AS lv |
---|
1958 | ON u.'.$conf['user_fields']['id'].' = lv.user_id |
---|
1959 | WHERE (TO_DAYS(NOW()) - TO_DAYS(lv.lastvisit) >= "'.$conf_UAM[17].'") |
---|
1960 | ORDER BY lv.lastvisit ASC;'; |
---|
1961 | |
---|
1962 | $result = pwg_query($query); |
---|
1963 | |
---|
1964 | while ($row = pwg_db_fetch_assoc($result)) |
---|
1965 | { |
---|
1966 | $user = $row; |
---|
1967 | $user['groups'] = array(); |
---|
1968 | |
---|
1969 | array_push($users, $user); |
---|
1970 | } |
---|
1971 | |
---|
1972 | // add group lists |
---|
1973 | $user_ids = array(); |
---|
1974 | foreach ($users as $i => $user) |
---|
1975 | { |
---|
1976 | $user_ids[$i] = $user['id']; |
---|
1977 | } |
---|
1978 | |
---|
1979 | return $users; |
---|
1980 | } |
---|
1981 | |
---|
1982 | |
---|
1983 | /** |
---|
1984 | * Function called from functions.inc.php - Get all ghost users to delete or downgrade automatically on any user login |
---|
1985 | * |
---|
1986 | * @return : List of users to delete or downgrade automatically |
---|
1987 | * |
---|
1988 | */ |
---|
1989 | function get_ghosts_autotasks() |
---|
1990 | { |
---|
1991 | global $conf, $page; |
---|
1992 | |
---|
1993 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1994 | |
---|
1995 | $users = array(); |
---|
1996 | |
---|
1997 | // search users depending expiration date and reminder sent |
---|
1998 | $query = ' |
---|
1999 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
2000 | lv.lastvisit |
---|
2001 | FROM '.USERS_TABLE.' AS u |
---|
2002 | INNER JOIN '.USER_LASTVISIT_TABLE.' AS lv |
---|
2003 | ON u.'.$conf['user_fields']['id'].' = lv.user_id |
---|
2004 | WHERE (TO_DAYS(NOW()) - TO_DAYS(lv.lastvisit) >= "'.$conf_UAM[17].'") |
---|
2005 | ORDER BY lv.lastvisit ASC;'; |
---|
2006 | |
---|
2007 | $result = pwg_query($query); |
---|
2008 | |
---|
2009 | while ($row = pwg_db_fetch_assoc($result)) |
---|
2010 | { |
---|
2011 | $user = $row; |
---|
2012 | $user['groups'] = array(); |
---|
2013 | |
---|
2014 | array_push($users, $user); |
---|
2015 | } |
---|
2016 | |
---|
2017 | // add group lists |
---|
2018 | $user_ids = array(); |
---|
2019 | foreach ($users as $i => $user) |
---|
2020 | { |
---|
2021 | $user_ids[$i] = $user['id']; |
---|
2022 | } |
---|
2023 | |
---|
2024 | return $users; |
---|
2025 | } |
---|
2026 | |
---|
2027 | |
---|
2028 | /** |
---|
2029 | * Function called from UAM_admin.php - Get all users to display the number of days since their last visit |
---|
2030 | * |
---|
2031 | * @return : List of users |
---|
2032 | * |
---|
2033 | */ |
---|
2034 | function get_user_list() |
---|
2035 | { |
---|
2036 | global $conf, $page; |
---|
2037 | |
---|
2038 | $users = array(); |
---|
2039 | |
---|
2040 | // search users depending expiration date |
---|
2041 | $query = ' |
---|
2042 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
2043 | u.'.$conf['user_fields']['username'].' AS username, |
---|
2044 | u.'.$conf['user_fields']['email'].' AS email, |
---|
2045 | ug.lastvisit |
---|
2046 | FROM '.USERS_TABLE.' AS u |
---|
2047 | INNER JOIN '.USER_LASTVISIT_TABLE.' AS ug |
---|
2048 | ON u.'.$conf['user_fields']['id'].' = ug.user_id |
---|
2049 | WHERE u.'.$conf['user_fields']['id'].' >= 3 |
---|
2050 | ORDER BY ug.lastvisit DESC |
---|
2051 | ;'; |
---|
2052 | |
---|
2053 | $result = pwg_query($query); |
---|
2054 | |
---|
2055 | while ($row = pwg_db_fetch_assoc($result)) |
---|
2056 | { |
---|
2057 | $user = $row; |
---|
2058 | $user['groups'] = array(); |
---|
2059 | |
---|
2060 | array_push($users, $user); |
---|
2061 | } |
---|
2062 | |
---|
2063 | // add group lists |
---|
2064 | $user_ids = array(); |
---|
2065 | foreach ($users as $i => $user) |
---|
2066 | { |
---|
2067 | $user_ids[$i] = $user['id']; |
---|
2068 | } |
---|
2069 | |
---|
2070 | return $users; |
---|
2071 | } |
---|
2072 | |
---|
2073 | /** |
---|
2074 | * Function called from UAM_admin.php - to determine who is expired or not and giving a different display color |
---|
2075 | * |
---|
2076 | * @param : user id |
---|
2077 | * |
---|
2078 | * @return : Bool |
---|
2079 | * |
---|
2080 | */ |
---|
2081 | function expiration($id) |
---|
2082 | { |
---|
2083 | global $conf, $page; |
---|
2084 | |
---|
2085 | // Get ConfirmMail configuration |
---|
2086 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
---|
2087 | |
---|
2088 | // Get UAM configuration |
---|
2089 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
2090 | |
---|
2091 | $query = " |
---|
2092 | SELECT registration_date |
---|
2093 | FROM ".USER_INFOS_TABLE." |
---|
2094 | WHERE user_id = '".$id."' |
---|
2095 | ;"; |
---|
2096 | list($registration_date) = pwg_db_fetch_row(pwg_query($query)); |
---|
2097 | |
---|
2098 | // Time limit process |
---|
2099 | // ******************************************** |
---|
2100 | if (!empty($registration_date)) |
---|
2101 | { |
---|
2102 | // dates formating and compare |
---|
2103 | $today = date("d-m-Y"); // Get today's date |
---|
2104 | list($day, $month, $year) = explode('-', $today); // explode date of today |
---|
2105 | $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp |
---|
2106 | |
---|
2107 | list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date |
---|
2108 | list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date |
---|
2109 | $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp |
---|
2110 | |
---|
2111 | $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps |
---|
2112 | $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days |
---|
2113 | |
---|
2114 | // Condition with the value set for time limit |
---|
2115 | if ($deltadays <= $conf_UAM_ConfirmMail[1]) // If Nb of days is less than the limit set |
---|
2116 | { |
---|
2117 | return false; |
---|
2118 | } |
---|
2119 | else |
---|
2120 | { |
---|
2121 | return true; |
---|
2122 | } |
---|
2123 | } |
---|
2124 | } |
---|
2125 | |
---|
2126 | |
---|
2127 | /** |
---|
2128 | * Returns a password's score for password complexity check |
---|
2129 | * |
---|
2130 | * @param : password filled by user |
---|
2131 | * |
---|
2132 | * @return : Score calculation |
---|
2133 | * |
---|
2134 | * Thanx to MathieuGut from http://m-gut.developpez.com |
---|
2135 | */ |
---|
2136 | function testpassword($password) // Le mot de passe passé en paramètre - $password given by user |
---|
2137 | { |
---|
2138 | |
---|
2139 | // Initialisation des variables - Variables initiation |
---|
2140 | $points = 0; |
---|
2141 | $point_lowercase = 0; |
---|
2142 | $point_uppercase = 0; |
---|
2143 | $point_numbers = 0; |
---|
2144 | $point_characters = 0; |
---|
2145 | |
---|
2146 | // On récupère la longueur du mot de passe - Getting password lengh |
---|
2147 | $length = strlen($password); |
---|
2148 | |
---|
2149 | // On fait une boucle pour lire chaque lettre - Loop to read password characters |
---|
2150 | for($i = 0; $i < $length; $i++) |
---|
2151 | { |
---|
2152 | // On sélectionne une à une chaque lettre - Select each letters |
---|
2153 | // $i étant à 0 lors du premier passage de la boucle - $i is 0 at first turn |
---|
2154 | $letters = $password[$i]; |
---|
2155 | |
---|
2156 | if ($letters>='a' && $letters<='z') |
---|
2157 | { |
---|
2158 | // On ajoute 1 point pour une minuscule - Adding 1 point to score for a lowercase |
---|
2159 | $points = $points + 1; |
---|
2160 | |
---|
2161 | // On rajoute le bonus pour une minuscule - Adding bonus points for lowercase |
---|
2162 | $point_lowercase = 1; |
---|
2163 | } |
---|
2164 | else if ($letters>='A' && $letters <='Z') |
---|
2165 | { |
---|
2166 | // On ajoute 2 points pour une majuscule - Adding 2 points to score for uppercase |
---|
2167 | $points = $points + 2; |
---|
2168 | |
---|
2169 | // On rajoute le bonus pour une majuscule - Adding bonus points for uppercase |
---|
2170 | $point_uppercase = 2; |
---|
2171 | } |
---|
2172 | else if ($letters>='0' && $letters<='9') |
---|
2173 | { |
---|
2174 | // On ajoute 3 points pour un chiffre - Adding 3 points to score for numbers |
---|
2175 | $points = $points + 3; |
---|
2176 | |
---|
2177 | // On rajoute le bonus pour un chiffre - Adding bonus points for numbers |
---|
2178 | $point_numbers = 3; |
---|
2179 | } |
---|
2180 | else |
---|
2181 | { |
---|
2182 | // On ajoute 5 points pour un caractère autre - Adding 5 points to score for special characters |
---|
2183 | $points = $points + 5; |
---|
2184 | |
---|
2185 | // On rajoute le bonus pour un caractère autre - Adding bonus points for special characters |
---|
2186 | $point_characters = 5; |
---|
2187 | } |
---|
2188 | } |
---|
2189 | |
---|
2190 | // Calcul du coefficient points/longueur - calculating the coefficient points/length |
---|
2191 | $step1 = $points / $length; |
---|
2192 | |
---|
2193 | // Calcul du coefficient de la diversité des types de caractères... - Calculation of the diversity of character types... |
---|
2194 | $step2 = $point_lowercase + $point_uppercase + $point_numbers + $point_characters; |
---|
2195 | |
---|
2196 | // Multiplication du coefficient de diversité avec celui de la longueur - Multiplying the coefficient of diversity with that of the length |
---|
2197 | $score = $step1 * $step2; |
---|
2198 | |
---|
2199 | // Multiplication du résultat par la longueur de la chaîne - Multiplying the result by the length of the chain |
---|
2200 | $finalscore = $score * $length; |
---|
2201 | |
---|
2202 | return $finalscore; |
---|
2203 | } |
---|
2204 | |
---|
2205 | /** |
---|
2206 | * Function called from maintain.inc.php - to check if database upgrade is needed |
---|
2207 | * |
---|
2208 | * @param : table name |
---|
2209 | * |
---|
2210 | * @return : boolean |
---|
2211 | * |
---|
2212 | */ |
---|
2213 | function table_exist($table) |
---|
2214 | { |
---|
2215 | $query = 'DESC '.$table.';'; |
---|
2216 | return (bool)($res=pwg_query($query)); |
---|
2217 | } |
---|
2218 | |
---|
2219 | // Email sending debugger function |
---|
2220 | function MailLog($to, $subject, $content, $language) |
---|
2221 | { |
---|
2222 | $fo=fopen (UAM_PATH.'admin/maillog.txt','a') ; |
---|
2223 | fwrite($fo,"======================\n") ; |
---|
2224 | fwrite($fo,'le ' . date('D, d M Y H:i:s') . "\r\n"); |
---|
2225 | fwrite($fo,$to . "\n" . $subject . "\r\n") ; |
---|
2226 | fwrite($fo, "\n" . $content . "\r\n") ; |
---|
2227 | fwrite($fo, 'Langue : '."\n" . $language . "\r\n") ; |
---|
2228 | fclose($fo) ; |
---|
2229 | //return mail ($to,$subject) ; |
---|
2230 | } |
---|
2231 | |
---|
2232 | /** |
---|
2233 | * Function called from UAM_admin.php and main.inc.php to get the plugin version and name |
---|
2234 | * |
---|
2235 | * @param : plugin directory |
---|
2236 | * |
---|
2237 | * @return : plugin's version and name |
---|
2238 | * |
---|
2239 | */ |
---|
2240 | function PluginInfos($dir) |
---|
2241 | { |
---|
2242 | $path = $dir; |
---|
2243 | |
---|
2244 | $plg_data = implode( '', file($path.'main.inc.php') ); |
---|
2245 | if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) ) |
---|
2246 | { |
---|
2247 | $plugin['name'] = trim( $val[1] ); |
---|
2248 | } |
---|
2249 | if (preg_match("|Version: (.*)|", $plg_data, $val)) |
---|
2250 | { |
---|
2251 | $plugin['version'] = trim($val[1]); |
---|
2252 | } |
---|
2253 | if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) ) |
---|
2254 | { |
---|
2255 | $plugin['uri'] = trim($val[1]); |
---|
2256 | } |
---|
2257 | if ($desc = load_language('description.txt', $path.'/', array('return' => true))) |
---|
2258 | { |
---|
2259 | $plugin['description'] = trim($desc); |
---|
2260 | } |
---|
2261 | elseif ( preg_match("|Description: (.*)|", $plg_data, $val) ) |
---|
2262 | { |
---|
2263 | $plugin['description'] = trim($val[1]); |
---|
2264 | } |
---|
2265 | if ( preg_match("|Author: (.*)|", $plg_data, $val) ) |
---|
2266 | { |
---|
2267 | $plugin['author'] = trim($val[1]); |
---|
2268 | } |
---|
2269 | if ( preg_match("|Author URI: (.*)|", $plg_data, $val) ) |
---|
2270 | { |
---|
2271 | $plugin['author uri'] = trim($val[1]); |
---|
2272 | } |
---|
2273 | if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid=')) |
---|
2274 | { |
---|
2275 | list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']); |
---|
2276 | if (is_numeric($extension)) $plugin['extension'] = $extension; |
---|
2277 | } |
---|
2278 | // IMPORTANT SECURITY ! |
---|
2279 | $plugin = array_map('htmlspecialchars', $plugin); |
---|
2280 | |
---|
2281 | return $plugin ; |
---|
2282 | } |
---|
2283 | |
---|
2284 | |
---|
2285 | function clean_obsolete_files() |
---|
2286 | { |
---|
2287 | if (file_exists(UAM_PATH.'obsolete.list') |
---|
2288 | and $old_files = file(UAM_PATH.'obsolete.list', FILE_IGNORE_NEW_LINES) |
---|
2289 | and !empty($old_files)) |
---|
2290 | { |
---|
2291 | array_push($old_files, 'obsolete.list'); |
---|
2292 | foreach($old_files as $old_file) |
---|
2293 | { |
---|
2294 | $path = UAM_PATH.$old_file; |
---|
2295 | if (is_file($path)) |
---|
2296 | { |
---|
2297 | @unlink($path); |
---|
2298 | } |
---|
2299 | } |
---|
2300 | } |
---|
2301 | } |
---|
2302 | |
---|
2303 | /** |
---|
2304 | * UAM_check_profile - Thx to LucMorizur |
---|
2305 | * checks if a user id is registered as having already |
---|
2306 | * visited his profile.php page. |
---|
2307 | * |
---|
2308 | * @uid : the user id |
---|
2309 | * |
---|
2310 | * @user_idsOK : (returned) array of all users ids having already visited |
---|
2311 | * their profile.php pages |
---|
2312 | * |
---|
2313 | * @returns : true or false whether the users has already visited his |
---|
2314 | * profile.php page or not |
---|
2315 | * |
---|
2316 | */ |
---|
2317 | function UAM_check_profile($uid, &$user_idsOK) |
---|
2318 | { |
---|
2319 | $t = array(); |
---|
2320 | $v = false; |
---|
2321 | |
---|
2322 | $query = " |
---|
2323 | SELECT value |
---|
2324 | FROM ".CONFIG_TABLE." |
---|
2325 | WHERE param = 'UserAdvManager_Redir' |
---|
2326 | ;"; |
---|
2327 | |
---|
2328 | if ($v = (($t = pwg_db_fetch_row(pwg_query($query))) !== false)) |
---|
2329 | { |
---|
2330 | $user_idsOK = explode(',', $t[0]); |
---|
2331 | $v = (in_array($uid, $user_idsOK)); |
---|
2332 | } |
---|
2333 | return $v; |
---|
2334 | } |
---|
2335 | ?> |
---|