1 | <?php |
---|
2 | include_once (UAM_PATH.'include/constants.php'); |
---|
3 | load_language('plugin.lang', UAM_PATH); |
---|
4 | |
---|
5 | |
---|
6 | /** |
---|
7 | * Triggered on get_admin_plugin_menu_links |
---|
8 | * |
---|
9 | * Plugin's administration menu |
---|
10 | */ |
---|
11 | function UAM_admin_menu($menu) |
---|
12 | { |
---|
13 | // +-----------------------------------------------------------------------+ |
---|
14 | // | Getting plugin name | |
---|
15 | // +-----------------------------------------------------------------------+ |
---|
16 | $plugin = PluginInfos(UAM_PATH); |
---|
17 | $name = $plugin['name']; |
---|
18 | |
---|
19 | array_push($menu, |
---|
20 | array( |
---|
21 | 'NAME' => $name, |
---|
22 | 'URL' => get_root_url().'admin.php?page=plugin-'.basename(UAM_PATH) |
---|
23 | ) |
---|
24 | ); |
---|
25 | |
---|
26 | return $menu; |
---|
27 | } |
---|
28 | |
---|
29 | |
---|
30 | /** |
---|
31 | * Triggered on loc_begin_admin_page |
---|
32 | * |
---|
33 | * Check options compatibility |
---|
34 | */ |
---|
35 | function UAM_check_compat() |
---|
36 | { |
---|
37 | global $conf, $page; |
---|
38 | |
---|
39 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
40 | |
---|
41 | // Check mandatory email address for email exclusion |
---|
42 | if (!$conf['obligatory_user_mail_address'] and $conf_UAM['MAILEXCLUSION'] == 'true') |
---|
43 | { |
---|
44 | array_push($page['warnings'], l10n('UAM_mail_exclusion_error')); |
---|
45 | } |
---|
46 | } |
---|
47 | |
---|
48 | |
---|
49 | /** |
---|
50 | * Triggered on loc_begin_index |
---|
51 | * |
---|
52 | * Initiating GhostTracker - Perform user logout after registration if not validated |
---|
53 | */ |
---|
54 | function UAM_Init() |
---|
55 | { |
---|
56 | global $conf, $user; |
---|
57 | |
---|
58 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
59 | |
---|
60 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
61 | |
---|
62 | // Admins, Guests and Adult_Content users are not tracked for Ghost Tracker or Users Tracker |
---|
63 | // ----------------------------------------------------------------------------------------- |
---|
64 | if (!is_admin() and !is_a_guest() and $user['username'] != "16" and $user['username'] != "18") |
---|
65 | { |
---|
66 | if ((isset($conf_UAM['GHOSTRACKER']) and $conf_UAM['GHOSTRACKER'] == 'true') or (isset($conf_UAM['ADDLASTVISIT']) and $conf_UAM['ADDLASTVISIT'] == 'true')) |
---|
67 | { |
---|
68 | $userid = get_userid($user['username']); |
---|
69 | |
---|
70 | // Looking for existing entry in last visit table |
---|
71 | // ---------------------------------------------- |
---|
72 | $query = ' |
---|
73 | SELECT * |
---|
74 | FROM '.USER_LASTVISIT_TABLE.' |
---|
75 | WHERE user_id = '.$userid.' |
---|
76 | ;'; |
---|
77 | |
---|
78 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
79 | |
---|
80 | if ($count == 0) |
---|
81 | { |
---|
82 | // If not, data are inserted in table |
---|
83 | // ---------------------------------- |
---|
84 | $query = ' |
---|
85 | INSERT INTO '.USER_LASTVISIT_TABLE.' (user_id, lastvisit, reminder) |
---|
86 | VALUES ('.$userid.', now(), "false") |
---|
87 | ;'; |
---|
88 | pwg_query($query); |
---|
89 | } |
---|
90 | else if ($count > 0) |
---|
91 | { |
---|
92 | // If yes, data are updated in table |
---|
93 | // --------------------------------- |
---|
94 | $query = ' |
---|
95 | UPDATE '.USER_LASTVISIT_TABLE.' |
---|
96 | SET lastvisit = now(), reminder = "false" |
---|
97 | WHERE user_id = '.$userid.' |
---|
98 | LIMIT 1 |
---|
99 | ;'; |
---|
100 | pwg_query($query); |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|
104 | // Perform user logout after registration if not validated |
---|
105 | if ((isset($conf_UAM['CONFIRM_MAIL']) and ($conf_UAM['CONFIRM_MAIL']=='true' or $conf_UAM['CONFIRM_MAIL']=='local')) |
---|
106 | and (isset($conf_UAM['REJECTCONNECT']) and $conf_UAM['REJECTCONNECT'] == 'true') |
---|
107 | and !UAM_UsrReg_Verif($user['id']) |
---|
108 | and !is_admin() |
---|
109 | and !is_webmaster()) |
---|
110 | { |
---|
111 | invalidate_user_cache(); |
---|
112 | logout_user(); |
---|
113 | if ( $conf['guest_access'] ) |
---|
114 | { |
---|
115 | redirect( make_index_url().'?UAM_msg=rejected', 0); |
---|
116 | } |
---|
117 | else |
---|
118 | { |
---|
119 | redirect( get_root_url().'identification.php?UAM_msg=rejected' , 0); |
---|
120 | } |
---|
121 | } |
---|
122 | } |
---|
123 | } |
---|
124 | |
---|
125 | |
---|
126 | /** |
---|
127 | * Triggered on register_user |
---|
128 | * |
---|
129 | * Additional controls on user registration |
---|
130 | */ |
---|
131 | function UAM_Adduser($register_user) |
---|
132 | { |
---|
133 | global $conf; |
---|
134 | |
---|
135 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
136 | |
---|
137 | // Exclusion of Adult_Content users |
---|
138 | // -------------------------------- |
---|
139 | if ($register_user['username'] != "16" and $register_user['username'] != "18") |
---|
140 | { |
---|
141 | $passwd = (isset($_POST['password'])) ? $_POST['password'] : ''; |
---|
142 | |
---|
143 | // -------------------------------------------------------------------------------------------------------------------- |
---|
144 | // Workflow when admins have to validate registrations (CONFIRM_MAIL = local) |
---|
145 | // No validation needed when admins add users if ADMINCONFMAIL is set to OFF - users are considered as valid by default |
---|
146 | // Else a notification email with validation link is send to admins |
---|
147 | // Finally when a user registers himself, a notification email with validation link is send to admins |
---|
148 | // -------------------------------------------------------------------------------------------------------------------- |
---|
149 | if (isset($conf_UAM['CONFIRM_MAIL']) and $conf_UAM['CONFIRM_MAIL'] == 'local') |
---|
150 | { |
---|
151 | if (is_admin() and isset($conf_UAM['ADMINCONFMAIL']) and $conf_UAM['ADMINCONFMAIL'] == 'true') |
---|
152 | { |
---|
153 | SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], true); |
---|
154 | } |
---|
155 | elseif (is_admin() and isset($conf_UAM['ADMINCONFMAIL']) and $conf_UAM['ADMINCONFMAIL'] == 'false') |
---|
156 | { |
---|
157 | SetValidated($register_user['id']); |
---|
158 | SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], false); |
---|
159 | } |
---|
160 | elseif (!is_admin()) |
---|
161 | { |
---|
162 | SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], true); |
---|
163 | } |
---|
164 | } |
---|
165 | // -------------------------------------------------------------------------------------------------------------------- |
---|
166 | // Workflow when users have to validate their registration (CONFIRM_MAIL = true) |
---|
167 | // No validation needed when admins add users if ADMINCONFMAIL is set to OFF - users are considered as valid by default |
---|
168 | // Else an email with validation link is send to user |
---|
169 | // Finally when a user registers himself, an email with validation link is send to him |
---|
170 | // -------------------------------------------------------------------------------------------------------------------- |
---|
171 | elseif (isset($conf_UAM['CONFIRM_MAIL']) and $conf_UAM['CONFIRM_MAIL'] == 'true') |
---|
172 | { |
---|
173 | if (is_admin() and isset($conf_UAM['ADMINCONFMAIL']) and $conf_UAM['ADMINCONFMAIL'] == 'true') |
---|
174 | { |
---|
175 | SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], true); |
---|
176 | } |
---|
177 | elseif (is_admin() and isset($conf_UAM['ADMINCONFMAIL']) and $conf_UAM['ADMINCONFMAIL'] == 'false') |
---|
178 | { |
---|
179 | SetValidated($register_user['id']); |
---|
180 | SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], false); |
---|
181 | } |
---|
182 | elseif (!is_admin()) |
---|
183 | { |
---|
184 | SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], true); |
---|
185 | } |
---|
186 | } |
---|
187 | } |
---|
188 | } |
---|
189 | |
---|
190 | |
---|
191 | /** |
---|
192 | * Triggered on delete_user |
---|
193 | * |
---|
194 | * Database cleanup on user deletion |
---|
195 | */ |
---|
196 | function UAM_Deluser($user_id) |
---|
197 | { |
---|
198 | // Cleanup for ConfirmMail table |
---|
199 | // ----------------------------- |
---|
200 | DeleteConfirmMail($user_id); |
---|
201 | // Cleanup for LastVisit table |
---|
202 | // --------------------------- |
---|
203 | DeleteLastVisit($user_id); |
---|
204 | // Cleanup Redirection settings |
---|
205 | // ---------------------------- |
---|
206 | DeleteRedir($user_id); |
---|
207 | } |
---|
208 | |
---|
209 | |
---|
210 | /** |
---|
211 | * Triggered on register_user_check |
---|
212 | * |
---|
213 | * Additional controls on user registration check |
---|
214 | */ |
---|
215 | function UAM_RegistrationCheck($errors, $user) |
---|
216 | { |
---|
217 | global $conf; |
---|
218 | |
---|
219 | // Exclusion of Adult_Content users |
---|
220 | // -------------------------------- |
---|
221 | if ($user['username'] != "16" and $user['username'] != "18") |
---|
222 | { |
---|
223 | load_language('plugin.lang', UAM_PATH); |
---|
224 | |
---|
225 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
226 | |
---|
227 | // Username without forbidden keys |
---|
228 | // ------------------------------- |
---|
229 | if (isset($conf_UAM['USERNAME_CHAR']) and $conf_UAM['USERNAME_CHAR'] == 'true' and !empty($user['username']) and ValidateUsername($user['username']) and !is_admin()) |
---|
230 | { |
---|
231 | $lang['reg_err_login1'] = l10n('UAM_reg_err_login2')."'".$conf_UAM['USERNAME_CHAR_LIST']."'"; |
---|
232 | array_push($errors, $lang['reg_err_login1']); |
---|
233 | } |
---|
234 | |
---|
235 | // Email without forbidden domains |
---|
236 | // ------------------------------- |
---|
237 | if (isset($conf_UAM['MAILEXCLUSION']) and $conf_UAM['MAILEXCLUSION'] == 'true' and !empty($user['email']) and ValidateEmailProvider($user['email']) and !is_admin()) |
---|
238 | { |
---|
239 | $lang['reg_err_login1'] = l10n('UAM_reg_err_login5')."'".$conf_UAM['MAILEXCLUSION_LIST']."'"; |
---|
240 | array_push($errors, $lang['reg_err_login1']); |
---|
241 | } |
---|
242 | return $errors; |
---|
243 | } |
---|
244 | } |
---|
245 | |
---|
246 | |
---|
247 | /** |
---|
248 | * Triggered on loc_begin_profile |
---|
249 | */ |
---|
250 | function UAM_Profile_Init() |
---|
251 | { |
---|
252 | global $conf, $user, $template; |
---|
253 | |
---|
254 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
255 | |
---|
256 | // Update first redirection parameter |
---|
257 | // ---------------------------------- |
---|
258 | if ((isset($conf_UAM['REDIRTOPROFILE']) and $conf_UAM['REDIRTOPROFILE'] == 'true')) |
---|
259 | { |
---|
260 | $user_idsOK = array(); |
---|
261 | if (!UAM_check_profile($user['id'], $user_idsOK)) |
---|
262 | { |
---|
263 | $user_idsOK[] = $user['id']; |
---|
264 | |
---|
265 | $query = ' |
---|
266 | UPDATE '.CONFIG_TABLE.' |
---|
267 | SET value = "'.implode(',', $user_idsOK).'" |
---|
268 | WHERE param = "UserAdvManager_Redir";'; |
---|
269 | |
---|
270 | pwg_query($query); |
---|
271 | } |
---|
272 | } |
---|
273 | |
---|
274 | // Controls on profile page submission |
---|
275 | // ----------------------------------- |
---|
276 | if (isset($_POST['validate']) and !is_admin()) |
---|
277 | { |
---|
278 | // Email without forbidden domains |
---|
279 | // ------------------------------- |
---|
280 | if (isset($conf_UAM['MAILEXCLUSION']) and $conf_UAM['MAILEXCLUSION'] == 'true' and !empty($_POST['mail_address'])) |
---|
281 | { |
---|
282 | if (ValidateEmailProvider($_POST['mail_address'])) |
---|
283 | { |
---|
284 | $template->append('errors', l10n('UAM_reg_err_login5')."'".$conf_UAM['MAILEXCLUSION_LIST']."'"); |
---|
285 | unset($_POST['validate']); |
---|
286 | } |
---|
287 | } |
---|
288 | |
---|
289 | // Sending registration confirmation by email |
---|
290 | // ------------------------------------------ |
---|
291 | if ((isset($conf_UAM['CONFIRM_MAIL']) and $conf_UAM['CONFIRM_MAIL'] == 'true') or (isset($conf_UAM['CONFIRM_MAIL']) and $conf_UAM['CONFIRM_MAIL'] == 'local')) |
---|
292 | { |
---|
293 | $confirm_mail_need = false; |
---|
294 | |
---|
295 | if (!empty($_POST['mail_address'])) |
---|
296 | { |
---|
297 | $query = ' |
---|
298 | SELECT '.$conf['user_fields']['email'].' AS email |
---|
299 | FROM '.USERS_TABLE.' |
---|
300 | WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\' |
---|
301 | ;'; |
---|
302 | |
---|
303 | list($current_email) = pwg_db_fetch_row(pwg_query($query)); |
---|
304 | |
---|
305 | // This is to set the user to "waiting" group or status until validation |
---|
306 | // --------------------------------------------------------------------- |
---|
307 | if ($_POST['mail_address'] != $current_email and (isset($conf_UAM['CONFIRM_MAIL']) and ($conf_UAM['CONFIRM_MAIL'] == 'true' or $conf_UAM['CONFIRM_MAIL'] == 'local'))) |
---|
308 | { |
---|
309 | SetPermission($user['id']);// Set to "waiting" group or status until user validation |
---|
310 | SetUnvalidated($user['id']); // Set UAM_validated field to false in #_users table |
---|
311 | $confirm_mail_need = true; |
---|
312 | } |
---|
313 | else |
---|
314 | { |
---|
315 | $confirm_mail_need = false; |
---|
316 | } |
---|
317 | } |
---|
318 | |
---|
319 | $typemail = 2; |
---|
320 | |
---|
321 | // Send email |
---|
322 | if ((isset($conf_UAM['MAIL_INFO']) and $conf_UAM['MAIL_INFO'] == 'true') or $confirm_mail_need) |
---|
323 | { |
---|
324 | $query = ' |
---|
325 | SELECT '.$conf['user_fields']['username'].' |
---|
326 | FROM '.USERS_TABLE.' |
---|
327 | WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\' |
---|
328 | ;'; |
---|
329 | |
---|
330 | list($username) = pwg_db_fetch_row(pwg_query($query)); |
---|
331 | |
---|
332 | SendMail2User($typemail, $user['id'], $username, $_POST['use_new_pwd'], $_POST['mail_address'], $confirm_mail_need); |
---|
333 | } |
---|
334 | } |
---|
335 | } |
---|
336 | } |
---|
337 | |
---|
338 | |
---|
339 | /** |
---|
340 | * Triggered on login_success |
---|
341 | * |
---|
342 | * Triggers scheduled tasks at login |
---|
343 | * Redirects a visitor (except for admins, webmasters and generic statuses) to his profile.php page (Thx to LucMorizur) |
---|
344 | * |
---|
345 | */ |
---|
346 | function UAM_LoginTasks() |
---|
347 | { |
---|
348 | global $conf, $user; |
---|
349 | |
---|
350 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
351 | |
---|
352 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
353 | |
---|
354 | // Performing GhostTracker scheduled tasks |
---|
355 | // --------------------------------------- |
---|
356 | if ((isset($conf_UAM['GTAUTO']) and $conf_UAM['GTAUTO'] == 'true')) |
---|
357 | { |
---|
358 | UAM_GT_ScheduledTasks(); |
---|
359 | } |
---|
360 | |
---|
361 | // Performing User validation scheduled tasks |
---|
362 | // ------------------------------------------ |
---|
363 | if ((isset($conf_UAM['CONFIRM_MAIL']) and $conf_UAM['CONFIRM_MAIL']=='true') |
---|
364 | and (isset($conf_UAM['USRAUTO']) and $conf_UAM['USRAUTO'] == 'true')) |
---|
365 | { |
---|
366 | UAM_USR_ScheduledTasks(); |
---|
367 | } |
---|
368 | |
---|
369 | // Avoid login into private galleries until registration confirmation is done |
---|
370 | if ((isset($conf_UAM['REJECTCONNECT']) and $conf_UAM['REJECTCONNECT'] == 'false') |
---|
371 | or ((isset($conf_UAM['REJECTCONNECT']) and $conf_UAM['REJECTCONNECT'] == 'true') and UAM_UsrReg_Verif($user['id'])) |
---|
372 | or (!is_admin() and !is_webmaster())) |
---|
373 | { |
---|
374 | |
---|
375 | // Performing redirection to profile page on first login |
---|
376 | // ----------------------------------------------------- |
---|
377 | if ((isset($conf_UAM['REDIRTOPROFILE']) and $conf_UAM['REDIRTOPROFILE'] == 'true')) |
---|
378 | { |
---|
379 | $query =' |
---|
380 | SELECT user_id, status |
---|
381 | FROM '.USER_INFOS_TABLE.' |
---|
382 | WHERE user_id = '.$user['id'].' |
---|
383 | ;'; |
---|
384 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
385 | |
---|
386 | if ($data['status'] <> "admin" and $data['status'] <> "webmaster" and $data['status'] <> "generic") // Exclusion of specific accounts |
---|
387 | { |
---|
388 | $user_idsOK = array(); |
---|
389 | if (!UAM_check_profile($user['id'], $user_idsOK)) |
---|
390 | redirect(PHPWG_ROOT_PATH.'profile.php'); |
---|
391 | } |
---|
392 | } |
---|
393 | } |
---|
394 | elseif ((isset($conf_UAM['REJECTCONNECT']) and $conf_UAM['REJECTCONNECT'] == 'true') and !UAM_UsrReg_Verif($user['id']) and !is_admin() and !is_webmaster()) |
---|
395 | { |
---|
396 | // Logged-in user cleanup, session destruction and redirected to custom page |
---|
397 | // ------------------------------------------------------------------------- |
---|
398 | invalidate_user_cache(); |
---|
399 | logout_user(); |
---|
400 | if ( $conf['guest_access'] ) |
---|
401 | { |
---|
402 | redirect( make_index_url().'?UAM_msg=rejected', 0); |
---|
403 | } |
---|
404 | else |
---|
405 | { |
---|
406 | redirect( get_root_url().'identification.php?UAM_msg=rejected' , 0); |
---|
407 | } |
---|
408 | } |
---|
409 | } |
---|
410 | |
---|
411 | |
---|
412 | /** |
---|
413 | * Adds a new module settable in PWG_Stuffs - Triggered on get_stuffs_modules in main.inc.php |
---|
414 | * Useful to inform unvalidated user for their status |
---|
415 | * |
---|
416 | */ |
---|
417 | function register_UAM_stuffs_module($modules) |
---|
418 | { |
---|
419 | array_push($modules, array( |
---|
420 | 'path' => UAM_PATH.'/stuffs_module', |
---|
421 | 'name' => l10n('UAM_Stuffs_Title'), |
---|
422 | 'description' => l10n('UAM_Stuffs_Desc'), |
---|
423 | ) |
---|
424 | ); |
---|
425 | return $modules; |
---|
426 | } |
---|
427 | |
---|
428 | |
---|
429 | /** |
---|
430 | * Triggered on UAM_LoginTasks() |
---|
431 | * |
---|
432 | * Executes optional post-login tasks for Ghost users |
---|
433 | * |
---|
434 | */ |
---|
435 | function UAM_GT_ScheduledTasks() |
---|
436 | { |
---|
437 | global $conf, $user, $page; |
---|
438 | |
---|
439 | if (!defined('PHPWG_ROOT_PATH')) |
---|
440 | { |
---|
441 | die('Hacking attempt!'); |
---|
442 | } |
---|
443 | |
---|
444 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
445 | |
---|
446 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
447 | |
---|
448 | $collection = array(); |
---|
449 | $reminder = false; |
---|
450 | |
---|
451 | $page['filtered_users'] = get_ghosts_autotasks(); |
---|
452 | |
---|
453 | foreach($page['filtered_users'] as $listed_user) |
---|
454 | { |
---|
455 | array_push($collection, $listed_user['id']); |
---|
456 | } |
---|
457 | |
---|
458 | // Auto group, status or privacy level downgrade and autodeletion if user already reminded |
---|
459 | // --------------------------------------------------------------------------------------- |
---|
460 | if ((isset($conf_UAM['GTAUTO']) and $conf_UAM['GTAUTO'] == 'true') and ((isset($conf_UAM['DOWNGRADE_GROUP']) and $conf_UAM['DOWNGRADE_GROUP'] <> -1) or (isset($conf_UAM['DOWNGRADE_STATUS']) and $conf_UAM['DOWNGRADE_STATUS'] <> -1) or (isset($conf_UAM['DOWNGRADE_LEVEL']) and $conf_UAM['DOWNGRADE_LEVEL'] <> -1))) |
---|
461 | { |
---|
462 | if (count($collection) > 0) |
---|
463 | { |
---|
464 | // Process if a non-admin nor webmaster user is logged |
---|
465 | // --------------------------------------------------- |
---|
466 | if (in_array($user['id'], $collection)) |
---|
467 | { |
---|
468 | // Check lastvisit reminder state |
---|
469 | // ------------------------------ |
---|
470 | $query = ' |
---|
471 | SELECT reminder |
---|
472 | FROM '.USER_LASTVISIT_TABLE.' |
---|
473 | WHERE user_id = '.$user['id'].';'; |
---|
474 | |
---|
475 | $result = pwg_db_fetch_assoc(pwg_query($query)); |
---|
476 | |
---|
477 | if (isset($result['reminder']) and $result['reminder'] == 'true') |
---|
478 | { |
---|
479 | $reminder = true; |
---|
480 | } |
---|
481 | else |
---|
482 | { |
---|
483 | $reminder = false; |
---|
484 | } |
---|
485 | |
---|
486 | // If user already reminded for ghost account |
---|
487 | // ------------------------------------------ |
---|
488 | if ($reminder) |
---|
489 | { |
---|
490 | // Delete account |
---|
491 | // -------------- |
---|
492 | delete_user($user['id']); |
---|
493 | |
---|
494 | // Logged-in user cleanup, session destruction and redirected to custom page |
---|
495 | // ------------------------------------------------------------------------- |
---|
496 | invalidate_user_cache(); |
---|
497 | logout_user(); |
---|
498 | redirect(make_index_url().'?UAM_msg=deleted', 0); |
---|
499 | } |
---|
500 | } |
---|
501 | else // Process if an admin or webmaster user is logged |
---|
502 | { |
---|
503 | foreach ($collection as $user_id) |
---|
504 | { |
---|
505 | // Check lastvisit reminder state |
---|
506 | // ------------------------------ |
---|
507 | $query = ' |
---|
508 | SELECT reminder |
---|
509 | FROM '.USER_LASTVISIT_TABLE.' |
---|
510 | WHERE user_id = '.$user_id.';'; |
---|
511 | |
---|
512 | $result = pwg_db_fetch_assoc(pwg_query($query)); |
---|
513 | |
---|
514 | if (isset($result['reminder']) and $result['reminder'] == 'true') |
---|
515 | { |
---|
516 | $reminder = true; |
---|
517 | } |
---|
518 | else |
---|
519 | { |
---|
520 | $reminder = false; |
---|
521 | } |
---|
522 | |
---|
523 | // If never reminded before |
---|
524 | // ------------------------ |
---|
525 | if (!$reminder) |
---|
526 | { |
---|
527 | // Reset of lastvisit date |
---|
528 | // ----------------------- |
---|
529 | $dbnow = date("Y-m-d H:i:s"); |
---|
530 | |
---|
531 | $query = ' |
---|
532 | UPDATE '.USER_LASTVISIT_TABLE.' |
---|
533 | SET lastvisit="'.$dbnow.'" |
---|
534 | WHERE user_id = '.$user_id.' |
---|
535 | ;'; |
---|
536 | pwg_query($query); |
---|
537 | |
---|
538 | // Auto change group and / or status |
---|
539 | // --------------------------------- |
---|
540 | // Delete user from all groups |
---|
541 | // --------------------------- |
---|
542 | if ($conf_UAM['NO_CONFIRM_GROUP'] <> -1 and $conf_UAM['VALIDATED_GROUP'] <> -1) |
---|
543 | { |
---|
544 | $query = ' |
---|
545 | DELETE FROM '.USER_GROUP_TABLE.' |
---|
546 | WHERE user_id = '.$user_id.' |
---|
547 | AND ( |
---|
548 | group_id = '.$conf_UAM['NO_CONFIRM_GROUP'].' |
---|
549 | OR |
---|
550 | group_id = '.$conf_UAM['VALIDATED_GROUP'].' |
---|
551 | ) |
---|
552 | ;'; |
---|
553 | pwg_query($query); |
---|
554 | } |
---|
555 | |
---|
556 | // Change user status |
---|
557 | // ------------------ |
---|
558 | if ($conf_UAM['DOWNGRADE_STATUS'] <> -1) |
---|
559 | { |
---|
560 | $query = ' |
---|
561 | UPDATE '.USER_INFOS_TABLE.' |
---|
562 | SET status = "'.$conf_UAM['DOWNGRADE_STATUS'].'" |
---|
563 | WHERE user_id = '.$user_id.' |
---|
564 | ;'; |
---|
565 | pwg_query($query); |
---|
566 | } |
---|
567 | |
---|
568 | // Change user group |
---|
569 | // ----------------- |
---|
570 | if ($conf_UAM['DOWNGRADE_GROUP'] <> -1) |
---|
571 | { |
---|
572 | $query = ' |
---|
573 | INSERT INTO '.USER_GROUP_TABLE.' |
---|
574 | (user_id, group_id) |
---|
575 | VALUES |
---|
576 | ('.$user_id.', "'.$conf_UAM['DOWNGRADE_GROUP'].'") |
---|
577 | ;'; |
---|
578 | pwg_query($query); |
---|
579 | } |
---|
580 | |
---|
581 | // Change user privacy level |
---|
582 | // ------------------------- |
---|
583 | if ($conf_UAM['DOWNGRADE_LEVEL'] <> -1) |
---|
584 | { |
---|
585 | $query = ' |
---|
586 | UPDATE '.USER_INFOS_TABLE.' |
---|
587 | SET level = "'.$conf_UAM['DOWNGRADE_LEVEL'].'" |
---|
588 | WHERE user_id = '.$user_id.' |
---|
589 | ;'; |
---|
590 | pwg_query($query); |
---|
591 | } |
---|
592 | |
---|
593 | // Auto send email notification on group / status downgrade |
---|
594 | // -------------------------------------------------------- |
---|
595 | if (isset($conf_UAM['GTAUTOMAIL']) and $conf_UAM['GTAUTOMAIL'] == 'true') |
---|
596 | { |
---|
597 | // Set reminder true |
---|
598 | // ----------------- |
---|
599 | $query = ' |
---|
600 | UPDATE '.USER_LASTVISIT_TABLE.' |
---|
601 | SET reminder = "true" |
---|
602 | WHERE user_id = '.$user_id.' |
---|
603 | ;'; |
---|
604 | pwg_query($query); |
---|
605 | |
---|
606 | // Reset confirmed user status to unvalidated |
---|
607 | // ------------------------------------------ |
---|
608 | $query = ' |
---|
609 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
610 | SET date_check = NULL |
---|
611 | WHERE user_id = '.$user_id.' |
---|
612 | ;'; |
---|
613 | pwg_query($query); |
---|
614 | |
---|
615 | // Get users information for email notification |
---|
616 | // -------------------------------------------- |
---|
617 | $query = ' |
---|
618 | SELECT id, username, mail_address |
---|
619 | FROM '.USERS_TABLE.' |
---|
620 | WHERE id = '.$user_id.' |
---|
621 | ;'; |
---|
622 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
623 | |
---|
624 | SetUnvalidated($user_id); |
---|
625 | demotion_mail($user_id, $data['username'], $data['mail_address']); |
---|
626 | } |
---|
627 | } |
---|
628 | elseif ($reminder) // If user already reminded for ghost account |
---|
629 | { |
---|
630 | // Delete account |
---|
631 | // -------------- |
---|
632 | delete_user($user_id); |
---|
633 | } |
---|
634 | } |
---|
635 | } |
---|
636 | } |
---|
637 | } |
---|
638 | } |
---|
639 | |
---|
640 | |
---|
641 | /** |
---|
642 | * Triggered on UAM_LoginTasks() |
---|
643 | * |
---|
644 | * Executes optional post-login tasks for unvalidated users |
---|
645 | * |
---|
646 | */ |
---|
647 | function UAM_USR_ScheduledTasks() |
---|
648 | { |
---|
649 | global $conf, $user, $page; |
---|
650 | |
---|
651 | if (!defined('PHPWG_ROOT_PATH')) |
---|
652 | { |
---|
653 | die('Hacking attempt!'); |
---|
654 | } |
---|
655 | |
---|
656 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
657 | |
---|
658 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
659 | |
---|
660 | $collection = array(); |
---|
661 | $reminder = false; |
---|
662 | |
---|
663 | $page['filtered_users'] = get_unvalid_user_autotasks(); |
---|
664 | |
---|
665 | foreach($page['filtered_users'] as $listed_user) |
---|
666 | { |
---|
667 | array_push($collection, $listed_user['id']); |
---|
668 | } |
---|
669 | |
---|
670 | // Unvalidated accounts auto email sending and autodeletion if user already reminded |
---|
671 | // --------------------------------------------------------------------------------- |
---|
672 | if ((isset($conf_UAM['USRAUTO']) and $conf_UAM['USRAUTO'] == 'true')) |
---|
673 | { |
---|
674 | if (count($collection) > 0) |
---|
675 | { |
---|
676 | // Process if a non-admin nor webmaster user is logged |
---|
677 | // --------------------------------------------------- |
---|
678 | if (in_array($user['id'], $collection)) |
---|
679 | { |
---|
680 | // Check ConfirmMail reminder state |
---|
681 | // -------------------------------- |
---|
682 | $query = ' |
---|
683 | SELECT reminder |
---|
684 | FROM '.USER_CONFIRM_MAIL_TABLE.' |
---|
685 | WHERE user_id = '.$user['id'].';'; |
---|
686 | |
---|
687 | $result = pwg_db_fetch_assoc(pwg_query($query)); |
---|
688 | |
---|
689 | if (isset($result['reminder']) and $result['reminder'] == 'true') |
---|
690 | { |
---|
691 | $reminder = true; |
---|
692 | } |
---|
693 | else |
---|
694 | { |
---|
695 | $reminder = false; |
---|
696 | } |
---|
697 | |
---|
698 | // If never reminded before, send reminder and set reminder True |
---|
699 | // ------------------------------------------------------------- |
---|
700 | if (!$reminder and isset($conf_UAM['USRAUTOMAIL']) and $conf_UAM['USRAUTOMAIL'] == 'true') |
---|
701 | { |
---|
702 | $typemail = 1; |
---|
703 | |
---|
704 | // Get current user information |
---|
705 | // ---------------------------- |
---|
706 | $query = ' |
---|
707 | SELECT id, username, mail_address |
---|
708 | FROM '.USERS_TABLE.' |
---|
709 | WHERE id = '.$user['id'].' |
---|
710 | ;'; |
---|
711 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
712 | |
---|
713 | ResendMail2User($typemail,$user['id'],stripslashes($data['username']),$data['mail_address'],true); |
---|
714 | } |
---|
715 | |
---|
716 | // If already reminded before, delete user |
---|
717 | // --------------------------------------- |
---|
718 | if ($reminder) |
---|
719 | { |
---|
720 | // delete account |
---|
721 | delete_user($user['id']); |
---|
722 | |
---|
723 | // Logged-in user cleanup, session destruction and redirected to custom page |
---|
724 | // ------------------------------------------------------------------------- |
---|
725 | invalidate_user_cache(); |
---|
726 | logout_user(); |
---|
727 | redirect(make_index_url().'?UAM_msg=deleted', 0); |
---|
728 | } |
---|
729 | } |
---|
730 | else // Process if an admin or webmaster user is logged |
---|
731 | { |
---|
732 | foreach ($collection as $user_id) |
---|
733 | { |
---|
734 | // Check reminder state |
---|
735 | // -------------------- |
---|
736 | $query = ' |
---|
737 | SELECT reminder |
---|
738 | FROM '.USER_CONFIRM_MAIL_TABLE.' |
---|
739 | WHERE user_id = '.$user_id.';'; |
---|
740 | |
---|
741 | $result = pwg_db_fetch_assoc(pwg_query($query)); |
---|
742 | |
---|
743 | if (isset($result['reminder']) and $result['reminder'] == 'true') |
---|
744 | { |
---|
745 | $reminder = true; |
---|
746 | } |
---|
747 | else |
---|
748 | { |
---|
749 | $reminder = false; |
---|
750 | } |
---|
751 | |
---|
752 | // If never reminded before, send reminder and set reminder True |
---|
753 | // ------------------------------------------------------------- |
---|
754 | if (!$reminder and isset($conf_UAM['USRAUTOMAIL']) and $conf_UAM['USRAUTOMAIL'] == 'true') |
---|
755 | { |
---|
756 | $typemail = 1; |
---|
757 | |
---|
758 | // Get current user information |
---|
759 | // ---------------------------- |
---|
760 | $query = ' |
---|
761 | SELECT id, username, mail_address |
---|
762 | FROM '.USERS_TABLE.' |
---|
763 | WHERE id = '.$user_id.' |
---|
764 | ;'; |
---|
765 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
766 | |
---|
767 | ResendMail2User($typemail,$user_id,stripslashes($data['username']),$data['mail_address'],true); |
---|
768 | } |
---|
769 | elseif ($reminder) // If user already reminded for account validation |
---|
770 | { |
---|
771 | // Delete account |
---|
772 | // -------------- |
---|
773 | delete_user($user_id); |
---|
774 | } |
---|
775 | } |
---|
776 | } |
---|
777 | } |
---|
778 | } |
---|
779 | } |
---|
780 | |
---|
781 | |
---|
782 | /** |
---|
783 | * Triggered on init |
---|
784 | * |
---|
785 | * Check for forbidden email domains in admin's users management panel |
---|
786 | */ |
---|
787 | function UAM_InitPage() |
---|
788 | { |
---|
789 | load_language('plugin.lang', UAM_PATH); |
---|
790 | global $conf, $template, $page, $lang, $errors; |
---|
791 | |
---|
792 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
793 | |
---|
794 | // Admin user management |
---|
795 | // --------------------- |
---|
796 | if (script_basename() == 'admin' and isset($_GET['page']) and $_GET['page'] == 'user_list') |
---|
797 | { |
---|
798 | if (isset($_POST['submit_add'])) |
---|
799 | { |
---|
800 | // Email without forbidden domains |
---|
801 | // ------------------------------- |
---|
802 | if (isset($conf_UAM['MAILEXCLUSION']) and $conf_UAM['MAILEXCLUSION'] == 'true' and !empty($_POST['email']) and ValidateEmailProvider($_POST['email'])) |
---|
803 | { |
---|
804 | $template->append('errors', l10n('UAM_reg_err_login5')."'".$conf_UAM['MAILEXCLUSION_LIST']."'"); |
---|
805 | unset($_POST['submit_add']); |
---|
806 | } |
---|
807 | } |
---|
808 | } |
---|
809 | if( isset($_GET['UAM_msg'])) |
---|
810 | { |
---|
811 | UAM_DisplayMsg(); |
---|
812 | } |
---|
813 | elseif (isset($_GET['key']) and isset($_GET['userid'])) |
---|
814 | { |
---|
815 | UAM_ConfirmMail(); |
---|
816 | } |
---|
817 | } |
---|
818 | |
---|
819 | |
---|
820 | /** |
---|
821 | * Triggered on init |
---|
822 | * |
---|
823 | * Display a message according to $_GET['UAM_msg'] |
---|
824 | */ |
---|
825 | function UAM_DisplayMsg() |
---|
826 | { |
---|
827 | if( isset($_GET['UAM_msg'])) |
---|
828 | { |
---|
829 | global $user, $lang, $conf, $page; |
---|
830 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
831 | |
---|
832 | // Connexion rejected until validation |
---|
833 | if (isset($conf_UAM['REJECTCONNECT_TEXT']) and !empty($conf_UAM['REJECTCONNECT_TEXT']) and $_GET['UAM_msg']=="rejected") |
---|
834 | { |
---|
835 | // Management of Extension flags ([mygallery], [myurl]) |
---|
836 | // --------------------------------------------------- |
---|
837 | $patterns[] = '#\[mygallery\]#i'; |
---|
838 | $replacements[] = $conf['gallery_title']; |
---|
839 | $patterns[] = '#\[myurl\]#i'; |
---|
840 | $replacements[] = get_gallery_home_url(); |
---|
841 | |
---|
842 | if (function_exists('get_user_language_desc')) |
---|
843 | { |
---|
844 | $custom_text = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM['REJECTCONNECT_TEXT'])); |
---|
845 | } |
---|
846 | else $custom_text = l10n(preg_replace($patterns, $replacements, $conf_UAM['REJECTCONNECT_TEXT'])); |
---|
847 | |
---|
848 | $page["errors"][]=$custom_text; |
---|
849 | } |
---|
850 | |
---|
851 | // User account deleted after validation deadline - Triggered by any other user |
---|
852 | elseif (isset($conf_UAM['GTAUTODEL']) and !empty($conf_UAM['GTAUTODEL']) and $_GET['UAM_msg']=="deleted") |
---|
853 | { |
---|
854 | // Management of Extension flags ([mygallery], [myurl]) - [username] flag can't be used here |
---|
855 | // ----------------------------------------------------------------------------------------- |
---|
856 | $patterns[] = '#\[mygallery\]#i'; |
---|
857 | $replacements[] = $conf['gallery_title']; |
---|
858 | $patterns[] = '#\[myurl\]#i'; |
---|
859 | $replacements[] = get_gallery_home_url(); |
---|
860 | |
---|
861 | if (function_exists('get_user_language_desc')) |
---|
862 | { |
---|
863 | $custom_text = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM['GTAUTODEL'])); |
---|
864 | } |
---|
865 | else $custom_text = l10n(preg_replace($patterns, $replacements, $conf_UAM['GTAUTODEL'])); |
---|
866 | |
---|
867 | $page["errors"][]=$custom_text; |
---|
868 | } |
---|
869 | |
---|
870 | // User account deleted after validation deadline - Triggered by user himself |
---|
871 | elseif (isset($conf_UAM['USRAUTODEL']) and !empty($conf_UAM['USRAUTODEL']) and $_GET['UAM_msg']=="deleted") |
---|
872 | { |
---|
873 | // Management of Extension flags ([mygallery], [myurl]) - [username] flag can't be used here |
---|
874 | // ----------------------------------------------------------------------------------------- |
---|
875 | $patterns[] = '#\[mygallery\]#i'; |
---|
876 | $replacements[] = $conf['gallery_title']; |
---|
877 | $patterns[] = '#\[myurl\]#i'; |
---|
878 | $replacements[] = get_gallery_home_url(); |
---|
879 | |
---|
880 | if (function_exists('get_user_language_desc')) |
---|
881 | { |
---|
882 | $custom_text = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM['USRAUTODEL'])); |
---|
883 | } |
---|
884 | else $custom_text = l10n(preg_replace($patterns, $replacements, $conf_UAM['USRAUTODEL'])); |
---|
885 | |
---|
886 | $page["errors"][]=$custom_text; |
---|
887 | } |
---|
888 | } |
---|
889 | } |
---|
890 | |
---|
891 | |
---|
892 | /** |
---|
893 | * Triggered on init |
---|
894 | * |
---|
895 | * Check the key and display a message |
---|
896 | */ |
---|
897 | function UAM_ConfirmMail() |
---|
898 | { |
---|
899 | global $conf; |
---|
900 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
901 | |
---|
902 | if (isset($_GET['key']) and isset($_GET['userid'])) |
---|
903 | { |
---|
904 | global $user, $lang, $conf, $page; |
---|
905 | |
---|
906 | $key = $_GET['key']; |
---|
907 | $userid = $_GET['userid']; |
---|
908 | |
---|
909 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
---|
910 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
911 | |
---|
912 | $query = ' |
---|
913 | SELECT '.USERS_TABLE.'.username |
---|
914 | FROM '.USERS_TABLE.' |
---|
915 | WHERE ('.USERS_TABLE.'.id ='.$userid.') |
---|
916 | ;'; |
---|
917 | $result = pwg_db_fetch_assoc(pwg_query($query)); |
---|
918 | |
---|
919 | if (VerifyConfirmMail($key)) |
---|
920 | { |
---|
921 | if (isset($conf_UAM['CONFIRM_MAIL']) and $conf_UAM['CONFIRM_MAIL'] == 'local') |
---|
922 | { |
---|
923 | validation_mail($userid); |
---|
924 | } |
---|
925 | // We have to get the user's language in database |
---|
926 | // ---------------------------------------------- |
---|
927 | $query = ' |
---|
928 | SELECT language |
---|
929 | FROM '.USER_INFOS_TABLE.' |
---|
930 | WHERE '.USER_INFOS_TABLE.'.user_id ='.$userid.' |
---|
931 | ;'; |
---|
932 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
933 | |
---|
934 | // Check if user is already registered (profile changing) - If not (new registration), language is set to current gallery language |
---|
935 | // ------------------------------------------------------------------------------------------------------------------------------- |
---|
936 | if (empty($data)) |
---|
937 | { |
---|
938 | // And switch gallery to this language before using personalized and multilangual contents |
---|
939 | // --------------------------------------------------------------------------------------- |
---|
940 | $language = pwg_get_session_var('lang_switch', $user['language']); |
---|
941 | switch_lang_to($language); |
---|
942 | } |
---|
943 | else |
---|
944 | { |
---|
945 | // And switch gallery to this language before using personalized and multilangual contents |
---|
946 | // --------------------------------------------------------------------------------------- |
---|
947 | switch_lang_to($data['language']); |
---|
948 | load_language('plugin.lang', UAM_PATH); |
---|
949 | } |
---|
950 | |
---|
951 | if (isset($conf_UAM_ConfirmMail['CONFIRMMAIL_CUSTOM_TXT1']) and !empty($conf_UAM_ConfirmMail['CONFIRMMAIL_CUSTOM_TXT1'])) |
---|
952 | { |
---|
953 | // Management of Extension flags ([username], [mygallery], [myurl]) |
---|
954 | // ---------------------------------------------------------------- |
---|
955 | $patterns[] = '#\[username\]#i'; |
---|
956 | $replacements[] = $result['username']; |
---|
957 | $patterns[] = '#\[mygallery\]#i'; |
---|
958 | $replacements[] = $conf['gallery_title']; |
---|
959 | $patterns[] = '#\[myurl\]#i'; |
---|
960 | $replacements[] = get_gallery_home_url(); |
---|
961 | |
---|
962 | if (function_exists('get_user_language_desc')) |
---|
963 | { |
---|
964 | $login_link = '<a href="'.get_gallery_home_url().'" style="font-weight: bold;text-align: center;color: #FF0000;text-transform: uppercase;">'.l10n('UAM_Follow this link to access the gallery').'</a>'; |
---|
965 | $custom_text = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM_ConfirmMail['CONFIRMMAIL_CUSTOM_TXT1']))."<br/><br/>".$login_link; |
---|
966 | } |
---|
967 | else |
---|
968 | { |
---|
969 | $custom_text = l10n(preg_replace($patterns, $replacements, $conf_UAM_ConfirmMail['CONFIRMMAIL_CUSTOM_TXT1'])); |
---|
970 | } |
---|
971 | $page['infos'][]=$custom_text; |
---|
972 | } |
---|
973 | } |
---|
974 | else |
---|
975 | { |
---|
976 | if (isset($conf_UAM_ConfirmMail['CONFIRMMAIL_CUSTOM_TXT2']) and !empty($conf_UAM_ConfirmMail['CONFIRMMAIL_CUSTOM_TXT2'])) |
---|
977 | { |
---|
978 | // Management of Extension flags ([username], [mygallery], [myurl]) |
---|
979 | // ---------------------------------------------------------------- |
---|
980 | $patterns[] = '#\[username\]#i'; |
---|
981 | $replacements[] = $result['username']; |
---|
982 | $patterns[] = '#\[mygallery\]#i'; |
---|
983 | $replacements[] = $conf['gallery_title']; |
---|
984 | $patterns[] = '#\[myurl\]#i'; |
---|
985 | $replacements[] = get_gallery_home_url(); |
---|
986 | |
---|
987 | if (function_exists('get_user_language_desc')) |
---|
988 | { |
---|
989 | $custom_text = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM_ConfirmMail['CONFIRMMAIL_CUSTOM_TXT2'])); |
---|
990 | } |
---|
991 | else |
---|
992 | { |
---|
993 | $custom_text = l10n(preg_replace($patterns, $replacements, $conf_UAM_ConfirmMail['CONFIRMMAIL_CUSTOM_TXT2'])); |
---|
994 | } |
---|
995 | |
---|
996 | $page['errors'][]=$custom_text; |
---|
997 | } |
---|
998 | } |
---|
999 | } |
---|
1000 | } |
---|
1001 | |
---|
1002 | |
---|
1003 | /** |
---|
1004 | * Triggered on render_lost_password_mail_content |
---|
1005 | * |
---|
1006 | * Adds a customized text in lost password email content |
---|
1007 | * Added text is inserted before users login name and new password |
---|
1008 | * |
---|
1009 | * @param : Standard Piwigo email content |
---|
1010 | * |
---|
1011 | * @return : Customized content added to standard content |
---|
1012 | * |
---|
1013 | */ |
---|
1014 | function UAM_lost_password_mail_content($infos) |
---|
1015 | { |
---|
1016 | global $conf; |
---|
1017 | |
---|
1018 | load_language('plugin.lang', UAM_PATH); |
---|
1019 | |
---|
1020 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1021 | |
---|
1022 | if (isset($conf_UAM['CUSTOMPASSWRETR']) and $conf_UAM['CUSTOMPASSWRETR'] == 'true') |
---|
1023 | { |
---|
1024 | // Management of Extension flags ([mygallery], [myurl]) |
---|
1025 | $patterns[] = '#\[mygallery\]#i'; |
---|
1026 | $replacements[] = $conf['gallery_title']; |
---|
1027 | $patterns[] = '#\[myurl\]#i'; |
---|
1028 | $replacements[] = get_gallery_home_url(); |
---|
1029 | |
---|
1030 | $infos = preg_replace($patterns, $replacements, $conf_UAM['CUSTOMPASSWRETR_TEXT'])."\n"."\n".$infos; |
---|
1031 | } |
---|
1032 | return $infos; |
---|
1033 | } |
---|
1034 | |
---|
1035 | |
---|
1036 | /** |
---|
1037 | * Function called from main.inc.php to send validation email |
---|
1038 | * |
---|
1039 | * @param : Type of email, user id, username, email address, confirmation (optional) |
---|
1040 | * |
---|
1041 | */ |
---|
1042 | function SendMail2User($typemail, $id, $username, $password, $email, $confirm) |
---|
1043 | { |
---|
1044 | global $conf; |
---|
1045 | |
---|
1046 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1047 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
---|
1048 | |
---|
1049 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
1050 | |
---|
1051 | $infos1_perso = ""; |
---|
1052 | $infos2_perso = ""; |
---|
1053 | $subject = ""; |
---|
1054 | |
---|
1055 | // We have to get the user's language in database |
---|
1056 | // ---------------------------------------------- |
---|
1057 | $query =' |
---|
1058 | SELECT user_id, language |
---|
1059 | FROM '.USER_INFOS_TABLE.' |
---|
1060 | WHERE user_id = '.$id.' |
---|
1061 | ;'; |
---|
1062 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
1063 | |
---|
1064 | // Check if user is already registered (profile changing) - If not (new registration), language is set to current gallery language |
---|
1065 | // ------------------------------------------------------------------------------------------------------------------------------- |
---|
1066 | if (empty($data)) |
---|
1067 | { |
---|
1068 | // And switch gallery to this language before using personalized and multilangual contents |
---|
1069 | // --------------------------------------------------------------------------------------- |
---|
1070 | $language = pwg_get_session_var( 'lang_switch', $user['language'] ); |
---|
1071 | switch_lang_to($language); |
---|
1072 | } |
---|
1073 | else |
---|
1074 | { |
---|
1075 | // And switch gallery to this language before using personalized and multilangual contents |
---|
1076 | // --------------------------------------------------------------------------------------- |
---|
1077 | //$language = $data['language']; // Usefull for debugging |
---|
1078 | switch_lang_to($data['language']); |
---|
1079 | load_language('plugin.lang', UAM_PATH); |
---|
1080 | } |
---|
1081 | |
---|
1082 | switch($typemail) |
---|
1083 | { |
---|
1084 | case 1: // Confirmation email on user registration - Without information email (already managed by Piwigo) |
---|
1085 | if (isset($conf_UAM['CONFIRMMAIL_SUBJECT']) and !empty($conf_UAM['CONFIRMMAIL_SUBJECT'])) |
---|
1086 | { |
---|
1087 | // Management of Extension flags ([username], [mygallery]) |
---|
1088 | // ------------------------------------------------------- |
---|
1089 | $patterns[] = '#\[username\]#i'; |
---|
1090 | $replacements[] = $username; |
---|
1091 | $patterns[] = '#\[mygallery\]#i'; |
---|
1092 | $replacements[] = $conf['gallery_title']; |
---|
1093 | |
---|
1094 | if (function_exists('get_user_language_desc')) |
---|
1095 | { |
---|
1096 | $subject = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM['CONFIRMMAIL_SUBJECT']))."\n\n"; |
---|
1097 | } |
---|
1098 | else $subject = l10n(preg_replace($patterns, $replacements, $conf_UAM['CONFIRMMAIL_SUBJECT']))."\n\n"; |
---|
1099 | } |
---|
1100 | |
---|
1101 | break; |
---|
1102 | |
---|
1103 | case 2: // Confirmation email on user profile update - Information email if modification done in user profile |
---|
1104 | if (isset($conf_UAM['INFOMAIL_SUBJECT']) and !empty($conf_UAM['INFOMAIL_SUBJECT'])) |
---|
1105 | { |
---|
1106 | // Management of Extension flags ([username], [mygallery]) |
---|
1107 | // ------------------------------------------------------- |
---|
1108 | $patterns[] = '#\[username\]#i'; |
---|
1109 | $replacements[] = $username; |
---|
1110 | $patterns[] = '#\[mygallery\]#i'; |
---|
1111 | $replacements[] = $conf['gallery_title']; |
---|
1112 | |
---|
1113 | if (function_exists('get_user_language_desc')) |
---|
1114 | { |
---|
1115 | $subject = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM['INFOMAIL_SUBJECT']))."\n\n"; |
---|
1116 | } |
---|
1117 | else $subject = l10n(preg_replace($patterns, $replacements, $conf_UAM['INFOMAIL_SUBJECT']))."\n\n"; |
---|
1118 | } |
---|
1119 | |
---|
1120 | $password = !empty($password) ? $password : l10n('UAM_no_update_pwd'); |
---|
1121 | |
---|
1122 | if (isset($conf_UAM['MAILINFO_TEXT']) and !empty($conf_UAM['MAILINFO_TEXT'])) |
---|
1123 | { |
---|
1124 | // Management of Extension flags ([username], [mygallery], [myurl]) |
---|
1125 | // ---------------------------------------------------------------- |
---|
1126 | $patterns[] = '#\[username\]#i'; |
---|
1127 | $replacements[] = $username; |
---|
1128 | $patterns[] = '#\[mygallery\]#i'; |
---|
1129 | $replacements[] = $conf['gallery_title']; |
---|
1130 | $patterns[] = '#\[myurl\]#i'; |
---|
1131 | $replacements[] = get_gallery_home_url(); |
---|
1132 | |
---|
1133 | if (function_exists('get_user_language_desc')) |
---|
1134 | { |
---|
1135 | $infos1_perso = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM['MAILINFO_TEXT']))."\n\n"; |
---|
1136 | } |
---|
1137 | else $infos1_perso = l10n(preg_replace($patterns, $replacements, $conf_UAM['MAILINFO_TEXT']))."\n\n"; |
---|
1138 | } |
---|
1139 | |
---|
1140 | if (isset($conf_UAM['MAIL_INFO']) and $conf_UAM['MAIL_INFO'] == 'true') |
---|
1141 | { |
---|
1142 | if (isset($conf_UAM['HIDEPASSW']) and $conf_UAM['HIDEPASSW'] == 'true') // Allow display of clear password in email |
---|
1143 | { |
---|
1144 | $infos1 = array( |
---|
1145 | get_l10n_args('UAM_infos_mail %s', stripslashes($username)), |
---|
1146 | get_l10n_args('UAM_User: %s', stripslashes($username)), |
---|
1147 | get_l10n_args('UAM_Password: %s', $password), |
---|
1148 | get_l10n_args('Email: %s', $email), |
---|
1149 | get_l10n_args('', ''), |
---|
1150 | ); |
---|
1151 | } |
---|
1152 | else // Do not allow display of clear password in email |
---|
1153 | { |
---|
1154 | $infos1 = array( |
---|
1155 | get_l10n_args('UAM_infos_mail %s', stripslashes($username)), |
---|
1156 | get_l10n_args('UAM_User: %s', stripslashes($username)), |
---|
1157 | get_l10n_args('Email: %s', $email), |
---|
1158 | get_l10n_args('', ''), |
---|
1159 | ); |
---|
1160 | } |
---|
1161 | } |
---|
1162 | |
---|
1163 | break; |
---|
1164 | } |
---|
1165 | |
---|
1166 | if ((isset($conf_UAM['CONFIRM_MAIL']) and ($conf_UAM['CONFIRM_MAIL'] == 'true')) and $confirm) // Add confirmation link ? |
---|
1167 | { |
---|
1168 | $infos2 = array( |
---|
1169 | get_l10n_args('UAM_Link: %s', AddConfirmMail($id, $email)), |
---|
1170 | get_l10n_args('', ''), |
---|
1171 | ); |
---|
1172 | |
---|
1173 | if (isset($conf_UAM['CONFIRMMAIL_TEXT']) and !empty($conf_UAM['CONFIRMMAIL_TEXT'])) // Add personal text in confirmation email ? |
---|
1174 | { |
---|
1175 | // Management of Extension flags ([username], [mygallery], [myurl], [Kdays]) |
---|
1176 | // ------------------------------------------------------------------------- |
---|
1177 | $patterns[] = '#\[username\]#i'; |
---|
1178 | $replacements[] = $username; |
---|
1179 | $patterns[] = '#\[mygallery\]#i'; |
---|
1180 | $replacements[] = $conf['gallery_title']; |
---|
1181 | $patterns[] = '#\[myurl\]#i'; |
---|
1182 | $replacements[] = get_gallery_home_url(); |
---|
1183 | |
---|
1184 | if (isset($conf_UAM_ConfirmMail['CONFIRMMAIL_TIMEOUT']) and $conf_UAM_ConfirmMail['CONFIRMMAIL_TIMEOUT'] == 'true') // [Kdays] replacement only if related option is active |
---|
1185 | { |
---|
1186 | $patterns[] = '#\[Kdays\]#i'; |
---|
1187 | $replacements[] = $conf_UAM_ConfirmMail['CONFIRMMAIL_DELAY']; |
---|
1188 | } |
---|
1189 | |
---|
1190 | if (function_exists('get_user_language_desc')) |
---|
1191 | { |
---|
1192 | $infos2_perso = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM['CONFIRMMAIL_TEXT']))."\n\n"; |
---|
1193 | } |
---|
1194 | else $infos2_perso = l10n(preg_replace($patterns, $replacements, $conf_UAM['CONFIRMMAIL_TEXT']))."\n\n"; |
---|
1195 | } |
---|
1196 | } |
---|
1197 | |
---|
1198 | |
---|
1199 | // Sending the email with subject and contents |
---|
1200 | // ------------------------------------------- |
---|
1201 | |
---|
1202 | if ((isset($conf_UAM['CONFIRM_MAIL']) and $conf_UAM['CONFIRM_MAIL'] == 'local') and $confirm) // Confirmation email send to admins |
---|
1203 | { |
---|
1204 | switch_lang_to(get_default_language()); |
---|
1205 | |
---|
1206 | load_language('plugin.lang', UAM_PATH); |
---|
1207 | $subject_admin = get_l10n_args('UAM_Subject admin validation for %s',$username); |
---|
1208 | |
---|
1209 | $content_admin = array( |
---|
1210 | get_l10n_args('UAM_Manual_validation_needed_for %s', stripslashes($username)), |
---|
1211 | get_l10n_args('', ''), |
---|
1212 | get_l10n_args('UAM_Link: %s', AddConfirmMail($id, $email)), |
---|
1213 | ); |
---|
1214 | |
---|
1215 | pwg_mail_notification_admins($subject_admin, $content_admin, true); |
---|
1216 | } |
---|
1217 | |
---|
1218 | |
---|
1219 | if (isset($conf_UAM['CONFIRM_MAIL']) and $conf_UAM['CONFIRM_MAIL'] == 'true' and $confirm) // Confirmation email send to users |
---|
1220 | { |
---|
1221 | // Adding gallery URL at the end of the email |
---|
1222 | if (isset($conf_UAM['ADD_GALLERY_URL_TO_EMAILS']) and $conf_UAM['ADD_GALLERY_URL_TO_EMAILS'] == 'true') |
---|
1223 | { |
---|
1224 | $content_confirmation = (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "").get_absolute_root_url(); |
---|
1225 | |
---|
1226 | pwg_mail( |
---|
1227 | array( |
---|
1228 | 'name' => stripslashes($username), |
---|
1229 | 'email' => $email, |
---|
1230 | ), |
---|
1231 | array( |
---|
1232 | 'content' => $content_confirmation, |
---|
1233 | 'content_format' => 'text/plain', |
---|
1234 | 'subject' => $subject, |
---|
1235 | ) |
---|
1236 | ); |
---|
1237 | } |
---|
1238 | // Do not add gallery URL at the end of the email |
---|
1239 | elseif (isset($conf_UAM['ADD_GALLERY_URL_TO_EMAILS']) and $conf_UAM['ADD_GALLERY_URL_TO_EMAILS'] == 'false') |
---|
1240 | { |
---|
1241 | $content_confirmation = (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : ""); |
---|
1242 | |
---|
1243 | pwg_mail( |
---|
1244 | array( |
---|
1245 | 'name' => stripslashes($username), |
---|
1246 | 'email' => $email, |
---|
1247 | ), |
---|
1248 | array( |
---|
1249 | 'content' => $content_confirmation, |
---|
1250 | 'content_format' => 'text/plain', |
---|
1251 | 'subject' => $subject, |
---|
1252 | ) |
---|
1253 | ); |
---|
1254 | } |
---|
1255 | // By default do not add gallery URL at the end of the email |
---|
1256 | else |
---|
1257 | { |
---|
1258 | $content_confirmation = (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : ""); |
---|
1259 | |
---|
1260 | pwg_mail( |
---|
1261 | array( |
---|
1262 | 'name' => stripslashes($username), |
---|
1263 | 'email' => $email, |
---|
1264 | ), |
---|
1265 | array( |
---|
1266 | 'content' => $content_confirmation, |
---|
1267 | 'content_format' => 'text/plain', |
---|
1268 | 'subject' => $subject, |
---|
1269 | ) |
---|
1270 | ); |
---|
1271 | } |
---|
1272 | } |
---|
1273 | |
---|
1274 | |
---|
1275 | if (isset($conf_UAM['MAIL_INFO']) and $conf_UAM['MAIL_INFO'] == 'true') // Information email send to users |
---|
1276 | { |
---|
1277 | // Adding gallery URL at the end of the email |
---|
1278 | if (isset($conf_UAM['ADD_GALLERY_URL_TO_EMAILS']) and $conf_UAM['ADD_GALLERY_URL_TO_EMAILS'] == 'true') |
---|
1279 | { |
---|
1280 | $content_info = (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "").get_absolute_root_url(); |
---|
1281 | |
---|
1282 | pwg_mail( |
---|
1283 | array( |
---|
1284 | 'name' => stripslashes($username), |
---|
1285 | 'email' => $email, |
---|
1286 | ), |
---|
1287 | array( |
---|
1288 | 'content' => $content_info, |
---|
1289 | 'content_format' => 'text/plain', |
---|
1290 | 'subject' => $subject, |
---|
1291 | ) |
---|
1292 | ); |
---|
1293 | } |
---|
1294 | // Do not add gallery URL at the end of the email |
---|
1295 | elseif (isset($conf_UAM['ADD_GALLERY_URL_TO_EMAILS']) and $conf_UAM['ADD_GALLERY_URL_TO_EMAILS'] == 'false') |
---|
1296 | { |
---|
1297 | $content_info = (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : ""); |
---|
1298 | |
---|
1299 | pwg_mail( |
---|
1300 | array( |
---|
1301 | 'name' => stripslashes($username), |
---|
1302 | 'email' => $email, |
---|
1303 | ), |
---|
1304 | array( |
---|
1305 | 'content' => $content_info, |
---|
1306 | 'content_format' => 'text/plain', |
---|
1307 | 'subject' => $subject, |
---|
1308 | ) |
---|
1309 | ); |
---|
1310 | } |
---|
1311 | // By default do not add gallery URL at the end of the email |
---|
1312 | else |
---|
1313 | { |
---|
1314 | $content_info = (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : ""); |
---|
1315 | |
---|
1316 | pwg_mail( |
---|
1317 | array( |
---|
1318 | 'name' => stripslashes($username), |
---|
1319 | 'email' => $email, |
---|
1320 | ), |
---|
1321 | array( |
---|
1322 | 'content' => $content_info, |
---|
1323 | 'content_format' => 'text/plain', |
---|
1324 | 'subject' => $subject, |
---|
1325 | ) |
---|
1326 | ); |
---|
1327 | } |
---|
1328 | } |
---|
1329 | // Switching back to default language |
---|
1330 | // ---------------------------------- |
---|
1331 | switch_lang_back(); |
---|
1332 | } |
---|
1333 | |
---|
1334 | |
---|
1335 | /** |
---|
1336 | * Function called from UAM_admin.php to resend validation email with or without new validation key |
---|
1337 | * |
---|
1338 | * @param : Type of email, user id, username, email address, confirmation (optional) |
---|
1339 | * |
---|
1340 | */ |
---|
1341 | function ResendMail2User($typemail, $user_id, $username, $email, $confirm) |
---|
1342 | { |
---|
1343 | global $conf; |
---|
1344 | |
---|
1345 | $subject = ""; |
---|
1346 | |
---|
1347 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1348 | |
---|
1349 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
---|
1350 | |
---|
1351 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
1352 | |
---|
1353 | // We have to get the user's language in database |
---|
1354 | // ---------------------------------------------- |
---|
1355 | $query =' |
---|
1356 | SELECT user_id, language |
---|
1357 | FROM '.USER_INFOS_TABLE.' |
---|
1358 | WHERE user_id = '.$user_id.' |
---|
1359 | ;'; |
---|
1360 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
1361 | $language = $data['language']; |
---|
1362 | |
---|
1363 | // And switch gallery to this language before using personalized and multilangual contents |
---|
1364 | // --------------------------------------------------------------------------------------- |
---|
1365 | switch_lang_to($data['language']); |
---|
1366 | |
---|
1367 | load_language('plugin.lang', UAM_PATH); |
---|
1368 | |
---|
1369 | switch($typemail) |
---|
1370 | { |
---|
1371 | case 1: //Generating email content for remind with a new key |
---|
1372 | if (isset($conf_UAM['CONFIRMMAIL_REMAIL_SUBJECT']) and !empty($conf_UAM['CONFIRMMAIL_REMAIL_SUBJECT'])) |
---|
1373 | { |
---|
1374 | // Management of Extension flags ([username], [mygallery]) |
---|
1375 | // ------------------------------------------------------- |
---|
1376 | $patterns[] = '#\[username\]#i'; |
---|
1377 | $replacements[] = $username; |
---|
1378 | $patterns[] = '#\[mygallery\]#i'; |
---|
1379 | $replacements[] = $conf['gallery_title']; |
---|
1380 | |
---|
1381 | if (function_exists('get_user_language_desc')) |
---|
1382 | { |
---|
1383 | $subject = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM['CONFIRMMAIL_REMAIL_SUBJECT']))."\n\n"; |
---|
1384 | } |
---|
1385 | else $subject = l10n(preg_replace($patterns, $replacements, $conf_UAM['CONFIRMMAIL_REMAIL_SUBJECT']))."\n\n"; |
---|
1386 | } |
---|
1387 | |
---|
1388 | if (isset($conf_UAM_ConfirmMail['CONFIRMMAIL_REMAIL_TXT1']) and !empty($conf_UAM_ConfirmMail['CONFIRMMAIL_REMAIL_TXT1']) and isset($conf_UAM_ConfirmMail['CONFIRMMAIL_REMAIL']) and $conf_UAM_ConfirmMail['CONFIRMMAIL_REMAIL'] == 'true' and $confirm) |
---|
1389 | { |
---|
1390 | // Management of Extension flags ([username], [mygallery], [myurl], [Kdays]) |
---|
1391 | // ------------------------------------------------------------------------- |
---|
1392 | $patterns[] = '#\[username\]#i'; |
---|
1393 | $replacements[] = $username; |
---|
1394 | $patterns[] = '#\[mygallery\]#i'; |
---|
1395 | $replacements[] = $conf['gallery_title']; |
---|
1396 | $patterns[] = '#\[myurl\]#i'; |
---|
1397 | $replacements[] = get_gallery_home_url(); |
---|
1398 | |
---|
1399 | if (isset($conf_UAM_ConfirmMail['CONFIRMMAIL_TIMEOUT']) and $conf_UAM_ConfirmMail['CONFIRMMAIL_TIMEOUT'] == 'true') // [Kdays] replacement only if related option is active |
---|
1400 | { |
---|
1401 | $patterns[] = '#\[Kdays\]#i'; |
---|
1402 | $replacements[] = $conf_UAM_ConfirmMail['CONFIRMMAIL_DELAY']; |
---|
1403 | } |
---|
1404 | |
---|
1405 | if (function_exists('get_user_language_desc')) |
---|
1406 | { |
---|
1407 | $infos1 = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM_ConfirmMail['CONFIRMMAIL_REMAIL_TXT1']))."\n\n"; |
---|
1408 | } |
---|
1409 | else $infos1 = l10n(preg_replace($patterns, $replacements, $conf_UAM_ConfirmMail['CONFIRMMAIL_REMAIL_TXT1']))."\n\n"; |
---|
1410 | |
---|
1411 | $infos2 = array |
---|
1412 | ( |
---|
1413 | get_l10n_args('UAM_Link: %s', ResetConfirmMail($user_id)), |
---|
1414 | get_l10n_args('', ''), |
---|
1415 | ); |
---|
1416 | } |
---|
1417 | |
---|
1418 | // Set reminder true |
---|
1419 | // ----------------- |
---|
1420 | $query = ' |
---|
1421 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
1422 | SET reminder = "true" |
---|
1423 | WHERE user_id = '.$user_id.' |
---|
1424 | ;'; |
---|
1425 | pwg_query($query); |
---|
1426 | |
---|
1427 | break; |
---|
1428 | |
---|
1429 | case 2: //Generating email content for remind without a new key |
---|
1430 | if (isset($conf_UAM['CONFIRMMAIL_REMAIL_SUBJECT']) and !empty($conf_UAM['CONFIRMMAIL_REMAIL_SUBJECT'])) |
---|
1431 | { |
---|
1432 | // Management of Extension flags ([username], [mygallery]) |
---|
1433 | // ------------------------------------------------------- |
---|
1434 | $patterns[] = '#\[username\]#i'; |
---|
1435 | $replacements[] = $username; |
---|
1436 | $patterns[] = '#\[mygallery\]#i'; |
---|
1437 | $replacements[] = $conf['gallery_title']; |
---|
1438 | |
---|
1439 | if (function_exists('get_user_language_desc')) |
---|
1440 | { |
---|
1441 | $subject = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM['CONFIRMMAIL_REMAIL_SUBJECT']))."\n\n"; |
---|
1442 | } |
---|
1443 | else $subject = l10n(preg_replace($patterns, $replacements, $conf_UAM['CONFIRMMAIL_REMAIL_SUBJECT']))."\n\n"; |
---|
1444 | } |
---|
1445 | |
---|
1446 | if (isset($conf_UAM_ConfirmMail['CONFIRMMAIL_REMAIL_TXT2']) and !empty($conf_UAM_ConfirmMail['CONFIRMMAIL_REMAIL_TXT2']) and isset($conf_UAM_ConfirmMail['CONFIRMMAIL_REMAIL']) and $conf_UAM_ConfirmMail['CONFIRMMAIL_REMAIL'] == 'true' and !$confirm) |
---|
1447 | { |
---|
1448 | // Management of Extension flags ([username], [mygallery], [myurl], [Kdays]) |
---|
1449 | // ------------------------------------------------------------------------- |
---|
1450 | $patterns[] = '#\[username\]#i'; |
---|
1451 | $replacements[] = $username; |
---|
1452 | $patterns[] = '#\[mygallery\]#i'; |
---|
1453 | $replacements[] = $conf['gallery_title']; |
---|
1454 | $patterns[] = '#\[myurl\]#i'; |
---|
1455 | $replacements[] = get_gallery_home_url(); |
---|
1456 | |
---|
1457 | if (isset($conf_UAM_ConfirmMail['CONFIRMMAIL_TIMEOUT']) and $conf_UAM_ConfirmMail['CONFIRMMAIL_TIMEOUT'] == 'true') // [Kdays] replacement only if related option is active |
---|
1458 | { |
---|
1459 | $patterns[] = '#\[Kdays\]#i'; |
---|
1460 | $replacements[] = $conf_UAM_ConfirmMail['CONFIRMMAIL_DELAY']; |
---|
1461 | } |
---|
1462 | |
---|
1463 | if (function_exists('get_user_language_desc')) |
---|
1464 | { |
---|
1465 | $infos1 = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM_ConfirmMail['CONFIRMMAIL_REMAIL_TXT2']))."\n\n"; |
---|
1466 | } |
---|
1467 | else $infos1 = l10n(preg_replace($patterns, $replacements, $conf_UAM_ConfirmMail['CONFIRMMAIL_REMAIL_TXT2']))."\n\n"; |
---|
1468 | } |
---|
1469 | |
---|
1470 | // Set reminder true |
---|
1471 | // ----------------- |
---|
1472 | $query = ' |
---|
1473 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
1474 | SET reminder = "true" |
---|
1475 | WHERE user_id = '.$user_id.' |
---|
1476 | ;'; |
---|
1477 | pwg_query($query); |
---|
1478 | |
---|
1479 | break; |
---|
1480 | } |
---|
1481 | |
---|
1482 | // Adding gallery URL at the end of the email |
---|
1483 | if (isset($conf_UAM['ADD_GALLERY_URL_TO_EMAILS']) and $conf_UAM['ADD_GALLERY_URL_TO_EMAILS'] == 'true') |
---|
1484 | { |
---|
1485 | $content = ($infos1."\n\n").(isset($infos2) ? l10n_args($infos2)."\n\n" : "").get_absolute_root_url(); |
---|
1486 | |
---|
1487 | pwg_mail( |
---|
1488 | array( |
---|
1489 | 'name' => stripslashes($username), |
---|
1490 | 'email' => $email, |
---|
1491 | ), |
---|
1492 | array( |
---|
1493 | 'content' => $content, |
---|
1494 | 'content_format' => 'text/plain', |
---|
1495 | 'subject' => $subject, |
---|
1496 | ) |
---|
1497 | ); |
---|
1498 | } |
---|
1499 | // Do not add gallery URL at the end of the email |
---|
1500 | elseif (isset($conf_UAM['ADD_GALLERY_URL_TO_EMAILS']) and $conf_UAM['ADD_GALLERY_URL_TO_EMAILS'] == 'false') |
---|
1501 | { |
---|
1502 | $content = ($infos1."\n\n").(isset($infos2) ? l10n_args($infos2)."\n\n" : ""); |
---|
1503 | |
---|
1504 | pwg_mail( |
---|
1505 | array( |
---|
1506 | 'name' => stripslashes($username), |
---|
1507 | 'email' => $email, |
---|
1508 | ), |
---|
1509 | array( |
---|
1510 | 'content' => $content, |
---|
1511 | 'content_format' => 'text/plain', |
---|
1512 | 'subject' => $subject, |
---|
1513 | ) |
---|
1514 | ); |
---|
1515 | } |
---|
1516 | // By default do not add gallery URL at the end of the email |
---|
1517 | else |
---|
1518 | { |
---|
1519 | $content = ($infos1."\n\n").(isset($infos2) ? l10n_args($infos2)."\n\n" : ""); |
---|
1520 | |
---|
1521 | pwg_mail( |
---|
1522 | array( |
---|
1523 | 'name' => stripslashes($username), |
---|
1524 | 'email' => $email, |
---|
1525 | ), |
---|
1526 | array( |
---|
1527 | 'content' => $content, |
---|
1528 | 'content_format' => 'text/plain', |
---|
1529 | 'subject' => $subject, |
---|
1530 | ) |
---|
1531 | ); |
---|
1532 | } |
---|
1533 | |
---|
1534 | // Switching back to default language |
---|
1535 | // ---------------------------------- |
---|
1536 | switch_lang_back(); |
---|
1537 | } |
---|
1538 | |
---|
1539 | |
---|
1540 | /** |
---|
1541 | * Function called from UAM_admin.php to send a reminder mail for ghost users |
---|
1542 | * |
---|
1543 | * @param : User id, username, email address |
---|
1544 | * |
---|
1545 | */ |
---|
1546 | function ghostreminder($user_id, $username, $email) |
---|
1547 | { |
---|
1548 | global $conf; |
---|
1549 | |
---|
1550 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1551 | $subject = ""; |
---|
1552 | |
---|
1553 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
1554 | |
---|
1555 | // We have to get the user's language in database |
---|
1556 | // ---------------------------------------------- |
---|
1557 | $query =' |
---|
1558 | SELECT user_id, language |
---|
1559 | FROM '.USER_INFOS_TABLE.' |
---|
1560 | WHERE user_id = '.$user_id.' |
---|
1561 | ;'; |
---|
1562 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
1563 | $language = $data['language']; |
---|
1564 | |
---|
1565 | // And switch gallery to this language before using personalized and multilangual contents |
---|
1566 | // --------------------------------------------------------------------------------------- |
---|
1567 | switch_lang_to($data['language']); |
---|
1568 | |
---|
1569 | load_language('plugin.lang', UAM_PATH); |
---|
1570 | |
---|
1571 | if (isset($conf_UAM['GTREMINDER_SUBJECT']) and !empty($conf_UAM['GTREMINDER_SUBJECT'])) |
---|
1572 | { |
---|
1573 | // Management of Extension flags ([username], [mygallery]) |
---|
1574 | // ------------------------------------------------------- |
---|
1575 | $patterns[] = '#\[username\]#i'; |
---|
1576 | $replacements[] = $username; |
---|
1577 | $patterns[] = '#\[mygallery\]#i'; |
---|
1578 | $replacements[] = $conf['gallery_title']; |
---|
1579 | |
---|
1580 | if (function_exists('get_user_language_desc')) |
---|
1581 | { |
---|
1582 | $subject = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM['GTREMINDER_SUBJECT']))."\n\n"; |
---|
1583 | } |
---|
1584 | else $subject = l10n(preg_replace($patterns, $replacements, $conf_UAM['GTREMINDER_SUBJECT']))."\n\n"; |
---|
1585 | } |
---|
1586 | |
---|
1587 | if (isset($conf_UAM['GHOSTRACKER_REMINDERTEXT']) and !empty($conf_UAM['GHOSTRACKER_REMINDERTEXT']) and isset($conf_UAM['GHOSTRACKER']) and $conf_UAM['GHOSTRACKER'] == 'true') |
---|
1588 | { |
---|
1589 | // Management of Extension flags ([username], [mygallery], [myurl], [days]) |
---|
1590 | // ------------------------------------------------------------------------ |
---|
1591 | $patterns[] = '#\[username\]#i'; |
---|
1592 | $replacements[] = $username; |
---|
1593 | $patterns[] = '#\[mygallery\]#i'; |
---|
1594 | $replacements[] = $conf['gallery_title']; |
---|
1595 | $patterns[] = '#\[myurl\]#i'; |
---|
1596 | $replacements[] = get_gallery_home_url(); |
---|
1597 | $patterns[] = '#\[days\]#i'; |
---|
1598 | $replacements[] = $conf_UAM['GHOSTRACKER_DAYLIMIT']; |
---|
1599 | |
---|
1600 | if (function_exists('get_user_language_desc')) |
---|
1601 | { |
---|
1602 | $infos1 = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM['GHOSTRACKER_REMINDERTEXT']))."\n\n"; |
---|
1603 | } |
---|
1604 | else |
---|
1605 | { |
---|
1606 | $infos1 = l10n(preg_replace($patterns, $replacements, $conf_UAM['GHOSTRACKER_REMINDERTEXT']))."\n\n"; |
---|
1607 | } |
---|
1608 | |
---|
1609 | resetlastvisit($user_id); |
---|
1610 | } |
---|
1611 | |
---|
1612 | // Adding gallery URL at the end of the email |
---|
1613 | if (isset($conf_UAM['ADD_GALLERY_URL_TO_EMAILS']) and $conf_UAM['ADD_GALLERY_URL_TO_EMAILS'] == 'true') |
---|
1614 | { |
---|
1615 | $content = $infos1.get_absolute_root_url(); |
---|
1616 | |
---|
1617 | pwg_mail( |
---|
1618 | array( |
---|
1619 | 'name' => stripslashes($username), |
---|
1620 | 'email' => $email, |
---|
1621 | ), |
---|
1622 | array( |
---|
1623 | 'content' => $content, |
---|
1624 | 'content_format' => 'text/plain', |
---|
1625 | 'subject' => $subject, |
---|
1626 | ) |
---|
1627 | ); |
---|
1628 | } |
---|
1629 | // Do not add gallery URL at the end of the email |
---|
1630 | elseif (isset($conf_UAM['ADD_GALLERY_URL_TO_EMAILS']) and $conf_UAM['ADD_GALLERY_URL_TO_EMAILS'] == 'false') |
---|
1631 | { |
---|
1632 | $content = $infos1; |
---|
1633 | |
---|
1634 | pwg_mail( |
---|
1635 | array( |
---|
1636 | 'name' => stripslashes($username), |
---|
1637 | 'email' => $email, |
---|
1638 | ), |
---|
1639 | array( |
---|
1640 | 'content' => $content, |
---|
1641 | 'content_format' => 'text/plain', |
---|
1642 | 'subject' => $subject, |
---|
1643 | ) |
---|
1644 | ); |
---|
1645 | } |
---|
1646 | // By default do not add gallery URL at the end of the email |
---|
1647 | else |
---|
1648 | { |
---|
1649 | $content = $infos1; |
---|
1650 | |
---|
1651 | pwg_mail( |
---|
1652 | array( |
---|
1653 | 'name' => stripslashes($username), |
---|
1654 | 'email' => $email, |
---|
1655 | ), |
---|
1656 | array( |
---|
1657 | 'content' => $content, |
---|
1658 | 'content_format' => 'text/plain', |
---|
1659 | 'subject' => $subject, |
---|
1660 | ) |
---|
1661 | ); |
---|
1662 | } |
---|
1663 | |
---|
1664 | // Switching back to default language |
---|
1665 | // ---------------------------------- |
---|
1666 | switch_lang_back(); |
---|
1667 | } |
---|
1668 | |
---|
1669 | |
---|
1670 | /** |
---|
1671 | * Function called from functions.inc.php to send notification email when user have been downgraded |
---|
1672 | * |
---|
1673 | * @param : user id, username, email address |
---|
1674 | * |
---|
1675 | */ |
---|
1676 | function demotion_mail($id, $username, $email) |
---|
1677 | { |
---|
1678 | global $conf; |
---|
1679 | |
---|
1680 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1681 | |
---|
1682 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
1683 | |
---|
1684 | $custom_txt = ""; |
---|
1685 | $subject = ""; |
---|
1686 | |
---|
1687 | // We have to get the user's language in database |
---|
1688 | // ---------------------------------------------- |
---|
1689 | $query = ' |
---|
1690 | SELECT user_id, language |
---|
1691 | FROM '.USER_INFOS_TABLE.' |
---|
1692 | WHERE user_id = '.$id.' |
---|
1693 | ;'; |
---|
1694 | |
---|
1695 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
1696 | |
---|
1697 | // Check if user is already registered (profile changing) - If not (new registration), language is set to current gallery language |
---|
1698 | // ------------------------------------------------------------------------------------------------------------------------------- |
---|
1699 | if (empty($data)) |
---|
1700 | { |
---|
1701 | // And switch gallery to this language before using personalized and multilangual contents |
---|
1702 | // --------------------------------------------------------------------------------------- |
---|
1703 | $language = pwg_get_session_var( 'lang_switch', $user['language'] ); |
---|
1704 | switch_lang_to($language); |
---|
1705 | } |
---|
1706 | else |
---|
1707 | { |
---|
1708 | // And switch gallery to this language before using personalized and multilangual contents |
---|
1709 | // --------------------------------------------------------------------------------------- |
---|
1710 | $language = $data['language']; // Usefull for debugging |
---|
1711 | switch_lang_to($data['language']); |
---|
1712 | load_language('plugin.lang', UAM_PATH); |
---|
1713 | } |
---|
1714 | |
---|
1715 | if (isset($conf_UAM['GTAUTOMAIL_SUBJECT']) and !empty($conf_UAM['GTAUTOMAIL_SUBJECT'])) |
---|
1716 | { |
---|
1717 | // Management of Extension flags ([username], [mygallery]) |
---|
1718 | // ------------------------------------------------------- |
---|
1719 | $patterns[] = '#\[username\]#i'; |
---|
1720 | $replacements[] = $username; |
---|
1721 | $patterns[] = '#\[mygallery\]#i'; |
---|
1722 | $replacements[] = $conf['gallery_title']; |
---|
1723 | |
---|
1724 | if (function_exists('get_user_language_desc')) |
---|
1725 | { |
---|
1726 | $subject = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM['GTAUTOMAIL_SUBJECT']))."\n\n"; |
---|
1727 | } |
---|
1728 | else $subject = l10n(preg_replace($patterns, $replacements, $conf_UAM['GTAUTOMAIL_SUBJECT']))."\n\n"; |
---|
1729 | } |
---|
1730 | |
---|
1731 | if (isset($conf_UAM['GTAUTOMAILTEXT']) and !empty($conf_UAM['GTAUTOMAILTEXT'])) |
---|
1732 | { |
---|
1733 | // Management of Extension flags ([username], [mygallery], [myurl]) |
---|
1734 | // ---------------------------------------------------------------- |
---|
1735 | $patterns[] = '#\[username\]#i'; |
---|
1736 | $replacements[] = stripslashes($username); |
---|
1737 | $patterns[] = '#\[mygallery\]#i'; |
---|
1738 | $replacements[] = $conf['gallery_title']; |
---|
1739 | $patterns[] = '#\[myurl\]#i'; |
---|
1740 | $replacements[] = get_gallery_home_url(); |
---|
1741 | |
---|
1742 | if (function_exists('get_user_language_desc')) |
---|
1743 | { |
---|
1744 | $custom_txt = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM['GTAUTOMAILTEXT']))."\n\n"; |
---|
1745 | } |
---|
1746 | else $custom_txt = l10n(preg_replace($patterns, $replacements, $conf_UAM['GTAUTOMAILTEXT']))."\n\n"; |
---|
1747 | } |
---|
1748 | |
---|
1749 | $infos1 = array( |
---|
1750 | get_l10n_args('UAM_User: %s', stripslashes($username)), |
---|
1751 | get_l10n_args('Email: %s', $email), |
---|
1752 | get_l10n_args('', ''), |
---|
1753 | ); |
---|
1754 | |
---|
1755 | $infos2 = array |
---|
1756 | ( |
---|
1757 | get_l10n_args('UAM_Link: %s', ResetConfirmMail($id)), |
---|
1758 | get_l10n_args('', ''), |
---|
1759 | ); |
---|
1760 | |
---|
1761 | resetlastvisit($id); |
---|
1762 | |
---|
1763 | // Sending the email with subject and contents |
---|
1764 | // ------------------------------------------- |
---|
1765 | // Adding gallery URL at the end of the email |
---|
1766 | if (isset($conf_UAM['ADD_GALLERY_URL_TO_EMAILS']) and $conf_UAM['ADD_GALLERY_URL_TO_EMAILS'] == 'true') |
---|
1767 | { |
---|
1768 | $content = ($custom_txt.l10n_args($infos1)."\n\n".l10n_args($infos2)."\n\n").get_absolute_root_url(); |
---|
1769 | |
---|
1770 | pwg_mail( |
---|
1771 | array( |
---|
1772 | 'name' => stripslashes($username), |
---|
1773 | 'email' => $email, |
---|
1774 | ), |
---|
1775 | array( |
---|
1776 | 'content' => $content, |
---|
1777 | 'content_format' => 'text/plain', |
---|
1778 | 'subject' => $subject, |
---|
1779 | ) |
---|
1780 | ); |
---|
1781 | } |
---|
1782 | // Do not add gallery URL at the end of the email |
---|
1783 | elseif (isset($conf_UAM['ADD_GALLERY_URL_TO_EMAILS']) and $conf_UAM['ADD_GALLERY_URL_TO_EMAILS'] == 'false') |
---|
1784 | { |
---|
1785 | $content = ($custom_txt.l10n_args($infos1)."\n\n".l10n_args($infos2)."\n\n"); |
---|
1786 | |
---|
1787 | pwg_mail( |
---|
1788 | array( |
---|
1789 | 'name' => stripslashes($username), |
---|
1790 | 'email' => $email, |
---|
1791 | ), |
---|
1792 | array( |
---|
1793 | 'content' => $content, |
---|
1794 | 'content_format' => 'text/plain', |
---|
1795 | 'subject' => $subject, |
---|
1796 | ) |
---|
1797 | ); |
---|
1798 | } |
---|
1799 | // By default do not add gallery URL at the end of the email |
---|
1800 | else |
---|
1801 | { |
---|
1802 | $content = ($custom_txt.l10n_args($infos1)."\n\n".l10n_args($infos2)."\n\n"); |
---|
1803 | |
---|
1804 | pwg_mail( |
---|
1805 | array( |
---|
1806 | 'name' => stripslashes($username), |
---|
1807 | 'email' => $email, |
---|
1808 | ), |
---|
1809 | array( |
---|
1810 | 'content' => $content, |
---|
1811 | 'content_format' => 'text/plain', |
---|
1812 | 'subject' => $subject, |
---|
1813 | ) |
---|
1814 | ); |
---|
1815 | } |
---|
1816 | |
---|
1817 | // Switching back to default language |
---|
1818 | // ---------------------------------- |
---|
1819 | switch_lang_back(); |
---|
1820 | } |
---|
1821 | |
---|
1822 | |
---|
1823 | /** |
---|
1824 | * Function called from UAM_admin.php to send notification email when user registration have been manually validated by admin |
---|
1825 | * |
---|
1826 | * @param : user id |
---|
1827 | * |
---|
1828 | */ |
---|
1829 | function validation_mail($id) |
---|
1830 | { |
---|
1831 | global $conf; |
---|
1832 | |
---|
1833 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
1834 | |
---|
1835 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
1836 | |
---|
1837 | $custom_txt = ""; |
---|
1838 | $subject = ""; |
---|
1839 | |
---|
1840 | // We have to get the user's language in database |
---|
1841 | // ---------------------------------------------- |
---|
1842 | $query =' |
---|
1843 | SELECT user_id, language |
---|
1844 | FROM '.USER_INFOS_TABLE.' |
---|
1845 | WHERE user_id = '.$id.' |
---|
1846 | ;'; |
---|
1847 | |
---|
1848 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
1849 | |
---|
1850 | // Check if user is already registered (profile changing) - If not (new registration), language is set to current gallery language |
---|
1851 | // ------------------------------------------------------------------------------------------------------------------------------- |
---|
1852 | if (empty($data)) |
---|
1853 | { |
---|
1854 | // And switch gallery to this language before using personalized and multilangual contents |
---|
1855 | // --------------------------------------------------------------------------------------- |
---|
1856 | $language = pwg_get_session_var( 'lang_switch', $user['language'] ); |
---|
1857 | switch_lang_to($language); |
---|
1858 | } |
---|
1859 | else |
---|
1860 | { |
---|
1861 | // And switch gallery to this language before using personalized and multilangual contents |
---|
1862 | // --------------------------------------------------------------------------------------- |
---|
1863 | $language = $data['language']; // Usefull for debugging |
---|
1864 | switch_lang_to($data['language']); |
---|
1865 | load_language('plugin.lang', UAM_PATH); |
---|
1866 | } |
---|
1867 | |
---|
1868 | // Retreive users email and user name from id |
---|
1869 | // ------------------------------------------ |
---|
1870 | $query =' |
---|
1871 | SELECT id, username, mail_address |
---|
1872 | FROM '.USERS_TABLE.' |
---|
1873 | WHERE id = '.$id.' |
---|
1874 | ;'; |
---|
1875 | |
---|
1876 | $result = pwg_db_fetch_assoc(pwg_query($query)); |
---|
1877 | |
---|
1878 | if (isset($conf_UAM['ADMINVALIDATIONMAIL_SUBJECT']) and !empty($conf_UAM['ADMINVALIDATIONMAIL_SUBJECT'])) |
---|
1879 | { |
---|
1880 | // Management of Extension flags ([username], [mygallery]) |
---|
1881 | // ------------------------------------------------------- |
---|
1882 | $patterns[] = '#\[username\]#i'; |
---|
1883 | $replacements[] = stripslashes($result['username']); |
---|
1884 | $patterns[] = '#\[mygallery\]#i'; |
---|
1885 | $replacements[] = $conf['gallery_title']; |
---|
1886 | |
---|
1887 | if (function_exists('get_user_language_desc')) |
---|
1888 | { |
---|
1889 | $subject = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM['ADMINVALIDATIONMAIL_SUBJECT']))."\n\n"; |
---|
1890 | } |
---|
1891 | else $subject = l10n(preg_replace($patterns, $replacements, $conf_UAM['ADMINVALIDATIONMAIL_SUBJECT']))."\n\n"; |
---|
1892 | } |
---|
1893 | |
---|
1894 | if (isset($conf_UAM['ADMINVALIDATIONMAIL']) and !empty($conf_UAM['ADMINVALIDATIONMAIL'])) |
---|
1895 | { |
---|
1896 | // Management of Extension flags ([username], [mygallery], [myurl]) |
---|
1897 | // ---------------------------------------------------------------- |
---|
1898 | $patterns[] = '#\[username\]#i'; |
---|
1899 | $replacements[] = stripslashes($result['username']); |
---|
1900 | $patterns[] = '#\[mygallery\]#i'; |
---|
1901 | $replacements[] = $conf['gallery_title']; |
---|
1902 | $patterns[] = '#\[myurl\]#i'; |
---|
1903 | $replacements[] = get_gallery_home_url(); |
---|
1904 | if (function_exists('get_user_language_desc')) |
---|
1905 | { |
---|
1906 | $custom_txt = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM['ADMINVALIDATIONMAIL']))."\n\n"; |
---|
1907 | } |
---|
1908 | else $custom_txt = l10n(preg_replace($patterns, $replacements, $conf_UAM['ADMINVALIDATIONMAIL']))."\n\n"; |
---|
1909 | } |
---|
1910 | |
---|
1911 | $infos = array( |
---|
1912 | get_l10n_args('UAM_User: %s', stripslashes($result['username'])), |
---|
1913 | get_l10n_args('Email: %s', $result['mail_address']), |
---|
1914 | get_l10n_args('', ''), |
---|
1915 | ); |
---|
1916 | |
---|
1917 | // Sending the email with subject and contents |
---|
1918 | // ------------------------------------------- |
---|
1919 | // Adding gallery URL at the end of the email |
---|
1920 | if (isset($conf_UAM['ADD_GALLERY_URL_TO_EMAILS']) and $conf_UAM['ADD_GALLERY_URL_TO_EMAILS'] == 'true') |
---|
1921 | { |
---|
1922 | $content = (l10n_args($infos)."\n\n".$custom_txt).get_absolute_root_url(); |
---|
1923 | |
---|
1924 | pwg_mail( |
---|
1925 | array( |
---|
1926 | 'name' => stripslashes($result['username']), |
---|
1927 | 'email' => $result['mail_address'], |
---|
1928 | ), |
---|
1929 | array( |
---|
1930 | 'content' => $content, |
---|
1931 | 'content_format' => 'text/plain', |
---|
1932 | 'subject' => $subject, |
---|
1933 | ) |
---|
1934 | ); |
---|
1935 | } |
---|
1936 | // Do not add gallery URL at the end of the email |
---|
1937 | elseif (isset($conf_UAM['ADD_GALLERY_URL_TO_EMAILS']) and $conf_UAM['ADD_GALLERY_URL_TO_EMAILS'] == 'false') |
---|
1938 | { |
---|
1939 | $content = (l10n_args($infos)."\n\n".$custom_txt); |
---|
1940 | |
---|
1941 | pwg_mail( |
---|
1942 | array( |
---|
1943 | 'name' => stripslashes($result['username']), |
---|
1944 | 'email' => $result['mail_address'], |
---|
1945 | ), |
---|
1946 | array( |
---|
1947 | 'content' => $content, |
---|
1948 | 'content_format' => 'text/plain', |
---|
1949 | 'subject' => $subject, |
---|
1950 | ) |
---|
1951 | ); |
---|
1952 | } |
---|
1953 | // By defaukt do not add gallery URL at the end of the email |
---|
1954 | else |
---|
1955 | { |
---|
1956 | $content = (l10n_args($infos)."\n\n".$custom_txt); |
---|
1957 | |
---|
1958 | pwg_mail( |
---|
1959 | array( |
---|
1960 | 'name' => stripslashes($result['username']), |
---|
1961 | 'email' => $result['mail_address'], |
---|
1962 | ), |
---|
1963 | array( |
---|
1964 | 'content' => $content, |
---|
1965 | 'content_format' => 'text/plain', |
---|
1966 | 'subject' => $subject, |
---|
1967 | ) |
---|
1968 | ); |
---|
1969 | } |
---|
1970 | |
---|
1971 | // Switching back to default language |
---|
1972 | // ---------------------------------- |
---|
1973 | switch_lang_back(); |
---|
1974 | } |
---|
1975 | |
---|
1976 | |
---|
1977 | /** |
---|
1978 | * Function called from functions AddConfirmMail and ResetConfirmMail for validation key generation |
---|
1979 | * |
---|
1980 | * @return : validation key |
---|
1981 | * |
---|
1982 | */ |
---|
1983 | function FindAvailableConfirmMailID() |
---|
1984 | { |
---|
1985 | while (true) |
---|
1986 | { |
---|
1987 | $id = generate_key(16); |
---|
1988 | |
---|
1989 | $query = ' |
---|
1990 | SELECT COUNT(*) |
---|
1991 | FROM '.USER_CONFIRM_MAIL_TABLE.' |
---|
1992 | WHERE id = "'.$id.'" |
---|
1993 | ;'; |
---|
1994 | list($count) = pwg_db_fetch_row(pwg_query($query)); |
---|
1995 | |
---|
1996 | if ($count == 0) |
---|
1997 | return $id; |
---|
1998 | } |
---|
1999 | } |
---|
2000 | |
---|
2001 | |
---|
2002 | /** |
---|
2003 | * Function called from functions SendMail2User to process unvalidated users and generate validation key link |
---|
2004 | * |
---|
2005 | * @param : User id, email address |
---|
2006 | * |
---|
2007 | * @return : Build validation key in URL |
---|
2008 | * |
---|
2009 | */ |
---|
2010 | function AddConfirmMail($user_id, $email) |
---|
2011 | { |
---|
2012 | global $conf; |
---|
2013 | |
---|
2014 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
2015 | $Confirm_Mail_ID = FindAvailableConfirmMailID(); |
---|
2016 | |
---|
2017 | $dbnow = date("Y-m-d H:i:s"); |
---|
2018 | |
---|
2019 | if (isset($Confirm_Mail_ID)) |
---|
2020 | { |
---|
2021 | $query = " |
---|
2022 | SELECT status |
---|
2023 | FROM ".USER_INFOS_TABLE." |
---|
2024 | WHERE user_id = '".$user_id."' |
---|
2025 | ;"; |
---|
2026 | list($status) = pwg_db_fetch_row(pwg_query($query)); |
---|
2027 | |
---|
2028 | // Insert $Confirm_Mail_ID in USER_CONFIRM_MAIL_TABLE |
---|
2029 | $query = " |
---|
2030 | INSERT INTO ".USER_CONFIRM_MAIL_TABLE." |
---|
2031 | (id, user_id, mail_address, status, date_check, reminder) |
---|
2032 | VALUES |
---|
2033 | ('".$Confirm_Mail_ID."', '".$user_id."', '".$email."', '".$status."', null, 'false') |
---|
2034 | ;"; |
---|
2035 | pwg_query($query); |
---|
2036 | |
---|
2037 | // Set user permissions |
---|
2038 | // -------------------- |
---|
2039 | SetPermission($user_id); |
---|
2040 | |
---|
2041 | // Set UAM_validated field to false in #_users table |
---|
2042 | // ------------------------------------------------- |
---|
2043 | SetUnvalidated($user_id); |
---|
2044 | |
---|
2045 | if ($conf['guest_access']) |
---|
2046 | { |
---|
2047 | return(get_absolute_root_url().'?key='.$Confirm_Mail_ID.'&userid='.$user_id); |
---|
2048 | } |
---|
2049 | else |
---|
2050 | { |
---|
2051 | return(get_absolute_root_url().'identification.php?key='.$Confirm_Mail_ID.'&userid='.$user_id); |
---|
2052 | } |
---|
2053 | } |
---|
2054 | } |
---|
2055 | |
---|
2056 | |
---|
2057 | /** |
---|
2058 | * Function called from UAM_Adduser() to set group/status/level to new users if manual validation is set |
---|
2059 | * |
---|
2060 | * @param : User id |
---|
2061 | * |
---|
2062 | * |
---|
2063 | */ |
---|
2064 | function SetPermission($user_id) |
---|
2065 | { |
---|
2066 | global $conf; |
---|
2067 | |
---|
2068 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
2069 | |
---|
2070 | // Groups cleanup |
---|
2071 | // -------------- |
---|
2072 | $query = ' |
---|
2073 | DELETE FROM '.USER_GROUP_TABLE.' |
---|
2074 | WHERE user_id = '.$user_id.' |
---|
2075 | AND ( |
---|
2076 | group_id = '.$conf_UAM['NO_CONFIRM_GROUP'].' |
---|
2077 | OR |
---|
2078 | group_id = '.$conf_UAM['VALIDATED_GROUP'].' |
---|
2079 | ) |
---|
2080 | ;'; |
---|
2081 | |
---|
2082 | pwg_query($query); |
---|
2083 | |
---|
2084 | if ($conf_UAM['NO_CONFIRM_STATUS'] <> -1) // Set status |
---|
2085 | { |
---|
2086 | $query = ' |
---|
2087 | UPDATE '.USER_INFOS_TABLE.' |
---|
2088 | SET status = "'.$conf_UAM['NO_CONFIRM_STATUS'].'" |
---|
2089 | WHERE user_id = '.$user_id.' |
---|
2090 | ;'; |
---|
2091 | |
---|
2092 | pwg_query($query); |
---|
2093 | } |
---|
2094 | |
---|
2095 | if ($conf_UAM['NO_CONFIRM_GROUP'] <> -1) // Set group |
---|
2096 | { |
---|
2097 | $query = ' |
---|
2098 | INSERT INTO '.USER_GROUP_TABLE.' |
---|
2099 | (user_id, group_id) |
---|
2100 | VALUES |
---|
2101 | ('.$user_id.', '.$conf_UAM['NO_CONFIRM_GROUP'].') |
---|
2102 | ;'; |
---|
2103 | |
---|
2104 | pwg_query($query); |
---|
2105 | } |
---|
2106 | |
---|
2107 | if ($conf_UAM['NO_VALID_LEVEL'] <> -1) // Set privacy level |
---|
2108 | { |
---|
2109 | $query = ' |
---|
2110 | UPDATE '.USER_INFOS_TABLE.' |
---|
2111 | SET level = "'.$conf_UAM['NO_VALID_LEVEL'].'" |
---|
2112 | WHERE user_id = '.$user_id.' |
---|
2113 | ;'; |
---|
2114 | |
---|
2115 | pwg_query($query); |
---|
2116 | } |
---|
2117 | } |
---|
2118 | |
---|
2119 | |
---|
2120 | /** |
---|
2121 | * Function called from UAM_admin.php to reset validation key |
---|
2122 | * |
---|
2123 | * @param : User id |
---|
2124 | * |
---|
2125 | * @return : Build validation key in URL |
---|
2126 | * |
---|
2127 | */ |
---|
2128 | function ResetConfirmMail($user_id) |
---|
2129 | { |
---|
2130 | global $conf; |
---|
2131 | |
---|
2132 | $Confirm_Mail_ID = FindAvailableConfirmMailID(); |
---|
2133 | |
---|
2134 | $dbnow = date("Y-m-d H:i:s"); |
---|
2135 | |
---|
2136 | if (isset($Confirm_Mail_ID)) |
---|
2137 | { |
---|
2138 | $query = ' |
---|
2139 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
2140 | SET id = "'.$Confirm_Mail_ID.'" |
---|
2141 | WHERE user_id = '.$user_id.' |
---|
2142 | ;'; |
---|
2143 | |
---|
2144 | pwg_query($query); |
---|
2145 | |
---|
2146 | $query = ' |
---|
2147 | UPDATE '.USER_INFOS_TABLE.' |
---|
2148 | SET registration_date = "'.$dbnow.'" |
---|
2149 | WHERE user_id = '.$user_id.' |
---|
2150 | ;'; |
---|
2151 | |
---|
2152 | pwg_query($query); |
---|
2153 | |
---|
2154 | if ( $conf['guest_access'] ) |
---|
2155 | { |
---|
2156 | return(get_absolute_root_url().'?key='.$Confirm_Mail_ID.'&userid='.$user_id); |
---|
2157 | } |
---|
2158 | else |
---|
2159 | { |
---|
2160 | return(get_absolute_root_url().'identification.php?key='.$Confirm_Mail_ID.'&userid='.$user_id); |
---|
2161 | } |
---|
2162 | } |
---|
2163 | } |
---|
2164 | |
---|
2165 | |
---|
2166 | /** |
---|
2167 | * Function called from functions.inc.php to reset last visit date after sending a reminder |
---|
2168 | * |
---|
2169 | * @param : User id |
---|
2170 | * |
---|
2171 | */ |
---|
2172 | function resetlastvisit($user_id) |
---|
2173 | { |
---|
2174 | global $conf; |
---|
2175 | |
---|
2176 | $dbnow = date("Y-m-d H:i:s"); |
---|
2177 | |
---|
2178 | $query = ' |
---|
2179 | UPDATE '.USER_LASTVISIT_TABLE.' |
---|
2180 | SET lastvisit = "'.$dbnow.'", reminder = "true" |
---|
2181 | WHERE user_id = '.$user_id.' |
---|
2182 | ;'; |
---|
2183 | |
---|
2184 | pwg_query($query); |
---|
2185 | } |
---|
2186 | |
---|
2187 | |
---|
2188 | /** |
---|
2189 | * Function called from main.inc.php - Triggered on user deletion |
---|
2190 | * |
---|
2191 | */ |
---|
2192 | function DeleteConfirmMail($user_id) |
---|
2193 | { |
---|
2194 | $query = ' |
---|
2195 | DELETE FROM '.USER_CONFIRM_MAIL_TABLE.' |
---|
2196 | WHERE user_id = '.$user_id.' |
---|
2197 | ;'; |
---|
2198 | |
---|
2199 | pwg_query($query); |
---|
2200 | } |
---|
2201 | |
---|
2202 | |
---|
2203 | /** |
---|
2204 | * Function called from main.inc.php - Triggered on user deletion |
---|
2205 | * |
---|
2206 | */ |
---|
2207 | function DeleteLastVisit($user_id) |
---|
2208 | { |
---|
2209 | $query = ' |
---|
2210 | DELETE FROM '.USER_LASTVISIT_TABLE.' |
---|
2211 | WHERE user_id = '.$user_id.' |
---|
2212 | ;'; |
---|
2213 | |
---|
2214 | pwg_query($query); |
---|
2215 | } |
---|
2216 | |
---|
2217 | |
---|
2218 | /** |
---|
2219 | * Function called from main.inc.php - Triggered on user deletion |
---|
2220 | * |
---|
2221 | * @param : User id |
---|
2222 | * |
---|
2223 | */ |
---|
2224 | function DeleteRedir($user_id) |
---|
2225 | { |
---|
2226 | $tab = array(); |
---|
2227 | |
---|
2228 | $query = ' |
---|
2229 | SELECT value |
---|
2230 | FROM '.CONFIG_TABLE.' |
---|
2231 | WHERE param = "UserAdvManager_Redir" |
---|
2232 | ;'; |
---|
2233 | |
---|
2234 | $tab = pwg_db_fetch_row(pwg_query($query)); |
---|
2235 | |
---|
2236 | $values = explode(',', $tab[0]); |
---|
2237 | |
---|
2238 | unset($values[array_search($user_id, $values)]); |
---|
2239 | |
---|
2240 | $query = ' |
---|
2241 | UPDATE '.CONFIG_TABLE.' |
---|
2242 | SET value = "'.implode(',', $values).'" |
---|
2243 | WHERE param = "UserAdvManager_Redir";'; |
---|
2244 | |
---|
2245 | pwg_query($query); |
---|
2246 | } |
---|
2247 | |
---|
2248 | |
---|
2249 | /** |
---|
2250 | * Function called from ConfirmMail.php to verify validation key used by user according time limit |
---|
2251 | * Return true is key validation is OK else return false |
---|
2252 | * |
---|
2253 | * @param : User id |
---|
2254 | * |
---|
2255 | * @return : Bool |
---|
2256 | * |
---|
2257 | */ |
---|
2258 | function VerifyConfirmMail($id) |
---|
2259 | { |
---|
2260 | global $conf; |
---|
2261 | |
---|
2262 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
2263 | |
---|
2264 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
2265 | |
---|
2266 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
---|
2267 | |
---|
2268 | $query = ' |
---|
2269 | SELECT COUNT(*) |
---|
2270 | FROM '.USER_CONFIRM_MAIL_TABLE.' |
---|
2271 | WHERE id = "'.$id.'" |
---|
2272 | ;'; |
---|
2273 | |
---|
2274 | list($count) = pwg_db_fetch_row(pwg_query($query)); |
---|
2275 | |
---|
2276 | if ($count == 1) |
---|
2277 | { |
---|
2278 | $query = ' |
---|
2279 | SELECT user_id, status, date_check |
---|
2280 | FROM '.USER_CONFIRM_MAIL_TABLE.' |
---|
2281 | WHERE id = "'.$id.'" |
---|
2282 | ;'; |
---|
2283 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
2284 | |
---|
2285 | if (!empty($data) and isset($data['user_id']) and is_null($data['date_check'])) |
---|
2286 | { |
---|
2287 | $query = ' |
---|
2288 | SELECT registration_date |
---|
2289 | FROM '.USER_INFOS_TABLE.' |
---|
2290 | WHERE user_id = '.$data['user_id'].' |
---|
2291 | ;'; |
---|
2292 | |
---|
2293 | list($registration_date) = pwg_db_fetch_row(pwg_query($query)); |
---|
2294 | |
---|
2295 | // Time limit process |
---|
2296 | // ******************************************** |
---|
2297 | if (!empty($registration_date)) |
---|
2298 | { |
---|
2299 | // Verify Confirmmail with time limit ON |
---|
2300 | // ------------------------------------- |
---|
2301 | if (isset ($conf_UAM_ConfirmMail['CONFIRMMAIL_DELAY'])) |
---|
2302 | { |
---|
2303 | // Dates formating and compare |
---|
2304 | // --------------------------- |
---|
2305 | $today = date("d-m-Y"); // Get today's date |
---|
2306 | list($day, $month, $year) = explode('-', $today); // explode date of today |
---|
2307 | $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp |
---|
2308 | |
---|
2309 | list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date |
---|
2310 | list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date |
---|
2311 | $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp |
---|
2312 | |
---|
2313 | $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps |
---|
2314 | $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days |
---|
2315 | |
---|
2316 | // Condition with the value set for time limit |
---|
2317 | // ------------------------------------------- |
---|
2318 | if ($deltadays <= $conf_UAM_ConfirmMail['CONFIRMMAIL_DELAY']) // If Nb of days is less than the limit set |
---|
2319 | { |
---|
2320 | $dbnow = date("Y-m-d H:i:s"); |
---|
2321 | |
---|
2322 | // Update ConfirmMail table |
---|
2323 | // ------------------------ |
---|
2324 | $query = ' |
---|
2325 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
2326 | SET date_check="'.$dbnow.'", reminder="false" |
---|
2327 | WHERE id = "'.$id.'" |
---|
2328 | ;'; |
---|
2329 | pwg_query($query); |
---|
2330 | |
---|
2331 | // Update LastVisit table - Force reminder field to false |
---|
2332 | // Usefull when a user has been automatically downgraded and revalidate its registration |
---|
2333 | // ------------------------------------------------------------------------------------- |
---|
2334 | $query = ' |
---|
2335 | UPDATE '.USER_LASTVISIT_TABLE.' |
---|
2336 | SET reminder="false" |
---|
2337 | WHERE user_id = "'.$data['user_id'].'" |
---|
2338 | ;'; |
---|
2339 | pwg_query($query); |
---|
2340 | |
---|
2341 | if ($conf_UAM['NO_CONFIRM_GROUP'] <> -1) // Delete user from unvalidated users group |
---|
2342 | { |
---|
2343 | $query = ' |
---|
2344 | DELETE FROM '.USER_GROUP_TABLE.' |
---|
2345 | WHERE user_id = '.$data['user_id'].' |
---|
2346 | AND group_id = '.$conf_UAM['NO_CONFIRM_GROUP'].' |
---|
2347 | ;'; |
---|
2348 | pwg_query($query); |
---|
2349 | } |
---|
2350 | |
---|
2351 | if ($conf_UAM['VALIDATED_GROUP'] <> -1) // Add user to validated users group |
---|
2352 | { |
---|
2353 | $query = ' |
---|
2354 | INSERT INTO '.USER_GROUP_TABLE.' |
---|
2355 | (user_id, group_id) |
---|
2356 | VALUES |
---|
2357 | ('.$data['user_id'].', '.$conf_UAM['VALIDATED_GROUP'].') |
---|
2358 | ;'; |
---|
2359 | pwg_query($query); |
---|
2360 | } |
---|
2361 | |
---|
2362 | if ($conf_UAM['VALIDATED_STATUS'] <> -1) // Change user's status |
---|
2363 | { |
---|
2364 | $query = ' |
---|
2365 | UPDATE '.USER_INFOS_TABLE.' |
---|
2366 | SET status = "'.$conf_UAM['VALIDATED_STATUS'].'" |
---|
2367 | WHERE user_id = '.$data['user_id'].' |
---|
2368 | ;'; |
---|
2369 | pwg_query($query); |
---|
2370 | } |
---|
2371 | |
---|
2372 | if ($conf_UAM['VALID_LEVEL'] <> -1) // Change user's privacy level |
---|
2373 | { |
---|
2374 | $query = ' |
---|
2375 | UPDATE '.USER_INFOS_TABLE.' |
---|
2376 | SET level = "'.$conf_UAM['VALID_LEVEL'].'" |
---|
2377 | WHERE user_id = '.$data['user_id'].' |
---|
2378 | ;'; |
---|
2379 | pwg_query($query); |
---|
2380 | } |
---|
2381 | |
---|
2382 | // Set UAM_validated field to True in #_users table |
---|
2383 | SetValidated($data['user_id']); |
---|
2384 | |
---|
2385 | // Refresh user's category cache |
---|
2386 | // ----------------------------- |
---|
2387 | invalidate_user_cache(); |
---|
2388 | |
---|
2389 | return true; |
---|
2390 | } |
---|
2391 | elseif ($deltadays > $conf_UAM_ConfirmMail['CONFIRMMAIL_DELAY']) // If timelimit exeeds |
---|
2392 | { |
---|
2393 | return false; |
---|
2394 | } |
---|
2395 | } |
---|
2396 | // Verify Confirmmail with time limit OFF |
---|
2397 | // -------------------------------------- |
---|
2398 | else |
---|
2399 | { |
---|
2400 | $dbnow = date("Y-m-d H:i:s"); |
---|
2401 | |
---|
2402 | // Update ConfirmMail table |
---|
2403 | // ------------------------ |
---|
2404 | $query = ' |
---|
2405 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
2406 | SET date_check="'.$dbnow.'" |
---|
2407 | WHERE id = "'.$id.'" |
---|
2408 | ;'; |
---|
2409 | pwg_query($query); |
---|
2410 | |
---|
2411 | // Update LastVisit table - Force reminder field to false |
---|
2412 | // Usefull when a user has been automatically downgraded and revalidate its registration |
---|
2413 | // ------------------------------------------------------------------------------------- |
---|
2414 | $query = ' |
---|
2415 | UPDATE '.USER_LASTVISIT_TABLE.' |
---|
2416 | SET reminder="false" |
---|
2417 | WHERE user_id = "'.$data['user_id'].'" |
---|
2418 | ;'; |
---|
2419 | pwg_query($query); |
---|
2420 | |
---|
2421 | if ($conf_UAM['NO_CONFIRM_GROUP'] <> -1) // Delete user from unvalidated users group |
---|
2422 | { |
---|
2423 | $query = ' |
---|
2424 | DELETE FROM '.USER_GROUP_TABLE.' |
---|
2425 | WHERE user_id = '.$data['user_id'].' |
---|
2426 | AND group_id = '.$conf_UAM['NO_CONFIRM_GROUP'].' |
---|
2427 | ;'; |
---|
2428 | pwg_query($query); |
---|
2429 | } |
---|
2430 | |
---|
2431 | if ($conf_UAM['VALIDATED_GROUP'] <> -1) |
---|
2432 | { |
---|
2433 | $query = ' |
---|
2434 | DELETE FROM '.USER_GROUP_TABLE.' |
---|
2435 | WHERE user_id = '.$data['user_id'].' |
---|
2436 | AND group_id = '.$conf_UAM['VALIDATED_GROUP'].' |
---|
2437 | ;'; |
---|
2438 | pwg_query($query); |
---|
2439 | |
---|
2440 | $query = ' |
---|
2441 | INSERT INTO '.USER_GROUP_TABLE.' |
---|
2442 | (user_id, group_id) |
---|
2443 | VALUES |
---|
2444 | ('.$data['user_id'].', '.$conf_UAM['VALIDATED_GROUP'].') |
---|
2445 | ;'; |
---|
2446 | pwg_query($query); |
---|
2447 | } |
---|
2448 | |
---|
2449 | if ($conf_UAM['VALIDATED_STATUS'] <> -1) // Change user's status |
---|
2450 | { |
---|
2451 | $query = ' |
---|
2452 | UPDATE '.USER_INFOS_TABLE.' |
---|
2453 | SET status = "'.$conf_UAM['VALIDATED_STATUS'].'" |
---|
2454 | WHERE user_id = '.$data['user_id'].' |
---|
2455 | ;'; |
---|
2456 | pwg_query($query); |
---|
2457 | } |
---|
2458 | |
---|
2459 | if ($conf_UAM['VALID_LEVEL'] <> -1) // Change user's privacy level |
---|
2460 | { |
---|
2461 | $query = ' |
---|
2462 | UPDATE '.USER_INFOS_TABLE.' |
---|
2463 | SET level = "'.$conf_UAM['VALID_LEVEL'].'" |
---|
2464 | WHERE user_id = '.$data['user_id'].' |
---|
2465 | ;'; |
---|
2466 | pwg_query($query); |
---|
2467 | } |
---|
2468 | |
---|
2469 | // Set UAM_validated field to True in #_users table |
---|
2470 | SetValidated($data['user_id']); |
---|
2471 | |
---|
2472 | // Refresh user's category cache |
---|
2473 | // ----------------------------- |
---|
2474 | invalidate_user_cache(); |
---|
2475 | |
---|
2476 | return true; |
---|
2477 | } |
---|
2478 | } |
---|
2479 | } |
---|
2480 | else if (!empty($data) and !is_null($data['date_check'])) |
---|
2481 | { |
---|
2482 | return false; |
---|
2483 | } |
---|
2484 | } |
---|
2485 | else |
---|
2486 | return false; |
---|
2487 | } |
---|
2488 | |
---|
2489 | |
---|
2490 | /** |
---|
2491 | * Function called from UAM_admin.php for manual validation by admin |
---|
2492 | * |
---|
2493 | * @param : User id |
---|
2494 | * |
---|
2495 | */ |
---|
2496 | function ManualValidation($id) |
---|
2497 | { |
---|
2498 | global $conf; |
---|
2499 | |
---|
2500 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
2501 | |
---|
2502 | if (isset($conf_UAM['CONFIRM_MAIL']) and $conf_UAM['CONFIRM_MAIL'] == 'true') // Set date of validation |
---|
2503 | { |
---|
2504 | $dbnow = date("Y-m-d H:i:s"); |
---|
2505 | |
---|
2506 | $query = ' |
---|
2507 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
2508 | SET date_check="'.$dbnow.'" |
---|
2509 | WHERE user_id = '.$id.' |
---|
2510 | ;'; |
---|
2511 | pwg_query($query); |
---|
2512 | } |
---|
2513 | |
---|
2514 | if ($conf_UAM['NO_CONFIRM_GROUP'] <> -1) // Delete user from waiting group |
---|
2515 | { |
---|
2516 | $query = ' |
---|
2517 | DELETE FROM '.USER_GROUP_TABLE.' |
---|
2518 | WHERE user_id = '.$id.' |
---|
2519 | AND group_id = '.$conf_UAM['NO_CONFIRM_GROUP'].' |
---|
2520 | ;'; |
---|
2521 | pwg_query($query); |
---|
2522 | } |
---|
2523 | |
---|
2524 | if ($conf_UAM['VALIDATED_GROUP'] <> -1) // Set user's valid group |
---|
2525 | { |
---|
2526 | $query = ' |
---|
2527 | DELETE FROM '.USER_GROUP_TABLE.' |
---|
2528 | WHERE user_id = '.$id.' |
---|
2529 | AND group_id = '.$conf_UAM['VALIDATED_GROUP'].' |
---|
2530 | ;'; |
---|
2531 | pwg_query($query); |
---|
2532 | |
---|
2533 | $query = ' |
---|
2534 | INSERT INTO '.USER_GROUP_TABLE.' |
---|
2535 | (user_id, group_id) |
---|
2536 | VALUES |
---|
2537 | ('.$id.', '.$conf_UAM['VALIDATED_GROUP'].') |
---|
2538 | ;'; |
---|
2539 | pwg_query($query); |
---|
2540 | } |
---|
2541 | |
---|
2542 | if ($conf_UAM['VALIDATED_STATUS'] <> -1) // Set user's valid status |
---|
2543 | { |
---|
2544 | $query = ' |
---|
2545 | UPDATE '.USER_INFOS_TABLE.' |
---|
2546 | SET status = "'.$conf_UAM['VALIDATED_STATUS'].'" |
---|
2547 | WHERE user_id = '.$id.' |
---|
2548 | ;'; |
---|
2549 | pwg_query($query); |
---|
2550 | } |
---|
2551 | |
---|
2552 | if ($conf_UAM['VALID_LEVEL'] <> -1) // Set user's valid privacy level |
---|
2553 | { |
---|
2554 | $query = ' |
---|
2555 | UPDATE '.USER_INFOS_TABLE.' |
---|
2556 | SET level = "'.$conf_UAM['VALID_LEVEL'].'" |
---|
2557 | WHERE user_id = '.$id.' |
---|
2558 | ;'; |
---|
2559 | pwg_query($query); |
---|
2560 | } |
---|
2561 | |
---|
2562 | // Set UAM_validated field to True in #_users table |
---|
2563 | SetValidated($id); |
---|
2564 | } |
---|
2565 | |
---|
2566 | |
---|
2567 | /** |
---|
2568 | * Function called from functions.inc.php - Check if username matches forbidden characters |
---|
2569 | * |
---|
2570 | * @param : User login |
---|
2571 | * |
---|
2572 | * @return : Bool |
---|
2573 | * |
---|
2574 | */ |
---|
2575 | function ValidateUsername($login) |
---|
2576 | { |
---|
2577 | global $conf; |
---|
2578 | |
---|
2579 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
2580 | |
---|
2581 | if (isset($login) and isset($conf_UAM['USERNAME_CHAR_LIST']) and !empty($conf_UAM['USERNAME_CHAR_LIST'])) |
---|
2582 | { |
---|
2583 | $conf_CharExclusion = preg_split("/,/",$conf_UAM['USERNAME_CHAR_LIST']); |
---|
2584 | for ($i = 0 ; $i < count($conf_CharExclusion) ; $i++) |
---|
2585 | { |
---|
2586 | //Detect meta-characters (# ! ^ $ ( ) [ ] { } ? + * . \ -) for special pattern |
---|
2587 | if ($conf_CharExclusion[$i] == "#" |
---|
2588 | or $conf_CharExclusion[$i] == "$" |
---|
2589 | or $conf_CharExclusion[$i] == "!" |
---|
2590 | or $conf_CharExclusion[$i] == "^" |
---|
2591 | or $conf_CharExclusion[$i] == "*" |
---|
2592 | or $conf_CharExclusion[$i] == "?" |
---|
2593 | or $conf_CharExclusion[$i] == "+" |
---|
2594 | or $conf_CharExclusion[$i] == "." |
---|
2595 | or $conf_CharExclusion[$i] == "\\" |
---|
2596 | or $conf_CharExclusion[$i] == "|" |
---|
2597 | or $conf_CharExclusion[$i] == "[" |
---|
2598 | or $conf_CharExclusion[$i] == "]" |
---|
2599 | or $conf_CharExclusion[$i] == "(" |
---|
2600 | or $conf_CharExclusion[$i] == ")" |
---|
2601 | or $conf_CharExclusion[$i] == "{" |
---|
2602 | or $conf_CharExclusion[$i] == "}" |
---|
2603 | or $conf_CharExclusion[$i] == "-") |
---|
2604 | { |
---|
2605 | $pattern = '/[][^$.\*+?(){}#|-]/i'; |
---|
2606 | } |
---|
2607 | else |
---|
2608 | { |
---|
2609 | $pattern = '/'.$conf_CharExclusion[$i].'/i'; |
---|
2610 | } |
---|
2611 | |
---|
2612 | if (preg_match($pattern, $login)) |
---|
2613 | { |
---|
2614 | return true; |
---|
2615 | } |
---|
2616 | } |
---|
2617 | } |
---|
2618 | else |
---|
2619 | { |
---|
2620 | return false; |
---|
2621 | } |
---|
2622 | } |
---|
2623 | |
---|
2624 | |
---|
2625 | /** |
---|
2626 | * Function called from main.inc.php - Check if user's email is in excluded email providers list |
---|
2627 | * Doesn't work on call - Must be copied in main.inc.php to work |
---|
2628 | * |
---|
2629 | * @param : Email address |
---|
2630 | * |
---|
2631 | * @return : Bool |
---|
2632 | * |
---|
2633 | */ |
---|
2634 | function ValidateEmailProvider($email) |
---|
2635 | { |
---|
2636 | global $conf; |
---|
2637 | |
---|
2638 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
2639 | |
---|
2640 | if (isset($email) and isset($conf_UAM['MAILEXCLUSION_LIST']) and !empty($conf_UAM['MAILEXCLUSION_LIST'])) |
---|
2641 | { |
---|
2642 | $conf_MailExclusion = preg_split("/[\s,]+/",$conf_UAM['MAILEXCLUSION_LIST']); |
---|
2643 | for ($i = 0 ; $i < count($conf_MailExclusion) ; $i++) |
---|
2644 | { |
---|
2645 | $pattern = '/'.$conf_MailExclusion[$i].'/i'; |
---|
2646 | if (preg_match($pattern, $email)) |
---|
2647 | { |
---|
2648 | return true; |
---|
2649 | } |
---|
2650 | } |
---|
2651 | } |
---|
2652 | else |
---|
2653 | { |
---|
2654 | return false; |
---|
2655 | } |
---|
2656 | } |
---|
2657 | |
---|
2658 | |
---|
2659 | /** |
---|
2660 | * Function called from UAM_admin.php - Get unvalidated users according time limit |
---|
2661 | * |
---|
2662 | * @return : List of users |
---|
2663 | * |
---|
2664 | */ |
---|
2665 | function get_unvalid_user_list() |
---|
2666 | { |
---|
2667 | global $conf, $page; |
---|
2668 | |
---|
2669 | // Get ConfirmMail configuration |
---|
2670 | // ----------------------------- |
---|
2671 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
---|
2672 | // Get UAM configuration |
---|
2673 | // --------------------- |
---|
2674 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
2675 | |
---|
2676 | $users = array(); |
---|
2677 | |
---|
2678 | // Search users depending expiration date |
---|
2679 | // -------------------------------------- |
---|
2680 | $query = ' |
---|
2681 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
2682 | u.'.$conf['user_fields']['username'].' AS username, |
---|
2683 | u.'.$conf['user_fields']['email'].' AS email, |
---|
2684 | ui.status, |
---|
2685 | ui.enabled_high, |
---|
2686 | ui.level, |
---|
2687 | ui.registration_date |
---|
2688 | FROM '.USERS_TABLE.' AS u |
---|
2689 | INNER JOIN '.USER_INFOS_TABLE.' AS ui |
---|
2690 | ON u.'.$conf['user_fields']['id'].' = ui.user_id |
---|
2691 | LEFT JOIN '.USER_GROUP_TABLE.' AS ug |
---|
2692 | ON u.'.$conf['user_fields']['id'].' = ug.user_id |
---|
2693 | WHERE u.'.$conf['user_fields']['id'].' >= 3 |
---|
2694 | AND u.'.$conf['user_fields']['id'].' <> '.$conf['default_user_id'].' |
---|
2695 | AND (TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) >= "'.$conf_UAM_ConfirmMail['CONFIRMMAIL_DELAY'].'" |
---|
2696 | OR TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) < "'.$conf_UAM_ConfirmMail['CONFIRMMAIL_DELAY'].'") |
---|
2697 | AND u.UAM_validated = "false" |
---|
2698 | ORDER BY ui.registration_date ASC |
---|
2699 | ;'; |
---|
2700 | |
---|
2701 | $result = pwg_query($query); |
---|
2702 | |
---|
2703 | while ($row = pwg_db_fetch_assoc($result)) |
---|
2704 | { |
---|
2705 | $user = $row; |
---|
2706 | $user['groups'] = array(); |
---|
2707 | |
---|
2708 | array_push($users, $user); |
---|
2709 | } |
---|
2710 | |
---|
2711 | // Add groups list |
---|
2712 | // --------------- |
---|
2713 | $user_ids = array(); |
---|
2714 | foreach ($users as $i => $user) |
---|
2715 | { |
---|
2716 | $user_ids[$i] = $user['id']; |
---|
2717 | } |
---|
2718 | |
---|
2719 | $user_nums = array_flip($user_ids); |
---|
2720 | |
---|
2721 | if (count($user_ids) > 0) |
---|
2722 | { |
---|
2723 | $query = ' |
---|
2724 | SELECT user_id, group_id |
---|
2725 | FROM '.USER_GROUP_TABLE.' |
---|
2726 | WHERE user_id IN ('.implode(',', $user_ids).') |
---|
2727 | ;'; |
---|
2728 | |
---|
2729 | $result = pwg_query($query); |
---|
2730 | |
---|
2731 | while ($row = pwg_db_fetch_assoc($result)) |
---|
2732 | { |
---|
2733 | array_push( |
---|
2734 | $users[$user_nums[$row['user_id']]]['groups'], |
---|
2735 | $row['group_id'] |
---|
2736 | ); |
---|
2737 | } |
---|
2738 | } |
---|
2739 | |
---|
2740 | return $users; |
---|
2741 | } |
---|
2742 | |
---|
2743 | |
---|
2744 | /** |
---|
2745 | * Function called from functions.inc.php - Get all users who haven't validate their registration in configured time |
---|
2746 | * to delete or remail them automatically |
---|
2747 | * |
---|
2748 | * @return : List of users |
---|
2749 | * |
---|
2750 | */ |
---|
2751 | function get_unvalid_user_autotasks() |
---|
2752 | { |
---|
2753 | global $conf, $page; |
---|
2754 | |
---|
2755 | // Get ConfirmMail configuration |
---|
2756 | // ----------------------------- |
---|
2757 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
---|
2758 | |
---|
2759 | $users = array(); |
---|
2760 | |
---|
2761 | // search users depending expiration date |
---|
2762 | // -------------------------------------- |
---|
2763 | $query = ' |
---|
2764 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
2765 | u.UAM_validated, |
---|
2766 | ui.registration_date |
---|
2767 | FROM '.USERS_TABLE.' AS u |
---|
2768 | INNER JOIN '.USER_INFOS_TABLE.' AS ui |
---|
2769 | ON u.'.$conf['user_fields']['id'].' = ui.user_id |
---|
2770 | WHERE u.'.$conf['user_fields']['id'].' >= 3 |
---|
2771 | AND u.'.$conf['user_fields']['id'].' <> '.$conf['default_user_id'].' |
---|
2772 | AND (TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) >= "'.$conf_UAM_ConfirmMail['CONFIRMMAIL_DELAY'].'") |
---|
2773 | AND u.UAM_validated <> "true" |
---|
2774 | ORDER BY ui.registration_date ASC;'; |
---|
2775 | |
---|
2776 | $result = pwg_query($query); |
---|
2777 | |
---|
2778 | while ($row = pwg_db_fetch_assoc($result)) |
---|
2779 | { |
---|
2780 | array_push($users, $row); |
---|
2781 | } |
---|
2782 | |
---|
2783 | return $users; |
---|
2784 | } |
---|
2785 | |
---|
2786 | |
---|
2787 | /** |
---|
2788 | * Function called from UAM_admin.php - Get ghost users |
---|
2789 | * |
---|
2790 | * @return : List of users |
---|
2791 | * |
---|
2792 | */ |
---|
2793 | function get_ghost_user_list() |
---|
2794 | { |
---|
2795 | global $conf, $page; |
---|
2796 | |
---|
2797 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
2798 | |
---|
2799 | $users = array(); |
---|
2800 | |
---|
2801 | // Search users depending expiration date |
---|
2802 | // -------------------------------------- |
---|
2803 | $query = ' |
---|
2804 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
2805 | u.'.$conf['user_fields']['username'].' AS username, |
---|
2806 | u.'.$conf['user_fields']['email'].' AS email, |
---|
2807 | lv.lastvisit, |
---|
2808 | lv.reminder |
---|
2809 | FROM '.USERS_TABLE.' AS u |
---|
2810 | INNER JOIN '.USER_LASTVISIT_TABLE.' AS lv |
---|
2811 | ON u.'.$conf['user_fields']['id'].' = lv.user_id |
---|
2812 | WHERE (TO_DAYS(NOW()) - TO_DAYS(lv.lastvisit) >= "'.$conf_UAM['GHOSTRACKER_DAYLIMIT'].'") |
---|
2813 | AND u.'.$conf['user_fields']['id'].' <> '.$conf['default_user_id'].' |
---|
2814 | ORDER BY lv.lastvisit ASC;'; |
---|
2815 | |
---|
2816 | $result = pwg_query($query); |
---|
2817 | |
---|
2818 | while ($row = pwg_db_fetch_assoc($result)) |
---|
2819 | { |
---|
2820 | $user = $row; |
---|
2821 | $user['groups'] = array(); |
---|
2822 | |
---|
2823 | array_push($users, $user); |
---|
2824 | } |
---|
2825 | |
---|
2826 | // Add groups list |
---|
2827 | // --------------- |
---|
2828 | $user_ids = array(); |
---|
2829 | foreach ($users as $i => $user) |
---|
2830 | { |
---|
2831 | $user_ids[$i] = $user['id']; |
---|
2832 | } |
---|
2833 | |
---|
2834 | return $users; |
---|
2835 | } |
---|
2836 | |
---|
2837 | |
---|
2838 | /** |
---|
2839 | * Function called from functions.inc.php - Get all ghost users to delete or downgrade automatically on any user login |
---|
2840 | * |
---|
2841 | * @return : List of users to delete or downgrade automatically |
---|
2842 | * |
---|
2843 | */ |
---|
2844 | function get_ghosts_autotasks() |
---|
2845 | { |
---|
2846 | global $conf, $page; |
---|
2847 | |
---|
2848 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
2849 | |
---|
2850 | $users = array(); |
---|
2851 | |
---|
2852 | // Search users depending expiration date and reminder sent |
---|
2853 | // -------------------------------------------------------- |
---|
2854 | $query = ' |
---|
2855 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
2856 | lv.lastvisit |
---|
2857 | FROM '.USERS_TABLE.' AS u |
---|
2858 | INNER JOIN '.USER_LASTVISIT_TABLE.' AS lv |
---|
2859 | ON u.'.$conf['user_fields']['id'].' = lv.user_id |
---|
2860 | WHERE (TO_DAYS(NOW()) - TO_DAYS(lv.lastvisit) >= "'.$conf_UAM['GHOSTRACKER_DAYLIMIT'].'") |
---|
2861 | AND u.'.$conf['user_fields']['id'].' <> '.$conf['default_user_id'].' |
---|
2862 | ORDER BY lv.lastvisit ASC;'; |
---|
2863 | |
---|
2864 | $result = pwg_query($query); |
---|
2865 | |
---|
2866 | while ($row = pwg_db_fetch_assoc($result)) |
---|
2867 | { |
---|
2868 | array_push($users, $row); |
---|
2869 | } |
---|
2870 | |
---|
2871 | return $users; |
---|
2872 | } |
---|
2873 | |
---|
2874 | |
---|
2875 | /** |
---|
2876 | * Function called from UAM_admin.php - Get all users to display the number of days since their last visit |
---|
2877 | * |
---|
2878 | * @return : List of users |
---|
2879 | * |
---|
2880 | */ |
---|
2881 | function get_user_list() |
---|
2882 | { |
---|
2883 | global $conf, $page; |
---|
2884 | |
---|
2885 | $users = array(); |
---|
2886 | |
---|
2887 | // Search users depending expiration date with exclusion of Adult_Content generic users |
---|
2888 | // ------------------------------------------------------------------------------------ |
---|
2889 | $query = ' |
---|
2890 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
2891 | u.'.$conf['user_fields']['username'].' AS username, |
---|
2892 | u.'.$conf['user_fields']['email'].' AS email, |
---|
2893 | ug.lastvisit |
---|
2894 | FROM '.USERS_TABLE.' AS u |
---|
2895 | INNER JOIN '.USER_LASTVISIT_TABLE.' AS ug |
---|
2896 | ON u.'.$conf['user_fields']['id'].' = ug.user_id |
---|
2897 | WHERE u.'.$conf['user_fields']['id'].' >= 3 |
---|
2898 | AND u.'.$conf['user_fields']['id'].' <> '.$conf['default_user_id'].' |
---|
2899 | AND u.username NOT LIKE "16" |
---|
2900 | AND u.username NOT LIKE "18" |
---|
2901 | ORDER BY ug.lastvisit DESC |
---|
2902 | ;'; |
---|
2903 | |
---|
2904 | $result = pwg_query($query); |
---|
2905 | |
---|
2906 | while ($row = pwg_db_fetch_assoc($result)) |
---|
2907 | { |
---|
2908 | $user = $row; |
---|
2909 | $user['groups'] = array(); |
---|
2910 | |
---|
2911 | array_push($users, $user); |
---|
2912 | } |
---|
2913 | |
---|
2914 | // Add groups list |
---|
2915 | // --------------- |
---|
2916 | $user_ids = array(); |
---|
2917 | foreach ($users as $i => $user) |
---|
2918 | { |
---|
2919 | $user_ids[$i] = $user['id']; |
---|
2920 | } |
---|
2921 | |
---|
2922 | return $users; |
---|
2923 | } |
---|
2924 | |
---|
2925 | |
---|
2926 | /** |
---|
2927 | * Function called from UAM_admin.php - to determine who is expired or not and giving a different display color |
---|
2928 | * |
---|
2929 | * @param : user id |
---|
2930 | * |
---|
2931 | * @return : Bool |
---|
2932 | * |
---|
2933 | */ |
---|
2934 | function expiration($id) |
---|
2935 | { |
---|
2936 | global $conf, $page; |
---|
2937 | |
---|
2938 | // Get ConfirmMail configuration |
---|
2939 | // ----------------------------- |
---|
2940 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
---|
2941 | |
---|
2942 | // Get UAM configuration |
---|
2943 | // --------------------- |
---|
2944 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
2945 | |
---|
2946 | $query = ' |
---|
2947 | SELECT registration_date |
---|
2948 | FROM '.USER_INFOS_TABLE.' |
---|
2949 | WHERE user_id = '.$id.' |
---|
2950 | ;'; |
---|
2951 | list($registration_date) = pwg_db_fetch_row(pwg_query($query)); |
---|
2952 | |
---|
2953 | // Time limit process |
---|
2954 | // ******************************************** |
---|
2955 | if (!empty($registration_date)) |
---|
2956 | { |
---|
2957 | // Dates formating and compare |
---|
2958 | // --------------------------- |
---|
2959 | $today = date("d-m-Y"); // Get today's date |
---|
2960 | list($day, $month, $year) = explode('-', $today); // explode date of today |
---|
2961 | $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp |
---|
2962 | |
---|
2963 | list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date |
---|
2964 | list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date |
---|
2965 | $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp |
---|
2966 | |
---|
2967 | $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps |
---|
2968 | $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days |
---|
2969 | |
---|
2970 | // Condition with the value set for time limit |
---|
2971 | // ------------------------------------------- |
---|
2972 | if ($deltadays <= $conf_UAM_ConfirmMail['CONFIRMMAIL_DELAY']) // If Nb of days is less than the limit set |
---|
2973 | { |
---|
2974 | return false; |
---|
2975 | } |
---|
2976 | else |
---|
2977 | { |
---|
2978 | return true; |
---|
2979 | } |
---|
2980 | } |
---|
2981 | } |
---|
2982 | |
---|
2983 | |
---|
2984 | /** |
---|
2985 | * UAM_check_profile - Thx to LucMorizur |
---|
2986 | * checks if a user id is registered as having already |
---|
2987 | * visited his profile page. |
---|
2988 | * |
---|
2989 | * @uid : the user id |
---|
2990 | * |
---|
2991 | * @user_idsOK : (returned) array of all users ids having already visited |
---|
2992 | * their profile.php pages |
---|
2993 | * |
---|
2994 | * @returns : true or false whether the users has already visited his |
---|
2995 | * profile.php page or not |
---|
2996 | * |
---|
2997 | */ |
---|
2998 | function UAM_check_profile($uid, &$user_idsOK) |
---|
2999 | { |
---|
3000 | $t = array(); |
---|
3001 | $v = false; |
---|
3002 | |
---|
3003 | $query = ' |
---|
3004 | SELECT value |
---|
3005 | FROM '.CONFIG_TABLE.' |
---|
3006 | WHERE param = "UserAdvManager_Redir" |
---|
3007 | ;'; |
---|
3008 | |
---|
3009 | if ($v = (($t = pwg_db_fetch_row(pwg_query($query))) !== false)) |
---|
3010 | { |
---|
3011 | $user_idsOK = explode(',', $t[0]); |
---|
3012 | $v = (in_array($uid, $user_idsOK)); |
---|
3013 | } |
---|
3014 | return $v; |
---|
3015 | } |
---|
3016 | |
---|
3017 | |
---|
3018 | /** |
---|
3019 | * UAM_UsrReg_Verif |
---|
3020 | * Check if the user who logged-in have validate his registration |
---|
3021 | * |
---|
3022 | * @returns : True if validation is OK else False |
---|
3023 | */ |
---|
3024 | function UAM_UsrReg_Verif($user_id) |
---|
3025 | { |
---|
3026 | global $conf; |
---|
3027 | |
---|
3028 | $query = ' |
---|
3029 | SELECT UAM_validated |
---|
3030 | FROM '.USERS_TABLE.' |
---|
3031 | WHERE id='.$user_id.' |
---|
3032 | ;'; |
---|
3033 | |
---|
3034 | $result = pwg_db_fetch_assoc(pwg_query($query)); |
---|
3035 | |
---|
3036 | if($result['UAM_validated'] == 'true' or is_null($result['UAM_validated'])) |
---|
3037 | { |
---|
3038 | return true; |
---|
3039 | } |
---|
3040 | else return false; |
---|
3041 | } |
---|
3042 | |
---|
3043 | |
---|
3044 | /** |
---|
3045 | * SetUnvalidated |
---|
3046 | * Set UAM_validated field to false in #_users table |
---|
3047 | * |
---|
3048 | **/ |
---|
3049 | function SetUnvalidated($user_id) |
---|
3050 | { |
---|
3051 | $query =' |
---|
3052 | UPDATE '.USERS_TABLE.' |
---|
3053 | SET UAM_validated = "false" |
---|
3054 | WHERE id = '.$user_id.' |
---|
3055 | LIMIT 1 |
---|
3056 | ;'; |
---|
3057 | |
---|
3058 | pwg_query($query); |
---|
3059 | } |
---|
3060 | |
---|
3061 | |
---|
3062 | /** |
---|
3063 | * SetValidated |
---|
3064 | * Set UAM_validated field to true in #_users table |
---|
3065 | * |
---|
3066 | **/ |
---|
3067 | function SetValidated($user_id) |
---|
3068 | { |
---|
3069 | $query =' |
---|
3070 | UPDATE '.USERS_TABLE.' |
---|
3071 | SET UAM_validated = "true" |
---|
3072 | WHERE id = '.$user_id.' |
---|
3073 | LIMIT 1 |
---|
3074 | ;'; |
---|
3075 | |
---|
3076 | pwg_query($query); |
---|
3077 | } |
---|
3078 | |
---|
3079 | |
---|
3080 | /** |
---|
3081 | * UAM specific database dump (only for MySql !) |
---|
3082 | * Creates an SQL dump of UAM specific tables and configuration settings |
---|
3083 | * |
---|
3084 | * @returns : Boolean to manage appropriate message display |
---|
3085 | * |
---|
3086 | */ |
---|
3087 | function UAM_dump($download) |
---|
3088 | { |
---|
3089 | global $conf; |
---|
3090 | |
---|
3091 | $plugin = PluginInfos(UAM_PATH); |
---|
3092 | $version = $plugin['version']; |
---|
3093 | |
---|
3094 | // Initial backup folder creation and file initialisation |
---|
3095 | // ------------------------------------------------------ |
---|
3096 | if (!is_dir(UAM_PATH.'/include/backup')) |
---|
3097 | mkdir(UAM_PATH.'/include/backup'); |
---|
3098 | |
---|
3099 | $Backup_File = UAM_PATH.'/include/backup/UAM_dbbackup.sql'; |
---|
3100 | |
---|
3101 | $fp = fopen($Backup_File, 'w'); |
---|
3102 | |
---|
3103 | // Writing plugin version |
---|
3104 | $insertions = "-- ".$version." --\n\n"; |
---|
3105 | fwrite($fp, $insertions); |
---|
3106 | |
---|
3107 | // Saving UAM specific tables |
---|
3108 | // -------------------------- |
---|
3109 | $ListTables = array(USER_CONFIRM_MAIL_TABLE, USER_LASTVISIT_TABLE); |
---|
3110 | $j=0; |
---|
3111 | |
---|
3112 | while($j < count($ListTables)) |
---|
3113 | { |
---|
3114 | $sql = 'SHOW CREATE TABLE '.$ListTables[$j]; |
---|
3115 | $res = pwg_query($sql); |
---|
3116 | |
---|
3117 | if ($res) |
---|
3118 | { |
---|
3119 | $insertions = "-- -------------------------------------------------------\n"; |
---|
3120 | $insertions .= "-- Create ".$ListTables[$j]." table\n"; |
---|
3121 | $insertions .= "-- ------------------------------------------------------\n\n"; |
---|
3122 | |
---|
3123 | $insertions .= "DROP TABLE IF EXISTS ".$ListTables[$j].";\n\n"; |
---|
3124 | |
---|
3125 | $array = pwg_db_fetch_row($res); |
---|
3126 | $array[1] .= ";\n\n"; |
---|
3127 | $insertions .= $array[1]; |
---|
3128 | |
---|
3129 | $req_table = pwg_query('DESCRIBE '.$ListTables[$j].';') or die(my_error()); |
---|
3130 | $nb_fields = pwg_db_num_rows($req_table); |
---|
3131 | $req_table2 = pwg_query('SELECT * FROM '.$ListTables[$j]) or die(my_error()); |
---|
3132 | |
---|
3133 | while ($line = pwg_db_fetch_row($req_table2)) |
---|
3134 | { |
---|
3135 | $insertions .= 'INSERT INTO '.$ListTables[$j].' VALUES ('; |
---|
3136 | for ($i=0; $i<$nb_fields; $i++) |
---|
3137 | { |
---|
3138 | $insertions .= '\'' . pwg_db_real_escape_string($line[$i]) . '\', '; |
---|
3139 | } |
---|
3140 | $insertions = substr($insertions, 0, -2); |
---|
3141 | $insertions .= ");\n"; |
---|
3142 | } |
---|
3143 | $insertions .= "\n\n"; |
---|
3144 | } |
---|
3145 | |
---|
3146 | fwrite($fp, $insertions); |
---|
3147 | $j++; |
---|
3148 | } |
---|
3149 | |
---|
3150 | // Saving UAM configuration |
---|
3151 | // ------------------------ |
---|
3152 | $insertions = "-- -------------------------------------------------------\n"; |
---|
3153 | $insertions .= "-- Insert UAM configuration in ".CONFIG_TABLE."\n"; |
---|
3154 | $insertions .= "-- ------------------------------------------------------\n\n"; |
---|
3155 | |
---|
3156 | fwrite($fp, $insertions); |
---|
3157 | |
---|
3158 | $pattern = "UserAdvManager%"; |
---|
3159 | $req_table = pwg_query('SELECT * FROM '.CONFIG_TABLE.' WHERE param LIKE "'.$pattern.'";') or die(my_error()); |
---|
3160 | $nb_fields = pwg_db_num_rows($req_table); |
---|
3161 | $nb_fields = $nb_fields - 1; // Fix the number of fields because pwg_db_num_rows() returns a bad number |
---|
3162 | |
---|
3163 | while ($line = pwg_db_fetch_row($req_table)) |
---|
3164 | { |
---|
3165 | $insertions = 'INSERT INTO '.CONFIG_TABLE.' VALUES ('; |
---|
3166 | for ($i=0; $i<$nb_fields; $i++) |
---|
3167 | { |
---|
3168 | $insertions .= '\'' . pwg_db_real_escape_string($line[$i]) . '\', '; |
---|
3169 | } |
---|
3170 | $insertions = substr($insertions, 0, -2); |
---|
3171 | $insertions .= ");\n"; |
---|
3172 | |
---|
3173 | fwrite($fp, $insertions); |
---|
3174 | } |
---|
3175 | |
---|
3176 | fclose($fp); |
---|
3177 | |
---|
3178 | // Download generated dump file |
---|
3179 | // ---------------------------- |
---|
3180 | if ($download == 'true') |
---|
3181 | { |
---|
3182 | if (@filesize($Backup_File)) |
---|
3183 | { |
---|
3184 | $http_headers = array( |
---|
3185 | 'Content-Length: '.@filesize($Backup_File), |
---|
3186 | 'Content-Type: text/x-sql', |
---|
3187 | 'Content-Disposition: attachment; filename="UAM_dbbackup.sql";', |
---|
3188 | 'Content-Transfer-Encoding: binary', |
---|
3189 | ); |
---|
3190 | |
---|
3191 | foreach ($http_headers as $header) |
---|
3192 | { |
---|
3193 | header($header); |
---|
3194 | } |
---|
3195 | |
---|
3196 | @readfile($Backup_File); |
---|
3197 | exit(); |
---|
3198 | } |
---|
3199 | } |
---|
3200 | |
---|
3201 | return true; |
---|
3202 | } |
---|
3203 | |
---|
3204 | |
---|
3205 | /** |
---|
3206 | * UAM_Restore_backup_file |
---|
3207 | * Restore backup database file |
---|
3208 | * |
---|
3209 | * @returns : Boolean |
---|
3210 | */ |
---|
3211 | function UAM_Restore_backup_file() |
---|
3212 | { |
---|
3213 | global $prefixeTable, $dblayer, $conf; |
---|
3214 | |
---|
3215 | define('DEFAULT_PREFIX_TABLE', 'piwigo_'); |
---|
3216 | |
---|
3217 | $Backup_File = UAM_PATH.'/include/backup/UAM_dbbackup.sql'; |
---|
3218 | |
---|
3219 | // Cleanup database before restoring |
---|
3220 | // --------------------------------- |
---|
3221 | |
---|
3222 | // Delete UserAdvManager global config in #_config table |
---|
3223 | $q = ' |
---|
3224 | DELETE FROM '.CONFIG_TABLE.' |
---|
3225 | WHERE param="UserAdvManager" |
---|
3226 | ;'; |
---|
3227 | |
---|
3228 | pwg_query($q); |
---|
3229 | |
---|
3230 | // Delete UserAdvManager_ConfirmMail global config in #_config table |
---|
3231 | $q = ' |
---|
3232 | DELETE FROM '.CONFIG_TABLE.' |
---|
3233 | WHERE param="UserAdvManager_ConfirmMail" |
---|
3234 | ;'; |
---|
3235 | |
---|
3236 | pwg_query($q); |
---|
3237 | |
---|
3238 | // Delete UserAdvManager_Redir config in #_config table |
---|
3239 | $q = ' |
---|
3240 | DELETE FROM '.CONFIG_TABLE.' |
---|
3241 | WHERE param="UserAdvManager_Redir" |
---|
3242 | ;'; |
---|
3243 | |
---|
3244 | pwg_query($q); |
---|
3245 | |
---|
3246 | // Delete UserAdvManager_Version config in #_config table |
---|
3247 | $q = ' |
---|
3248 | DELETE FROM '.CONFIG_TABLE.' |
---|
3249 | WHERE param="UserAdvManager_Version" |
---|
3250 | ;'; |
---|
3251 | |
---|
3252 | pwg_query($q); |
---|
3253 | |
---|
3254 | // Restore sql backup file - DROP TABLE queries are executed |
---|
3255 | // --------------------------------------------------------- |
---|
3256 | UAM_execute_sqlfile( |
---|
3257 | $Backup_File, |
---|
3258 | DEFAULT_PREFIX_TABLE, |
---|
3259 | $prefixeTable, |
---|
3260 | $dblayer |
---|
3261 | ); |
---|
3262 | } |
---|
3263 | |
---|
3264 | |
---|
3265 | /** |
---|
3266 | * loads an sql file and executes all queries / Based on Piwigo's original install file |
---|
3267 | * |
---|
3268 | * Before executing a query, $replaced is... replaced by $replacing. This is |
---|
3269 | * useful when the SQL file contains generic words. |
---|
3270 | * |
---|
3271 | * @param string filepath |
---|
3272 | * @param string replaced |
---|
3273 | * @param string replacing |
---|
3274 | * @return void |
---|
3275 | */ |
---|
3276 | function UAM_execute_sqlfile($filepath, $replaced, $replacing, $dblayer) |
---|
3277 | { |
---|
3278 | $sql_lines = file($filepath); |
---|
3279 | $query = ''; |
---|
3280 | foreach ($sql_lines as $sql_line) |
---|
3281 | { |
---|
3282 | $sql_line = trim($sql_line); |
---|
3283 | if (preg_match('/(^--|^$)/', $sql_line)) |
---|
3284 | { |
---|
3285 | continue; |
---|
3286 | } |
---|
3287 | |
---|
3288 | $query.= ' '.$sql_line; |
---|
3289 | |
---|
3290 | // if we reached the end of query, we execute it and reinitialize the |
---|
3291 | // variable "query" |
---|
3292 | if (preg_match('/;$/', $sql_line)) |
---|
3293 | { |
---|
3294 | $query = trim($query); |
---|
3295 | $query = str_replace($replaced, $replacing, $query); |
---|
3296 | if ('mysql' == $dblayer) |
---|
3297 | { |
---|
3298 | if (preg_match('/^(CREATE TABLE .*)[\s]*;[\s]*/im', $query, $matches)) |
---|
3299 | { |
---|
3300 | $query = $matches[1].' DEFAULT CHARACTER SET utf8'.';'; |
---|
3301 | } |
---|
3302 | } |
---|
3303 | pwg_query($query); |
---|
3304 | $query = ''; |
---|
3305 | } |
---|
3306 | } |
---|
3307 | } |
---|
3308 | |
---|
3309 | |
---|
3310 | /** |
---|
3311 | * Delete obsolete files on plugin upgrade |
---|
3312 | * Obsolete files are listed in file obsolete.list |
---|
3313 | * |
---|
3314 | */ |
---|
3315 | function clean_obsolete_files() |
---|
3316 | { |
---|
3317 | if (file_exists(UAM_PATH.'obsolete.list') |
---|
3318 | and $old_files = file(UAM_PATH.'obsolete.list', FILE_IGNORE_NEW_LINES) |
---|
3319 | and !empty($old_files)) |
---|
3320 | { |
---|
3321 | array_push($old_files, 'obsolete.list'); |
---|
3322 | foreach($old_files as $old_file) |
---|
3323 | { |
---|
3324 | $path = UAM_PATH.$old_file; |
---|
3325 | if (is_file($path)) |
---|
3326 | { |
---|
3327 | @unlink($path); |
---|
3328 | } |
---|
3329 | elseif (is_dir($path)) |
---|
3330 | { |
---|
3331 | @rmdir($path); |
---|
3332 | } |
---|
3333 | } |
---|
3334 | } |
---|
3335 | } |
---|
3336 | |
---|
3337 | |
---|
3338 | /** |
---|
3339 | * Function called from maintain.inc.php - to check if database upgrade is needed |
---|
3340 | * |
---|
3341 | * @param : table name |
---|
3342 | * |
---|
3343 | * @return : boolean |
---|
3344 | * |
---|
3345 | */ |
---|
3346 | function table_exist($table) |
---|
3347 | { |
---|
3348 | $query = 'DESC '.$table.';'; |
---|
3349 | return (bool)($res=pwg_query($query)); |
---|
3350 | } |
---|
3351 | |
---|
3352 | |
---|
3353 | /** |
---|
3354 | * Function called from UAM_admin.php and main.inc.php to get the plugin version and name |
---|
3355 | * |
---|
3356 | * @param : plugin directory |
---|
3357 | * |
---|
3358 | * @return : plugin's version and name |
---|
3359 | * |
---|
3360 | */ |
---|
3361 | function PluginInfos($dir) |
---|
3362 | { |
---|
3363 | $path = $dir; |
---|
3364 | |
---|
3365 | $plg_data = implode( '', file($path.'main.inc.php') ); |
---|
3366 | if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) ) |
---|
3367 | { |
---|
3368 | $plugin['name'] = trim( $val[1] ); |
---|
3369 | } |
---|
3370 | if (preg_match("|Version: (.*)|", $plg_data, $val)) |
---|
3371 | { |
---|
3372 | $plugin['version'] = trim($val[1]); |
---|
3373 | } |
---|
3374 | if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) ) |
---|
3375 | { |
---|
3376 | $plugin['uri'] = trim($val[1]); |
---|
3377 | } |
---|
3378 | if ($desc = load_language('description.txt', $path.'/', array('return' => true))) |
---|
3379 | { |
---|
3380 | $plugin['description'] = trim($desc); |
---|
3381 | } |
---|
3382 | elseif ( preg_match("|Description: (.*)|", $plg_data, $val) ) |
---|
3383 | { |
---|
3384 | $plugin['description'] = trim($val[1]); |
---|
3385 | } |
---|
3386 | if ( preg_match("|Author: (.*)|", $plg_data, $val) ) |
---|
3387 | { |
---|
3388 | $plugin['author'] = trim($val[1]); |
---|
3389 | } |
---|
3390 | if ( preg_match("|Author URI: (.*)|", $plg_data, $val) ) |
---|
3391 | { |
---|
3392 | $plugin['author uri'] = trim($val[1]); |
---|
3393 | } |
---|
3394 | if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid=')) |
---|
3395 | { |
---|
3396 | list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']); |
---|
3397 | if (is_numeric($extension)) $plugin['extension'] = $extension; |
---|
3398 | } |
---|
3399 | // IMPORTANT SECURITY ! |
---|
3400 | // -------------------- |
---|
3401 | $plugin = array_map('htmlspecialchars', $plugin); |
---|
3402 | |
---|
3403 | return $plugin ; |
---|
3404 | } |
---|
3405 | |
---|
3406 | |
---|
3407 | /** |
---|
3408 | * Useful for debugging - 4 vars can be set |
---|
3409 | * Output result to log.txt file |
---|
3410 | * |
---|
3411 | */ |
---|
3412 | function UAMLog($var1, $var2, $var3, $var4) |
---|
3413 | { |
---|
3414 | $fo=fopen (UAM_PATH.'log.txt','a') ; |
---|
3415 | fwrite($fo,"======================\n") ; |
---|
3416 | fwrite($fo,'le ' . date('D, d M Y H:i:s') . "\r\n"); |
---|
3417 | fwrite($fo,$var1 ."\r\n") ; |
---|
3418 | fwrite($fo,$var2 ."\r\n") ; |
---|
3419 | fwrite($fo,$var3 ."\r\n") ; |
---|
3420 | fwrite($fo,$var4 ."\r\n") ; |
---|
3421 | fclose($fo) ; |
---|
3422 | } |
---|
3423 | |
---|
3424 | ?> |
---|