source: extensions/NBC_UserAdvManager/tags/2.14.0/admin/UAM_admin.php @ 5092

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

[NBC_UserAdvManager] Tag 2.14.0 merged from 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      }
567      /* Plugin version inserted */
568      $template->assign(
569        array(
570          'UAM_VERSION' => $version,
571          'NBC_UAM_PATH'=> NBC_UAM_PATH,
572          )
573        );
574
575                $template->append(
576                'users',
577        array(
578                'ID'          => $local_user['id'],
579                'USERNAME'    => stripslashes($local_user['username']),
580                                        'EMAIL'       => get_email_address_as_display_text($local_user['email']),
581          'LASTVISIT'   => $local_user['lastvisit'],
582          'DAYS'        => $deltadays,
583          'DISPLAY'     => $display,
584                                )
585                        );
586                }
587// +-----------------------------------------------------------------------+
588// |                             errors display                            |
589// +-----------------------------------------------------------------------+
590                if ( isset ($errors) and count($errors) != 0)
591                {
592                $template->assign('errors',array());
593                        foreach ($errors as $error)
594                {
595                                array_push($page['errors'], $error);
596                }
597                } 
598
599// +-----------------------------------------------------------------------+
600// |                           templates display                           |
601// +-----------------------------------------------------------------------+
602                $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/userlist.tpl');
603    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');         
604  }
605  else
606  {
607                array_push($page['infos'], l10n('Err_Userlist_Settings'));
608  }
609  break;
610
611
612// *************************************************************************
613// +-----------------------------------------------------------------------+
614// |                           Users manager page                          |
615// +-----------------------------------------------------------------------+
616// *************************************************************************
617  case 'usermanager':
618
619  $conf_UAM = unserialize($conf['nbc_UserAdvManager']);
620
621  $conf_UAM_ConfirmMail = unserialize($conf['nbc_UserAdvManager_ConfirmMail']);
622       
623  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')
624  {
625// +-----------------------------------------------------------------------+
626// |                           initialization                              |
627// +-----------------------------------------------------------------------+
628
629                if (!defined('PHPWG_ROOT_PATH'))
630    {
631        die('Hacking attempt!');
632    }
633         
634    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
635
636// +-----------------------------------------------------------------------+
637// | Check Access and exit when user status is not ok                      |
638// +-----------------------------------------------------------------------+
639                check_status(ACCESS_ADMINISTRATOR);
640
641// +-----------------------------------------------------------------------+
642// |                               user list                               |
643// +-----------------------------------------------------------------------+
644
645                $page['filtered_users'] = get_unvalid_user_list();
646
647// +-----------------------------------------------------------------------+
648// |                            selected users                             |
649// +-----------------------------------------------------------------------+
650                if (isset($_POST['Del_Selected']))
651                {
652                $collection = array();
653
654                        switch ($_POST['target'])
655        {
656                case 'all' :
657        {
658                foreach($page['filtered_users'] as $local_user)
659                {
660                        array_push($collection, $local_user['id']);
661                }
662                                        break;
663                                }
664        case 'selection' :
665        {
666                if (isset($_POST['selection']))
667                {
668                        $collection = $_POST['selection'];
669                }
670                break;
671        }
672                        }
673
674                        if (count($collection) == 0)
675        {
676                array_push($page['errors'], l10n('Select at least one user'));
677                }
678                }
679
680// +-----------------------------------------------------------------------+
681// |                             delete users                              |
682// +-----------------------------------------------------------------------+
683                if (isset($_POST['Del_Selected']) and count($collection) > 0)
684        {
685                if (in_array($conf['guest_id'], $collection))
686                {
687                array_push($page['errors'], l10n('Guest cannot be deleted'));
688        }
689        if (($conf['guest_id'] != $conf['default_user_id']) and
690                in_array($conf['default_user_id'], $collection))
691        {
692                array_push($page['errors'], l10n('Default user cannot be deleted'));
693        }
694        if (in_array($conf['webmaster_id'], $collection))
695        {
696                array_push($page['errors'], l10n('Webmaster cannot be deleted'));
697        }
698        if (in_array($user['id'], $collection))
699        {
700                array_push($page['errors'], l10n('You cannot delete your account'));
701        }
702
703                        if (count($page['errors']) == 0)
704        {
705                foreach ($collection as $user_id)
706        {
707                delete_user($user_id);
708        }
709                array_push(
710                $page['infos'],
711                l10n_dec(
712                '%d user deleted', '%d users deleted',
713                count($collection)
714                )
715        );
716
717        foreach ($page['filtered_users'] as $filter_key => $filter_user)
718        {
719                if (in_array($filter_user['id'], $collection))
720                {
721                        unset($page['filtered_users'][$filter_key]);
722                }
723                }
724                        }
725                }
726
727// +-----------------------------------------------------------------------+
728// |                 Resend new validation key to users                    |
729// +-----------------------------------------------------------------------+
730// +-----------------------------------------------------------------------+
731// |                            selected users                             |
732// +-----------------------------------------------------------------------+
733                if (isset($_POST['Mail_With_Key']))
734                {
735                $collection = array();
736
737                        switch ($_POST['target'])
738        {
739                case 'all' :
740        {
741                foreach($page['filtered_users'] as $local_user)
742                {
743                        array_push($collection, $local_user['id']);
744                }
745                break;
746                                }
747        case 'selection' :
748        {
749                if (isset($_POST['selection']))
750                {
751                        $collection = $_POST['selection'];
752                }
753                break;
754        }
755                        }
756
757        if (count($collection) == 0)
758        {
759                array_push($page['errors'], l10n('Select at least one user'));
760        }
761                }
762// +-----------------------------------------------------------------------+
763// |                 Resend new validation key to users                    |
764// +-----------------------------------------------------------------------+
765                if (isset($_POST['Mail_With_Key']) and count($collection) > 0)
766                {
767                        if (in_array($conf['guest_id'], $collection))
768                {
769                array_push($page['errors'], l10n('No_validation_for_Guest'));
770        }
771        if (($conf['guest_id'] != $conf['default_user_id']) and
772                in_array($conf['default_user_id'], $collection))
773        {
774                array_push($page['errors'], l10n('No_validation_for_default_user'));
775        }
776                if (in_array($conf['webmaster_id'], $collection))
777        {
778                array_push($page['errors'], l10n('No_validation_for_Webmaster'));
779        }
780        if (in_array($user['id'], $collection))
781        {
782                array_push($page['errors'], l10n('No_validation_for_your_account'));
783        }
784
785        if (count($page['errors']) == 0)
786        {
787                foreach ($collection as $user_id)
788        {       
789                $typemail = 1;
790                                  $query = "
791SELECT id, username, mail_address
792  FROM ".USERS_TABLE."
793WHERE id = '".$user_id."'
794;";
795                                        $data = mysql_fetch_assoc(pwg_query($query));
796                               
797                ResendMail2User($typemail,$user_id,stripslashes($data['username']),$data['mail_address'],true);
798        }
799        array_push(
800                $page['infos'],
801                l10n_dec(
802                        '%d_Mail_With_Key', '%d_Mails_With_Key',
803                count($collection)
804                )
805        );
806       
807                                $page['filtered_users'] = get_unvalid_user_list();
808                        }
809                }
810
811// +-----------------------------------------------------------------------+
812// |             Send reminder without new key to users                    |
813// +-----------------------------------------------------------------------+
814// +-----------------------------------------------------------------------+
815// |                            selected users                             |
816// +-----------------------------------------------------------------------+
817                if (isset($_POST['Mail_Without_Key']))
818                {
819                $collection = array();
820
821                        switch ($_POST['target'])
822        {
823                case 'all' :
824        {
825                foreach($page['filtered_users'] as $local_user)
826                {
827                        array_push($collection, $local_user['id']);
828                }
829                break;
830                                }
831        case 'selection' :
832        {
833                if (isset($_POST['selection']))
834                {
835                        $collection = $_POST['selection'];
836                }
837                break;
838        }
839                        }
840
841        if (count($collection) == 0)
842        {
843                array_push($page['errors'], l10n('Select at least one user'));
844        }
845                }
846// +-----------------------------------------------------------------------+
847// |             Send reminder without new key to users                    |
848// +-----------------------------------------------------------------------+
849                if (isset($_POST['Mail_Without_Key']) and count($collection) > 0)
850                {
851                        if (in_array($conf['guest_id'], $collection))
852                {
853                array_push($page['errors'], l10n('No_validation_for_Guest'));
854        }
855        if (($conf['guest_id'] != $conf['default_user_id']) and
856                in_array($conf['default_user_id'], $collection))
857        {
858                array_push($page['errors'], l10n('No_validation_for_default_user'));
859        }
860                if (in_array($conf['webmaster_id'], $collection))
861        {
862                array_push($page['errors'], l10n('No_validation_for_Webmaster'));
863        }
864        if (in_array($user['id'], $collection))
865        {
866                array_push($page['errors'], l10n('No_validation_for_your_account'));
867        }
868
869        if (count($page['errors']) == 0)
870        {
871                foreach ($collection as $user_id)
872        {
873                $typemail = 2;
874                                  $query = "
875SELECT id, username, mail_address
876  FROM ".USERS_TABLE."
877WHERE id = '".$user_id."'
878;";
879                                       
880                                        $data = mysql_fetch_assoc(pwg_query($query));
881                               
882                ResendMail2User($typemail,$user_id,stripslashes($data['username']),$data['mail_address'],false);                               
883        }
884        array_push(
885                $page['infos'],
886                l10n_dec(
887                        '%d_Reminder_Sent', '%d_Reminders_Sent',
888                count($collection)
889                )
890        );
891       
892                                $page['filtered_users'] = get_unvalid_user_list();
893                        }
894                }
895
896// +-----------------------------------------------------------------------+
897// |                                                                            Force validation                                                         |
898// +-----------------------------------------------------------------------+
899// +-----------------------------------------------------------------------+
900// |                            selected users                             |
901// +-----------------------------------------------------------------------+
902                if (isset($_POST['Force_Validation']))
903                {
904                $collection = array();
905
906                        switch ($_POST['target'])
907        {
908                case 'all' :
909        {
910                foreach($page['filtered_users'] as $local_user)
911                {
912                        array_push($collection, $local_user['id']);
913                }
914                break;
915                                }
916        case 'selection' :
917        {
918                if (isset($_POST['selection']))
919                {
920                        $collection = $_POST['selection'];
921                }
922                break;
923        }
924                        }
925
926        if (count($collection) == 0)
927        {
928                array_push($page['errors'], l10n('Select at least one user'));
929        }
930                }
931// +-----------------------------------------------------------------------+
932// |                                                                            Force validation                                                         |
933// +-----------------------------------------------------------------------+
934                if (isset($_POST['Force_Validation']) and count($collection) > 0)
935                {
936                        if (in_array($conf['guest_id'], $collection))
937                {
938                array_push($page['errors'], l10n('No_validation_for_Guest'));
939        }
940        if (($conf['guest_id'] != $conf['default_user_id']) and
941                in_array($conf['default_user_id'], $collection))
942        {
943                array_push($page['errors'], l10n('No_validation_for_default_user'));
944        }
945                if (in_array($conf['webmaster_id'], $collection))
946        {
947                array_push($page['errors'], l10n('No_validation_for_Webmaster'));
948        }
949        if (in_array($user['id'], $collection))
950        {
951                array_push($page['errors'], l10n('No_validation_for_your_account'));
952        }
953
954        if (count($page['errors']) == 0)
955        {
956                foreach ($collection as $user_id)
957        {
958                                  $query = "
959SELECT id, username, mail_address
960  FROM ".USERS_TABLE."
961WHERE id = '".$user_id."'
962;";
963                                       
964                                        $data = mysql_fetch_assoc(pwg_query($query));
965                               
966                ForceValidation($data['id']);                           
967        }
968        array_push(
969                $page['infos'],
970                l10n_dec(
971                        '%d_Validated_User', '%d_Validated_Users',
972                count($collection)
973                )
974        );
975
976                                $page['filtered_users'] = get_unvalid_user_list();
977                        }
978                }
979               
980
981// +-----------------------------------------------------------------------+
982// |                              groups list                              |
983// +-----------------------------------------------------------------------+
984
985                $groups[-1] = '------------';
986
987    $query = '
988SELECT id, name
989  FROM '.GROUPS_TABLE.'
990ORDER BY name ASC
991;';
992
993                $result = pwg_query($query);
994         
995    while ($row = mysql_fetch_assoc($result))
996    {
997      $groups[$row['id']] = $row['name'];
998    }
999
1000// +-----------------------------------------------------------------------+
1001// |                           Template Init                               |
1002// +-----------------------------------------------------------------------+
1003                $base_url = PHPWG_ROOT_PATH.'admin.php?page=user_list';
1004
1005    if (isset($_GET['start']) and is_numeric($_GET['start']))
1006    {
1007      $start = $_GET['start'];
1008    }
1009    else
1010    {
1011      $start = 0;
1012    }
1013
1014/* Hide radio-button if not allow to assign adviser */
1015                if ($conf['allow_adviser'])
1016        {
1017        $template->assign('adviser', true);
1018        }
1019
1020// +-----------------------------------------------------------------------+
1021// |                            navigation bar                             |
1022// +-----------------------------------------------------------------------+
1023
1024$url = PHPWG_ROOT_PATH.'admin.php'.get_query_string_diff(array('start'));
1025
1026$navbar = create_navigation_bar(
1027  $url,
1028  count($page['filtered_users']),
1029  $start,
1030  $conf['users_page']
1031  );
1032
1033$template->assign('NAVBAR', $navbar);
1034
1035// +-----------------------------------------------------------------------+
1036// |                               user list                               |
1037// +-----------------------------------------------------------------------+
1038
1039                $profile_url = get_root_url().'admin.php?page=profile&amp;user_id=';
1040                $perm_url = get_root_url().'admin.php?page=user_perm&amp;user_id=';
1041
1042    $visible_user_list = array();
1043    foreach ($page['filtered_users'] as $num => $local_user)
1044    {
1045/* simulate LIMIT $start, $conf['users_page'] */
1046                        if ($num < $start)
1047      {
1048        continue;
1049      }
1050      if ($num >= $start + $conf['users_page'])
1051      {
1052        break;
1053      }
1054
1055      $visible_user_list[] = $local_user;
1056                }
1057
1058                foreach ($visible_user_list as $local_user)
1059    {
1060      $groups_string = preg_replace(
1061        '/(\d+)/e',
1062        "\$groups['$1']",
1063        implode(
1064                ', ',
1065            $local_user['groups']
1066         )
1067                        );
1068
1069      $query = '
1070SELECT user_id, reminder
1071FROM '.USER_CONFIRM_MAIL_TABLE.'
1072WHERE user_id = '.$local_user['id'].'
1073;';
1074      $result = pwg_query($query);
1075     
1076      $row = mysql_fetch_assoc($result);
1077   
1078      if (isset($row['reminder']) and $row['reminder'] == 'true')
1079      {
1080        $reminder = l10n('Reminder_Sent_OK');
1081      }
1082      else if ((isset($row['reminder']) and $row['reminder'] == 'false') or !isset($row['reminder']))
1083      {
1084        $reminder = l10n('Reminder_Sent_NOK');
1085      }
1086
1087
1088                if (isset($_POST['pref_submit'])
1089                and isset($_POST['selection'])
1090        and in_array($local_user['id'], $_POST['selection']))
1091                {
1092                                $checked = 'checked="checked"';
1093                }
1094                        else
1095        {
1096                $checked = '';
1097        }
1098
1099        $properties = array();
1100        if ( $local_user['level'] != 0 )
1101                        {
1102                $properties[] = l10n( sprintf('Level %d', $local_user['level']) );
1103                        }
1104        $properties[] =
1105                (isset($local_user['enabled_high']) and ($local_user['enabled_high'] == 'true'))
1106                ? l10n('is_high_enabled') : l10n('is_high_disabled');
1107
1108                        $expiration = expiration($local_user['id']);
1109
1110                $template->append(
1111                'users',
1112        array(
1113                'ID'               => $local_user['id'],
1114                'CHECKED'          => $checked,
1115                'U_PROFILE'        => $profile_url.$local_user['id'],
1116                'U_PERM'           => $perm_url.$local_user['id'],
1117                'USERNAME'         => stripslashes($local_user['username'])
1118                                  .($local_user['id'] == $conf['guest_id']
1119                                  ? '<BR>['.l10n('is_the_guest').']' : '')
1120                                  .($local_user['id'] == $conf['default_user_id']
1121                                  ? '<BR>['.l10n('is_the_default').']' : ''),
1122                                  'STATUS' => l10n('user_status_'
1123                                  .$local_user['status']).(($local_user['adviser'] == 'true')
1124                                  ? '<BR>['.l10n('adviser').']' : ''),
1125                                        'EMAIL'            => get_email_address_as_display_text($local_user['email']),
1126                'GROUPS'           => $groups_string,
1127                'REGISTRATION'     => $local_user['registration_date'],
1128          'REMINDER'         => $reminder,   
1129                'EXPIRATION'       => $expiration,
1130                                )
1131                        );
1132                }
1133    /* Plugin version inserted */
1134    $template->assign(
1135      array(
1136        'UAM_VERSION'      => $version,
1137        'NBC_UAM_PATH'     => NBC_UAM_PATH,
1138      )
1139    );
1140
1141// +-----------------------------------------------------------------------+
1142// |                             errors display                            |
1143// +-----------------------------------------------------------------------+
1144                if ( isset ($errors) and count($errors) != 0)
1145                {
1146                $template->assign('errors',array());
1147                        foreach ($errors as $error)
1148                {
1149                                array_push($page['errors'], $error);
1150                }
1151                } 
1152
1153// +-----------------------------------------------------------------------+
1154// |                           templates display                           |
1155// +-----------------------------------------------------------------------+
1156                $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/usermanager.tpl');
1157    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');         
1158        }
1159  else
1160  {
1161                array_push($page['infos'], l10n('Err_UserManager_Settings'));
1162  }
1163  break;
1164
1165
1166// *************************************************************************
1167// +-----------------------------------------------------------------------+
1168// |                           Ghost Tracker page                          |
1169// +-----------------------------------------------------------------------+
1170// *************************************************************************
1171  case 'ghosttracker':
1172
1173  $conf_UAM = unserialize($conf['nbc_UserAdvManager']);
1174       
1175  if (isset($conf_UAM[17]) and $conf_UAM[17]=='true')
1176  {
1177// +-----------------------------------------------------------------------+
1178// |                           initialization                              |
1179// +-----------------------------------------------------------------------+
1180
1181                if (!defined('PHPWG_ROOT_PATH'))
1182    {
1183        die('Hacking attempt!');
1184    }
1185         
1186    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
1187
1188// +-----------------------------------------------------------------------+
1189// | Check Access and exit when user status is not ok                      |
1190// +-----------------------------------------------------------------------+
1191                check_status(ACCESS_ADMINISTRATOR);
1192
1193// +-----------------------------------------------------------------------+
1194// |                               user list                               |
1195// +-----------------------------------------------------------------------+
1196
1197                $page['filtered_users'] = get_ghost_user_list();
1198
1199// +-----------------------------------------------------------------------+
1200// |                            selected users                             |
1201// +-----------------------------------------------------------------------+
1202                if (isset($_POST['Del_Selected']))
1203                {
1204                $collection = array();
1205
1206                        switch ($_POST['target'])
1207        {
1208                case 'all' :
1209        {
1210                foreach($page['filtered_users'] as $local_user)
1211                {
1212                        array_push($collection, $local_user['id']);
1213                }
1214                                        break;
1215                                }
1216        case 'selection' :
1217        {
1218                if (isset($_POST['selection']))
1219                {
1220                        $collection = $_POST['selection'];
1221                }
1222                break;
1223        }
1224                        }
1225
1226                        if (count($collection) == 0)
1227        {
1228                array_push($page['errors'], l10n('Select at least one user'));
1229                }
1230                }
1231
1232// +-----------------------------------------------------------------------+
1233// |                             delete users                              |
1234// +-----------------------------------------------------------------------+
1235                if (isset($_POST['Del_Selected']) and count($collection) > 0)
1236        {
1237                if (in_array($conf['guest_id'], $collection))
1238                {
1239                array_push($page['errors'], l10n('Guest cannot be deleted'));
1240        }
1241        if (($conf['guest_id'] != $conf['default_user_id']) and
1242                in_array($conf['default_user_id'], $collection))
1243        {
1244                array_push($page['errors'], l10n('Default user cannot be deleted'));
1245        }
1246        if (in_array($conf['webmaster_id'], $collection))
1247        {
1248                array_push($page['errors'], l10n('Webmaster cannot be deleted'));
1249        }
1250        if (in_array($user['id'], $collection))
1251        {
1252                array_push($page['errors'], l10n('You cannot delete your account'));
1253        }
1254
1255                        if (count($page['errors']) == 0)
1256        {
1257                foreach ($collection as $user_id)
1258        {
1259                delete_user($user_id);
1260        }
1261                array_push(
1262                $page['infos'],
1263                l10n_dec(
1264                '%d user deleted', '%d users deleted',
1265                count($collection)
1266                )
1267        );
1268
1269        foreach ($page['filtered_users'] as $filter_key => $filter_user)
1270        {
1271                if (in_array($filter_user['id'], $collection))
1272                {
1273                        unset($page['filtered_users'][$filter_key]);
1274                }
1275                }
1276                        }
1277                }
1278
1279// +-----------------------------------------------------------------------+
1280// |                          Send ghost reminder                          |
1281// +-----------------------------------------------------------------------+
1282// +-----------------------------------------------------------------------+
1283// |                            selected users                             |
1284// +-----------------------------------------------------------------------+
1285                if (isset($_POST['Reminder_Email']))
1286                {
1287                $collection = array();
1288
1289                        switch ($_POST['target'])
1290        {
1291                case 'all' :
1292        {
1293                foreach($page['filtered_users'] as $local_user)
1294                {
1295                        array_push($collection, $local_user['id']);
1296                }
1297                break;
1298                                }
1299        case 'selection' :
1300        {
1301                if (isset($_POST['selection']))
1302                {
1303                        $collection = $_POST['selection'];
1304                }
1305                break;
1306        }
1307                        }
1308
1309        if (count($collection) == 0)
1310        {
1311                array_push($page['errors'], l10n('Select at least one user'));
1312        }
1313                }
1314// +-----------------------------------------------------------------------+
1315// |                         Send ghost reminder                           |
1316// +-----------------------------------------------------------------------+
1317                if (isset($_POST['Reminder_Email']) and count($collection) > 0)
1318                {
1319                        if (in_array($conf['guest_id'], $collection))
1320                {
1321                array_push($page['errors'], l10n('No_reminder_for_Guest'));
1322        }
1323        if (($conf['guest_id'] != $conf['default_user_id']) and
1324                in_array($conf['default_user_id'], $collection))
1325        {
1326                array_push($page['errors'], l10n('No_reminder_for_default_user'));
1327        }
1328                if (in_array($conf['webmaster_id'], $collection))
1329        {
1330                array_push($page['errors'], l10n('No_reminder_for_Webmaster'));
1331        }
1332        if (in_array($user['id'], $collection))
1333        {
1334                array_push($page['errors'], l10n('No_reminder_for_your_account'));
1335        }
1336
1337        if (count($page['errors']) == 0)
1338        {
1339                foreach ($collection as $user_id)
1340        {
1341                                  $query = "
1342SELECT id, username, mail_address
1343  FROM ".USERS_TABLE."
1344WHERE id = '".$user_id."'
1345;";
1346                                       
1347                                        $data = mysql_fetch_assoc(pwg_query($query));
1348                               
1349                ghostreminder($user_id,stripslashes($data['username']),$data['mail_address']);                         
1350        }
1351        array_push(
1352                $page['infos'],
1353                l10n_dec(
1354                        '%d_Reminder_Sent', '%d_Reminders_Sent',
1355                count($collection)
1356                )
1357        );
1358       
1359                                $page['filtered_users'] = get_ghost_user_list();
1360                        }
1361                }
1362   
1363    if (isset($_POST['GhostTracker_Init']))
1364    {
1365      /* Reset is only allowed for admins ! */
1366      if (is_admin() and !is_adviser())
1367      {
1368        $query1 = '
1369SELECT *
1370  FROM '.USER_LASTVISIT_TABLE.';';
1371
1372        $count = mysql_num_rows(pwg_query($query1));
1373
1374        if ($count <> 0)
1375        {
1376          $query = '
1377SELECT DISTINCT u.id,
1378                ui.status AS status
1379FROM '.USERS_TABLE.' AS u
1380  INNER JOIN '.USER_INFOS_TABLE.' AS ui
1381    ON u.id = ui.user_id
1382WHERE u.id NOT IN (SELECT user_id FROM '.USER_LASTVISIT_TABLE.')
1383  AND status != "webmaster"
1384  AND status != "guest"
1385  AND status != "admin"
1386ORDER BY u.id ASC
1387;';
1388
1389          $result = pwg_query($query);
1390         
1391          while ($row = mysql_fetch_assoc($result))
1392          {
1393            list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
1394           
1395            $query = "
1396INSERT INTO ".USER_LASTVISIT_TABLE." (user_id, lastvisit, reminder)
1397VALUES ('".$row['id']."','".$dbnow."','false')
1398;";
1399            pwg_query($query);
1400          }
1401        }
1402        else if ($count == 0)
1403        {
1404          $query = '
1405SELECT DISTINCT u.id,
1406                ui.status AS status
1407FROM '.USERS_TABLE.' AS u
1408  INNER JOIN '.USER_INFOS_TABLE.' AS ui
1409    ON u.id = ui.user_id
1410WHERE status != "webmaster"
1411  AND status != "guest"
1412  AND status != "admin"
1413ORDER BY u.id ASC
1414;';
1415
1416          $result = pwg_query($query);
1417         
1418          while($row = mysql_fetch_assoc($result))
1419          {
1420            list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
1421           
1422            $query = "
1423INSERT INTO ".USER_LASTVISIT_TABLE." (user_id, lastvisit, reminder)
1424VALUES ('".$row['id']."','".$dbnow."','false')
1425;";
1426            pwg_query($query);
1427          }
1428        }
1429       
1430        array_push($page['infos'], l10n('GhostTracker_Init_OK'));
1431      }
1432    }
1433
1434// +-----------------------------------------------------------------------+
1435// |                           Template Init                               |
1436// +-----------------------------------------------------------------------+
1437                $base_url = PHPWG_ROOT_PATH.'admin.php?page=user_list';
1438
1439    if (isset($_GET['start']) and is_numeric($_GET['start']))
1440    {
1441      $start = $_GET['start'];
1442    }
1443    else
1444    {
1445      $start = 0;
1446    }
1447
1448/* Hide radio-button if not allow to assign adviser */
1449                if ($conf['allow_adviser'])
1450    {
1451      $template->assign('adviser', true);
1452        }
1453
1454// +-----------------------------------------------------------------------+
1455// |                            navigation bar                             |
1456// +-----------------------------------------------------------------------+
1457
1458$url = PHPWG_ROOT_PATH.'admin.php'.get_query_string_diff(array('start'));
1459
1460$navbar = create_navigation_bar(
1461  $url,
1462  count($page['filtered_users']),
1463  $start,
1464  $conf['users_page']
1465  );
1466
1467$template->assign('NAVBAR', $navbar);
1468
1469// +-----------------------------------------------------------------------+
1470// |                               user list                               |
1471// +-----------------------------------------------------------------------+
1472
1473    $visible_user_list = array();
1474    foreach ($page['filtered_users'] as $num => $local_user)
1475    {
1476/* simulate LIMIT $start, $conf['users_page'] */
1477                        if ($num < $start)
1478      {
1479        continue;
1480      }
1481      if ($num >= $start + $conf['users_page'])
1482      {
1483        break;
1484      }
1485
1486      $visible_user_list[] = $local_user;
1487                }
1488
1489/* Plugin version inserted */
1490      $template->assign(
1491        array(
1492          'UAM_VERSION'      => $version,
1493          'NBC_UAM_PATH'     => NBC_UAM_PATH,
1494        )
1495      );
1496
1497                foreach ($visible_user_list as $local_user)
1498    {
1499      $reminder = '';
1500   
1501      if (isset($local_user['reminder']) and $local_user['reminder'] == 'true')
1502      {
1503        $reminder = l10n('Reminder_Sent_OK');
1504      }
1505      else if (isset($local_user['reminder']) and $local_user['reminder'] == 'false')
1506      {
1507        $reminder = l10n('Reminder_Sent_NOK');
1508      }
1509   
1510      if (isset($_POST['pref_submit']) and isset($_POST['selection']) and in_array($local_user['id'], $_POST['selection']))
1511                {
1512                                $checked = 'checked="checked"';
1513                }
1514                        else
1515        {
1516                $checked = '';
1517        }
1518
1519      $template->append(
1520          'users',
1521        array(
1522                'ID'          => $local_user['id'],
1523                'CHECKED'     => $checked,
1524                'USERNAME'    => stripslashes($local_user['username']),
1525                                        'EMAIL'       => get_email_address_as_display_text($local_user['email']),
1526          'LASTVISIT'   => $local_user['lastvisit'],
1527          'REMINDER'    => $reminder,
1528                                )
1529                        );
1530                }
1531
1532// +-----------------------------------------------------------------------+
1533// |                             errors display                            |
1534// +-----------------------------------------------------------------------+
1535                if ( isset ($errors) and count($errors) != 0)
1536                {
1537                $template->assign('errors',array());
1538                        foreach ($errors as $error)
1539                {
1540                                array_push($page['errors'], $error);
1541                }
1542                } 
1543
1544// +-----------------------------------------------------------------------+
1545// |                           templates display                           |
1546// +-----------------------------------------------------------------------+
1547                $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/ghosttracker.tpl');
1548    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');         
1549        }
1550  else
1551  {
1552                array_push($page['infos'], l10n('Err_GhostTracker_Settings'));
1553  }
1554
1555  break;
1556}
1557?>
Note: See TracBrowser for help on using the repository browser.