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

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

r11018 merged from trunk to branch 2.20

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