source: trunk/admin/user_list.php @ 393

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