source: extensions/NBC_UserAdvManager/trunk/admin/UserAdvManager_admin.php @ 4544

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

[NBC_UserAdvManager]

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