source: extensions/UserAdvManager/branches/2.50/admin/UAM_admin.php @ 24213

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

r24212 merged from trunk to branch 2.50Next version is 2.5.14:
Evolution 2951 fixed - Add an option to add the gallery URL at the end of emails sent by UAM
Update ru_RU, thanks to : Konve
Update lv_LV, thanks to : agrisans
Add pt_PT, thanks to : ANO

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