source: trunk/admin/group_perm.php @ 2268

Last change on this file since 2268 was 2268, checked in by rvelices, 16 years ago
  • security fix (profile)
  • les langues a la hache
  • fix some copy/paste errors
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 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: 2008-03-08 12:38:09 +0000 (Sat, 08 Mar 2008) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 2268 $
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}
32
33include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
34
35// +-----------------------------------------------------------------------+
36// | Check Access and exit when user status is not ok                      |
37// +-----------------------------------------------------------------------+
38check_status(ACCESS_ADMINISTRATOR);
39
40// +-----------------------------------------------------------------------+
41// |                            variables init                             |
42// +-----------------------------------------------------------------------+
43
44if (isset($_GET['group_id']) and is_numeric($_GET['group_id']))
45{
46  $page['group'] = $_GET['group_id'];
47}
48else
49{
50  die('group_id URL parameter is missing');
51}
52
53// +-----------------------------------------------------------------------+
54// |                                updates                                |
55// +-----------------------------------------------------------------------+
56
57if (isset($_POST['falsify'])
58    and isset($_POST['cat_true'])
59    and count($_POST['cat_true']) > 0)
60{
61  // if you forbid access to a category, all sub-categories become
62  // automatically forbidden
63  $subcats = get_subcat_ids($_POST['cat_true']);
64  $query = '
65DELETE
66  FROM '.GROUP_ACCESS_TABLE.'
67  WHERE group_id = '.$page['group'].'
68  AND cat_id IN ('.implode(',', $subcats).')
69;';
70  pwg_query($query);
71}
72else if (isset($_POST['trueify'])
73         and isset($_POST['cat_false'])
74         and count($_POST['cat_false']) > 0)
75{
76  $uppercats = get_uppercat_ids($_POST['cat_false']);
77  $private_uppercats = array();
78
79  $query = '
80SELECT id
81  FROM '.CATEGORIES_TABLE.'
82  WHERE id IN ('.implode(',', $uppercats).')
83  AND status = \'private\'
84;';
85  $result = pwg_query($query);
86  while ($row = mysql_fetch_array($result))
87  {
88    array_push($private_uppercats, $row['id']);
89  }
90
91  // retrying to authorize a category which is already authorized may cause
92  // an error (in SQL statement), so we need to know which categories are
93  // accesible
94  $authorized_ids = array();
95
96  $query = '
97SELECT cat_id
98  FROM '.GROUP_ACCESS_TABLE.'
99  WHERE group_id = '.$page['group'].'
100;';
101  $result = pwg_query($query);
102
103  while ($row = mysql_fetch_array($result))
104  {
105    array_push($authorized_ids, $row['cat_id']);
106  }
107
108  $inserts = array();
109  $to_autorize_ids = array_diff($private_uppercats, $authorized_ids);
110  foreach ($to_autorize_ids as $to_autorize_id)
111  {
112    array_push(
113      $inserts,
114      array(
115        'group_id' => $page['group'],
116        'cat_id' => $to_autorize_id
117        )
118      );
119  }
120
121  mass_inserts(GROUP_ACCESS_TABLE, array('group_id','cat_id'), $inserts);
122}
123
124// +-----------------------------------------------------------------------+
125// |                             template init                             |
126// +-----------------------------------------------------------------------+
127
128$template->set_filenames(
129  array(
130    'group_perm' => 'admin/group_perm.tpl',
131    'double_select' => 'admin/double_select.tpl'
132    )
133  );
134
135$template->assign_vars(
136  array(
137    'TITLE' =>
138      sprintf(
139        l10n('Manage permissions for group "%s"'),
140        get_groupname($page['group']
141          )
142        ),
143    'L_CAT_OPTIONS_TRUE'=>l10n('authorized'),
144    'L_CAT_OPTIONS_FALSE'=>l10n('forbidden'),
145    'L_CAT_OPTIONS_INFO'=>l10n('permuser_info'),
146
147    'F_ACTION' =>
148        PHPWG_ROOT_PATH.
149        'admin.php?page=group_perm&amp;group_id='.
150        $page['group']
151    )
152  );
153
154// only private categories are listed
155$query_true = '
156SELECT id,name,uppercats,global_rank
157  FROM '.CATEGORIES_TABLE.' INNER JOIN '.GROUP_ACCESS_TABLE.' ON cat_id = id
158  WHERE status = \'private\'
159    AND group_id = '.$page['group'].'
160;';
161display_select_cat_wrapper($query_true,array(),'category_option_true');
162
163$result = pwg_query($query_true);
164$authorized_ids = array();
165while ($row = mysql_fetch_array($result))
166{
167  array_push($authorized_ids, $row['id']);
168}
169
170$query_false = '
171SELECT id,name,uppercats,global_rank
172  FROM '.CATEGORIES_TABLE.'
173  WHERE status = \'private\'';
174if (count($authorized_ids) > 0)
175{
176  $query_false.= '
177    AND id NOT IN ('.implode(',', $authorized_ids).')';
178}
179$query_false.= '
180;';
181display_select_cat_wrapper($query_false,array(),'category_option_false');
182
183// +-----------------------------------------------------------------------+
184// |                           html code display                           |
185// +-----------------------------------------------------------------------+
186
187$template->assign_var_from_handle('DOUBLE_SELECT', 'double_select');
188$template->assign_var_from_handle('ADMIN_CONTENT', 'group_perm');
189
190?>
Note: See TracBrowser for help on using the repository browser.