root/extensions/NBC_UserAdvManager/trunk/include/functions.inc.php @ 9253

Revision 9253, 59.4 KB (checked in by Eric, 2 years ago)

Bug 2192 fixed
Bug 2045 improvement

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