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

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

[NBC_UserAdvManager] Pre-2.14.0

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