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

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

Translation improvement : Merging duplicated strings. DE language are not set to find what's wrong with the translation tool.

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