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

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

r9324 merged from trunk to branch 2.20

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