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

Last change on this file since 6785 was 6785, checked in by Eric, 14 years ago
  • Bug 1693 fixed - Multi-languages are available for ConfirmMail customization (using Extended Description plugin)
  • Bug 1810 partially fixed - Auto login is not performed after visitors have validated their registration but the "home" button changes his link to redirect to identification page when the redirection option is set. Note: The redirection to profile.php doesn't work because I was unable to use the log_user() function on ConfirmMail page. This feature is still under investigation to perform the best way.
  • Property svn:eol-style set to LF
File size: 32.6 KB
RevLine 
[5056]1<?php
[5181]2include_once (UAM_PATH.'include/constants.php');
3load_language('plugin.lang', UAM_PATH);
[5056]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) */
[5064]9  global $conf;
[5056]10
[5181]11  $conf_UAM = unserialize($conf['UserAdvManager']);
[5056]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;';
[5633]24  $data = pwg_db_fetch_assoc(pwg_query($query));
[5056]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']);
[5181]38    load_language('plugin.lang', UAM_PATH);
[5056]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     
[6354]47      if (isset($conf_UAM[9]) and $conf_UAM[9] <> '')
[5056]48      {
49        if (function_exists('get_user_language_desc'))
50        {
[6354]51          $infos1_perso = get_user_language_desc($conf_UAM[9])."\n\n";
[5056]52        }
[6354]53        else $infos1_perso = l10n($conf_UAM[9])."\n\n"; 
[5056]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
[6354]83  if ( isset($conf_UAM[1]) and $conf_UAM[1] == 'true' and $confirm)
[5056]84  {
85    $infos2 = array
86    (
87      get_l10n_args('Link: %s', AddConfirmMail($id, $email)),
88      get_l10n_args('', ''),
89    );
90
[6354]91    if (isset($conf_UAM[10]) and $conf_UAM[10] <> '')
[5056]92    {
93      if (function_exists('get_user_language_desc'))
94      {
[6354]95        $infos2_perso = get_user_language_desc($conf_UAM[10])."\n\n";
[5056]96      }
[6354]97      else $infos2_perso = l10n($conf_UAM[10])."\n\n";
[5056]98    }
99  }
100
[5084]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
[5056]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) */
[5064]151  global $conf;
[5056]152
[5181]153  $conf_UAM = unserialize($conf['UserAdvManager']);
[5056]154
[5181]155  $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']);
[5056]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;';
[5633]168  $data = pwg_db_fetch_assoc(pwg_query($query));
[5056]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   
[5181]174  load_language('plugin.lang', UAM_PATH);
[5056]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) */
[5064]253  global $conf;
[5056]254
[5181]255  $conf_UAM = unserialize($conf['UserAdvManager']);
[5056]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;';
[5633]267  $data = pwg_db_fetch_assoc(pwg_query($query));
[5056]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   
[5181]273  load_language('plugin.lang', UAM_PATH);
[5056]274 
275  $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Ghost_reminder_of_%s', $username));     
276
[6354]277  if (isset($conf_UAM[18]) and $conf_UAM[18] <> '' and isset($conf_UAM[16]) and $conf_UAM[16] == 'true')
[5056]278  {
279    if (function_exists('get_user_language_desc'))
280    {
[6354]281      $infos1 = get_user_language_desc($conf_UAM[18])."\n\n";
[5056]282    }
283    else
284    {
[6354]285      $infos1 = l10n($conf_UAM[18])."\n\n";
[5056]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;";
[5633]322    list($count) = pwg_db_fetch_row(pwg_query($query));
[5056]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
[5181]335  $conf_UAM = unserialize($conf['UserAdvManager']);
[5056]336  $Confirm_Mail_ID = FindAvailableConfirmMailID();
337
[5633]338  list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
[5056]339 
340  if (isset($Confirm_Mail_ID))
341  {
342    $query = "
343SELECT status
344  FROM ".USER_INFOS_TABLE."
345WHERE user_id = '".$user_id."'
346;";
[5633]347    list($status) = pwg_db_fetch_row(pwg_query($query));
[5056]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 (
[6354]361    group_id = '".$conf_UAM[2]."'
362  OR
[5056]363    group_id = '".$conf_UAM[3]."'
364  )
365;";
366    pwg_query($query);
367
[6354]368    if (!is_admin() and $conf_UAM[8] <> -1)
[5056]369    {
370      $query = "
371UPDATE ".USER_INFOS_TABLE."
[6354]372SET status = '".$conf_UAM[8]."'
[5056]373WHERE user_id = '".$user_id."'
374;";
375      pwg_query($query);
376    }
377
[6354]378    if ( $conf_UAM[2] <> -1 )
[5056]379    {
380      $query = "
381INSERT INTO ".USER_GROUP_TABLE."
382  (user_id, group_id)
383VALUES
[6354]384  ('".$user_id."', '".$conf_UAM[2]."')
[5056]385;";
386      pwg_query($query);
387    }
388   
[6785]389    return get_absolute_root_url().UAM_PATH.'ConfirmMail.php?key='.$Confirm_Mail_ID.'&userid='.$user_id;
[5056]390  }
391}
392
393
[6757]394/* Function called from main.inc.php to set group to new users if manual validation is set */
395function setgroup($user_id)
396{
397  global $conf;
398 
399  $conf_UAM = unserialize($conf['UserAdvManager']);
400
401  $query = "
402DELETE FROM ".USER_GROUP_TABLE."
403WHERE user_id = '".$user_id."'
404  AND (
405    group_id = '".$conf_UAM[2]."'
406  OR
407    group_id = '".$conf_UAM[3]."'
408  )
409;";
410  pwg_query($query);
411
412  if (!is_admin() and $conf_UAM[8] <> -1)
413  {
414    $query = "
415UPDATE ".USER_INFOS_TABLE."
416SET status = '".$conf_UAM[8]."'
417WHERE user_id = '".$user_id."'
418;";
419    pwg_query($query);
420  }
421
422  if ( $conf_UAM[2] <> -1 )
423  {
424    $query = "
425INSERT INTO ".USER_GROUP_TABLE."
426  (user_id, group_id)
427VALUES
428  ('".$user_id."', '".$conf_UAM[2]."')
429;";
430    pwg_query($query);
431  }
432}
433
434
[5056]435/* Function called from UAM_admin.php to reset validation key */
436function ResetConfirmMail($user_id)
437{
438  global $conf;
439 
440  $Confirm_Mail_ID = FindAvailableConfirmMailID();
441
[5633]442  list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
[5056]443 
444  if (isset($Confirm_Mail_ID))
445  { 
446    $query = "
447UPDATE ".USER_CONFIRM_MAIL_TABLE."
448SET id = '".$Confirm_Mail_ID."'
449WHERE user_id = '".$user_id."'
450;";
451    pwg_query($query);
452
453                $query = "
454UPDATE ".USER_INFOS_TABLE."
455SET registration_date = '".$dbnow."'
456WHERE user_id = '".$user_id."'
457;";
458                pwg_query($query);
459   
[6785]460    return get_absolute_root_url().UAM_PATH.'ConfirmMail.php?key='.$Confirm_Mail_ID.'&userid='.$user_id;
[5056]461  }
462}
463
464
465/* Function called from function_UserAdvManager.inc.php to reset last visit date after sending a reminder */
466function resetlastvisit($user_id)
467{
468  global $conf;
469
[5633]470  list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
[5056]471
472  $query = "
473UPDATE ".USER_LASTVISIT_TABLE."
474SET lastvisit = '".$dbnow."', reminder = 'true'
475WHERE user_id = '".$user_id."'
476;";
477  pwg_query($query);
478}
479
480
481/* Function called from main.inc.php - Triggered on user deletion */
482function DeleteConfirmMail($user_id)
483{
484  $query = "
485DELETE FROM ".USER_CONFIRM_MAIL_TABLE."
486WHERE user_id = '".$user_id."'
487;";
488  pwg_query($query);
489}
490
491/* Function called from main.inc.php - Triggered on user deletion */
492function DeleteLastVisit($user_id)
493{
494  $query = "
495DELETE FROM ".USER_LASTVISIT_TABLE."
496WHERE user_id = '".$user_id."'
497;";
498  pwg_query($query);
499}
500
[6775]501
502/* Function called from main.inc.php - Triggered on user deletion */
503function DeleteRedir($user_id)
504{
505  $tab = array();
506
[6785]507  $query = '
[6775]508SELECT value
[6785]509FROM '.CONFIG_TABLE.'
510WHERE param = "UserAdvManager_Redir"
511;';
[6775]512
513  $tab = pwg_db_fetch_row(pwg_query($query));
514 
515  $values = explode(',', $tab[0]);
516
517  unset($values[array_search($user_id, $values)]);
518     
519  $query = "
520UPDATE ".CONFIG_TABLE."
521SET value = \"".implode(',', $values)."\"
522WHERE param = 'UserAdvManager_Redir';";
523
524  pwg_query($query);
525}
526
527
[5056]528/* Function called from ConfirmMail.php to verify validation key used by user according time limit */
[6785]529/* Return true is key validation is OK else return false */
[5056]530function VerifyConfirmMail($id)
531{
532  global $conf;
533
534  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
535 
[5181]536  $conf_UAM = unserialize($conf['UserAdvManager']);
[5056]537
[5181]538  $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']);
[5056]539
540  $query = "
541SELECT COUNT(*)
542FROM ".USER_CONFIRM_MAIL_TABLE."
543WHERE id = '".$id."'
544;";
[5633]545  list($count) = pwg_db_fetch_row(pwg_query($query));
[5056]546
547  if ($count == 1)
548  {
549    $query = "
550SELECT user_id, status, date_check
551FROM ".USER_CONFIRM_MAIL_TABLE."
552WHERE id = '".$id."'
553;";
[5633]554    $data = pwg_db_fetch_assoc(pwg_query($query));
[5056]555       
556    if (!empty($data) and isset($data['user_id']) and !isset($data['date_check']))
557    {
558      $query = "
559SELECT registration_date
560FROM ".USER_INFOS_TABLE."
561WHERE user_id = '".$data['user_id']."'
562;";
[5633]563      list($registration_date) = pwg_db_fetch_row(pwg_query($query));
[5056]564
565/*              Time limit process              */
[5064]566/* ******************************************** */ 
[5056]567      if (!empty($registration_date))
568      {
569                                // Verify Confirmmail with time limit ON
570                                if (isset ($conf_UAM_ConfirmMail[1]))
571                                {
572                                        // dates formating and compare
573                                        $today = date("d-m-Y"); // Get today's date
574                                        list($day, $month, $year) = explode('-', $today); // explode date of today                                               
575                                        $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp
576                       
577                                list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date
578                                        list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date
579                                        $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp
580                       
581                                        $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps     
582                                        $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days
583
584                                        // Condition with the value set for time limit
585                                        if ($deltadays <= $conf_UAM_ConfirmMail[1]) // If Nb of days is less than the limit set
586                                        {
[5633]587                                                list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
[5056]588
589                                                $query = '
590UPDATE '.USER_CONFIRM_MAIL_TABLE.'
591SET date_check="'.$dbnow.'"
592WHERE id = "'.$id.'"
593;';
594                                                pwg_query($query);
595     
[6354]596                                                if ($conf_UAM[2] <> -1) // Delete user from unvalidated users group
[5056]597                                                {
598                                                        $query = "
599DELETE FROM ".USER_GROUP_TABLE."
600WHERE user_id = '".$data['user_id']."'
[6354]601  AND group_id = '".$conf_UAM[2]."'
[5056]602;";
603                                                        pwg_query($query);
604                                                }
605           
[6354]606                                                if ($conf_UAM[3] <> -1) // Add user to validated users group
[5056]607                                                {
608                                                        $query = "
609INSERT INTO ".USER_GROUP_TABLE."
610  (user_id, group_id)
611VALUES
[6354]612  ('".$data['user_id']."', '".$conf_UAM[3]."')
[5056]613;";
614                                                        pwg_query($query);
615                                                }
616
[6354]617                                                if (($conf_UAM[4] <> -1 or isset($data['status']))) // Change user's status
[5056]618                                                {
619                                                        $query = "
620UPDATE ".USER_INFOS_TABLE."
[6354]621SET status = '".(isset($data['status']) ? $data['status'] : $conf_UAM[4])."'
[5056]622WHERE user_id = '".$data['user_id']."'
623;";
624                                                        pwg_query($query);
625                                                }
626                                                // Refresh user's category cache
627                                                invalidate_user_cache();
628 
629                                                return true;
630                                        }
631                                        elseif ($deltadays > $conf_UAM_ConfirmMail[1]) // If timelimit exeeds
632                                        {
633                                                return false;
634                                        }
635                                }
636                                // Verify Confirmmail with time limit OFF
637                                else
638                                {
[5633]639                                        list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
[5056]640
641                                        $query = '
642UPDATE '.USER_CONFIRM_MAIL_TABLE.'
643SET date_check="'.$dbnow.'"
644WHERE id = "'.$id.'"
645;';
646                                        pwg_query($query);
647     
[6354]648                                        if ($conf_UAM[2] <> -1)
[5056]649                                        {
650                                                $query = "
651DELETE FROM ".USER_GROUP_TABLE."
652WHERE user_id = '".$data['user_id']."'
[6354]653AND group_id = '".$conf_UAM[2]."'
[5056]654;";
655                                                pwg_query($query);
656                                        }
657   
[6354]658                                        if ($conf_UAM[3] <> -1)
[5056]659                                        {
660                                                $query = "
661DELETE FROM ".USER_GROUP_TABLE."
662WHERE user_id = '".$data['user_id']."'
[6354]663AND group_id = '".$conf_UAM[3]."'
[5056]664;";
665                                                pwg_query($query);
666
667                                                $query = "
668INSERT INTO ".USER_GROUP_TABLE."
669  (user_id, group_id)
670VALUES
[6354]671  ('".$data['user_id']."', '".$conf_UAM[3]."')
[5056]672;";
673                                                pwg_query($query);
674                                        }
675
[6354]676                                        if (($conf_UAM[4] <> -1 or isset($data['status'])))
[5056]677                                        {
678                                                $query = "
679UPDATE ".USER_INFOS_TABLE."
[6354]680SET status = '".(isset($data['status']) ? $data['status'] : $conf_UAM[4])."'
[5056]681WHERE user_id = '".$data['user_id']."'
682;";
683                                                pwg_query($query);
684                                        }
685                                        // Refresh user's category cache
686                                        invalidate_user_cache();
687 
688                                        return true;
689                                }
690                        }
691                }
692        }
693  else
694    return false;
695}
696
697/* Function called from UAM_admin.php to force users validation by admin */
698function ForceValidation($id)
699{
700  global $conf;
701
702  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
703
[5181]704  $conf_UAM = unserialize($conf['UserAdvManager']);
[5056]705       
706  $query = "
707SELECT COUNT(*)
708  FROM ".USER_CONFIRM_MAIL_TABLE."
709WHERE user_id = '".$id."'
710;";
[5633]711  list($count) = pwg_db_fetch_row(pwg_query($query));
[5056]712
713  if ($count == 1)
714  {
715    $query = "
716SELECT user_id, status, date_check
717  FROM ".USER_CONFIRM_MAIL_TABLE."
718WHERE user_id = '".$id."'
719;";
[5633]720    $data = pwg_db_fetch_assoc(pwg_query($query));
[5056]721
722    if (!empty($data) and isset($data['user_id']) and !isset($data['date_check']))
723    {     
[5633]724                        list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
[5056]725
726                        $query = "
727UPDATE ".USER_CONFIRM_MAIL_TABLE."
728SET date_check='".$dbnow."'
729WHERE user_id = '".$data['user_id']."'
730;";
731                        pwg_query($query);
732             
[6354]733                        if ($conf_UAM[2] <> -1)
[5056]734                        {
735                                $query = "
736DELETE FROM ".USER_GROUP_TABLE."
737WHERE user_id = '".$data['user_id']."'
[6354]738  AND group_id = '".$conf_UAM[2]."'
[5056]739;";
740                                pwg_query($query);
741                        }
742 
[6354]743                        if ($conf_UAM[3] <> -1)
[5056]744                        {
745                                $query = "
746DELETE FROM ".USER_GROUP_TABLE."
747WHERE user_id = '".$data['user_id']."'
[6354]748  AND group_id = '".$conf_UAM[3]."'
[5056]749                                ;";
750                                pwg_query($query);
751       
752                                $query = "
753INSERT INTO ".USER_GROUP_TABLE."
754  (user_id, group_id)
755VALUES
[6354]756  ('".$data['user_id']."', '".$conf_UAM[3]."')
[5056]757;";
758                                pwg_query($query);
759                        }
760
[6354]761                        if (($conf_UAM[4] <> -1 or isset($data['status'])))
[5056]762                        {
763                                $query = "
764UPDATE ".USER_INFOS_TABLE."
[6354]765SET status = '".(isset($data['status']) ? $data['status'] : $conf_UAM[4])."'
[5056]766WHERE user_id = '".$data['user_id']."'
767;";
768                                pwg_query($query);
769                        }
770                        // Refresh user's category cache
771                        invalidate_user_cache();
772                        return true;
773                }
774        }
775}
776
777
778/* Function called from main.inc.php - Check if username matches forbidden caracters */
779function ValidateUsername($login)
780{
781  global $conf;
782
[5181]783  $conf_UAM = unserialize($conf['UserAdvManager']);
[5056]784
[6354]785  if (isset($login) and isset($conf_UAM[7]) and $conf_UAM[7] <> '')
[5056]786  {
[6354]787    $conf_CharExclusion = preg_split("/,/",$conf_UAM[7]);
[5181]788    for ($i = 0 ; $i < count($conf_CharExclusion) ; $i++)
[5056]789    {
[5181]790      $pattern = '/'.$conf_CharExclusion[$i].'/i';
[5056]791      if (preg_match($pattern, $login))
792      {
793        return true;
794      }
795    }
796  }
797  else
798  {
799    return false;
800  }
801}
802
803
804/* Function called from main.inc.php - Check if user's email is in excluded email providers list */
805/* Doesn't work on call - Must be copied in main.inc.php to work */
806function ValidateEmailProvider($email)
807{
808  global $conf;
809
[5181]810  $conf_UAM = unserialize($conf['UserAdvManager']);
[5056]811 
[6354]812        if (isset($email) and isset($conf_UAM[12]) and $conf_UAM[12] <> '')
[5056]813        {
814                //$ncsemail = strtolower($email);
[6354]815                $conf_MailExclusion = preg_split("/[\s,]+/",$conf_UAM[12]);
[5181]816                for ($i = 0 ; $i < count($conf_MailExclusion) ; $i++)
[5056]817                {
[5181]818                        $pattern = '/'.$conf_MailExclusion[$i].'/i';
[5056]819                        if (preg_match($pattern, $email))
820      {
821                        return true;
822      }
823                }
824        }
825  else
826  {
827    return false;
828  }
829}
830
831
832/* Function called from UserAdvManager.php - Get unvalidated users according time limit */
833function get_unvalid_user_list()
834{
835        global $conf, $page;
836         
837        /* Get ConfirmMail configuration */
[5181]838  $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']);
[5056]839  /* Get UAM configuration */
[5181]840  $conf_UAM = unserialize($conf['UserAdvManager']);
[5056]841 
842  $users = array();
843
844        /* search users depending expiration date */
845  $query = '
846SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
847                u.'.$conf['user_fields']['username'].' AS username,
848                u.'.$conf['user_fields']['email'].' AS email,
849                ui.status,
850                ui.adviser,
851                ui.enabled_high,
852                ui.level,
853                ui.registration_date
854FROM '.USERS_TABLE.' AS u
855  INNER JOIN '.USER_INFOS_TABLE.' AS ui
856    ON u.'.$conf['user_fields']['id'].' = ui.user_id
857  LEFT JOIN '.USER_GROUP_TABLE.' AS ug
858    ON u.'.$conf['user_fields']['id'].' = ug.user_id
859WHERE u.'.$conf['user_fields']['id'].' >= 3
860  AND (TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) >= "'.$conf_UAM_ConfirmMail[1].'"
861  OR TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) < "'.$conf_UAM_ConfirmMail[1].'")';
862
[6354]863        if ($conf_UAM[2] <> '-1' and $conf_UAM[8] == '-1')
[5056]864  {
865    $query.= '
[6354]866  AND ug.group_id = '.$conf_UAM[2];
[5056]867  }
[6354]868  if ($conf_UAM[2] == '-1' and $conf_UAM[8] <> '-1')
[5056]869  {
870    $query.= '
[6354]871  AND ui.status = \''.$conf_UAM[8]."'";
[5056]872  }
[6354]873  if ($conf_UAM[2] <> '-1' and $conf_UAM[8] <> '-1')
[5056]874  {
875    $query.= '
[6354]876  AND ug.group_id = \''.$conf_UAM[2]."'";
[5056]877  }
878  $query.= '
[6399]879ORDER BY ui.registration_date ASC
[5056]880;';
881
882        $result = pwg_query($query);
883     
[5633]884  while ($row = pwg_db_fetch_assoc($result))
[5056]885  {
886        $user = $row;
887    $user['groups'] = array();
888
889    array_push($users, $user);
890        }
891
892        /* add group lists */
893  $user_ids = array();
894  foreach ($users as $i => $user)
895  {
896        $user_ids[$i] = $user['id'];
897        }
898       
899        $user_nums = array_flip($user_ids);
900
901  if (count($user_ids) > 0)
902  {
903        $query = '
904SELECT user_id, group_id
905  FROM '.USER_GROUP_TABLE.'
906WHERE user_id IN ('.implode(',', $user_ids).')
907;';
908       
909                $result = pwg_query($query);
910       
[5633]911    while ($row = pwg_db_fetch_assoc($result))
[5056]912    {
913        array_push(
914        $users[$user_nums[$row['user_id']]]['groups'],
915        $row['group_id']
916                        );
917                }
918        }
919
920        return $users;
921}
922
923
924/* Function called from UserAdvManager.php - Get ghost users */
925function get_ghost_user_list()
926{
927        global $conf, $page;
928
[5181]929  $conf_UAM = unserialize($conf['UserAdvManager']);
[5056]930 
931  $users = array();
932
933        /* search users depending expiration date */
934  $query = '
935SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
936                u.'.$conf['user_fields']['username'].' AS username,
937                u.'.$conf['user_fields']['email'].' AS email,
938                lv.lastvisit,
939                lv.reminder
940FROM '.USERS_TABLE.' AS u
941  INNER JOIN '.USER_LASTVISIT_TABLE.' AS lv
942    ON u.'.$conf['user_fields']['id'].' = lv.user_id
[6354]943WHERE (TO_DAYS(NOW()) - TO_DAYS(lv.lastvisit) >= "'.$conf_UAM[17].'")
[6399]944ORDER BY lv.lastvisit ASC;';
[5056]945
946        $result = pwg_query($query);
947     
[5633]948  while ($row = pwg_db_fetch_assoc($result))
[5056]949  {
950        $user = $row;
951    $user['groups'] = array();
952
953    array_push($users, $user);
954        }
955
956        /* add group lists */
957  $user_ids = array();
958  foreach ($users as $i => $user)
959  {
960        $user_ids[$i] = $user['id'];
961        }
962
963        return $users;
964}
965
966
967/* Function called from UserAdvManager.php - Get all users to display the number of days since their last visit */
968function get_user_list()
969{
970        global $conf, $page;
971 
972  $users = array();
973
974        /* search users depending expiration date */
975  $query = '
976SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
977                u.'.$conf['user_fields']['username'].' AS username,
978                u.'.$conf['user_fields']['email'].' AS email,
979                ug.lastvisit
980FROM '.USERS_TABLE.' AS u
981  INNER JOIN '.USER_LASTVISIT_TABLE.' AS ug
982    ON u.'.$conf['user_fields']['id'].' = ug.user_id
983WHERE u.'.$conf['user_fields']['id'].' >= 3
[6399]984ORDER BY ug.lastvisit DESC
[5056]985;';
986
987        $result = pwg_query($query);
988     
[5633]989  while ($row = pwg_db_fetch_assoc($result))
[5056]990  {
991        $user = $row;
992    $user['groups'] = array();
993
994    array_push($users, $user);
995        }
996
997        /* add group lists */
998  $user_ids = array();
999  foreach ($users as $i => $user)
1000  {
1001        $user_ids[$i] = $user['id'];
1002        }
1003
1004        return $users;
1005}
1006
1007
1008/* Function called from UserAdvManager.php - to determine who is expired or not and giving a different display color */
1009function expiration($id)
1010{
1011        global $conf, $page;
1012         
1013        /* Get ConfirmMail configuration */
[5181]1014  $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']);
[5056]1015         
1016        /* Get UAM configuration */
[5181]1017  $conf_UAM = unserialize($conf['UserAdvManager']);
[5056]1018       
1019        $query = "
1020SELECT registration_date
1021  FROM ".USER_INFOS_TABLE."
1022WHERE user_id = '".$id."'
1023;";
[5633]1024        list($registration_date) = pwg_db_fetch_row(pwg_query($query));
[5056]1025
1026/*              Time limit process              */
[5064]1027/* ******************************************** */ 
[5056]1028        if (!empty($registration_date))
1029  {
1030                // dates formating and compare
1031                $today = date("d-m-Y"); // Get today's date
1032                list($day, $month, $year) = explode('-', $today); // explode date of today                                               
1033                $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp
1034               
1035          list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date
1036                list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date
1037                $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp
1038                       
1039                $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps     
1040                $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days
1041
1042                // Condition with the value set for time limit
1043                if ($deltadays <= $conf_UAM_ConfirmMail[1]) // If Nb of days is less than the limit set
1044                {
1045                        return false;
1046                }
1047                else
1048                {
[6754]1049                        return true;
[5056]1050                }
1051        }
1052}
1053
1054
1055/**
1056 * Returns a password's score for password complexity check
1057 *
1058 * @param password filled by user
1059 *
1060 * Thanx to MathieuGut from http://m-gut.developpez.com
1061 */
1062function testpassword($password) // Le mot de passe passé en paramètre - $password given by user
1063{
1064
1065  // Initialisation des variables - Variables initiation
1066  $points = 0;
1067  $point_lowercase = 0;
1068  $point_uppercase = 0;
1069  $point_numbers = 0;
1070  $point_characters = 0;
1071
1072  // On récupère la longueur du mot de passe - Getting password lengh   
1073  $length = strlen($password);
1074 
1075  // On fait une boucle pour lire chaque lettre - Loop to read password characters
1076  for($i = 0; $i < $length; $i++)
1077  {
1078    // On sélectionne une à une chaque lettre - Select each letters
1079    // $i étant à 0 lors du premier passage de la boucle - $i is 0 at first turn
1080    $letters = $password[$i];
1081
1082    if ($letters>='a' && $letters<='z')
1083    {
1084      // On ajoute 1 point pour une minuscule - Adding 1 point to score for a lowercase
1085                  $points = $points + 1;
1086
1087                  // On rajoute le bonus pour une minuscule - Adding bonus points for lowercase
1088                  $point_lowercase = 1;
1089    }
1090    else if ($letters>='A' && $letters <='Z')
1091    {
1092      // On ajoute 2 points pour une majuscule - Adding 2 points to score for uppercase
1093      $points = $points + 2;
1094               
1095      // On rajoute le bonus pour une majuscule - Adding bonus points for uppercase
1096      $point_uppercase = 2;
1097    }
1098    else if ($letters>='0' && $letters<='9')
1099    {
1100      // On ajoute 3 points pour un chiffre - Adding 3 points to score for numbers
1101      $points = $points + 3;
1102               
1103      // On rajoute le bonus pour un chiffre - Adding bonus points for numbers
1104      $point_numbers = 3;
1105    }
1106    else
1107    {
1108      // On ajoute 5 points pour un caractère autre - Adding 5 points to score for special characters
1109      $points = $points + 5;
1110               
1111      // On rajoute le bonus pour un caractère autre - Adding bonus points for special characters
1112      $point_characters = 5;
1113    }
1114  }
1115
1116  // Calcul du coefficient points/longueur - calculating the coefficient points/length
1117  $step1 = $points / $length;
1118
1119  // Calcul du coefficient de la diversité des types de caractères... - Calculation of the diversity of character types...
1120  $step2 = $point_lowercase + $point_uppercase + $point_numbers + $point_characters;
1121
1122  // Multiplication du coefficient de diversité avec celui de la longueur - Multiplying the coefficient of diversity with that of the length
1123  $score = $step1 * $step2;
1124
1125  // Multiplication du résultat par la longueur de la chaîne - Multiplying the result by the length of the chain
1126  $finalscore = $score * $length;
1127
1128  return $finalscore;
1129}
1130
1131/* Function called from maintain.inc.php - to check if database upgrade is needed */
1132function table_exist($table)
1133{
1134  $query = 'DESC '.$table.';';
[5633]1135  return (bool)($res=pwg_query($query));
[5056]1136}
1137
1138/* Email sending debugger function */
[5181]1139function MailLog($to, $subject, $content, $language)
[5056]1140{
[5181]1141   $fo=fopen (UAM_PATH.'admin/maillog.txt','a') ;
[5056]1142   fwrite($fo,"======================\n") ;
1143   fwrite($fo,'le ' . date('D, d M Y H:i:s') . "\r\n");
1144   fwrite($fo,$to . "\n" . $subject . "\r\n") ;
1145   fwrite($fo, "\n" . $content . "\r\n") ;
1146   fwrite($fo, 'Langue : '."\n" . $language . "\r\n") ;
1147   fclose($fo) ;
[5064]1148   //return mail ($to,$subject) ;
[5056]1149}
1150
1151
[5181]1152/* Function called from UAM_admin.php and main.inc.php to get the plugin version and name */
1153function PluginInfos($dir)
[5056]1154{
1155  $path = $dir;
1156
1157  $plg_data = implode( '', file($path.'main.inc.php') );
1158  if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) )
1159  {
1160    $plugin['name'] = trim( $val[1] );
1161  }
1162  if (preg_match("|Version: (.*)|", $plg_data, $val))
1163  {
1164    $plugin['version'] = trim($val[1]);
1165  }
1166  if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) )
1167  {
1168    $plugin['uri'] = trim($val[1]);
1169  }
1170  if ($desc = load_language('description.txt', $path.'/', array('return' => true)))
1171  {
1172    $plugin['description'] = trim($desc);
1173  }
1174  elseif ( preg_match("|Description: (.*)|", $plg_data, $val) )
1175  {
1176    $plugin['description'] = trim($val[1]);
1177  }
1178  if ( preg_match("|Author: (.*)|", $plg_data, $val) )
1179  {
1180    $plugin['author'] = trim($val[1]);
1181  }
1182  if ( preg_match("|Author URI: (.*)|", $plg_data, $val) )
1183  {
1184    $plugin['author uri'] = trim($val[1]);
1185  }
1186  if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid='))
1187  {
1188    list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']);
1189    if (is_numeric($extension)) $plugin['extension'] = $extension;
1190  }
1191// IMPORTANT SECURITY !
1192  $plugin = array_map('htmlspecialchars', $plugin);
1193
1194  return $plugin ;
1195}
1196
1197
[5064]1198function clean_obsolete_files()
[5056]1199{
[5181]1200  if (file_exists(UAM_PATH.'obsolete.list')
1201    and $old_files = file(UAM_PATH.'obsolete.list', FILE_IGNORE_NEW_LINES)
[5064]1202    and !empty($old_files))
[5056]1203  {
[5064]1204    array_push($old_files, 'obsolete.list');
1205    foreach($old_files as $old_file)
1206    {
[5181]1207      $path = UAM_PATH.$old_file;
[5064]1208      if (is_file($path))
1209      {
1210        @unlink($path);
1211      }
1212    }
[5056]1213  }
1214}
[6775]1215
1216
1217// check_consult - Thx to LucMorizur
1218// checks if a user id is registered as having already
1219// visited his profile.php page.
1220// @uid        : the user id
1221// @user_idsOK : (returned) array of all users ids having already visited
1222//               their profile.php pages
1223//
1224// @returns    : true or false whether the users has already visited his
1225//               profile.php page or not
1226function check_consult($uid, &$user_idsOK)
1227{
1228  $t = array();
1229  $v = false;
1230 
1231  $query = "
1232SELECT value
1233FROM ".CONFIG_TABLE."
1234WHERE param = 'UserAdvManager_Redir'
1235;";
1236 
1237  if ($v = (($t = pwg_db_fetch_row(pwg_query($query))) !== false))
1238  {
1239    $user_idsOK = explode(',', $t[0]);
1240    $v = (in_array($uid, $user_idsOK));
1241  }
1242  return $v;
1243}
[5056]1244?>
Note: See TracBrowser for help on using the repository browser.