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

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

bug 2055 fixed : New automated task for unvalidated registers (auto email reminder sent and auto deletion if already reminded).
Localisation files cleanup : all keys for "enable" and "disable" options have been replaced by one unic key.

  • Property svn:eol-style set to LF
File size: 51.7 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    // Avoid jquery accordion menu bug when there is no users to display
564    // Pending because it causes php warnings when no users are listed (when $visible_user_list[] is empty)
565    /*if (empty($visible_user_list))
566    {
567      $visible_user_list[] = null;
568    }*/
569
570                foreach ($visible_user_list as $local_user)
571    {
572      // dates formating and compare
573      $today = date("d-m-Y"); // Get today's date
574      list($day, $month, $year) = explode('-', $today); // explode date of today                                                 
575      $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp
576               
577      list($regdate, $regtime) = explode(' ', $local_user['lastvisit']); // Explode date and time from registration date
578      list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date
579      $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp
580                       
581      $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps       
582      $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days
583     
584      if (isset($conf_UAM[16]) and $conf_UAM[16]=='true' and $conf_UAM[17] <> '')
585      {
586        if ($deltadays <= ($conf_UAM[17]/2))
587        {
588          $display = 'green';
589        }
590       
591        if (($deltadays > ($conf_UAM[17]/2)) and ($deltadays < $conf_UAM[17]))
592        {
593          $display = 'orange';
594        }
595       
596        if ($deltadays >= $conf_UAM[17])
597        {
598          $display = 'red';
599        }
600      }
601      else $display = '';
602
603                $template->append(
604                'users',
605        array(
606                'ID'          => $local_user['id'],
607                'USERNAME'    => stripslashes($local_user['username']),
608                                        'EMAIL'       => get_email_address_as_display_text($local_user['email']),
609          'LASTVISIT'   => $local_user['lastvisit'],
610          'DAYS'        => $deltadays,
611          'DISPLAY'     => $display,
612                                )
613                        );
614                }
615    //Plugin version inserted
616    $template->assign(
617      array(
618        'UAM_VERSION'  => $version,
619        'UAM_PATH'     => UAM_PATH,
620      )
621    );   
622// +-----------------------------------------------------------------------+
623// |                             errors display                            |
624// +-----------------------------------------------------------------------+
625                if ( isset ($errors) and count($errors) != 0)
626                {
627                $template->assign('errors',array());
628                        foreach ($errors as $error)
629                {
630                                array_push($page['errors'], $error);
631                }
632                } 
633
634// +-----------------------------------------------------------------------+
635// |                           templates display                           |
636// +-----------------------------------------------------------------------+
637                $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/userlist.tpl');
638    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');         
639  }
640  else
641  {
642                array_push($page['errors'], l10n('UAM_Err_Userlist_Settings'));
643  }
644  break;
645
646
647// *************************************************************************
648// +-----------------------------------------------------------------------+
649// |                           Users manager page                          |
650// +-----------------------------------------------------------------------+
651// *************************************************************************
652  case 'usermanager':
653
654  $conf_UAM = unserialize($conf['UserAdvManager']);
655
656  $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']);
657       
658  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')))
659  {
660// +-----------------------------------------------------------------------+
661// |                           initialization                              |
662// +-----------------------------------------------------------------------+
663
664                if (!defined('PHPWG_ROOT_PATH'))
665    {
666        die('Hacking attempt!');
667    }
668
669    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
670
671// +-----------------------------------------------------------------------+
672// | Check Access and exit when user status is not ok                      |
673// +-----------------------------------------------------------------------+
674                check_status(ACCESS_ADMINISTRATOR);
675
676// +-----------------------------------------------------------------------+
677// |                               user list                               |
678// +-----------------------------------------------------------------------+
679
680                $page['filtered_users'] = get_unvalid_user_list();
681
682// +-----------------------------------------------------------------------+
683// |                            selected users                             |
684// +-----------------------------------------------------------------------+
685                if (isset($_POST['Del_Selected']))
686                {
687                $collection = array();
688
689                        switch ($_POST['target'])
690        {
691                case 'all' :
692        {
693                foreach($page['filtered_users'] as $local_user)
694                {
695                        array_push($collection, $local_user['id']);
696                }
697                                        break;
698                                }
699        case 'selection' :
700        {
701                if (isset($_POST['selection']))
702                {
703                        $collection = $_POST['selection'];
704                }
705                break;
706        }
707                        }
708
709                        if (count($collection) == 0)
710        {
711                array_push($page['errors'], l10n('Select at least one user'));
712                }
713                }
714
715// +-----------------------------------------------------------------------+
716// |                             delete users                              |
717// +-----------------------------------------------------------------------+
718                if (isset($_POST['Del_Selected']) and count($collection) > 0)
719        {
720                if (in_array($conf['guest_id'], $collection))
721                {
722                array_push($page['errors'], l10n('Guest cannot be deleted'));
723        }
724        if (($conf['guest_id'] != $conf['default_user_id']) and
725                in_array($conf['default_user_id'], $collection))
726        {
727                array_push($page['errors'], l10n('Default user cannot be deleted'));
728        }
729        if (in_array($conf['webmaster_id'], $collection))
730        {
731                array_push($page['errors'], l10n('Webmaster cannot be deleted'));
732        }
733        if (in_array($user['id'], $collection))
734        {
735                array_push($page['errors'], l10n('You cannot delete your account'));
736        }
737
738                        if (count($page['errors']) == 0)
739        {
740                foreach ($collection as $user_id)
741        {
742                delete_user($user_id);
743        }
744                array_push(
745                $page['infos'],
746                l10n_dec(
747                '%d user deleted', '%d users deleted',
748                count($collection)
749                )
750        );
751
752        foreach ($page['filtered_users'] as $filter_key => $filter_user)
753        {
754                if (in_array($filter_user['id'], $collection))
755                {
756                        unset($page['filtered_users'][$filter_key]);
757                }
758                }
759                        }
760                }
761
762// +-----------------------------------------------------------------------+
763// |                 Resend new validation key to users                    |
764// +-----------------------------------------------------------------------+
765// +-----------------------------------------------------------------------+
766// |                            selected users                             |
767// +-----------------------------------------------------------------------+
768                if (isset($_POST['Mail_With_Key']))
769                {
770                $collection = array();
771
772                        switch ($_POST['target'])
773        {
774                case 'all' :
775        {
776                foreach($page['filtered_users'] as $local_user)
777                {
778                        array_push($collection, $local_user['id']);
779                }
780                break;
781                                }
782        case 'selection' :
783        {
784                if (isset($_POST['selection']))
785                {
786                        $collection = $_POST['selection'];
787                }
788                break;
789        }
790                        }
791
792        if (count($collection) == 0)
793        {
794                array_push($page['errors'], l10n('Select at least one user'));
795        }
796                }
797// +-----------------------------------------------------------------------+
798// |                 Resend new validation key to users                    |
799// +-----------------------------------------------------------------------+
800                if (isset($_POST['Mail_With_Key']) and count($collection) > 0)
801                {
802                        if (in_array($conf['guest_id'], $collection))
803                {
804                array_push($page['errors'], l10n('UAM_No_validation_for_Guest'));
805        }
806        if (($conf['guest_id'] != $conf['default_user_id']) and
807                in_array($conf['default_user_id'], $collection))
808        {
809                array_push($page['errors'], l10n('UAM_No_validation_for_default_user'));
810        }
811                if (in_array($conf['webmaster_id'], $collection))
812        {
813                array_push($page['errors'], l10n('UAM_No_validation_for_Webmaster'));
814        }
815        if (in_array($user['id'], $collection))
816        {
817                array_push($page['errors'], l10n('UAM_No_validation_for_your_account'));
818        }
819
820        if (count($page['errors']) == 0)
821        {
822                foreach ($collection as $user_id)
823        {       
824                $typemail = 1;
825                                  $query = "
826SELECT id, username, mail_address
827  FROM ".USERS_TABLE."
828WHERE id = '".$user_id."'
829;";
830                                        $data = pwg_db_fetch_assoc(pwg_query($query));
831                               
832                ResendMail2User($typemail,$user_id,stripslashes($data['username']),$data['mail_address'],true);
833        }
834        array_push(
835                $page['infos'],
836                l10n_dec(
837                        'UAM_%d_Mail_With_Key', 'UAM_%d_Mails_With_Key',
838                count($collection)
839                )
840        );
841       
842                                $page['filtered_users'] = get_unvalid_user_list();
843                        }
844                }
845
846// +-----------------------------------------------------------------------+
847// |             Send reminder without new key to users                    |
848// +-----------------------------------------------------------------------+
849// +-----------------------------------------------------------------------+
850// |                            selected users                             |
851// +-----------------------------------------------------------------------+
852                if (isset($_POST['Mail_Without_Key']))
853                {
854                $collection = array();
855
856                        switch ($_POST['target'])
857        {
858                case 'all' :
859        {
860                foreach($page['filtered_users'] as $local_user)
861                {
862                        array_push($collection, $local_user['id']);
863                }
864                break;
865                                }
866        case 'selection' :
867        {
868                if (isset($_POST['selection']))
869                {
870                        $collection = $_POST['selection'];
871                }
872                break;
873        }
874                        }
875
876        if (count($collection) == 0)
877        {
878                array_push($page['errors'], l10n('Select at least one user'));
879        }
880                }
881// +-----------------------------------------------------------------------+
882// |             Send reminder without new key to users                    |
883// +-----------------------------------------------------------------------+
884                if (isset($_POST['Mail_Without_Key']) and count($collection) > 0)
885                {
886                        if (in_array($conf['guest_id'], $collection))
887                {
888                array_push($page['errors'], l10n('UAM_No_validation_for_Guest'));
889        }
890        if (($conf['guest_id'] != $conf['default_user_id']) and
891                in_array($conf['default_user_id'], $collection))
892        {
893                array_push($page['errors'], l10n('UAM_No_validation_for_default_user'));
894        }
895                if (in_array($conf['webmaster_id'], $collection))
896        {
897                array_push($page['errors'], l10n('UAM_No_validation_for_Webmaster'));
898        }
899        if (in_array($user['id'], $collection))
900        {
901                array_push($page['errors'], l10n('UAM_No_validation_for_your_account'));
902        }
903
904        if (count($page['errors']) == 0)
905        {
906                foreach ($collection as $user_id)
907        {
908                $typemail = 2;
909                                  $query = "
910SELECT id, username, mail_address
911  FROM ".USERS_TABLE."
912WHERE id = '".$user_id."'
913;";
914                                       
915                                        $data = pwg_db_fetch_assoc(pwg_query($query));
916                               
917                ResendMail2User($typemail,$user_id,stripslashes($data['username']),$data['mail_address'],false);                               
918        }
919        array_push(
920                $page['infos'],
921                l10n_dec(
922                        'UAM_%d_Reminder_Sent', 'UAM_%d_Reminders_Sent',
923                count($collection)
924                )
925        );
926       
927                                $page['filtered_users'] = get_unvalid_user_list();
928                        }
929                }
930
931// +-----------------------------------------------------------------------+
932// |                                                                            Force validation                                                         |
933// +-----------------------------------------------------------------------+
934// +-----------------------------------------------------------------------+
935// |                            selected users                             |
936// +-----------------------------------------------------------------------+
937                if (isset($_POST['Force_Validation']))
938                {
939                $collection = array();
940
941                        switch ($_POST['target'])
942        {
943                case 'all' :
944        {
945                foreach($page['filtered_users'] as $local_user)
946                {
947                        array_push($collection, $local_user['id']);
948                }
949                break;
950                                }
951        case 'selection' :
952        {
953                if (isset($_POST['selection']))
954                {
955                        $collection = $_POST['selection'];
956                }
957                break;
958        }
959                        }
960
961        if (count($collection) == 0)
962        {
963                array_push($page['errors'], l10n('Select at least one user'));
964        }
965                }
966// +-----------------------------------------------------------------------+
967// |                                                                            Force validation                                                         |
968// +-----------------------------------------------------------------------+
969                if (isset($_POST['Force_Validation']) and count($collection) > 0)
970                {
971                        if (in_array($conf['guest_id'], $collection))
972                {
973                array_push($page['errors'], l10n('UAM_No_validation_for_Guest'));
974        }
975        if (($conf['guest_id'] != $conf['default_user_id']) and
976                in_array($conf['default_user_id'], $collection))
977        {
978                array_push($page['errors'], l10n('UAM_No_validation_for_default_user'));
979        }
980                if (in_array($conf['webmaster_id'], $collection))
981        {
982                array_push($page['errors'], l10n('UAM_No_validation_for_Webmaster'));
983        }
984        if (in_array($user['id'], $collection))
985        {
986                array_push($page['errors'], l10n('UAM_No_validation_for_your_account'));
987        }
988
989        if (count($page['errors']) == 0)
990        {
991                foreach ($collection as $user_id)
992        {
993          ForceValidation($user_id);
994          validation_mail($user_id);
995        }
996        array_push(
997                $page['infos'],
998                l10n_dec(
999                        'UAM_%d_Validated_User', 'UAM_%d_Validated_Users',
1000                count($collection)
1001                )
1002        );
1003
1004                                $page['filtered_users'] = get_unvalid_user_list();
1005                        }
1006                }
1007               
1008
1009// +-----------------------------------------------------------------------+
1010// |                              groups list                              |
1011// +-----------------------------------------------------------------------+
1012
1013                $groups[-1] = '------------';
1014
1015    $query = '
1016SELECT id, name
1017  FROM '.GROUPS_TABLE.'
1018ORDER BY name ASC
1019;';
1020
1021                $result = pwg_query($query);
1022         
1023    while ($row = pwg_db_fetch_assoc($result))
1024    {
1025      $groups[$row['id']] = $row['name'];
1026    }
1027
1028// +-----------------------------------------------------------------------+
1029// |                               user list                               |
1030// +-----------------------------------------------------------------------+
1031
1032                $profile_url = get_root_url().'admin.php?page=profile&amp;user_id=';
1033                $perm_url = get_root_url().'admin.php?page=user_perm&amp;user_id=';
1034
1035    $visible_user_list = array();
1036    foreach ($page['filtered_users'] as $num => $local_user)
1037    {
1038      $visible_user_list[] = $local_user;
1039                }
1040
1041    // Avoid jquery accordeon menu bug when there is no users to display
1042    // Pending because it causes php warnings when no users are listed (when $visible_user_list[] is empty)
1043    /*if (empty($visible_user_list))
1044    {
1045      $visible_user_list[] = null;
1046    }*/
1047
1048                foreach ($visible_user_list as $local_user)
1049    {
1050      $groups_string = preg_replace(
1051        '/(\d+)/e',
1052        "\$groups['$1']",
1053        implode(
1054                ', ',
1055            $local_user['groups']
1056         )
1057                        );
1058
1059      $query = '
1060SELECT user_id, reminder
1061FROM '.USER_CONFIRM_MAIL_TABLE.'
1062WHERE user_id = '.$local_user['id'].'
1063;';
1064      $result = pwg_query($query);
1065     
1066      $row = pwg_db_fetch_assoc($result);
1067   
1068      if (isset($row['reminder']) and $row['reminder'] == 'true')
1069      {
1070        $reminder = l10n('UAM_Reminder_Sent_OK');
1071      }
1072      else if ((isset($row['reminder']) and $row['reminder'] == 'false') or !isset($row['reminder']))
1073      {
1074        $reminder = l10n('UAM_Reminder_Sent_NOK');
1075      }
1076
1077
1078                if (isset($_POST['pref_submit'])
1079                and isset($_POST['selection'])
1080        and in_array($local_user['id'], $_POST['selection']))
1081                {
1082                                $checked = 'checked="checked"';
1083                }
1084                        else
1085        {
1086                $checked = '';
1087        }
1088
1089        $properties = array();
1090        if ( $local_user['level'] != 0 )
1091                        {
1092                $properties[] = l10n( sprintf('Level %d', $local_user['level']) );
1093                        }
1094        $properties[] =
1095                (isset($local_user['enabled_high']) and ($local_user['enabled_high'] == 'true'))
1096                ? l10n('is_high_enabled') : l10n('is_high_disabled');
1097
1098                        $expiration = expiration($local_user['id']);
1099     
1100                $template->append(
1101                'users',
1102        array(
1103                'ID'               => $local_user['id'],
1104                'CHECKED'          => $checked,
1105                'U_PROFILE'        => $profile_url.$local_user['id'],
1106                'U_PERM'           => $perm_url.$local_user['id'],
1107                'USERNAME'         => stripslashes($local_user['username'])
1108                                  .($local_user['id'] == $conf['guest_id']
1109                                  ? '<BR>['.l10n('is_the_guest').']' : '')
1110                                  .($local_user['id'] == $conf['default_user_id']
1111                                  ? '<BR>['.l10n('is_the_default').']' : ''),
1112                                  'STATUS' => l10n('user_status_'
1113                                  .$local_user['status']),
1114                                        'EMAIL'            => get_email_address_as_display_text($local_user['email']),
1115                'GROUPS'           => $groups_string,
1116                'REGISTRATION'     => $local_user['registration_date'],
1117          'REMINDER'         => $reminder,   
1118                'EXPIRATION'       => $expiration,
1119                                )
1120                        );
1121                }   
1122
1123    // Check if validation of register is made by admin or visitor
1124    // If visitor, $Confirm_Local is used to mask useless buttons
1125    $Confirm_Local = "";
1126   
1127    if ($conf_UAM[1] == 'local')
1128    {
1129      $Confirm_Local = $conf_UAM[1];
1130    }
1131    else
1132    {
1133      $Confirm_Local = "";
1134    } 
1135   
1136    //Plugin version inserted
1137    $template->assign(
1138      array(
1139        'CONFIRM_LOCAL'=> $Confirm_Local,
1140        'UAM_VERSION'  => $version,
1141        'UAM_PATH'     => UAM_PATH,
1142      )
1143    );
1144
1145// +-----------------------------------------------------------------------+
1146// |                             errors display                            |
1147// +-----------------------------------------------------------------------+
1148                if ( isset ($errors) and count($errors) != 0)
1149                {
1150                $template->assign('errors',array());
1151                        foreach ($errors as $error)
1152                {
1153                                array_push($page['errors'], $error);
1154                }
1155                } 
1156
1157// +-----------------------------------------------------------------------+
1158// |                           templates display                           |
1159// +-----------------------------------------------------------------------+
1160                $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/usermanager.tpl');
1161    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');         
1162        }
1163  else
1164  {
1165                array_push($page['errors'], l10n('UAM_Err_UserManager_Settings'));
1166  }
1167  break;
1168
1169
1170// *************************************************************************
1171// +-----------------------------------------------------------------------+
1172// |                           Ghost Tracker page                          |
1173// +-----------------------------------------------------------------------+
1174// *************************************************************************
1175  case 'ghosttracker':
1176
1177  $conf_UAM = unserialize($conf['UserAdvManager']);
1178       
1179  if (isset($conf_UAM[16]) and $conf_UAM[16]=='true')
1180  {
1181// +-----------------------------------------------------------------------+
1182// |                           initialization                              |
1183// +-----------------------------------------------------------------------+
1184
1185                if (!defined('PHPWG_ROOT_PATH'))
1186    {
1187        die('Hacking attempt!');
1188    }
1189         
1190    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
1191
1192// +-----------------------------------------------------------------------+
1193// | Check Access and exit when user status is not ok                      |
1194// +-----------------------------------------------------------------------+
1195                check_status(ACCESS_ADMINISTRATOR);
1196
1197// +-----------------------------------------------------------------------+
1198// |                               user list                               |
1199// +-----------------------------------------------------------------------+
1200
1201                $page['filtered_users'] = get_ghost_user_list();
1202
1203// +-----------------------------------------------------------------------+
1204// |                            selected users                             |
1205// +-----------------------------------------------------------------------+
1206                if (isset($_POST['Del_Selected']))
1207                {
1208                $collection = array();
1209
1210                        switch ($_POST['target'])
1211        {
1212                case 'all' :
1213        {
1214                foreach($page['filtered_users'] as $local_user)
1215                {
1216                        array_push($collection, $local_user['id']);
1217                }
1218                                        break;
1219                                }
1220        case 'selection' :
1221        {
1222                if (isset($_POST['selection']))
1223                {
1224                        $collection = $_POST['selection'];
1225                }
1226                break;
1227        }
1228                        }
1229
1230                        if (count($collection) == 0)
1231        {
1232                array_push($page['errors'], l10n('Select at least one user'));
1233                }
1234                }
1235
1236// +-----------------------------------------------------------------------+
1237// |                             delete users                              |
1238// +-----------------------------------------------------------------------+
1239                if (isset($_POST['Del_Selected']) and count($collection) > 0)
1240        {
1241                if (in_array($conf['guest_id'], $collection))
1242                {
1243                array_push($page['errors'], l10n('Guest cannot be deleted'));
1244        }
1245        if (($conf['guest_id'] != $conf['default_user_id']) and
1246                in_array($conf['default_user_id'], $collection))
1247        {
1248                array_push($page['errors'], l10n('Default user cannot be deleted'));
1249        }
1250        if (in_array($conf['webmaster_id'], $collection))
1251        {
1252                array_push($page['errors'], l10n('Webmaster cannot be deleted'));
1253        }
1254        if (in_array($user['id'], $collection))
1255        {
1256                array_push($page['errors'], l10n('You cannot delete your account'));
1257        }
1258
1259                        if (count($page['errors']) == 0)
1260        {
1261                foreach ($collection as $user_id)
1262        {
1263                delete_user($user_id);
1264        }
1265                array_push(
1266                $page['infos'],
1267                l10n_dec(
1268                '%d user deleted', '%d users deleted',
1269                count($collection)
1270                )
1271        );
1272
1273        foreach ($page['filtered_users'] as $filter_key => $filter_user)
1274        {
1275                if (in_array($filter_user['id'], $collection))
1276                {
1277                        unset($page['filtered_users'][$filter_key]);
1278                }
1279                }
1280                        }
1281                }
1282
1283// +-----------------------------------------------------------------------+
1284// |                          Send ghost reminder                          |
1285// +-----------------------------------------------------------------------+
1286// +-----------------------------------------------------------------------+
1287// |                            selected users                             |
1288// +-----------------------------------------------------------------------+
1289                if (isset($_POST['Reminder_Email']))
1290                {
1291                $collection = array();
1292
1293                        switch ($_POST['target'])
1294        {
1295                case 'all' :
1296        {
1297                foreach($page['filtered_users'] as $local_user)
1298                {
1299                        array_push($collection, $local_user['id']);
1300                }
1301                break;
1302                                }
1303        case 'selection' :
1304        {
1305                if (isset($_POST['selection']))
1306                {
1307                        $collection = $_POST['selection'];
1308                }
1309                break;
1310        }
1311                        }
1312
1313        if (count($collection) == 0)
1314        {
1315                array_push($page['errors'], l10n('Select at least one user'));
1316        }
1317                }
1318// +-----------------------------------------------------------------------+
1319// |                         Send ghost reminder                           |
1320// +-----------------------------------------------------------------------+
1321                if (isset($_POST['Reminder_Email']) and count($collection) > 0)
1322                {
1323                        if (in_array($conf['guest_id'], $collection))
1324                {
1325                array_push($page['errors'], l10n('UAM_No_reminder_for_Guest'));
1326        }
1327        if (($conf['guest_id'] != $conf['default_user_id']) and
1328                in_array($conf['default_user_id'], $collection))
1329        {
1330                array_push($page['errors'], l10n('UAM_No_reminder_for_default_user'));
1331        }
1332                if (in_array($conf['webmaster_id'], $collection))
1333        {
1334                array_push($page['errors'], l10n('UAM_No_reminder_for_Webmaster'));
1335        }
1336        if (in_array($user['id'], $collection))
1337        {
1338                array_push($page['errors'], l10n('UAM_No_reminder_for_your_account'));
1339        }
1340
1341        if (count($page['errors']) == 0)
1342        {
1343                foreach ($collection as $user_id)
1344        {
1345                                  $query = "
1346SELECT id, username, mail_address
1347  FROM ".USERS_TABLE."
1348WHERE id = '".$user_id."'
1349;";
1350                                       
1351                                        $data = pwg_db_fetch_assoc(pwg_query($query));
1352                               
1353                ghostreminder($user_id,stripslashes($data['username']),$data['mail_address']);                         
1354        }
1355        array_push(
1356                $page['infos'],
1357                l10n_dec(
1358                        'UAM_%d_Reminder_Sent', 'UAM_%d_Reminders_Sent',
1359                count($collection)
1360                )
1361        );
1362       
1363                                $page['filtered_users'] = get_ghost_user_list();
1364                        }
1365                }
1366   
1367    if (isset($_POST['GhostTracker_Init']) and is_admin()) //Reset is only allowed for admins !
1368    {
1369      $query1 = '
1370SELECT *
1371  FROM '.USER_LASTVISIT_TABLE.';';
1372
1373      $count = pwg_db_num_rows(pwg_query($query1));
1374
1375      if ($count <> 0)
1376      {
1377        $query = '
1378SELECT DISTINCT u.id,
1379                ui.status AS status
1380FROM '.USERS_TABLE.' AS u
1381  INNER JOIN '.USER_INFOS_TABLE.' AS ui
1382    ON u.id = ui.user_id
1383WHERE u.id NOT IN (SELECT user_id FROM '.USER_LASTVISIT_TABLE.')
1384  AND status != "webmaster"
1385  AND status != "guest"
1386  AND status != "admin"
1387ORDER BY u.id ASC
1388;';
1389
1390        $result = pwg_query($query);
1391         
1392        while ($row = pwg_db_fetch_assoc($result))
1393        {
1394          list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
1395           
1396          $query = "
1397INSERT INTO ".USER_LASTVISIT_TABLE." (user_id, lastvisit, reminder)
1398VALUES ('".$row['id']."','".$dbnow."','false')
1399;";
1400          pwg_query($query);
1401        }
1402      }
1403      else if ($count == 0)
1404      {
1405        $query = '
1406SELECT DISTINCT u.id,
1407                ui.status AS status
1408FROM '.USERS_TABLE.' AS u
1409  INNER JOIN '.USER_INFOS_TABLE.' AS ui
1410    ON u.id = ui.user_id
1411WHERE status != "webmaster"
1412  AND status != "guest"
1413  AND status != "admin"
1414ORDER BY u.id ASC
1415;';
1416
1417        $result = pwg_query($query);
1418         
1419        while($row = pwg_db_fetch_assoc($result))
1420        {
1421          list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
1422           
1423          $query = "
1424INSERT INTO ".USER_LASTVISIT_TABLE." (user_id, lastvisit, reminder)
1425VALUES ('".$row['id']."','".$dbnow."','false')
1426;";
1427          pwg_query($query);
1428        }
1429      }
1430       
1431      array_push($page['infos'], l10n('UAM_GhostTracker_Init_OK'));
1432    }
1433
1434// +-----------------------------------------------------------------------+
1435// |                               user list                               |
1436// +-----------------------------------------------------------------------+
1437
1438    $visible_user_list = array();
1439    foreach ($page['filtered_users'] as $num => $local_user)
1440    {
1441      $visible_user_list[] = $local_user;
1442                }
1443
1444    // Avoid jquery accordeon menu bug when there is no users to display
1445    if (empty($visible_user_list))
1446    {
1447      $visible_user_list[] = null;
1448    }
1449   
1450                foreach ($visible_user_list as $local_user)
1451    {
1452      $reminder = '';
1453   
1454      if (isset($local_user['reminder']) and $local_user['reminder'] == 'true')
1455      {
1456        $reminder = l10n('UAM_Reminder_Sent_OK');
1457      }
1458      else if (isset($local_user['reminder']) and $local_user['reminder'] == 'false')
1459      {
1460        $reminder = l10n('UAM_Reminder_Sent_NOK');
1461      }
1462   
1463      if (isset($_POST['pref_submit']) and isset($_POST['selection']) and in_array($local_user['id'], $_POST['selection']))
1464                {
1465                                $checked = 'checked="checked"';
1466                }
1467                        else
1468        {
1469                $checked = '';
1470        }
1471
1472      $template->append(
1473          'users',
1474        array(
1475                'ID'          => $local_user['id'],
1476                'CHECKED'     => $checked,
1477                'USERNAME'    => stripslashes($local_user['username']),
1478                                        'EMAIL'       => get_email_address_as_display_text($local_user['email']),
1479          'LASTVISIT'   => $local_user['lastvisit'],
1480          'REMINDER'    => $reminder,
1481                                )
1482                        );
1483                }
1484
1485    //Plugin version inserted
1486    $template->assign(
1487      array(
1488        'UAM_VERSION'  => $version,
1489        'UAM_PATH'     => UAM_PATH,
1490      )
1491    );
1492
1493// +-----------------------------------------------------------------------+
1494// |                             errors display                            |
1495// +-----------------------------------------------------------------------+
1496                if ( isset ($errors) and count($errors) != 0)
1497                {
1498                $template->assign('errors',array());
1499                        foreach ($errors as $error)
1500                {
1501                                array_push($page['errors'], $error);
1502                }
1503                } 
1504
1505// +-----------------------------------------------------------------------+
1506// |                           templates display                           |
1507// +-----------------------------------------------------------------------+
1508                $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/ghosttracker.tpl');
1509    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');         
1510        }
1511  else
1512  {
1513                array_push($page['errors'], l10n('UAM_Err_GhostTracker_Settings'));
1514  }
1515
1516  break;
1517}
1518?>
Note: See TracBrowser for help on using the repository browser.