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

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