source: trunk/admin/user_perm.php @ 1072

Last change on this file since 1072 was 1072, checked in by rub, 18 years ago

Step 2 improvement issue 0000301:

o Add and use Functions Check of status
o Restricted Access for user generic

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.3 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-03-09 22:46:28 +0000 (Thu, 09 Mar 2006) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1072 $
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('IN_ADMIN'))
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['user_id']) and is_numeric($_GET['user_id']))
45{
46  $page['user'] = $_GET['user_id'];
47}
48else
49{
50  echo l10n('user_id URL parameter is missing');
51  exit();
52}
53
54// +-----------------------------------------------------------------------+
55// |                                updates                                |
56// +-----------------------------------------------------------------------+
57
58if (isset($_POST['falsify'])
59    and isset($_POST['cat_true'])
60    and count($_POST['cat_true']) > 0)
61{
62  // if you forbid access to a category, all sub-categories become
63  // automatically forbidden
64  $subcats = get_subcat_ids($_POST['cat_true']);
65  $query = '
66DELETE FROM '.USER_ACCESS_TABLE.'
67  WHERE user_id = '.$page['user'].'
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 '.USER_ACCESS_TABLE.'
99  WHERE user_id = '.$page['user'].'
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($inserts, array('user_id' => $page['user'],
113                               'cat_id' => $to_autorize_id));
114  }
115
116  mass_inserts(USER_ACCESS_TABLE, array('user_id','cat_id'), $inserts);
117}
118
119// +-----------------------------------------------------------------------+
120// |                             template init                             |
121// +-----------------------------------------------------------------------+
122
123$template->set_filenames(
124  array(
125    'user_perm' => 'admin/user_perm.tpl',
126    'double_select' => 'admin/double_select.tpl'
127    )
128  );
129
130$template->assign_vars(
131  array(
132    'TITLE' =>
133      sprintf(
134        l10n('Manage permissions for user "%s"'),
135        get_username($page['user']
136          )
137        ),
138    'L_CAT_OPTIONS_TRUE'=>$lang['authorized'],
139    'L_CAT_OPTIONS_FALSE'=>$lang['forbidden'],
140   
141    'F_ACTION' =>
142        PHPWG_ROOT_PATH.
143        'admin.php?page=user_perm'.
144        '&amp;user_id='.$page['user']
145    )
146  );
147
148
149// retrieve category ids authorized to the groups the user belongs to
150$group_authorized = array();
151
152$query = '
153SELECT DISTINCT cat_id, c.uppercats, c.global_rank
154  FROM '.USER_GROUP_TABLE.' AS ug
155    INNER JOIN '.GROUP_ACCESS_TABLE.' AS ga
156      ON ug.group_id = ga.group_id
157    INNER JOIN '.CATEGORIES_TABLE.' AS c
158      ON c.id = ga.cat_id
159  WHERE ug.user_id = '.$page['user'].'
160;';
161$result = pwg_query($query);
162
163if (mysql_num_rows($result) > 0)
164{
165  $template->assign_block_vars('groups', array());
166
167  $cats = array();
168  while ($row = mysql_fetch_array($result))
169  {
170    array_push($cats, $row);
171    array_push($group_authorized, $row['cat_id']);
172  }
173  usort($cats, 'global_rank_compare');
174
175  foreach ($cats as $category)
176  {
177    $template->assign_block_vars(
178      'groups.category',
179      array(
180        'NAME' => get_cat_display_name_cache($category['uppercats'], '', false)
181        )
182      );
183  }
184}
185
186// only private categories are listed
187$query_true = '
188SELECT id,name,uppercats,global_rank
189  FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_ACCESS_TABLE.' ON cat_id = id
190  WHERE status = \'private\'
191    AND user_id = '.$page['user'];
192if (count($group_authorized) > 0)
193{
194  $query_true.= '
195    AND cat_id NOT IN ('.implode(',', $group_authorized).')';
196}
197$query_true.= '
198;';
199display_select_cat_wrapper($query_true,array(),'category_option_true');
200 
201$result = pwg_query($query_true);
202$authorized_ids = array();
203while ($row = mysql_fetch_array($result))
204{
205  array_push($authorized_ids, $row['id']);
206}
207
208$query_false = '
209SELECT id,name,uppercats,global_rank
210  FROM '.CATEGORIES_TABLE.'
211  WHERE status = \'private\'';
212if (count($authorized_ids) > 0)
213{
214  $query_false.= '
215    AND id NOT IN ('.implode(',', $authorized_ids).')';
216}
217if (count($group_authorized) > 0)
218{
219  $query_false.= '
220    AND id NOT IN ('.implode(',', $group_authorized).')';
221}
222$query_false.= '
223;';
224display_select_cat_wrapper($query_false,array(),'category_option_false');
225
226// +-----------------------------------------------------------------------+
227// |                           sending html code                           |
228// +-----------------------------------------------------------------------+
229
230$template->assign_var_from_handle('DOUBLE_SELECT', 'double_select');
231$template->assign_var_from_handle('ADMIN_CONTENT', 'user_perm');
232?>
Note: See TracBrowser for help on using the repository browser.