source: extensions/UserAdvManager/branches/2.30/admin/UAM_admin.php @ 12276

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

Merge r12275 from trunk to branch 2.30

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