source: extensions/UserAdvManager/branches/2.20/admin/UAM_admin.php @ 9909

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

r9908 merged from trunk to branch 2.20

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