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

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

merge r26094, r26292, r26686, r26706, r26861, r26862, r26914, r26933, r26934 and r26947 from trunk to branch 2.6

Dev:

  • Replace word "categorie" by "album" in en_UK and fr_FR translation files
  • Fix html5 validation errors
  • Piwigo 2.6 compliance: Improve confirmation email sending - More accurate when users or admins are set to confirm registrations
  • Piwigo 2.6 compliance: Update tablesorter jquery plugin for compliance with jquery v1.10
  • Improve confirmation and information email sending workflow
  • HTML5 recommandation improvement - Tablesorter and tablepager jquery plugin customization (step 1)

Translations:
Update pt_BR, thanks to : flaviove
Update pt_PT, thanks to : Bridges
Add sk_SK, thanks to : JoeKundlak
Update sk_SK, thanks to : JoeKundlak

  • Property svn:eol-style set to LF
File size: 69.5 KB
RevLine 
[5056]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
[5181]11if (!defined('UAM_PATH')) define('UAM_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
[5056]12
13//ini_set('error_reporting', E_ALL);
14//ini_set('display_errors', true);
15
[5593]16include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
[5056]17include_once (PHPWG_ROOT_PATH.'/include/constants.php');
18
[5181]19load_language('plugin.lang', UAM_PATH);
[12205]20load_language('help.lang', UAM_PATH);
[5056]21
[7955]22
23// +-----------------------------------------------------------------------+
24// |                   Variables initialization                            |
25// +-----------------------------------------------------------------------+
26$my_base_url = get_admin_plugin_menu_link(__FILE__);
27
[5056]28$page['global'] = array();
29$error = array();
30$pattern = '/;/';
31$replacement = '.';
32
33$UAM_Exclusionlist_Error = false;
[11318]34$UAM_Illegal_Flag_Error1 = false;
35$UAM_Illegal_Flag_Error2 = false;
36$UAM_Illegal_Flag_Error3 = false;
[12689]37$UAM_Email_Mandatory_Check = false;
[5056]38
[10342]39$dump_download = '';
[7955]40
[5056]41// +-----------------------------------------------------------------------+
42// |                            Tabssheet                                  |
43// +-----------------------------------------------------------------------+
44if (!isset($_GET['tab']))
45        $page['tab'] = 'global';
46else
[17918]47 $page['tab'] = $_GET['tab'];
[5056]48
49$tabsheet = new tabsheet();
50$tabsheet->add('global',
[9177]51               l10n('UAM_Tab_Global'),
[5056]52               $my_base_url.'&amp;tab=global');
[17918]53$tabsheet->add('userlist',
54               l10n('UAM_Tracking registered users'),
55               $my_base_url.'&amp;tab=userlist');
[5056]56$tabsheet->add('usermanager',
[13107]57               l10n('UAM_Tracking confirmations'),
[5056]58               $my_base_url.'&amp;tab=usermanager');
59$tabsheet->add('ghosttracker',
[9177]60               l10n('UAM_Tab_GhostTracker'),
[5056]61               $my_base_url.'&amp;tab=ghosttracker');
62$tabsheet->select($page['tab']);
63$tabsheet->assign();
64
65
66// +-----------------------------------------------------------------------+
67// |                      Getting plugin version                           |
68// +-----------------------------------------------------------------------+
[5181]69$plugin =  PluginInfos(UAM_PATH);
[5762]70$version = $plugin['version'];
[5056]71
72
73// +----------------------------------------------------------+
74// |            FCK Editor for email text fields              |
75// +----------------------------------------------------------+
[5181]76$toolbar = 'Basic';
[5073]77$width = '750px';
78$height = '300px';
79$areas = array();
[12661]80array_push( $areas,'UAM_ConfirmMail_Custom_Txt1','UAM_ConfirmMail_Custom_Txt2','UAM_GTAutoDelText','UAM_USRAutoDelText','UAM_CustomRejectConnexion_Text');
[5084]81
[5073]82if (function_exists('set_fckeditor_instance'))
[5084]83{
[20591]84  $fcke_config = unserialize($conf['FCKEditor']);
[5084]85  foreach($areas as $area)
86  {
[20591]87    if (!isset($fcke_config[$area]))
[5084]88    {
89      $fcke_config[$area] = false;
90    }
91  }
[20591]92  $conf['FCKEditor'] = serialize($fcke_config);
[5084]93
[20591]94  set_fckeditor_instance($areas, $toolbar, $width, $height);
[5181]95}
[5056]96
97
98// +-----------------------------------------------------------------------+
99// |                            Tabssheet select                           |
100// +-----------------------------------------------------------------------+
101
102switch ($page['tab'])
103{
104// *************************************************************************
105// +-----------------------------------------------------------------------+
106// |                           Global Config                               |
107// +-----------------------------------------------------------------------+
108// *************************************************************************
[20591]109  case 'global':
[5056]110
[25092]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']))
[20591]112  {
[5056]113
[20591]114  // Render email contents fields
115  // ----------------------------
116    $_POST['UAM_MailInfo_Text'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_MailInfo_Text'])));
[11318]117
[20591]118    $_POST['UAM_ConfirmMail_Text'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_ConfirmMail_Text'])));
[5056]119
[20591]120    $_POST['UAM_GhostTracker_ReminderText'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_GhostTracker_ReminderText'])));
[14729]121
[20591]122    $_POST['UAM_GTAutoDelText'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_GTAutoDelText'])));
[5056]123
[20591]124    $_POST['UAM_GTAutoMailText'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_GTAutoMailText'])));
[9135]125
[20591]126    $_POST['UAM_AdminValidationMail_Text'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_AdminValidationMail_Text'])));
[5056]127
[20591]128    $_POST['UAM_CustomPasswRetr_Text'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_CustomPasswRetr_Text'])));
[9135]129
[20591]130    $_POST['UAM_USRAutoDelText'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_GTAutoDelText'])));
[9266]131
[20591]132    $_POST['UAM_CustomRejectConnexion_Text'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_CustomRejectConnexion_Text'])));
[12661]133
[20591]134  // Render email subjects fields
135  // ---------------------------
136    $_POST['UAM_ConfirmMail_Subject'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_ConfirmMail_Subject'])));
[14635]137
[20591]138    $_POST['UAM_ConfirmMail_Remail_Subject'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_ConfirmMail_Remail_Subject'])));
[14729]139
[20591]140    $_POST['UAM_InfoMail_Subject'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_InfoMail_Subject'])));
[14729]141
[20591]142    $_POST['UAM_GTAutoMail_Subject'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_GTAutoMail_Subject'])));
[14729]143
[20591]144    $_POST['UAM_GTReminder_Subject'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_GTReminder_Subject'])));
[14729]145
[20591]146    $_POST['UAM_AdminValidationMail_Subject'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_AdminValidationMail_Subject'])));
[14729]147
148
[20591]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    }
[6754]165
[8065]166    // Consistency check between ConfirmMail and AutoMail - We cannot use GTAutoMail if ConfirmMail is disabled
[12271]167    // ---------------------------------------------------------------------------------------------------------
[8065]168    $conf_UAM = unserialize($conf['UserAdvManager']);
[11318]169    $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']);
[8065]170   
[26948]171    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')
[8065]172    {
[20591]173      $newvalue = 'false';
[8065]174      $_POST['UAM_GTAutoMail'] = $newvalue;
[9177]175      array_push($page['errors'], l10n('UAM_Error_GTAutoMail_cannot_be_set_without_ConfirmMail'));
[8065]176    }
177
[11318]178    // Check if [Kdays] flag is used in a legal way (ConfirmMail Time out have to be set)
[12271]179    // ----------------------------------------------------------------------------------
[21075]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)
[11318]181    {
182      $UAM_Illegal_Flag_Error1 = true;
183      array_push($page['errors'], l10n('UAM_Error_Using_illegal_Kdays'));
184    }
185
[21611]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    {
[24371]191      // Unset old group as group by default
[21611]192      $query = '
[24371]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
[21611]202FROM '.GROUPS_TABLE.'
203WHERE id = '.$_POST['UAM_Validated_Group'].'
204;';
205
206      $UAM_group = pwg_db_fetch_assoc(pwg_query($query));
207
[24371]208      $query = '
[21611]209UPDATE '.GROUPS_TABLE.'
[24371]210SET is_default = \''.boolean_to_string(true).'\'
[21611]211WHERE id = '.$_POST['UAM_Validated_Group'].'
212;';
[24371]213      pwg_query($query);
[21611]214
[24371]215      array_push(
216        $page['infos'],
217        sprintf(l10n('UAM_group "%s" updated'), $UAM_group['name'])
218      );
[21611]219    }
220
[12205]221    // Save global UAM configuration
[12271]222    // -----------------------------
[21075]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'));
[24212]266    $newconf_UAM['ADD_GALLERY_URL_TO_EMAILS'] = (isset($_POST['UAM_AddURL2Mail']) ? $_POST['UAM_AddURL2Mail'] : 'false');
[5056]267
[5181]268    $conf['UserAdvManager'] = serialize($newconf_UAM);
[5056]269
[21075]270    conf_update_param('UserAdvManager', pwg_db_real_escape_string($conf['UserAdvManager'])); 
[5056]271
[12271]272    // Email confirmation settings
273    // --------------------------
[6753]274    $_POST['UAM_ConfirmMail_ReMail_Txt1'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_ConfirmMail_ReMail_Txt1'])));
[5056]275
[6753]276    $_POST['UAM_ConfirmMail_ReMail_Txt2'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_ConfirmMail_ReMail_Txt2'])));
[17918]277
[6753]278    $_POST['UAM_ConfirmMail_Custom_Txt1'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_ConfirmMail_Custom_Txt1'])));
[17918]279
[6753]280    $_POST['UAM_ConfirmMail_Custom_Txt2'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_ConfirmMail_Custom_Txt2'])));
[11318]281
282    // Check if [Kdays] flag is used in a legal way (ConfirmMail Time out have to be set)
[12271]283    // ----------------------------------------------------------------------------------
[21075]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)
[11318]285    {
286      $UAM_Illegal_Flag_Error2 = true;
287      array_push($page['errors'], l10n('UAM_Error_Using_illegal_flag'));
288    }
[21075]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)
[11318]290    {
291      $UAM_Illegal_Flag_Error3 = true;
292      array_push($page['errors'], l10n('UAM_Error_Using_illegal_flag'));
293    }
[12205]294
295    // Save ConfirmMail settings
[12271]296    // -------------------------
[21075]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'));
[5056]304
[5181]305    $conf['UserAdvManager_ConfirmMail'] = serialize($newconf_UAM_ConfirmMail);
[5056]306
[10976]307    conf_update_param('UserAdvManager_ConfirmMail', pwg_db_real_escape_string($conf['UserAdvManager_ConfirmMail']));
[5056]308
[20591]309    array_push($page['infos'], l10n('UAM_save_config'));
[5056]310  }
311
[10342]312  // Saving UAM tables and configuration settings
[12271]313  // --------------------------------------------
[10342]314  if (isset($_POST['save']))
315  {
316    $dump_download = (isset($_POST['dump_download'])) ? 'true' : 'false';
317   
[12239]318    if(UAM_dump($dump_download) and $dump_download == 'false')
[10342]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  }
[5056]327
[12275]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
[12314]334    if (file_exists($Backup_File) and $file = file($Backup_File, FILE_IGNORE_NEW_LINES) and !empty($file))
[12275]335    {
[12314]336      // Check backup file version
337      // -------------------------
338      if ($file[0] == "-- ".$version." --")
[12275]339      {
[12314]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        }
[12275]349      }
[12314]350      else array_push($page['errors'], l10n('UAM_Bad_version_backup'));
[12275]351    }
352    else
353    {
354      array_push($page['errors'], l10n('UAM_No_Backup_File'));
355    }
356  }
357
[5181]358  $conf_UAM = unserialize($conf['UserAdvManager']);
[5056]359
[12271]360  // Group setting for unvalidated, validated users and downgrade group
361  // ------------------------------------------------------------------
[5056]362  $groups[-1] = '---------';
363  $No_Valid = -1;
364  $Valid = -1;
[8065]365  $Downgrade = -1;
[5056]366       
[12271]367  // Get groups list in database
368  // ---------------------------
[5056]369  $query = '
370SELECT id, name
[20591]371FROM '.GROUPS_TABLE.'
[5056]372ORDER BY name ASC
373;';
374       
375  $result = pwg_query($query);
376       
[5633]377  while ($row = pwg_db_fetch_assoc($result))
[5056]378  {
379    $groups[$row['id']] = $row['name'];
[7955]380    //configuration value for unvalidated users
[21075]381    if (isset($conf_UAM['NO_CONFIRM_GROUP']) and $conf_UAM['NO_CONFIRM_GROUP'] == $row['id'])
[5056]382    {
[20591]383      $No_Valid = $row['id'];
384    }
[7955]385    //configuration value for validated users
[21075]386    if (isset($conf_UAM['VALIDATED_GROUP']) and $conf_UAM['VALIDATED_GROUP'] == $row['id'])
[20591]387    {
388      $Valid = $row['id'];
389    }
[8065]390    //configuration value for downgrade users
[21075]391    if (isset($conf_UAM['DOWNGRADE_GROUP']) and $conf_UAM['DOWNGRADE_GROUP'] == $row['id'])
[20591]392    {
393      $Downgrade = $row['id'];
394    }
[5056]395  }
396       
[12271]397  // Template initialization for unvalidated users group
398  // ---------------------------------------------------
[5056]399  $template->assign(
[20591]400    'No_Confirm_Group',
401      array(
402        'group_options'=> $groups,
403        'group_selected' => $No_Valid
404      )
405    );
[12271]406
407  // Template initialization for validated users group
408  // -------------------------------------------------
[5056]409  $template->assign(
[20591]410    'Validated_Group',
411      array(
412        'group_options'=> $groups,
413        'group_selected' => $Valid
414      )
415    );
[12271]416
417  // Template initialization for downgrade group
418  // -------------------------------------------
[8065]419  $template->assign(
420    'Downgrade_Group',
[20591]421      array(
422        'group_options'=> $groups,
423        'group_selected' => $Downgrade
424      )
[8065]425        );
[5056]426       
[12271]427  // Status setting for unvalidated, validated users and downgrade status
428  // --------------------------------------------------------------------
[5056]429  $status_options[-1] = '------------';
430  $No_Valid_Status = -1;
431  $Valid_Status = -1;
[8065]432  $Downgrade_Status = -1;
[25092]433
434  // Bug fix - We can not use "Guest" status and other are not suitable so we fix NO_CONFIRM_STATUS to "------------"
[25101]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//    );
[25092]444
[12271]445  // Get unvalidate status values
446  // ----------------------------
[25101]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 
[12271]466  // Get validate status values
467  // --------------------------
[5056]468  foreach (get_enums(USER_INFOS_TABLE, 'status') as $status)
[20591]469  {
470    $status_options[$status] = l10n('user_status_'.$status);
[21075]471    if (isset($conf_UAM['VALIDATED_STATUS']) and $conf_UAM['VALIDATED_STATUS'] == $status)
[20591]472    {
473      $Valid_Status = $status;
474    }
[5056]475               
[12271]476    // Template initialization for validated users status
477    // --------------------------------------------------
478    $template->assign(
[20591]479      'Confirm_Status',
480        array(
481          'Status_options' => $status_options,
482          'Status_selected' => $Valid_Status
483        )
484      );
485  }
[5056]486
[25092]487
488  // Bug fix - We can not use "Guest" status and other are not suitable so we fix DOWNGRADE_STATUS to "------------"
[25101]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//    );
[25092]498
[12271]499  // Get downgrade status values
500  // ---------------------------
[25101]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  }
[8065]519
[12189]520
[12271]521  // Level setting for unvalidated, validated users and downgrade level
522  // ------------------------------------------------------------------
[12189]523  $level_options[-1] = '------------';
524  $No_Valid_Level = -1;
525  $Valid_Level = -1;
526  $Downgrade_Level = -1;
527
528  // Get unvalidated privacy levels values
[12271]529  // -------------------------------------
[12189]530  foreach ($conf['available_permission_levels'] as $level)
531  {
[20591]532    $level_options[$level] = l10n(sprintf('Level %d', $level));
[21075]533    if (isset($conf_UAM['NO_VALID_LEVEL']) and $conf_UAM['NO_VALID_LEVEL'] == $level)
[20591]534    {
535      $No_Valid_Level = $level;
536    }
[12271]537
538    // Template initialization for unvalidated users level
539    // ---------------------------------------------------
540    $template->assign(
[20591]541      'No_Valid_Level',
542        array(
543          'Level_options' => $level_options,
544          'Level_selected' => $No_Valid_Level
545        )
546      );
[12189]547  }
548
549  // Get validated privacy levels values
[12271]550  // -----------------------------------
[12189]551  foreach ($conf['available_permission_levels'] as $level)
552  {
[20591]553    $level_options[$level] = l10n(sprintf('Level %d', $level));
[21075]554    if (isset($conf_UAM['VALID_LEVEL']) and $conf_UAM['VALID_LEVEL'] == $level)
[20591]555    {
556      $Valid_Level = $level;
557    }
[12271]558
559    // Template initialization for unvalidated users level
560    // ---------------------------------------------------
561    $template->assign(
[20591]562      'Valid_Level',
563        array(
564          'Level_options' => $level_options,
565          'Level_selected' => $Valid_Level
566        )
567      );
[12189]568  }
569
570  // Get downgrade privacy levels values
[12271]571  // -----------------------------------
[12189]572  foreach ($conf['available_permission_levels'] as $level)
573  {
[20591]574    $level_options[$level] = l10n(sprintf('Level %d', $level));
[21075]575    if (isset($conf_UAM['DOWNGRADE_LEVEL']) and $conf_UAM['DOWNGRADE_LEVEL'] == $level)
[20591]576    {
577      $Downgrade_Level = $level;
578    }
[12271]579
580    // Template initialization for unvalidated users level
581    // ---------------------------------------------------
582    $template->assign(
[20591]583      'Downgrade_Level',
584        array(
585          'Level_options' => $level_options,
586          'Level_selected' => $Downgrade_Level
587        )
588      );
[12189]589  }
590
[12689]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
[12271]598  // Save last opened paragraph in configuration tab
599  // -----------------------------------------------
[5056]600  $nb_para=(isset($_POST["nb_para"])) ? $_POST["nb_para"]:"";
601  $nb_para2=(isset($_POST["nb_para2"])) ? $_POST["nb_para2"]:"";
602
[5181]603  $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']);
[7955]604
[12271]605  // ------------------------------------------
[7955]606  // Template initialization for forms and data
[12271]607  // ------------------------------------------
[10359]608  $themeconf=$template->get_template_vars('themeconf');
609  $UAM_theme=$themeconf['id'];
610
[5056]611  $template->assign(
[20591]612    array(
[17918]613                                                'nb_para'                           => $nb_para,
[20591]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,
[21075]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'],
[24212]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"' : '' ,
[20591]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,
[21075]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'],
[5056]695    )
696  );
697
698  if (isset($_POST['audit']))
[20591]699  {
700    $msg_error1 = '';
[5056]701               
[12271]702    // Username without forbidden keys
703    // -------------------------------
[21075]704    if ( isset($conf_UAM['USERNAME_CHAR']) and $conf_UAM['USERNAME_CHAR'] == 'true' )
[20591]705          {
706      $query = '
[17918]707SELECT '.$conf['user_fields']['username'].', '.$conf['user_fields']['email'].'
[20591]708FROM '.USERS_TABLE.'
[17918]709;';
[5056]710
[20591]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 = '';
[5056]721               
[12271]722    // Email without forbidden domain
723    // ------------------------------
[21075]724    if ( isset($conf_UAM['MAILEXCLUSION']) and $conf_UAM['MAILEXCLUSION'] == 'true' )
[20591]725    {
726      $query = '
[17918]727SELECT '.$conf['user_fields']['username'].', '.$conf['user_fields']['email'].'
[20591]728FROM '.USERS_TABLE.'
[17918]729;';
[20591]730
731      $result = pwg_query($query);
732
733      while($row = pwg_db_fetch_assoc($result))
734      {
[21075]735        $conf_MailExclusion = preg_split("/[\s,]+/",$conf_UAM['MAILEXCLUSION_LIST']);
[20591]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'));
[17918]757  }
[5056]758
759
760// +-----------------------------------------------------------------------+
761// |                             errors display                            |
762// +-----------------------------------------------------------------------+
[20591]763  if (isset ($errors) and count($errors) != 0)
[5056]764  {
[20591]765    $template->assign('errors',array());
766    foreach ($errors as $error)
767    {
768      array_push($page['errors'], $error);
769    }
770  } 
[5056]771
772// +-----------------------------------------------------------------------+
773// |                           templates display                           |
774// +-----------------------------------------------------------------------+
[5593]775  $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/global.tpl');
[5056]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 
[5181]788  $conf_UAM = unserialize($conf['UserAdvManager']);
[5056]789 
[21075]790  if (isset($conf_UAM['ADDLASTVISIT']) and $conf_UAM['ADDLASTVISIT']=='true')
[5056]791  {
792// +-----------------------------------------------------------------------+
793// |                           initialization                              |
794// +-----------------------------------------------------------------------+
795
[20591]796    if (!defined('PHPWG_ROOT_PATH'))
797    {
798      die('Hacking attempt!');
799    }
[5056]800         
[20591]801    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
[5056]802
803// +-----------------------------------------------------------------------+
804// | Check Access and exit when user status is not ok                      |
805// +-----------------------------------------------------------------------+
[20591]806    check_status(ACCESS_ADMINISTRATOR);
[5056]807
808
809// +-----------------------------------------------------------------------+
810// |                               user list                               |
811// +-----------------------------------------------------------------------+
812
[20591]813    $page['filtered_users'] = get_user_list();
[5056]814
815// +-----------------------------------------------------------------------+
816// |                               user list                               |
817// +-----------------------------------------------------------------------+
818
[20591]819      $visible_user_list = array();
[17918]820                foreach ($page['filtered_users'] as $num => $local_user)
821                {
[20591]822        $visible_user_list[] = $local_user;
823      }
[5056]824
[20591]825                        foreach ($visible_user_list as $local_user)
826      {
827        // dates formating and compare
[17918]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
[5056]832
[17918]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
[20591]837        $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps     
[17918]838                $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days
839 
[21075]840        if (isset($conf_UAM['GHOSTRACKER']) and $conf_UAM['GHOSTRACKER']=='true' and !empty($conf_UAM['GHOSTRACKER_DAYLIMIT']))
[17918]841                {
[21075]842          if ($deltadays <= ($conf_UAM['GHOSTRACKER_DAYLIMIT']/2))
[17918]843                {
[20591]844            $display = 'green';
[17918]845                }
846
[21075]847          if (($deltadays > ($conf_UAM['GHOSTRACKER_DAYLIMIT']/2)) and ($deltadays < $conf_UAM['GHOSTRACKER_DAYLIMIT']))
[17918]848                {
[20591]849            $display = 'orange';
[17918]850                }
851
[21075]852                if ($deltadays >= $conf_UAM['GHOSTRACKER_DAYLIMIT'])
[17918]853                {
[20591]854            $display = 'red';
[17918]855                        }
[20591]856        }
[17918]857                else $display = '';
858
859                // Template initialization
860                // -----------------------
861                        $template->append(
862                                'users',
863                                array(
864                                        'ID'          => $local_user['id'],
[20591]865                'USERNAME'    => stripslashes($local_user['username']),
[25745]866                'EMAIL'       => $local_user['email'],
[20591]867                'LASTVISIT'   => $local_user['lastvisit'],
868                'DAYS'        => $deltadays,
869                'DISPLAY'     => $display,
870              )
871            );
872      }
[17918]873
[20591]874      // Plugin version inserted
[17918]875                // -----------------------
876                $template->assign(
877                                array(
878                                'UAM_VERSION'  => $version,
[20591]879                  'UAM_PATH'     => UAM_PATH,
880          )
881      );
882
[5056]883// +-----------------------------------------------------------------------+
884// |                             errors display                            |
885// +-----------------------------------------------------------------------+
[20591]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      } 
[5056]894
895// +-----------------------------------------------------------------------+
896// |                           templates display                           |
897// +-----------------------------------------------------------------------+
[20591]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  }
[5056]905
[17918]906break;
[5056]907
[17918]908
[5056]909// *************************************************************************
910// +-----------------------------------------------------------------------+
911// |                           Users manager page                          |
912// +-----------------------------------------------------------------------+
913// *************************************************************************
914  case 'usermanager':
915
[5181]916  $conf_UAM = unserialize($conf['UserAdvManager']);
[5056]917
[5181]918  $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']);
[5056]919       
[21075]920  if (isset($conf_UAM['CONFIRM_MAIL']) and ($conf_UAM['CONFIRM_MAIL']=='true' or $conf_UAM['CONFIRM_MAIL']=='local'))
[8072]921  {
[5056]922// +-----------------------------------------------------------------------+
923// |                           initialization                              |
924// +-----------------------------------------------------------------------+
925
[20591]926    if (!defined('PHPWG_ROOT_PATH'))
[5056]927    {
[20591]928      die('Hacking attempt!');
[5056]929    }
[8072]930
[5056]931    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
932
933// +-----------------------------------------------------------------------+
934// | Check Access and exit when user status is not ok                      |
935// +-----------------------------------------------------------------------+
[20591]936    check_status(ACCESS_ADMINISTRATOR);
[5056]937
938// +-----------------------------------------------------------------------+
939// |                               user list                               |
940// +-----------------------------------------------------------------------+
941
[20591]942    $page['filtered_users'] = get_unvalid_user_list();
[5056]943
944// +-----------------------------------------------------------------------+
945// |                            selected users                             |
946// +-----------------------------------------------------------------------+
[20591]947    if (isset($_POST['Del_Selected']))
948    {
949      $collection = array();
[5056]950
[20591]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      }
[17918]970
[20591]971      if (count($collection) == 0)
972      {
973        array_push($page['errors'], l10n('Select at least one user'));
974      }
975    }
[5056]976
977// +-----------------------------------------------------------------------+
978// |                             delete users                              |
979// +-----------------------------------------------------------------------+
[20591]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      }
[5056]999
[20591]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        );
[5056]1013
[20591]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    }
[5056]1023
1024// +-----------------------------------------------------------------------+
1025// |                 Resend new validation key to users                    |
1026// +-----------------------------------------------------------------------+
1027// +-----------------------------------------------------------------------+
1028// |                            selected users                             |
1029// +-----------------------------------------------------------------------+
[20591]1030    if (isset($_POST['Mail_With_Key']))
1031    {
1032      $collection = array();
[5056]1033
[20591]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      }
[17918]1053
[20591]1054      if (count($collection) == 0)
1055      {
1056        array_push($page['errors'], l10n('Select at least one user'));
1057      }
1058    }
[5056]1059// +-----------------------------------------------------------------------+
1060// |                 Resend new validation key to users                    |
1061// +-----------------------------------------------------------------------+
[20591]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      }
[5056]1081
[20591]1082      if (count($page['errors']) == 0)
1083      {
1084        foreach ($collection as $user_id)
1085        {
1086          $typemail = 1;
1087          $query = '
[5056]1088SELECT id, username, mail_address
[20591]1089FROM '.USERS_TABLE.'
[17918]1090WHERE id = '.$user_id.'
1091;';
[20591]1092          $data = pwg_db_fetch_assoc(pwg_query($query));
[5056]1093
[20591]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
[5056]1108// +-----------------------------------------------------------------------+
1109// |             Send reminder without new key to users                    |
1110// +-----------------------------------------------------------------------+
1111// +-----------------------------------------------------------------------+
1112// |                            selected users                             |
1113// +-----------------------------------------------------------------------+
[20591]1114    if (isset($_POST['Mail_Without_Key']))
1115    {
1116      $collection = array();
[5056]1117
[20591]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      }
[17918]1137
[20591]1138      if (count($collection) == 0)
1139      {
1140        array_push($page['errors'], l10n('Select at least one user'));
1141      }
1142    }
[5056]1143// +-----------------------------------------------------------------------+
1144// |             Send reminder without new key to users                    |
1145// +-----------------------------------------------------------------------+
[20591]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      }
[5056]1165
[20591]1166      if (count($page['errors']) == 0)
1167      {
1168        foreach ($collection as $user_id)
1169        {
1170          $typemail = 2;
1171          $query = '
[5056]1172SELECT id, username, mail_address
[20591]1173FROM '.USERS_TABLE.'
[17918]1174WHERE id = '.$user_id.'
1175;';
[5056]1176                                       
[20591]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',
[17918]1185                        count($collection)
[20591]1186          )
1187        );
[5056]1188
[20591]1189        $page['filtered_users'] = get_unvalid_user_list();
1190      }
1191    }
1192
[5056]1193// +-----------------------------------------------------------------------+
[20591]1194// |                                                                             Manual validation      by admins              |
[5056]1195// +-----------------------------------------------------------------------+
1196// +-----------------------------------------------------------------------+
1197// |                            selected users                             |
1198// +-----------------------------------------------------------------------+
[20591]1199    if (isset($_POST['Manual_Validation']))
1200    {
1201      $collection = array();
[5056]1202
[20591]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          }
[17918]1219                break;
[20591]1220        }
1221      }
[17918]1222
[20591]1223      if (count($collection) == 0)
1224      {
1225        array_push($page['errors'], l10n('Select at least one user'));
1226      }
1227    }
[5056]1228// +-----------------------------------------------------------------------+
1229// |                                                                            Force validation                                                         |
1230// +-----------------------------------------------------------------------+
[20591]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      }
[5056]1250
[20591]1251      if (count($page['errors']) == 0)
1252      {
1253        foreach ($collection as $user_id)
1254        {
1255          ManualValidation($user_id);
[8092]1256          validation_mail($user_id);
[20591]1257        }
1258        array_push(
1259          $page['infos'],
1260          l10n_dec(
1261            'UAM_%d_Validated_User', 'UAM_%d_Validated_Users',
[17918]1262                        count($collection)
[20591]1263          )
1264        );
[5056]1265
[20591]1266        $page['filtered_users'] = get_unvalid_user_list();
1267      }
1268    }
[5056]1269
[20591]1270
[5056]1271// +-----------------------------------------------------------------------+
1272// |                              groups list                              |
1273// +-----------------------------------------------------------------------+
1274
[20591]1275    $groups[-1] = '------------';
[5056]1276
1277    $query = '
1278SELECT id, name
[20591]1279FROM '.GROUPS_TABLE.'
[5056]1280ORDER BY name ASC
1281;';
1282
[20591]1283    $result = pwg_query($query);
1284     
[5633]1285    while ($row = pwg_db_fetch_assoc($result))
[5056]1286    {
[20591]1287      $groups[$row['id']] = $row['name'];
[5056]1288    }
1289
1290// +-----------------------------------------------------------------------+
1291// |                               user list                               |
1292// +-----------------------------------------------------------------------+
1293
[20591]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=';
[5056]1296
1297    $visible_user_list = array();
1298    foreach ($page['filtered_users'] as $num => $local_user)
1299    {
[20591]1300      $visible_user_list[] = $local_user;
1301    }
[5056]1302
[20591]1303    foreach ($visible_user_list as $local_user)
[5056]1304    {
[20591]1305      $groups_string = preg_replace(
1306        '/(\d+)/e',
[5056]1307        "\$groups['$1']",
1308        implode(
[20591]1309          ', ',
1310          $local_user['groups']
1311        )
1312      );
[5056]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     
[5633]1321      $row = pwg_db_fetch_assoc($result);
[5056]1322   
1323      if (isset($row['reminder']) and $row['reminder'] == 'true')
1324      {
[9177]1325        $reminder = l10n('UAM_Reminder_Sent_OK');
[5056]1326      }
[21695]1327      else if ((isset($row['reminder']) and $row['reminder'] == 'false') or $row['reminder'] == null)
[5056]1328      {
[9177]1329        $reminder = l10n('UAM_Reminder_Sent_NOK');
[5056]1330      }
1331
[20591]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      }
[5056]1342
[20591]1343      $properties = array();
[5056]1344
[20591]1345      if ($local_user['level'] != 0)
1346      {
1347        $properties[] = l10n( sprintf('Level %d', $local_user['level']) );
1348      }
[12271]1349
[20591]1350      $properties[] = (isset($local_user['enabled_high']) and ($local_user['enabled_high'] == 'true'))
[23516]1351        ? l10n('High definition') : l10n('High definition');
[20591]1352
1353      $expiration = expiration($local_user['id']);
1354
[12271]1355      // Template initialization
1356      // -----------------------
[20591]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']
[23516]1366                                ? '<BR>['.l10n('guest').']' : '')
[20591]1367                                .($local_user['id'] == $conf['default_user_id']
[23516]1368                                ? '<BR>['.l10n('default values').']' : ''),
[20591]1369                                'STATUS' => l10n('user_status_'
1370                                .$local_user['status']),
[25745]1371          'EMAIL'            => $local_user['email'],
[20591]1372          'GROUPS'           => $groups_string,
1373          'REGISTRATION'     => $local_user['registration_date'],
[21598]1374          'REMINDER'         => $reminder,   
[20591]1375          'EXPIRATION'       => $expiration,
1376        )
1377      );
1378    }   
[6754]1379
1380    // Check if validation of register is made by admin or visitor
1381    // If visitor, $Confirm_Local is used to mask useless buttons
[12271]1382    // -----------------------------------------------------------
[6754]1383    $Confirm_Local = "";
1384   
[21075]1385    if ($conf_UAM['CONFIRM_MAIL'] == 'local')
[6754]1386    {
[21075]1387      $Confirm_Local = $conf_UAM['CONFIRM_MAIL'];
[6754]1388    }
1389    else
1390    {
1391      $Confirm_Local = "";
1392    } 
1393   
[12271]1394    // Plugin version inserted
1395    // -----------------------
[5056]1396    $template->assign(
[20591]1397      array(
[6754]1398        'CONFIRM_LOCAL'=> $Confirm_Local,
[5181]1399        'UAM_VERSION'  => $version,
1400        'UAM_PATH'     => UAM_PATH,
[5056]1401      )
1402    );
1403
1404// +-----------------------------------------------------------------------+
1405// |                             errors display                            |
1406// +-----------------------------------------------------------------------+
[20591]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    } 
[5056]1415
1416// +-----------------------------------------------------------------------+
1417// |                           templates display                           |
1418// +-----------------------------------------------------------------------+
[20591]1419    $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/usermanager.tpl');
1420    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');         
1421  }
[5056]1422  else
1423  {
[20591]1424    array_push($page['errors'], l10n('UAM_Err_UserManager_Settings'));
[5056]1425  }
1426  break;
1427
1428
1429// *************************************************************************
1430// +-----------------------------------------------------------------------+
1431// |                           Ghost Tracker page                          |
1432// +-----------------------------------------------------------------------+
1433// *************************************************************************
[20591]1434  case 'ghosttracker':
[5056]1435
[5181]1436  $conf_UAM = unserialize($conf['UserAdvManager']);
[5056]1437       
[21075]1438  if (isset($conf_UAM['GHOSTRACKER_DAYLIMIT']) and $conf_UAM['GHOSTRACKER']=='true')
[5056]1439  {
1440// +-----------------------------------------------------------------------+
1441// |                           initialization                              |
1442// +-----------------------------------------------------------------------+
1443
[20591]1444    if (!defined('PHPWG_ROOT_PATH'))
1445    {
1446      die('Hacking attempt!');
1447    }
1448     
1449    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
[5056]1450
1451// +-----------------------------------------------------------------------+
1452// | Check Access and exit when user status is not ok                      |
1453// +-----------------------------------------------------------------------+
[20591]1454    check_status(ACCESS_ADMINISTRATOR);
[5056]1455
1456// +-----------------------------------------------------------------------+
1457// |                               user list                               |
1458// +-----------------------------------------------------------------------+
1459
[20591]1460    $page['filtered_users'] = get_ghost_user_list();
[5056]1461
1462// +-----------------------------------------------------------------------+
1463// |                            selected users                             |
1464// +-----------------------------------------------------------------------+
[20591]1465    if (isset($_POST['Del_Selected']))
1466    {
1467      $collection = array();
[5056]1468
[20591]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      }
[17918]1488
[20591]1489      if (count($collection) == 0)
1490      {
1491        array_push($page['errors'], l10n('Select at least one user'));
1492      }
1493    }
[5056]1494
1495// +-----------------------------------------------------------------------+
1496// |                             delete users                              |
1497// +-----------------------------------------------------------------------+
[20591]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      }
[5056]1517
[20591]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',
[17918]1528                        count($collection)
[20591]1529          )
1530        );
[5056]1531
[20591]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    }
[5056]1541
1542// +-----------------------------------------------------------------------+
1543// |                          Send ghost reminder                          |
1544// +-----------------------------------------------------------------------+
1545// +-----------------------------------------------------------------------+
1546// |                            selected users                             |
1547// +-----------------------------------------------------------------------+
[20591]1548    if (isset($_POST['Reminder_Email']))
1549    {
1550      $collection = array();
[5056]1551
[20591]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          }
[17918]1568                break;
[20591]1569        }
1570      }
[17918]1571
[20591]1572      if (count($collection) == 0)
1573      {
1574        array_push($page['errors'], l10n('Select at least one user'));
1575      }
1576    }
[5056]1577// +-----------------------------------------------------------------------+
1578// |                         Send ghost reminder                           |
1579// +-----------------------------------------------------------------------+
[20591]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      }
[5056]1599
[20591]1600      if (count($page['errors']) == 0)
1601      {
1602        foreach ($collection as $user_id)
1603        {
1604          $query = '
[5056]1605SELECT id, username, mail_address
[20591]1606FROM '.USERS_TABLE.'
[17918]1607WHERE id = '.$user_id.'
1608;';
[5056]1609                                       
[20591]1610          $data = pwg_db_fetch_assoc(pwg_query($query));
[17918]1611
[20591]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
[9253]1627    if (isset($_POST['GhostTracker_Init']) and is_admin()) //Reset is only allowed for admins !
[5056]1628    {
[20591]1629      $query1 = '
[5056]1630SELECT *
[20591]1631FROM '.USER_LASTVISIT_TABLE.';';
[5056]1632
[9253]1633      $count = pwg_db_num_rows(pwg_query($query1));
[5056]1634
[9253]1635      if ($count <> 0)
1636      {
[20591]1637        $query = '
[5056]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
[9253]1650        $result = pwg_query($query);
[20591]1651
[9253]1652        while ($row = pwg_db_fetch_assoc($result))
1653        {
[19234]1654          $dbnow = date("Y-m-d H:i:s");
[5056]1655           
[17918]1656          $query = '
1657INSERT INTO '.USER_LASTVISIT_TABLE.'
1658                                (user_id, lastvisit, reminder)
1659VALUES ('.$row['id'].',"'.$dbnow.'","false")
1660;';
[9253]1661          pwg_query($query);
[5056]1662        }
[9253]1663      }
1664      else if ($count == 0)
1665      {
1666        $query = '
[5056]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
[9253]1678        $result = pwg_query($query);
[20591]1679
[9253]1680        while($row = pwg_db_fetch_assoc($result))
1681        {
[19234]1682          $dbnow = date("Y-m-d H:i:s");
[20591]1683
[17918]1684          $query = '
1685INSERT INTO '.USER_LASTVISIT_TABLE.'
1686    (user_id, lastvisit, reminder)
1687VALUES ('.$row['id'].',"'.$dbnow.'","false")
1688;';
[9253]1689          pwg_query($query);
[5056]1690        }
[9253]1691      }
[20591]1692
[9253]1693      array_push($page['infos'], l10n('UAM_GhostTracker_Init_OK'));
[5056]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;
[20591]1704    }
1705
1706    foreach ($visible_user_list as $local_user)
[17918]1707        {
[20591]1708      $reminder = '';
1709
[5056]1710      if (isset($local_user['reminder']) and $local_user['reminder'] == 'true')
1711      {
[9177]1712        $reminder = l10n('UAM_Reminder_Sent_OK');
[5056]1713      }
1714      else if (isset($local_user['reminder']) and $local_user['reminder'] == 'false')
1715      {
[9177]1716        $reminder = l10n('UAM_Reminder_Sent_NOK');
[5056]1717      }
[20591]1718
[5056]1719      if (isset($_POST['pref_submit']) and isset($_POST['selection']) and in_array($local_user['id'], $_POST['selection']))
[20591]1720      {
1721        $checked = 'checked="checked"';
1722      }
1723      else
1724      {
1725        $checked = '';
1726      }
[5056]1727
[12271]1728      // Template initialization
1729      // -----------------------
[5056]1730      $template->append(
1731          'users',
1732        array(
[20591]1733          'ID'          => $local_user['id'],
[5056]1734                'CHECKED'     => $checked,
1735                'USERNAME'    => stripslashes($local_user['username']),
[25745]1736          'EMAIL'       => $local_user['email'],
[5056]1737          'LASTVISIT'   => $local_user['lastvisit'],
1738          'REMINDER'    => $reminder,
[20591]1739        )
1740      );
1741    }
[5056]1742
[12271]1743    // Plugin version inserted
1744    // -----------------------
[9153]1745    $template->assign(
1746      array(
1747        'UAM_VERSION'  => $version,
1748        'UAM_PATH'     => UAM_PATH,
1749      )
1750    );
1751
[5056]1752// +-----------------------------------------------------------------------+
1753// |                             errors display                            |
1754// +-----------------------------------------------------------------------+
[20591]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    } 
[5056]1763
1764// +-----------------------------------------------------------------------+
1765// |                           templates display                           |
1766// +-----------------------------------------------------------------------+
[20591]1767    $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/ghosttracker.tpl');
[5056]1768    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');         
[20591]1769  }
[5056]1770  else
1771  {
[20591]1772    array_push($page['errors'], l10n('UAM_Err_GhostTracker_Settings'));
[5056]1773  }
1774
1775  break;
1776}
1777?>
Note: See TracBrowser for help on using the repository browser.