source: extensions/NBC_UserAdvManager/tags/2.12.6/include/functions_UserAdvManager.inc.php @ 4251

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

[NBC_UserAdvManager] Creating 2.12.6 release - Merged from Branch 2.12 to Tag 2.12.6 :

  • Bug 1236 fixed : Admins couldn't add new users accounts in admin panel.
  • Beginning of IT translation
  • Some language files corrections
  • Property svn:eol-style set to LF
File size: 26.2 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(*)
189  FROM ".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
213  FROM ".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."', reminder = 'true'
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/* Function called from main.inc.php - Triggered on user deletion */
320function DeleteLastVisit($user_id)
321{
322  $query = "
323DELETE FROM ".USER_LASTVISIT_TABLE."
324WHERE user_id = '".$user_id."'
325;";
326  pwg_query($query);
327}
328
329/* Function called from ConfirmMail.php to verify validation key used by user according time limit */
330function VerifyConfirmMail($id)
331{
332  global $conf;
333
334  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
335 
336  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
337  $conf_nbc_UserAdvManager_ConfirmMail = isset($conf['nbc_UserAdvManager_ConfirmMail']) ? explode(";" , $conf['nbc_UserAdvManager_ConfirmMail']) : array();
338
339  $query = "
340SELECT COUNT(*)
341FROM ".USER_CONFIRM_MAIL_TABLE."
342WHERE id = '".$id."'
343;";
344  list($count) = mysql_fetch_row(pwg_query($query));
345
346  if ($count == 1)
347  {
348    $query = "
349SELECT user_id, status, date_check
350FROM ".USER_CONFIRM_MAIL_TABLE."
351WHERE id = '".$id."'
352;";
353    $data = mysql_fetch_array(pwg_query($query));
354       
355    if (!empty($data) and isset($data['user_id']) and !isset($data['date_check']))
356    {
357      $query = "
358SELECT registration_date
359FROM ".USER_INFOS_TABLE."
360WHERE user_id = '".$data['user_id']."'
361;";
362      list($registration_date) = mysql_fetch_row(pwg_query($query));
363
364/*              Time limit process              */
365/* ****************** begin ******************* */ 
366      if (!empty($registration_date))
367      {
368                                // Verify Confirmmail with time limit ON
369                                if (isset ($conf_nbc_UserAdvManager_ConfirmMail[1]))
370                                {
371                                        // dates formating and compare
372                                        $today = date("d-m-Y"); // Get today's date
373                                        list($day, $month, $year) = explode('-', $today); // explode date of today                                               
374                                        $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp
375                       
376                                list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date
377                                        list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date
378                                        $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp
379                       
380                                        $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps     
381                                        $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days
382
383                                        // Condition with the value set for time limit
384                                        if ($deltadays <= $conf_nbc_UserAdvManager_ConfirmMail[1]) // If Nb of days is less than the limit set
385                                        {
386                                                list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
387
388                                                $query = '
389UPDATE '.USER_CONFIRM_MAIL_TABLE.'
390SET date_check="'.$dbnow.'"
391WHERE id = "'.$id.'"
392;';
393                                                pwg_query($query);
394     
395                                                if ($conf_nbc_UserAdvManager[3] <> -1) // Delete user from unvalidated users group
396                                                {
397                                                        $query = "
398DELETE FROM ".USER_GROUP_TABLE."
399WHERE user_id = '".$data['user_id']."'
400  AND group_id = '".$conf_nbc_UserAdvManager[3]."'
401;";
402                                                        pwg_query($query);
403                                                }
404           
405                                                if ($conf_nbc_UserAdvManager[4] <> -1) // Add user to validated users group
406                                                {
407                                                        $query = "
408INSERT INTO ".USER_GROUP_TABLE."
409  (user_id, group_id)
410VALUES
411  ('".$data['user_id']."', '".$conf_nbc_UserAdvManager[4]."')
412;";
413                                                        pwg_query($query);
414                                                }
415
416                                                if (($conf_nbc_UserAdvManager[5] <> -1 or isset($data['status']))) // Change user's status
417                                                {
418                                                        $query = "
419UPDATE ".USER_INFOS_TABLE."
420SET status = '".(isset($data['status']) ? $data['status'] : $conf_nbc_UserAdvManager[5])."'
421WHERE user_id = '".$data['user_id']."'
422;";
423                                                        pwg_query($query);
424                                                }
425                                                // Refresh user's category cache
426                                                invalidate_user_cache();
427 
428                                                return true;
429                                        }
430                                        elseif ($deltadays > $conf_nbc_UserAdvManager_ConfirmMail[1]) // If timelimit exeeds
431                                        {
432                                                return false;
433                                        }
434                                }
435                                // Verify Confirmmail with time limit OFF
436                                else
437                                {
438                                        list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
439
440                                        $query = '
441UPDATE '.USER_CONFIRM_MAIL_TABLE.'
442SET date_check="'.$dbnow.'"
443WHERE id = "'.$id.'"
444;';
445                                        pwg_query($query);
446     
447                                        if ($conf_nbc_UserAdvManager[3] <> -1)
448                                        {
449                                                $query = "
450DELETE FROM ".USER_GROUP_TABLE."
451WHERE user_id = '".$data['user_id']."'
452AND group_id = '".$conf_nbc_UserAdvManager[3]."'
453;";
454                                                pwg_query($query);
455                                        }
456   
457                                        if ($conf_nbc_UserAdvManager[4] <> -1)
458                                        {
459                                                $query = "
460DELETE FROM ".USER_GROUP_TABLE."
461WHERE user_id = '".$data['user_id']."'
462AND group_id = '".$conf_nbc_UserAdvManager[4]."'
463;";
464                                                pwg_query($query);
465
466                                                $query = "
467INSERT INTO ".USER_GROUP_TABLE."
468  (user_id, group_id)
469VALUES
470  ('".$data['user_id']."', '".$conf_nbc_UserAdvManager[4]."')
471;";
472                                                pwg_query($query);
473                                        }
474
475                                        if (($conf_nbc_UserAdvManager[5] <> -1 or isset($data['status'])))
476                                        {
477                                                $query = "
478UPDATE ".USER_INFOS_TABLE."
479SET status = '".(isset($data['status']) ? $data['status'] : $conf_nbc_UserAdvManager[5])."'
480WHERE user_id = '".$data['user_id']."'
481;";
482                                                pwg_query($query);
483                                        }
484                                        // Refresh user's category cache
485                                        invalidate_user_cache();
486 
487                                        return true;
488                                }
489                        }
490                }
491        }
492  else
493    return false;
494}
495
496/* Function called from UserAdvManager_admin.php to force users validation by admin */
497function ForceValidation($id)
498{
499  global $conf;
500
501  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
502 
503  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
504       
505  $query = "
506SELECT COUNT(*)
507  FROM ".USER_CONFIRM_MAIL_TABLE."
508WHERE user_id = '".$id."'
509;";
510  list($count) = mysql_fetch_row(pwg_query($query));
511
512  if ($count == 1)
513  {
514    $query = "
515SELECT user_id, status, date_check
516  FROM ".USER_CONFIRM_MAIL_TABLE."
517WHERE user_id = '".$id."'
518;";
519    $data = mysql_fetch_array(pwg_query($query));
520
521    if (!empty($data) and isset($data['user_id']) and !isset($data['date_check']))
522    {     
523                        list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
524
525                        $query = "
526UPDATE ".USER_CONFIRM_MAIL_TABLE."
527SET date_check='".$dbnow."'
528WHERE user_id = '".$data['user_id']."'
529;";
530                        pwg_query($query);
531             
532                        if ($conf_nbc_UserAdvManager[3] <> -1)
533                        {
534                                $query = "
535DELETE FROM ".USER_GROUP_TABLE."
536WHERE user_id = '".$data['user_id']."'
537  AND group_id = '".$conf_nbc_UserAdvManager[3]."'
538;";
539                                pwg_query($query);
540                        }
541 
542                        if ($conf_nbc_UserAdvManager[4] <> -1)
543                        {
544                                $query = "
545DELETE FROM ".USER_GROUP_TABLE."
546WHERE user_id = '".$data['user_id']."'
547  AND group_id = '".$conf_nbc_UserAdvManager[4]."'
548                                ;";
549                                pwg_query($query);
550       
551                                $query = "
552INSERT INTO ".USER_GROUP_TABLE."
553  (user_id, group_id)
554VALUES
555  ('".$data['user_id']."', '".$conf_nbc_UserAdvManager[4]."')
556;";
557                                pwg_query($query);
558                        }
559
560                        if (($conf_nbc_UserAdvManager[5] <> -1 or isset($data['status'])))
561                        {
562                                $query = "
563UPDATE ".USER_INFOS_TABLE."
564SET status = '".(isset($data['status']) ? $data['status'] : $conf_nbc_UserAdvManager[5])."'
565WHERE user_id = '".$data['user_id']."'
566;";
567                                pwg_query($query);
568                        }
569                        // Refresh user's category cache
570                        invalidate_user_cache();
571                        return true;
572                }
573        }
574}
575
576/* Function called from main.inc.php - Get username case insensitive */
577function NotSensibleSearchUsername($username)
578{
579  global $conf;
580 
581  if (isset($username))
582  {
583    $query = "
584SELECT ".$conf['user_fields']['username']."
585  FROM ".USERS_TABLE."
586WHERE LOWER(".$conf['user_fields']['username'].") = '".strtolower($username)."'
587;";
588    list($username) = mysql_fetch_row(pwg_query($query));
589
590    return isset($username) ? $username : '';
591  }
592}
593
594
595/* Function called from main.inc.php - Check if username matches forbidden caracters */
596function ValidateUsername($login)
597{
598  global $conf;
599
600  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
601
602  if (isset($login) and isset($conf_nbc_UserAdvManager[8]) and $conf_nbc_UserAdvManager[8] <> '')
603  {
604        $pattern = '/'.$conf_nbc_UserAdvManager[8].'/';
605    if ( preg_match($pattern, $login) )
606      return false;
607    else
608      return true;
609  }
610  else
611  {
612    return true;
613  }
614}
615
616
617/* Function called from main.inc.php - Check if user's email is in excluded email providers list */
618function ValidateEmailProvider($email)
619{
620  global $conf;
621
622        $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
623        if (isset($conf_nbc_UserAdvManager[12]))
624        {
625                $ncsemail = strtolower($email);
626                $conf_nbc_MailExclusion = preg_split('/,/',$conf_nbc_UserAdvManager[13]);
627                for ($i = 0 ; $i < count($conf_nbc_MailExclusion) ; $i++)
628                {
629                        $pattern = '/'.$conf_nbc_MailExclusion[$i].'/';
630                        if (preg_match($pattern, $ncsemail))
631                        return false;
632                else
633                        return true;
634                }
635        }
636}
637
638
639/* Function called from UserAdvManager.php - Get unvalidated users according time limit */
640function get_unvalid_user_list()
641{
642        global $conf, $page;
643         
644        /* Get ConfirmMail configuration */
645        $conf_nbc_UserAdvManager_ConfirmMail = isset($conf['nbc_UserAdvManager_ConfirmMail']) ? explode(";" , $conf['nbc_UserAdvManager_ConfirmMail']) : array();
646         
647        /* Get UserAdvManager configuration */
648        $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); 
649 
650  $users = array();
651
652        /* search users depending expiration date */
653  $query = '
654SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
655                u.'.$conf['user_fields']['username'].' AS username,
656                u.'.$conf['user_fields']['email'].' AS email,
657                ui.status,
658                ui.adviser,
659                ui.enabled_high,
660                ui.level,
661                ui.registration_date
662FROM '.USERS_TABLE.' AS u
663  INNER JOIN '.USER_INFOS_TABLE.' AS ui
664    ON u.'.$conf['user_fields']['id'].' = ui.user_id
665  LEFT JOIN '.USER_GROUP_TABLE.' AS ug
666    ON u.'.$conf['user_fields']['id'].' = ug.user_id
667WHERE u.'.$conf['user_fields']['id'].' >= 3
668  AND (TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) >= "'.$conf_nbc_UserAdvManager_ConfirmMail[1].'"
669  OR TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) < "'.$conf_nbc_UserAdvManager_ConfirmMail[1].'")';
670
671        if ($conf_nbc_UserAdvManager[3] <> '-1' and $conf_nbc_UserAdvManager[9] == '-1')
672  {
673    $query.= '
674  AND ug.group_id = '.$conf_nbc_UserAdvManager[3];
675  }
676  if ($conf_nbc_UserAdvManager[3] == '-1' and $conf_nbc_UserAdvManager[9] <> '-1')
677  {
678    $query.= '
679  AND ui.status = \''.$conf_nbc_UserAdvManager[9]."'";
680  }
681  if ($conf_nbc_UserAdvManager[3] <> '-1' and $conf_nbc_UserAdvManager[9] <> '-1')
682  {
683    $query.= '
684  AND ug.group_id = \''.$conf_nbc_UserAdvManager[3]."'";
685  }
686  $query.= '
687ORDER BY id ASC
688;';
689
690        $result = pwg_query($query);
691     
692  while ($row = mysql_fetch_array($result))
693  {
694        $user = $row;
695    $user['groups'] = array();
696
697    array_push($users, $user);
698        }
699
700        /* add group lists */
701  $user_ids = array();
702  foreach ($users as $i => $user)
703  {
704        $user_ids[$i] = $user['id'];
705        }
706       
707        $user_nums = array_flip($user_ids);
708
709  if (count($user_ids) > 0)
710  {
711        $query = '
712SELECT user_id, group_id
713  FROM '.USER_GROUP_TABLE.'
714WHERE user_id IN ('.implode(',', $user_ids).')
715;';
716       
717                $result = pwg_query($query);
718       
719    while ($row = mysql_fetch_array($result))
720    {
721        array_push(
722        $users[$user_nums[$row['user_id']]]['groups'],
723        $row['group_id']
724                        );
725                }
726        }
727
728        return $users;
729}
730
731
732/* Function called from UserAdvManager.php - Get ghost users */
733function get_ghost_user_list()
734{
735        global $conf, $page;
736         
737        /* Get UserAdvManager configuration */
738        $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); 
739 
740  $users = array();
741
742        /* search users depending expiration date */
743  $query = '
744SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
745                u.'.$conf['user_fields']['username'].' AS username,
746                u.'.$conf['user_fields']['email'].' AS email,
747                lv.lastvisit,
748                lv.reminder
749FROM '.USERS_TABLE.' AS u
750  INNER JOIN '.USER_LASTVISIT_TABLE.' AS lv
751    ON u.'.$conf['user_fields']['id'].' = lv.user_id
752WHERE (TO_DAYS(NOW()) - TO_DAYS(lv.lastvisit) >= "'.$conf_nbc_UserAdvManager[18].'")
753ORDER BY id ASC;';
754
755        $result = pwg_query($query);
756     
757  while ($row = mysql_fetch_array($result))
758  {
759        $user = $row;
760    $user['groups'] = array();
761
762    array_push($users, $user);
763        }
764
765        /* add group lists */
766  $user_ids = array();
767  foreach ($users as $i => $user)
768  {
769        $user_ids[$i] = $user['id'];
770        }
771
772        return $users;
773}
774
775
776/* Function called from UserAdvManager.php - to determine who is expired or not and giving a different display color */
777function expiration($id)
778{
779        global $conf, $page;
780         
781        /* Get ConfirmMail configuration */
782        $conf_nbc_UserAdvManager_ConfirmMail = isset($conf['nbc_UserAdvManager_ConfirmMail']) ? explode(";" , $conf['nbc_UserAdvManager_ConfirmMail']) : array();
783         
784        /* Get UserAdvManager configuration */
785        $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); 
786       
787        $query = "
788SELECT registration_date
789  FROM ".USER_INFOS_TABLE."
790WHERE user_id = '".$id."'
791;";
792        list($registration_date) = mysql_fetch_row(pwg_query($query));
793
794/*              Time limit process              */
795/* ****************** begin ******************* */ 
796        if (!empty($registration_date))
797  {
798                // dates formating and compare
799                $today = date("d-m-Y"); // Get today's date
800                list($day, $month, $year) = explode('-', $today); // explode date of today                                               
801                $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp
802               
803          list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date
804                list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date
805                $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp
806                       
807                $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps     
808                $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days
809
810                // Condition with the value set for time limit
811                if ($deltadays <= $conf_nbc_UserAdvManager_ConfirmMail[1]) // If Nb of days is less than the limit set
812                {
813                        return false;
814                }
815                else
816                {
817                        return True;
818                }
819        }
820}
821
822
823/**
824 * Returns a password's score for password complexity check
825 *
826 * @param password filled by user
827 *
828 * Thanx to MathieuGut from http://m-gut.developpez.com
829 */
830function testpassword($password) // Le mot de passe passé en paramètre - $password given by user
831{
832
833  // Initialisation des variables - Variables initiation
834  $points = 0;
835  $point_lowercase = 0;
836  $point_uppercase = 0;
837  $point_numbers = 0;
838  $point_characters = 0;
839
840  // On récupère la longueur du mot de passe - Getting password lengh   
841  $length = strlen($password);
842 
843  // On fait une boucle pour lire chaque lettre - Loop to read password characters
844  for($i = 0; $i < $length; $i++)
845  {
846    // On sélectionne une à une chaque lettre - Select each letters
847    // $i étant à 0 lors du premier passage de la boucle - $i is 0 at first turn
848    $letters = $password[$i];
849
850    if ($letters>='a' && $letters<='z')
851    {
852      // On ajoute 1 point pour une minuscule - Adding 1 point to score for a lowercase
853                  $points = $points + 1;
854
855                  // On rajoute le bonus pour une minuscule - Adding bonus points for lowercase
856                  $point_lowercase = 1;
857    }
858    else if ($letters>='A' && $letters <='Z')
859    {
860      // On ajoute 2 points pour une majuscule - Adding 2 points to score for uppercase
861      $points = $points + 2;
862               
863      // On rajoute le bonus pour une majuscule - Adding bonus points for uppercase
864      $point_uppercase = 2;
865    }
866    else if ($letters>='0' && $letters<='9')
867    {
868      // On ajoute 3 points pour un chiffre - Adding 3 points to score for numbers
869      $points = $points + 3;
870               
871      // On rajoute le bonus pour un chiffre - Adding bonus points for numbers
872      $point_numbers = 3;
873    }
874    else
875    {
876      // On ajoute 5 points pour un caractère autre - Adding 5 points to score for special characters
877      $points = $points + 5;
878               
879      // On rajoute le bonus pour un caractère autre - Adding bonus points for special characters
880      $point_characters = 5;
881    }
882  }
883
884  // Calcul du coefficient points/longueur - calculating the coefficient points / length
885  $step1 = $points / $length;
886
887  // Calcul du coefficient de la diversité des types de caractères... - Calculation of the diversity of character types...
888  $step2 = $point_lowercase + $point_uppercase + $point_numbers + $point_characters;
889
890  // Multiplication du coefficient de diversité avec celui de la longueur - Multiplying the coefficient of diversity with that of the length
891  $score = $step1 * $step2;
892
893  // Multiplication du résultat par la longueur de la chaîne - Multiplying the result by the length of the chain
894  $finalscore = $score * $length;
895
896  return $finalscore;
897}
898
899/* Function called from maintain.inc.php - to check if database upgrade is needed */
900function table_exist($table)
901{
902  $query = 'DESC '.$table.';';
903  return (bool)($res=mysql_query($query));
904}
905?>
Note: See TracBrowser for help on using the repository browser.