source: extensions/NBC_UserAdvManager/branches/2.20/admin/UAM_admin.php @ 9136

Last change on this file since 9136 was 9136, checked in by Eric, 13 years ago

Bug 1666 merged from trunk to branch 2.20

  • 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 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']) and isset($_POST['UAM_CustomPasswRetr']))
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    $_POST['UAM_CustomPasswRetr_Text'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_CustomPasswRetr_Text'])));
124
125    //Check if CR-LF exist at begining and end of mail exclusion list - If yes, removes them
126    if (preg_match('/^[\s]+/', $_POST['UAM_MailExclusion_List']))
127    {
128      array_push($page['errors'], l10n('mail_exclusionlist_error'));
129      $UAM_Exclusionlist_Error = true;
130    }
131
132    // Consistency check between ConfirmMail and AutoMail - We cannot use GTAutoMail if ConfirmMail is disabled
133    $conf_UAM = unserialize($conf['UserAdvManager']);
134   
135    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')
136    {
137      $newvalue = 'false';
138      $_POST['UAM_GTAutoMail'] = $newvalue;
139      array_push($page['errors'], l10n('Error_GTAutoMail_cannot_be_set_without_ConfirmMail'));
140    }
141
142                $newconf_UAM = array(
143      $_POST['UAM_Mail_Info'],
144      $_POST['UAM_Confirm_Mail'],
145      (isset($_POST['UAM_No_Confirm_Group'])?$_POST['UAM_No_Confirm_Group']:''),
146      (isset($_POST['UAM_Validated_Group'])?$_POST['UAM_Validated_Group']:''),
147      (isset($_POST['UAM_Validated_Status'])?$_POST['UAM_Validated_Status']:''),
148      $_POST['UAM_No_Comment_Anonymous'],
149      $_POST['UAM_Username_Char'],
150      $_POST['UAM_Username_List'],
151      (isset($_POST['UAM_No_Confirm_Status'])?$_POST['UAM_No_Confirm_Status']:''),
152      $_POST['UAM_MailInfo_Text'],
153      $_POST['UAM_ConfirmMail_Text'],
154      $_POST['UAM_MailExclusion'],
155      $_POST['UAM_MailExclusion_List'],
156      $_POST['UAM_Password_Enforced'],
157      $_POST['UAM_Password_Score'],
158      $_POST['UAM_AdminPassword_Enforced'],
159      $_POST['UAM_GhostUser_Tracker'],
160      $_POST['UAM_GhostTracker_DayLimit'],
161      $_POST['UAM_GhostTracker_ReminderText'],
162      $_POST['UAM_Add_LastVisit_Column'],
163      $_POST['UAM_Admin_ConfMail'],
164      $_POST['UAM_RedirToProfile'],
165      $_POST['UAM_GTAuto'],
166      $_POST['UAM_GTAutoMail'],
167      $_POST['UAM_GTAutoDelText'],
168      $_POST['UAM_GTAutoMailText'],
169      (isset($_POST['UAM_Downgrade_Group'])?$_POST['UAM_Downgrade_Group']:''),
170      (isset($_POST['UAM_Downgrade_Status'])?$_POST['UAM_Downgrade_Status']:''),
171      $_POST['UAM_AdminValidationMail_Text'],
172      $_POST['UAM_CustomPasswRetr'],
173      $_POST['UAM_CustomPasswRetr_Text']
174      );
175
176    $conf['UserAdvManager'] = serialize($newconf_UAM);
177
178                $query = '
179                UPDATE '.CONFIG_TABLE.'
180                SET value="'.addslashes($conf['UserAdvManager']).'"
181                WHERE param="UserAdvManager"
182                LIMIT 1
183                ;';
184               
185                pwg_query($query);
186
187    //Email confirmation settings
188    $_POST['UAM_ConfirmMail_ReMail_Txt1'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_ConfirmMail_ReMail_Txt1'])));
189
190    $_POST['UAM_ConfirmMail_ReMail_Txt2'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_ConfirmMail_ReMail_Txt2'])));
191   
192    $_POST['UAM_ConfirmMail_Custom_Txt1'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_ConfirmMail_Custom_Txt1'])));
193   
194    $_POST['UAM_ConfirmMail_Custom_Txt2'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_ConfirmMail_Custom_Txt2'])));
195   
196          $newconf_UAM_ConfirmMail = array (
197      $_POST['UAM_ConfirmMail_TimeOut'],
198      $_POST['UAM_ConfirmMail_Delay'],
199      $_POST['UAM_ConfirmMail_ReMail_Txt1'],
200      $_POST['UAM_ConfirmMail_Remail'],
201      $_POST['UAM_ConfirmMail_ReMail_Txt2'],
202      $_POST['UAM_ConfirmMail_Custom_Txt1'],
203      $_POST['UAM_ConfirmMail_Custom_Txt2']);
204
205    $conf['UserAdvManager_ConfirmMail'] = serialize($newconf_UAM_ConfirmMail);
206   
207          $query = '
208      UPDATE '.CONFIG_TABLE.'
209                        SET value="'.addslashes($conf['UserAdvManager_ConfirmMail']).'"
210                        WHERE param="UserAdvManager_ConfirmMail"
211                        LIMIT 1
212                ;';
213
214                pwg_query($query);
215
216                array_push($page['infos'], l10n('UAM_save_config'));
217  }
218
219
220  //Testing password enforcement
221  if (isset($_POST['PasswordTest']) and isset($_POST['UAM_Password_Test']) and !empty($_POST['UAM_Password_Test']))
222  {
223    $UAM_Password_Test_Score = testpassword($_POST['UAM_Password_Test']);
224  }
225  else if (isset($_POST['PasswordTest']) and empty($_POST['UAM_Password_Test']))
226  {
227    array_push($page['errors'], l10n('reg_err_login3'));
228  }
229
230  $conf_UAM = unserialize($conf['UserAdvManager']);
231
232  //Group setting for unvalidated, validated users and downgrade group
233  $groups[-1] = '---------';
234  $No_Valid = -1;
235  $Valid = -1;
236  $Downgrade = -1;
237       
238  //Check groups list in database
239  $query = '
240SELECT id, name
241FROM '.GROUPS_TABLE.'
242ORDER BY name ASC
243;';
244       
245  $result = pwg_query($query);
246       
247  while ($row = pwg_db_fetch_assoc($result))
248  {
249    $groups[$row['id']] = $row['name'];
250    //configuration value for unvalidated users
251    if (isset($conf_UAM[2]) and $conf_UAM[2] == $row['id'])
252    {
253                $No_Valid = $row['id'];
254                }
255    //configuration value for validated users
256    if (isset($conf_UAM[3]) and $conf_UAM[3] == $row['id'])
257                {
258                $Valid = $row['id'];
259                }
260    //configuration value for downgrade users
261    if (isset($conf_UAM[26]) and $conf_UAM[26] == $row['id'])
262                {
263                $Downgrade = $row['id'];
264                }
265  }
266       
267  //Template initialization for unvalidated users group
268  $template->assign(
269    'No_Confirm_Group',
270        array(
271                'group_options'=> $groups,
272                'group_selected' => $No_Valid
273                        )
274                );
275  //Template initialization for validated users group
276  $template->assign(
277    'Validated_Group',
278                array(
279      'group_options'=> $groups,
280      'group_selected' => $Valid
281                        )
282        );
283  //Template initialization for downgrade group
284  $template->assign(
285    'Downgrade_Group',
286                array(
287      'group_options'=> $groups,
288      'group_selected' => $Downgrade
289                        )
290        );
291       
292  //Status setting for unvalidated, validated users and downgrade status
293  $status_options[-1] = '------------';
294  $No_Valid_Status = -1;
295  $Valid_Status = -1;
296  $Downgrade_Status = -1;
297       
298  //Get unvalidate status values
299  foreach (get_enums(USER_INFOS_TABLE, 'status') as $status)
300  {
301          $status_options[$status] = l10n('user_status_'.$status);
302          if (isset($conf_UAM[8]) and $conf_UAM[8] == $status)
303          {
304            $No_Valid_Status = $status;
305          }
306         
307      //Template initialization for unvalidated users status
308      $template->assign(
309        'No_Confirm_Status',
310        array(
311                                        'Status_options' => $status_options,
312                                'Status_selected' => $No_Valid_Status
313                                        )
314                        );
315  }
316 
317  //Get validate status values
318  foreach (get_enums(USER_INFOS_TABLE, 'status') as $status)
319  {
320          $status_options[$status] = l10n('user_status_'.$status);
321          if (isset($conf_UAM[4]) and $conf_UAM[4] == $status)
322                {
323                  $Valid_Status = $status;
324                }
325               
326      //Template initialization for validated users status
327      $template->assign(
328            'Confirm_Status',
329            array(
330                    'Status_options' => $status_options,
331                    'Status_selected' => $Valid_Status
332                    )
333            );
334        }
335
336  //Get downgrade status values
337  foreach (get_enums(USER_INFOS_TABLE, 'status') as $status)
338  {
339          $status_options[$status] = l10n('user_status_'.$status);
340          if (isset($conf_UAM[27]) and $conf_UAM[27] == $status)
341                {
342                  $Downgrade_Status = $status;
343                }
344               
345      //Template initialization for validated users status
346      $template->assign(
347            'Downgrade_Status',
348            array(
349                    'Status_options' => $status_options,
350                    'Status_selected' => $Downgrade_Status
351                    )
352            );
353        }
354
355  //Save last opened paragraph in configuration tab
356  $nb_para=(isset($_POST["nb_para"])) ? $_POST["nb_para"]:"";
357  $nb_para2=(isset($_POST["nb_para2"])) ? $_POST["nb_para2"]:"";
358
359  $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']);
360
361  // Template initialization for forms and data
362  $template->assign(
363    array(
364    'nb_para'                        => $nb_para,
365    'nb_para2'                       => $nb_para2,
366    'UAM_VERSION'                    => $version,
367    'UAM_PATH'                       => UAM_PATH,
368                'UAM_MAIL_INFO_TRUE'             => $conf_UAM[0]=='true' ?  'checked="checked"' : '' ,
369                'UAM_MAIL_INFO_FALSE'            => $conf_UAM[0]=='false' ?  'checked="checked"' : '' ,
370                'UAM_MAILINFO_TEXT'              => $conf_UAM[9],
371                'UAM_USERNAME_CHAR_TRUE'         => $conf_UAM[6]=='true' ?  'checked="checked"' : '' ,
372                'UAM_USERNAME_CHAR_FALSE'        => $conf_UAM[6]=='false' ?  'checked="checked"' : '' ,
373                'UAM_USERNAME_CHAR_LIST'         => $conf_UAM[7],
374                'UAM_CONFIRM_MAIL_TRUE'          => $conf_UAM[1]=='true' ?  'checked="checked"' : '' ,
375                'UAM_CONFIRM_MAIL_FALSE'         => $conf_UAM[1]=='false' ?  'checked="checked"' : '' ,
376    'UAM_CONFIRM_MAIL_LOCAL'         => $conf_UAM[1]=='local' ?  'checked="checked"' : '' ,
377                'UAM_CONFIRMMAIL_TEXT'           => $conf_UAM[10],
378                'UAM_No_Confirm_Group'           => $conf_UAM[2],
379                'UAM_Validated_Group'            => $conf_UAM[3],
380                'UAM_No_Confirm_Status'          => $conf_UAM[8],
381                'UAM_Validated_Status'           => $conf_UAM[4],
382                'UAM_NO_COMMENT_ANO_TRUE'        => $conf_UAM[5]=='true' ?  'checked="checked"' : '' ,
383                'UAM_NO_COMMENT_ANO_FALSE'       => $conf_UAM[5]=='false' ?  'checked="checked"' : '' ,
384                'UAM_MAILEXCLUSION_TRUE'         => $conf_UAM[11]=='true' ?  'checked="checked"' : '' ,
385                'UAM_MAILEXCLUSION_FALSE'        => $conf_UAM[11]=='false' ?  'checked="checked"' : '' ,
386                'UAM_MAILEXCLUSION_LIST'         => $conf_UAM[12],
387                'UAM_PASSWORDENF_TRUE'           => $conf_UAM[13]=='true' ?  'checked="checked"' : '' ,
388                'UAM_PASSWORDENF_FALSE'          => $conf_UAM[13]=='false' ?  'checked="checked"' : '' ,
389                'UAM_PASSWORD_SCORE'             => $conf_UAM[14],
390    'UAM_ADMINPASSWENF_TRUE'         => $conf_UAM[15]=='true' ?  'checked="checked"' : '' ,
391                'UAM_ADMINPASSWENF_FALSE'        => $conf_UAM[15]=='false' ?  'checked="checked"' : '' ,
392    'UAM_GHOSTRACKER_TRUE'           => $conf_UAM[16]=='true' ?  'checked="checked"' : '' ,
393                'UAM_GHOSTRACKER_FALSE'          => $conf_UAM[16]=='false' ?  'checked="checked"' : '' ,
394    'UAM_GHOSTRACKER_DAYLIMIT'       => $conf_UAM[17],
395    'UAM_GHOSTRACKER_REMINDERTEXT'   => $conf_UAM[18],
396    'UAM_ADDLASTVISIT_TRUE'          => $conf_UAM[19]=='true' ?  'checked="checked"' : '' ,
397    'UAM_ADDLASTVISIT_FALSE'         => $conf_UAM[19]=='false' ?  'checked="checked"' : '' ,
398    'UAM_ADMINCONFMAIL_TRUE'         => $conf_UAM[20]=='true' ?  'checked="checked"' : '' ,
399    'UAM_ADMINCONFMAIL_FALSE'        => $conf_UAM[20]=='false' ?  'checked="checked"' : '' ,
400    'UAM_REDIRTOPROFILE_TRUE'        => $conf_UAM[21]=='true' ?  'checked="checked"' : '' ,
401    'UAM_REDIRTOPROFILE_FALSE'       => $conf_UAM[21]=='false' ?  'checked="checked"' : '' ,
402    'UAM_GTAUTO_TRUE'                => $conf_UAM[22]=='true' ?  'checked="checked"' : '' ,
403    'UAM_GTAUTO_FALSE'               => $conf_UAM[22]=='false' ?  'checked="checked"' : '' ,
404    'UAM_GTAUTOMAIL_TRUE'            => $conf_UAM[23]=='true' ?  'checked="checked"' : '' ,
405    'UAM_GTAUTOMAIL_FALSE'           => $conf_UAM[23]=='false' ?  'checked="checked"' : '' ,
406    'UAM_GTAUTODEL_TEXT'             => $conf_UAM[24],
407    'UAM_GTAUTOMAILTEXT'             => $conf_UAM[25],
408                'UAM_Downgrade_Group'            => $conf_UAM[26],
409                'UAM_Downgrade_Status'           => $conf_UAM[27],
410    'UAM_ADMINVALIDATIONMAIL_TEXT'   => $conf_UAM[28],
411    'UAM_CUSTOMPASSWRETR_TRUE'       => $conf_UAM[29]=='true' ?  'checked="checked"' : '' ,
412    'UAM_CUSTOMPASSWRETR_FALSE'      => $conf_UAM[29]=='false' ?  'checked="checked"' : '' ,
413    'UAM_CUSTOMPASSWRETR_TEXT'       => $conf_UAM[30],
414                'UAM_PASSWORD_TEST_SCORE'        => $UAM_Password_Test_Score,
415    'UAM_ERROR_REPORTS4'             => $UAM_Exclusionlist_Error,
416                'UAM_CONFIRMMAIL_TIMEOUT_TRUE'   => $conf_UAM_ConfirmMail[0]=='true' ?  'checked="checked"' : '' ,
417                'UAM_CONFIRMMAIL_TIMEOUT_FALSE'  => $conf_UAM_ConfirmMail[0]=='false' ?  'checked="checked"' : '' ,
418                'UAM_CONFIRMMAIL_DELAY'                                  => $conf_UAM_ConfirmMail[1],
419    'UAM_CONFIRMMAIL_REMAIL_TRUE'                => $conf_UAM_ConfirmMail[3]=='true' ? 'checked="checked"' : '',
420    'UAM_CONFIRMMAIL_REMAIL_FALSE'       => $conf_UAM_ConfirmMail[3]=='false' ? 'checked="checked"' : '',
421    'UAM_CONFIRMMAIL_REMAIL_TXT1'                => $conf_UAM_ConfirmMail[2],
422    'UAM_CONFIRMMAIL_REMAIL_TXT2'                => $conf_UAM_ConfirmMail[4],
423    'UAM_CONFIRMMAIL_CUSTOM_TXT1'                => $conf_UAM_ConfirmMail[5],
424    'UAM_CONFIRMMAIL_CUSTOM_TXT2'                => $conf_UAM_ConfirmMail[6],
425    )
426  );
427
428  if (isset($_POST['audit']))
429        {
430                $msg_error1 = '';
431               
432    //Username without forbidden keys
433    if ( isset($conf_UAM[6]) and $conf_UAM[6] == 'true' )
434          {
435                        $query = "
436SELECT ".$conf['user_fields']['username'].", ".$conf['user_fields']['email']."
437  FROM ".USERS_TABLE."
438;";
439                         
440                        $result = pwg_query($query);
441                       
442                        while($row = pwg_db_fetch_assoc($result))
443                        {
444                                if (!ValidateUsername(stripslashes($row['username'])))
445                                        $msg_error1 .= (($msg_error1 <> '') ? '<br>' : '') . l10n('Err_audit_username_char').stripslashes($row['username']);
446                        }
447                }
448
449                $msg_error2 = '';
450               
451    //Email without forbidden domain
452    if ( isset($conf_UAM[11]) and $conf_UAM[11] == 'true' )
453          {
454                        $query = "
455SELECT ".$conf['user_fields']['username'].", ".$conf['user_fields']['email']."
456  FROM ".USERS_TABLE."
457;";
458                         
459                  $result = pwg_query($query);
460                       
461                  while($row = pwg_db_fetch_assoc($result))
462                  {
463                          $conf_MailExclusion = preg_split("/[\s,]+/",$conf_UAM[12]);
464                          for ($i = 0 ; $i < count($conf_MailExclusion) ; $i++)
465                          {
466                                        $pattern = '/'.$conf_MailExclusion[$i].'/';
467                                  if (preg_match($pattern, $row['mail_address']))
468                                  {
469                                                $msg_error2 .=  (($msg_error2 <> '') ? '<br>' : '') . l10n('Err_audit_email_forbidden').stripslashes($row['username']).' ('.$row['mail_address'].')';
470                                        }
471                                }
472                        }
473                }
474               
475    if ($msg_error1 <> '')
476                        $errors[] = $msg_error1.'<br><br>';
477               
478                if ($msg_error2 <> '')
479                        $errors[] = $msg_error2.'<br><br>';
480               
481                if ($msg_error1 <> '' or $msg_error2 <> '')
482                array_push($page['errors'], l10n('Err_audit_advise'));
483                else
484        array_push($page['infos'], l10n('UAM_audit_ok'));
485        }
486
487
488// +-----------------------------------------------------------------------+
489// |                             errors display                            |
490// +-----------------------------------------------------------------------+
491  if (isset ($errors) and count($errors) != 0)
492  {
493          $template->assign('errors',array());
494          foreach ($errors as $error)
495          {
496                  array_push($page['errors'], $error);
497                }
498        } 
499
500// +-----------------------------------------------------------------------+
501// |                           templates display                           |
502// +-----------------------------------------------------------------------+
503  $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/global.tpl');
504  $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
505
506  break;
507
508
509// *************************************************************************
510// +-----------------------------------------------------------------------+
511// |                           Users list page                             |
512// +-----------------------------------------------------------------------+
513// *************************************************************************
514  case 'userlist':
515 
516  $conf_UAM = unserialize($conf['UserAdvManager']);
517 
518  if (isset($conf_UAM[19]) and $conf_UAM[19]=='true')
519  {
520// +-----------------------------------------------------------------------+
521// |                           initialization                              |
522// +-----------------------------------------------------------------------+
523
524                if (!defined('PHPWG_ROOT_PATH'))
525    {
526        die('Hacking attempt!');
527    }
528         
529    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
530
531// +-----------------------------------------------------------------------+
532// | Check Access and exit when user status is not ok                      |
533// +-----------------------------------------------------------------------+
534                check_status(ACCESS_ADMINISTRATOR);
535
536
537// +-----------------------------------------------------------------------+
538// |                               user list                               |
539// +-----------------------------------------------------------------------+
540
541                $page['filtered_users'] = get_user_list();
542
543// +-----------------------------------------------------------------------+
544// |                               user list                               |
545// +-----------------------------------------------------------------------+
546
547    $visible_user_list = array();
548    foreach ($page['filtered_users'] as $num => $local_user)
549    {
550      $visible_user_list[] = $local_user;
551                }
552
553                foreach ($visible_user_list as $local_user)
554    {
555      // dates formating and compare
556      $today = date("d-m-Y"); // Get today's date
557      list($day, $month, $year) = explode('-', $today); // explode date of today                                                 
558      $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp
559               
560      list($regdate, $regtime) = explode(' ', $local_user['lastvisit']); // Explode date and time from registration date
561      list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date
562      $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp
563                       
564      $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps       
565      $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days
566     
567      if (isset($conf_UAM[16]) and $conf_UAM[16]=='true' and $conf_UAM[17] <> '')
568      {
569        if ($deltadays <= ($conf_UAM[17]/2))
570        {
571          $display = 'green';
572        }
573       
574        if (($deltadays > ($conf_UAM[17]/2)) and ($deltadays < $conf_UAM[17]))
575        {
576          $display = 'orange';
577        }
578       
579        if ($deltadays >= $conf_UAM[17])
580        {
581          $display = 'red';
582        }
583      }
584      else $display = '';
585
586                $template->append(
587                'users',
588        array(
589                'ID'          => $local_user['id'],
590                'USERNAME'    => stripslashes($local_user['username']),
591                                        'EMAIL'       => get_email_address_as_display_text($local_user['email']),
592          'LASTVISIT'   => $local_user['lastvisit'],
593          'DAYS'        => $deltadays,
594          'DISPLAY'     => $display,
595                                )
596                        );
597                }
598    //Plugin version inserted
599    $template->assign(
600      array(
601        'UAM_VERSION'  => $version,
602        'UAM_PATH'     => UAM_PATH,
603      )
604    );   
605// +-----------------------------------------------------------------------+
606// |                             errors display                            |
607// +-----------------------------------------------------------------------+
608                if ( isset ($errors) and count($errors) != 0)
609                {
610                $template->assign('errors',array());
611                        foreach ($errors as $error)
612                {
613                                array_push($page['errors'], $error);
614                }
615                } 
616
617// +-----------------------------------------------------------------------+
618// |                           templates display                           |
619// +-----------------------------------------------------------------------+
620                $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/userlist.tpl');
621    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');         
622  }
623  else
624  {
625                array_push($page['errors'], l10n('Err_Userlist_Settings'));
626  }
627  break;
628
629
630// *************************************************************************
631// +-----------------------------------------------------------------------+
632// |                           Users manager page                          |
633// +-----------------------------------------------------------------------+
634// *************************************************************************
635  case 'usermanager':
636
637  $conf_UAM = unserialize($conf['UserAdvManager']);
638
639  $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']);
640       
641  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')))
642  {
643// +-----------------------------------------------------------------------+
644// |                           initialization                              |
645// +-----------------------------------------------------------------------+
646
647                if (!defined('PHPWG_ROOT_PATH'))
648    {
649        die('Hacking attempt!');
650    }
651
652    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
653
654// +-----------------------------------------------------------------------+
655// | Check Access and exit when user status is not ok                      |
656// +-----------------------------------------------------------------------+
657                check_status(ACCESS_ADMINISTRATOR);
658
659// +-----------------------------------------------------------------------+
660// |                               user list                               |
661// +-----------------------------------------------------------------------+
662
663                $page['filtered_users'] = get_unvalid_user_list();
664
665// +-----------------------------------------------------------------------+
666// |                            selected users                             |
667// +-----------------------------------------------------------------------+
668                if (isset($_POST['Del_Selected']))
669                {
670                $collection = array();
671
672                        switch ($_POST['target'])
673        {
674                case 'all' :
675        {
676                foreach($page['filtered_users'] as $local_user)
677                {
678                        array_push($collection, $local_user['id']);
679                }
680                                        break;
681                                }
682        case 'selection' :
683        {
684                if (isset($_POST['selection']))
685                {
686                        $collection = $_POST['selection'];
687                }
688                break;
689        }
690                        }
691
692                        if (count($collection) == 0)
693        {
694                array_push($page['errors'], l10n('Select at least one user'));
695                }
696                }
697
698// +-----------------------------------------------------------------------+
699// |                             delete users                              |
700// +-----------------------------------------------------------------------+
701                if (isset($_POST['Del_Selected']) and count($collection) > 0)
702        {
703                if (in_array($conf['guest_id'], $collection))
704                {
705                array_push($page['errors'], l10n('Guest cannot be deleted'));
706        }
707        if (($conf['guest_id'] != $conf['default_user_id']) and
708                in_array($conf['default_user_id'], $collection))
709        {
710                array_push($page['errors'], l10n('Default user cannot be deleted'));
711        }
712        if (in_array($conf['webmaster_id'], $collection))
713        {
714                array_push($page['errors'], l10n('Webmaster cannot be deleted'));
715        }
716        if (in_array($user['id'], $collection))
717        {
718                array_push($page['errors'], l10n('You cannot delete your account'));
719        }
720
721                        if (count($page['errors']) == 0)
722        {
723                foreach ($collection as $user_id)
724        {
725                delete_user($user_id);
726        }
727                array_push(
728                $page['infos'],
729                l10n_dec(
730                '%d user deleted', '%d users deleted',
731                count($collection)
732                )
733        );
734
735        foreach ($page['filtered_users'] as $filter_key => $filter_user)
736        {
737                if (in_array($filter_user['id'], $collection))
738                {
739                        unset($page['filtered_users'][$filter_key]);
740                }
741                }
742                        }
743                }
744
745// +-----------------------------------------------------------------------+
746// |                 Resend new validation key to users                    |
747// +-----------------------------------------------------------------------+
748// +-----------------------------------------------------------------------+
749// |                            selected users                             |
750// +-----------------------------------------------------------------------+
751                if (isset($_POST['Mail_With_Key']))
752                {
753                $collection = array();
754
755                        switch ($_POST['target'])
756        {
757                case 'all' :
758        {
759                foreach($page['filtered_users'] as $local_user)
760                {
761                        array_push($collection, $local_user['id']);
762                }
763                break;
764                                }
765        case 'selection' :
766        {
767                if (isset($_POST['selection']))
768                {
769                        $collection = $_POST['selection'];
770                }
771                break;
772        }
773                        }
774
775        if (count($collection) == 0)
776        {
777                array_push($page['errors'], l10n('Select at least one user'));
778        }
779                }
780// +-----------------------------------------------------------------------+
781// |                 Resend new validation key to users                    |
782// +-----------------------------------------------------------------------+
783                if (isset($_POST['Mail_With_Key']) and count($collection) > 0)
784                {
785                        if (in_array($conf['guest_id'], $collection))
786                {
787                array_push($page['errors'], l10n('No_validation_for_Guest'));
788        }
789        if (($conf['guest_id'] != $conf['default_user_id']) and
790                in_array($conf['default_user_id'], $collection))
791        {
792                array_push($page['errors'], l10n('No_validation_for_default_user'));
793        }
794                if (in_array($conf['webmaster_id'], $collection))
795        {
796                array_push($page['errors'], l10n('No_validation_for_Webmaster'));
797        }
798        if (in_array($user['id'], $collection))
799        {
800                array_push($page['errors'], l10n('No_validation_for_your_account'));
801        }
802
803        if (count($page['errors']) == 0)
804        {
805                foreach ($collection as $user_id)
806        {       
807                $typemail = 1;
808                                  $query = "
809SELECT id, username, mail_address
810  FROM ".USERS_TABLE."
811WHERE id = '".$user_id."'
812;";
813                                        $data = pwg_db_fetch_assoc(pwg_query($query));
814                               
815                ResendMail2User($typemail,$user_id,stripslashes($data['username']),$data['mail_address'],true);
816        }
817        array_push(
818                $page['infos'],
819                l10n_dec(
820                        '%d_Mail_With_Key', '%d_Mails_With_Key',
821                count($collection)
822                )
823        );
824       
825                                $page['filtered_users'] = get_unvalid_user_list();
826                        }
827                }
828
829// +-----------------------------------------------------------------------+
830// |             Send reminder without new key to users                    |
831// +-----------------------------------------------------------------------+
832// +-----------------------------------------------------------------------+
833// |                            selected users                             |
834// +-----------------------------------------------------------------------+
835                if (isset($_POST['Mail_Without_Key']))
836                {
837                $collection = array();
838
839                        switch ($_POST['target'])
840        {
841                case 'all' :
842        {
843                foreach($page['filtered_users'] as $local_user)
844                {
845                        array_push($collection, $local_user['id']);
846                }
847                break;
848                                }
849        case 'selection' :
850        {
851                if (isset($_POST['selection']))
852                {
853                        $collection = $_POST['selection'];
854                }
855                break;
856        }
857                        }
858
859        if (count($collection) == 0)
860        {
861                array_push($page['errors'], l10n('Select at least one user'));
862        }
863                }
864// +-----------------------------------------------------------------------+
865// |             Send reminder without new key to users                    |
866// +-----------------------------------------------------------------------+
867                if (isset($_POST['Mail_Without_Key']) and count($collection) > 0)
868                {
869                        if (in_array($conf['guest_id'], $collection))
870                {
871                array_push($page['errors'], l10n('No_validation_for_Guest'));
872        }
873        if (($conf['guest_id'] != $conf['default_user_id']) and
874                in_array($conf['default_user_id'], $collection))
875        {
876                array_push($page['errors'], l10n('No_validation_for_default_user'));
877        }
878                if (in_array($conf['webmaster_id'], $collection))
879        {
880                array_push($page['errors'], l10n('No_validation_for_Webmaster'));
881        }
882        if (in_array($user['id'], $collection))
883        {
884                array_push($page['errors'], l10n('No_validation_for_your_account'));
885        }
886
887        if (count($page['errors']) == 0)
888        {
889                foreach ($collection as $user_id)
890        {
891                $typemail = 2;
892                                  $query = "
893SELECT id, username, mail_address
894  FROM ".USERS_TABLE."
895WHERE id = '".$user_id."'
896;";
897                                       
898                                        $data = pwg_db_fetch_assoc(pwg_query($query));
899                               
900                ResendMail2User($typemail,$user_id,stripslashes($data['username']),$data['mail_address'],false);                               
901        }
902        array_push(
903                $page['infos'],
904                l10n_dec(
905                        '%d_Reminder_Sent', '%d_Reminders_Sent',
906                count($collection)
907                )
908        );
909       
910                                $page['filtered_users'] = get_unvalid_user_list();
911                        }
912                }
913
914// +-----------------------------------------------------------------------+
915// |                                                                            Force validation                                                         |
916// +-----------------------------------------------------------------------+
917// +-----------------------------------------------------------------------+
918// |                            selected users                             |
919// +-----------------------------------------------------------------------+
920                if (isset($_POST['Force_Validation']))
921                {
922                $collection = array();
923
924                        switch ($_POST['target'])
925        {
926                case 'all' :
927        {
928                foreach($page['filtered_users'] as $local_user)
929                {
930                        array_push($collection, $local_user['id']);
931                }
932                break;
933                                }
934        case 'selection' :
935        {
936                if (isset($_POST['selection']))
937                {
938                        $collection = $_POST['selection'];
939                }
940                break;
941        }
942                        }
943
944        if (count($collection) == 0)
945        {
946                array_push($page['errors'], l10n('Select at least one user'));
947        }
948                }
949// +-----------------------------------------------------------------------+
950// |                                                                            Force validation                                                         |
951// +-----------------------------------------------------------------------+
952                if (isset($_POST['Force_Validation']) and count($collection) > 0)
953                {
954                        if (in_array($conf['guest_id'], $collection))
955                {
956                array_push($page['errors'], l10n('No_validation_for_Guest'));
957        }
958        if (($conf['guest_id'] != $conf['default_user_id']) and
959                in_array($conf['default_user_id'], $collection))
960        {
961                array_push($page['errors'], l10n('No_validation_for_default_user'));
962        }
963                if (in_array($conf['webmaster_id'], $collection))
964        {
965                array_push($page['errors'], l10n('No_validation_for_Webmaster'));
966        }
967        if (in_array($user['id'], $collection))
968        {
969                array_push($page['errors'], l10n('No_validation_for_your_account'));
970        }
971
972        if (count($page['errors']) == 0)
973        {
974                foreach ($collection as $user_id)
975        {
976          ForceValidation($user_id);
977          validation_mail($user_id);
978        }
979        array_push(
980                $page['infos'],
981                l10n_dec(
982                        '%d_Validated_User', '%d_Validated_Users',
983                count($collection)
984                )
985        );
986
987                                $page['filtered_users'] = get_unvalid_user_list();
988                        }
989                }
990               
991
992// +-----------------------------------------------------------------------+
993// |                              groups list                              |
994// +-----------------------------------------------------------------------+
995
996                $groups[-1] = '------------';
997
998    $query = '
999SELECT id, name
1000  FROM '.GROUPS_TABLE.'
1001ORDER BY name ASC
1002;';
1003
1004                $result = pwg_query($query);
1005         
1006    while ($row = pwg_db_fetch_assoc($result))
1007    {
1008      $groups[$row['id']] = $row['name'];
1009    }
1010
1011// +-----------------------------------------------------------------------+
1012// |                               user list                               |
1013// +-----------------------------------------------------------------------+
1014
1015                $profile_url = get_root_url().'admin.php?page=profile&amp;user_id=';
1016                $perm_url = get_root_url().'admin.php?page=user_perm&amp;user_id=';
1017
1018    $visible_user_list = array();
1019    foreach ($page['filtered_users'] as $num => $local_user)
1020    {
1021      $visible_user_list[] = $local_user;
1022                }
1023
1024                foreach ($visible_user_list as $local_user)
1025    {
1026      $groups_string = preg_replace(
1027        '/(\d+)/e',
1028        "\$groups['$1']",
1029        implode(
1030                ', ',
1031            $local_user['groups']
1032         )
1033                        );
1034
1035      $query = '
1036SELECT user_id, reminder
1037FROM '.USER_CONFIRM_MAIL_TABLE.'
1038WHERE user_id = '.$local_user['id'].'
1039;';
1040      $result = pwg_query($query);
1041     
1042      $row = pwg_db_fetch_assoc($result);
1043   
1044      if (isset($row['reminder']) and $row['reminder'] == 'true')
1045      {
1046        $reminder = l10n('Reminder_Sent_OK');
1047      }
1048      else if ((isset($row['reminder']) and $row['reminder'] == 'false') or !isset($row['reminder']))
1049      {
1050        $reminder = l10n('Reminder_Sent_NOK');
1051      }
1052
1053
1054                if (isset($_POST['pref_submit'])
1055                and isset($_POST['selection'])
1056        and in_array($local_user['id'], $_POST['selection']))
1057                {
1058                                $checked = 'checked="checked"';
1059                }
1060                        else
1061        {
1062                $checked = '';
1063        }
1064
1065        $properties = array();
1066        if ( $local_user['level'] != 0 )
1067                        {
1068                $properties[] = l10n( sprintf('Level %d', $local_user['level']) );
1069                        }
1070        $properties[] =
1071                (isset($local_user['enabled_high']) and ($local_user['enabled_high'] == 'true'))
1072                ? l10n('is_high_enabled') : l10n('is_high_disabled');
1073
1074                        $expiration = expiration($local_user['id']);
1075     
1076                $template->append(
1077                'users',
1078        array(
1079                'ID'               => $local_user['id'],
1080                'CHECKED'          => $checked,
1081                'U_PROFILE'        => $profile_url.$local_user['id'],
1082                'U_PERM'           => $perm_url.$local_user['id'],
1083                'USERNAME'         => stripslashes($local_user['username'])
1084                                  .($local_user['id'] == $conf['guest_id']
1085                                  ? '<BR>['.l10n('is_the_guest').']' : '')
1086                                  .($local_user['id'] == $conf['default_user_id']
1087                                  ? '<BR>['.l10n('is_the_default').']' : ''),
1088                                  'STATUS' => l10n('user_status_'
1089                                  .$local_user['status']),
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())
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// +-----------------------------------------------------------------------+
1415// |                               user list                               |
1416// +-----------------------------------------------------------------------+
1417
1418    $visible_user_list = array();
1419    foreach ($page['filtered_users'] as $num => $local_user)
1420    {
1421      $visible_user_list[] = $local_user;
1422                }
1423
1424      //Plugin version inserted
1425      $template->assign(
1426        array(
1427          'UAM_VERSION'  => $version,
1428          'UAM_PATH'     => UAM_PATH,
1429        )
1430      );
1431
1432                foreach ($visible_user_list as $local_user)
1433    {
1434      $reminder = '';
1435   
1436      if (isset($local_user['reminder']) and $local_user['reminder'] == 'true')
1437      {
1438        $reminder = l10n('Reminder_Sent_OK');
1439      }
1440      else if (isset($local_user['reminder']) and $local_user['reminder'] == 'false')
1441      {
1442        $reminder = l10n('Reminder_Sent_NOK');
1443      }
1444   
1445      if (isset($_POST['pref_submit']) and isset($_POST['selection']) and in_array($local_user['id'], $_POST['selection']))
1446                {
1447                                $checked = 'checked="checked"';
1448                }
1449                        else
1450        {
1451                $checked = '';
1452        }
1453
1454      $template->append(
1455          'users',
1456        array(
1457                'ID'          => $local_user['id'],
1458                'CHECKED'     => $checked,
1459                'USERNAME'    => stripslashes($local_user['username']),
1460                                        'EMAIL'       => get_email_address_as_display_text($local_user['email']),
1461          'LASTVISIT'   => $local_user['lastvisit'],
1462          'REMINDER'    => $reminder,
1463                                )
1464                        );
1465                }
1466
1467// +-----------------------------------------------------------------------+
1468// |                             errors display                            |
1469// +-----------------------------------------------------------------------+
1470                if ( isset ($errors) and count($errors) != 0)
1471                {
1472                $template->assign('errors',array());
1473                        foreach ($errors as $error)
1474                {
1475                                array_push($page['errors'], $error);
1476                }
1477                } 
1478
1479// +-----------------------------------------------------------------------+
1480// |                           templates display                           |
1481// +-----------------------------------------------------------------------+
1482                $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/ghosttracker.tpl');
1483    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');         
1484        }
1485  else
1486  {
1487                array_push($page['errors'], l10n('Err_GhostTracker_Settings'));
1488  }
1489
1490  break;
1491}
1492?>
Note: See TracBrowser for help on using the repository browser.