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