source: extensions/UserAdvManager/trunk/include/functions.inc.php @ 30347

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

Piwigo 2.6 compliance - Step 34 and final:
Improve confirmation and information email sending workflow

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