source: extensions/NBC_UserAdvManager/trunk/include/functions.inc.php @ 9177

Last change on this file since 9177 was 9177, checked in by Eric, 13 years ago

Bug 2188 : Avoid translation flags conflicts

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