source: extensions/UserAdvManager/trunk/admin/UAM_admin.php @ 24371

Last change on this file since 24371 was 24371, checked in by Eric, 11 years ago

Next version is 2.50.13 :
Bug 2958 fixed - Only one user group can be set as default group. Unicity check when a group is set for validated users.
Update el_GR, thanks to : bas_alba
Update da_DK, thanks to : Kaare

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