source: extensions/UserAdvManager/trunk/admin/UAM_admin.php @ 14635

Last change on this file since 14635 was 14635, checked in by Eric, 12 years ago

Bug 2628 fixed - Php notice when email is not mandatory for registration

  • Property svn:eol-style set to LF
File size: 59.6 KB
RevLine 
[5056]1<?php
2
3global $user, $lang, $conf, $errors;
4
5if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
6// +-----------------------------------------------------------------------+
7// | Check Access and exit when user status is not ok                      |
8// +-----------------------------------------------------------------------+
9check_status(ACCESS_ADMINISTRATOR);
10
[5181]11if (!defined('UAM_PATH')) define('UAM_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
[5056]12
13//ini_set('error_reporting', E_ALL);
14//ini_set('display_errors', true);
15
[5593]16include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
[5056]17include_once (PHPWG_ROOT_PATH.'/include/constants.php');
18
[5181]19load_language('plugin.lang', UAM_PATH);
[12205]20load_language('help.lang', UAM_PATH);
[5056]21
[7955]22
23// +-----------------------------------------------------------------------+
24// |                   Variables initialization                            |
25// +-----------------------------------------------------------------------+
26$my_base_url = get_admin_plugin_menu_link(__FILE__);
27
[5056]28$page['global'] = array();
29$error = array();
30$pattern = '/;/';
31$replacement = '.';
32
33$UAM_Password_Test_Score = 0;
34$UAM_Exclusionlist_Error = false;
[11318]35$UAM_Illegal_Flag_Error1 = false;
36$UAM_Illegal_Flag_Error2 = false;
37$UAM_Illegal_Flag_Error3 = false;
[12689]38$UAM_Email_Mandatory_Check = false;
[5056]39
[10342]40$dump_download = '';
[7955]41
[5056]42// +-----------------------------------------------------------------------+
43// |                            Tabssheet                                  |
44// +-----------------------------------------------------------------------+
45if (!isset($_GET['tab']))
46        $page['tab'] = 'global';
47else
48  $page['tab'] = $_GET['tab'];
49
50$tabsheet = new tabsheet();
51$tabsheet->add('global',
[9177]52               l10n('UAM_Tab_Global'),
[5056]53               $my_base_url.'&amp;tab=global');
54  $tabsheet->add('userlist',
[13107]55                 l10n('UAM_Tracking registered users'),
[5056]56                 $my_base_url.'&amp;tab=userlist');
57$tabsheet->add('usermanager',
[13107]58               l10n('UAM_Tracking confirmations'),
[5056]59               $my_base_url.'&amp;tab=usermanager');
60$tabsheet->add('ghosttracker',
[9177]61               l10n('UAM_Tab_GhostTracker'),
[5056]62               $my_base_url.'&amp;tab=ghosttracker');
63$tabsheet->select($page['tab']);
64$tabsheet->assign();
65
66
67// +-----------------------------------------------------------------------+
68// |                      Getting plugin version                           |
69// +-----------------------------------------------------------------------+
[5181]70$plugin =  PluginInfos(UAM_PATH);
[5762]71$version = $plugin['version'];
[5056]72
73
74// +----------------------------------------------------------+
75// |            FCK Editor for email text fields              |
76// +----------------------------------------------------------+
[5181]77$toolbar = 'Basic';
[5073]78$width = '750px';
79$height = '300px';
80$areas = array();
[12661]81array_push( $areas,'UAM_ConfirmMail_Custom_Txt1','UAM_ConfirmMail_Custom_Txt2','UAM_GTAutoDelText','UAM_USRAutoDelText','UAM_CustomRejectConnexion_Text');
[5084]82
[5073]83if (function_exists('set_fckeditor_instance'))
[5084]84{
85  $fcke_config = unserialize($conf['FCKEditor']);
86  foreach($areas as $area)
87  {
88    if (!isset($fcke_config[$area]))
89    {
90      $fcke_config[$area] = false;
91    }
92  }
93  $conf['FCKEditor'] = serialize($fcke_config);
94
[5073]95  set_fckeditor_instance($areas, $toolbar, $width, $height);
[5181]96}
[5056]97
98
99// +-----------------------------------------------------------------------+
100// |                            Tabssheet select                           |
101// +-----------------------------------------------------------------------+
102
103switch ($page['tab'])
104{
105// *************************************************************************
106// +-----------------------------------------------------------------------+
107// |                           Global Config                               |
108// +-----------------------------------------------------------------------+
109// *************************************************************************
110  case 'global':
111
[12661]112        if (isset($_POST['submit']) and isset($_POST['UAM_Mail_Info']) and isset($_POST['UAM_Username_Char']) and isset($_POST['UAM_Confirm_Mail']) and isset($_POST['UAM_Password_Enforced']) and isset($_POST['UAM_AdminPassword_Enforced']) and isset($_POST['UAM_GhostUser_Tracker']) and isset($_POST['UAM_Admin_ConfMail']) and isset($_POST['UAM_RedirToProfile']) and isset($_POST['UAM_GTAuto']) and isset($_POST['UAM_GTAutoMail']) and isset($_POST['UAM_CustomPasswRetr']) and isset($_POST['UAM_USRAuto']) and isset($_POST['UAM_USRAutoMail']) and isset($_POST['UAM_Stuffs']) and isset($_POST['UAM_HidePassw']) and isset($_POST['UAM_PwdReset']) and isset($_POST['UAM_RejectConnexion']))
[5056]113  {
114
[12271]115    // Render free text fields
116    // -----------------------
[6753]117                $_POST['UAM_MailInfo_Text'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_MailInfo_Text'])));
[11318]118
[12271]119    $_POST['UAM_ConfirmMail_Text'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_ConfirmMail_Text'])));
[5056]120
[6753]121    $_POST['UAM_GhostTracker_ReminderText'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_GhostTracker_ReminderText'])));
[8065]122   
123    $_POST['UAM_GTAutoDelText'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_GTAutoDelText'])));
[5056]124
[8065]125    $_POST['UAM_GTAutoMailText'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_GTAutoMailText'])));
[9135]126
[8092]127    $_POST['UAM_AdminValidationMail_Text'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_AdminValidationMail_Text'])));
[5056]128
[9135]129    $_POST['UAM_CustomPasswRetr_Text'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_CustomPasswRetr_Text'])));
130
[9266]131    $_POST['UAM_USRAutoDelText'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_GTAutoDelText'])));
132
[12661]133    $_POST['UAM_CustomRejectConnexion_Text'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_CustomRejectConnexion_Text'])));
134
[14635]135
136  // Check if emails are mandatory for registrations (needed for email exclusion option)
137  // -----------------------------------------------------------------------------------
138  if ($conf['obligatory_user_mail_address'])
139  {
[9153]140    // Check if CR-LF exist at begining and end of mail exclusion list - If yes, removes them
[12271]141    // --------------------------------------------------------------------------------------
[5056]142    if (preg_match('/^[\s]+/', $_POST['UAM_MailExclusion_List']))
143    {
[9177]144      array_push($page['errors'], l10n('UAM_mail_exclusionlist_error'));
[5056]145      $UAM_Exclusionlist_Error = true;
146    }
[14635]147  }
148  elseif (!$conf['obligatory_user_mail_address'])
149  {
150    $_POST['UAM_MailExclusion_List'] = '';
151  }
[6754]152
[8065]153    // Consistency check between ConfirmMail and AutoMail - We cannot use GTAutoMail if ConfirmMail is disabled
[12271]154    // ---------------------------------------------------------------------------------------------------------
[8065]155    $conf_UAM = unserialize($conf['UserAdvManager']);
[11318]156    $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']);
[8065]157   
158    if (((isset($conf_UAM['1']) and ($conf_UAM['1'] == 'false' or $conf_UAM['1'] == 'local')) or ($_POST['UAM_Confirm_Mail'] == 'false' or $_POST['UAM_Confirm_Mail'] == 'local')) and $_POST['UAM_GTAutoMail'] == 'true')
159    {
160      $newvalue = 'false';
161      $_POST['UAM_GTAutoMail'] = $newvalue;
[9177]162      array_push($page['errors'], l10n('UAM_Error_GTAutoMail_cannot_be_set_without_ConfirmMail'));
[8065]163    }
164
[11318]165    // Check if [Kdays] flag is used in a legal way (ConfirmMail Time out have to be set)
[12271]166    // ----------------------------------------------------------------------------------
[11318]167    if (isset($conf_UAM_ConfirmMail[0]) and $conf_UAM_ConfirmMail[0] == 'false' and preg_match('#\[Kdays\]#i',$_POST['UAM_ConfirmMail_Text']) != 0)
168    {
169      $UAM_Illegal_Flag_Error1 = true;
170      array_push($page['errors'], l10n('UAM_Error_Using_illegal_Kdays'));
171    }
172
[12205]173    // Save global UAM configuration
[12271]174    // -----------------------------
[5056]175                $newconf_UAM = array(
176      $_POST['UAM_Mail_Info'],
177      $_POST['UAM_Confirm_Mail'],
178      (isset($_POST['UAM_No_Confirm_Group'])?$_POST['UAM_No_Confirm_Group']:''),
179      (isset($_POST['UAM_Validated_Group'])?$_POST['UAM_Validated_Group']:''),
180      (isset($_POST['UAM_Validated_Status'])?$_POST['UAM_Validated_Status']:''),
181      $_POST['UAM_Username_Char'],
182      $_POST['UAM_Username_List'],
183      (isset($_POST['UAM_No_Confirm_Status'])?$_POST['UAM_No_Confirm_Status']:''),
184      $_POST['UAM_MailInfo_Text'],
185      $_POST['UAM_ConfirmMail_Text'],
186      $_POST['UAM_MailExclusion'],
187      $_POST['UAM_MailExclusion_List'],
188      $_POST['UAM_Password_Enforced'],
189      $_POST['UAM_Password_Score'],
190      $_POST['UAM_AdminPassword_Enforced'],
191      $_POST['UAM_GhostUser_Tracker'],
192      $_POST['UAM_GhostTracker_DayLimit'],
193      $_POST['UAM_GhostTracker_ReminderText'],
[5064]194      $_POST['UAM_Add_LastVisit_Column'],
[6775]195      $_POST['UAM_Admin_ConfMail'],
[8065]196      $_POST['UAM_RedirToProfile'],
197      $_POST['UAM_GTAuto'],
198      $_POST['UAM_GTAutoMail'],
199      $_POST['UAM_GTAutoDelText'],
200      $_POST['UAM_GTAutoMailText'],
201      (isset($_POST['UAM_Downgrade_Group'])?$_POST['UAM_Downgrade_Group']:''),
[8092]202      (isset($_POST['UAM_Downgrade_Status'])?$_POST['UAM_Downgrade_Status']:''),
[9135]203      $_POST['UAM_AdminValidationMail_Text'],
204      $_POST['UAM_CustomPasswRetr'],
[9266]205      $_POST['UAM_CustomPasswRetr_Text'],
206      $_POST['UAM_USRAuto'],
207      $_POST['UAM_USRAutoDelText'],
[9908]208      $_POST['UAM_USRAutoMail'],
[10391]209      $_POST['UAM_Stuffs'],
[10957]210      $_POST['UAM_HidePassw'],
[12189]211      (isset($_POST['UAM_No_Valid_Level'])?$_POST['UAM_No_Valid_Level']:''),
212      (isset($_POST['UAM_Valid_Level'])?$_POST['UAM_Valid_Level']:''),
213      (isset($_POST['UAM_Downgrade_Level'])?$_POST['UAM_Downgrade_Level']:''),
[12239]214      $_POST['UAM_PwdReset'],
[12661]215      $_POST['UAM_RejectConnexion'],
216      $_POST['UAM_CustomRejectConnexion_Text'],
[8092]217      );
[5056]218
[5181]219    $conf['UserAdvManager'] = serialize($newconf_UAM);
[5056]220
[10976]221    conf_update_param('UserAdvManager', pwg_db_real_escape_string($conf['UserAdvManager']));
[5056]222
[12271]223    // Email confirmation settings
224    // --------------------------
[6753]225    $_POST['UAM_ConfirmMail_ReMail_Txt1'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_ConfirmMail_ReMail_Txt1'])));
[5056]226
[6753]227    $_POST['UAM_ConfirmMail_ReMail_Txt2'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_ConfirmMail_ReMail_Txt2'])));
[5181]228   
[6753]229    $_POST['UAM_ConfirmMail_Custom_Txt1'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_ConfirmMail_Custom_Txt1'])));
[5181]230   
[6753]231    $_POST['UAM_ConfirmMail_Custom_Txt2'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_ConfirmMail_Custom_Txt2'])));
[11318]232
233    // Check if [Kdays] flag is used in a legal way (ConfirmMail Time out have to be set)
[12271]234    // ----------------------------------------------------------------------------------
[11318]235    if (isset($conf_UAM_ConfirmMail[0]) and $conf_UAM_ConfirmMail[0] == 'false' and preg_match('#\[Kdays\]#i',$_POST['UAM_ConfirmMail_ReMail_Txt1']) == 1)
236    {
237      $UAM_Illegal_Flag_Error2 = true;
238      array_push($page['errors'], l10n('UAM_Error_Using_illegal_flag'));
239    }
240    elseif (isset($conf_UAM_ConfirmMail[0]) and $conf_UAM_ConfirmMail[0] == 'false' and preg_match('#\[Kdays\]#i',$_POST['UAM_ConfirmMail_ReMail_Txt2']) == 1)
241    {
242      $UAM_Illegal_Flag_Error3 = true;
243      array_push($page['errors'], l10n('UAM_Error_Using_illegal_flag'));
244    }
[12205]245
246    // Save ConfirmMail settings
[12271]247    // -------------------------
[5056]248          $newconf_UAM_ConfirmMail = array (
249      $_POST['UAM_ConfirmMail_TimeOut'],
250      $_POST['UAM_ConfirmMail_Delay'],
251      $_POST['UAM_ConfirmMail_ReMail_Txt1'],
252      $_POST['UAM_ConfirmMail_Remail'],
[5181]253      $_POST['UAM_ConfirmMail_ReMail_Txt2'],
254      $_POST['UAM_ConfirmMail_Custom_Txt1'],
255      $_POST['UAM_ConfirmMail_Custom_Txt2']);
[5056]256
[5181]257    $conf['UserAdvManager_ConfirmMail'] = serialize($newconf_UAM_ConfirmMail);
[5056]258
[10976]259    conf_update_param('UserAdvManager_ConfirmMail', pwg_db_real_escape_string($conf['UserAdvManager_ConfirmMail']));
[5056]260
261                array_push($page['infos'], l10n('UAM_save_config'));
262  }
263
[10342]264  // Saving UAM tables and configuration settings
[12271]265  // --------------------------------------------
[10342]266  if (isset($_POST['save']))
267  {
268    $dump_download = (isset($_POST['dump_download'])) ? 'true' : 'false';
269   
[12239]270    if(UAM_dump($dump_download) and $dump_download == 'false')
[10342]271    {
272      array_push($page['infos'], l10n('UAM_Dump_OK'));
273    }
274    else
275    {
276      array_push($page['errors'], l10n('UAM_Dump_NOK'));
277    }
278  }
[5056]279
[12275]280  // Restoring UAM tables and configuration settings
281  // -----------------------------------------------
282  if (isset($_POST['restore']))
283  {
284    $Backup_File = UAM_PATH.'/include/backup/UAM_dbbackup.sql';
285
[12314]286    if (file_exists($Backup_File) and $file = file($Backup_File, FILE_IGNORE_NEW_LINES) and !empty($file))
[12275]287    {
[12314]288      // Check backup file version
289      // -------------------------
290      if ($file[0] == "-- ".$version." --")
[12275]291      {
[12314]292        $restore = UAM_Restore_backup_file();
293        if(empty($restore))
294        {
295          array_push($page['infos'], l10n('UAM_Restoration_OK'));
296        }
297        else
298        {
299          array_push($page['errors'], l10n('UAM_Restoration_NOK'));
300        }
[12275]301      }
[12314]302      else array_push($page['errors'], l10n('UAM_Bad_version_backup'));
[12275]303    }
304    else
305    {
306      array_push($page['errors'], l10n('UAM_No_Backup_File'));
307    }
308  }
309
[12271]310  // Testing password enforcement
311  // ----------------------------
[8841]312  if (isset($_POST['PasswordTest']) and isset($_POST['UAM_Password_Test']) and !empty($_POST['UAM_Password_Test']))
[5056]313  {
314    $UAM_Password_Test_Score = testpassword($_POST['UAM_Password_Test']);
315  }
[8841]316  else if (isset($_POST['PasswordTest']) and empty($_POST['UAM_Password_Test']))
[5056]317  {
[9177]318    array_push($page['errors'], l10n('UAM_reg_err_login3'));
[5056]319  }
320
[5181]321  $conf_UAM = unserialize($conf['UserAdvManager']);
[5056]322
[12271]323  // Group setting for unvalidated, validated users and downgrade group
324  // ------------------------------------------------------------------
[5056]325  $groups[-1] = '---------';
326  $No_Valid = -1;
327  $Valid = -1;
[8065]328  $Downgrade = -1;
[5056]329       
[12271]330  // Get groups list in database
331  // ---------------------------
[5056]332  $query = '
333SELECT id, name
334FROM '.GROUPS_TABLE.'
335ORDER BY name ASC
336;';
337       
338  $result = pwg_query($query);
339       
[5633]340  while ($row = pwg_db_fetch_assoc($result))
[5056]341  {
342    $groups[$row['id']] = $row['name'];
[7955]343    //configuration value for unvalidated users
[6354]344    if (isset($conf_UAM[2]) and $conf_UAM[2] == $row['id'])
[5056]345    {
346                $No_Valid = $row['id'];
347                }
[7955]348    //configuration value for validated users
[6354]349    if (isset($conf_UAM[3]) and $conf_UAM[3] == $row['id'])
[5056]350                {
351                $Valid = $row['id'];
352                }
[8065]353    //configuration value for downgrade users
[11018]354    if (isset($conf_UAM[25]) and $conf_UAM[25] == $row['id'])
[8065]355                {
356                $Downgrade = $row['id'];
357                }
[5056]358  }
359       
[12271]360  // Template initialization for unvalidated users group
361  // ---------------------------------------------------
[5056]362  $template->assign(
363    'No_Confirm_Group',
364        array(
365                'group_options'=> $groups,
366                'group_selected' => $No_Valid
367                        )
368                );
[12271]369
370  // Template initialization for validated users group
371  // -------------------------------------------------
[5056]372  $template->assign(
373    'Validated_Group',
374                array(
375      'group_options'=> $groups,
376      'group_selected' => $Valid
377                        )
378        );
[12271]379
380  // Template initialization for downgrade group
381  // -------------------------------------------
[8065]382  $template->assign(
383    'Downgrade_Group',
384                array(
385      'group_options'=> $groups,
386      'group_selected' => $Downgrade
387                        )
388        );
[5056]389       
[12271]390  // Status setting for unvalidated, validated users and downgrade status
391  // --------------------------------------------------------------------
[5056]392  $status_options[-1] = '------------';
393  $No_Valid_Status = -1;
394  $Valid_Status = -1;
[8065]395  $Downgrade_Status = -1;
[5056]396       
[12271]397  // Get unvalidate status values
398  // ----------------------------
[5056]399  foreach (get_enums(USER_INFOS_TABLE, 'status') as $status)
400  {
401          $status_options[$status] = l10n('user_status_'.$status);
[11018]402          if (isset($conf_UAM[7]) and $conf_UAM[7] == $status)
[5056]403          {
404            $No_Valid_Status = $status;
405          }
406         
[12271]407    // Template initialization for unvalidated users status
408    // ----------------------------------------------------
409    $template->assign(
410      'No_Confirm_Status',
411      array(
412        'Status_options' => $status_options,
413        'Status_selected' => $No_Valid_Status
414                        )
415          );
[5056]416  }
417 
[12271]418  // Get validate status values
419  // --------------------------
[5056]420  foreach (get_enums(USER_INFOS_TABLE, 'status') as $status)
421  {
422          $status_options[$status] = l10n('user_status_'.$status);
[6354]423          if (isset($conf_UAM[4]) and $conf_UAM[4] == $status)
[5056]424                {
425                  $Valid_Status = $status;
426                }
427               
[12271]428    // Template initialization for validated users status
429    // --------------------------------------------------
430    $template->assign(
431          'Confirm_Status',
432          array(
433                  'Status_options' => $status_options,
434                  'Status_selected' => $Valid_Status
435                  )
436          );
[5056]437        }
438
[12271]439  // Get downgrade status values
440  // ---------------------------
[8065]441  foreach (get_enums(USER_INFOS_TABLE, 'status') as $status)
442  {
443          $status_options[$status] = l10n('user_status_'.$status);
[11018]444          if (isset($conf_UAM[26]) and $conf_UAM[26] == $status)
[8065]445                {
446                  $Downgrade_Status = $status;
447                }
448               
[12271]449    // Template initialization for validated users status
450    // --------------------------------------------------
451    $template->assign(
452          'Downgrade_Status',
453          array(
454                  'Status_options' => $status_options,
455                  'Status_selected' => $Downgrade_Status
456                  )
457          );
[8065]458        }
459
[12189]460
[12271]461  // Level setting for unvalidated, validated users and downgrade level
462  // ------------------------------------------------------------------
[12189]463  $level_options[-1] = '------------';
464  $No_Valid_Level = -1;
465  $Valid_Level = -1;
466  $Downgrade_Level = -1;
467
468  // Get unvalidated privacy levels values
[12271]469  // -------------------------------------
[12189]470  foreach ($conf['available_permission_levels'] as $level)
471  {
472    $level_options[$level] = l10n(sprintf('Level %d', $level));
473          if (isset($conf_UAM[35]) and $conf_UAM[35] == $level)
474          {
475            $No_Valid_Level = $level;
476          }
[12271]477
478    // Template initialization for unvalidated users level
479    // ---------------------------------------------------
480    $template->assign(
481      'No_Valid_Level',
482      array(
483        'Level_options' => $level_options,
484        'Level_selected' => $No_Valid_Level
485                        )
486          );
[12189]487  }
488
489  // Get validated privacy levels values
[12271]490  // -----------------------------------
[12189]491  foreach ($conf['available_permission_levels'] as $level)
492  {
493    $level_options[$level] = l10n(sprintf('Level %d', $level));
494          if (isset($conf_UAM[36]) and $conf_UAM[36] == $level)
495          {
496            $Valid_Level = $level;
497          }
[12271]498
499    // Template initialization for unvalidated users level
500    // ---------------------------------------------------
501    $template->assign(
502      'Valid_Level',
503      array(
504        'Level_options' => $level_options,
505        'Level_selected' => $Valid_Level
506                        )
507          );
[12189]508  }
509
510  // Get downgrade privacy levels values
[12271]511  // -----------------------------------
[12189]512  foreach ($conf['available_permission_levels'] as $level)
513  {
514    $level_options[$level] = l10n(sprintf('Level %d', $level));
515          if (isset($conf_UAM[37]) and $conf_UAM[37] == $level)
516          {
517            $Downgrade_Level = $level;
518          }
[12271]519
520    // Template initialization for unvalidated users level
521    // ---------------------------------------------------
522    $template->assign(
523      'Downgrade_Level',
524      array(
525        'Level_options' => $level_options,
526        'Level_selected' => $Downgrade_Level
527                        )
528          );
[12189]529  }
530
[12689]531  // Check if emails are mandatory for registrations (needed for email exclusion option)
532  // -----------------------------------------------------------------------------------
533  if (!$conf['obligatory_user_mail_address'])
534  {
535    $UAM_Email_Mandatory_Check = true;
536  }
537
[12271]538  // Save last opened paragraph in configuration tab
539  // -----------------------------------------------
[5056]540  $nb_para=(isset($_POST["nb_para"])) ? $_POST["nb_para"]:"";
541  $nb_para2=(isset($_POST["nb_para2"])) ? $_POST["nb_para2"]:"";
542
[5181]543  $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']);
[7955]544
[12271]545  // ------------------------------------------
[7955]546  // Template initialization for forms and data
[12271]547  // ------------------------------------------
[10359]548  $themeconf=$template->get_template_vars('themeconf');
549  $UAM_theme=$themeconf['id'];
550
[5056]551  $template->assign(
552    array(
553    'nb_para'                        => $nb_para,
554    'nb_para2'                       => $nb_para2,
555    'UAM_VERSION'                    => $version,
[5181]556    'UAM_PATH'                       => UAM_PATH,
[10342]557    'UAM_DUMP_DOWNLOAD'              => $dump_download,
[10359]558    'UAM_THEME'                      => $UAM_theme,
[5056]559                'UAM_MAIL_INFO_TRUE'             => $conf_UAM[0]=='true' ?  'checked="checked"' : '' ,
560                'UAM_MAIL_INFO_FALSE'            => $conf_UAM[0]=='false' ?  'checked="checked"' : '' ,
[11018]561                'UAM_MAILINFO_TEXT'              => $conf_UAM[8],
562                'UAM_USERNAME_CHAR_TRUE'         => $conf_UAM[5]=='true' ?  'checked="checked"' : '' ,
563                'UAM_USERNAME_CHAR_FALSE'        => $conf_UAM[5]=='false' ?  'checked="checked"' : '' ,
564                'UAM_USERNAME_CHAR_LIST'         => $conf_UAM[6],
[6354]565                'UAM_CONFIRM_MAIL_TRUE'          => $conf_UAM[1]=='true' ?  'checked="checked"' : '' ,
566                'UAM_CONFIRM_MAIL_FALSE'         => $conf_UAM[1]=='false' ?  'checked="checked"' : '' ,
[6754]567    'UAM_CONFIRM_MAIL_LOCAL'         => $conf_UAM[1]=='local' ?  'checked="checked"' : '' ,
[11018]568                'UAM_CONFIRMMAIL_TEXT'           => $conf_UAM[9],
[6354]569                'UAM_No_Confirm_Group'           => $conf_UAM[2],
570                'UAM_Validated_Group'            => $conf_UAM[3],
[11018]571                'UAM_No_Confirm_Status'          => $conf_UAM[7],
[6354]572                'UAM_Validated_Status'           => $conf_UAM[4],
[11018]573                'UAM_MAILEXCLUSION_TRUE'         => $conf_UAM[10]=='true' ?  'checked="checked"' : '' ,
574                'UAM_MAILEXCLUSION_FALSE'        => $conf_UAM[10]=='false' ?  'checked="checked"' : '' ,
575                'UAM_MAILEXCLUSION_LIST'         => $conf_UAM[11],
576                'UAM_PASSWORDENF_TRUE'           => $conf_UAM[12]=='true' ?  'checked="checked"' : '' ,
577                'UAM_PASSWORDENF_FALSE'          => $conf_UAM[12]=='false' ?  'checked="checked"' : '' ,
578                'UAM_PASSWORD_SCORE'             => $conf_UAM[13],
579    'UAM_ADMINPASSWENF_TRUE'         => $conf_UAM[14]=='true' ?  'checked="checked"' : '' ,
580                'UAM_ADMINPASSWENF_FALSE'        => $conf_UAM[14]=='false' ?  'checked="checked"' : '' ,
581    'UAM_GHOSTRACKER_TRUE'           => $conf_UAM[15]=='true' ?  'checked="checked"' : '' ,
582                'UAM_GHOSTRACKER_FALSE'          => $conf_UAM[15]=='false' ?  'checked="checked"' : '' ,
583    'UAM_GHOSTRACKER_DAYLIMIT'       => $conf_UAM[16],
584    'UAM_GHOSTRACKER_REMINDERTEXT'   => $conf_UAM[17],
585    'UAM_ADDLASTVISIT_TRUE'          => $conf_UAM[18]=='true' ?  'checked="checked"' : '' ,
586    'UAM_ADDLASTVISIT_FALSE'         => $conf_UAM[18]=='false' ?  'checked="checked"' : '' ,
587    'UAM_ADMINCONFMAIL_TRUE'         => $conf_UAM[19]=='true' ?  'checked="checked"' : '' ,
588    'UAM_ADMINCONFMAIL_FALSE'        => $conf_UAM[19]=='false' ?  'checked="checked"' : '' ,
589    'UAM_REDIRTOPROFILE_TRUE'        => $conf_UAM[20]=='true' ?  'checked="checked"' : '' ,
590    'UAM_REDIRTOPROFILE_FALSE'       => $conf_UAM[20]=='false' ?  'checked="checked"' : '' ,
591    'UAM_GTAUTO_TRUE'                => $conf_UAM[21]=='true' ?  'checked="checked"' : '' ,
592    'UAM_GTAUTO_FALSE'               => $conf_UAM[21]=='false' ?  'checked="checked"' : '' ,
593    'UAM_GTAUTOMAIL_TRUE'            => $conf_UAM[22]=='true' ?  'checked="checked"' : '' ,
594    'UAM_GTAUTOMAIL_FALSE'           => $conf_UAM[22]=='false' ?  'checked="checked"' : '' ,
595    'UAM_GTAUTODEL_TEXT'             => $conf_UAM[23],
596    'UAM_GTAUTOMAILTEXT'             => $conf_UAM[24],
597                'UAM_Downgrade_Group'            => $conf_UAM[25],
598                'UAM_Downgrade_Status'           => $conf_UAM[26],
599    'UAM_ADMINVALIDATIONMAIL_TEXT'   => $conf_UAM[27],
600    'UAM_CUSTOMPASSWRETR_TRUE'       => $conf_UAM[28]=='true' ?  'checked="checked"' : '' ,
601    'UAM_CUSTOMPASSWRETR_FALSE'      => $conf_UAM[28]=='false' ?  'checked="checked"' : '' ,
602    'UAM_CUSTOMPASSWRETR_TEXT'       => $conf_UAM[29],
603    'UAM_USRAUTO_TRUE'               => $conf_UAM[30]=='true' ?  'checked="checked"' : '' ,
604    'UAM_USRAUTO_FALSE'              => $conf_UAM[30]=='false' ?  'checked="checked"' : '' ,
605    'UAM_USRAUTODEL_TEXT'            => $conf_UAM[31],
606    'UAM_USRAUTOMAIL_TRUE'           => $conf_UAM[32]=='true' ?  'checked="checked"' : '' ,
607    'UAM_USRAUTOMAIL_FALSE'          => $conf_UAM[32]=='false' ?  'checked="checked"' : '' ,
608    'UAM_STUFFS_TRUE'                => $conf_UAM[33]=='true' ?  'checked="checked"' : '' ,
609    'UAM_STUFFS_FALSE'               => $conf_UAM[33]=='false' ?  'checked="checked"' : '' ,
610    'UAM_HIDEPASSW_TRUE'             => $conf_UAM[34]=='true' ?  'checked="checked"' : '' ,
611    'UAM_HIDEPASSW_FALSE'            => $conf_UAM[34]=='false' ?  'checked="checked"' : '' ,
[12189]612                'UAM_NO_VALID_LEVEL'             => $conf_UAM[35],
613                'UAM_VALID_LEVEL'                => $conf_UAM[36],
614    'UAM_DOWNGRADE_LEVEL'            => $conf_UAM[37],
[12239]615    'UAM_PWDRESET_TRUE'              => $conf_UAM[38]=='true' ?  'checked="checked"' : '' ,
616    'UAM_PWDRESET_FALSE'             => $conf_UAM[38]=='false' ?  'checked="checked"' : '' ,
[12661]617    'UAM_REJECTCONNECT_TRUE'         => $conf_UAM[39]=='true' ?  'checked="checked"' : '' ,
618    'UAM_REJECTCONNECT_FALSE'        => $conf_UAM[39]=='false' ?  'checked="checked"' : '' ,
619    'UAM_REJECTCONNECT_TEXT'         => $conf_UAM[40],
[5056]620                'UAM_PASSWORD_TEST_SCORE'        => $UAM_Password_Test_Score,
[11318]621    'UAM_ERROR_REPORTS1'             => $UAM_Exclusionlist_Error,
622    'UAM_ERROR_REPORTS2'             => $UAM_Illegal_Flag_Error1,
623    'UAM_ERROR_REPORTS3'             => $UAM_Illegal_Flag_Error2,
624    'UAM_ERROR_REPORTS4'             => $UAM_Illegal_Flag_Error3,
[12689]625    'UAM_EMAIL_MANDATORY'            => $UAM_Email_Mandatory_Check,
[5056]626                'UAM_CONFIRMMAIL_TIMEOUT_TRUE'   => $conf_UAM_ConfirmMail[0]=='true' ?  'checked="checked"' : '' ,
627                'UAM_CONFIRMMAIL_TIMEOUT_FALSE'  => $conf_UAM_ConfirmMail[0]=='false' ?  'checked="checked"' : '' ,
628                'UAM_CONFIRMMAIL_DELAY'                                  => $conf_UAM_ConfirmMail[1],
629    'UAM_CONFIRMMAIL_REMAIL_TRUE'                => $conf_UAM_ConfirmMail[3]=='true' ? 'checked="checked"' : '',
630    'UAM_CONFIRMMAIL_REMAIL_FALSE'       => $conf_UAM_ConfirmMail[3]=='false' ? 'checked="checked"' : '',
631    'UAM_CONFIRMMAIL_REMAIL_TXT1'                => $conf_UAM_ConfirmMail[2],
632    'UAM_CONFIRMMAIL_REMAIL_TXT2'                => $conf_UAM_ConfirmMail[4],
[5181]633    'UAM_CONFIRMMAIL_CUSTOM_TXT1'                => $conf_UAM_ConfirmMail[5],
634    'UAM_CONFIRMMAIL_CUSTOM_TXT2'                => $conf_UAM_ConfirmMail[6],
[5056]635    )
636  );
637
638  if (isset($_POST['audit']))
639        {
640                $msg_error1 = '';
641               
[12271]642    // Username without forbidden keys
643    // -------------------------------
[11018]644    if ( isset($conf_UAM[5]) and $conf_UAM[5] == 'true' )
[5056]645          {
646                        $query = "
647SELECT ".$conf['user_fields']['username'].", ".$conf['user_fields']['email']."
648  FROM ".USERS_TABLE."
649;";
650                         
651                        $result = pwg_query($query);
652                       
[5633]653                        while($row = pwg_db_fetch_assoc($result))
[5056]654                        {
655                                if (!ValidateUsername(stripslashes($row['username'])))
[12271]656                                        $msg_error1 .= (($msg_error1 <> '') ? '<br>' : '').l10n('UAM_Err_audit_username_char').stripslashes($row['username']);
[5056]657                        }
658                }
659
[6801]660                $msg_error2 = '';
[5056]661               
[12271]662    // Email without forbidden domain
663    // ------------------------------
[11018]664    if ( isset($conf_UAM[10]) and $conf_UAM[10] == 'true' )
[5056]665          {
666                        $query = "
667SELECT ".$conf['user_fields']['username'].", ".$conf['user_fields']['email']."
668  FROM ".USERS_TABLE."
669;";
670                         
671                  $result = pwg_query($query);
672                       
[5633]673                  while($row = pwg_db_fetch_assoc($result))
[5056]674                  {
[11018]675                          $conf_MailExclusion = preg_split("/[\s,]+/",$conf_UAM[11]);
[5181]676                          for ($i = 0 ; $i < count($conf_MailExclusion) ; $i++)
[5056]677                          {
[5181]678                                        $pattern = '/'.$conf_MailExclusion[$i].'/';
[5056]679                                  if (preg_match($pattern, $row['mail_address']))
680                                  {
[12271]681                                                $msg_error2 .=  (($msg_error2 <> '') ? '<br>' : '').l10n('UAM_Err_audit_email_forbidden').stripslashes($row['username']).' ('.$row['mail_address'].')';
[5056]682                                        }
683                                }
684                        }
685                }
686               
687    if ($msg_error1 <> '')
[6784]688                        $errors[] = $msg_error1.'<br><br>';
[5056]689               
690                if ($msg_error2 <> '')
[6784]691                        $errors[] = $msg_error2.'<br><br>';
[5056]692               
[6801]693                if ($msg_error1 <> '' or $msg_error2 <> '')
[9177]694                array_push($page['errors'], l10n('UAM_Err_audit_advise'));
[5056]695                else
696        array_push($page['infos'], l10n('UAM_audit_ok'));
697        }
698
699
700// +-----------------------------------------------------------------------+
701// |                             errors display                            |
702// +-----------------------------------------------------------------------+
703  if (isset ($errors) and count($errors) != 0)
704  {
705          $template->assign('errors',array());
706          foreach ($errors as $error)
707          {
708                  array_push($page['errors'], $error);
709                }
710        } 
711
712// +-----------------------------------------------------------------------+
713// |                           templates display                           |
714// +-----------------------------------------------------------------------+
[5593]715  $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/global.tpl');
[5056]716  $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
717
718  break;
719
720
721// *************************************************************************
722// +-----------------------------------------------------------------------+
723// |                           Users list page                             |
724// +-----------------------------------------------------------------------+
725// *************************************************************************
726  case 'userlist':
727 
[5181]728  $conf_UAM = unserialize($conf['UserAdvManager']);
[5056]729 
[11018]730  if (isset($conf_UAM[18]) and $conf_UAM[18]=='true')
[5056]731  {
732// +-----------------------------------------------------------------------+
733// |                           initialization                              |
734// +-----------------------------------------------------------------------+
735
736                if (!defined('PHPWG_ROOT_PATH'))
737    {
738        die('Hacking attempt!');
739    }
740         
741    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
742
743// +-----------------------------------------------------------------------+
744// | Check Access and exit when user status is not ok                      |
745// +-----------------------------------------------------------------------+
746                check_status(ACCESS_ADMINISTRATOR);
747
748
749// +-----------------------------------------------------------------------+
750// |                               user list                               |
751// +-----------------------------------------------------------------------+
752
753                $page['filtered_users'] = get_user_list();
754
755// +-----------------------------------------------------------------------+
756// |                               user list                               |
757// +-----------------------------------------------------------------------+
758
759    $visible_user_list = array();
760    foreach ($page['filtered_users'] as $num => $local_user)
761    {
762      $visible_user_list[] = $local_user;
763                }
764
765                foreach ($visible_user_list as $local_user)
766    {
767      // dates formating and compare
[12271]768      // ---------------------------
[5056]769      $today = date("d-m-Y"); // Get today's date
770      list($day, $month, $year) = explode('-', $today); // explode date of today                                                 
771      $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp
772               
773      list($regdate, $regtime) = explode(' ', $local_user['lastvisit']); // Explode date and time from registration date
774      list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date
775      $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp
776                       
777      $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps       
778      $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days
779     
[11018]780      if (isset($conf_UAM[15]) and $conf_UAM[15]=='true' and $conf_UAM[16] <> '')
[5056]781      {
[11018]782        if ($deltadays <= ($conf_UAM[16]/2))
[5056]783        {
784          $display = 'green';
785        }
786       
[11018]787        if (($deltadays > ($conf_UAM[16]/2)) and ($deltadays < $conf_UAM[16]))
[5056]788        {
789          $display = 'orange';
790        }
791       
[11018]792        if ($deltadays >= $conf_UAM[16])
[5056]793        {
794          $display = 'red';
795        }
796      }
[5105]797      else $display = '';
[5056]798
[12271]799      // Template initialization
800      // -----------------------
[5056]801                $template->append(
802                'users',
803        array(
804                'ID'          => $local_user['id'],
805                'USERNAME'    => stripslashes($local_user['username']),
806                                        'EMAIL'       => get_email_address_as_display_text($local_user['email']),
807          'LASTVISIT'   => $local_user['lastvisit'],
808          'DAYS'        => $deltadays,
809          'DISPLAY'     => $display,
810                                )
811                        );
812                }
[12271]813    // Plugin version inserted
814    // -----------------------
[5593]815    $template->assign(
816      array(
817        'UAM_VERSION'  => $version,
818        'UAM_PATH'     => UAM_PATH,
819      )
820    );   
[5056]821// +-----------------------------------------------------------------------+
822// |                             errors display                            |
823// +-----------------------------------------------------------------------+
824                if ( isset ($errors) and count($errors) != 0)
825                {
826                $template->assign('errors',array());
827                        foreach ($errors as $error)
828                {
829                                array_push($page['errors'], $error);
830                }
831                } 
832
833// +-----------------------------------------------------------------------+
834// |                           templates display                           |
835// +-----------------------------------------------------------------------+
[5593]836                $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/userlist.tpl');
[5056]837    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');         
838  }
839  else
840  {
[9177]841                array_push($page['errors'], l10n('UAM_Err_Userlist_Settings'));
[5056]842  }
843  break;
844
845
846// *************************************************************************
847// +-----------------------------------------------------------------------+
848// |                           Users manager page                          |
849// +-----------------------------------------------------------------------+
850// *************************************************************************
851  case 'usermanager':
852
[5181]853  $conf_UAM = unserialize($conf['UserAdvManager']);
[5056]854
[5181]855  $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']);
[5056]856       
[11018]857  if (isset($conf_UAM[1]) and ($conf_UAM[1]=='true' or $conf_UAM[1]=='local') and ((isset($conf_UAM[2]) and $conf_UAM[2] <> '-1') or (isset($conf_UAM[7]) and $conf_UAM[7] <> '-1')))
[8072]858  {
[5056]859// +-----------------------------------------------------------------------+
860// |                           initialization                              |
861// +-----------------------------------------------------------------------+
862
863                if (!defined('PHPWG_ROOT_PATH'))
864    {
865        die('Hacking attempt!');
866    }
[8072]867
[5056]868    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
869
870// +-----------------------------------------------------------------------+
871// | Check Access and exit when user status is not ok                      |
872// +-----------------------------------------------------------------------+
873                check_status(ACCESS_ADMINISTRATOR);
874
875// +-----------------------------------------------------------------------+
876// |                               user list                               |
877// +-----------------------------------------------------------------------+
878
879                $page['filtered_users'] = get_unvalid_user_list();
880
881// +-----------------------------------------------------------------------+
882// |                            selected users                             |
883// +-----------------------------------------------------------------------+
884                if (isset($_POST['Del_Selected']))
885                {
886                $collection = array();
887
888                        switch ($_POST['target'])
889        {
890                case 'all' :
891        {
892                foreach($page['filtered_users'] as $local_user)
893                {
894                        array_push($collection, $local_user['id']);
895                }
896                                        break;
897                                }
898        case 'selection' :
899        {
900                if (isset($_POST['selection']))
901                {
902                        $collection = $_POST['selection'];
903                }
904                break;
905        }
906                        }
907
908                        if (count($collection) == 0)
909        {
910                array_push($page['errors'], l10n('Select at least one user'));
911                }
912                }
913
914// +-----------------------------------------------------------------------+
915// |                             delete users                              |
916// +-----------------------------------------------------------------------+
917                if (isset($_POST['Del_Selected']) and count($collection) > 0)
918        {
919                if (in_array($conf['guest_id'], $collection))
920                {
921                array_push($page['errors'], l10n('Guest cannot be deleted'));
922        }
923        if (($conf['guest_id'] != $conf['default_user_id']) and
924                in_array($conf['default_user_id'], $collection))
925        {
926                array_push($page['errors'], l10n('Default user cannot be deleted'));
927        }
928        if (in_array($conf['webmaster_id'], $collection))
929        {
930                array_push($page['errors'], l10n('Webmaster cannot be deleted'));
931        }
932        if (in_array($user['id'], $collection))
933        {
934                array_push($page['errors'], l10n('You cannot delete your account'));
935        }
936
937                        if (count($page['errors']) == 0)
938        {
939                foreach ($collection as $user_id)
940        {
941                delete_user($user_id);
942        }
943                array_push(
944                $page['infos'],
945                l10n_dec(
946                '%d user deleted', '%d users deleted',
947                count($collection)
948                )
949        );
950
951        foreach ($page['filtered_users'] as $filter_key => $filter_user)
952        {
953                if (in_array($filter_user['id'], $collection))
954                {
955                        unset($page['filtered_users'][$filter_key]);
956                }
957                }
958                        }
959                }
960
961// +-----------------------------------------------------------------------+
962// |                 Resend new validation key to users                    |
963// +-----------------------------------------------------------------------+
964// +-----------------------------------------------------------------------+
965// |                            selected users                             |
966// +-----------------------------------------------------------------------+
967                if (isset($_POST['Mail_With_Key']))
968                {
969                $collection = array();
970
971                        switch ($_POST['target'])
972        {
973                case 'all' :
974        {
975                foreach($page['filtered_users'] as $local_user)
976                {
977                        array_push($collection, $local_user['id']);
978                }
979                break;
980                                }
981        case 'selection' :
982        {
983                if (isset($_POST['selection']))
984                {
985                        $collection = $_POST['selection'];
986                }
987                break;
988        }
989                        }
990
991        if (count($collection) == 0)
992        {
993                array_push($page['errors'], l10n('Select at least one user'));
994        }
995                }
996// +-----------------------------------------------------------------------+
997// |                 Resend new validation key to users                    |
998// +-----------------------------------------------------------------------+
999                if (isset($_POST['Mail_With_Key']) and count($collection) > 0)
1000                {
1001                        if (in_array($conf['guest_id'], $collection))
1002                {
[9177]1003                array_push($page['errors'], l10n('UAM_No_validation_for_Guest'));
[5056]1004        }
1005        if (($conf['guest_id'] != $conf['default_user_id']) and
1006                in_array($conf['default_user_id'], $collection))
1007        {
[9177]1008                array_push($page['errors'], l10n('UAM_No_validation_for_default_user'));
[5056]1009        }
1010                if (in_array($conf['webmaster_id'], $collection))
1011        {
[9177]1012                array_push($page['errors'], l10n('UAM_No_validation_for_Webmaster'));
[5056]1013        }
1014        if (in_array($user['id'], $collection))
1015        {
[9177]1016                array_push($page['errors'], l10n('UAM_No_validation_for_your_account'));
[5056]1017        }
1018
1019        if (count($page['errors']) == 0)
1020        {
1021                foreach ($collection as $user_id)
1022        {       
1023                $typemail = 1;
1024                                  $query = "
1025SELECT id, username, mail_address
1026  FROM ".USERS_TABLE."
1027WHERE id = '".$user_id."'
1028;";
[5633]1029                                        $data = pwg_db_fetch_assoc(pwg_query($query));
[5056]1030                               
1031                ResendMail2User($typemail,$user_id,stripslashes($data['username']),$data['mail_address'],true);
1032        }
1033        array_push(
1034                $page['infos'],
1035                l10n_dec(
[9177]1036                        'UAM_%d_Mail_With_Key', 'UAM_%d_Mails_With_Key',
[5056]1037                count($collection)
1038                )
1039        );
1040       
1041                                $page['filtered_users'] = get_unvalid_user_list();
1042                        }
1043                }
1044
1045// +-----------------------------------------------------------------------+
1046// |             Send reminder without new key to users                    |
1047// +-----------------------------------------------------------------------+
1048// +-----------------------------------------------------------------------+
1049// |                            selected users                             |
1050// +-----------------------------------------------------------------------+
1051                if (isset($_POST['Mail_Without_Key']))
1052                {
1053                $collection = array();
1054
1055                        switch ($_POST['target'])
1056        {
1057                case 'all' :
1058        {
1059                foreach($page['filtered_users'] as $local_user)
1060                {
1061                        array_push($collection, $local_user['id']);
1062                }
1063                break;
1064                                }
1065        case 'selection' :
1066        {
1067                if (isset($_POST['selection']))
1068                {
1069                        $collection = $_POST['selection'];
1070                }
1071                break;
1072        }
1073                        }
1074
1075        if (count($collection) == 0)
1076        {
1077                array_push($page['errors'], l10n('Select at least one user'));
1078        }
1079                }
1080// +-----------------------------------------------------------------------+
1081// |             Send reminder without new key to users                    |
1082// +-----------------------------------------------------------------------+
1083                if (isset($_POST['Mail_Without_Key']) and count($collection) > 0)
1084                {
1085                        if (in_array($conf['guest_id'], $collection))
1086                {
[9177]1087                array_push($page['errors'], l10n('UAM_No_validation_for_Guest'));
[5056]1088        }
1089        if (($conf['guest_id'] != $conf['default_user_id']) and
1090                in_array($conf['default_user_id'], $collection))
1091        {
[9177]1092                array_push($page['errors'], l10n('UAM_No_validation_for_default_user'));
[5056]1093        }
1094                if (in_array($conf['webmaster_id'], $collection))
1095        {
[9177]1096                array_push($page['errors'], l10n('UAM_No_validation_for_Webmaster'));
[5056]1097        }
1098        if (in_array($user['id'], $collection))
1099        {
[9177]1100                array_push($page['errors'], l10n('UAM_No_validation_for_your_account'));
[5056]1101        }
1102
1103        if (count($page['errors']) == 0)
1104        {
1105                foreach ($collection as $user_id)
1106        {
1107                $typemail = 2;
1108                                  $query = "
1109SELECT id, username, mail_address
1110  FROM ".USERS_TABLE."
1111WHERE id = '".$user_id."'
1112;";
1113                                       
[5633]1114                                        $data = pwg_db_fetch_assoc(pwg_query($query));
[5056]1115                               
1116                ResendMail2User($typemail,$user_id,stripslashes($data['username']),$data['mail_address'],false);                               
1117        }
1118        array_push(
1119                $page['infos'],
1120                l10n_dec(
[9177]1121                        'UAM_%d_Reminder_Sent', 'UAM_%d_Reminders_Sent',
[5056]1122                count($collection)
1123                )
1124        );
1125       
1126                                $page['filtered_users'] = get_unvalid_user_list();
1127                        }
1128                }
1129
1130// +-----------------------------------------------------------------------+
1131// |                                                                            Force validation                                                         |
1132// +-----------------------------------------------------------------------+
1133// +-----------------------------------------------------------------------+
1134// |                            selected users                             |
1135// +-----------------------------------------------------------------------+
1136                if (isset($_POST['Force_Validation']))
1137                {
1138                $collection = array();
1139
1140                        switch ($_POST['target'])
1141        {
1142                case 'all' :
1143        {
1144                foreach($page['filtered_users'] as $local_user)
1145                {
1146                        array_push($collection, $local_user['id']);
1147                }
1148                break;
1149                                }
1150        case 'selection' :
1151        {
1152                if (isset($_POST['selection']))
1153                {
1154                        $collection = $_POST['selection'];
1155                }
1156                break;
1157        }
1158                        }
1159
1160        if (count($collection) == 0)
1161        {
1162                array_push($page['errors'], l10n('Select at least one user'));
1163        }
1164                }
1165// +-----------------------------------------------------------------------+
1166// |                                                                            Force validation                                                         |
1167// +-----------------------------------------------------------------------+
1168                if (isset($_POST['Force_Validation']) and count($collection) > 0)
1169                {
1170                        if (in_array($conf['guest_id'], $collection))
1171                {
[9177]1172                array_push($page['errors'], l10n('UAM_No_validation_for_Guest'));
[5056]1173        }
1174        if (($conf['guest_id'] != $conf['default_user_id']) and
1175                in_array($conf['default_user_id'], $collection))
1176        {
[9177]1177                array_push($page['errors'], l10n('UAM_No_validation_for_default_user'));
[5056]1178        }
1179                if (in_array($conf['webmaster_id'], $collection))
1180        {
[9177]1181                array_push($page['errors'], l10n('UAM_No_validation_for_Webmaster'));
[5056]1182        }
1183        if (in_array($user['id'], $collection))
1184        {
[9177]1185                array_push($page['errors'], l10n('UAM_No_validation_for_your_account'));
[5056]1186        }
1187
1188        if (count($page['errors']) == 0)
1189        {
1190                foreach ($collection as $user_id)
1191        {
[8072]1192          ForceValidation($user_id);
[8092]1193          validation_mail($user_id);
[5056]1194        }
1195        array_push(
1196                $page['infos'],
1197                l10n_dec(
[9177]1198                        'UAM_%d_Validated_User', 'UAM_%d_Validated_Users',
[5056]1199                count($collection)
1200                )
1201        );
1202
1203                                $page['filtered_users'] = get_unvalid_user_list();
1204                        }
1205                }
1206               
1207
1208// +-----------------------------------------------------------------------+
1209// |                              groups list                              |
1210// +-----------------------------------------------------------------------+
1211
1212                $groups[-1] = '------------';
1213
1214    $query = '
1215SELECT id, name
1216  FROM '.GROUPS_TABLE.'
1217ORDER BY name ASC
1218;';
1219
1220                $result = pwg_query($query);
1221         
[5633]1222    while ($row = pwg_db_fetch_assoc($result))
[5056]1223    {
1224      $groups[$row['id']] = $row['name'];
1225    }
1226
1227// +-----------------------------------------------------------------------+
1228// |                               user list                               |
1229// +-----------------------------------------------------------------------+
1230
1231                $profile_url = get_root_url().'admin.php?page=profile&amp;user_id=';
1232                $perm_url = get_root_url().'admin.php?page=user_perm&amp;user_id=';
1233
1234    $visible_user_list = array();
1235    foreach ($page['filtered_users'] as $num => $local_user)
1236    {
1237      $visible_user_list[] = $local_user;
1238                }
1239
1240                foreach ($visible_user_list as $local_user)
1241    {
1242      $groups_string = preg_replace(
1243        '/(\d+)/e',
1244        "\$groups['$1']",
1245        implode(
1246                ', ',
1247            $local_user['groups']
1248         )
1249                        );
1250
1251      $query = '
1252SELECT user_id, reminder
1253FROM '.USER_CONFIRM_MAIL_TABLE.'
1254WHERE user_id = '.$local_user['id'].'
1255;';
1256      $result = pwg_query($query);
1257     
[5633]1258      $row = pwg_db_fetch_assoc($result);
[5056]1259   
1260      if (isset($row['reminder']) and $row['reminder'] == 'true')
1261      {
[9177]1262        $reminder = l10n('UAM_Reminder_Sent_OK');
[5056]1263      }
1264      else if ((isset($row['reminder']) and $row['reminder'] == 'false') or !isset($row['reminder']))
1265      {
[9177]1266        $reminder = l10n('UAM_Reminder_Sent_NOK');
[5056]1267      }
1268
1269
1270                if (isset($_POST['pref_submit'])
1271                and isset($_POST['selection'])
1272        and in_array($local_user['id'], $_POST['selection']))
1273                {
1274                                $checked = 'checked="checked"';
1275                }
1276                        else
1277        {
1278                $checked = '';
1279        }
1280
1281        $properties = array();
1282        if ( $local_user['level'] != 0 )
1283                        {
1284                $properties[] = l10n( sprintf('Level %d', $local_user['level']) );
1285                        }
1286        $properties[] =
1287                (isset($local_user['enabled_high']) and ($local_user['enabled_high'] == 'true'))
1288                ? l10n('is_high_enabled') : l10n('is_high_disabled');
1289
1290                        $expiration = expiration($local_user['id']);
[12271]1291
1292      // Template initialization
1293      // -----------------------
[5056]1294                $template->append(
1295                'users',
1296        array(
1297                'ID'               => $local_user['id'],
1298                'CHECKED'          => $checked,
1299                'U_PROFILE'        => $profile_url.$local_user['id'],
1300                'U_PERM'           => $perm_url.$local_user['id'],
1301                'USERNAME'         => stripslashes($local_user['username'])
1302                                  .($local_user['id'] == $conf['guest_id']
1303                                  ? '<BR>['.l10n('is_the_guest').']' : '')
1304                                  .($local_user['id'] == $conf['default_user_id']
1305                                  ? '<BR>['.l10n('is_the_default').']' : ''),
1306                                  'STATUS' => l10n('user_status_'
[8841]1307                                  .$local_user['status']),
[5056]1308                                        'EMAIL'            => get_email_address_as_display_text($local_user['email']),
1309                'GROUPS'           => $groups_string,
1310                'REGISTRATION'     => $local_user['registration_date'],
1311          'REMINDER'         => $reminder,   
1312                'EXPIRATION'       => $expiration,
1313                                )
1314                        );
[6754]1315                }   
1316
1317    // Check if validation of register is made by admin or visitor
1318    // If visitor, $Confirm_Local is used to mask useless buttons
[12271]1319    // -----------------------------------------------------------
[6754]1320    $Confirm_Local = "";
1321   
1322    if ($conf_UAM[1] == 'local')
1323    {
1324      $Confirm_Local = $conf_UAM[1];
1325    }
1326    else
1327    {
1328      $Confirm_Local = "";
1329    } 
1330   
[12271]1331    // Plugin version inserted
1332    // -----------------------
[5056]1333    $template->assign(
1334      array(
[6754]1335        'CONFIRM_LOCAL'=> $Confirm_Local,
[5181]1336        'UAM_VERSION'  => $version,
1337        'UAM_PATH'     => UAM_PATH,
[5056]1338      )
1339    );
1340
1341// +-----------------------------------------------------------------------+
1342// |                             errors display                            |
1343// +-----------------------------------------------------------------------+
1344                if ( isset ($errors) and count($errors) != 0)
1345                {
1346                $template->assign('errors',array());
1347                        foreach ($errors as $error)
1348                {
1349                                array_push($page['errors'], $error);
1350                }
1351                } 
1352
1353// +-----------------------------------------------------------------------+
1354// |                           templates display                           |
1355// +-----------------------------------------------------------------------+
[5593]1356                $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/usermanager.tpl');
[5056]1357    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');         
1358        }
1359  else
1360  {
[9177]1361                array_push($page['errors'], l10n('UAM_Err_UserManager_Settings'));
[5056]1362  }
1363  break;
1364
1365
1366// *************************************************************************
1367// +-----------------------------------------------------------------------+
1368// |                           Ghost Tracker page                          |
1369// +-----------------------------------------------------------------------+
1370// *************************************************************************
1371  case 'ghosttracker':
1372
[5181]1373  $conf_UAM = unserialize($conf['UserAdvManager']);
[5056]1374       
[11018]1375  if (isset($conf_UAM[16]) and $conf_UAM[15]=='true')
[5056]1376  {
1377// +-----------------------------------------------------------------------+
1378// |                           initialization                              |
1379// +-----------------------------------------------------------------------+
1380
1381                if (!defined('PHPWG_ROOT_PATH'))
1382    {
1383        die('Hacking attempt!');
1384    }
1385         
1386    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
1387
1388// +-----------------------------------------------------------------------+
1389// | Check Access and exit when user status is not ok                      |
1390// +-----------------------------------------------------------------------+
1391                check_status(ACCESS_ADMINISTRATOR);
1392
1393// +-----------------------------------------------------------------------+
1394// |                               user list                               |
1395// +-----------------------------------------------------------------------+
1396
1397                $page['filtered_users'] = get_ghost_user_list();
1398
1399// +-----------------------------------------------------------------------+
1400// |                            selected users                             |
1401// +-----------------------------------------------------------------------+
1402                if (isset($_POST['Del_Selected']))
1403                {
1404                $collection = array();
1405
1406                        switch ($_POST['target'])
1407        {
1408                case 'all' :
1409        {
1410                foreach($page['filtered_users'] as $local_user)
1411                {
1412                        array_push($collection, $local_user['id']);
1413                }
1414                                        break;
1415                                }
1416        case 'selection' :
1417        {
1418                if (isset($_POST['selection']))
1419                {
1420                        $collection = $_POST['selection'];
1421                }
1422                break;
1423        }
1424                        }
1425
1426                        if (count($collection) == 0)
1427        {
1428                array_push($page['errors'], l10n('Select at least one user'));
1429                }
1430                }
1431
1432// +-----------------------------------------------------------------------+
1433// |                             delete users                              |
1434// +-----------------------------------------------------------------------+
1435                if (isset($_POST['Del_Selected']) and count($collection) > 0)
1436        {
1437                if (in_array($conf['guest_id'], $collection))
1438                {
1439                array_push($page['errors'], l10n('Guest cannot be deleted'));
1440        }
1441        if (($conf['guest_id'] != $conf['default_user_id']) and
1442                in_array($conf['default_user_id'], $collection))
1443        {
1444                array_push($page['errors'], l10n('Default user cannot be deleted'));
1445        }
1446        if (in_array($conf['webmaster_id'], $collection))
1447        {
1448                array_push($page['errors'], l10n('Webmaster cannot be deleted'));
1449        }
1450        if (in_array($user['id'], $collection))
1451        {
1452                array_push($page['errors'], l10n('You cannot delete your account'));
1453        }
1454
1455                        if (count($page['errors']) == 0)
1456        {
1457                foreach ($collection as $user_id)
1458        {
1459                delete_user($user_id);
1460        }
1461                array_push(
1462                $page['infos'],
1463                l10n_dec(
1464                '%d user deleted', '%d users deleted',
1465                count($collection)
1466                )
1467        );
1468
1469        foreach ($page['filtered_users'] as $filter_key => $filter_user)
1470        {
1471                if (in_array($filter_user['id'], $collection))
1472                {
1473                        unset($page['filtered_users'][$filter_key]);
1474                }
1475                }
1476                        }
1477                }
1478
1479// +-----------------------------------------------------------------------+
1480// |                          Send ghost reminder                          |
1481// +-----------------------------------------------------------------------+
1482// +-----------------------------------------------------------------------+
1483// |                            selected users                             |
1484// +-----------------------------------------------------------------------+
1485                if (isset($_POST['Reminder_Email']))
1486                {
1487                $collection = array();
1488
1489                        switch ($_POST['target'])
1490        {
1491                case 'all' :
1492        {
1493                foreach($page['filtered_users'] as $local_user)
1494                {
1495                        array_push($collection, $local_user['id']);
1496                }
1497                break;
1498                                }
1499        case 'selection' :
1500        {
1501                if (isset($_POST['selection']))
1502                {
1503                        $collection = $_POST['selection'];
1504                }
1505                break;
1506        }
1507                        }
1508
1509        if (count($collection) == 0)
1510        {
1511                array_push($page['errors'], l10n('Select at least one user'));
1512        }
1513                }
1514// +-----------------------------------------------------------------------+
1515// |                         Send ghost reminder                           |
1516// +-----------------------------------------------------------------------+
1517                if (isset($_POST['Reminder_Email']) and count($collection) > 0)
1518                {
1519                        if (in_array($conf['guest_id'], $collection))
1520                {
[9177]1521                array_push($page['errors'], l10n('UAM_No_reminder_for_Guest'));
[5056]1522        }
1523        if (($conf['guest_id'] != $conf['default_user_id']) and
1524                in_array($conf['default_user_id'], $collection))
1525        {
[9177]1526                array_push($page['errors'], l10n('UAM_No_reminder_for_default_user'));
[5056]1527        }
1528                if (in_array($conf['webmaster_id'], $collection))
1529        {
[9177]1530                array_push($page['errors'], l10n('UAM_No_reminder_for_Webmaster'));
[5056]1531        }
1532        if (in_array($user['id'], $collection))
1533        {
[9177]1534                array_push($page['errors'], l10n('UAM_No_reminder_for_your_account'));
[5056]1535        }
1536
1537        if (count($page['errors']) == 0)
1538        {
1539                foreach ($collection as $user_id)
1540        {
1541                                  $query = "
1542SELECT id, username, mail_address
1543  FROM ".USERS_TABLE."
1544WHERE id = '".$user_id."'
1545;";
1546                                       
[5633]1547                                        $data = pwg_db_fetch_assoc(pwg_query($query));
[5056]1548                               
1549                ghostreminder($user_id,stripslashes($data['username']),$data['mail_address']);                         
1550        }
1551        array_push(
1552                $page['infos'],
1553                l10n_dec(
[9177]1554                        'UAM_%d_Reminder_Sent', 'UAM_%d_Reminders_Sent',
[5056]1555                count($collection)
1556                )
1557        );
1558       
1559                                $page['filtered_users'] = get_ghost_user_list();
1560                        }
1561                }
1562   
[9253]1563    if (isset($_POST['GhostTracker_Init']) and is_admin()) //Reset is only allowed for admins !
[5056]1564    {
[9253]1565      $query1 = '
[5056]1566SELECT *
1567  FROM '.USER_LASTVISIT_TABLE.';';
1568
[9253]1569      $count = pwg_db_num_rows(pwg_query($query1));
[5056]1570
[9253]1571      if ($count <> 0)
1572      {
1573        $query = '
[5056]1574SELECT DISTINCT u.id,
1575                ui.status AS status
1576FROM '.USERS_TABLE.' AS u
1577  INNER JOIN '.USER_INFOS_TABLE.' AS ui
1578    ON u.id = ui.user_id
1579WHERE u.id NOT IN (SELECT user_id FROM '.USER_LASTVISIT_TABLE.')
1580  AND status != "webmaster"
1581  AND status != "guest"
1582  AND status != "admin"
1583ORDER BY u.id ASC
1584;';
1585
[9253]1586        $result = pwg_query($query);
[5056]1587         
[9253]1588        while ($row = pwg_db_fetch_assoc($result))
1589        {
1590          list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
[5056]1591           
[9253]1592          $query = "
[5056]1593INSERT INTO ".USER_LASTVISIT_TABLE." (user_id, lastvisit, reminder)
1594VALUES ('".$row['id']."','".$dbnow."','false')
1595;";
[9253]1596          pwg_query($query);
[5056]1597        }
[9253]1598      }
1599      else if ($count == 0)
1600      {
1601        $query = '
[5056]1602SELECT DISTINCT u.id,
1603                ui.status AS status
1604FROM '.USERS_TABLE.' AS u
1605  INNER JOIN '.USER_INFOS_TABLE.' AS ui
1606    ON u.id = ui.user_id
1607WHERE status != "webmaster"
1608  AND status != "guest"
1609  AND status != "admin"
1610ORDER BY u.id ASC
1611;';
1612
[9253]1613        $result = pwg_query($query);
[5056]1614         
[9253]1615        while($row = pwg_db_fetch_assoc($result))
1616        {
1617          list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
[5056]1618           
[9253]1619          $query = "
[5056]1620INSERT INTO ".USER_LASTVISIT_TABLE." (user_id, lastvisit, reminder)
1621VALUES ('".$row['id']."','".$dbnow."','false')
1622;";
[9253]1623          pwg_query($query);
[5056]1624        }
[9253]1625      }
[5056]1626       
[9253]1627      array_push($page['infos'], l10n('UAM_GhostTracker_Init_OK'));
[5056]1628    }
1629
1630// +-----------------------------------------------------------------------+
1631// |                               user list                               |
1632// +-----------------------------------------------------------------------+
1633
1634    $visible_user_list = array();
1635    foreach ($page['filtered_users'] as $num => $local_user)
1636    {
1637      $visible_user_list[] = $local_user;
1638                }
[9153]1639   
[5056]1640                foreach ($visible_user_list as $local_user)
1641    {
1642      $reminder = '';
1643   
1644      if (isset($local_user['reminder']) and $local_user['reminder'] == 'true')
1645      {
[9177]1646        $reminder = l10n('UAM_Reminder_Sent_OK');
[5056]1647      }
1648      else if (isset($local_user['reminder']) and $local_user['reminder'] == 'false')
1649      {
[9177]1650        $reminder = l10n('UAM_Reminder_Sent_NOK');
[5056]1651      }
1652   
1653      if (isset($_POST['pref_submit']) and isset($_POST['selection']) and in_array($local_user['id'], $_POST['selection']))
1654                {
1655                                $checked = 'checked="checked"';
1656                }
1657                        else
1658        {
1659                $checked = '';
1660        }
1661
[12271]1662      // Template initialization
1663      // -----------------------
[5056]1664      $template->append(
1665          'users',
1666        array(
1667                'ID'          => $local_user['id'],
1668                'CHECKED'     => $checked,
1669                'USERNAME'    => stripslashes($local_user['username']),
1670                                        'EMAIL'       => get_email_address_as_display_text($local_user['email']),
1671          'LASTVISIT'   => $local_user['lastvisit'],
1672          'REMINDER'    => $reminder,
1673                                )
1674                        );
1675                }
1676
[12271]1677    // Plugin version inserted
1678    // -----------------------
[9153]1679    $template->assign(
1680      array(
1681        'UAM_VERSION'  => $version,
1682        'UAM_PATH'     => UAM_PATH,
1683      )
1684    );
1685
[5056]1686// +-----------------------------------------------------------------------+
1687// |                             errors display                            |
1688// +-----------------------------------------------------------------------+
1689                if ( isset ($errors) and count($errors) != 0)
1690                {
1691                $template->assign('errors',array());
1692                        foreach ($errors as $error)
1693                {
1694                                array_push($page['errors'], $error);
1695                }
1696                } 
1697
1698// +-----------------------------------------------------------------------+
1699// |                           templates display                           |
1700// +-----------------------------------------------------------------------+
[5593]1701                $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/ghosttracker.tpl');
[5056]1702    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');         
1703        }
1704  else
1705  {
[9177]1706                array_push($page['errors'], l10n('UAM_Err_GhostTracker_Settings'));
[5056]1707  }
1708
1709  break;
1710}
1711?>
Note: See TracBrowser for help on using the repository browser.