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

Last change on this file since 27209 was 27178, checked in by Eric, 10 years ago

Obsolete translation keys cleanup

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