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