source: trunk/admin/user_list.php @ 164

Last change on this file since 164 was 164, checked in by z0rglub, 21 years ago

The generation of mail address works back. Since the add of another form on
the same page, it didn't work, because, when adding a new user and no
errors, the $_POST was cleaned, but made no differences between the 2
forms...

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.3 KB
Line 
1<?php
2/***************************************************************************
3 *                               user_list.php                             *
4 *                            -------------------                          *
5 *   application   : PhpWebGallery 1.3 <http://phpwebgallery.net>          *
6 *   author        : Pierrick LE GALL <pierrick@z0rglub.com>               *
7 *                                                                         *
8 *   $Id: user_list.php 164 2003-09-24 19:30:24Z z0rglub $
9 *                                                                         *
10 ***************************************************************************/
11
12/***************************************************************************
13 *                                                                         *
14 *   This program is free software; you can redistribute it and/or modify  *
15 *   it under the terms of the GNU General Public License as published by  *
16 *   the Free Software Foundation;                                         *
17 *                                                                         *
18 ***************************************************************************/
19include_once( './include/isadmin.inc.php' );
20//----------------------------------------------------- template initialization
21$sub = $vtp->Open( '../template/'.$user['template'].'/admin/user_list.vtp' );
22$tpl = array( 'listuser_confirm','listuser_modify_hint','listuser_modify',
23              'listuser_permission','listuser_permission_hint',
24              'listuser_delete_hint','listuser_delete','yes','no',
25              'listuser_button_all','listuser_button_invert',
26              'listuser_button_create_address','title_add','login','password',
27              'add','errors_title' );
28templatize_array( $tpl, 'lang', $sub );
29$vtp->setGlobalVar( $sub, 'user_template',   $user['template'] );
30//------------------------------------------------------------------ add a user
31$errors = array();
32if ( isset( $_POST['submit_add_user'] ) )
33{
34  $errors = register_user(
35    $_POST['username'], $_POST['password'], $_POST['password'], '', 'guest' );
36}
37//-------------------------------------------------------------- errors display
38if ( sizeof( $errors ) != 0 )
39{
40  $vtp->addSession( $sub, 'errors' );
41  foreach ( $errors as $error ) {
42    $vtp->addSession( $sub, 'li' );
43    $vtp->setVar( $sub, 'li.li', $error );
44    $vtp->closeSession( $sub, 'li' );
45  }
46  $vtp->closeSession( $sub, 'errors' );
47}
48else if ( isset( $_POST['submit_add_user'] ) )
49{
50  $_POST = array();
51}
52//--------------------------------------------------------------- delete a user
53if ( isset ( $_GET['delete'] ) and is_numeric( $_GET['delete'] ) )
54{
55  $query = 'SELECT username';
56  $query.= ' FROM '.PREFIX_TABLE.'users';
57  $query.= ' WHERE id = '.$_GET['delete'];
58  $query.= ';';
59  $row = mysql_fetch_array( mysql_query( $query ) );
60  // confirm user deletion ?
61  if ( $_GET['confirm'] != 1 )
62  {
63    $vtp->addSession( $sub, 'deletion' );
64    $vtp->setVar( $sub, 'deletion.login', $row['username'] );
65    $yes_url = './admin.php?page=user_list&amp;delete='.$_GET['delete'];
66    $yes_url.= '&amp;confirm=1';
67    $vtp->setVar( $sub, 'deletion.yes_url', add_session_id( $yes_url ) );
68    $no_url = './admin.php?page=user_list';
69    $vtp->setVar( $sub, 'deletion.no_url', add_session_id( $no_url ) );
70    $vtp->closeSession( $sub, 'deletion' );
71  }
72  // user deletion confirmed
73  else
74  {
75    $vtp->addSession( $sub, 'confirmation' );
76    if ( $row['username'] != 'guest'
77         and $row['username'] != $conf['webmaster'] )
78    {
79      $query = 'SELECT COUNT(*) AS nb_result';
80      $query.= ' FROM '.PREFIX_TABLE.'users';
81      $query.= ' WHERE id = '.$_GET['delete'];
82      $query.= ';';
83      $row2 = mysql_fetch_array( mysql_query( $query ) );
84      if ( $row2['nb_result'] > 0 )
85      {
86        delete_user( $_GET['delete'] );
87        $vtp->setVar( $sub, 'confirmation.class', 'info' );
88        $info = '"'.$row['username'].'" '.$lang['listuser_info_deletion'];
89        $vtp->setVar( $sub, 'confirmation.info', $info );
90      }
91      else
92      {
93        $vtp->setVar( $sub, 'confirmation.class', 'erreur' );
94        $vtp->setVar( $sub, 'confirmation.info', $lang['user_err_unknown'] );
95      }
96    }
97    else
98    {
99      $vtp->setVar( $sub, 'confirmation.class', 'erreur' );
100      $vtp->setVar( $sub, 'confirmation.info', $lang['user_err_modify'] );
101    }
102    $vtp->closeSession( $sub, 'confirmation' );
103  }
104}
105//------------------------------------------------------------------ users list
106else
107{
108  // add a user
109  $vtp->addSession( $sub, 'add_user' );
110  $action = './admin.php?'.$_SERVER['QUERY_STRING'];
111  $vtp->setVar( $sub, 'add_user.form_action', $action );
112  $vtp->setVar( $sub, 'add_user.f_username', $_POST['username'] );
113  $vtp->closeSession( $sub, 'add_user' );
114 
115  $vtp->addSession( $sub, 'users' );
116
117  $action = './admin.php?'.$_SERVER['QUERY_STRING'];
118  if ( !isset( $_GET['mail'] ) )
119  {
120    $action.= '&amp;mail=true';
121  }
122  $vtp->setVar( $sub, 'users.form_action', $action );
123
124  $query = 'SELECT id,username,status,mail_address';
125  $query.= ' FROM '.PREFIX_TABLE.'users';
126  $query.= ' ORDER BY status ASC, username ASC';
127  $query.= ';';
128  $result = mysql_query( $query );
129
130  $current_status = '';
131  while ( $row = mysql_fetch_array( $result ) )
132  {
133    // display the line indicating the status of the next users
134    if ( $row['status'] != $current_status )
135    {
136      if ( $current_status != '' )
137      {
138        $vtp->closeSession( $sub, 'category' );
139      }
140      $vtp->addSession( $sub, 'category' );
141      $title = $lang['listuser_user_group'].' ';
142      switch ( $row['status'] )
143      {
144      case 'admin' : $title.= $lang['adduser_status_admin']; break;
145      case 'guest' : $title.= $lang['adduser_status_guest']; break;
146      }
147      $vtp->setVar( $sub, 'category.title', $title );
148      $current_status = $row['status'];
149    }
150    $vtp->addSession( $sub, 'user' );
151    // checkbox for mail management if the user has a mail address
152    if ( $row['mail_address'] != '' and $row['username'] != 'guest' )
153    {
154      $vtp->addSession( $sub, 'checkbox' );
155      $vtp->setVar( $sub, 'checkbox.name', 'mail-'.$row['id'] );
156      $vtp->closeSession( $sub, 'checkbox' );
157    }
158    // use a special color for the login of the user ?
159    if ( $row['username'] == $conf['webmaster'] )
160    {
161      $vtp->setVar( $sub, 'user.color', 'red' );
162    }
163    if ( $row['username'] == 'guest' )
164    {
165      $vtp->setVar( $sub, 'user.color', 'green' );
166      $vtp->setVar( $sub, 'user.login', $lang['guest'] );
167    }
168    else
169    {
170      $vtp->setVar( $sub, 'user.login', $row['username'] );
171    }
172    // modify or not modify ?
173    if ( $row['username'] == 'guest'
174         or ( $row['username'] == $conf['webmaster']
175              and $user['username'] != $conf['webmaster'] ) )
176    {
177      $vtp->addSession( $sub, 'not_modify' );
178      $vtp->closeSession( $sub, 'not_modify' );
179    }
180    else
181    {
182      $vtp->addSession( $sub, 'modify' );
183      $url = './admin.php?page=user_modify&amp;user_id=';
184      $url.= $row['id'];
185      $vtp->setVar( $sub, 'modify.url', add_session_id( $url ) );
186      $vtp->setVar( $sub, 'modify.login', $row['username'] );
187      $vtp->closeSession( $sub, 'modify' );
188    }
189    // manage permission or not ?
190    if ( $row['username'] == $conf['webmaster']
191         and $user['username'] != $conf['webmaster'] )
192    {
193      $vtp->addSession( $sub, 'not_permission' );
194      $vtp->closeSession( $sub, 'not_permission' );
195    }
196    else
197    {
198      $vtp->addSession( $sub, 'permission' );
199      $url = './admin.php?page=user_perm&amp;user_id='.$row['id'];
200      $vtp->setVar( $sub, 'permission.url', add_session_id( $url ) );
201      $vtp->setVar( $sub, 'permission.login', $row['username'] );
202      $vtp->closeSession( $sub, 'permission' );
203    }
204    // is the user deletable or not ?
205    if ( $row['username'] == 'guest'
206         or $row['username'] == $conf['webmaster'] )
207    {
208      $vtp->addSession( $sub, 'not_delete' );
209      $vtp->closeSession( $sub, 'not_delete' );
210    }
211    else
212    {
213      $vtp->addSession( $sub, 'delete' );
214      $url = './admin.php?page=user_list&amp;delete='.$row['id'];
215      $vtp->setVar( $sub, 'delete.url', add_session_id( $url ) );
216      $vtp->setVar( $sub, 'delete.login', $row['username'] );
217      $vtp->closeSession( $sub, 'delete' );
218    }
219    $vtp->closeSession( $sub, 'user' );
220  }
221  $vtp->closeSession( $sub, 'category' );
222  // mail management : creation of the mail address if asked by administrator
223  if ( isset( $_POST['submit_generate_mail'] ) and isset( $_GET['mail'] ) )
224  {
225    $mails = array();
226    $query = 'SELECT id,mail_address';
227    $query.= ' FROM '.PREFIX_TABLE.'users';
228    $query.= ';';
229    $result = mysql_query( $query );
230    while ( $row = mysql_fetch_array( $result ) )
231    {
232      if ( $_POST['mail-'.$row['id']] == 1 )
233        array_push( $mails, $row['mail_address'] );
234    }
235    $mail_destination = '';
236    foreach ( $mails as $i => $mail_address ) {
237      if ( $i > 0 ) $mail_destination.= ',';
238      $mail_destination.= $mail_address;
239    }
240    if ( sizeof( $mails ) > 0 )
241    {
242      $vtp->addSession( $sub, 'mail_link' );
243      $vtp->setVar( $sub, 'mail_link.mailto', $mail_destination );
244      $vtp->setVar( $sub, 'mail_link.mail_address_start',
245                    substr( $mail_destination, 0, 50 ) );
246      $vtp->closeSession( $sub, 'mail_link' );
247    }
248  }
249  $vtp->closeSession( $sub, 'users' );
250}
251//----------------------------------------------------------- sending html code
252$vtp->Parse( $handle , 'sub', $sub );
253?>
Note: See TracBrowser for help on using the repository browser.