source: extensions/UserAdvManager/branches/2.12/include/functions_UserAdvManager.inc.php @ 15907

Last change on this file since 15907 was 4317, checked in by Eric, 14 years ago

[NBC_UserAdvManager] Merged from trunk to branch 2.12
Bug 1238 fixed - Simple custom email text wasn't send when Extended Description plugin wasn't set
Bug 1245 fixed - Semicolons (;) are no longer allowed in text areas (mail info text, ConfirmMail text, reminder text,...). They'll be replaced by dots (.).
Bug 1248 fixed - Php notice on user registration with a forbidden email domain
Bug 1250 fixed - Email provider didn't work after the third exclusion in list

  • Property svn:eol-style set to LF
File size: 26.9 KB
Line 
1<?php
2include_once (NBC_UserAdvManager_PATH.'include/constants.php');
3load_language('plugin.lang', NBC_UserAdvManager_PATH);
4
5/* Function called from main.inc.php to send validation email */
6function SendMail2User($typemail, $id, $username, $password, $email, $confirm)
7{
8  global $conf;
9  load_language('plugin.lang', NBC_UserAdvManager_PATH);
10  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
11 
12        include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
13 
14        $infos1_perso = "";
15  $infos2_perso = "";
16
17  switch($typemail)
18  {
19    case 1:
20      $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Add of %s', stripslashes($username)));
21      $password = $password <> '' ? $password : l10n('UserAdvManager_empty_pwd');
22     
23      if (isset($conf_nbc_UserAdvManager[10]) and $conf_nbc_UserAdvManager[10] <> '')
24      {
25        if (function_exists('get_user_language_desc'))
26        {
27          $infos1_perso = get_user_language_desc($conf_nbc_UserAdvManager[10])."\n\n";
28        }
29        else $infos1_perso = l10n($conf_nbc_UserAdvManager[10])."\n\n"; 
30      }
31     
32      break;
33     
34    case 2:
35      $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Update of %s', stripslashes($username)));
36      $password = $password <> '' ? $password : l10n('UserAdvManager_empty_pwd');
37
38      break;
39       
40    case 3:
41      $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Update of %s', stripslashes($username)));
42      $password = $password <> '' ? $password : l10n('UserAdvManager_no_update_pwd');
43
44      break;
45  }
46
47  if (isset($conf_nbc_UserAdvManager[0]) and $conf_nbc_UserAdvManager[0] == 'true')
48  {
49    $infos1 = array(
50      get_l10n_args('infos_mail %s', stripslashes($username)),
51      get_l10n_args('User: %s', stripslashes($username)),
52      get_l10n_args('Password: %s', $password),
53      get_l10n_args('Email: %s', $email),
54      get_l10n_args('', ''),
55    );
56  }
57
58
59  if ( isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2] == 'true' and $confirm)
60  {
61    $infos2 = array
62    (
63      get_l10n_args('Link: %s', AddConfirmMail($id, $email)),
64      get_l10n_args('', ''),
65    );
66
67    if (isset($conf_nbc_UserAdvManager[11]) and $conf_nbc_UserAdvManager[11] <> '')
68    {
69      if (function_exists('get_user_language_desc'))
70      {
71        $infos2_perso = get_user_language_desc($conf_nbc_UserAdvManager[11])."\n\n";
72      }
73      else $infos2_perso = l10n($conf_nbc_UserAdvManager[11])."\n\n";
74    }
75  }
76
77  pwg_mail($email, array(
78    'subject' => $subject,
79    'content' => (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "").get_absolute_root_url(),
80  ));
81
82/* ********************** */
83/* Email sending debugger */
84/* This is only to trace  */
85/* the send of emails for */
86/* debugging              */
87/* ********************** */ 
88//  MailLog($email,$subject);
89/* ********************** */
90}
91
92
93/* Email sending debugger function */
94//function MailLog  ($to, $subject)
95//{
96//   $fo=fopen (NBC_UserAdvManager_PATH.'admin/maillog.txt','a') ;
97//   fwrite($fo,"======================\n") ;
98//   fwrite($fo,'le ' . date('D, d M Y H:i:s') . "\r\n");
99//   fwrite($fo,$to . "\n" . $subject . "\r\n") ;
100//   fclose($fo) ;
101   //return mail ($to,$subject) ;
102//}
103
104
105/* Function called from UserAdvManager_admin.php to resend validation email with or without new validation key */
106function ResendMail2User($typemail, $user_id, $username, $email, $confirm)
107{
108  global $conf;
109  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
110        $conf_nbc_UserAdvManager_ConfirmMail = isset($conf['nbc_UserAdvManager_ConfirmMail']) ? explode(";" , $conf['nbc_UserAdvManager_ConfirmMail']) : array();
111 
112        include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
113 
114        $infos1_perso = "";
115  $infos2_perso = "";
116
117  switch($typemail)
118  {
119    case 1:
120      $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Reminder_with_key_of_%s', $username));
121     
122      if (isset($conf_nbc_UserAdvManager_ConfirmMail[2]) and $conf_nbc_UserAdvManager_ConfirmMail[2] <> '' and isset($conf_nbc_UserAdvManager_ConfirmMail[3]) and $conf_nbc_UserAdvManager_ConfirmMail[3] == 'true' and $confirm)
123      {
124        if (function_exists('get_user_language_desc'))
125        {
126          $infos1 = get_user_language_desc($conf_nbc_UserAdvManager_ConfirmMail[2])."\n\n";
127        }
128                                else $infos1 = l10n($conf_nbc_UserAdvManager_ConfirmMail[2])."\n\n";
129
130        $infos2 = array
131        (
132          get_l10n_args('Link: %s', ResetConfirmMail($user_id)),
133          get_l10n_args('', ''),
134        );       
135                        }
136     
137                break;
138     
139    case 2:
140      $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Reminder_without_key_of_%s',$username));
141     
142      if (isset($conf_nbc_UserAdvManager_ConfirmMail[2]) and $conf_nbc_UserAdvManager_ConfirmMail[2] <> '' and isset($conf_nbc_UserAdvManager_ConfirmMail[3]) and $conf_nbc_UserAdvManager_ConfirmMail[3] == 'true' and !$confirm)
143      {
144        if (function_exists('get_user_language_desc'))
145        {
146          $infos1 = get_user_language_desc($conf_nbc_UserAdvManager_ConfirmMail[2])."\n\n";
147        }
148        else $infos1 = l10n($conf_nbc_UserAdvManager_ConfirmMail[2])."\n\n";                           
149      }
150     
151    break;
152        }
153 
154  pwg_mail($email, array(
155    'subject' => $subject,
156    'content' => ($infos1."\n\n").(isset($infos2) ? l10n_args($infos2)."\n\n" : "").get_absolute_root_url(),
157  ));
158
159/* ********************** */
160/* Email sending debugger */
161/* This is only to trace  */
162/* the send of emails for */
163/* debugging              */
164/* ********************** */ 
165//  MailLog($email,$subject);
166/* ********************** */
167}
168
169
170/* Function called from UserAdvManager_admin.php to send a reminder mail for ghost users */
171function ghostreminder($user_id, $username, $email)
172{
173  global $conf;
174  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
175 
176        include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
177 
178        $infos1_perso = "";
179
180  $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Ghost_remainder_of_%s', $username));
181     
182  if (isset($conf_nbc_UserAdvManager[19]) and $conf_nbc_UserAdvManager[19] <> '' and isset($conf_nbc_UserAdvManager[17]) and $conf_nbc_UserAdvManager[17] == 'true')
183  {
184    if (function_exists('get_user_language_desc'))
185    {
186      $infos1 = get_user_language_desc($conf_nbc_UserAdvManager[19])."\n\n";
187    }
188    else $infos1 = l10n($conf_nbc_UserAdvManager[19])."\n\n";
189   
190    resetlastvisit($user_id);
191  }
192
193  pwg_mail($email, array(
194    'subject' => $subject,
195    'content' => $infos1.get_absolute_root_url(),
196  ));
197
198/* ********************** */
199/* Email sending debugger */
200/* This is only to trace  */
201/* the send of emails for */
202/* debugging              */
203/* ********************** */ 
204//  MailLog($email,$subject);
205/* ********************** */
206}
207
208
209/* Function called from functions AddConfirmMail and ResetConfirmMail for validation key generation */
210function FindAvailableConfirmMailID()
211{
212  while (true)
213  {
214    $id = generate_key(16);
215    $query = "
216SELECT COUNT(*)
217  FROM ".USER_CONFIRM_MAIL_TABLE."
218WHERE id = '".$id."'
219;";
220    list($count) = mysql_fetch_row(pwg_query($query));
221
222    if ($count == 0)
223      return $id;
224  }
225}
226
227
228/* Function called from functions SendMail2User to process unvalidated users and generate validation key link */
229function AddConfirmMail($user_id, $email)
230{
231  global $conf;
232  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
233  $Confirm_Mail_ID = FindAvailableConfirmMailID();
234
235  list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
236 
237  if (isset($Confirm_Mail_ID))
238  {
239    $query = "
240SELECT status
241  FROM ".USER_INFOS_TABLE."
242WHERE user_id = '".$user_id."'
243;";
244    list($status) = mysql_fetch_row(pwg_query($query));
245   
246    $query = "
247INSERT INTO ".USER_CONFIRM_MAIL_TABLE."
248  (id, user_id, mail_address, status, date_check)
249VALUES
250  ('".$Confirm_Mail_ID."', '".$user_id."', '".$email."', '".$status."', null)
251;";
252    pwg_query($query);
253
254    $query = "
255DELETE FROM ".USER_GROUP_TABLE."
256WHERE user_id = '".$user_id."'
257  AND (
258    group_id = '".$conf_nbc_UserAdvManager[3]."'
259  OR
260    group_id = '".$conf_nbc_UserAdvManager[4]."'
261  )
262;";
263    pwg_query($query);
264
265    if (!is_admin() and $conf_nbc_UserAdvManager[9] <> -1)
266    {
267      $query = "
268UPDATE ".USER_INFOS_TABLE."
269SET status = '".$conf_nbc_UserAdvManager[9]."'
270WHERE user_id = '".$user_id."'
271;";
272      pwg_query($query);
273    }
274
275    if ( $conf_nbc_UserAdvManager[3] <> -1 )
276    {
277      $query = "
278INSERT INTO ".USER_GROUP_TABLE."
279  (user_id, group_id)
280VALUES
281  ('".$user_id."', '".$conf_nbc_UserAdvManager[3]."')
282;";
283      pwg_query($query);
284    }
285   
286    return get_absolute_root_url().NBC_UserAdvManager_PATH.'ConfirmMail.php?key='.$Confirm_Mail_ID;
287  }
288}
289
290
291/* Function called from UserAdvManager_admin.php to reset validation key */
292function ResetConfirmMail($user_id)
293{
294  global $conf;
295 
296  $Confirm_Mail_ID = FindAvailableConfirmMailID();
297
298  list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
299 
300  if (isset($Confirm_Mail_ID))
301  { 
302    $query = "
303UPDATE ".USER_CONFIRM_MAIL_TABLE."
304SET id = '".$Confirm_Mail_ID."'
305WHERE user_id = '".$user_id."'
306;";
307    pwg_query($query);
308
309                $query = "
310UPDATE ".USER_INFOS_TABLE."
311SET registration_date = '".$dbnow."'
312WHERE user_id = '".$user_id."'
313;";
314                pwg_query($query);
315   
316    return get_absolute_root_url().NBC_UserAdvManager_PATH.'ConfirmMail.php?key='.$Confirm_Mail_ID;
317  }
318}
319
320
321/* Function called from function_UserAdvManager.inc.php to reset last visit date after sending a reminder */
322function resetlastvisit($user_id)
323{
324  global $conf;
325
326  list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
327
328  $query = "
329UPDATE ".USER_LASTVISIT_TABLE."
330SET lastvisit = '".$dbnow."', reminder = 'true'
331WHERE user_id = '".$user_id."'
332;";
333  pwg_query($query);
334}
335
336
337/* Function called from main.inc.php - Triggered on user deletion */
338function DeleteConfirmMail($user_id)
339{
340  $query = "
341DELETE FROM ".USER_CONFIRM_MAIL_TABLE."
342WHERE user_id = '".$user_id."'
343;";
344  pwg_query($query);
345}
346
347/* Function called from main.inc.php - Triggered on user deletion */
348function DeleteLastVisit($user_id)
349{
350  $query = "
351DELETE FROM ".USER_LASTVISIT_TABLE."
352WHERE user_id = '".$user_id."'
353;";
354  pwg_query($query);
355}
356
357/* Function called from ConfirmMail.php to verify validation key used by user according time limit */
358function VerifyConfirmMail($id)
359{
360  global $conf;
361
362  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
363 
364  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
365  $conf_nbc_UserAdvManager_ConfirmMail = isset($conf['nbc_UserAdvManager_ConfirmMail']) ? explode(";" , $conf['nbc_UserAdvManager_ConfirmMail']) : array();
366
367  $query = "
368SELECT COUNT(*)
369FROM ".USER_CONFIRM_MAIL_TABLE."
370WHERE id = '".$id."'
371;";
372  list($count) = mysql_fetch_row(pwg_query($query));
373
374  if ($count == 1)
375  {
376    $query = "
377SELECT user_id, status, date_check
378FROM ".USER_CONFIRM_MAIL_TABLE."
379WHERE id = '".$id."'
380;";
381    $data = mysql_fetch_assoc(pwg_query($query));
382       
383    if (!empty($data) and isset($data['user_id']) and !isset($data['date_check']))
384    {
385      $query = "
386SELECT registration_date
387FROM ".USER_INFOS_TABLE."
388WHERE user_id = '".$data['user_id']."'
389;";
390      list($registration_date) = mysql_fetch_row(pwg_query($query));
391
392/*              Time limit process              */
393/* ****************** begin ******************* */ 
394      if (!empty($registration_date))
395      {
396                                // Verify Confirmmail with time limit ON
397                                if (isset ($conf_nbc_UserAdvManager_ConfirmMail[1]))
398                                {
399                                        // dates formating and compare
400                                        $today = date("d-m-Y"); // Get today's date
401                                        list($day, $month, $year) = explode('-', $today); // explode date of today                                               
402                                        $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp
403                       
404                                list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date
405                                        list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date
406                                        $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp
407                       
408                                        $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps     
409                                        $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days
410
411                                        // Condition with the value set for time limit
412                                        if ($deltadays <= $conf_nbc_UserAdvManager_ConfirmMail[1]) // If Nb of days is less than the limit set
413                                        {
414                                                list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
415
416                                                $query = '
417UPDATE '.USER_CONFIRM_MAIL_TABLE.'
418SET date_check="'.$dbnow.'"
419WHERE id = "'.$id.'"
420;';
421                                                pwg_query($query);
422     
423                                                if ($conf_nbc_UserAdvManager[3] <> -1) // Delete user from unvalidated users group
424                                                {
425                                                        $query = "
426DELETE FROM ".USER_GROUP_TABLE."
427WHERE user_id = '".$data['user_id']."'
428  AND group_id = '".$conf_nbc_UserAdvManager[3]."'
429;";
430                                                        pwg_query($query);
431                                                }
432           
433                                                if ($conf_nbc_UserAdvManager[4] <> -1) // Add user to validated users group
434                                                {
435                                                        $query = "
436INSERT INTO ".USER_GROUP_TABLE."
437  (user_id, group_id)
438VALUES
439  ('".$data['user_id']."', '".$conf_nbc_UserAdvManager[4]."')
440;";
441                                                        pwg_query($query);
442                                                }
443
444                                                if (($conf_nbc_UserAdvManager[5] <> -1 or isset($data['status']))) // Change user's status
445                                                {
446                                                        $query = "
447UPDATE ".USER_INFOS_TABLE."
448SET status = '".(isset($data['status']) ? $data['status'] : $conf_nbc_UserAdvManager[5])."'
449WHERE user_id = '".$data['user_id']."'
450;";
451                                                        pwg_query($query);
452                                                }
453                                                // Refresh user's category cache
454                                                invalidate_user_cache();
455 
456                                                return true;
457                                        }
458                                        elseif ($deltadays > $conf_nbc_UserAdvManager_ConfirmMail[1]) // If timelimit exeeds
459                                        {
460                                                return false;
461                                        }
462                                }
463                                // Verify Confirmmail with time limit OFF
464                                else
465                                {
466                                        list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
467
468                                        $query = '
469UPDATE '.USER_CONFIRM_MAIL_TABLE.'
470SET date_check="'.$dbnow.'"
471WHERE id = "'.$id.'"
472;';
473                                        pwg_query($query);
474     
475                                        if ($conf_nbc_UserAdvManager[3] <> -1)
476                                        {
477                                                $query = "
478DELETE FROM ".USER_GROUP_TABLE."
479WHERE user_id = '".$data['user_id']."'
480AND group_id = '".$conf_nbc_UserAdvManager[3]."'
481;";
482                                                pwg_query($query);
483                                        }
484   
485                                        if ($conf_nbc_UserAdvManager[4] <> -1)
486                                        {
487                                                $query = "
488DELETE FROM ".USER_GROUP_TABLE."
489WHERE user_id = '".$data['user_id']."'
490AND group_id = '".$conf_nbc_UserAdvManager[4]."'
491;";
492                                                pwg_query($query);
493
494                                                $query = "
495INSERT INTO ".USER_GROUP_TABLE."
496  (user_id, group_id)
497VALUES
498  ('".$data['user_id']."', '".$conf_nbc_UserAdvManager[4]."')
499;";
500                                                pwg_query($query);
501                                        }
502
503                                        if (($conf_nbc_UserAdvManager[5] <> -1 or isset($data['status'])))
504                                        {
505                                                $query = "
506UPDATE ".USER_INFOS_TABLE."
507SET status = '".(isset($data['status']) ? $data['status'] : $conf_nbc_UserAdvManager[5])."'
508WHERE user_id = '".$data['user_id']."'
509;";
510                                                pwg_query($query);
511                                        }
512                                        // Refresh user's category cache
513                                        invalidate_user_cache();
514 
515                                        return true;
516                                }
517                        }
518                }
519        }
520  else
521    return false;
522}
523
524/* Function called from UserAdvManager_admin.php to force users validation by admin */
525function ForceValidation($id)
526{
527  global $conf;
528
529  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
530 
531  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
532       
533  $query = "
534SELECT COUNT(*)
535  FROM ".USER_CONFIRM_MAIL_TABLE."
536WHERE user_id = '".$id."'
537;";
538  list($count) = mysql_fetch_row(pwg_query($query));
539
540  if ($count == 1)
541  {
542    $query = "
543SELECT user_id, status, date_check
544  FROM ".USER_CONFIRM_MAIL_TABLE."
545WHERE user_id = '".$id."'
546;";
547    $data = mysql_fetch_assoc(pwg_query($query));
548
549    if (!empty($data) and isset($data['user_id']) and !isset($data['date_check']))
550    {     
551                        list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
552
553                        $query = "
554UPDATE ".USER_CONFIRM_MAIL_TABLE."
555SET date_check='".$dbnow."'
556WHERE user_id = '".$data['user_id']."'
557;";
558                        pwg_query($query);
559             
560                        if ($conf_nbc_UserAdvManager[3] <> -1)
561                        {
562                                $query = "
563DELETE FROM ".USER_GROUP_TABLE."
564WHERE user_id = '".$data['user_id']."'
565  AND group_id = '".$conf_nbc_UserAdvManager[3]."'
566;";
567                                pwg_query($query);
568                        }
569 
570                        if ($conf_nbc_UserAdvManager[4] <> -1)
571                        {
572                                $query = "
573DELETE FROM ".USER_GROUP_TABLE."
574WHERE user_id = '".$data['user_id']."'
575  AND group_id = '".$conf_nbc_UserAdvManager[4]."'
576                                ;";
577                                pwg_query($query);
578       
579                                $query = "
580INSERT INTO ".USER_GROUP_TABLE."
581  (user_id, group_id)
582VALUES
583  ('".$data['user_id']."', '".$conf_nbc_UserAdvManager[4]."')
584;";
585                                pwg_query($query);
586                        }
587
588                        if (($conf_nbc_UserAdvManager[5] <> -1 or isset($data['status'])))
589                        {
590                                $query = "
591UPDATE ".USER_INFOS_TABLE."
592SET status = '".(isset($data['status']) ? $data['status'] : $conf_nbc_UserAdvManager[5])."'
593WHERE user_id = '".$data['user_id']."'
594;";
595                                pwg_query($query);
596                        }
597                        // Refresh user's category cache
598                        invalidate_user_cache();
599                        return true;
600                }
601        }
602}
603
604/* Function called from main.inc.php - Get username case insensitive */
605function NotSensibleSearchUsername($username)
606{
607  global $conf;
608 
609  if (isset($username))
610  {
611    $query = "
612SELECT ".$conf['user_fields']['username']."
613  FROM ".USERS_TABLE."
614WHERE LOWER(".$conf['user_fields']['username'].") = '".strtolower($username)."'
615;";
616    list($username) = mysql_fetch_row(pwg_query($query));
617
618    return isset($username) ? stripslashes($username) : '';
619  }
620}
621
622
623/* Function called from main.inc.php - Check if username matches forbidden caracters */
624function ValidateUsername($login)
625{
626  global $conf;
627
628  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
629
630  if (isset($login) and isset($conf_nbc_UserAdvManager[8]) and $conf_nbc_UserAdvManager[8] <> '')
631  {
632        $pattern = '/'.$conf_nbc_UserAdvManager[8].'/';
633    if ( preg_match($pattern, $login) )
634      return false;
635    else
636      return true;
637  }
638  else
639  {
640    return true;
641  }
642}
643
644
645/* Function called from main.inc.php - Check if user's email is in excluded email providers list */
646/* Doesn't work on call - Must be copied in main.inc.php to work */
647function ValidateEmailProvider($email)
648{
649  global $conf;
650
651        $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
652        if (isset($conf_nbc_UserAdvManager[12]))
653        {
654                $ncsemail = strtolower($email);
655                $conf_nbc_MailExclusion = preg_split('/,/',$conf_nbc_UserAdvManager[13]);
656                for ($i = 0 ; $i < count($conf_nbc_MailExclusion) ; $i++)
657                {
658                        $pattern = '/'.$conf_nbc_MailExclusion[$i].'/';
659                        if (preg_match($pattern, $ncsemail))
660      {
661                        return false;
662      }
663      else
664      {
665                        return true;
666      }
667                }
668        }
669}
670
671
672/* Function called from UserAdvManager.php - Get unvalidated users according time limit */
673function get_unvalid_user_list()
674{
675        global $conf, $page;
676         
677        /* Get ConfirmMail configuration */
678        $conf_nbc_UserAdvManager_ConfirmMail = isset($conf['nbc_UserAdvManager_ConfirmMail']) ? explode(";" , $conf['nbc_UserAdvManager_ConfirmMail']) : array();
679         
680        /* Get UserAdvManager configuration */
681        $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); 
682 
683  $users = array();
684
685        /* search users depending expiration date */
686  $query = '
687SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
688                u.'.$conf['user_fields']['username'].' AS username,
689                u.'.$conf['user_fields']['email'].' AS email,
690                ui.status,
691                ui.adviser,
692                ui.enabled_high,
693                ui.level,
694                ui.registration_date
695FROM '.USERS_TABLE.' AS u
696  INNER JOIN '.USER_INFOS_TABLE.' AS ui
697    ON u.'.$conf['user_fields']['id'].' = ui.user_id
698  LEFT JOIN '.USER_GROUP_TABLE.' AS ug
699    ON u.'.$conf['user_fields']['id'].' = ug.user_id
700WHERE u.'.$conf['user_fields']['id'].' >= 3
701  AND (TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) >= "'.$conf_nbc_UserAdvManager_ConfirmMail[1].'"
702  OR TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) < "'.$conf_nbc_UserAdvManager_ConfirmMail[1].'")';
703
704        if ($conf_nbc_UserAdvManager[3] <> '-1' and $conf_nbc_UserAdvManager[9] == '-1')
705  {
706    $query.= '
707  AND ug.group_id = '.$conf_nbc_UserAdvManager[3];
708  }
709  if ($conf_nbc_UserAdvManager[3] == '-1' and $conf_nbc_UserAdvManager[9] <> '-1')
710  {
711    $query.= '
712  AND ui.status = \''.$conf_nbc_UserAdvManager[9]."'";
713  }
714  if ($conf_nbc_UserAdvManager[3] <> '-1' and $conf_nbc_UserAdvManager[9] <> '-1')
715  {
716    $query.= '
717  AND ug.group_id = \''.$conf_nbc_UserAdvManager[3]."'";
718  }
719  $query.= '
720ORDER BY id ASC
721;';
722
723        $result = pwg_query($query);
724     
725  while ($row = mysql_fetch_assoc($result))
726  {
727        $user = $row;
728    $user['groups'] = array();
729
730    array_push($users, $user);
731        }
732
733        /* add group lists */
734  $user_ids = array();
735  foreach ($users as $i => $user)
736  {
737        $user_ids[$i] = $user['id'];
738        }
739       
740        $user_nums = array_flip($user_ids);
741
742  if (count($user_ids) > 0)
743  {
744        $query = '
745SELECT user_id, group_id
746  FROM '.USER_GROUP_TABLE.'
747WHERE user_id IN ('.implode(',', $user_ids).')
748;';
749       
750                $result = pwg_query($query);
751       
752    while ($row = mysql_fetch_assoc($result))
753    {
754        array_push(
755        $users[$user_nums[$row['user_id']]]['groups'],
756        $row['group_id']
757                        );
758                }
759        }
760
761        return $users;
762}
763
764
765/* Function called from UserAdvManager.php - Get ghost users */
766function get_ghost_user_list()
767{
768        global $conf, $page;
769         
770        /* Get UserAdvManager configuration */
771        $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); 
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                lv.lastvisit,
781                lv.reminder
782FROM '.USERS_TABLE.' AS u
783  INNER JOIN '.USER_LASTVISIT_TABLE.' AS lv
784    ON u.'.$conf['user_fields']['id'].' = lv.user_id
785WHERE (TO_DAYS(NOW()) - TO_DAYS(lv.lastvisit) >= "'.$conf_nbc_UserAdvManager[18].'")
786ORDER BY id ASC;';
787
788        $result = pwg_query($query);
789     
790  while ($row = mysql_fetch_assoc($result))
791  {
792        $user = $row;
793    $user['groups'] = array();
794
795    array_push($users, $user);
796        }
797
798        /* add group lists */
799  $user_ids = array();
800  foreach ($users as $i => $user)
801  {
802        $user_ids[$i] = $user['id'];
803        }
804
805        return $users;
806}
807
808
809/* Function called from UserAdvManager.php - to determine who is expired or not and giving a different display color */
810function expiration($id)
811{
812        global $conf, $page;
813         
814        /* Get ConfirmMail configuration */
815        $conf_nbc_UserAdvManager_ConfirmMail = isset($conf['nbc_UserAdvManager_ConfirmMail']) ? explode(";" , $conf['nbc_UserAdvManager_ConfirmMail']) : array();
816         
817        /* Get UserAdvManager configuration */
818        $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); 
819       
820        $query = "
821SELECT registration_date
822  FROM ".USER_INFOS_TABLE."
823WHERE user_id = '".$id."'
824;";
825        list($registration_date) = mysql_fetch_row(pwg_query($query));
826
827/*              Time limit process              */
828/* ****************** begin ******************* */ 
829        if (!empty($registration_date))
830  {
831                // dates formating and compare
832                $today = date("d-m-Y"); // Get today's date
833                list($day, $month, $year) = explode('-', $today); // explode date of today                                               
834                $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp
835               
836          list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date
837                list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date
838                $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp
839                       
840                $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps     
841                $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days
842
843                // Condition with the value set for time limit
844                if ($deltadays <= $conf_nbc_UserAdvManager_ConfirmMail[1]) // If Nb of days is less than the limit set
845                {
846                        return false;
847                }
848                else
849                {
850                        return True;
851                }
852        }
853}
854
855
856/**
857 * Returns a password's score for password complexity check
858 *
859 * @param password filled by user
860 *
861 * Thanx to MathieuGut from http://m-gut.developpez.com
862 */
863function testpassword($password) // Le mot de passe passé en paramètre - $password given by user
864{
865
866  // Initialisation des variables - Variables initiation
867  $points = 0;
868  $point_lowercase = 0;
869  $point_uppercase = 0;
870  $point_numbers = 0;
871  $point_characters = 0;
872
873  // On récupère la longueur du mot de passe - Getting password lengh   
874  $length = strlen($password);
875 
876  // On fait une boucle pour lire chaque lettre - Loop to read password characters
877  for($i = 0; $i < $length; $i++)
878  {
879    // On sélectionne une à une chaque lettre - Select each letters
880    // $i étant à 0 lors du premier passage de la boucle - $i is 0 at first turn
881    $letters = $password[$i];
882
883    if ($letters>='a' && $letters<='z')
884    {
885      // On ajoute 1 point pour une minuscule - Adding 1 point to score for a lowercase
886                  $points = $points + 1;
887
888                  // On rajoute le bonus pour une minuscule - Adding bonus points for lowercase
889                  $point_lowercase = 1;
890    }
891    else if ($letters>='A' && $letters <='Z')
892    {
893      // On ajoute 2 points pour une majuscule - Adding 2 points to score for uppercase
894      $points = $points + 2;
895               
896      // On rajoute le bonus pour une majuscule - Adding bonus points for uppercase
897      $point_uppercase = 2;
898    }
899    else if ($letters>='0' && $letters<='9')
900    {
901      // On ajoute 3 points pour un chiffre - Adding 3 points to score for numbers
902      $points = $points + 3;
903               
904      // On rajoute le bonus pour un chiffre - Adding bonus points for numbers
905      $point_numbers = 3;
906    }
907    else
908    {
909      // On ajoute 5 points pour un caractère autre - Adding 5 points to score for special characters
910      $points = $points + 5;
911               
912      // On rajoute le bonus pour un caractère autre - Adding bonus points for special characters
913      $point_characters = 5;
914    }
915  }
916
917  // Calcul du coefficient points/longueur - calculating the coefficient points / length
918  $step1 = $points / $length;
919
920  // Calcul du coefficient de la diversité des types de caractères... - Calculation of the diversity of character types...
921  $step2 = $point_lowercase + $point_uppercase + $point_numbers + $point_characters;
922
923  // Multiplication du coefficient de diversité avec celui de la longueur - Multiplying the coefficient of diversity with that of the length
924  $score = $step1 * $step2;
925
926  // Multiplication du résultat par la longueur de la chaîne - Multiplying the result by the length of the chain
927  $finalscore = $score * $length;
928
929  return $finalscore;
930}
931
932/* Function called from maintain.inc.php - to check if database upgrade is needed */
933function table_exist($table)
934{
935  $query = 'DESC '.$table.';';
936  return (bool)($res=mysql_query($query));
937}
938?>
Note: See TracBrowser for help on using the repository browser.