source: trunk/admin/user_perm.php @ 657

Last change on this file since 657 was 657, checked in by plg, 19 years ago
  • user permissions ask update at each admin page generation. Table user_forbidden must be updated only if current user is not in administrative section
  • bug fixed : category.php, error on page title when non category selected
  • admin/search : bug on variable $PHP_SELF, replaced by $_SERVERPHP_SELF
  • admin/user_perm : inheritence management. When a category become authorized, all parent categories become authorized, when a category become forbidden, all child category become forbidden
  • no more recursivity in delete_categories function
  • new function get_fs_directories for future new method of synchronization
  • new function get_uppercat_ids replacing several pieces of code doing the same
  • new function get_fulldirs used for metadata function get_filelist and future new method of synchronization
  • new function get_fs for future new method of synchronization
  • typo correction on lang item "about_message"
  • no link to category privacy status management on user permission anymore (giving the menu item instead)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 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-2004 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-12-25 19:33:36 +0000 (Sat, 25 Dec 2004) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 657 $
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}
32include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
33
34$userdata = array();
35if (isset($_POST['submituser']))
36{
37  $userdata = getuserdata($_POST['username']);
38}
39else if (isset($_POST['falsify'])
40         and isset($_POST['cat_true'])
41         and count($_POST['cat_true']) > 0)
42{
43  $userdata = getuserdata(intval($_POST['userid']));
44  // if you forbid access to a category, all sub-categories become
45  // automatically forbidden
46  $subcats = get_subcat_ids($_POST['cat_true']);
47  $query = '
48DELETE FROM '.USER_ACCESS_TABLE.'
49  WHERE user_id = '.$userdata['id'].'
50    AND cat_id IN ('.implode(',', $subcats).')
51;';
52  pwg_query($query);
53}
54else if (isset($_POST['trueify'])
55         and isset($_POST['cat_false'])
56         and count($_POST['cat_false']) > 0)
57{
58  $userdata = getuserdata(intval($_POST['userid']));
59   
60  $uppercats = get_uppercat_ids($_POST['cat_false']);
61  $private_uppercats = array();
62
63  $query = '
64SELECT id
65  FROM '.CATEGORIES_TABLE.'
66  WHERE id IN ('.implode(',', $uppercats).')
67    AND status = \'private\'
68;';
69  $result = pwg_query($query);
70  while ($row = mysql_fetch_array($result))
71  {
72    array_push($private_uppercats, $row['id']);
73  }
74
75  // retrying to authorize a category which is already authorized may cause
76  // an error (in SQL statement), so we need to know which categories are
77  // accesible
78  $authorized_ids = array();
79   
80  $query = '
81SELECT cat_id
82  FROM '.USER_ACCESS_TABLE.'
83  WHERE user_id = '.$userdata['id'].'
84;';
85  $result = pwg_query($query);
86 
87  while ($row = mysql_fetch_array($result))
88  {
89    array_push($authorized_ids, $row['cat_id']);
90  }
91 
92  $inserts = array();
93  $to_autorize_ids = array_diff($private_uppercats, $authorized_ids);
94  foreach ($to_autorize_ids as $to_autorize_id)
95  {
96    array_push($inserts, array('user_id' => $userdata['id'],
97                               'cat_id' => $to_autorize_id));
98  }
99
100  mass_inserts(USER_ACCESS_TABLE, array('user_id','cat_id'), $inserts);
101}
102//----------------------------------------------------- template initialization
103if (empty($userdata))
104{
105  $template->set_filenames(array('user' => 'admin/user_perm.tpl'));
106
107  $base_url = PHPWG_ROOT_PATH.'admin.php?page=';
108 
109  $template->assign_vars(array(
110    'L_SELECT_USERNAME'=>$lang['Select_username'],
111    'L_LOOKUP_USER'=>$lang['Look_up_user'],
112    'L_FIND_USERNAME'=>$lang['Find_username'],
113    'L_AUTH_USER'=>$lang['permuser_only_private'],
114    'L_SUBMIT'=>$lang['submit'],
115
116    'F_SEARCH_USER_ACTION' => add_session_id($base_url.'user_perm'),
117    'U_SEARCH_USER' => add_session_id(PHPWG_ROOT_PATH.'admin/search.php')
118    ));
119}
120else
121{
122  $template->set_filenames(array('user'=>'admin/cat_options.tpl'));
123  $template->assign_vars(
124    array(
125      'L_RESET'=>$lang['reset'],
126      'L_CAT_OPTIONS_TRUE'=>$lang['authorized'],
127      'L_CAT_OPTIONS_FALSE'=>$lang['forbidden'],
128      'L_CAT_OPTIONS_INFO'=>$lang['permuser_info'],
129     
130      'HIDDEN_NAME'=> 'userid',
131      'HIDDEN_VALUE'=>$userdata['id'],
132      'F_ACTION' => add_session_id(PHPWG_ROOT_PATH.'admin.php?page=user_perm'),
133      ));
134
135  // only private categories are listed
136  $query_true = '
137SELECT id,name,uppercats,global_rank
138  FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_ACCESS_TABLE.' ON cat_id = id
139  WHERE status = \'private\'
140    AND user_id = '.$userdata['id'].'
141;';
142  display_select_cat_wrapper($query_true,array(),'category_option_true');
143 
144  $result = pwg_query($query_true);
145  $authorized_ids = array();
146  while ($row = mysql_fetch_array($result))
147  {
148    array_push($authorized_ids, $row['id']);
149  }
150 
151  $query_false = '
152SELECT id,name,uppercats,global_rank
153  FROM '.CATEGORIES_TABLE.'
154  WHERE status = \'private\'';
155  if (count($authorized_ids) > 0)
156  {
157    $query_false.= '
158    AND id NOT IN ('.implode(',', $authorized_ids).')';
159  }
160  $query_false.= '
161;';
162  display_select_cat_wrapper($query_false,array(),'category_option_false');
163}
164//----------------------------------------------------------- sending html code
165$template->assign_var_from_handle('ADMIN_CONTENT', 'user');
166?>
Note: See TracBrowser for help on using the repository browser.