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

Last change on this file since 6754 was 6754, checked in by Eric, 14 years ago
  • Bug 1656 fixed: New ability to manually validate new registers
  • Language files updated - Some DE, ES and IT translation are missing
  • Property svn:eol-style set to LF
File size: 30.6 KB
Line 
1<?php
2include_once (UAM_PATH.'include/constants.php');
3load_language('plugin.lang', UAM_PATH);
4
5/* Function called from main.inc.php to send validation email */
6function SendMail2User($typemail, $id, $username, $password, $email, $confirm)
7{
8  /* Only available for next Piwigo release (bug in switch_lang function) */
9  global $conf;
10
11  $conf_UAM = unserialize($conf['UserAdvManager']);
12 
13        include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
14 
15        $infos1_perso = "";
16  $infos2_perso = "";
17
18/* We have to get the user's language in database */
19  $query ='
20SELECT user_id, language
21FROM '.USER_INFOS_TABLE.'
22WHERE user_id = '.$id.'
23;';
24  $data = pwg_db_fetch_assoc(pwg_query($query));
25
26/* Check if user is already registered (profile changing) - If not (new registration), language is set to current gallery language */
27  if (empty($data))
28  {
29/* And switch gallery to this language before using personalized and multilangual contents */
30    $language = pwg_get_session_var( 'lang_switch', $user['language'] );
31    switch_lang_to($language);
32  }
33  else
34  {
35/* And switch gallery to this language before using personalized and multilangual contents */
36    $language = $data['language']; /* Usefull for debugging */
37    switch_lang_to($data['language']);
38    load_language('plugin.lang', UAM_PATH);
39  }
40
41  switch($typemail)
42  {
43    case 1:
44      $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Add of %s', stripslashes($username)));
45      $password = $password <> '' ? $password : l10n('UAM_empty_pwd');
46     
47      if (isset($conf_UAM[9]) and $conf_UAM[9] <> '')
48      {
49        if (function_exists('get_user_language_desc'))
50        {
51          $infos1_perso = get_user_language_desc($conf_UAM[9])."\n\n";
52        }
53        else $infos1_perso = l10n($conf_UAM[9])."\n\n"; 
54      }
55     
56      break;
57     
58    case 2:
59      $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Update of %s', stripslashes($username)));
60      $password = $password <> '' ? $password : l10n('UAM_empty_pwd');
61
62      break;
63       
64    case 3:
65      $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Update of %s', stripslashes($username)));
66      $password = $password <> '' ? $password : l10n('UAM_no_update_pwd');
67
68      break;
69  }
70
71  if (isset($conf_UAM[0]) and $conf_UAM[0] == 'true')
72  {
73    $infos1 = array(
74      get_l10n_args('infos_mail %s', stripslashes($username)),
75      get_l10n_args('User: %s', stripslashes($username)),
76      get_l10n_args('Password: %s', $password),
77      get_l10n_args('Email: %s', $email),
78      get_l10n_args('', ''),
79    );
80  }
81
82
83  if ( isset($conf_UAM[1]) and $conf_UAM[1] == 'true' and $confirm)
84  {
85    $infos2 = array
86    (
87      get_l10n_args('Link: %s', AddConfirmMail($id, $email)),
88      get_l10n_args('', ''),
89    );
90
91    if (isset($conf_UAM[10]) and $conf_UAM[10] <> '')
92    {
93      if (function_exists('get_user_language_desc'))
94      {
95        $infos2_perso = get_user_language_desc($conf_UAM[10])."\n\n";
96      }
97      else $infos2_perso = l10n($conf_UAM[10])."\n\n";
98    }
99  }
100
101/* ******************************************************** */
102/* **** Pending code since to find how to make it work **** */
103/* ******************************************************** */
104// Testing if FCK Editor is used. Then decoding htmlchars to avoid problems with pwg_mail()
105/*$areas = array();
106array_push( $areas,'UAM_MailInfo_Text','UAM_ConfirmMail_Text');
107
108if (function_exists('set_fckeditor_instance'))
109{
110  $fcke_config = unserialize($conf['FCKEditor']);
111  foreach($areas as $area)
112  {
113    if (isset($fcke_config['UAM_MailInfo_Text']) and $fcke_config['UAM_MailInfo_Text'] = true)
114    {
115      $infos1_perso = html_entity_decode($infos1_perso,ENT_QUOTES,UTF-8);
116    }
117   
118    if (isset($fcke_config['UAM_ConfirmMail_Text']) and $fcke_config['UAM_ConfirmMail_Text'] = true)
119    {
120      $infos2_perso = html_entity_decode($infos2_perso,ENT_QUOTES,UTF-8);
121    }
122  }
123}*/
124
125
126/* Sending the email with subject and contents */
127  pwg_mail($email, array(
128    'subject' => $subject,
129    'content' => (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "").get_absolute_root_url(),
130  ));
131
132/* ********************** */
133/* Email sending debugger */
134/* This is only to trace  */
135/* the send of emails for */
136/* debugging              */
137/* ********************** */
138//$content = (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "").get_absolute_root_url();   
139//MailLog($email,$subject,$content,$language);
140/* ********************** */
141
142/* Switching back to default language */
143switch_lang_back();
144}
145
146
147/* Function called from UAM_admin.php to resend validation email with or without new validation key */
148function ResendMail2User($typemail, $user_id, $username, $email, $confirm)
149{
150  /* Only available for next Piwigo release (bug in switch_lang function) */
151  global $conf;
152
153  $conf_UAM = unserialize($conf['UserAdvManager']);
154
155  $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']);
156 
157        include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
158 
159        $infos1_perso = "";
160  $infos2_perso = "";
161 
162/* We have to get the user's language in database */
163  $query ='
164SELECT user_id, language
165FROM '.USER_INFOS_TABLE.'
166WHERE user_id = '.$user_id.'
167;';
168  $data = pwg_db_fetch_assoc(pwg_query($query));
169  $language = $data['language'];
170 
171/* And switch gallery to this language before using personalized and multilangual contents */
172  switch_lang_to($data['language']);
173   
174  load_language('plugin.lang', UAM_PATH);
175
176  switch($typemail)
177  {
178    case 1:
179      $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Reminder_with_key_of_%s', $username));
180     
181      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)
182      {
183        if (function_exists('get_user_language_desc'))
184        {
185          $infos1 = get_user_language_desc($conf_UAM_ConfirmMail[2])."\n\n";
186        }
187                                else $infos1 = l10n($conf_UAM_ConfirmMail[2])."\n\n";
188
189        $infos2 = array
190        (
191          get_l10n_args('Link: %s', ResetConfirmMail($user_id)),
192          get_l10n_args('', ''),
193        );       
194                        }
195
196/* Set reminder true */     
197      $query = "
198UPDATE ".USER_CONFIRM_MAIL_TABLE."
199SET reminder = 'true'
200WHERE user_id = '".$user_id."'
201;";
202      pwg_query($query);
203     
204                break;
205     
206    case 2:
207      $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Reminder_without_key_of_%s',$username));
208     
209      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)
210      {
211        if (function_exists('get_user_language_desc'))
212        {
213          $infos1 = get_user_language_desc($conf_UAM_ConfirmMail[2])."\n\n";
214        }
215        else $infos1 = l10n($conf_UAM_ConfirmMail[2])."\n\n";
216      }
217     
218/* Set reminder true */     
219      $query = "
220UPDATE ".USER_CONFIRM_MAIL_TABLE."
221SET reminder = 'true'
222WHERE user_id = '".$user_id."'
223;";
224      pwg_query($query);
225     
226    break;
227        }
228 
229  pwg_mail($email, array(
230    'subject' => $subject,
231    'content' => ($infos1."\n\n").(isset($infos2) ? l10n_args($infos2)."\n\n" : "").get_absolute_root_url(),
232  ));
233
234/* ********************** */
235/* Email sending debugger */
236/* This is only to trace  */
237/* the send of emails for */
238/* debugging              */
239/* ********************** */
240//$content = ($infos1."\n\n").(isset($infos2) ? l10n_args($infos2)."\n\n" : "").get_absolute_root_url();
241//MailLog($email,$subject,$content,$language);
242/* ********************** */
243
244/* Switching back to default language */
245switch_lang_back();
246}
247
248
249/* Function called from UAM_admin.php to send a reminder mail for ghost users */
250function ghostreminder($user_id, $username, $email)
251{
252  /* Only available for next Piwigo release (bug in switch_lang function) */
253  global $conf;
254
255  $conf_UAM = unserialize($conf['UserAdvManager']);
256 
257        include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
258 
259        $infos1_perso = "";
260
261/* We have to get the user's language in database */
262  $query ='
263SELECT user_id, language
264FROM '.USER_INFOS_TABLE.'
265WHERE user_id = '.$user_id.'
266;';
267  $data = pwg_db_fetch_assoc(pwg_query($query));
268  $language = $data['language'];
269
270/* And switch gallery to this language before using personalized and multilangual contents */
271  switch_lang_to($data['language']);
272   
273  load_language('plugin.lang', UAM_PATH);
274 
275  $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Ghost_reminder_of_%s', $username));     
276
277  if (isset($conf_UAM[18]) and $conf_UAM[18] <> '' and isset($conf_UAM[16]) and $conf_UAM[16] == 'true')
278  {
279    if (function_exists('get_user_language_desc'))
280    {
281      $infos1 = get_user_language_desc($conf_UAM[18])."\n\n";
282    }
283    else
284    {
285      $infos1 = l10n($conf_UAM[18])."\n\n";
286    }
287
288    resetlastvisit($user_id);
289  }
290
291  pwg_mail($email, array(
292    'subject' => $subject,
293    'content' => $infos1.get_absolute_root_url(),
294  ));
295
296/* ********************** */
297/* Email sending debugger */
298/* This is only to trace  */
299/* the send of emails for */
300/* debugging              */
301/* ********************** */
302//$content = get_user_language_desc($conf_UAM[19])."\n\n"; 
303//MailLog($email,$subject,$content,$language);
304/* ********************** */
305
306/* Switching back to default language */
307switch_lang_back();
308}
309
310
311/* Function called from functions AddConfirmMail and ResetConfirmMail for validation key generation */
312function FindAvailableConfirmMailID()
313{
314  while (true)
315  {
316    $id = generate_key(16);
317    $query = "
318SELECT COUNT(*)
319  FROM ".USER_CONFIRM_MAIL_TABLE."
320WHERE id = '".$id."'
321;";
322    list($count) = pwg_db_fetch_row(pwg_query($query));
323
324    if ($count == 0)
325      return $id;
326  }
327}
328
329
330/* Function called from functions SendMail2User to process unvalidated users and generate validation key link */
331function AddConfirmMail($user_id, $email)
332{
333  global $conf;
334
335  $conf_UAM = unserialize($conf['UserAdvManager']);
336  $Confirm_Mail_ID = FindAvailableConfirmMailID();
337
338  list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
339 
340  if (isset($Confirm_Mail_ID))
341  {
342    $query = "
343SELECT status
344  FROM ".USER_INFOS_TABLE."
345WHERE user_id = '".$user_id."'
346;";
347    list($status) = pwg_db_fetch_row(pwg_query($query));
348   
349    $query = "
350INSERT INTO ".USER_CONFIRM_MAIL_TABLE."
351  (id, user_id, mail_address, status, date_check)
352VALUES
353  ('".$Confirm_Mail_ID."', '".$user_id."', '".$email."', '".$status."', null)
354;";
355    pwg_query($query);
356
357    $query = "
358DELETE FROM ".USER_GROUP_TABLE."
359WHERE user_id = '".$user_id."'
360  AND (
361    group_id = '".$conf_UAM[2]."'
362  OR
363    group_id = '".$conf_UAM[3]."'
364  )
365;";
366    pwg_query($query);
367
368    if (!is_admin() and $conf_UAM[8] <> -1)
369    {
370      $query = "
371UPDATE ".USER_INFOS_TABLE."
372SET status = '".$conf_UAM[8]."'
373WHERE user_id = '".$user_id."'
374;";
375      pwg_query($query);
376    }
377
378    if ( $conf_UAM[2] <> -1 )
379    {
380      $query = "
381INSERT INTO ".USER_GROUP_TABLE."
382  (user_id, group_id)
383VALUES
384  ('".$user_id."', '".$conf_UAM[2]."')
385;";
386      pwg_query($query);
387    }
388   
389    return get_absolute_root_url().UAM_PATH.'ConfirmMail.php?key='.$Confirm_Mail_ID;
390  }
391}
392
393
394/* Function called from UAM_admin.php to reset validation key */
395function ResetConfirmMail($user_id)
396{
397  global $conf;
398 
399  $Confirm_Mail_ID = FindAvailableConfirmMailID();
400
401  list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
402 
403  if (isset($Confirm_Mail_ID))
404  { 
405    $query = "
406UPDATE ".USER_CONFIRM_MAIL_TABLE."
407SET id = '".$Confirm_Mail_ID."'
408WHERE user_id = '".$user_id."'
409;";
410    pwg_query($query);
411
412                $query = "
413UPDATE ".USER_INFOS_TABLE."
414SET registration_date = '".$dbnow."'
415WHERE user_id = '".$user_id."'
416;";
417                pwg_query($query);
418   
419    return get_absolute_root_url().UAM_PATH.'ConfirmMail.php?key='.$Confirm_Mail_ID;
420  }
421}
422
423
424/* Function called from function_UserAdvManager.inc.php to reset last visit date after sending a reminder */
425function resetlastvisit($user_id)
426{
427  global $conf;
428
429  list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
430
431  $query = "
432UPDATE ".USER_LASTVISIT_TABLE."
433SET lastvisit = '".$dbnow."', reminder = 'true'
434WHERE user_id = '".$user_id."'
435;";
436  pwg_query($query);
437}
438
439
440/* Function called from main.inc.php - Triggered on user deletion */
441function DeleteConfirmMail($user_id)
442{
443  $query = "
444DELETE FROM ".USER_CONFIRM_MAIL_TABLE."
445WHERE user_id = '".$user_id."'
446;";
447  pwg_query($query);
448}
449
450/* Function called from main.inc.php - Triggered on user deletion */
451function DeleteLastVisit($user_id)
452{
453  $query = "
454DELETE FROM ".USER_LASTVISIT_TABLE."
455WHERE user_id = '".$user_id."'
456;";
457  pwg_query($query);
458}
459
460/* Function called from ConfirmMail.php to verify validation key used by user according time limit */
461function VerifyConfirmMail($id)
462{
463  global $conf;
464
465  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
466 
467  $conf_UAM = unserialize($conf['UserAdvManager']);
468
469  $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']);
470
471  $query = "
472SELECT COUNT(*)
473FROM ".USER_CONFIRM_MAIL_TABLE."
474WHERE id = '".$id."'
475;";
476  list($count) = pwg_db_fetch_row(pwg_query($query));
477
478  if ($count == 1)
479  {
480    $query = "
481SELECT user_id, status, date_check
482FROM ".USER_CONFIRM_MAIL_TABLE."
483WHERE id = '".$id."'
484;";
485    $data = pwg_db_fetch_assoc(pwg_query($query));
486       
487    if (!empty($data) and isset($data['user_id']) and !isset($data['date_check']))
488    {
489      $query = "
490SELECT registration_date
491FROM ".USER_INFOS_TABLE."
492WHERE user_id = '".$data['user_id']."'
493;";
494      list($registration_date) = pwg_db_fetch_row(pwg_query($query));
495
496/*              Time limit process              */
497/* ******************************************** */ 
498      if (!empty($registration_date))
499      {
500                                // Verify Confirmmail with time limit ON
501                                if (isset ($conf_UAM_ConfirmMail[1]))
502                                {
503                                        // dates formating and compare
504                                        $today = date("d-m-Y"); // Get today's date
505                                        list($day, $month, $year) = explode('-', $today); // explode date of today                                               
506                                        $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp
507                       
508                                list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date
509                                        list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date
510                                        $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp
511                       
512                                        $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps     
513                                        $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days
514
515                                        // Condition with the value set for time limit
516                                        if ($deltadays <= $conf_UAM_ConfirmMail[1]) // If Nb of days is less than the limit set
517                                        {
518                                                list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
519
520                                                $query = '
521UPDATE '.USER_CONFIRM_MAIL_TABLE.'
522SET date_check="'.$dbnow.'"
523WHERE id = "'.$id.'"
524;';
525                                                pwg_query($query);
526     
527                                                if ($conf_UAM[2] <> -1) // Delete user from unvalidated users group
528                                                {
529                                                        $query = "
530DELETE FROM ".USER_GROUP_TABLE."
531WHERE user_id = '".$data['user_id']."'
532  AND group_id = '".$conf_UAM[2]."'
533;";
534                                                        pwg_query($query);
535                                                }
536           
537                                                if ($conf_UAM[3] <> -1) // Add user to validated users group
538                                                {
539                                                        $query = "
540INSERT INTO ".USER_GROUP_TABLE."
541  (user_id, group_id)
542VALUES
543  ('".$data['user_id']."', '".$conf_UAM[3]."')
544;";
545                                                        pwg_query($query);
546                                                }
547
548                                                if (($conf_UAM[4] <> -1 or isset($data['status']))) // Change user's status
549                                                {
550                                                        $query = "
551UPDATE ".USER_INFOS_TABLE."
552SET status = '".(isset($data['status']) ? $data['status'] : $conf_UAM[4])."'
553WHERE user_id = '".$data['user_id']."'
554;";
555                                                        pwg_query($query);
556                                                }
557                                                // Refresh user's category cache
558                                                invalidate_user_cache();
559 
560                                                return true;
561                                        }
562                                        elseif ($deltadays > $conf_UAM_ConfirmMail[1]) // If timelimit exeeds
563                                        {
564                                                return false;
565                                        }
566                                }
567                                // Verify Confirmmail with time limit OFF
568                                else
569                                {
570                                        list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
571
572                                        $query = '
573UPDATE '.USER_CONFIRM_MAIL_TABLE.'
574SET date_check="'.$dbnow.'"
575WHERE id = "'.$id.'"
576;';
577                                        pwg_query($query);
578     
579                                        if ($conf_UAM[2] <> -1)
580                                        {
581                                                $query = "
582DELETE FROM ".USER_GROUP_TABLE."
583WHERE user_id = '".$data['user_id']."'
584AND group_id = '".$conf_UAM[2]."'
585;";
586                                                pwg_query($query);
587                                        }
588   
589                                        if ($conf_UAM[3] <> -1)
590                                        {
591                                                $query = "
592DELETE FROM ".USER_GROUP_TABLE."
593WHERE user_id = '".$data['user_id']."'
594AND group_id = '".$conf_UAM[3]."'
595;";
596                                                pwg_query($query);
597
598                                                $query = "
599INSERT INTO ".USER_GROUP_TABLE."
600  (user_id, group_id)
601VALUES
602  ('".$data['user_id']."', '".$conf_UAM[3]."')
603;";
604                                                pwg_query($query);
605                                        }
606
607                                        if (($conf_UAM[4] <> -1 or isset($data['status'])))
608                                        {
609                                                $query = "
610UPDATE ".USER_INFOS_TABLE."
611SET status = '".(isset($data['status']) ? $data['status'] : $conf_UAM[4])."'
612WHERE user_id = '".$data['user_id']."'
613;";
614                                                pwg_query($query);
615                                        }
616                                        // Refresh user's category cache
617                                        invalidate_user_cache();
618 
619                                        return true;
620                                }
621                        }
622                }
623        }
624  else
625    return false;
626}
627
628/* Function called from UAM_admin.php to force users validation by admin */
629function ForceValidation($id)
630{
631  global $conf;
632
633  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
634
635  $conf_UAM = unserialize($conf['UserAdvManager']);
636       
637  $query = "
638SELECT COUNT(*)
639  FROM ".USER_CONFIRM_MAIL_TABLE."
640WHERE user_id = '".$id."'
641;";
642  list($count) = pwg_db_fetch_row(pwg_query($query));
643
644  if ($count == 1)
645  {
646    $query = "
647SELECT user_id, status, date_check
648  FROM ".USER_CONFIRM_MAIL_TABLE."
649WHERE user_id = '".$id."'
650;";
651    $data = pwg_db_fetch_assoc(pwg_query($query));
652
653    if (!empty($data) and isset($data['user_id']) and !isset($data['date_check']))
654    {     
655                        list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
656
657                        $query = "
658UPDATE ".USER_CONFIRM_MAIL_TABLE."
659SET date_check='".$dbnow."'
660WHERE user_id = '".$data['user_id']."'
661;";
662                        pwg_query($query);
663             
664                        if ($conf_UAM[2] <> -1)
665                        {
666                                $query = "
667DELETE FROM ".USER_GROUP_TABLE."
668WHERE user_id = '".$data['user_id']."'
669  AND group_id = '".$conf_UAM[2]."'
670;";
671                                pwg_query($query);
672                        }
673 
674                        if ($conf_UAM[3] <> -1)
675                        {
676                                $query = "
677DELETE FROM ".USER_GROUP_TABLE."
678WHERE user_id = '".$data['user_id']."'
679  AND group_id = '".$conf_UAM[3]."'
680                                ;";
681                                pwg_query($query);
682       
683                                $query = "
684INSERT INTO ".USER_GROUP_TABLE."
685  (user_id, group_id)
686VALUES
687  ('".$data['user_id']."', '".$conf_UAM[3]."')
688;";
689                                pwg_query($query);
690                        }
691
692                        if (($conf_UAM[4] <> -1 or isset($data['status'])))
693                        {
694                                $query = "
695UPDATE ".USER_INFOS_TABLE."
696SET status = '".(isset($data['status']) ? $data['status'] : $conf_UAM[4])."'
697WHERE user_id = '".$data['user_id']."'
698;";
699                                pwg_query($query);
700                        }
701                        // Refresh user's category cache
702                        invalidate_user_cache();
703                        return true;
704                }
705        }
706}
707
708
709/* Function called from main.inc.php - Check if username matches forbidden caracters */
710function ValidateUsername($login)
711{
712  global $conf;
713
714  $conf_UAM = unserialize($conf['UserAdvManager']);
715
716  if (isset($login) and isset($conf_UAM[7]) and $conf_UAM[7] <> '')
717  {
718    $conf_CharExclusion = preg_split("/,/",$conf_UAM[7]);
719    for ($i = 0 ; $i < count($conf_CharExclusion) ; $i++)
720    {
721      $pattern = '/'.$conf_CharExclusion[$i].'/i';
722      if (preg_match($pattern, $login))
723      {
724        return true;
725      }
726    }
727  }
728  else
729  {
730    return false;
731  }
732}
733
734
735/* Function called from main.inc.php - Check if user's email is in excluded email providers list */
736/* Doesn't work on call - Must be copied in main.inc.php to work */
737function ValidateEmailProvider($email)
738{
739  global $conf;
740
741  $conf_UAM = unserialize($conf['UserAdvManager']);
742 
743        if (isset($email) and isset($conf_UAM[12]) and $conf_UAM[12] <> '')
744        {
745                //$ncsemail = strtolower($email);
746                $conf_MailExclusion = preg_split("/[\s,]+/",$conf_UAM[12]);
747                for ($i = 0 ; $i < count($conf_MailExclusion) ; $i++)
748                {
749                        $pattern = '/'.$conf_MailExclusion[$i].'/i';
750                        if (preg_match($pattern, $email))
751      {
752                        return true;
753      }
754                }
755        }
756  else
757  {
758    return false;
759  }
760}
761
762
763/* Function called from UserAdvManager.php - Get unvalidated users according time limit */
764function get_unvalid_user_list()
765{
766        global $conf, $page;
767         
768        /* Get ConfirmMail configuration */
769  $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']);
770  /* Get UAM configuration */
771  $conf_UAM = unserialize($conf['UserAdvManager']);
772 
773  $users = array();
774
775        /* search users depending expiration date */
776  $query = '
777SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
778                u.'.$conf['user_fields']['username'].' AS username,
779                u.'.$conf['user_fields']['email'].' AS email,
780                ui.status,
781                ui.adviser,
782                ui.enabled_high,
783                ui.level,
784                ui.registration_date
785FROM '.USERS_TABLE.' AS u
786  INNER JOIN '.USER_INFOS_TABLE.' AS ui
787    ON u.'.$conf['user_fields']['id'].' = ui.user_id
788  LEFT JOIN '.USER_GROUP_TABLE.' AS ug
789    ON u.'.$conf['user_fields']['id'].' = ug.user_id
790WHERE u.'.$conf['user_fields']['id'].' >= 3
791  AND (TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) >= "'.$conf_UAM_ConfirmMail[1].'"
792  OR TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) < "'.$conf_UAM_ConfirmMail[1].'")';
793
794        if ($conf_UAM[2] <> '-1' and $conf_UAM[8] == '-1')
795  {
796    $query.= '
797  AND ug.group_id = '.$conf_UAM[2];
798  }
799  if ($conf_UAM[2] == '-1' and $conf_UAM[8] <> '-1')
800  {
801    $query.= '
802  AND ui.status = \''.$conf_UAM[8]."'";
803  }
804  if ($conf_UAM[2] <> '-1' and $conf_UAM[8] <> '-1')
805  {
806    $query.= '
807  AND ug.group_id = \''.$conf_UAM[2]."'";
808  }
809  $query.= '
810ORDER BY ui.registration_date ASC
811;';
812
813        $result = pwg_query($query);
814     
815  while ($row = pwg_db_fetch_assoc($result))
816  {
817        $user = $row;
818    $user['groups'] = array();
819
820    array_push($users, $user);
821        }
822
823        /* add group lists */
824  $user_ids = array();
825  foreach ($users as $i => $user)
826  {
827        $user_ids[$i] = $user['id'];
828        }
829       
830        $user_nums = array_flip($user_ids);
831
832  if (count($user_ids) > 0)
833  {
834        $query = '
835SELECT user_id, group_id
836  FROM '.USER_GROUP_TABLE.'
837WHERE user_id IN ('.implode(',', $user_ids).')
838;';
839       
840                $result = pwg_query($query);
841       
842    while ($row = pwg_db_fetch_assoc($result))
843    {
844        array_push(
845        $users[$user_nums[$row['user_id']]]['groups'],
846        $row['group_id']
847                        );
848                }
849        }
850
851        return $users;
852}
853
854
855/* Function called from UserAdvManager.php - Get ghost users */
856function get_ghost_user_list()
857{
858        global $conf, $page;
859
860  $conf_UAM = unserialize($conf['UserAdvManager']);
861 
862  $users = array();
863
864        /* search users depending expiration date */
865  $query = '
866SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
867                u.'.$conf['user_fields']['username'].' AS username,
868                u.'.$conf['user_fields']['email'].' AS email,
869                lv.lastvisit,
870                lv.reminder
871FROM '.USERS_TABLE.' AS u
872  INNER JOIN '.USER_LASTVISIT_TABLE.' AS lv
873    ON u.'.$conf['user_fields']['id'].' = lv.user_id
874WHERE (TO_DAYS(NOW()) - TO_DAYS(lv.lastvisit) >= "'.$conf_UAM[17].'")
875ORDER BY lv.lastvisit ASC;';
876
877        $result = pwg_query($query);
878     
879  while ($row = pwg_db_fetch_assoc($result))
880  {
881        $user = $row;
882    $user['groups'] = array();
883
884    array_push($users, $user);
885        }
886
887        /* add group lists */
888  $user_ids = array();
889  foreach ($users as $i => $user)
890  {
891        $user_ids[$i] = $user['id'];
892        }
893
894        return $users;
895}
896
897
898/* Function called from UserAdvManager.php - Get all users to display the number of days since their last visit */
899function get_user_list()
900{
901        global $conf, $page;
902 
903  $users = array();
904
905        /* search users depending expiration date */
906  $query = '
907SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
908                u.'.$conf['user_fields']['username'].' AS username,
909                u.'.$conf['user_fields']['email'].' AS email,
910                ug.lastvisit
911FROM '.USERS_TABLE.' AS u
912  INNER JOIN '.USER_LASTVISIT_TABLE.' AS ug
913    ON u.'.$conf['user_fields']['id'].' = ug.user_id
914WHERE u.'.$conf['user_fields']['id'].' >= 3
915ORDER BY ug.lastvisit DESC
916;';
917
918        $result = pwg_query($query);
919     
920  while ($row = pwg_db_fetch_assoc($result))
921  {
922        $user = $row;
923    $user['groups'] = array();
924
925    array_push($users, $user);
926        }
927
928        /* add group lists */
929  $user_ids = array();
930  foreach ($users as $i => $user)
931  {
932        $user_ids[$i] = $user['id'];
933        }
934
935        return $users;
936}
937
938
939/* Function called from UserAdvManager.php - to determine who is expired or not and giving a different display color */
940function expiration($id)
941{
942        global $conf, $page;
943         
944        /* Get ConfirmMail configuration */
945  $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']);
946         
947        /* Get UAM configuration */
948  $conf_UAM = unserialize($conf['UserAdvManager']);
949       
950        $query = "
951SELECT registration_date
952  FROM ".USER_INFOS_TABLE."
953WHERE user_id = '".$id."'
954;";
955        list($registration_date) = pwg_db_fetch_row(pwg_query($query));
956
957/*              Time limit process              */
958/* ******************************************** */ 
959        if (!empty($registration_date))
960  {
961                // dates formating and compare
962                $today = date("d-m-Y"); // Get today's date
963                list($day, $month, $year) = explode('-', $today); // explode date of today                                               
964                $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp
965               
966          list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date
967                list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date
968                $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp
969                       
970                $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps     
971                $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days
972
973                // Condition with the value set for time limit
974                if ($deltadays <= $conf_UAM_ConfirmMail[1]) // If Nb of days is less than the limit set
975                {
976                        return false;
977                }
978                else
979                {
980                        return true;
981                }
982        }
983}
984
985
986/**
987 * Returns a password's score for password complexity check
988 *
989 * @param password filled by user
990 *
991 * Thanx to MathieuGut from http://m-gut.developpez.com
992 */
993function testpassword($password) // Le mot de passe passé en paramètre - $password given by user
994{
995
996  // Initialisation des variables - Variables initiation
997  $points = 0;
998  $point_lowercase = 0;
999  $point_uppercase = 0;
1000  $point_numbers = 0;
1001  $point_characters = 0;
1002
1003  // On récupère la longueur du mot de passe - Getting password lengh   
1004  $length = strlen($password);
1005 
1006  // On fait une boucle pour lire chaque lettre - Loop to read password characters
1007  for($i = 0; $i < $length; $i++)
1008  {
1009    // On sélectionne une à une chaque lettre - Select each letters
1010    // $i étant à 0 lors du premier passage de la boucle - $i is 0 at first turn
1011    $letters = $password[$i];
1012
1013    if ($letters>='a' && $letters<='z')
1014    {
1015      // On ajoute 1 point pour une minuscule - Adding 1 point to score for a lowercase
1016                  $points = $points + 1;
1017
1018                  // On rajoute le bonus pour une minuscule - Adding bonus points for lowercase
1019                  $point_lowercase = 1;
1020    }
1021    else if ($letters>='A' && $letters <='Z')
1022    {
1023      // On ajoute 2 points pour une majuscule - Adding 2 points to score for uppercase
1024      $points = $points + 2;
1025               
1026      // On rajoute le bonus pour une majuscule - Adding bonus points for uppercase
1027      $point_uppercase = 2;
1028    }
1029    else if ($letters>='0' && $letters<='9')
1030    {
1031      // On ajoute 3 points pour un chiffre - Adding 3 points to score for numbers
1032      $points = $points + 3;
1033               
1034      // On rajoute le bonus pour un chiffre - Adding bonus points for numbers
1035      $point_numbers = 3;
1036    }
1037    else
1038    {
1039      // On ajoute 5 points pour un caractère autre - Adding 5 points to score for special characters
1040      $points = $points + 5;
1041               
1042      // On rajoute le bonus pour un caractère autre - Adding bonus points for special characters
1043      $point_characters = 5;
1044    }
1045  }
1046
1047  // Calcul du coefficient points/longueur - calculating the coefficient points/length
1048  $step1 = $points / $length;
1049
1050  // Calcul du coefficient de la diversité des types de caractères... - Calculation of the diversity of character types...
1051  $step2 = $point_lowercase + $point_uppercase + $point_numbers + $point_characters;
1052
1053  // Multiplication du coefficient de diversité avec celui de la longueur - Multiplying the coefficient of diversity with that of the length
1054  $score = $step1 * $step2;
1055
1056  // Multiplication du résultat par la longueur de la chaîne - Multiplying the result by the length of the chain
1057  $finalscore = $score * $length;
1058
1059  return $finalscore;
1060}
1061
1062/* Function called from maintain.inc.php - to check if database upgrade is needed */
1063function table_exist($table)
1064{
1065  $query = 'DESC '.$table.';';
1066  return (bool)($res=pwg_query($query));
1067}
1068
1069/* Email sending debugger function */
1070function MailLog($to, $subject, $content, $language)
1071{
1072   $fo=fopen (UAM_PATH.'admin/maillog.txt','a') ;
1073   fwrite($fo,"======================\n") ;
1074   fwrite($fo,'le ' . date('D, d M Y H:i:s') . "\r\n");
1075   fwrite($fo,$to . "\n" . $subject . "\r\n") ;
1076   fwrite($fo, "\n" . $content . "\r\n") ;
1077   fwrite($fo, 'Langue : '."\n" . $language . "\r\n") ;
1078   fclose($fo) ;
1079   //return mail ($to,$subject) ;
1080}
1081
1082
1083/* Function called from UAM_admin.php and main.inc.php to get the plugin version and name */
1084function PluginInfos($dir)
1085{
1086  $path = $dir;
1087
1088  $plg_data = implode( '', file($path.'main.inc.php') );
1089  if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) )
1090  {
1091    $plugin['name'] = trim( $val[1] );
1092  }
1093  if (preg_match("|Version: (.*)|", $plg_data, $val))
1094  {
1095    $plugin['version'] = trim($val[1]);
1096  }
1097  if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) )
1098  {
1099    $plugin['uri'] = trim($val[1]);
1100  }
1101  if ($desc = load_language('description.txt', $path.'/', array('return' => true)))
1102  {
1103    $plugin['description'] = trim($desc);
1104  }
1105  elseif ( preg_match("|Description: (.*)|", $plg_data, $val) )
1106  {
1107    $plugin['description'] = trim($val[1]);
1108  }
1109  if ( preg_match("|Author: (.*)|", $plg_data, $val) )
1110  {
1111    $plugin['author'] = trim($val[1]);
1112  }
1113  if ( preg_match("|Author URI: (.*)|", $plg_data, $val) )
1114  {
1115    $plugin['author uri'] = trim($val[1]);
1116  }
1117  if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid='))
1118  {
1119    list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']);
1120    if (is_numeric($extension)) $plugin['extension'] = $extension;
1121  }
1122// IMPORTANT SECURITY !
1123  $plugin = array_map('htmlspecialchars', $plugin);
1124
1125  return $plugin ;
1126}
1127
1128
1129function clean_obsolete_files()
1130{
1131  if (file_exists(UAM_PATH.'obsolete.list')
1132    and $old_files = file(UAM_PATH.'obsolete.list', FILE_IGNORE_NEW_LINES)
1133    and !empty($old_files))
1134  {
1135    array_push($old_files, 'obsolete.list');
1136    foreach($old_files as $old_file)
1137    {
1138      $path = UAM_PATH.$old_file;
1139      if (is_file($path))
1140      {
1141        @unlink($path);
1142      }
1143    }
1144  }
1145}
1146?>
Note: See TracBrowser for help on using the repository browser.