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

Last change on this file since 5064 was 5064, checked in by Eric, 14 years ago

[NBC_UserAdvManager] Pre-2.14.0

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