source: extensions/NBC_UserAdvManager/trunk/admin/UAM_admin.php @ 9253

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

Bug 2192 fixed
Bug 2045 improvement

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