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

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