source: extensions/UserAdvManager/branches/2.40/admin/UAM_admin.php @ 18160

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

r17807 to r18159 merged from trunk to branch 2.40 - Thx to flop25 for his really appreciated and usefull help ;-)

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