source: branches/branch-1_5/admin/group_list.php @ 1003

Last change on this file since 1003 was 1003, checked in by nikrou, 18 years ago

Improve security of sessions:

  • use only cookies to store session id on client side
  • use default php session system with database handler to store sessions on server side
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.5 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-01-15 12:52:55 +0000 (Sun, 15 Jan 2006) $
10// | last modifier : $Author: nikrou $
11// | revision      : $Revision: 1003 $
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// +-----------------------------------------------------------------------+
27
28if( !defined("PHPWG_ROOT_PATH") )
29{
30  die ("Hacking attempt!");
31}
32include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php' );
33
34// +-----------------------------------------------------------------------+
35// |                             delete a group                            |
36// +-----------------------------------------------------------------------+
37
38if (isset($_GET['delete']) and is_numeric($_GET['delete']))
39{
40  // destruction of the access linked to the group
41  $query = '
42DELETE
43  FROM '.GROUP_ACCESS_TABLE.'
44  WHERE group_id = '.$_GET['delete'].'
45;';
46  pwg_query($query);
47 
48  // destruction of the users links for this group
49  $query = '
50DELETE
51  FROM '.USER_GROUP_TABLE.'
52  WHERE group_id = '.$_GET['delete'].'
53;';
54  pwg_query($query);
55
56  $query = '
57SELECT name
58  FROM '.GROUPS_TABLE.'
59  WHERE id = '.$_GET['delete'].'
60;';
61  list($groupname) = mysql_fetch_row(pwg_query($query));
62 
63  // destruction of the group
64  $query = '
65DELETE
66  FROM '.GROUPS_TABLE.'
67  WHERE id = '.$_GET['delete'].'
68;';
69  pwg_query($query);
70
71  array_push(
72    $page['infos'],
73    sprintf(l10n('group "%s" deleted'), $groupname)
74    );
75}
76
77// +-----------------------------------------------------------------------+
78// |                              add a group                              |
79// +-----------------------------------------------------------------------+
80
81if (isset($_POST['submit_add']))
82{
83  if (empty($_POST['groupname']))
84  {
85    array_push($page['errors'], $lang['group_add_error1']);
86  }
87  if (count($page['errors']) == 0)
88  {
89    // is the group not already existing ?
90    $query = '
91SELECT COUNT(*)
92  FROM '.GROUPS_TABLE.'
93  WHERE name = \''.$_POST['groupname'].'\'
94;';
95    list($count) = mysql_fetch_row(pwg_query($query));
96    if ($count != 0)
97    {
98      array_push($page['errors'], $lang['group_add_error2']);
99    }
100  }
101  if (count($page['errors']) == 0)
102  {
103    // creating the group
104    $query = '
105INSERT INTO '.GROUPS_TABLE.'
106  (name)
107  VALUES
108  (\''.mysql_escape_string($_POST['groupname']).'\')
109;';
110    pwg_query($query);
111
112    array_push(
113      $page['infos'],
114      sprintf(l10n('group "%s" added'), $_POST['groupname'])
115      );
116  }
117}
118
119// +-----------------------------------------------------------------------+
120// |                             template init                             |
121// +-----------------------------------------------------------------------+
122
123$template->set_filenames(array('group_list' => 'admin/group_list.tpl'));
124
125$template->assign_vars(
126  array(
127    'F_ADD_ACTION' => PHPWG_ROOT_PATH.'admin.php?page=group_list'
128    )
129  );
130
131// +-----------------------------------------------------------------------+
132// |                              group list                               |
133// +-----------------------------------------------------------------------+
134
135$query = '
136SELECT id, name
137  FROM '.GROUPS_TABLE.'
138  ORDER BY id ASC
139;';
140$result = pwg_query($query);
141
142$admin_url = PHPWG_ROOT_PATH.'admin.php?page=';
143$perm_url    = $admin_url.'group_perm&amp;group_id=';
144$del_url     = $admin_url.'group_list&amp;delete=';
145$members_url = $admin_url.'user_list&amp;group=';
146
147$num = 0;
148while ($row = mysql_fetch_array($result))
149{
150  $query = '
151SELECT COUNT(*)
152  FROM '.USER_GROUP_TABLE.'
153  WHERE group_id = '.$row['id'].'
154;';
155  list($counter) = mysql_fetch_row(pwg_query($query));
156 
157  $template->assign_block_vars(
158    'group',
159    array(
160      'CLASS' => ($num++ % 2 == 1) ? 'row2' : 'row1',
161      'NAME' => $row['name'],
162      'MEMBERS' => sprintf(l10n('%d members'), $counter),
163      'U_MEMBERS' => $members_url.$row['id'],
164      'U_DELETE' => $del_url.$row['id'],
165      'U_PERM' => $perm_url.$row['id']
166      )
167    );
168}
169
170// +-----------------------------------------------------------------------+
171// |                           sending html code                           |
172// +-----------------------------------------------------------------------+
173
174$template->assign_var_from_handle('ADMIN_CONTENT', 'group_list');
175
176?>
Note: See TracBrowser for help on using the repository browser.