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