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

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

[NBC_UserAdvManager]
Bug 1238 fixed - Simple custom email text wasn't send when Extended Description plugin wasn't set
Bug 1245 fixed - Semicolons (;) are no longer allowed in text areas (mail info text, ConfirmMail text, reminder text,...). They'll be replaced by dots (.).
Bug 1248 fixed - Php notice on user registration with a forbidden email domain
Bug 1250 fixed - Email provider didn't work after the third exclusion in list

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