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

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