source: trunk/admin/user_list.php @ 362

Last change on this file since 362 was 362, checked in by z0rglub, 20 years ago

header global refactoring

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