source: trunk/admin/group_list.php @ 21

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

* empty log message *

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