source: extensions/UserAdvManager/branches/2.30/admin/UAM_admin.php @ 12667

Last change on this file since 12667 was 12667, checked in by Eric, 12 years ago

r12661 and r12666 merged from trunk to branche 2.30

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