source: extensions/NBC_UserAdvManager/trunk/include/functions_UserAdvManager.inc.php @ 4340

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

[NBC_UserAdvManager]

  • Bug 1259 fixed - PHP notice on user addition by admin in user_list page
  • Bug 1257 fixed - If email exclusion list begins with a CR-LF, an informative warning message is displayed (I was unable to delete automatically this CR-LF).
  • Property svn:eol-style set to LF
File size: 27.0 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    $usercase = strtolower($username);
612    $query = "
613SELECT ".$conf['user_fields']['username']."
614  FROM ".USERS_TABLE."
615WHERE LOWER(".stripcslashes($conf['user_fields']['username']).") = '".$usercase."'
616;";
617    list($usercase) = mysql_fetch_row(pwg_query($query));
618
619    return isset($username) ? stripslashes($usercase) : '';
620  }
621}
622
623
624/* Function called from main.inc.php - Check if username matches forbidden caracters */
625function ValidateUsername($login)
626{
627  global $conf;
628
629  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
630
631  if (isset($login) and isset($conf_nbc_UserAdvManager[8]) and $conf_nbc_UserAdvManager[8] <> '')
632  {
633        $pattern = '/'.$conf_nbc_UserAdvManager[8].'/';
634    if ( preg_match($pattern, $login) )
635      return false;
636    else
637      return true;
638  }
639  else
640  {
641    return true;
642  }
643}
644
645
646/* Function called from main.inc.php - Check if user's email is in excluded email providers list */
647/* Doesn't work on call - Must be copied in main.inc.php to work */
648function ValidateEmailProvider($email)
649{
650  global $conf;
651
652        $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
653        if (isset($conf_nbc_UserAdvManager[12]))
654        {
655                $ncsemail = strtolower($email);
656                $conf_nbc_MailExclusion = preg_split("/[\s,]+/",$conf_nbc_UserAdvManager[13]);
657                for ($i = 0 ; $i < count($conf_nbc_MailExclusion) ; $i++)
658                {
659                        $pattern = '/'.$conf_nbc_MailExclusion[$i].'/';
660                        if (preg_match($pattern, $ncsemail))
661      {
662                        return false;
663      }
664      else
665      {
666                        return true;
667      }
668                }
669        }
670}
671
672
673/* Function called from UserAdvManager.php - Get unvalidated users according time limit */
674function get_unvalid_user_list()
675{
676        global $conf, $page;
677         
678        /* Get ConfirmMail configuration */
679        $conf_nbc_UserAdvManager_ConfirmMail = isset($conf['nbc_UserAdvManager_ConfirmMail']) ? explode(";" , $conf['nbc_UserAdvManager_ConfirmMail']) : array();
680         
681        /* Get UserAdvManager configuration */
682        $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); 
683 
684  $users = array();
685
686        /* search users depending expiration date */
687  $query = '
688SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
689                u.'.$conf['user_fields']['username'].' AS username,
690                u.'.$conf['user_fields']['email'].' AS email,
691                ui.status,
692                ui.adviser,
693                ui.enabled_high,
694                ui.level,
695                ui.registration_date
696FROM '.USERS_TABLE.' AS u
697  INNER JOIN '.USER_INFOS_TABLE.' AS ui
698    ON u.'.$conf['user_fields']['id'].' = ui.user_id
699  LEFT JOIN '.USER_GROUP_TABLE.' AS ug
700    ON u.'.$conf['user_fields']['id'].' = ug.user_id
701WHERE u.'.$conf['user_fields']['id'].' >= 3
702  AND (TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) >= "'.$conf_nbc_UserAdvManager_ConfirmMail[1].'"
703  OR TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) < "'.$conf_nbc_UserAdvManager_ConfirmMail[1].'")';
704
705        if ($conf_nbc_UserAdvManager[3] <> '-1' and $conf_nbc_UserAdvManager[9] == '-1')
706  {
707    $query.= '
708  AND ug.group_id = '.$conf_nbc_UserAdvManager[3];
709  }
710  if ($conf_nbc_UserAdvManager[3] == '-1' and $conf_nbc_UserAdvManager[9] <> '-1')
711  {
712    $query.= '
713  AND ui.status = \''.$conf_nbc_UserAdvManager[9]."'";
714  }
715  if ($conf_nbc_UserAdvManager[3] <> '-1' and $conf_nbc_UserAdvManager[9] <> '-1')
716  {
717    $query.= '
718  AND ug.group_id = \''.$conf_nbc_UserAdvManager[3]."'";
719  }
720  $query.= '
721ORDER BY id ASC
722;';
723
724        $result = pwg_query($query);
725     
726  while ($row = mysql_fetch_assoc($result))
727  {
728        $user = $row;
729    $user['groups'] = array();
730
731    array_push($users, $user);
732        }
733
734        /* add group lists */
735  $user_ids = array();
736  foreach ($users as $i => $user)
737  {
738        $user_ids[$i] = $user['id'];
739        }
740       
741        $user_nums = array_flip($user_ids);
742
743  if (count($user_ids) > 0)
744  {
745        $query = '
746SELECT user_id, group_id
747  FROM '.USER_GROUP_TABLE.'
748WHERE user_id IN ('.implode(',', $user_ids).')
749;';
750       
751                $result = pwg_query($query);
752       
753    while ($row = mysql_fetch_assoc($result))
754    {
755        array_push(
756        $users[$user_nums[$row['user_id']]]['groups'],
757        $row['group_id']
758                        );
759                }
760        }
761
762        return $users;
763}
764
765
766/* Function called from UserAdvManager.php - Get ghost users */
767function get_ghost_user_list()
768{
769        global $conf, $page;
770         
771        /* Get UserAdvManager configuration */
772        $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); 
773 
774  $users = array();
775
776        /* search users depending expiration date */
777  $query = '
778SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
779                u.'.$conf['user_fields']['username'].' AS username,
780                u.'.$conf['user_fields']['email'].' AS email,
781                lv.lastvisit,
782                lv.reminder
783FROM '.USERS_TABLE.' AS u
784  INNER JOIN '.USER_LASTVISIT_TABLE.' AS lv
785    ON u.'.$conf['user_fields']['id'].' = lv.user_id
786WHERE (TO_DAYS(NOW()) - TO_DAYS(lv.lastvisit) >= "'.$conf_nbc_UserAdvManager[18].'")
787ORDER BY id ASC;';
788
789        $result = pwg_query($query);
790     
791  while ($row = mysql_fetch_assoc($result))
792  {
793        $user = $row;
794    $user['groups'] = array();
795
796    array_push($users, $user);
797        }
798
799        /* add group lists */
800  $user_ids = array();
801  foreach ($users as $i => $user)
802  {
803        $user_ids[$i] = $user['id'];
804        }
805
806        return $users;
807}
808
809
810/* Function called from UserAdvManager.php - to determine who is expired or not and giving a different display color */
811function expiration($id)
812{
813        global $conf, $page;
814         
815        /* Get ConfirmMail configuration */
816        $conf_nbc_UserAdvManager_ConfirmMail = isset($conf['nbc_UserAdvManager_ConfirmMail']) ? explode(";" , $conf['nbc_UserAdvManager_ConfirmMail']) : array();
817         
818        /* Get UserAdvManager configuration */
819        $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); 
820       
821        $query = "
822SELECT registration_date
823  FROM ".USER_INFOS_TABLE."
824WHERE user_id = '".$id."'
825;";
826        list($registration_date) = mysql_fetch_row(pwg_query($query));
827
828/*              Time limit process              */
829/* ****************** begin ******************* */ 
830        if (!empty($registration_date))
831  {
832                // dates formating and compare
833                $today = date("d-m-Y"); // Get today's date
834                list($day, $month, $year) = explode('-', $today); // explode date of today                                               
835                $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp
836               
837          list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date
838                list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date
839                $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp
840                       
841                $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps     
842                $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days
843
844                // Condition with the value set for time limit
845                if ($deltadays <= $conf_nbc_UserAdvManager_ConfirmMail[1]) // If Nb of days is less than the limit set
846                {
847                        return false;
848                }
849                else
850                {
851                        return True;
852                }
853        }
854}
855
856
857/**
858 * Returns a password's score for password complexity check
859 *
860 * @param password filled by user
861 *
862 * Thanx to MathieuGut from http://m-gut.developpez.com
863 */
864function testpassword($password) // Le mot de passe passé en paramètre - $password given by user
865{
866
867  // Initialisation des variables - Variables initiation
868  $points = 0;
869  $point_lowercase = 0;
870  $point_uppercase = 0;
871  $point_numbers = 0;
872  $point_characters = 0;
873
874  // On récupère la longueur du mot de passe - Getting password lengh   
875  $length = strlen($password);
876 
877  // On fait une boucle pour lire chaque lettre - Loop to read password characters
878  for($i = 0; $i < $length; $i++)
879  {
880    // On sélectionne une à une chaque lettre - Select each letters
881    // $i étant à 0 lors du premier passage de la boucle - $i is 0 at first turn
882    $letters = $password[$i];
883
884    if ($letters>='a' && $letters<='z')
885    {
886      // On ajoute 1 point pour une minuscule - Adding 1 point to score for a lowercase
887                  $points = $points + 1;
888
889                  // On rajoute le bonus pour une minuscule - Adding bonus points for lowercase
890                  $point_lowercase = 1;
891    }
892    else if ($letters>='A' && $letters <='Z')
893    {
894      // On ajoute 2 points pour une majuscule - Adding 2 points to score for uppercase
895      $points = $points + 2;
896               
897      // On rajoute le bonus pour une majuscule - Adding bonus points for uppercase
898      $point_uppercase = 2;
899    }
900    else if ($letters>='0' && $letters<='9')
901    {
902      // On ajoute 3 points pour un chiffre - Adding 3 points to score for numbers
903      $points = $points + 3;
904               
905      // On rajoute le bonus pour un chiffre - Adding bonus points for numbers
906      $point_numbers = 3;
907    }
908    else
909    {
910      // On ajoute 5 points pour un caractère autre - Adding 5 points to score for special characters
911      $points = $points + 5;
912               
913      // On rajoute le bonus pour un caractère autre - Adding bonus points for special characters
914      $point_characters = 5;
915    }
916  }
917
918  // Calcul du coefficient points/longueur - calculating the coefficient points / length
919  $step1 = $points / $length;
920
921  // Calcul du coefficient de la diversité des types de caractères... - Calculation of the diversity of character types...
922  $step2 = $point_lowercase + $point_uppercase + $point_numbers + $point_characters;
923
924  // Multiplication du coefficient de diversité avec celui de la longueur - Multiplying the coefficient of diversity with that of the length
925  $score = $step1 * $step2;
926
927  // Multiplication du résultat par la longueur de la chaîne - Multiplying the result by the length of the chain
928  $finalscore = $score * $length;
929
930  return $finalscore;
931}
932
933/* Function called from maintain.inc.php - to check if database upgrade is needed */
934function table_exist($table)
935{
936  $query = 'DESC '.$table.';';
937  return (bool)($res=mysql_query($query));
938}
939?>
Note: See TracBrowser for help on using the repository browser.