source: extensions/UserAdvManager/branches/2.6/admin/UAM_admin.php

Last change on this file was 30752, checked in by Eric, 9 years ago

Help files refactory - Split help.lang.php into files per section and tabs
Merged from trunk to branches 2.6 and 2.7

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