source: extensions/UserAdvManager/branches/2.20/admin/UAM_admin.php @ 10360

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

r10359 merged from trunk to branch 2.20

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