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

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

For compliance with new online translation tool:

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