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

Last change on this file since 12314 was 12314, checked in by Eric, 13 years ago

Bug 2455 fixed - Exclusion of specific users (généric and admins users) for password reset function.
Bug 2451 fixed - Unable to handle Sql errors but control of backup file validity have been enforced.

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