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

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

[NBC_UserAdvManager]

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