source: trunk/admin/group_list.php @ 143

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

The delete link was pointing a removed page

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 KB
Line 
1<?php
2/***************************************************************************
3 *                                 group_list.php                          *
4 *                            -------------------                          *
5 *   application   : PhpWebGallery 1.3 <http://phpwebgallery.net>          *
6 *   author        : Pierrick LE GALL <pierrick@z0rglub.com>               *
7 *                                                                         *
8 *   $Id: group_list.php 143 2003-09-20 16:57:48Z 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/group_list.vtp' );
22$tpl = array( 'group_add','add','listuser_permission','delete',
23              'group_confirm','yes','no','group_list_title' );
24templatize_array( $tpl, 'lang', $sub );
25$vtp->setGlobalVar( $sub, 'user_template', $user['template'] );
26//-------------------------------------------------------------- delete a group
27$error = array();
28if ( isset ( $_GET['delete'] ) and is_numeric( $_GET['delete'] ) )
29{
30  $query = 'SELECT name';
31  $query.= ' FROM '.PREFIX_TABLE.'groups';
32  $query.= ' WHERE id = '.$_GET['delete'];
33  $query.= ';';
34  $row = mysql_fetch_array( mysql_query( $query ) );
35  // confirm group deletion ?
36  if ( $_GET['confirm'] != 1 )
37  {
38    $vtp->addSession( $sub, 'deletion' );
39    $vtp->setVar( $sub, 'deletion.name', $row['name'] );
40    $yes_url = './admin.php?page=group_list&amp;delete='.$_GET['delete'];
41    $yes_url.= '&amp;confirm=1';
42    $vtp->setVar( $sub, 'deletion.yes_url', add_session_id( $yes_url ) );
43    $no_url = './admin.php?page=group_list';
44    $vtp->setVar( $sub, 'deletion.no_url', add_session_id( $no_url ) );
45    $vtp->closeSession( $sub, 'deletion' );
46  }
47  // group deletion confirmed
48  else
49  {
50    $vtp->addSession( $sub, 'confirmation' );
51    $query = 'SELECT COUNT(*) AS nb_result';
52    $query.= ' FROM '.PREFIX_TABLE.'groups';
53    $query.= ' WHERE id = '.$_GET['delete'];
54    $query.= ';';
55    $row2 = mysql_fetch_array( mysql_query( $query ) );
56    if ( $row2['nb_result'] > 0 )
57    {
58      delete_group( $_GET['delete'] );
59      $vtp->setVar( $sub, 'confirmation.class', 'info' );
60      $info = '"'.$row['name'].'" '.$lang['listuser_info_deletion'];
61      $vtp->setVar( $sub, 'confirmation.info', $info );
62    }
63    else
64    {
65      $vtp->setVar( $sub, 'confirmation.class', 'erreur' );
66      $vtp->setVar( $sub, 'confirmation.info', $lang['group_err_unknown'] );
67    }
68    $vtp->closeSession( $sub, 'confirmation' );
69  }
70}
71//----------------------------------------------------------------- add a group
72if ( isset( $_POST['submit'] ) )
73{
74  if ( preg_match( "/'/", $_POST['name'] )
75       or preg_match( '/"/', $_POST['name'] ) )
76  {
77    array_push( $error, $lang['group_add_error1'] );
78  }
79  if ( count( $error ) == 0 )
80  {
81    // is the group not already existing ?
82    $query = 'SELECT id';
83    $query.= ' FROM '.PREFIX_TABLE.'groups';
84    $query.= " WHERE name = '".$_POST['name']."'";
85    $query.= ';';
86    $result = mysql_query( $query );
87    if ( mysql_num_rows( $result ) > 0 )
88    {
89      array_push( $error, $lang['group_add_error2'] );
90    }
91  }
92  if ( count( $error ) == 0 )
93  {
94    // creating the group
95    $query = ' INSERT INTO '.PREFIX_TABLE.'groups';
96    $query.= " (name) VALUES ('".$_POST['name']."')";
97    $query.= ';';
98    mysql_query( $query );
99  }
100}
101//-------------------------------------------------------------- errors display
102if ( sizeof( $error ) != 0 )
103{
104  $vtp->addSession( $sub, 'errors' );
105  for ( $i = 0; $i < sizeof( $error ); $i++ )
106  {
107    $vtp->addSession( $sub, 'li' );
108    $vtp->setVar( $sub, 'li.li', $error[$i] );
109    $vtp->closeSession( $sub, 'li' );
110  }
111  $vtp->closeSession( $sub, 'errors' );
112}
113//----------------------------------------------------------------- groups list
114$vtp->addSession( $sub, 'groups' );
115
116$query = 'SELECT id,name';
117$query.= ' FROM '.PREFIX_TABLE.'groups';
118$query.= ' ORDER BY id ASC';
119$query.= ';';
120$result = mysql_query( $query );
121while ( $row = mysql_fetch_array( $result ) )
122{
123  $vtp->addSession( $sub, 'group' );
124  $vtp->setVar( $sub, 'group.name', $row['name'] );
125  $url = './admin.php?page=group_perm&amp;group_id='.$row['id'];
126  $vtp->setVar( $sub, 'group.permission_url', add_session_id( $url ) );
127  $url = './admin.php?page=group_list&amp;delete='.$row['id'];
128  $vtp->setVar( $sub, 'group.deletion_url', add_session_id( $url ) );
129  $vtp->closeSession( $sub, 'group' );
130}
131
132$vtp->closeSession( $sub, 'groups' );
133//------------------------------------------------------- create new group form
134$action = './admin.php?'.$_SERVER['QUERY_STRING'];
135$vtp->setVar( $sub, 'form_action', $action );
136//----------------------------------------------------------- sending html code
137$vtp->Parse( $handle , 'sub', $sub );
138?>
Note: See TracBrowser for help on using the repository browser.