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

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

[NBC_UserAdvManager] final coding for release 2.12.0 :

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