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

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

[NBC_UserAdvManager] Pre 2.13

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