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

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

Piwigo 2.6 compliance :
Remove get_email_address_as_display_text()

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