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('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('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('reg_err_login6')."'".$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('reg_err_login7')."'".$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('reg_err_login7')."'".$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('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[21]) and $conf_UAM[21] == 'true')) |
---|
326 | { |
---|
327 | if ((isset($conf_UAM[22]) and $conf_UAM[22] == 'true')) |
---|
328 | { |
---|
329 | UAM_ScheduledTasks(); |
---|
330 | } |
---|
331 | } |
---|
332 | |
---|
333 | // Performing redirection |
---|
334 | $query =' |
---|
335 | SELECT user_id, status |
---|
336 | FROM '.USER_INFOS_TABLE.' |
---|
337 | WHERE user_id = '.$user['id'].' |
---|
338 | ;'; |
---|
339 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
340 | |
---|
341 | if ($data['status'] <> "admin" and $data['status'] <> "webmaster" and $data['status'] <> "generic") |
---|
342 | { |
---|
343 | $user_idsOK = array(); |
---|
344 | if (!UAM_check_profile($user['id'], $user_idsOK)) |
---|
345 | redirect(PHPWG_ROOT_PATH.'profile.php'); |
---|
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 | |
---|
363 | $page['filtered_users'] = get_ghosts_autotasks(); |
---|
364 | |
---|
365 | { |
---|
366 | foreach($page['filtered_users'] as $listed_user) |
---|
367 | { |
---|
368 | array_push($collection, $listed_user['id']); |
---|
369 | } |
---|
370 | |
---|
371 | if (count($collection) > 0) |
---|
372 | { |
---|
373 | if (in_array($user['id'], $collection)) |
---|
374 | { |
---|
375 | invalidate_user_cache(); |
---|
376 | |
---|
377 | foreach ($collection as $user_id) |
---|
378 | { |
---|
379 | //delete_user($user_id); |
---|
380 | } |
---|
381 | logout_user(); |
---|
382 | redirect(UAM_PATH.'del_account.php'); |
---|
383 | } |
---|
384 | else |
---|
385 | { |
---|
386 | foreach ($collection as $user_id) |
---|
387 | { |
---|
388 | //delete_user($user_id); |
---|
389 | } |
---|
390 | } |
---|
391 | } |
---|
392 | } |
---|
393 | |
---|
394 | // Ghost accounts auto group or status downgrade with or without information email sending |
---|
395 | if ((isset($conf_UAM[22]) and $conf_UAM[22] == 'true') and (isset($conf_UAM[23]) and $conf_UAM[23] == 'false') and ((isset($conf_UAM[27]) and $conf_UAM[27] <> -1) or (isset($conf_UAM[28]) and $conf_UAM[28] <> -1))) |
---|
396 | { |
---|
397 | foreach($page['filtered_users'] as $listed_user) |
---|
398 | { |
---|
399 | array_push($collection, $listed_user['id']); |
---|
400 | } |
---|
401 | |
---|
402 | if (count($collection) > 0) |
---|
403 | { |
---|
404 | if (in_array($user['id'], $collection)) |
---|
405 | { |
---|
406 | foreach ($collection as $user_id) |
---|
407 | { |
---|
408 | // Auto change group and / or status |
---|
409 | // Delete user from all groups |
---|
410 | $query = " |
---|
411 | DELETE FROM ".USER_GROUP_TABLE." |
---|
412 | WHERE user_id = '".$user_id."' |
---|
413 | AND ( |
---|
414 | group_id = '".$conf_UAM[2]."' |
---|
415 | OR |
---|
416 | group_id = '".$conf_UAM[3]."' |
---|
417 | ) |
---|
418 | ;"; |
---|
419 | |
---|
420 | pwg_query($query); |
---|
421 | |
---|
422 | // Change user status |
---|
423 | if (!is_admin() and $conf_UAM[28] <> -1) |
---|
424 | { |
---|
425 | $query = " |
---|
426 | UPDATE ".USER_INFOS_TABLE." |
---|
427 | SET status = '".$conf_UAM[28]."' |
---|
428 | WHERE user_id = '".$user_id."' |
---|
429 | ;"; |
---|
430 | pwg_query($query); |
---|
431 | } |
---|
432 | |
---|
433 | // Change user group |
---|
434 | if (!is_admin() and $conf_UAM[27] <> -1) |
---|
435 | { |
---|
436 | $query = " |
---|
437 | INSERT INTO ".USER_GROUP_TABLE." |
---|
438 | (user_id, group_id) |
---|
439 | VALUES |
---|
440 | ('".$user_id."', '".$conf_UAM[27]."') |
---|
441 | ;"; |
---|
442 | pwg_query($query); |
---|
443 | } |
---|
444 | |
---|
445 | // Auto send email notification on group / status downgrade |
---|
446 | if ((isset($conf_UAM[24]) and $conf_UAM[24] == 'true')) |
---|
447 | { |
---|
448 | // Reset confirmed user status to unvalidated |
---|
449 | $query = ' |
---|
450 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
451 | SET date_check = NULL |
---|
452 | WHERE user_id = "'.$user_id.'" |
---|
453 | ;'; |
---|
454 | pwg_query($query); |
---|
455 | |
---|
456 | // Get users information for email notification |
---|
457 | $query = ' |
---|
458 | SELECT id, username, mail_address |
---|
459 | FROM '.USERS_TABLE.' |
---|
460 | WHERE id = '.$user_id.' |
---|
461 | ;'; |
---|
462 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
463 | |
---|
464 | demotion_mail($user_id, $data['username'], $data['mail_address']); |
---|
465 | } |
---|
466 | } |
---|
467 | invalidate_user_cache(); |
---|
468 | log_user($user['id'], false); |
---|
469 | redirect(make_index_url()); |
---|
470 | } |
---|
471 | else |
---|
472 | { |
---|
473 | foreach ($collection as $user_id) |
---|
474 | { |
---|
475 | // Auto change group and / or status |
---|
476 | // Delete user from all groups |
---|
477 | $query = " |
---|
478 | DELETE FROM ".USER_GROUP_TABLE." |
---|
479 | WHERE user_id = '".$user_id."' |
---|
480 | AND ( |
---|
481 | group_id = '".$conf_UAM[2]."' |
---|
482 | OR |
---|
483 | group_id = '".$conf_UAM[3]."' |
---|
484 | ) |
---|
485 | ;"; |
---|
486 | |
---|
487 | pwg_query($query); |
---|
488 | |
---|
489 | // Change user status |
---|
490 | if (!is_admin() and $conf_UAM[28] <> -1) |
---|
491 | { |
---|
492 | $query = " |
---|
493 | UPDATE ".USER_INFOS_TABLE." |
---|
494 | SET status = '".$conf_UAM[28]."' |
---|
495 | WHERE user_id = '".$user_id."' |
---|
496 | ;"; |
---|
497 | pwg_query($query); |
---|
498 | } |
---|
499 | |
---|
500 | // Change user group |
---|
501 | if (!is_admin() and $conf_UAM[27] <> -1) |
---|
502 | { |
---|
503 | $query = " |
---|
504 | INSERT INTO ".USER_GROUP_TABLE." |
---|
505 | (user_id, group_id) |
---|
506 | VALUES |
---|
507 | ('".$user_id."', '".$conf_UAM[27]."') |
---|
508 | ;"; |
---|
509 | pwg_query($query); |
---|
510 | } |
---|
511 | |
---|
512 | // Auto send email notification on group / status downgrade |
---|
513 | if ((isset($conf_UAM[24]) and $conf_UAM[24] == 'true')) |
---|
514 | { |
---|
515 | // Reset confirmed user status to unvalidated |
---|
516 | $query = ' |
---|
517 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
518 | SET date_check = NULL |
---|
519 | WHERE user_id = "'.$user_id.'" |
---|
520 | ;'; |
---|
521 | pwg_query($query); |
---|
522 | |
---|
523 | // Get users information for email notification |
---|
524 | $query = ' |
---|
525 | SELECT id, username, mail_address |
---|
526 | FROM '.USERS_TABLE.' |
---|
527 | WHERE id = '.$user_id.' |
---|
528 | ;'; |
---|
529 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
530 | |
---|
531 | demotion_mail($user_id, $data['username'], $data['mail_address']); |
---|
532 | } |
---|
533 | } |
---|
534 | } |
---|
535 | } |
---|
536 | } |
---|
537 | } |
---|
538 | |
---|
539 | /** |
---|
540 | * Triggered on init |
---|
541 | * |
---|
542 | * Check for forbidden email domains in admin's users management panel |
---|
543 | */ |
---|
544 | function UAM_InitPage() |
---|
545 | { |
---|
546 | load_language('plugin.lang', UAM_PATH); |
---|
547 | global $conf, $template, $page, $lang, $errors; |
---|
548 | |
---|
549 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
550 | |
---|
551 | // Admin user management |
---|
552 | if (script_basename() == 'admin' and isset($_GET['page']) and $_GET['page'] == 'user_list') |
---|
553 | { |
---|
554 | if (isset($_POST['submit_add'])) |
---|
555 | { |
---|
556 | // Email without forbidden domains |
---|
557 | if (isset($conf_UAM[11]) and $conf_UAM[11] == 'true' and !empty($_POST['email']) and ValidateEmailProvider($_POST['email'])) |
---|
558 | { |
---|
559 | $template->append('errors', l10n('reg_err_login7')."'".$conf_UAM[12]."'"); |
---|
560 | unset($_POST['submit_add']); |
---|
561 | } |
---|
562 | } |
---|
563 | } |
---|
564 | } |
---|
565 | |
---|
566 | /** |
---|
567 | * Triggered on user_comment_check |
---|
568 | * |
---|
569 | * checks if author is mandatory and set on comments post |
---|
570 | * |
---|
571 | * @param : comment action, comment |
---|
572 | * |
---|
573 | * @return : comment action |
---|
574 | * |
---|
575 | */ |
---|
576 | function UAM_CheckEmptyCommentAuthor($comment_action, $comm) |
---|
577 | { |
---|
578 | load_language('plugin.lang', UAM_PATH); |
---|
579 | global $infos, $conf, $template; |
---|
580 | |
---|
581 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
582 | |
---|
583 | // User creation OR update |
---|
584 | if (isset($conf_UAM[5]) and $conf_UAM[5] == 'true' and $conf['comments_forall'] == 'true' and $comm['author'] == 'guest') |
---|
585 | { |
---|
586 | $comment_action = 'reject'; |
---|
587 | |
---|
588 | array_push($infos, l10n('UAM_Empty Author')); |
---|
589 | } |
---|
590 | |
---|
591 | return $comment_action; |
---|
592 | } |
---|
593 | |
---|
594 | /** |
---|
595 | * Function called from main.inc.php to send validation email |
---|
596 | * |
---|
597 | * @param : Type of email, user id, username, email address, confirmation (optional) |
---|
598 | * |
---|
599 | */ |
---|
600 | function SendMail2User($typemail, $id, $username, $password, $email, $confirm) |
---|
601 | { |
---|
602 | global $conf; |
---|
603 | |
---|
604 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
605 | |
---|
606 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
607 | |
---|
608 | $infos1_perso = ""; |
---|
609 | $infos2_perso = ""; |
---|
610 | |
---|
611 | // We have to get the user's language in database |
---|
612 | $query =' |
---|
613 | SELECT user_id, language |
---|
614 | FROM '.USER_INFOS_TABLE.' |
---|
615 | WHERE user_id = '.$id.' |
---|
616 | ;'; |
---|
617 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
618 | |
---|
619 | // Check if user is already registered (profile changing) - If not (new registration), language is set to current gallery language |
---|
620 | if (empty($data)) |
---|
621 | { |
---|
622 | // And switch gallery to this language before using personalized and multilangual contents |
---|
623 | $language = pwg_get_session_var( 'lang_switch', $user['language'] ); |
---|
624 | switch_lang_to($language); |
---|
625 | } |
---|
626 | else |
---|
627 | { |
---|
628 | // And switch gallery to this language before using personalized and multilangual contents |
---|
629 | $language = $data['language']; // Usefull for debugging |
---|
630 | switch_lang_to($data['language']); |
---|
631 | load_language('plugin.lang', UAM_PATH); |
---|
632 | } |
---|
633 | |
---|
634 | switch($typemail) |
---|
635 | { |
---|
636 | case 1: |
---|
637 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Add of %s', stripslashes($username))); |
---|
638 | $password = $password <> '' ? $password : l10n('UAM_empty_pwd'); |
---|
639 | |
---|
640 | if (isset($conf_UAM[9]) and $conf_UAM[9] <> '') |
---|
641 | { |
---|
642 | if (function_exists('get_user_language_desc')) |
---|
643 | { |
---|
644 | $infos1_perso = get_user_language_desc($conf_UAM[9])."\n\n"; |
---|
645 | } |
---|
646 | else $infos1_perso = l10n($conf_UAM[9])."\n\n"; |
---|
647 | } |
---|
648 | |
---|
649 | break; |
---|
650 | |
---|
651 | case 2: |
---|
652 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Update of %s', stripslashes($username))); |
---|
653 | $password = $password <> '' ? $password : l10n('UAM_empty_pwd'); |
---|
654 | |
---|
655 | break; |
---|
656 | |
---|
657 | case 3: |
---|
658 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Update of %s', stripslashes($username))); |
---|
659 | $password = $password <> '' ? $password : l10n('UAM_no_update_pwd'); |
---|
660 | |
---|
661 | break; |
---|
662 | } |
---|
663 | |
---|
664 | if (isset($conf_UAM[0]) and $conf_UAM[0] == 'true') |
---|
665 | { |
---|
666 | $infos1 = array( |
---|
667 | get_l10n_args('infos_mail %s', stripslashes($username)), |
---|
668 | get_l10n_args('User: %s', stripslashes($username)), |
---|
669 | get_l10n_args('Password: %s', $password), |
---|
670 | get_l10n_args('Email: %s', $email), |
---|
671 | get_l10n_args('', ''), |
---|
672 | ); |
---|
673 | } |
---|
674 | |
---|
675 | |
---|
676 | if ( isset($conf_UAM[1]) and $conf_UAM[1] == 'true' and $confirm) |
---|
677 | { |
---|
678 | $infos2 = array |
---|
679 | ( |
---|
680 | get_l10n_args('Link: %s', AddConfirmMail($id, $email)), |
---|
681 | get_l10n_args('', ''), |
---|
682 | ); |
---|
683 | |
---|
684 | if (isset($conf_UAM[10]) and $conf_UAM[10] <> '') |
---|
685 | { |
---|
686 | if (function_exists('get_user_language_desc')) |
---|
687 | { |
---|
688 | $infos2_perso = get_user_language_desc($conf_UAM[10])."\n\n"; |
---|
689 | } |
---|
690 | else $infos2_perso = l10n($conf_UAM[10])."\n\n"; |
---|
691 | } |
---|
692 | } |
---|
693 | |
---|
694 | // ******************************************************** |
---|
695 | // **** Pending code since to find how to make it work **** |
---|
696 | // ******************************************************** |
---|
697 | // Testing if FCK Editor is used. Then decoding htmlchars to avoid problems with pwg_mail() |
---|
698 | /*$areas = array(); |
---|
699 | array_push( $areas,'UAM_MailInfo_Text','UAM_ConfirmMail_Text'); |
---|
700 | |
---|
701 | if (function_exists('set_fckeditor_instance')) |
---|
702 | { |
---|
703 | $fcke_config = unserialize($conf['FCKEditor']); |
---|
704 | foreach($areas as $area) |
---|
705 | { |
---|
706 | if (isset($fcke_config['UAM_MailInfo_Text']) and $fcke_config['UAM_MailInfo_Text'] = true) |
---|
707 | { |
---|
708 | $infos1_perso = html_entity_decode($infos1_perso,ENT_QUOTES,UTF-8); |
---|
709 | } |
---|
710 | |
---|
711 | if (isset($fcke_config['UAM_ConfirmMail_Text']) and $fcke_config['UAM_ConfirmMail_Text'] = true) |
---|
712 | { |
---|
713 | $infos2_perso = html_entity_decode($infos2_perso,ENT_QUOTES,UTF-8); |
---|
714 | } |
---|
715 | } |
---|
716 | }*/ |
---|
717 | |
---|
718 | |
---|
719 | // Sending the email with subject and contents |
---|
720 | pwg_mail($email, array( |
---|
721 | 'subject' => $subject, |
---|
722 | 'content' => (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "").get_absolute_root_url(), |
---|
723 | )); |
---|
724 | |
---|
725 | // ********************** |
---|
726 | // Email sending debugger |
---|
727 | // This is only to trace |
---|
728 | // the send of emails for |
---|
729 | // debugging |
---|
730 | // ********************** |
---|
731 | //$content = (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "").get_absolute_root_url(); |
---|
732 | //MailLog($email,$subject,$content,$language); |
---|
733 | // ********************** |
---|
734 | |
---|
735 | // Switching back to default language |
---|
736 | switch_lang_back(); |
---|
737 | } |
---|
738 | |
---|
739 | /** |
---|
740 | * Function called from UAM_admin.php to resend validation email with or without new validation key |
---|
741 | * |
---|
742 | * @param : Type of email, user id, username, email address, confirmation (optional) |
---|
743 | * |
---|
744 | */ |
---|
745 | function ResendMail2User($typemail, $user_id, $username, $email, $confirm) |
---|
746 | { |
---|
747 | global $conf; |
---|
748 | |
---|
749 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
750 | |
---|
751 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
---|
752 | |
---|
753 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
754 | |
---|
755 | // We have to get the user's language in database |
---|
756 | $query =' |
---|
757 | SELECT user_id, language |
---|
758 | FROM '.USER_INFOS_TABLE.' |
---|
759 | WHERE user_id = '.$user_id.' |
---|
760 | ;'; |
---|
761 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
762 | $language = $data['language']; |
---|
763 | |
---|
764 | // And switch gallery to this language before using personalized and multilangual contents |
---|
765 | switch_lang_to($data['language']); |
---|
766 | |
---|
767 | load_language('plugin.lang', UAM_PATH); |
---|
768 | |
---|
769 | switch($typemail) |
---|
770 | { |
---|
771 | case 1: |
---|
772 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Reminder_with_key_of_%s', $username)); |
---|
773 | |
---|
774 | 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) |
---|
775 | { |
---|
776 | if (function_exists('get_user_language_desc')) |
---|
777 | { |
---|
778 | $infos1 = get_user_language_desc($conf_UAM_ConfirmMail[2])."\n\n"; |
---|
779 | } |
---|
780 | else $infos1 = l10n($conf_UAM_ConfirmMail[2])."\n\n"; |
---|
781 | |
---|
782 | $infos2 = array |
---|
783 | ( |
---|
784 | get_l10n_args('Link: %s', ResetConfirmMail($user_id)), |
---|
785 | get_l10n_args('', ''), |
---|
786 | ); |
---|
787 | } |
---|
788 | |
---|
789 | // Set reminder true |
---|
790 | $query = " |
---|
791 | UPDATE ".USER_CONFIRM_MAIL_TABLE." |
---|
792 | SET reminder = 'true' |
---|
793 | WHERE user_id = '".$user_id."' |
---|
794 | ;"; |
---|
795 | pwg_query($query); |
---|
796 | |
---|
797 | break; |
---|
798 | |
---|
799 | case 2: |
---|
800 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Reminder_without_key_of_%s',$username)); |
---|
801 | |
---|
802 | 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) |
---|
803 | { |
---|
804 | if (function_exists('get_user_language_desc')) |
---|
805 | { |
---|
806 | $infos1 = get_user_language_desc($conf_UAM_ConfirmMail[2])."\n\n"; |
---|
807 | } |
---|
808 | else $infos1 = l10n($conf_UAM_ConfirmMail[2])."\n\n"; |
---|
809 | } |
---|
810 | |
---|
811 | // Set reminder true |
---|
812 | $query = " |
---|
813 | UPDATE ".USER_CONFIRM_MAIL_TABLE." |
---|
814 | SET reminder = 'true' |
---|
815 | WHERE user_id = '".$user_id."' |
---|
816 | ;"; |
---|
817 | pwg_query($query); |
---|
818 | |
---|
819 | break; |
---|
820 | } |
---|
821 | |
---|
822 | pwg_mail($email, array( |
---|
823 | 'subject' => $subject, |
---|
824 | 'content' => ($infos1."\n\n").(isset($infos2) ? l10n_args($infos2)."\n\n" : "").get_absolute_root_url(), |
---|
825 | )); |
---|
826 | |
---|
827 | // ********************** |
---|
828 | // Email sending debugger |
---|
829 | // This is only to trace |
---|
830 | // the send of emails for |
---|
831 | // debugging |
---|
832 | // ********************** |
---|
833 | //$content = ($infos1."\n\n").(isset($infos2) ? l10n_args($infos2)."\n\n" : "").get_absolute_root_url(); |
---|
834 | //MailLog($email,$subject,$content,$language); |
---|
835 | // ********************** |
---|
836 | |
---|
837 | // Switching back to default language |
---|
838 | switch_lang_back(); |
---|
839 | } |
---|
840 | |
---|
841 | /** |
---|
842 | * Function called from UAM_admin.php to send a reminder mail for ghost users |
---|
843 | * |
---|
844 | * @param : User id, username, email address |
---|
845 | * |
---|
846 | */ |
---|
847 | function ghostreminder($user_id, $username, $email) |
---|
848 | { |
---|
849 | global $conf; |
---|
850 | |
---|
851 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
852 | |
---|
853 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
854 | |
---|
855 | $infos1_perso = ""; |
---|
856 | |
---|
857 | // We have to get the user's language in database |
---|
858 | $query =' |
---|
859 | SELECT user_id, language |
---|
860 | FROM '.USER_INFOS_TABLE.' |
---|
861 | WHERE user_id = '.$user_id.' |
---|
862 | ;'; |
---|
863 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
864 | $language = $data['language']; |
---|
865 | |
---|
866 | // And switch gallery to this language before using personalized and multilangual contents |
---|
867 | switch_lang_to($data['language']); |
---|
868 | |
---|
869 | load_language('plugin.lang', UAM_PATH); |
---|
870 | |
---|
871 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Ghost_reminder_of_%s', $username)); |
---|
872 | |
---|
873 | if (isset($conf_UAM[18]) and $conf_UAM[18] <> '' and isset($conf_UAM[16]) and $conf_UAM[16] == 'true') |
---|
874 | { |
---|
875 | if (function_exists('get_user_language_desc')) |
---|
876 | { |
---|
877 | $infos1 = get_user_language_desc($conf_UAM[18])."\n\n"; |
---|
878 | } |
---|
879 | else |
---|
880 | { |
---|
881 | $infos1 = l10n($conf_UAM[18])."\n\n"; |
---|
882 | } |
---|
883 | |
---|
884 | resetlastvisit($user_id); |
---|
885 | } |
---|
886 | |
---|
887 | pwg_mail($email, array( |
---|
888 | 'subject' => $subject, |
---|
889 | 'content' => $infos1.get_absolute_root_url(), |
---|
890 | )); |
---|
891 | |
---|
892 | // ********************** |
---|
893 | // Email sending debugger |
---|
894 | // This is only to trace |
---|
895 | // the send of emails for |
---|
896 | // debugging |
---|
897 | // ********************** |
---|
898 | //$content = get_user_language_desc($conf_UAM[19])."\n\n"; |
---|
899 | //MailLog($email,$subject,$content,$language); |
---|
900 | // ********************** |
---|
901 | |
---|
902 | // Switching back to default language |
---|
903 | switch_lang_back(); |
---|
904 | } |
---|
905 | |
---|
906 | /** |
---|
907 | * Function called from functions.inc.php to send notification email when user have been downgraded |
---|
908 | * |
---|
909 | * @param : user id, username, email address, confirmation |
---|
910 | * |
---|
911 | */ |
---|
912 | function demotion_mail($id, $username, $email) |
---|
913 | { |
---|
914 | global $conf; |
---|
915 | |
---|
916 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
917 | |
---|
918 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
919 | |
---|
920 | $custom_txt = ""; |
---|
921 | |
---|
922 | // We have to get the user's language in database |
---|
923 | $query =' |
---|
924 | SELECT user_id, language |
---|
925 | FROM '.USER_INFOS_TABLE.' |
---|
926 | WHERE user_id = '.$id.' |
---|
927 | ;'; |
---|
928 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
929 | |
---|
930 | // Check if user is already registered (profile changing) - If not (new registration), language is set to current gallery language |
---|
931 | if (empty($data)) |
---|
932 | { |
---|
933 | // And switch gallery to this language before using personalized and multilangual contents |
---|
934 | $language = pwg_get_session_var( 'lang_switch', $user['language'] ); |
---|
935 | switch_lang_to($language); |
---|
936 | } |
---|
937 | else |
---|
938 | { |
---|
939 | // And switch gallery to this language before using personalized and multilangual contents |
---|
940 | $language = $data['language']; // Usefull for debugging |
---|
941 | switch_lang_to($data['language']); |
---|
942 | load_language('plugin.lang', UAM_PATH); |
---|
943 | } |
---|
944 | |
---|
945 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Demotion of %s', stripslashes($username))); |
---|
946 | |
---|
947 | if (isset($conf_UAM[26]) and $conf_UAM[26] <> '') |
---|
948 | { |
---|
949 | if (function_exists('get_user_language_desc')) |
---|
950 | { |
---|
951 | $custom_txt = get_user_language_desc($conf_UAM[26])."\n\n"; |
---|
952 | } |
---|
953 | else $custom_txt = l10n($conf_UAM[26])."\n\n"; |
---|
954 | } |
---|
955 | |
---|
956 | $infos1 = array( |
---|
957 | get_l10n_args('User: %s', stripslashes($username)), |
---|
958 | get_l10n_args('Email: %s', $email), |
---|
959 | get_l10n_args('', ''), |
---|
960 | ); |
---|
961 | |
---|
962 | $infos2 = array |
---|
963 | ( |
---|
964 | get_l10n_args('Link: %s', ResetConfirmMail($id)), |
---|
965 | get_l10n_args('', ''), |
---|
966 | ); |
---|
967 | |
---|
968 | |
---|
969 | // Sending the email with subject and contents |
---|
970 | pwg_mail($email, array( |
---|
971 | 'subject' => $subject, |
---|
972 | 'content' => ($custom_txt.l10n_args($infos1)."\n\n".l10n_args($infos2)."\n\n").get_absolute_root_url(), |
---|
973 | )); |
---|
974 | |
---|
975 | // ********************** |
---|
976 | // Email sending debugger |
---|
977 | // This is only to trace |
---|
978 | // the send of emails for |
---|
979 | // debugging |
---|
980 | // ********************** |
---|
981 | //$content = ($infos1."\n\n".$infos2."\n\n").get_absolute_root_url(); |
---|
982 | //MailLog($email,$subject,$content,$language); |
---|
983 | // ********************** |
---|
984 | |
---|
985 | // Switching back to default language |
---|
986 | switch_lang_back(); |
---|
987 | } |
---|
988 | |
---|
989 | /** |
---|
990 | * Function called from functions AddConfirmMail and ResetConfirmMail for validation key generation |
---|
991 | * |
---|
992 | * @return : validation key |
---|
993 | * |
---|
994 | */ |
---|
995 | function FindAvailableConfirmMailID() |
---|
996 | { |
---|
997 | while (true) |
---|
998 | { |
---|
999 | $id = generate_key(16); |
---|
1000 | $query = " |
---|
1001 | SELECT COUNT(*) |
---|
1002 | FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
1003 | WHERE id = '".$id."' |
---|
1004 | ;"; |
---|
1005 | list($count) = pwg_db_fetch_row(pwg_query($query)); |
---|
1006 | |
---|
1007 | if ($count == 0) |
---|
1008 | return $id; |
---|
1009 | } |
---|
1010 | } |
---|
1011 | |
---|
1012 | /** |
---|
1013 | * Function called from functions SendMail2User to process unvalidated users and generate validation key link |
---|
1014 | * |
---|
1015 | * @param : User id, email address |
---|
1016 | * |
---|
1017 | * @return : Build validation key in URL |
---|
1018 | * |
---|
1019 | */ |
---|
1020 | function AddConfirmMail($user_id, $email) |
---|
1021 | { |
---|
1022 | global $conf; |
---|
1023 | |
---|
1024 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1025 | $Confirm_Mail_ID = FindAvailableConfirmMailID(); |
---|
1026 | |
---|
1027 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
1028 | |
---|
1029 | if (isset($Confirm_Mail_ID)) |
---|
1030 | { |
---|
1031 | $query = " |
---|
1032 | SELECT status |
---|
1033 | FROM ".USER_INFOS_TABLE." |
---|
1034 | WHERE user_id = '".$user_id."' |
---|
1035 | ;"; |
---|
1036 | list($status) = pwg_db_fetch_row(pwg_query($query)); |
---|
1037 | |
---|
1038 | $query = " |
---|
1039 | INSERT INTO ".USER_CONFIRM_MAIL_TABLE." |
---|
1040 | (id, user_id, mail_address, status, date_check) |
---|
1041 | VALUES |
---|
1042 | ('".$Confirm_Mail_ID."', '".$user_id."', '".$email."', '".$status."', null) |
---|
1043 | ;"; |
---|
1044 | pwg_query($query); |
---|
1045 | |
---|
1046 | // Delete user from all groups |
---|
1047 | $query = " |
---|
1048 | DELETE FROM ".USER_GROUP_TABLE." |
---|
1049 | WHERE user_id = '".$user_id."' |
---|
1050 | AND ( |
---|
1051 | group_id = '".$conf_UAM[2]."' |
---|
1052 | OR |
---|
1053 | group_id = '".$conf_UAM[3]."' |
---|
1054 | ) |
---|
1055 | ;"; |
---|
1056 | pwg_query($query); |
---|
1057 | |
---|
1058 | // Set user unvalidated status |
---|
1059 | if (!is_admin() and $conf_UAM[8] <> -1) |
---|
1060 | { |
---|
1061 | $query = " |
---|
1062 | UPDATE ".USER_INFOS_TABLE." |
---|
1063 | SET status = '".$conf_UAM[8]."' |
---|
1064 | WHERE user_id = '".$user_id."' |
---|
1065 | ;"; |
---|
1066 | pwg_query($query); |
---|
1067 | } |
---|
1068 | |
---|
1069 | // Set user unvalidated group |
---|
1070 | if (!is_admin() and $conf_UAM[2] <> -1) |
---|
1071 | { |
---|
1072 | $query = " |
---|
1073 | INSERT INTO ".USER_GROUP_TABLE." |
---|
1074 | (user_id, group_id) |
---|
1075 | VALUES |
---|
1076 | ('".$user_id."', '".$conf_UAM[2]."') |
---|
1077 | ;"; |
---|
1078 | pwg_query($query); |
---|
1079 | } |
---|
1080 | |
---|
1081 | return get_absolute_root_url().UAM_PATH.'ConfirmMail.php?key='.$Confirm_Mail_ID.'&userid='.$user_id; |
---|
1082 | } |
---|
1083 | } |
---|
1084 | |
---|
1085 | /** |
---|
1086 | * Function called from main.inc.php to set group to new users if manual validation is set |
---|
1087 | * |
---|
1088 | * @param : User id |
---|
1089 | * |
---|
1090 | * |
---|
1091 | */ |
---|
1092 | function setgroup($user_id) |
---|
1093 | { |
---|
1094 | global $conf; |
---|
1095 | |
---|
1096 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1097 | |
---|
1098 | $query = " |
---|
1099 | DELETE FROM ".USER_GROUP_TABLE." |
---|
1100 | WHERE user_id = '".$user_id."' |
---|
1101 | AND ( |
---|
1102 | group_id = '".$conf_UAM[2]."' |
---|
1103 | OR |
---|
1104 | group_id = '".$conf_UAM[3]."' |
---|
1105 | ) |
---|
1106 | ;"; |
---|
1107 | pwg_query($query); |
---|
1108 | |
---|
1109 | if (!is_admin() and $conf_UAM[8] <> -1) |
---|
1110 | { |
---|
1111 | $query = " |
---|
1112 | UPDATE ".USER_INFOS_TABLE." |
---|
1113 | SET status = '".$conf_UAM[8]."' |
---|
1114 | WHERE user_id = '".$user_id."' |
---|
1115 | ;"; |
---|
1116 | pwg_query($query); |
---|
1117 | } |
---|
1118 | |
---|
1119 | if (!is_admin() and $conf_UAM[2] <> -1) |
---|
1120 | { |
---|
1121 | $query = " |
---|
1122 | INSERT INTO ".USER_GROUP_TABLE." |
---|
1123 | (user_id, group_id) |
---|
1124 | VALUES |
---|
1125 | ('".$user_id."', '".$conf_UAM[2]."') |
---|
1126 | ;"; |
---|
1127 | pwg_query($query); |
---|
1128 | } |
---|
1129 | } |
---|
1130 | |
---|
1131 | /** |
---|
1132 | * Function called from UAM_admin.php to reset validation key |
---|
1133 | * |
---|
1134 | * @param : User id |
---|
1135 | * |
---|
1136 | * @return : Build validation key in URL |
---|
1137 | * |
---|
1138 | */ |
---|
1139 | function ResetConfirmMail($user_id) |
---|
1140 | { |
---|
1141 | global $conf; |
---|
1142 | |
---|
1143 | $Confirm_Mail_ID = FindAvailableConfirmMailID(); |
---|
1144 | |
---|
1145 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
1146 | |
---|
1147 | if (isset($Confirm_Mail_ID)) |
---|
1148 | { |
---|
1149 | $query = " |
---|
1150 | UPDATE ".USER_CONFIRM_MAIL_TABLE." |
---|
1151 | SET id = '".$Confirm_Mail_ID."' |
---|
1152 | WHERE user_id = '".$user_id."' |
---|
1153 | ;"; |
---|
1154 | pwg_query($query); |
---|
1155 | |
---|
1156 | $query = " |
---|
1157 | UPDATE ".USER_INFOS_TABLE." |
---|
1158 | SET registration_date = '".$dbnow."' |
---|
1159 | WHERE user_id = '".$user_id."' |
---|
1160 | ;"; |
---|
1161 | pwg_query($query); |
---|
1162 | |
---|
1163 | return get_absolute_root_url().UAM_PATH.'ConfirmMail.php?key='.$Confirm_Mail_ID.'&userid='.$user_id; |
---|
1164 | } |
---|
1165 | } |
---|
1166 | |
---|
1167 | /** |
---|
1168 | * Function called from functions.inc.php to reset last visit date after sending a reminder |
---|
1169 | * |
---|
1170 | * @param : User id |
---|
1171 | * |
---|
1172 | */ |
---|
1173 | function resetlastvisit($user_id) |
---|
1174 | { |
---|
1175 | global $conf; |
---|
1176 | |
---|
1177 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
1178 | |
---|
1179 | $query = " |
---|
1180 | UPDATE ".USER_LASTVISIT_TABLE." |
---|
1181 | SET lastvisit = '".$dbnow."', reminder = 'true' |
---|
1182 | WHERE user_id = '".$user_id."' |
---|
1183 | ;"; |
---|
1184 | pwg_query($query); |
---|
1185 | } |
---|
1186 | |
---|
1187 | |
---|
1188 | /** |
---|
1189 | * Function called from main.inc.php - Triggered on user deletion |
---|
1190 | * |
---|
1191 | */ |
---|
1192 | function DeleteConfirmMail($user_id) |
---|
1193 | { |
---|
1194 | $query = " |
---|
1195 | DELETE FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
1196 | WHERE user_id = '".$user_id."' |
---|
1197 | ;"; |
---|
1198 | pwg_query($query); |
---|
1199 | } |
---|
1200 | |
---|
1201 | /** |
---|
1202 | * Function called from main.inc.php - Triggered on user deletion |
---|
1203 | * |
---|
1204 | */ |
---|
1205 | function DeleteLastVisit($user_id) |
---|
1206 | { |
---|
1207 | $query = " |
---|
1208 | DELETE FROM ".USER_LASTVISIT_TABLE." |
---|
1209 | WHERE user_id = '".$user_id."' |
---|
1210 | ;"; |
---|
1211 | pwg_query($query); |
---|
1212 | } |
---|
1213 | |
---|
1214 | /** |
---|
1215 | * Function called from main.inc.php - Triggered on user deletion |
---|
1216 | * |
---|
1217 | * @param : User id |
---|
1218 | * |
---|
1219 | */ |
---|
1220 | function DeleteRedir($user_id) |
---|
1221 | { |
---|
1222 | $tab = array(); |
---|
1223 | |
---|
1224 | $query = ' |
---|
1225 | SELECT value |
---|
1226 | FROM '.CONFIG_TABLE.' |
---|
1227 | WHERE param = "UserAdvManager_Redir" |
---|
1228 | ;'; |
---|
1229 | |
---|
1230 | $tab = pwg_db_fetch_row(pwg_query($query)); |
---|
1231 | |
---|
1232 | $values = explode(',', $tab[0]); |
---|
1233 | |
---|
1234 | unset($values[array_search($user_id, $values)]); |
---|
1235 | |
---|
1236 | $query = " |
---|
1237 | UPDATE ".CONFIG_TABLE." |
---|
1238 | SET value = \"".implode(',', $values)."\" |
---|
1239 | WHERE param = 'UserAdvManager_Redir';"; |
---|
1240 | |
---|
1241 | pwg_query($query); |
---|
1242 | } |
---|
1243 | |
---|
1244 | /** |
---|
1245 | * Function called from ConfirmMail.php to verify validation key used by user according time limit |
---|
1246 | * Return true is key validation is OK else return false |
---|
1247 | * |
---|
1248 | * @param : User id |
---|
1249 | * |
---|
1250 | * @return : Bool |
---|
1251 | * |
---|
1252 | */ |
---|
1253 | function VerifyConfirmMail($id) |
---|
1254 | { |
---|
1255 | global $conf; |
---|
1256 | |
---|
1257 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
1258 | |
---|
1259 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1260 | |
---|
1261 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
---|
1262 | |
---|
1263 | $query = " |
---|
1264 | SELECT COUNT(*) |
---|
1265 | FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
1266 | WHERE id = '".$id."' |
---|
1267 | ;"; |
---|
1268 | list($count) = pwg_db_fetch_row(pwg_query($query)); |
---|
1269 | |
---|
1270 | if ($count == 1) |
---|
1271 | { |
---|
1272 | $query = " |
---|
1273 | SELECT user_id, status, date_check |
---|
1274 | FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
1275 | WHERE id = '".$id."' |
---|
1276 | ;"; |
---|
1277 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
1278 | |
---|
1279 | //if (!empty($data) and isset($data['user_id']) and !isset($data['date_check'])) |
---|
1280 | if (!empty($data) and isset($data['user_id'])) |
---|
1281 | { |
---|
1282 | $query = " |
---|
1283 | SELECT registration_date |
---|
1284 | FROM ".USER_INFOS_TABLE." |
---|
1285 | WHERE user_id = '".$data['user_id']."' |
---|
1286 | ;"; |
---|
1287 | list($registration_date) = pwg_db_fetch_row(pwg_query($query)); |
---|
1288 | |
---|
1289 | // Time limit process |
---|
1290 | // ******************************************** |
---|
1291 | if (!empty($registration_date)) |
---|
1292 | { |
---|
1293 | // Verify Confirmmail with time limit ON |
---|
1294 | if (isset ($conf_UAM_ConfirmMail[1])) |
---|
1295 | { |
---|
1296 | // dates formating and compare |
---|
1297 | $today = date("d-m-Y"); // Get today's date |
---|
1298 | list($day, $month, $year) = explode('-', $today); // explode date of today |
---|
1299 | $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp |
---|
1300 | |
---|
1301 | list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date |
---|
1302 | list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date |
---|
1303 | $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp |
---|
1304 | |
---|
1305 | $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps |
---|
1306 | $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days |
---|
1307 | |
---|
1308 | // Condition with the value set for time limit |
---|
1309 | if ($deltadays <= $conf_UAM_ConfirmMail[1]) // If Nb of days is less than the limit set |
---|
1310 | { |
---|
1311 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
1312 | |
---|
1313 | $query = ' |
---|
1314 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
1315 | SET date_check="'.$dbnow.'" |
---|
1316 | WHERE id = "'.$id.'" |
---|
1317 | ;'; |
---|
1318 | pwg_query($query); |
---|
1319 | |
---|
1320 | if ($conf_UAM[2] <> -1) // Delete user from unvalidated users group |
---|
1321 | { |
---|
1322 | $query = " |
---|
1323 | DELETE FROM ".USER_GROUP_TABLE." |
---|
1324 | WHERE user_id = '".$data['user_id']."' |
---|
1325 | AND group_id = '".$conf_UAM[2]."' |
---|
1326 | ;"; |
---|
1327 | pwg_query($query); |
---|
1328 | } |
---|
1329 | |
---|
1330 | if ($conf_UAM[3] <> -1) // Add user to validated users group |
---|
1331 | { |
---|
1332 | $query = " |
---|
1333 | INSERT INTO ".USER_GROUP_TABLE." |
---|
1334 | (user_id, group_id) |
---|
1335 | VALUES |
---|
1336 | ('".$data['user_id']."', '".$conf_UAM[3]."') |
---|
1337 | ;"; |
---|
1338 | pwg_query($query); |
---|
1339 | } |
---|
1340 | |
---|
1341 | if (($conf_UAM[4] <> -1 or isset($data['status']))) // Change user's status |
---|
1342 | { |
---|
1343 | $query = " |
---|
1344 | UPDATE ".USER_INFOS_TABLE." |
---|
1345 | SET status = '".(isset($data['status']) ? $data['status'] : $conf_UAM[4])."' |
---|
1346 | WHERE user_id = '".$data['user_id']."' |
---|
1347 | ;"; |
---|
1348 | pwg_query($query); |
---|
1349 | } |
---|
1350 | // Refresh user's category cache |
---|
1351 | invalidate_user_cache(); |
---|
1352 | |
---|
1353 | return true; |
---|
1354 | } |
---|
1355 | elseif ($deltadays > $conf_UAM_ConfirmMail[1]) // If timelimit exeeds |
---|
1356 | { |
---|
1357 | return false; |
---|
1358 | } |
---|
1359 | } |
---|
1360 | // Verify Confirmmail with time limit OFF |
---|
1361 | else |
---|
1362 | { |
---|
1363 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
1364 | |
---|
1365 | $query = ' |
---|
1366 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
1367 | SET date_check="'.$dbnow.'" |
---|
1368 | WHERE id = "'.$id.'" |
---|
1369 | ;'; |
---|
1370 | pwg_query($query); |
---|
1371 | |
---|
1372 | if ($conf_UAM[2] <> -1) |
---|
1373 | { |
---|
1374 | $query = " |
---|
1375 | DELETE FROM ".USER_GROUP_TABLE." |
---|
1376 | WHERE user_id = '".$data['user_id']."' |
---|
1377 | AND group_id = '".$conf_UAM[2]."' |
---|
1378 | ;"; |
---|
1379 | pwg_query($query); |
---|
1380 | } |
---|
1381 | |
---|
1382 | if ($conf_UAM[3] <> -1) |
---|
1383 | { |
---|
1384 | $query = " |
---|
1385 | DELETE FROM ".USER_GROUP_TABLE." |
---|
1386 | WHERE user_id = '".$data['user_id']."' |
---|
1387 | AND group_id = '".$conf_UAM[3]."' |
---|
1388 | ;"; |
---|
1389 | pwg_query($query); |
---|
1390 | |
---|
1391 | $query = " |
---|
1392 | INSERT INTO ".USER_GROUP_TABLE." |
---|
1393 | (user_id, group_id) |
---|
1394 | VALUES |
---|
1395 | ('".$data['user_id']."', '".$conf_UAM[3]."') |
---|
1396 | ;"; |
---|
1397 | pwg_query($query); |
---|
1398 | } |
---|
1399 | |
---|
1400 | if (($conf_UAM[4] <> -1 or isset($data['status']))) |
---|
1401 | { |
---|
1402 | $query = " |
---|
1403 | UPDATE ".USER_INFOS_TABLE." |
---|
1404 | SET status = '".(isset($data['status']) ? $data['status'] : $conf_UAM[4])."' |
---|
1405 | WHERE user_id = '".$data['user_id']."' |
---|
1406 | ;"; |
---|
1407 | pwg_query($query); |
---|
1408 | } |
---|
1409 | // Refresh user's category cache |
---|
1410 | invalidate_user_cache(); |
---|
1411 | |
---|
1412 | return true; |
---|
1413 | } |
---|
1414 | } |
---|
1415 | } |
---|
1416 | } |
---|
1417 | else |
---|
1418 | return false; |
---|
1419 | } |
---|
1420 | |
---|
1421 | /** |
---|
1422 | * Function called from UAM_admin.php to force users validation by admin |
---|
1423 | * |
---|
1424 | * @param : User id |
---|
1425 | * |
---|
1426 | */ |
---|
1427 | function ForceValidation($id) |
---|
1428 | { |
---|
1429 | global $conf; |
---|
1430 | |
---|
1431 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
1432 | |
---|
1433 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1434 | |
---|
1435 | if (isset($conf_UAM[1]) and $conf_UAM[1] == 'true') |
---|
1436 | { |
---|
1437 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
1438 | |
---|
1439 | $query = " |
---|
1440 | UPDATE ".USER_CONFIRM_MAIL_TABLE." |
---|
1441 | SET date_check='".$dbnow."' |
---|
1442 | WHERE user_id = '".$id."' |
---|
1443 | ;"; |
---|
1444 | pwg_query($query); |
---|
1445 | |
---|
1446 | if ($conf_UAM[2] <> -1) |
---|
1447 | { |
---|
1448 | $query = " |
---|
1449 | DELETE FROM ".USER_GROUP_TABLE." |
---|
1450 | WHERE user_id = '".$id."' |
---|
1451 | AND group_id = '".$conf_UAM[2]."' |
---|
1452 | ;"; |
---|
1453 | pwg_query($query); |
---|
1454 | } |
---|
1455 | |
---|
1456 | if ($conf_UAM[3] <> -1) |
---|
1457 | { |
---|
1458 | $query = " |
---|
1459 | DELETE FROM ".USER_GROUP_TABLE." |
---|
1460 | WHERE user_id = '".$id."' |
---|
1461 | AND group_id = '".$conf_UAM[3]."' |
---|
1462 | ;"; |
---|
1463 | pwg_query($query); |
---|
1464 | |
---|
1465 | $query = " |
---|
1466 | INSERT INTO ".USER_GROUP_TABLE." |
---|
1467 | (user_id, group_id) |
---|
1468 | VALUES |
---|
1469 | ('".$id."', '".$conf_UAM[3]."') |
---|
1470 | ;"; |
---|
1471 | pwg_query($query); |
---|
1472 | } |
---|
1473 | |
---|
1474 | if ($conf_UAM[4] <> -1) |
---|
1475 | { |
---|
1476 | $query = " |
---|
1477 | UPDATE ".USER_INFOS_TABLE." |
---|
1478 | SET status = '".$conf_UAM[4]."' |
---|
1479 | WHERE user_id = '".$id."' |
---|
1480 | ;"; |
---|
1481 | pwg_query($query); |
---|
1482 | } |
---|
1483 | } |
---|
1484 | elseif (isset($conf_UAM[1]) and $conf_UAM[1] == 'local') |
---|
1485 | { |
---|
1486 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
1487 | |
---|
1488 | if ($conf_UAM[2] <> -1) |
---|
1489 | { |
---|
1490 | $query = " |
---|
1491 | DELETE FROM ".USER_GROUP_TABLE." |
---|
1492 | WHERE user_id = '".$id."' |
---|
1493 | AND group_id = '".$conf_UAM[2]."' |
---|
1494 | ;"; |
---|
1495 | pwg_query($query); |
---|
1496 | } |
---|
1497 | |
---|
1498 | if ($conf_UAM[3] <> -1) |
---|
1499 | { |
---|
1500 | $query = " |
---|
1501 | DELETE FROM ".USER_GROUP_TABLE." |
---|
1502 | WHERE user_id = '".$id."' |
---|
1503 | AND group_id = '".$conf_UAM[3]."' |
---|
1504 | ;"; |
---|
1505 | pwg_query($query); |
---|
1506 | |
---|
1507 | $query = " |
---|
1508 | INSERT INTO ".USER_GROUP_TABLE." |
---|
1509 | (user_id, group_id) |
---|
1510 | VALUES |
---|
1511 | ('".$id."', '".$conf_UAM[3]."') |
---|
1512 | ;"; |
---|
1513 | pwg_query($query); |
---|
1514 | } |
---|
1515 | |
---|
1516 | if ($conf_UAM[4] <> -1) |
---|
1517 | { |
---|
1518 | $query = " |
---|
1519 | UPDATE ".USER_INFOS_TABLE." |
---|
1520 | SET status = '".$conf_UAM[4]."' |
---|
1521 | WHERE user_id = '".$id."' |
---|
1522 | ;"; |
---|
1523 | pwg_query($query); |
---|
1524 | } |
---|
1525 | } |
---|
1526 | } |
---|
1527 | |
---|
1528 | /** |
---|
1529 | * Function called from main.inc.php - Check if username matches forbidden caracters |
---|
1530 | * |
---|
1531 | * @param : User login |
---|
1532 | * |
---|
1533 | * @return : Bool |
---|
1534 | * |
---|
1535 | */ |
---|
1536 | function ValidateUsername($login) |
---|
1537 | { |
---|
1538 | global $conf; |
---|
1539 | |
---|
1540 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1541 | |
---|
1542 | if (isset($login) and isset($conf_UAM[7]) and $conf_UAM[7] <> '') |
---|
1543 | { |
---|
1544 | $conf_CharExclusion = preg_split("/,/",$conf_UAM[7]); |
---|
1545 | for ($i = 0 ; $i < count($conf_CharExclusion) ; $i++) |
---|
1546 | { |
---|
1547 | $pattern = '/'.$conf_CharExclusion[$i].'/i'; |
---|
1548 | if (preg_match($pattern, $login)) |
---|
1549 | { |
---|
1550 | return true; |
---|
1551 | } |
---|
1552 | } |
---|
1553 | } |
---|
1554 | else |
---|
1555 | { |
---|
1556 | return false; |
---|
1557 | } |
---|
1558 | } |
---|
1559 | |
---|
1560 | /** |
---|
1561 | * Function called from main.inc.php - Check if user's email is in excluded email providers list |
---|
1562 | * Doesn't work on call - Must be copied in main.inc.php to work |
---|
1563 | * |
---|
1564 | * @param : Email address |
---|
1565 | * |
---|
1566 | * @return : Bool |
---|
1567 | * |
---|
1568 | */ |
---|
1569 | function ValidateEmailProvider($email) |
---|
1570 | { |
---|
1571 | global $conf; |
---|
1572 | |
---|
1573 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1574 | |
---|
1575 | if (isset($email) and isset($conf_UAM[12]) and $conf_UAM[12] <> '') |
---|
1576 | { |
---|
1577 | $conf_MailExclusion = preg_split("/[\s,]+/",$conf_UAM[12]); |
---|
1578 | for ($i = 0 ; $i < count($conf_MailExclusion) ; $i++) |
---|
1579 | { |
---|
1580 | $pattern = '/'.$conf_MailExclusion[$i].'/i'; |
---|
1581 | if (preg_match($pattern, $email)) |
---|
1582 | { |
---|
1583 | return true; |
---|
1584 | } |
---|
1585 | } |
---|
1586 | } |
---|
1587 | else |
---|
1588 | { |
---|
1589 | return false; |
---|
1590 | } |
---|
1591 | } |
---|
1592 | |
---|
1593 | /** |
---|
1594 | * Function called from UAM_admin.php - Get unvalidated users according time limit |
---|
1595 | * |
---|
1596 | * @return : List of users |
---|
1597 | * |
---|
1598 | */ |
---|
1599 | function get_unvalid_user_list() |
---|
1600 | { |
---|
1601 | global $conf, $page; |
---|
1602 | |
---|
1603 | // Get ConfirmMail configuration |
---|
1604 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
---|
1605 | // Get UAM configuration |
---|
1606 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1607 | |
---|
1608 | $users = array(); |
---|
1609 | |
---|
1610 | // search users depending expiration date |
---|
1611 | $query = ' |
---|
1612 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
1613 | u.'.$conf['user_fields']['username'].' AS username, |
---|
1614 | u.'.$conf['user_fields']['email'].' AS email, |
---|
1615 | ui.status, |
---|
1616 | ui.adviser, |
---|
1617 | ui.enabled_high, |
---|
1618 | ui.level, |
---|
1619 | ui.registration_date |
---|
1620 | FROM '.USERS_TABLE.' AS u |
---|
1621 | INNER JOIN '.USER_INFOS_TABLE.' AS ui |
---|
1622 | ON u.'.$conf['user_fields']['id'].' = ui.user_id |
---|
1623 | LEFT JOIN '.USER_GROUP_TABLE.' AS ug |
---|
1624 | ON u.'.$conf['user_fields']['id'].' = ug.user_id |
---|
1625 | WHERE u.'.$conf['user_fields']['id'].' >= 3 |
---|
1626 | AND (TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) >= "'.$conf_UAM_ConfirmMail[1].'" |
---|
1627 | OR TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) < "'.$conf_UAM_ConfirmMail[1].'")'; |
---|
1628 | |
---|
1629 | if ($conf_UAM[2] <> '-1' and $conf_UAM[8] == '-1') |
---|
1630 | { |
---|
1631 | $query.= ' |
---|
1632 | AND ug.group_id = '.$conf_UAM[2]; |
---|
1633 | } |
---|
1634 | if ($conf_UAM[2] == '-1' and $conf_UAM[8] <> '-1') |
---|
1635 | { |
---|
1636 | $query.= ' |
---|
1637 | AND ui.status = \''.$conf_UAM[8]."'"; |
---|
1638 | } |
---|
1639 | if ($conf_UAM[2] <> '-1' and $conf_UAM[8] <> '-1') |
---|
1640 | { |
---|
1641 | $query.= ' |
---|
1642 | AND ug.group_id = \''.$conf_UAM[2]."'"; |
---|
1643 | } |
---|
1644 | $query.= ' |
---|
1645 | ORDER BY ui.registration_date ASC |
---|
1646 | ;'; |
---|
1647 | |
---|
1648 | $result = pwg_query($query); |
---|
1649 | |
---|
1650 | while ($row = pwg_db_fetch_assoc($result)) |
---|
1651 | { |
---|
1652 | $user = $row; |
---|
1653 | $user['groups'] = array(); |
---|
1654 | |
---|
1655 | array_push($users, $user); |
---|
1656 | } |
---|
1657 | |
---|
1658 | // add group lists |
---|
1659 | $user_ids = array(); |
---|
1660 | foreach ($users as $i => $user) |
---|
1661 | { |
---|
1662 | $user_ids[$i] = $user['id']; |
---|
1663 | } |
---|
1664 | |
---|
1665 | $user_nums = array_flip($user_ids); |
---|
1666 | |
---|
1667 | if (count($user_ids) > 0) |
---|
1668 | { |
---|
1669 | $query = ' |
---|
1670 | SELECT user_id, group_id |
---|
1671 | FROM '.USER_GROUP_TABLE.' |
---|
1672 | WHERE user_id IN ('.implode(',', $user_ids).') |
---|
1673 | ;'; |
---|
1674 | |
---|
1675 | $result = pwg_query($query); |
---|
1676 | |
---|
1677 | while ($row = pwg_db_fetch_assoc($result)) |
---|
1678 | { |
---|
1679 | array_push( |
---|
1680 | $users[$user_nums[$row['user_id']]]['groups'], |
---|
1681 | $row['group_id'] |
---|
1682 | ); |
---|
1683 | } |
---|
1684 | } |
---|
1685 | |
---|
1686 | return $users; |
---|
1687 | } |
---|
1688 | |
---|
1689 | /** |
---|
1690 | * Function called from UAM_admin.php - Get ghost users |
---|
1691 | * |
---|
1692 | * @return : List of users |
---|
1693 | * |
---|
1694 | */ |
---|
1695 | function get_ghost_user_list() |
---|
1696 | { |
---|
1697 | global $conf, $page; |
---|
1698 | |
---|
1699 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1700 | |
---|
1701 | $users = array(); |
---|
1702 | |
---|
1703 | // search users depending expiration date |
---|
1704 | $query = ' |
---|
1705 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
1706 | u.'.$conf['user_fields']['username'].' AS username, |
---|
1707 | u.'.$conf['user_fields']['email'].' AS email, |
---|
1708 | lv.lastvisit, |
---|
1709 | lv.reminder |
---|
1710 | FROM '.USERS_TABLE.' AS u |
---|
1711 | INNER JOIN '.USER_LASTVISIT_TABLE.' AS lv |
---|
1712 | ON u.'.$conf['user_fields']['id'].' = lv.user_id |
---|
1713 | WHERE (TO_DAYS(NOW()) - TO_DAYS(lv.lastvisit) >= "'.$conf_UAM[17].'") |
---|
1714 | ORDER BY lv.lastvisit ASC;'; |
---|
1715 | |
---|
1716 | $result = pwg_query($query); |
---|
1717 | |
---|
1718 | while ($row = pwg_db_fetch_assoc($result)) |
---|
1719 | { |
---|
1720 | $user = $row; |
---|
1721 | $user['groups'] = array(); |
---|
1722 | |
---|
1723 | array_push($users, $user); |
---|
1724 | } |
---|
1725 | |
---|
1726 | // add group lists |
---|
1727 | $user_ids = array(); |
---|
1728 | foreach ($users as $i => $user) |
---|
1729 | { |
---|
1730 | $user_ids[$i] = $user['id']; |
---|
1731 | } |
---|
1732 | |
---|
1733 | return $users; |
---|
1734 | } |
---|
1735 | |
---|
1736 | |
---|
1737 | /** |
---|
1738 | * Function called from functions.inc.php - Get all ghost users to delete or downgrade automatically on any user login |
---|
1739 | * |
---|
1740 | * @return : List of users to delete or downgrade automatically |
---|
1741 | * |
---|
1742 | */ |
---|
1743 | function get_ghosts_autotasks() |
---|
1744 | { |
---|
1745 | global $conf, $page; |
---|
1746 | |
---|
1747 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1748 | |
---|
1749 | $users = array(); |
---|
1750 | |
---|
1751 | // search users depending expiration date and reminder sent |
---|
1752 | $query = ' |
---|
1753 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
1754 | lv.lastvisit, |
---|
1755 | lv.reminder |
---|
1756 | FROM '.USERS_TABLE.' AS u |
---|
1757 | INNER JOIN '.USER_LASTVISIT_TABLE.' AS lv |
---|
1758 | ON u.'.$conf['user_fields']['id'].' = lv.user_id |
---|
1759 | WHERE (TO_DAYS(NOW()) - TO_DAYS(lv.lastvisit) >= "'.$conf_UAM[17].'") |
---|
1760 | AND lv.reminder = "true" |
---|
1761 | ORDER BY lv.lastvisit ASC;'; |
---|
1762 | |
---|
1763 | $result = pwg_query($query); |
---|
1764 | |
---|
1765 | while ($row = pwg_db_fetch_assoc($result)) |
---|
1766 | { |
---|
1767 | $user = $row; |
---|
1768 | $user['groups'] = array(); |
---|
1769 | |
---|
1770 | array_push($users, $user); |
---|
1771 | } |
---|
1772 | |
---|
1773 | // add group lists |
---|
1774 | $user_ids = array(); |
---|
1775 | foreach ($users as $i => $user) |
---|
1776 | { |
---|
1777 | $user_ids[$i] = $user['id']; |
---|
1778 | } |
---|
1779 | |
---|
1780 | return $users; |
---|
1781 | } |
---|
1782 | |
---|
1783 | |
---|
1784 | /** |
---|
1785 | * Function called from UAM_admin.php - Get all users to display the number of days since their last visit |
---|
1786 | * |
---|
1787 | * @return : List of users |
---|
1788 | * |
---|
1789 | */ |
---|
1790 | function get_user_list() |
---|
1791 | { |
---|
1792 | global $conf, $page; |
---|
1793 | |
---|
1794 | $users = array(); |
---|
1795 | |
---|
1796 | // search users depending expiration date |
---|
1797 | $query = ' |
---|
1798 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
1799 | u.'.$conf['user_fields']['username'].' AS username, |
---|
1800 | u.'.$conf['user_fields']['email'].' AS email, |
---|
1801 | ug.lastvisit |
---|
1802 | FROM '.USERS_TABLE.' AS u |
---|
1803 | INNER JOIN '.USER_LASTVISIT_TABLE.' AS ug |
---|
1804 | ON u.'.$conf['user_fields']['id'].' = ug.user_id |
---|
1805 | WHERE u.'.$conf['user_fields']['id'].' >= 3 |
---|
1806 | ORDER BY ug.lastvisit DESC |
---|
1807 | ;'; |
---|
1808 | |
---|
1809 | $result = pwg_query($query); |
---|
1810 | |
---|
1811 | while ($row = pwg_db_fetch_assoc($result)) |
---|
1812 | { |
---|
1813 | $user = $row; |
---|
1814 | $user['groups'] = array(); |
---|
1815 | |
---|
1816 | array_push($users, $user); |
---|
1817 | } |
---|
1818 | |
---|
1819 | // add group lists |
---|
1820 | $user_ids = array(); |
---|
1821 | foreach ($users as $i => $user) |
---|
1822 | { |
---|
1823 | $user_ids[$i] = $user['id']; |
---|
1824 | } |
---|
1825 | |
---|
1826 | return $users; |
---|
1827 | } |
---|
1828 | |
---|
1829 | /** |
---|
1830 | * Function called from UAM_admin.php - to determine who is expired or not and giving a different display color |
---|
1831 | * |
---|
1832 | * @param : user id |
---|
1833 | * |
---|
1834 | * @return : Bool |
---|
1835 | * |
---|
1836 | */ |
---|
1837 | function expiration($id) |
---|
1838 | { |
---|
1839 | global $conf, $page; |
---|
1840 | |
---|
1841 | // Get ConfirmMail configuration |
---|
1842 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
---|
1843 | |
---|
1844 | // Get UAM configuration |
---|
1845 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1846 | |
---|
1847 | $query = " |
---|
1848 | SELECT registration_date |
---|
1849 | FROM ".USER_INFOS_TABLE." |
---|
1850 | WHERE user_id = '".$id."' |
---|
1851 | ;"; |
---|
1852 | list($registration_date) = pwg_db_fetch_row(pwg_query($query)); |
---|
1853 | |
---|
1854 | // Time limit process |
---|
1855 | // ******************************************** |
---|
1856 | if (!empty($registration_date)) |
---|
1857 | { |
---|
1858 | // dates formating and compare |
---|
1859 | $today = date("d-m-Y"); // Get today's date |
---|
1860 | list($day, $month, $year) = explode('-', $today); // explode date of today |
---|
1861 | $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp |
---|
1862 | |
---|
1863 | list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date |
---|
1864 | list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date |
---|
1865 | $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp |
---|
1866 | |
---|
1867 | $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps |
---|
1868 | $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days |
---|
1869 | |
---|
1870 | // Condition with the value set for time limit |
---|
1871 | if ($deltadays <= $conf_UAM_ConfirmMail[1]) // If Nb of days is less than the limit set |
---|
1872 | { |
---|
1873 | return false; |
---|
1874 | } |
---|
1875 | else |
---|
1876 | { |
---|
1877 | return true; |
---|
1878 | } |
---|
1879 | } |
---|
1880 | } |
---|
1881 | |
---|
1882 | |
---|
1883 | /** |
---|
1884 | * Returns a password's score for password complexity check |
---|
1885 | * |
---|
1886 | * @param : password filled by user |
---|
1887 | * |
---|
1888 | * @return : Score calculation |
---|
1889 | * |
---|
1890 | * Thanx to MathieuGut from http://m-gut.developpez.com |
---|
1891 | */ |
---|
1892 | function testpassword($password) // Le mot de passe passé en paramètre - $password given by user |
---|
1893 | { |
---|
1894 | |
---|
1895 | // Initialisation des variables - Variables initiation |
---|
1896 | $points = 0; |
---|
1897 | $point_lowercase = 0; |
---|
1898 | $point_uppercase = 0; |
---|
1899 | $point_numbers = 0; |
---|
1900 | $point_characters = 0; |
---|
1901 | |
---|
1902 | // On récupère la longueur du mot de passe - Getting password lengh |
---|
1903 | $length = strlen($password); |
---|
1904 | |
---|
1905 | // On fait une boucle pour lire chaque lettre - Loop to read password characters |
---|
1906 | for($i = 0; $i < $length; $i++) |
---|
1907 | { |
---|
1908 | // On sélectionne une à une chaque lettre - Select each letters |
---|
1909 | // $i étant à 0 lors du premier passage de la boucle - $i is 0 at first turn |
---|
1910 | $letters = $password[$i]; |
---|
1911 | |
---|
1912 | if ($letters>='a' && $letters<='z') |
---|
1913 | { |
---|
1914 | // On ajoute 1 point pour une minuscule - Adding 1 point to score for a lowercase |
---|
1915 | $points = $points + 1; |
---|
1916 | |
---|
1917 | // On rajoute le bonus pour une minuscule - Adding bonus points for lowercase |
---|
1918 | $point_lowercase = 1; |
---|
1919 | } |
---|
1920 | else if ($letters>='A' && $letters <='Z') |
---|
1921 | { |
---|
1922 | // On ajoute 2 points pour une majuscule - Adding 2 points to score for uppercase |
---|
1923 | $points = $points + 2; |
---|
1924 | |
---|
1925 | // On rajoute le bonus pour une majuscule - Adding bonus points for uppercase |
---|
1926 | $point_uppercase = 2; |
---|
1927 | } |
---|
1928 | else if ($letters>='0' && $letters<='9') |
---|
1929 | { |
---|
1930 | // On ajoute 3 points pour un chiffre - Adding 3 points to score for numbers |
---|
1931 | $points = $points + 3; |
---|
1932 | |
---|
1933 | // On rajoute le bonus pour un chiffre - Adding bonus points for numbers |
---|
1934 | $point_numbers = 3; |
---|
1935 | } |
---|
1936 | else |
---|
1937 | { |
---|
1938 | // On ajoute 5 points pour un caractère autre - Adding 5 points to score for special characters |
---|
1939 | $points = $points + 5; |
---|
1940 | |
---|
1941 | // On rajoute le bonus pour un caractère autre - Adding bonus points for special characters |
---|
1942 | $point_characters = 5; |
---|
1943 | } |
---|
1944 | } |
---|
1945 | |
---|
1946 | // Calcul du coefficient points/longueur - calculating the coefficient points/length |
---|
1947 | $step1 = $points / $length; |
---|
1948 | |
---|
1949 | // Calcul du coefficient de la diversité des types de caractères... - Calculation of the diversity of character types... |
---|
1950 | $step2 = $point_lowercase + $point_uppercase + $point_numbers + $point_characters; |
---|
1951 | |
---|
1952 | // Multiplication du coefficient de diversité avec celui de la longueur - Multiplying the coefficient of diversity with that of the length |
---|
1953 | $score = $step1 * $step2; |
---|
1954 | |
---|
1955 | // Multiplication du résultat par la longueur de la chaîne - Multiplying the result by the length of the chain |
---|
1956 | $finalscore = $score * $length; |
---|
1957 | |
---|
1958 | return $finalscore; |
---|
1959 | } |
---|
1960 | |
---|
1961 | /** |
---|
1962 | * Function called from maintain.inc.php - to check if database upgrade is needed |
---|
1963 | * |
---|
1964 | * @param : table name |
---|
1965 | * |
---|
1966 | * @return : boolean |
---|
1967 | * |
---|
1968 | */ |
---|
1969 | function table_exist($table) |
---|
1970 | { |
---|
1971 | $query = 'DESC '.$table.';'; |
---|
1972 | return (bool)($res=pwg_query($query)); |
---|
1973 | } |
---|
1974 | |
---|
1975 | // Email sending debugger function |
---|
1976 | function MailLog($to, $subject, $content, $language) |
---|
1977 | { |
---|
1978 | $fo=fopen (UAM_PATH.'admin/maillog.txt','a') ; |
---|
1979 | fwrite($fo,"======================\n") ; |
---|
1980 | fwrite($fo,'le ' . date('D, d M Y H:i:s') . "\r\n"); |
---|
1981 | fwrite($fo,$to . "\n" . $subject . "\r\n") ; |
---|
1982 | fwrite($fo, "\n" . $content . "\r\n") ; |
---|
1983 | fwrite($fo, 'Langue : '."\n" . $language . "\r\n") ; |
---|
1984 | fclose($fo) ; |
---|
1985 | //return mail ($to,$subject) ; |
---|
1986 | } |
---|
1987 | |
---|
1988 | /** |
---|
1989 | * Function called from UAM_admin.php and main.inc.php to get the plugin version and name |
---|
1990 | * |
---|
1991 | * @param : plugin directory |
---|
1992 | * |
---|
1993 | * @return : plugin's version and name |
---|
1994 | * |
---|
1995 | */ |
---|
1996 | function PluginInfos($dir) |
---|
1997 | { |
---|
1998 | $path = $dir; |
---|
1999 | |
---|
2000 | $plg_data = implode( '', file($path.'main.inc.php') ); |
---|
2001 | if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) ) |
---|
2002 | { |
---|
2003 | $plugin['name'] = trim( $val[1] ); |
---|
2004 | } |
---|
2005 | if (preg_match("|Version: (.*)|", $plg_data, $val)) |
---|
2006 | { |
---|
2007 | $plugin['version'] = trim($val[1]); |
---|
2008 | } |
---|
2009 | if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) ) |
---|
2010 | { |
---|
2011 | $plugin['uri'] = trim($val[1]); |
---|
2012 | } |
---|
2013 | if ($desc = load_language('description.txt', $path.'/', array('return' => true))) |
---|
2014 | { |
---|
2015 | $plugin['description'] = trim($desc); |
---|
2016 | } |
---|
2017 | elseif ( preg_match("|Description: (.*)|", $plg_data, $val) ) |
---|
2018 | { |
---|
2019 | $plugin['description'] = trim($val[1]); |
---|
2020 | } |
---|
2021 | if ( preg_match("|Author: (.*)|", $plg_data, $val) ) |
---|
2022 | { |
---|
2023 | $plugin['author'] = trim($val[1]); |
---|
2024 | } |
---|
2025 | if ( preg_match("|Author URI: (.*)|", $plg_data, $val) ) |
---|
2026 | { |
---|
2027 | $plugin['author uri'] = trim($val[1]); |
---|
2028 | } |
---|
2029 | if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid=')) |
---|
2030 | { |
---|
2031 | list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']); |
---|
2032 | if (is_numeric($extension)) $plugin['extension'] = $extension; |
---|
2033 | } |
---|
2034 | // IMPORTANT SECURITY ! |
---|
2035 | $plugin = array_map('htmlspecialchars', $plugin); |
---|
2036 | |
---|
2037 | return $plugin ; |
---|
2038 | } |
---|
2039 | |
---|
2040 | |
---|
2041 | function clean_obsolete_files() |
---|
2042 | { |
---|
2043 | if (file_exists(UAM_PATH.'obsolete.list') |
---|
2044 | and $old_files = file(UAM_PATH.'obsolete.list', FILE_IGNORE_NEW_LINES) |
---|
2045 | and !empty($old_files)) |
---|
2046 | { |
---|
2047 | array_push($old_files, 'obsolete.list'); |
---|
2048 | foreach($old_files as $old_file) |
---|
2049 | { |
---|
2050 | $path = UAM_PATH.$old_file; |
---|
2051 | if (is_file($path)) |
---|
2052 | { |
---|
2053 | @unlink($path); |
---|
2054 | } |
---|
2055 | } |
---|
2056 | } |
---|
2057 | } |
---|
2058 | |
---|
2059 | /** |
---|
2060 | * UAM_check_profile - Thx to LucMorizur |
---|
2061 | * checks if a user id is registered as having already |
---|
2062 | * visited his profile.php page. |
---|
2063 | * |
---|
2064 | * @uid : the user id |
---|
2065 | * |
---|
2066 | * @user_idsOK : (returned) array of all users ids having already visited |
---|
2067 | * their profile.php pages |
---|
2068 | * |
---|
2069 | * @returns : true or false whether the users has already visited his |
---|
2070 | * profile.php page or not |
---|
2071 | * |
---|
2072 | */ |
---|
2073 | function UAM_check_profile($uid, &$user_idsOK) |
---|
2074 | { |
---|
2075 | $t = array(); |
---|
2076 | $v = false; |
---|
2077 | |
---|
2078 | $query = " |
---|
2079 | SELECT value |
---|
2080 | FROM ".CONFIG_TABLE." |
---|
2081 | WHERE param = 'UserAdvManager_Redir' |
---|
2082 | ;"; |
---|
2083 | |
---|
2084 | if ($v = (($t = pwg_db_fetch_row(pwg_query($query))) !== false)) |
---|
2085 | { |
---|
2086 | $user_idsOK = explode(',', $t[0]); |
---|
2087 | $v = (in_array($uid, $user_idsOK)); |
---|
2088 | } |
---|
2089 | return $v; |
---|
2090 | } |
---|
2091 | ?> |
---|