source: extensions/NBC_UserAdvManager/branches/2.14/admin/UAM_admin.php @ 5106

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

[NBC_UserAdvManager] Pre-2.14.1 merged from trunk to branch 2.14

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