source: extensions/UserAdvManager/branches/2.51/include/functions.inc.php @ 25093

Last change on this file since 25093 was 25093, checked in by Eric, 10 years ago

r25092 merged from trunk to branch 2.51 :
Bug 1109 fixed - Password enforcement features have been removed from UAM and set in a new dedicated plugin : Password Policy

Language files cleanup

Bug 2984 fixed - Display issue in Miscellaneous options
Bug 2986 fixed - Status for unvalidated users can not be "Guest" and is forced to "-------"
Bug 2987 fixed - New registered users have to follow a link on confirmation page before log in

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