source: extensions/UserAdvManager/tags/2.20.7/admin/UAM_admin.php @ 20461

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

r10957 merged from trunk to branch 2.20

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