source: extensions/NBC_UserAdvManager/trunk/admin/UserAdvManager_admin.php @ 4124

Last change on this file since 4124 was 4124, checked in by Eric, 14 years ago

[NBC_UserAdvManager] pre 2.12.0 :

  • Adding of password enforcement control function
  • Main code refactory
  • French language file refactory
  • Admin panel refactory
  • Property svn:eol-style set to LF
File size: 32.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
11//ini_set('error_reporting', E_ALL);
12//ini_set('display_errors', true);
13
14include_once (PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
15include_once (PHPWG_ROOT_PATH.'/include/constants.php');
16$my_base_url = get_admin_plugin_menu_link(__FILE__);
17
18load_language('plugin.lang', NBC_UserAdvManager_PATH);
19
20// +-----------------------------------------------------------------------+
21// |                            Tabssheet                                  |
22// +-----------------------------------------------------------------------+
23if (!isset($_GET['tab']))
24        $page['tab'] = 'global';
25else
26  $page['tab'] = $_GET['tab'];
27
28$tabsheet = new tabsheet();
29$tabsheet->add('global',
30               l10n('Tab_Global'),
31               $my_base_url.'&amp;tab=global');
32$tabsheet->add('confirmmail',
33               l10n('Tab_ConfirmMail'),
34               $my_base_url.'&amp;tab=confirmmail');
35$tabsheet->add('usermanager',
36               l10n('Tab_UserManager'),
37               $my_base_url.'&amp;tab=usermanager');
38$tabsheet->select($page['tab']);
39$tabsheet->assign();
40
41$page['global'] = array();
42$error = array();
43$UserAdvManager_Password_Test_Score = 0;
44
45// +-----------------------------------------------------------------------+
46// |                            Tabssheet select                           |
47// +-----------------------------------------------------------------------+
48
49switch ($page['tab'])
50{
51// *************************************************************************
52// +-----------------------------------------------------------------------+
53// |                           Global Config                               |
54// +-----------------------------------------------------------------------+
55// *************************************************************************
56  case 'global':
57       
58        if (isset($_POST['submit']) and !is_adviser() and isset($_POST['UserAdvManager_Mail_Info']) and isset($_POST['UserAdvManager_No_Casse']) and isset($_POST['UserAdvManager_Username_Char']) and isset($_POST['UserAdvManager_Confirm_Mail']) and isset($_POST['UserAdvManager_No_Comment_Anonymous']) and isset($_POST['UserAdvManager_Password_Enforced']) and isset($_POST['UserAdvManager_AdminPassword_Enforced']))
59  {
60                $_POST['UserAdvManager_MailInfo_Text'] = str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UserAdvManager_MailInfo_Text']));
61                $_POST['UserAdvManager_ConfirmMail_Text'] = str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UserAdvManager_ConfirmMail_Text']));
62               
63                $newconf_nbc_UserAdvManager = $_POST['UserAdvManager_Mail_Info'].';'.$_POST['UserAdvManager_No_Casse'].';'.$_POST['UserAdvManager_Confirm_Mail'].';'.(isset($_POST['UserAdvManager_No_Confirm_Group'])?$_POST['UserAdvManager_No_Confirm_Group']:'').';'.(isset($_POST['UserAdvManager_Validated_Group'])?$_POST['UserAdvManager_Validated_Group']:'').';'.(isset($_POST['UserAdvManager_Validated_Status'])?$_POST['UserAdvManager_Validated_Status']:'').';'.$_POST['UserAdvManager_No_Comment_Anonymous'].';'.$_POST['UserAdvManager_Username_Char'].';'.$_POST['UserAdvManager_Username_List'].';'.(isset($_POST['UserAdvManager_No_Confirm_Status'])?$_POST['UserAdvManager_No_Confirm_Status']:'').';'.$_POST['UserAdvManager_MailInfo_Text'].';'.$_POST['UserAdvManager_ConfirmMail_Text'].';'.$_POST['UserAdvManager_MailExclusion'].';'.$_POST['UserAdvManager_MailExclusion_List'].';'.$_POST['UserAdvManager_Password_Enforced'].';'.$_POST['UserAdvManager_Password_Score'].';'.$_POST['UserAdvManager_AdminPassword_Enforced'];
64               
65                $conf['nbc_UserAdvManager'] = $newconf_nbc_UserAdvManager;
66               
67                $query = '
68                UPDATE '.CONFIG_TABLE.'
69                SET value="'.$newconf_nbc_UserAdvManager.'"
70                WHERE param="nbc_UserAdvManager"
71                LIMIT 1
72                ;';
73               
74                pwg_query($query);
75               
76                array_push($page['infos'], l10n('UserAdvManager_save_config'));
77  }
78
79  if (isset($_POST['PasswordTest']) and !is_adviser() and isset($_POST['UserAdvManager_Password_Test']) and !empty($_POST['UserAdvManager_Password_Test']))
80  {
81    $UserAdvManager_Password_Test_Score = testpassword($_POST['UserAdvManager_Password_Test']);
82  }
83  else if (isset($_POST['PasswordTest']) and !is_adviser() and empty($_POST['UserAdvManager_Password_Test']))
84  {
85    array_push($page['errors'], l10n('reg_err_login3'));
86  }
87       
88  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
89       
90/* Group setting for unvalidated and validated users */
91  $groups[-1] = '---------';
92  $No_Valid = -1;
93  $Valid = -1;
94       
95/* Check groups list in database  */
96  $query = '
97    SELECT id, name
98                FROM '.GROUPS_TABLE.'
99                ORDER BY name ASC
100                ;';
101       
102  $result = pwg_query($query);
103       
104  while ($row = mysql_fetch_array($result))
105  {
106    $groups[$row['id']] = $row['name'];
107/* configuration value for unvalidated users */
108    if (isset($conf_nbc_UserAdvManager[3]) and $conf_nbc_UserAdvManager[3] == $row['id'])
109    {
110                $No_Valid = $row['id'];
111                }
112/* configuration value for validated users */
113    if (isset($conf_nbc_UserAdvManager[4]) and $conf_nbc_UserAdvManager[4] == $row['id'])
114                {
115                $Valid = $row['id'];
116                }
117  }
118       
119/* Template initialization for unvalidated users group */
120  $template->assign(
121    'No_Confirm_Group',
122        array(
123                'group_options'=> $groups,
124                'group_selected' => $No_Valid
125                        )
126                );
127/* Template initialization for validated users group */
128  $template->assign(
129    'Validated_Group',
130                array(
131      'group_options'=> $groups,
132      'group_selected' => $Valid
133                        )
134        );
135       
136/* Status setting for unvalidated and validated users */
137  $status_options[-1] = '------------';
138  $No_Valid_Status = -1;
139  $Valid_Status = -1;
140       
141/* Get status values */
142  foreach (get_enums(USER_INFOS_TABLE, 'status') as $status)
143  {
144          $status_options[$status] = l10n('user_status_'.$status);
145          if (isset($conf_nbc_UserAdvManager[9]) and $conf_nbc_UserAdvManager[9] == $status)
146          {
147            $No_Valid_Status = $status;
148          }
149         
150/* Template initialization for unvalidated users group */
151      $template->assign(
152        'No_Confirm_Status',
153        array(
154                                        'Status_options' => $status_options,
155                                'Status_selected' => $No_Valid_Status
156                                        )
157                        );
158  }
159 
160/* Get status values */
161  foreach (get_enums(USER_INFOS_TABLE, 'status') as $status)
162  {
163          $status_options[$status] = l10n('user_status_'.$status);
164          if (isset($conf_nbc_UserAdvManager[5]) and $conf_nbc_UserAdvManager[5] == $status)
165                {
166                  $Valid_Status = $status;
167                }
168               
169/* Template initialization for unvalidated users group */
170      $template->assign(
171            'Confirm_Status',
172            array(
173                    'Status_options' => $status_options,
174                    'Status_selected' => $Valid_Status
175                    )
176            );
177        }
178       
179  $template->assign(
180    array(
181                'UserAdvManager_MAIL_INFO_TRUE'       => $conf_nbc_UserAdvManager[0]=='true' ?  'checked="checked"' : '' ,
182                'UserAdvManager_MAIL_INFO_FALSE'      => $conf_nbc_UserAdvManager[0]=='false' ?  'checked="checked"' : '' ,
183                'UserAdvManager_MAILINFO_TEXT'        => $conf_nbc_UserAdvManager[10],
184                'UserAdvManager_NO_CASSE_TRUE'        => $conf_nbc_UserAdvManager[1]=='true' ?  'checked="checked"' : '' ,
185                'UserAdvManager_NO_CASSE_FALSE'       => $conf_nbc_UserAdvManager[1]=='false' ?  'checked="checked"' : '' ,
186                'UserAdvManager_USERNAME_CHAR_TRUE'   => $conf_nbc_UserAdvManager[7]=='true' ?  'checked="checked"' : '' ,
187                'UserAdvManager_USERNAME_CHAR_FALSE'  => $conf_nbc_UserAdvManager[7]=='false' ?  'checked="checked"' : '' ,
188                'UserAdvManager_USERNAME_CHAR_LIST'   => $conf_nbc_UserAdvManager[8],
189                'UserAdvManager_CONFIRM_MAIL_TRUE'    => $conf_nbc_UserAdvManager[2]=='true' ?  'checked="checked"' : '' ,
190                'UserAdvManager_CONFIRM_MAIL_FALSE'   => $conf_nbc_UserAdvManager[2]=='false' ?  'checked="checked"' : '' ,
191                'UserAdvManager_CONFIRMMAIL_TEXT'     => $conf_nbc_UserAdvManager[11],
192                'UserAdvManager_No_Confirm_Group'     => $conf_nbc_UserAdvManager[3],
193                'UserAdvManager_Validated_Group'      => $conf_nbc_UserAdvManager[4],
194                'UserAdvManager_No_Confirm_Status'    => $conf_nbc_UserAdvManager[9],
195                'UserAdvManager_Validated_Status'     => $conf_nbc_UserAdvManager[5],
196                'UserAdvManager_NO_COMMENT_ANO_TRUE'  => $conf_nbc_UserAdvManager[6]=='true' ?  'checked="checked"' : '' ,
197                'UserAdvManager_NO_COMMENT_ANO_FALSE' => $conf_nbc_UserAdvManager[6]=='false' ?  'checked="checked"' : '' ,
198                'UserAdvManager_MAILEXCLUSION_TRUE'   => $conf_nbc_UserAdvManager[12]=='true' ?  'checked="checked"' : '' ,
199                'UserAdvManager_MAILEXCLUSION_FALSE'  => $conf_nbc_UserAdvManager[12]=='false' ?  'checked="checked"' : '' ,
200                'UserAdvManager_MAILEXCLUSION_LIST'   => $conf_nbc_UserAdvManager[13],
201                'UserAdvManager_PASSWORDENF_TRUE'     => $conf_nbc_UserAdvManager[14]=='true' ?  'checked="checked"' : '' ,
202                'UserAdvManager_PASSWORDENF_FALSE'    => $conf_nbc_UserAdvManager[14]=='false' ?  'checked="checked"' : '' ,
203                'UserAdvManager_PASSWORD_SCORE'       => $conf_nbc_UserAdvManager[15],
204    'UserAdvManager_ADMINPASSWENF_TRUE'   => $conf_nbc_UserAdvManager[16]=='true' ?  'checked="checked"' : '' ,
205                'UserAdvManager_ADMINPASSWENF_FALSE'  => $conf_nbc_UserAdvManager[16]=='false' ?  'checked="checked"' : '' ,
206                'UserAdvManager_PASSWORD_TEST_SCORE'  => $UserAdvManager_Password_Test_Score,
207    )
208  );
209       
210
211  if (isset($_POST['audit']))
212        {
213                $msg_error1 = '';
214               
215/* username insensible a la casse */
216    if (isset($conf_nbc_UserAdvManager[3]) and $conf_nbc_UserAdvManager[3] == 'true')
217          {
218                        $query = "
219                        SELECT ".$conf['user_fields']['username']."
220                                FROM ".USERS_TABLE." p1
221                                WHERE EXISTS(
222                                SELECT ".$conf['user_fields']['username']."
223                                FROM ".USERS_TABLE." p2
224                                WHERE p1.".$conf['user_fields']['id']." <> p2.".$conf['user_fields']['id']."
225                                AND LOWER(p1.".$conf['user_fields']['username'].") = LOWER(p2.".$conf['user_fields']['username'].")
226                                )
227                        ;";
228                         
229                  $result = pwg_query($query);
230                       
231                  while($row = mysql_fetch_array($result))
232                {
233                                $msg_error1 .= (($msg_error1 <> '') ? '<br/>' : '') . l10n('Err_audit_no_casse').$row['username'];
234                        }
235                }
236
237                $msg_error2 = '';
238               
239/* Username without forbidden keys */
240    if ( isset($conf_nbc_UserAdvManager[7]) and $conf_nbc_UserAdvManager[7] == 'true' )
241          {
242                        $query = "
243                        SELECT ".$conf['user_fields']['username'].", ".$conf['user_fields']['email']."
244                                FROM ".USERS_TABLE."
245                        ;";
246                         
247                        $result = pwg_query($query);
248                       
249                        while($row = mysql_fetch_array($result))
250                        {
251                                if (!ValidateUsername($row['username']))
252                                        $msg_error2 .= (($msg_error2 <> '') ? '<br/>' : '') . l10n('Err_audit_username_char').$row['username'];
253                        }
254                }
255
256                $msg_error3 = '';
257               
258/* Email without forbidden domain */
259    if ( isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' )
260          {
261                        $query = "
262                        SELECT ".$conf['user_fields']['username'].", ".$conf['user_fields']['email']."
263                                FROM ".USERS_TABLE."
264                        ;";
265                         
266                  $result = pwg_query($query);
267                       
268                  while($row = mysql_fetch_array($result))
269                  {
270                                $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
271                          $conf_nbc_MailExclusion = preg_split('/,/',$conf_nbc_UserAdvManager[13]);
272                          for ($i = 0 ; $i < count($conf_nbc_MailExclusion) ; $i++)
273                          {
274                                        $pattern = '/'.$conf_nbc_MailExclusion[$i].'/';
275                                  if (preg_match($pattern, $row['mail_address']))
276                                  {
277                                                $msg_error3 .=  (($msg_error3 <> '') ? '<br/>' : '') . l10n('Err_audit_email_forbidden').$row['username'].' ('.$row['mail_address'].')';
278                                        }
279                                }
280                        }
281                }
282               
283    if ($msg_error1 <> '')
284                        $errors[] = $msg_error1.'<br/><br/>';
285               
286                if ($msg_error2 <> '')
287                        $errors[] = $msg_error2.'<br/><br/>';
288               
289                if ($msg_error3 <> '')
290                $errors[] = $msg_error3.'<br/><br/>';
291               
292                if ($msg_error1 <> '' or $msg_error2 <> '' or $msg_error3 <> '')
293                array_push($page['errors'], l10n('Err_audit_advise'));
294                else
295        array_push($page['infos'], l10n('UserAdvManager_audit_ok'));
296        }
297
298
299// +-----------------------------------------------------------------------+
300// |                             errors display                            |
301// +-----------------------------------------------------------------------+
302  if (isset ($errors) and count($errors) != 0)
303  {
304          $template->assign('errors',array());
305          foreach ($errors as $error)
306          {
307                  array_push($page['errors'], $error);
308                }
309        } 
310
311// +-----------------------------------------------------------------------+
312// |                           templates display                           |
313// +-----------------------------------------------------------------------+
314  $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/global.tpl');
315  $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
316
317  break;
318
319// *************************************************************************
320// +-----------------------------------------------------------------------+
321// |                           ConfirmMail Config                          |
322// +-----------------------------------------------------------------------+
323// *************************************************************************
324  case 'confirmmail':
325       
326  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
327       
328  if (isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2]=='true')
329  {
330    if ( isset($_POST['submit']) and !is_adviser() and isset($_POST['UserAdvManager_ConfirmMail_TimeOut']) )
331                {
332                $_POST['UserAdvManager_ConfirmMail_ReMail_Txt1'] = str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UserAdvManager_ConfirmMail_ReMail_Txt1']));
333                $_POST['UserAdvManager_ConfirmMail_ReMail_Txt2'] = str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UserAdvManager_ConfirmMail_ReMail_Txt2']));
334                 
335                $newconf_nbc_UserAdvManager_ConfirmMail = $_POST['UserAdvManager_ConfirmMail_TimeOut'].';'.$_POST['UserAdvManager_ConfirmMail_Delay'].';'.$_POST['UserAdvManager_ConfirmMail_ReMail_Txt1'].';'.$_POST['UserAdvManager_ConfirmMail_Remail'].';'.$_POST['UserAdvManager_ConfirmMail_ReMail_Txt2'];
336                 
337//NODO:Adding new option [Auto deletion : True | False] - No access to cron functionnalities
338
339                $conf['nbc_UserAdvManager_ConfirmMail'] = $newconf_nbc_UserAdvManager_ConfirmMail;
340               
341                $query = '
342                UPDATE '.CONFIG_TABLE.'
343                                SET value="'.$newconf_nbc_UserAdvManager_ConfirmMail.'"
344                                WHERE param="nbc_UserAdvManager_ConfirmMail"
345                                LIMIT 1
346                        ;';
347               
348                        pwg_query($query);
349               
350                        array_push($page['infos'], l10n('UserAdvManager_save_config'));
351                }
352       
353                $conf_nbc_UserAdvManager_ConfirmMail = isset($conf['nbc_UserAdvManager_ConfirmMail']) ? explode(";" , $conf['nbc_UserAdvManager_ConfirmMail']) : array();               
354
355          $template->assign(
356          array(
357                'UserAdvManager_CONFIRMMAIL_TIMEOUT_TRUE'               => $conf_nbc_UserAdvManager_ConfirmMail[0]=='true' ?  'checked="checked"' : '' ,
358                'UserAdvManager_CONFIRMMAIL_TIMEOUT_FALSE'      => $conf_nbc_UserAdvManager_ConfirmMail[0]=='false' ?  'checked="checked"' : '' ,
359                'UserAdvManager_CONFIRMMAIL_DELAY'                                      => $conf_nbc_UserAdvManager_ConfirmMail[1],
360    'UserAdvManager_CONFIRMMAIL_REMAIL_TRUE'            => $conf_nbc_UserAdvManager_ConfirmMail[3]=='true' ? 'checked="checked"' : '',
361    'UserAdvManager_CONFIRMMAIL_REMAIL_FALSE'           => $conf_nbc_UserAdvManager_ConfirmMail[3]=='false' ? 'checked="checked"' : '',
362    'UserAdvManager_CONFIRMMAIL_REMAIL_TXT1'            => $conf_nbc_UserAdvManager_ConfirmMail[2],
363    'UserAdvManager_CONFIRMMAIL_REMAIL_TXT2'            => $conf_nbc_UserAdvManager_ConfirmMail[4],
364        )
365          );           
366
367// +-----------------------------------------------------------------------+
368// |                             errors display                            |
369// +-----------------------------------------------------------------------+
370                if ( isset ($errors) and count($errors) != 0)
371                {
372                $template->assign('errors',array());
373                        foreach ($errors as $error)
374                {
375                                array_push($page['errors'], $error);
376                }
377                } 
378
379// +-----------------------------------------------------------------------+
380// |                           templates display                           |
381// +-----------------------------------------------------------------------+
382                $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/confirmmail.tpl');
383    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');         
384  }
385  else
386  {
387                array_push($page['infos'], l10n('Err_ConfirmMail_Settings'));
388  }
389  break;
390
391
392// *************************************************************************
393// +-----------------------------------------------------------------------+
394// |                           Users manager page                          |
395// +-----------------------------------------------------------------------+
396// *************************************************************************
397  case 'usermanager':
398 
399  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
400  $conf_nbc_UserAdvManager_ConfirmMail = isset($conf['nbc_UserAdvManager_ConfirmMail']) ? explode(";" , $conf['nbc_UserAdvManager_ConfirmMail']) : array();
401       
402  if (isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2]=='true' and ((isset($conf_nbc_UserAdvManager[3]) and $conf_nbc_UserAdvManager[3] <> '-1') or (isset($conf_nbc_UserAdvManager[9]) and $conf_nbc_UserAdvManager[9] <> '-1')) and isset($conf_nbc_UserAdvManager_ConfirmMail[0]) and $conf_nbc_UserAdvManager_ConfirmMail[0]=='true')
403  {
404// +-----------------------------------------------------------------------+
405// |                           initialization                              |
406// +-----------------------------------------------------------------------+
407
408                if (!defined('PHPWG_ROOT_PATH'))
409    {
410        die('Hacking attempt!');
411    }
412         
413    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
414
415// +-----------------------------------------------------------------------+
416// | Check Access and exit when user status is not ok                      |
417// +-----------------------------------------------------------------------+
418                check_status(ACCESS_ADMINISTRATOR);
419
420    $page['order_by_items'] = array(
421      'id' => l10n('registration_date'),
422      'username' => l10n('Username'),
423      'level' => l10n('Privacy level'),
424      'language' => l10n('language'),
425    );
426
427// +-----------------------------------------------------------------------+
428// |                               user list                               |
429// +-----------------------------------------------------------------------+
430
431                $page['filtered_users'] = get_unvalid_user_list();
432
433// +-----------------------------------------------------------------------+
434// |                            selected users                             |
435// +-----------------------------------------------------------------------+
436                if (isset($_POST['Del_Selected']))
437                {
438                $collection = array();
439
440                        switch ($_POST['target'])
441        {
442                case 'all' :
443        {
444                foreach($page['filtered_users'] as $local_user)
445                {
446                        array_push($collection, $local_user['id']);
447                }
448                                        break;
449                                }
450        case 'selection' :
451        {
452                if (isset($_POST['selection']))
453                {
454                        $collection = $_POST['selection'];
455                }
456                break;
457        }
458                        }
459
460                        if (count($collection) == 0)
461        {
462                array_push($page['errors'], l10n('Select at least one user'));
463                }
464                }
465
466// +-----------------------------------------------------------------------+
467// |                             delete users                              |
468// +-----------------------------------------------------------------------+
469                if (isset($_POST['Del_Selected']) and count($collection) > 0)
470        {
471                if (in_array($conf['guest_id'], $collection))
472                {
473                array_push($page['errors'], l10n('Guest cannot be deleted'));
474        }
475        if (($conf['guest_id'] != $conf['default_user_id']) and
476                in_array($conf['default_user_id'], $collection))
477        {
478                array_push($page['errors'], l10n('Default user cannot be deleted'));
479        }
480        if (in_array($conf['webmaster_id'], $collection))
481        {
482                array_push($page['errors'], l10n('Webmaster cannot be deleted'));
483        }
484        if (in_array($user['id'], $collection))
485        {
486                array_push($page['errors'], l10n('You cannot delete your account'));
487        }
488
489                        if (count($page['errors']) == 0)
490        {
491                foreach ($collection as $user_id)
492        {
493                delete_user($user_id);
494        }
495                array_push(
496                $page['infos'],
497                l10n_dec(
498                '%d user deleted', '%d users deleted',
499                count($collection)
500                )
501        );
502
503        foreach ($page['filtered_users'] as $filter_key => $filter_user)
504        {
505                if (in_array($filter_user['id'], $collection))
506                {
507                        unset($page['filtered_users'][$filter_key]);
508                }
509                }
510                        }
511                }
512
513// +-----------------------------------------------------------------------+
514// |                 Resend new validation key to users                    |
515// +-----------------------------------------------------------------------+
516// +-----------------------------------------------------------------------+
517// |                            selected users                             |
518// +-----------------------------------------------------------------------+
519                if (isset($_POST['Mail_With_Key']))
520                {
521                $collection = array();
522
523                        switch ($_POST['target'])
524        {
525                case 'all' :
526        {
527                foreach($page['filtered_users'] as $local_user)
528                {
529                        array_push($collection, $local_user['id']);
530                }
531                break;
532                                }
533        case 'selection' :
534        {
535                if (isset($_POST['selection']))
536                {
537                        $collection = $_POST['selection'];
538                }
539                break;
540        }
541                        }
542
543        if (count($collection) == 0)
544        {
545                array_push($page['errors'], l10n('Select at least one user'));
546        }
547                }
548// +-----------------------------------------------------------------------+
549// |                 Resend new validation key to users                    |
550// +-----------------------------------------------------------------------+
551                if (isset($_POST['Mail_With_Key']) and count($collection) > 0)
552                {
553                        if (in_array($conf['guest_id'], $collection))
554                {
555                array_push($page['errors'], l10n('No_validation_for_Guest'));
556        }
557        if (($conf['guest_id'] != $conf['default_user_id']) and
558                in_array($conf['default_user_id'], $collection))
559        {
560                array_push($page['errors'], l10n('No_validation_for_default_user'));
561        }
562                if (in_array($conf['webmaster_id'], $collection))
563        {
564                array_push($page['errors'], l10n('No_validation_for_Webmaster'));
565        }
566        if (in_array($user['id'], $collection))
567        {
568                array_push($page['errors'], l10n('No_validation_for_your_account'));
569        }
570
571        if (count($page['errors']) == 0)
572        {
573                foreach ($collection as $user_id)
574        {       
575                $typemail = 1;
576                                  $query = "
577                                                SELECT id, username, mail_address
578                                                FROM ".USERS_TABLE."
579                                                WHERE id = '".$user_id."'
580                                                ;";
581                                        $data = mysql_fetch_array(pwg_query($query));
582                               
583                ResendMail2User($typemail,$user_id,$data['username'],$data['mail_address'],true);
584        }
585        array_push(
586                $page['infos'],
587                l10n_dec(
588                        '%d_Mail_With_Key', '%d_Mails_With_Key',
589                count($collection)
590                )
591        );
592       
593                                $page['filtered_users'] = get_unvalid_user_list();
594                        }
595                }
596
597// +-----------------------------------------------------------------------+
598// |             Send reminder without new key to users                    |
599// +-----------------------------------------------------------------------+
600// +-----------------------------------------------------------------------+
601// |                            selected users                             |
602// +-----------------------------------------------------------------------+
603                if (isset($_POST['Mail_Without_Key']))
604                {
605                $collection = array();
606
607                        switch ($_POST['target'])
608        {
609                case 'all' :
610        {
611                foreach($page['filtered_users'] as $local_user)
612                {
613                        array_push($collection, $local_user['id']);
614                }
615                break;
616                                }
617        case 'selection' :
618        {
619                if (isset($_POST['selection']))
620                {
621                        $collection = $_POST['selection'];
622                }
623                break;
624        }
625                        }
626
627        if (count($collection) == 0)
628        {
629                array_push($page['errors'], l10n('Select at least one user'));
630        }
631                }
632// +-----------------------------------------------------------------------+
633// |             Send reminder without new key to users                    |
634// +-----------------------------------------------------------------------+
635                if (isset($_POST['Mail_Without_Key']) and count($collection) > 0)
636                {
637                        if (in_array($conf['guest_id'], $collection))
638                {
639                array_push($page['errors'], l10n('No_validation_for_Guest'));
640        }
641        if (($conf['guest_id'] != $conf['default_user_id']) and
642                in_array($conf['default_user_id'], $collection))
643        {
644                array_push($page['errors'], l10n('No_validation_for_default_user'));
645        }
646                if (in_array($conf['webmaster_id'], $collection))
647        {
648                array_push($page['errors'], l10n('No_validation_for_Webmaster'));
649        }
650        if (in_array($user['id'], $collection))
651        {
652                array_push($page['errors'], l10n('No_validation_for_your_account'));
653        }
654
655        if (count($page['errors']) == 0)
656        {
657                foreach ($collection as $user_id)
658        {
659                $typemail = 2;
660                                  $query = "
661                                                SELECT id, username, mail_address
662                                                FROM ".USERS_TABLE."
663                                                WHERE id = '".$user_id."'
664                                        ;";
665                                       
666                                        $data = mysql_fetch_array(pwg_query($query));
667                               
668                ResendMail2User($typemail,$user_id,$data['username'],$data['mail_address'],false);                             
669        }
670        array_push(
671                $page['infos'],
672                l10n_dec(
673                        '%d_Reminder_Sent', '%d_Reminders_Sent',
674                count($collection)
675                )
676        );
677       
678                                $page['filtered_users'] = get_unvalid_user_list();
679                        }
680                }
681
682// +-----------------------------------------------------------------------+
683// |                                                                            Force validation                                                         |
684// +-----------------------------------------------------------------------+
685// +-----------------------------------------------------------------------+
686// |                            selected users                             |
687// +-----------------------------------------------------------------------+
688                if (isset($_POST['Force_Validation']))
689                {
690                $collection = array();
691
692                        switch ($_POST['target'])
693        {
694                case 'all' :
695        {
696                foreach($page['filtered_users'] as $local_user)
697                {
698                        array_push($collection, $local_user['id']);
699                }
700                break;
701                                }
702        case 'selection' :
703        {
704                if (isset($_POST['selection']))
705                {
706                        $collection = $_POST['selection'];
707                }
708                break;
709        }
710                        }
711
712        if (count($collection) == 0)
713        {
714                array_push($page['errors'], l10n('Select at least one user'));
715        }
716                }
717// +-----------------------------------------------------------------------+
718// |                                                                            Force validation                                                         |
719// +-----------------------------------------------------------------------+
720                if (isset($_POST['Force_Validation']) and count($collection) > 0)
721                {
722                        if (in_array($conf['guest_id'], $collection))
723                {
724                array_push($page['errors'], l10n('No_validation_for_Guest'));
725        }
726        if (($conf['guest_id'] != $conf['default_user_id']) and
727                in_array($conf['default_user_id'], $collection))
728        {
729                array_push($page['errors'], l10n('No_validation_for_default_user'));
730        }
731                if (in_array($conf['webmaster_id'], $collection))
732        {
733                array_push($page['errors'], l10n('No_validation_for_Webmaster'));
734        }
735        if (in_array($user['id'], $collection))
736        {
737                array_push($page['errors'], l10n('No_validation_for_your_account'));
738        }
739
740        if (count($page['errors']) == 0)
741        {
742                foreach ($collection as $user_id)
743        {
744                                  $query = "
745                                                SELECT id, username, mail_address
746                                                FROM ".USERS_TABLE."
747                                                WHERE id = '".$user_id."'
748                                        ;";
749                                       
750                                        $data = mysql_fetch_array(pwg_query($query));
751                               
752                ForceValidation($data['id']);                           
753        }
754        array_push(
755                $page['infos'],
756                l10n_dec(
757                        '%d_Validated_User', '%d_Validated_Users',
758                count($collection)
759                )
760        );
761
762                                $page['filtered_users'] = get_unvalid_user_list();
763                        }
764                }
765               
766
767// +-----------------------------------------------------------------------+
768// |                              groups list                              |
769// +-----------------------------------------------------------------------+
770
771                $groups[-1] = '------------';
772
773    $query = '
774      SELECT id, name
775      FROM '.GROUPS_TABLE.'
776      ORDER BY name ASC
777      ;';
778
779                $result = pwg_query($query);
780         
781    while ($row = mysql_fetch_array($result))
782    {
783      $groups[$row['id']] = $row['name'];
784    }
785
786// +-----------------------------------------------------------------------+
787// |                           Template Init                               |
788// +-----------------------------------------------------------------------+
789                $base_url = PHPWG_ROOT_PATH.'admin.php?page=user_list';
790
791    if (isset($_GET['start']) and is_numeric($_GET['start']))
792    {
793      $start = $_GET['start'];
794    }
795    else
796    {
797      $start = 0;
798    }
799
800    $template->assign(
801      array(
802        'F_ADD_ACTION' => $base_url,
803        'F_USERNAME' => @htmlentities($_GET['username']),
804        'F_FILTER_ACTION' => get_root_url().'admin.php'
805        )
806          );
807
808/* Hide radio-button if not allow to assign adviser */
809                if ($conf['allow_adviser'])
810        {
811        $template->assign('adviser', true);
812        }
813       
814// +-----------------------------------------------------------------------+
815// |                               user list                               |
816// +-----------------------------------------------------------------------+
817
818                $profile_url = get_root_url().'admin.php?page=profile&amp;user_id=';
819                $perm_url = get_root_url().'admin.php?page=user_perm&amp;user_id=';
820
821    $visible_user_list = array();
822    foreach ($page['filtered_users'] as $num => $local_user)
823    {
824/* simulate LIMIT $start, $conf['users_page'] */
825                        if ($num < $start)
826      {
827        continue;
828      }
829      if ($num >= $start + $conf['users_page'])
830      {
831        break;
832      }
833
834      $visible_user_list[] = $local_user;
835                }
836
837                foreach ($visible_user_list as $local_user)
838    {
839      $groups_string = preg_replace(
840        '/(\d+)/e',
841        "\$groups['$1']",
842        implode(
843                ', ',
844            $local_user['groups']
845         )
846                        );
847
848                if (isset($_POST['pref_submit'])
849                and isset($_POST['selection'])
850        and in_array($local_user['id'], $_POST['selection']))
851                {
852                                $checked = 'checked="checked"';
853                }
854                        else
855        {
856                $checked = '';
857        }
858
859        $properties = array();
860        if ( $local_user['level'] != 0 )
861                        {
862                $properties[] = l10n( sprintf('Level %d', $local_user['level']) );
863                        }
864        $properties[] =
865                (isset($local_user['enabled_high']) and ($local_user['enabled_high'] == 'true'))
866                ? l10n('is_high_enabled') : l10n('is_high_disabled');
867
868                        $expiration = expiration($local_user['id']);
869             
870                $template->append(
871                'users',
872        array(
873                'ID' => $local_user['id'],
874                'CHECKED' => $checked,
875                'U_PROFILE' => $profile_url.$local_user['id'],
876                'U_PERM' => $perm_url.$local_user['id'],
877                'USERNAME' => $local_user['username']
878                                                .($local_user['id'] == $conf['guest_id']
879                                                ? '<BR />['.l10n('is_the_guest').']' : '')
880                .($local_user['id'] == $conf['default_user_id']
881                ? '<BR />['.l10n('is_the_default').']' : ''),
882                                        'STATUS' => l10n('user_status_'.
883                                                $local_user['status']).(($local_user['adviser'] == 'true')
884                ? '<BR />['.l10n('adviser').']' : ''),
885                                        'EMAIL' => get_email_address_as_display_text($local_user['email']),
886                'GROUPS' => $groups_string,
887                'REGISTRATION' => $local_user['registration_date'],
888                'EXPIRATION' => $expiration,
889                                )
890                        );
891                }
892
893// +-----------------------------------------------------------------------+
894// |                             errors display                            |
895// +-----------------------------------------------------------------------+
896                if ( isset ($errors) and count($errors) != 0)
897                {
898                $template->assign('errors',array());
899                        foreach ($errors as $error)
900                {
901                                array_push($page['errors'], $error);
902                }
903                } 
904
905// +-----------------------------------------------------------------------+
906// |                           templates display                           |
907// +-----------------------------------------------------------------------+
908                $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/usermanager.tpl');
909    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');         
910        }
911  else
912  {
913                array_push($page['infos'], l10n('Err_UserManager_Settings'));
914  }
915  break; 
916}
917?>
Note: See TracBrowser for help on using the repository browser.