source: extensions/NBC_UserAdvManager/trunk/admin/UAM_admin.php @ 8841

Last change on this file since 8841 was 8841, checked in by Eric, 13 years ago

Set compatibility for Piwigo 2.2-RC
Note : Little display bug remains on Piwigo's left menu due to sortable tables (userlist.tpl, usermanager.tpl and ghosttracker.tpl) when no user is listed.

  • Property svn:eol-style set to LF
File size: 49.7 KB
Line 
1<?php
2
3global $user, $lang, $conf, $errors;
4
5if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
6// +-----------------------------------------------------------------------+
7// | Check Access and exit when user status is not ok                      |
8// +-----------------------------------------------------------------------+
9check_status(ACCESS_ADMINISTRATOR);
10
11if (!defined('UAM_PATH')) define('UAM_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
12
13//ini_set('error_reporting', E_ALL);
14//ini_set('display_errors', true);
15
16include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
17include_once (PHPWG_ROOT_PATH.'/include/constants.php');
18
19load_language('plugin.lang', UAM_PATH);
20load_language('help/plugin.lang', UAM_PATH);
21
22
23// +-----------------------------------------------------------------------+
24// |                   Variables initialization                            |
25// +-----------------------------------------------------------------------+
26$my_base_url = get_admin_plugin_menu_link(__FILE__);
27
28$page['global'] = array();
29$error = array();
30$pattern = '/;/';
31$replacement = '.';
32
33$UAM_Password_Test_Score = 0;
34$UAM_Exclusionlist_Error = false;
35
36
37// +-----------------------------------------------------------------------+
38// |                            Tabssheet                                  |
39// +-----------------------------------------------------------------------+
40if (!isset($_GET['tab']))
41        $page['tab'] = 'global';
42else
43  $page['tab'] = $_GET['tab'];
44
45$tabsheet = new tabsheet();
46$tabsheet->add('global',
47               l10n('Tab_Global'),
48               $my_base_url.'&amp;tab=global');
49  $tabsheet->add('userlist',
50                 l10n('Tab_UserList'),
51                 $my_base_url.'&amp;tab=userlist');
52$tabsheet->add('usermanager',
53               l10n('Tab_UserManager'),
54               $my_base_url.'&amp;tab=usermanager');
55$tabsheet->add('ghosttracker',
56               l10n('Tab_GhostTracker'),
57               $my_base_url.'&amp;tab=ghosttracker');
58$tabsheet->select($page['tab']);
59$tabsheet->assign();
60
61
62// +-----------------------------------------------------------------------+
63// |                      Getting plugin version                           |
64// +-----------------------------------------------------------------------+
65$plugin =  PluginInfos(UAM_PATH);
66$version = $plugin['version'];
67
68
69// +----------------------------------------------------------+
70// |            FCK Editor for email text fields              |
71// +----------------------------------------------------------+
72$toolbar = 'Basic';
73$width = '750px';
74$height = '300px';
75$areas = array();
76array_push( $areas,'UAM_ConfirmMail_Custom_Txt1','UAM_ConfirmMail_Custom_Txt2','UAM_GTAutoDelText');
77
78if (function_exists('set_fckeditor_instance'))
79{
80  $fcke_config = unserialize($conf['FCKEditor']);
81  foreach($areas as $area)
82  {
83    if (!isset($fcke_config[$area]))
84    {
85      $fcke_config[$area] = false;
86    }
87  }
88  $conf['FCKEditor'] = serialize($fcke_config);
89
90  set_fckeditor_instance($areas, $toolbar, $width, $height);
91}
92
93
94// +-----------------------------------------------------------------------+
95// |                            Tabssheet select                           |
96// +-----------------------------------------------------------------------+
97
98switch ($page['tab'])
99{
100// *************************************************************************
101// +-----------------------------------------------------------------------+
102// |                           Global Config                               |
103// +-----------------------------------------------------------------------+
104// *************************************************************************
105  case 'global':
106
107        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_No_Comment_Anonymous']) and isset($_POST['UAM_Password_Enforced']) and isset($_POST['UAM_AdminPassword_Enforced']) and isset($_POST['UAM_GhostUser_Tracker']) and isset($_POST['UAM_Admin_ConfMail']) and isset($_POST['UAM_RedirToProfile']) and isset($_POST['UAM_GTAuto']))
108  {
109
110    //General configuration settings
111                $_POST['UAM_MailInfo_Text'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_MailInfo_Text'])));
112   
113                $_POST['UAM_ConfirmMail_Text'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_ConfirmMail_Text'])));
114
115    $_POST['UAM_GhostTracker_ReminderText'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_GhostTracker_ReminderText'])));
116   
117    $_POST['UAM_GTAutoDelText'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_GTAutoDelText'])));
118
119    $_POST['UAM_GTAutoMailText'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_GTAutoMailText'])));
120   
121    $_POST['UAM_AdminValidationMail_Text'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_AdminValidationMail_Text'])));
122
123    //Check if CR-LF exist at begining and end of mail exclusion list - If yes, removes them
124    if (preg_match('/^[\s]+/', $_POST['UAM_MailExclusion_List']))
125    {
126      array_push($page['errors'], l10n('mail_exclusionlist_error'));
127      $UAM_Exclusionlist_Error = true;
128    }
129
130    // Consistency check between ConfirmMail and AutoMail - We cannot use GTAutoMail if ConfirmMail is disabled
131    $conf_UAM = unserialize($conf['UserAdvManager']);
132   
133    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')
134    {
135      $newvalue = 'false';
136      $_POST['UAM_GTAutoMail'] = $newvalue;
137      array_push($page['errors'], l10n('Error_GTAutoMail_cannot_be_set_without_ConfirmMail'));
138    }
139
140                $newconf_UAM = array(
141      $_POST['UAM_Mail_Info'],
142      $_POST['UAM_Confirm_Mail'],
143      (isset($_POST['UAM_No_Confirm_Group'])?$_POST['UAM_No_Confirm_Group']:''),
144      (isset($_POST['UAM_Validated_Group'])?$_POST['UAM_Validated_Group']:''),
145      (isset($_POST['UAM_Validated_Status'])?$_POST['UAM_Validated_Status']:''),
146      $_POST['UAM_No_Comment_Anonymous'],
147      $_POST['UAM_Username_Char'],
148      $_POST['UAM_Username_List'],
149      (isset($_POST['UAM_No_Confirm_Status'])?$_POST['UAM_No_Confirm_Status']:''),
150      $_POST['UAM_MailInfo_Text'],
151      $_POST['UAM_ConfirmMail_Text'],
152      $_POST['UAM_MailExclusion'],
153      $_POST['UAM_MailExclusion_List'],
154      $_POST['UAM_Password_Enforced'],
155      $_POST['UAM_Password_Score'],
156      $_POST['UAM_AdminPassword_Enforced'],
157      $_POST['UAM_GhostUser_Tracker'],
158      $_POST['UAM_GhostTracker_DayLimit'],
159      $_POST['UAM_GhostTracker_ReminderText'],
160      $_POST['UAM_Add_LastVisit_Column'],
161      $_POST['UAM_Admin_ConfMail'],
162      $_POST['UAM_RedirToProfile'],
163      $_POST['UAM_GTAuto'],
164      $_POST['UAM_GTAutoMail'],
165      $_POST['UAM_GTAutoDelText'],
166      $_POST['UAM_GTAutoMailText'],
167      (isset($_POST['UAM_Downgrade_Group'])?$_POST['UAM_Downgrade_Group']:''),
168      (isset($_POST['UAM_Downgrade_Status'])?$_POST['UAM_Downgrade_Status']:''),
169      $_POST['UAM_AdminValidationMail_Text']
170      );
171
172    $conf['UserAdvManager'] = serialize($newconf_UAM);
173
174                $query = '
175                UPDATE '.CONFIG_TABLE.'
176                SET value="'.addslashes($conf['UserAdvManager']).'"
177                WHERE param="UserAdvManager"
178                LIMIT 1
179                ;';
180               
181                pwg_query($query);
182
183    //Email confirmation settings
184    $_POST['UAM_ConfirmMail_ReMail_Txt1'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_ConfirmMail_ReMail_Txt1'])));
185
186    $_POST['UAM_ConfirmMail_ReMail_Txt2'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_ConfirmMail_ReMail_Txt2'])));
187   
188    $_POST['UAM_ConfirmMail_Custom_Txt1'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_ConfirmMail_Custom_Txt1'])));
189   
190    $_POST['UAM_ConfirmMail_Custom_Txt2'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_ConfirmMail_Custom_Txt2'])));
191   
192          $newconf_UAM_ConfirmMail = array (
193      $_POST['UAM_ConfirmMail_TimeOut'],
194      $_POST['UAM_ConfirmMail_Delay'],
195      $_POST['UAM_ConfirmMail_ReMail_Txt1'],
196      $_POST['UAM_ConfirmMail_Remail'],
197      $_POST['UAM_ConfirmMail_ReMail_Txt2'],
198      $_POST['UAM_ConfirmMail_Custom_Txt1'],
199      $_POST['UAM_ConfirmMail_Custom_Txt2']);
200
201    $conf['UserAdvManager_ConfirmMail'] = serialize($newconf_UAM_ConfirmMail);
202   
203          $query = '
204      UPDATE '.CONFIG_TABLE.'
205                        SET value="'.addslashes($conf['UserAdvManager_ConfirmMail']).'"
206                        WHERE param="UserAdvManager_ConfirmMail"
207                        LIMIT 1
208                ;';
209
210                pwg_query($query);
211
212                array_push($page['infos'], l10n('UAM_save_config'));
213  }
214
215
216  //Testing password enforcement
217  if (isset($_POST['PasswordTest']) and isset($_POST['UAM_Password_Test']) and !empty($_POST['UAM_Password_Test']))
218  {
219    $UAM_Password_Test_Score = testpassword($_POST['UAM_Password_Test']);
220  }
221  else if (isset($_POST['PasswordTest']) and empty($_POST['UAM_Password_Test']))
222  {
223    array_push($page['errors'], l10n('reg_err_login3'));
224  }
225
226  $conf_UAM = unserialize($conf['UserAdvManager']);
227
228  //Group setting for unvalidated, validated users and downgrade group
229  $groups[-1] = '---------';
230  $No_Valid = -1;
231  $Valid = -1;
232  $Downgrade = -1;
233       
234  //Check groups list in database
235  $query = '
236SELECT id, name
237FROM '.GROUPS_TABLE.'
238ORDER BY name ASC
239;';
240       
241  $result = pwg_query($query);
242       
243  while ($row = pwg_db_fetch_assoc($result))
244  {
245    $groups[$row['id']] = $row['name'];
246    //configuration value for unvalidated users
247    if (isset($conf_UAM[2]) and $conf_UAM[2] == $row['id'])
248    {
249                $No_Valid = $row['id'];
250                }
251    //configuration value for validated users
252    if (isset($conf_UAM[3]) and $conf_UAM[3] == $row['id'])
253                {
254                $Valid = $row['id'];
255                }
256    //configuration value for downgrade users
257    if (isset($conf_UAM[26]) and $conf_UAM[26] == $row['id'])
258                {
259                $Downgrade = $row['id'];
260                }
261  }
262       
263  //Template initialization for unvalidated users group
264  $template->assign(
265    'No_Confirm_Group',
266        array(
267                'group_options'=> $groups,
268                'group_selected' => $No_Valid
269                        )
270                );
271  //Template initialization for validated users group
272  $template->assign(
273    'Validated_Group',
274                array(
275      'group_options'=> $groups,
276      'group_selected' => $Valid
277                        )
278        );
279  //Template initialization for downgrade group
280  $template->assign(
281    'Downgrade_Group',
282                array(
283      'group_options'=> $groups,
284      'group_selected' => $Downgrade
285                        )
286        );
287       
288  //Status setting for unvalidated, validated users and downgrade status
289  $status_options[-1] = '------------';
290  $No_Valid_Status = -1;
291  $Valid_Status = -1;
292  $Downgrade_Status = -1;
293       
294  //Get unvalidate status values
295  foreach (get_enums(USER_INFOS_TABLE, 'status') as $status)
296  {
297          $status_options[$status] = l10n('user_status_'.$status);
298          if (isset($conf_UAM[8]) and $conf_UAM[8] == $status)
299          {
300            $No_Valid_Status = $status;
301          }
302         
303      //Template initialization for unvalidated users status
304      $template->assign(
305        'No_Confirm_Status',
306        array(
307                                        'Status_options' => $status_options,
308                                'Status_selected' => $No_Valid_Status
309                                        )
310                        );
311  }
312 
313  //Get validate status values
314  foreach (get_enums(USER_INFOS_TABLE, 'status') as $status)
315  {
316          $status_options[$status] = l10n('user_status_'.$status);
317          if (isset($conf_UAM[4]) and $conf_UAM[4] == $status)
318                {
319                  $Valid_Status = $status;
320                }
321               
322      //Template initialization for validated users status
323      $template->assign(
324            'Confirm_Status',
325            array(
326                    'Status_options' => $status_options,
327                    'Status_selected' => $Valid_Status
328                    )
329            );
330        }
331
332  //Get downgrade status values
333  foreach (get_enums(USER_INFOS_TABLE, 'status') as $status)
334  {
335          $status_options[$status] = l10n('user_status_'.$status);
336          if (isset($conf_UAM[27]) and $conf_UAM[27] == $status)
337                {
338                  $Downgrade_Status = $status;
339                }
340               
341      //Template initialization for validated users status
342      $template->assign(
343            'Downgrade_Status',
344            array(
345                    'Status_options' => $status_options,
346                    'Status_selected' => $Downgrade_Status
347                    )
348            );
349        }
350
351  //Save last opened paragraph in configuration tab
352  $nb_para=(isset($_POST["nb_para"])) ? $_POST["nb_para"]:"";
353  $nb_para2=(isset($_POST["nb_para2"])) ? $_POST["nb_para2"]:"";
354
355  $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']);
356
357  // Template initialization for forms and data
358  $template->assign(
359    array(
360    'nb_para'                        => $nb_para,
361    'nb_para2'                       => $nb_para2,
362    'UAM_VERSION'                    => $version,
363    'UAM_PATH'                       => UAM_PATH,
364                'UAM_MAIL_INFO_TRUE'             => $conf_UAM[0]=='true' ?  'checked="checked"' : '' ,
365                'UAM_MAIL_INFO_FALSE'            => $conf_UAM[0]=='false' ?  'checked="checked"' : '' ,
366                'UAM_MAILINFO_TEXT'              => $conf_UAM[9],
367                'UAM_USERNAME_CHAR_TRUE'         => $conf_UAM[6]=='true' ?  'checked="checked"' : '' ,
368                'UAM_USERNAME_CHAR_FALSE'        => $conf_UAM[6]=='false' ?  'checked="checked"' : '' ,
369                'UAM_USERNAME_CHAR_LIST'         => $conf_UAM[7],
370                'UAM_CONFIRM_MAIL_TRUE'          => $conf_UAM[1]=='true' ?  'checked="checked"' : '' ,
371                'UAM_CONFIRM_MAIL_FALSE'         => $conf_UAM[1]=='false' ?  'checked="checked"' : '' ,
372    'UAM_CONFIRM_MAIL_LOCAL'         => $conf_UAM[1]=='local' ?  'checked="checked"' : '' ,
373                'UAM_CONFIRMMAIL_TEXT'           => $conf_UAM[10],
374                'UAM_No_Confirm_Group'           => $conf_UAM[2],
375                'UAM_Validated_Group'            => $conf_UAM[3],
376                'UAM_No_Confirm_Status'          => $conf_UAM[8],
377                'UAM_Validated_Status'           => $conf_UAM[4],
378                'UAM_NO_COMMENT_ANO_TRUE'        => $conf_UAM[5]=='true' ?  'checked="checked"' : '' ,
379                'UAM_NO_COMMENT_ANO_FALSE'       => $conf_UAM[5]=='false' ?  'checked="checked"' : '' ,
380                'UAM_MAILEXCLUSION_TRUE'         => $conf_UAM[11]=='true' ?  'checked="checked"' : '' ,
381                'UAM_MAILEXCLUSION_FALSE'        => $conf_UAM[11]=='false' ?  'checked="checked"' : '' ,
382                'UAM_MAILEXCLUSION_LIST'         => $conf_UAM[12],
383                'UAM_PASSWORDENF_TRUE'           => $conf_UAM[13]=='true' ?  'checked="checked"' : '' ,
384                'UAM_PASSWORDENF_FALSE'          => $conf_UAM[13]=='false' ?  'checked="checked"' : '' ,
385                'UAM_PASSWORD_SCORE'             => $conf_UAM[14],
386    'UAM_ADMINPASSWENF_TRUE'         => $conf_UAM[15]=='true' ?  'checked="checked"' : '' ,
387                'UAM_ADMINPASSWENF_FALSE'        => $conf_UAM[15]=='false' ?  'checked="checked"' : '' ,
388    'UAM_GHOSTRACKER_TRUE'           => $conf_UAM[16]=='true' ?  'checked="checked"' : '' ,
389                'UAM_GHOSTRACKER_FALSE'          => $conf_UAM[16]=='false' ?  'checked="checked"' : '' ,
390    'UAM_GHOSTRACKER_DAYLIMIT'       => $conf_UAM[17],
391    'UAM_GHOSTRACKER_REMINDERTEXT'   => $conf_UAM[18],
392    'UAM_ADDLASTVISIT_TRUE'          => $conf_UAM[19]=='true' ?  'checked="checked"' : '' ,
393    'UAM_ADDLASTVISIT_FALSE'         => $conf_UAM[19]=='false' ?  'checked="checked"' : '' ,
394    'UAM_ADMINCONFMAIL_TRUE'         => $conf_UAM[20]=='true' ?  'checked="checked"' : '' ,
395    'UAM_ADMINCONFMAIL_FALSE'        => $conf_UAM[20]=='false' ?  'checked="checked"' : '' ,
396    'UAM_REDIRTOPROFILE_TRUE'        => $conf_UAM[21]=='true' ?  'checked="checked"' : '' ,
397    'UAM_REDIRTOPROFILE_FALSE'       => $conf_UAM[21]=='false' ?  'checked="checked"' : '' ,
398    'UAM_GTAUTO_TRUE'                => $conf_UAM[22]=='true' ?  'checked="checked"' : '' ,
399    'UAM_GTAUTO_FALSE'               => $conf_UAM[22]=='false' ?  'checked="checked"' : '' ,
400    'UAM_GTAUTOMAIL_TRUE'            => $conf_UAM[23]=='true' ?  'checked="checked"' : '' ,
401    'UAM_GTAUTOMAIL_FALSE'           => $conf_UAM[23]=='false' ?  'checked="checked"' : '' ,
402    'UAM_GTAUTODEL_TEXT'             => $conf_UAM[24],
403    'UAM_GTAUTOMAILTEXT'             => $conf_UAM[25],
404                'UAM_Downgrade_Group'            => $conf_UAM[26],
405                'UAM_Downgrade_Status'           => $conf_UAM[27],
406    'UAM_ADMINVALIDATIONMAIL_TEXT'   => $conf_UAM[28],
407                'UAM_PASSWORD_TEST_SCORE'        => $UAM_Password_Test_Score,
408    'UAM_ERROR_REPORTS4'             => $UAM_Exclusionlist_Error,
409                'UAM_CONFIRMMAIL_TIMEOUT_TRUE'   => $conf_UAM_ConfirmMail[0]=='true' ?  'checked="checked"' : '' ,
410                'UAM_CONFIRMMAIL_TIMEOUT_FALSE'  => $conf_UAM_ConfirmMail[0]=='false' ?  'checked="checked"' : '' ,
411                'UAM_CONFIRMMAIL_DELAY'                                  => $conf_UAM_ConfirmMail[1],
412    'UAM_CONFIRMMAIL_REMAIL_TRUE'                => $conf_UAM_ConfirmMail[3]=='true' ? 'checked="checked"' : '',
413    'UAM_CONFIRMMAIL_REMAIL_FALSE'       => $conf_UAM_ConfirmMail[3]=='false' ? 'checked="checked"' : '',
414    'UAM_CONFIRMMAIL_REMAIL_TXT1'                => $conf_UAM_ConfirmMail[2],
415    'UAM_CONFIRMMAIL_REMAIL_TXT2'                => $conf_UAM_ConfirmMail[4],
416    'UAM_CONFIRMMAIL_CUSTOM_TXT1'                => $conf_UAM_ConfirmMail[5],
417    'UAM_CONFIRMMAIL_CUSTOM_TXT2'                => $conf_UAM_ConfirmMail[6],
418    )
419  );
420
421  if (isset($_POST['audit']))
422        {
423                $msg_error1 = '';
424               
425    //Username without forbidden keys
426    if ( isset($conf_UAM[6]) and $conf_UAM[6] == 'true' )
427          {
428                        $query = "
429SELECT ".$conf['user_fields']['username'].", ".$conf['user_fields']['email']."
430  FROM ".USERS_TABLE."
431;";
432                         
433                        $result = pwg_query($query);
434                       
435                        while($row = pwg_db_fetch_assoc($result))
436                        {
437                                if (!ValidateUsername(stripslashes($row['username'])))
438                                        $msg_error1 .= (($msg_error1 <> '') ? '<br>' : '') . l10n('Err_audit_username_char').stripslashes($row['username']);
439                        }
440                }
441
442                $msg_error2 = '';
443               
444    //Email without forbidden domain
445    if ( isset($conf_UAM[11]) and $conf_UAM[11] == 'true' )
446          {
447                        $query = "
448SELECT ".$conf['user_fields']['username'].", ".$conf['user_fields']['email']."
449  FROM ".USERS_TABLE."
450;";
451                         
452                  $result = pwg_query($query);
453                       
454                  while($row = pwg_db_fetch_assoc($result))
455                  {
456                          $conf_MailExclusion = preg_split("/[\s,]+/",$conf_UAM[12]);
457                          for ($i = 0 ; $i < count($conf_MailExclusion) ; $i++)
458                          {
459                                        $pattern = '/'.$conf_MailExclusion[$i].'/';
460                                  if (preg_match($pattern, $row['mail_address']))
461                                  {
462                                                $msg_error2 .=  (($msg_error2 <> '') ? '<br>' : '') . l10n('Err_audit_email_forbidden').stripslashes($row['username']).' ('.$row['mail_address'].')';
463                                        }
464                                }
465                        }
466                }
467               
468    if ($msg_error1 <> '')
469                        $errors[] = $msg_error1.'<br><br>';
470               
471                if ($msg_error2 <> '')
472                        $errors[] = $msg_error2.'<br><br>';
473               
474                if ($msg_error1 <> '' or $msg_error2 <> '')
475                array_push($page['errors'], l10n('Err_audit_advise'));
476                else
477        array_push($page['infos'], l10n('UAM_audit_ok'));
478        }
479
480
481// +-----------------------------------------------------------------------+
482// |                             errors display                            |
483// +-----------------------------------------------------------------------+
484  if (isset ($errors) and count($errors) != 0)
485  {
486          $template->assign('errors',array());
487          foreach ($errors as $error)
488          {
489                  array_push($page['errors'], $error);
490                }
491        } 
492
493// +-----------------------------------------------------------------------+
494// |                           templates display                           |
495// +-----------------------------------------------------------------------+
496  $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/global.tpl');
497  $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
498
499  break;
500
501
502// *************************************************************************
503// +-----------------------------------------------------------------------+
504// |                           Users list page                             |
505// +-----------------------------------------------------------------------+
506// *************************************************************************
507  case 'userlist':
508 
509  $conf_UAM = unserialize($conf['UserAdvManager']);
510 
511  if (isset($conf_UAM[19]) and $conf_UAM[19]=='true')
512  {
513// +-----------------------------------------------------------------------+
514// |                           initialization                              |
515// +-----------------------------------------------------------------------+
516
517                if (!defined('PHPWG_ROOT_PATH'))
518    {
519        die('Hacking attempt!');
520    }
521         
522    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
523
524// +-----------------------------------------------------------------------+
525// | Check Access and exit when user status is not ok                      |
526// +-----------------------------------------------------------------------+
527                check_status(ACCESS_ADMINISTRATOR);
528
529
530// +-----------------------------------------------------------------------+
531// |                               user list                               |
532// +-----------------------------------------------------------------------+
533
534                $page['filtered_users'] = get_user_list();
535
536// +-----------------------------------------------------------------------+
537// |                               user list                               |
538// +-----------------------------------------------------------------------+
539
540    $visible_user_list = array();
541    foreach ($page['filtered_users'] as $num => $local_user)
542    {
543      $visible_user_list[] = $local_user;
544                }
545
546                foreach ($visible_user_list as $local_user)
547    {
548      // dates formating and compare
549      $today = date("d-m-Y"); // Get today's date
550      list($day, $month, $year) = explode('-', $today); // explode date of today                                                 
551      $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp
552               
553      list($regdate, $regtime) = explode(' ', $local_user['lastvisit']); // Explode date and time from registration date
554      list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date
555      $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp
556                       
557      $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps       
558      $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days
559     
560      if (isset($conf_UAM[16]) and $conf_UAM[16]=='true' and $conf_UAM[17] <> '')
561      {
562        if ($deltadays <= ($conf_UAM[17]/2))
563        {
564          $display = 'green';
565        }
566       
567        if (($deltadays > ($conf_UAM[17]/2)) and ($deltadays < $conf_UAM[17]))
568        {
569          $display = 'orange';
570        }
571       
572        if ($deltadays >= $conf_UAM[17])
573        {
574          $display = 'red';
575        }
576      }
577      else $display = '';
578
579                $template->append(
580                'users',
581        array(
582                'ID'          => $local_user['id'],
583                'USERNAME'    => stripslashes($local_user['username']),
584                                        'EMAIL'       => get_email_address_as_display_text($local_user['email']),
585          'LASTVISIT'   => $local_user['lastvisit'],
586          'DAYS'        => $deltadays,
587          'DISPLAY'     => $display,
588                                )
589                        );
590                }
591    //Plugin version inserted
592    $template->assign(
593      array(
594        'UAM_VERSION'  => $version,
595        'UAM_PATH'     => UAM_PATH,
596      )
597    );   
598// +-----------------------------------------------------------------------+
599// |                             errors display                            |
600// +-----------------------------------------------------------------------+
601                if ( isset ($errors) and count($errors) != 0)
602                {
603                $template->assign('errors',array());
604                        foreach ($errors as $error)
605                {
606                                array_push($page['errors'], $error);
607                }
608                } 
609
610// +-----------------------------------------------------------------------+
611// |                           templates display                           |
612// +-----------------------------------------------------------------------+
613                $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/userlist.tpl');
614    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');         
615  }
616  else
617  {
618                array_push($page['errors'], l10n('Err_Userlist_Settings'));
619  }
620  break;
621
622
623// *************************************************************************
624// +-----------------------------------------------------------------------+
625// |                           Users manager page                          |
626// +-----------------------------------------------------------------------+
627// *************************************************************************
628  case 'usermanager':
629
630  $conf_UAM = unserialize($conf['UserAdvManager']);
631
632  $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']);
633       
634  if (isset($conf_UAM[1]) and ($conf_UAM[1]=='true' or $conf_UAM[1]=='local') and ((isset($conf_UAM[2]) and $conf_UAM[2] <> '-1') or (isset($conf_UAM[8]) and $conf_UAM[8] <> '-1')))
635  {
636// +-----------------------------------------------------------------------+
637// |                           initialization                              |
638// +-----------------------------------------------------------------------+
639
640                if (!defined('PHPWG_ROOT_PATH'))
641    {
642        die('Hacking attempt!');
643    }
644
645    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
646
647// +-----------------------------------------------------------------------+
648// | Check Access and exit when user status is not ok                      |
649// +-----------------------------------------------------------------------+
650                check_status(ACCESS_ADMINISTRATOR);
651
652// +-----------------------------------------------------------------------+
653// |                               user list                               |
654// +-----------------------------------------------------------------------+
655
656                $page['filtered_users'] = get_unvalid_user_list();
657
658// +-----------------------------------------------------------------------+
659// |                            selected users                             |
660// +-----------------------------------------------------------------------+
661                if (isset($_POST['Del_Selected']))
662                {
663                $collection = array();
664
665                        switch ($_POST['target'])
666        {
667                case 'all' :
668        {
669                foreach($page['filtered_users'] as $local_user)
670                {
671                        array_push($collection, $local_user['id']);
672                }
673                                        break;
674                                }
675        case 'selection' :
676        {
677                if (isset($_POST['selection']))
678                {
679                        $collection = $_POST['selection'];
680                }
681                break;
682        }
683                        }
684
685                        if (count($collection) == 0)
686        {
687                array_push($page['errors'], l10n('Select at least one user'));
688                }
689                }
690
691// +-----------------------------------------------------------------------+
692// |                             delete users                              |
693// +-----------------------------------------------------------------------+
694                if (isset($_POST['Del_Selected']) and count($collection) > 0)
695        {
696                if (in_array($conf['guest_id'], $collection))
697                {
698                array_push($page['errors'], l10n('Guest cannot be deleted'));
699        }
700        if (($conf['guest_id'] != $conf['default_user_id']) and
701                in_array($conf['default_user_id'], $collection))
702        {
703                array_push($page['errors'], l10n('Default user cannot be deleted'));
704        }
705        if (in_array($conf['webmaster_id'], $collection))
706        {
707                array_push($page['errors'], l10n('Webmaster cannot be deleted'));
708        }
709        if (in_array($user['id'], $collection))
710        {
711                array_push($page['errors'], l10n('You cannot delete your account'));
712        }
713
714                        if (count($page['errors']) == 0)
715        {
716                foreach ($collection as $user_id)
717        {
718                delete_user($user_id);
719        }
720                array_push(
721                $page['infos'],
722                l10n_dec(
723                '%d user deleted', '%d users deleted',
724                count($collection)
725                )
726        );
727
728        foreach ($page['filtered_users'] as $filter_key => $filter_user)
729        {
730                if (in_array($filter_user['id'], $collection))
731                {
732                        unset($page['filtered_users'][$filter_key]);
733                }
734                }
735                        }
736                }
737
738// +-----------------------------------------------------------------------+
739// |                 Resend new validation key to users                    |
740// +-----------------------------------------------------------------------+
741// +-----------------------------------------------------------------------+
742// |                            selected users                             |
743// +-----------------------------------------------------------------------+
744                if (isset($_POST['Mail_With_Key']))
745                {
746                $collection = array();
747
748                        switch ($_POST['target'])
749        {
750                case 'all' :
751        {
752                foreach($page['filtered_users'] as $local_user)
753                {
754                        array_push($collection, $local_user['id']);
755                }
756                break;
757                                }
758        case 'selection' :
759        {
760                if (isset($_POST['selection']))
761                {
762                        $collection = $_POST['selection'];
763                }
764                break;
765        }
766                        }
767
768        if (count($collection) == 0)
769        {
770                array_push($page['errors'], l10n('Select at least one user'));
771        }
772                }
773// +-----------------------------------------------------------------------+
774// |                 Resend new validation key to users                    |
775// +-----------------------------------------------------------------------+
776                if (isset($_POST['Mail_With_Key']) and count($collection) > 0)
777                {
778                        if (in_array($conf['guest_id'], $collection))
779                {
780                array_push($page['errors'], l10n('No_validation_for_Guest'));
781        }
782        if (($conf['guest_id'] != $conf['default_user_id']) and
783                in_array($conf['default_user_id'], $collection))
784        {
785                array_push($page['errors'], l10n('No_validation_for_default_user'));
786        }
787                if (in_array($conf['webmaster_id'], $collection))
788        {
789                array_push($page['errors'], l10n('No_validation_for_Webmaster'));
790        }
791        if (in_array($user['id'], $collection))
792        {
793                array_push($page['errors'], l10n('No_validation_for_your_account'));
794        }
795
796        if (count($page['errors']) == 0)
797        {
798                foreach ($collection as $user_id)
799        {       
800                $typemail = 1;
801                                  $query = "
802SELECT id, username, mail_address
803  FROM ".USERS_TABLE."
804WHERE id = '".$user_id."'
805;";
806                                        $data = pwg_db_fetch_assoc(pwg_query($query));
807                               
808                ResendMail2User($typemail,$user_id,stripslashes($data['username']),$data['mail_address'],true);
809        }
810        array_push(
811                $page['infos'],
812                l10n_dec(
813                        '%d_Mail_With_Key', '%d_Mails_With_Key',
814                count($collection)
815                )
816        );
817       
818                                $page['filtered_users'] = get_unvalid_user_list();
819                        }
820                }
821
822// +-----------------------------------------------------------------------+
823// |             Send reminder without new key to users                    |
824// +-----------------------------------------------------------------------+
825// +-----------------------------------------------------------------------+
826// |                            selected users                             |
827// +-----------------------------------------------------------------------+
828                if (isset($_POST['Mail_Without_Key']))
829                {
830                $collection = array();
831
832                        switch ($_POST['target'])
833        {
834                case 'all' :
835        {
836                foreach($page['filtered_users'] as $local_user)
837                {
838                        array_push($collection, $local_user['id']);
839                }
840                break;
841                                }
842        case 'selection' :
843        {
844                if (isset($_POST['selection']))
845                {
846                        $collection = $_POST['selection'];
847                }
848                break;
849        }
850                        }
851
852        if (count($collection) == 0)
853        {
854                array_push($page['errors'], l10n('Select at least one user'));
855        }
856                }
857// +-----------------------------------------------------------------------+
858// |             Send reminder without new key to users                    |
859// +-----------------------------------------------------------------------+
860                if (isset($_POST['Mail_Without_Key']) and count($collection) > 0)
861                {
862                        if (in_array($conf['guest_id'], $collection))
863                {
864                array_push($page['errors'], l10n('No_validation_for_Guest'));
865        }
866        if (($conf['guest_id'] != $conf['default_user_id']) and
867                in_array($conf['default_user_id'], $collection))
868        {
869                array_push($page['errors'], l10n('No_validation_for_default_user'));
870        }
871                if (in_array($conf['webmaster_id'], $collection))
872        {
873                array_push($page['errors'], l10n('No_validation_for_Webmaster'));
874        }
875        if (in_array($user['id'], $collection))
876        {
877                array_push($page['errors'], l10n('No_validation_for_your_account'));
878        }
879
880        if (count($page['errors']) == 0)
881        {
882                foreach ($collection as $user_id)
883        {
884                $typemail = 2;
885                                  $query = "
886SELECT id, username, mail_address
887  FROM ".USERS_TABLE."
888WHERE id = '".$user_id."'
889;";
890                                       
891                                        $data = pwg_db_fetch_assoc(pwg_query($query));
892                               
893                ResendMail2User($typemail,$user_id,stripslashes($data['username']),$data['mail_address'],false);                               
894        }
895        array_push(
896                $page['infos'],
897                l10n_dec(
898                        '%d_Reminder_Sent', '%d_Reminders_Sent',
899                count($collection)
900                )
901        );
902       
903                                $page['filtered_users'] = get_unvalid_user_list();
904                        }
905                }
906
907// +-----------------------------------------------------------------------+
908// |                                                                            Force validation                                                         |
909// +-----------------------------------------------------------------------+
910// +-----------------------------------------------------------------------+
911// |                            selected users                             |
912// +-----------------------------------------------------------------------+
913                if (isset($_POST['Force_Validation']))
914                {
915                $collection = array();
916
917                        switch ($_POST['target'])
918        {
919                case 'all' :
920        {
921                foreach($page['filtered_users'] as $local_user)
922                {
923                        array_push($collection, $local_user['id']);
924                }
925                break;
926                                }
927        case 'selection' :
928        {
929                if (isset($_POST['selection']))
930                {
931                        $collection = $_POST['selection'];
932                }
933                break;
934        }
935                        }
936
937        if (count($collection) == 0)
938        {
939                array_push($page['errors'], l10n('Select at least one user'));
940        }
941                }
942// +-----------------------------------------------------------------------+
943// |                                                                            Force validation                                                         |
944// +-----------------------------------------------------------------------+
945                if (isset($_POST['Force_Validation']) and count($collection) > 0)
946                {
947                        if (in_array($conf['guest_id'], $collection))
948                {
949                array_push($page['errors'], l10n('No_validation_for_Guest'));
950        }
951        if (($conf['guest_id'] != $conf['default_user_id']) and
952                in_array($conf['default_user_id'], $collection))
953        {
954                array_push($page['errors'], l10n('No_validation_for_default_user'));
955        }
956                if (in_array($conf['webmaster_id'], $collection))
957        {
958                array_push($page['errors'], l10n('No_validation_for_Webmaster'));
959        }
960        if (in_array($user['id'], $collection))
961        {
962                array_push($page['errors'], l10n('No_validation_for_your_account'));
963        }
964
965        if (count($page['errors']) == 0)
966        {
967                foreach ($collection as $user_id)
968        {
969          ForceValidation($user_id);
970          validation_mail($user_id);
971        }
972        array_push(
973                $page['infos'],
974                l10n_dec(
975                        '%d_Validated_User', '%d_Validated_Users',
976                count($collection)
977                )
978        );
979
980                                $page['filtered_users'] = get_unvalid_user_list();
981                        }
982                }
983               
984
985// +-----------------------------------------------------------------------+
986// |                              groups list                              |
987// +-----------------------------------------------------------------------+
988
989                $groups[-1] = '------------';
990
991    $query = '
992SELECT id, name
993  FROM '.GROUPS_TABLE.'
994ORDER BY name ASC
995;';
996
997                $result = pwg_query($query);
998         
999    while ($row = pwg_db_fetch_assoc($result))
1000    {
1001      $groups[$row['id']] = $row['name'];
1002    }
1003
1004// +-----------------------------------------------------------------------+
1005// |                               user list                               |
1006// +-----------------------------------------------------------------------+
1007
1008                $profile_url = get_root_url().'admin.php?page=profile&amp;user_id=';
1009                $perm_url = get_root_url().'admin.php?page=user_perm&amp;user_id=';
1010
1011    $visible_user_list = array();
1012    foreach ($page['filtered_users'] as $num => $local_user)
1013    {
1014      $visible_user_list[] = $local_user;
1015                }
1016
1017                foreach ($visible_user_list as $local_user)
1018    {
1019      $groups_string = preg_replace(
1020        '/(\d+)/e',
1021        "\$groups['$1']",
1022        implode(
1023                ', ',
1024            $local_user['groups']
1025         )
1026                        );
1027
1028      $query = '
1029SELECT user_id, reminder
1030FROM '.USER_CONFIRM_MAIL_TABLE.'
1031WHERE user_id = '.$local_user['id'].'
1032;';
1033      $result = pwg_query($query);
1034     
1035      $row = pwg_db_fetch_assoc($result);
1036   
1037      if (isset($row['reminder']) and $row['reminder'] == 'true')
1038      {
1039        $reminder = l10n('Reminder_Sent_OK');
1040      }
1041      else if ((isset($row['reminder']) and $row['reminder'] == 'false') or !isset($row['reminder']))
1042      {
1043        $reminder = l10n('Reminder_Sent_NOK');
1044      }
1045
1046
1047                if (isset($_POST['pref_submit'])
1048                and isset($_POST['selection'])
1049        and in_array($local_user['id'], $_POST['selection']))
1050                {
1051                                $checked = 'checked="checked"';
1052                }
1053                        else
1054        {
1055                $checked = '';
1056        }
1057
1058        $properties = array();
1059        if ( $local_user['level'] != 0 )
1060                        {
1061                $properties[] = l10n( sprintf('Level %d', $local_user['level']) );
1062                        }
1063        $properties[] =
1064                (isset($local_user['enabled_high']) and ($local_user['enabled_high'] == 'true'))
1065                ? l10n('is_high_enabled') : l10n('is_high_disabled');
1066
1067                        $expiration = expiration($local_user['id']);
1068     
1069                $template->append(
1070                'users',
1071        array(
1072                'ID'               => $local_user['id'],
1073                'CHECKED'          => $checked,
1074                'U_PROFILE'        => $profile_url.$local_user['id'],
1075                'U_PERM'           => $perm_url.$local_user['id'],
1076                'USERNAME'         => stripslashes($local_user['username'])
1077                                  .($local_user['id'] == $conf['guest_id']
1078                                  ? '<BR>['.l10n('is_the_guest').']' : '')
1079                                  .($local_user['id'] == $conf['default_user_id']
1080                                  ? '<BR>['.l10n('is_the_default').']' : ''),
1081                                  'STATUS' => l10n('user_status_'
1082                                  .$local_user['status']),
1083                                        'EMAIL'            => get_email_address_as_display_text($local_user['email']),
1084                'GROUPS'           => $groups_string,
1085                'REGISTRATION'     => $local_user['registration_date'],
1086          'REMINDER'         => $reminder,   
1087                'EXPIRATION'       => $expiration,
1088                                )
1089                        );
1090                }   
1091
1092    // Check if validation of register is made by admin or visitor
1093    // If visitor, $Confirm_Local is used to mask useless buttons
1094    $Confirm_Local = "";
1095   
1096    if ($conf_UAM[1] == 'local')
1097    {
1098      $Confirm_Local = $conf_UAM[1];
1099    }
1100    else
1101    {
1102      $Confirm_Local = "";
1103    } 
1104   
1105    //Plugin version inserted
1106    $template->assign(
1107      array(
1108        'CONFIRM_LOCAL'=> $Confirm_Local,
1109        'UAM_VERSION'  => $version,
1110        'UAM_PATH'     => UAM_PATH,
1111      )
1112    );
1113
1114// +-----------------------------------------------------------------------+
1115// |                             errors display                            |
1116// +-----------------------------------------------------------------------+
1117                if ( isset ($errors) and count($errors) != 0)
1118                {
1119                $template->assign('errors',array());
1120                        foreach ($errors as $error)
1121                {
1122                                array_push($page['errors'], $error);
1123                }
1124                } 
1125
1126// +-----------------------------------------------------------------------+
1127// |                           templates display                           |
1128// +-----------------------------------------------------------------------+
1129                $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/usermanager.tpl');
1130    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');         
1131        }
1132  else
1133  {
1134                array_push($page['errors'], l10n('Err_UserManager_Settings'));
1135  }
1136  break;
1137
1138
1139// *************************************************************************
1140// +-----------------------------------------------------------------------+
1141// |                           Ghost Tracker page                          |
1142// +-----------------------------------------------------------------------+
1143// *************************************************************************
1144  case 'ghosttracker':
1145
1146  $conf_UAM = unserialize($conf['UserAdvManager']);
1147       
1148  if (isset($conf_UAM[16]) and $conf_UAM[16]=='true')
1149  {
1150// +-----------------------------------------------------------------------+
1151// |                           initialization                              |
1152// +-----------------------------------------------------------------------+
1153
1154                if (!defined('PHPWG_ROOT_PATH'))
1155    {
1156        die('Hacking attempt!');
1157    }
1158         
1159    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
1160
1161// +-----------------------------------------------------------------------+
1162// | Check Access and exit when user status is not ok                      |
1163// +-----------------------------------------------------------------------+
1164                check_status(ACCESS_ADMINISTRATOR);
1165
1166// +-----------------------------------------------------------------------+
1167// |                               user list                               |
1168// +-----------------------------------------------------------------------+
1169
1170                $page['filtered_users'] = get_ghost_user_list();
1171
1172// +-----------------------------------------------------------------------+
1173// |                            selected users                             |
1174// +-----------------------------------------------------------------------+
1175                if (isset($_POST['Del_Selected']))
1176                {
1177                $collection = array();
1178
1179                        switch ($_POST['target'])
1180        {
1181                case 'all' :
1182        {
1183                foreach($page['filtered_users'] as $local_user)
1184                {
1185                        array_push($collection, $local_user['id']);
1186                }
1187                                        break;
1188                                }
1189        case 'selection' :
1190        {
1191                if (isset($_POST['selection']))
1192                {
1193                        $collection = $_POST['selection'];
1194                }
1195                break;
1196        }
1197                        }
1198
1199                        if (count($collection) == 0)
1200        {
1201                array_push($page['errors'], l10n('Select at least one user'));
1202                }
1203                }
1204
1205// +-----------------------------------------------------------------------+
1206// |                             delete users                              |
1207// +-----------------------------------------------------------------------+
1208                if (isset($_POST['Del_Selected']) and count($collection) > 0)
1209        {
1210                if (in_array($conf['guest_id'], $collection))
1211                {
1212                array_push($page['errors'], l10n('Guest cannot be deleted'));
1213        }
1214        if (($conf['guest_id'] != $conf['default_user_id']) and
1215                in_array($conf['default_user_id'], $collection))
1216        {
1217                array_push($page['errors'], l10n('Default user cannot be deleted'));
1218        }
1219        if (in_array($conf['webmaster_id'], $collection))
1220        {
1221                array_push($page['errors'], l10n('Webmaster cannot be deleted'));
1222        }
1223        if (in_array($user['id'], $collection))
1224        {
1225                array_push($page['errors'], l10n('You cannot delete your account'));
1226        }
1227
1228                        if (count($page['errors']) == 0)
1229        {
1230                foreach ($collection as $user_id)
1231        {
1232                delete_user($user_id);
1233        }
1234                array_push(
1235                $page['infos'],
1236                l10n_dec(
1237                '%d user deleted', '%d users deleted',
1238                count($collection)
1239                )
1240        );
1241
1242        foreach ($page['filtered_users'] as $filter_key => $filter_user)
1243        {
1244                if (in_array($filter_user['id'], $collection))
1245                {
1246                        unset($page['filtered_users'][$filter_key]);
1247                }
1248                }
1249                        }
1250                }
1251
1252// +-----------------------------------------------------------------------+
1253// |                          Send ghost reminder                          |
1254// +-----------------------------------------------------------------------+
1255// +-----------------------------------------------------------------------+
1256// |                            selected users                             |
1257// +-----------------------------------------------------------------------+
1258                if (isset($_POST['Reminder_Email']))
1259                {
1260                $collection = array();
1261
1262                        switch ($_POST['target'])
1263        {
1264                case 'all' :
1265        {
1266                foreach($page['filtered_users'] as $local_user)
1267                {
1268                        array_push($collection, $local_user['id']);
1269                }
1270                break;
1271                                }
1272        case 'selection' :
1273        {
1274                if (isset($_POST['selection']))
1275                {
1276                        $collection = $_POST['selection'];
1277                }
1278                break;
1279        }
1280                        }
1281
1282        if (count($collection) == 0)
1283        {
1284                array_push($page['errors'], l10n('Select at least one user'));
1285        }
1286                }
1287// +-----------------------------------------------------------------------+
1288// |                         Send ghost reminder                           |
1289// +-----------------------------------------------------------------------+
1290                if (isset($_POST['Reminder_Email']) and count($collection) > 0)
1291                {
1292                        if (in_array($conf['guest_id'], $collection))
1293                {
1294                array_push($page['errors'], l10n('No_reminder_for_Guest'));
1295        }
1296        if (($conf['guest_id'] != $conf['default_user_id']) and
1297                in_array($conf['default_user_id'], $collection))
1298        {
1299                array_push($page['errors'], l10n('No_reminder_for_default_user'));
1300        }
1301                if (in_array($conf['webmaster_id'], $collection))
1302        {
1303                array_push($page['errors'], l10n('No_reminder_for_Webmaster'));
1304        }
1305        if (in_array($user['id'], $collection))
1306        {
1307                array_push($page['errors'], l10n('No_reminder_for_your_account'));
1308        }
1309
1310        if (count($page['errors']) == 0)
1311        {
1312                foreach ($collection as $user_id)
1313        {
1314                                  $query = "
1315SELECT id, username, mail_address
1316  FROM ".USERS_TABLE."
1317WHERE id = '".$user_id."'
1318;";
1319                                       
1320                                        $data = pwg_db_fetch_assoc(pwg_query($query));
1321                               
1322                ghostreminder($user_id,stripslashes($data['username']),$data['mail_address']);                         
1323        }
1324        array_push(
1325                $page['infos'],
1326                l10n_dec(
1327                        '%d_Reminder_Sent', '%d_Reminders_Sent',
1328                count($collection)
1329                )
1330        );
1331       
1332                                $page['filtered_users'] = get_ghost_user_list();
1333                        }
1334                }
1335   
1336    if (isset($_POST['GhostTracker_Init']))
1337    {
1338      //Reset is only allowed for admins !
1339      if (is_admin())
1340      {
1341        $query1 = '
1342SELECT *
1343  FROM '.USER_LASTVISIT_TABLE.';';
1344
1345        $count = pwg_db_num_rows(pwg_query($query1));
1346
1347        if ($count <> 0)
1348        {
1349          $query = '
1350SELECT DISTINCT u.id,
1351                ui.status AS status
1352FROM '.USERS_TABLE.' AS u
1353  INNER JOIN '.USER_INFOS_TABLE.' AS ui
1354    ON u.id = ui.user_id
1355WHERE u.id NOT IN (SELECT user_id FROM '.USER_LASTVISIT_TABLE.')
1356  AND status != "webmaster"
1357  AND status != "guest"
1358  AND status != "admin"
1359ORDER BY u.id ASC
1360;';
1361
1362          $result = pwg_query($query);
1363         
1364          while ($row = pwg_db_fetch_assoc($result))
1365          {
1366            list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
1367           
1368            $query = "
1369INSERT INTO ".USER_LASTVISIT_TABLE." (user_id, lastvisit, reminder)
1370VALUES ('".$row['id']."','".$dbnow."','false')
1371;";
1372            pwg_query($query);
1373          }
1374        }
1375        else if ($count == 0)
1376        {
1377          $query = '
1378SELECT DISTINCT u.id,
1379                ui.status AS status
1380FROM '.USERS_TABLE.' AS u
1381  INNER JOIN '.USER_INFOS_TABLE.' AS ui
1382    ON u.id = ui.user_id
1383WHERE status != "webmaster"
1384  AND status != "guest"
1385  AND status != "admin"
1386ORDER BY u.id ASC
1387;';
1388
1389          $result = pwg_query($query);
1390         
1391          while($row = pwg_db_fetch_assoc($result))
1392          {
1393            list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
1394           
1395            $query = "
1396INSERT INTO ".USER_LASTVISIT_TABLE." (user_id, lastvisit, reminder)
1397VALUES ('".$row['id']."','".$dbnow."','false')
1398;";
1399            pwg_query($query);
1400          }
1401        }
1402       
1403        array_push($page['infos'], l10n('GhostTracker_Init_OK'));
1404      }
1405    }
1406
1407// +-----------------------------------------------------------------------+
1408// |                               user list                               |
1409// +-----------------------------------------------------------------------+
1410
1411    $visible_user_list = array();
1412    foreach ($page['filtered_users'] as $num => $local_user)
1413    {
1414      $visible_user_list[] = $local_user;
1415                }
1416
1417      //Plugin version inserted
1418      $template->assign(
1419        array(
1420          'UAM_VERSION'  => $version,
1421          'UAM_PATH'     => UAM_PATH,
1422        )
1423      );
1424
1425                foreach ($visible_user_list as $local_user)
1426    {
1427      $reminder = '';
1428   
1429      if (isset($local_user['reminder']) and $local_user['reminder'] == 'true')
1430      {
1431        $reminder = l10n('Reminder_Sent_OK');
1432      }
1433      else if (isset($local_user['reminder']) and $local_user['reminder'] == 'false')
1434      {
1435        $reminder = l10n('Reminder_Sent_NOK');
1436      }
1437   
1438      if (isset($_POST['pref_submit']) and isset($_POST['selection']) and in_array($local_user['id'], $_POST['selection']))
1439                {
1440                                $checked = 'checked="checked"';
1441                }
1442                        else
1443        {
1444                $checked = '';
1445        }
1446
1447      $template->append(
1448          'users',
1449        array(
1450                'ID'          => $local_user['id'],
1451                'CHECKED'     => $checked,
1452                'USERNAME'    => stripslashes($local_user['username']),
1453                                        'EMAIL'       => get_email_address_as_display_text($local_user['email']),
1454          'LASTVISIT'   => $local_user['lastvisit'],
1455          'REMINDER'    => $reminder,
1456                                )
1457                        );
1458                }
1459
1460// +-----------------------------------------------------------------------+
1461// |                             errors display                            |
1462// +-----------------------------------------------------------------------+
1463                if ( isset ($errors) and count($errors) != 0)
1464                {
1465                $template->assign('errors',array());
1466                        foreach ($errors as $error)
1467                {
1468                                array_push($page['errors'], $error);
1469                }
1470                } 
1471
1472// +-----------------------------------------------------------------------+
1473// |                           templates display                           |
1474// +-----------------------------------------------------------------------+
1475                $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/ghosttracker.tpl');
1476    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');         
1477        }
1478  else
1479  {
1480                array_push($page['errors'], l10n('Err_GhostTracker_Settings'));
1481  }
1482
1483  break;
1484}
1485?>
Note: See TracBrowser for help on using the repository browser.