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

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

Bug 2336 fixed - New feature : Add [Kdays] autotext flag to insert the number of days until expiration.
Version 2.20.11 hard coded for publication.

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