source: trunk/admin/user_perm.php @ 24061

Last change on this file since 24061 was 22950, checked in by plg, 11 years ago

merge r22949 from branch 2.5 to trunk

bug 2909 fixed: make sure the selection of private album is not empty before
adding permission to user. The good test had been removed in r11729

  • Property svn:eol-style set to LF
File size: 6.0 KB
RevLine 
[21]1<?php
[362]2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[19703]5// | Copyright(C) 2008-2013 Piwigo Team                  http://piwigo.org |
[2297]6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
[393]23
[657]24if (!defined('IN_ADMIN'))
[393]25{
[657]26  die('Hacking attempt!');
[393]27}
28
[1072]29include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
30
[815]31// +-----------------------------------------------------------------------+
[1072]32// | Check Access and exit when user status is not ok                      |
33// +-----------------------------------------------------------------------+
34check_status(ACCESS_ADMINISTRATOR);
35
36// +-----------------------------------------------------------------------+
[815]37// |                            variables init                             |
38// +-----------------------------------------------------------------------+
39
40if (isset($_GET['user_id']) and is_numeric($_GET['user_id']))
[393]41{
[815]42  $page['user'] = $_GET['user_id'];
[393]43}
[815]44else
[709]45{
[1754]46  die('user_id URL parameter is missing');
[709]47}
[815]48
49// +-----------------------------------------------------------------------+
50// |                                updates                                |
51// +-----------------------------------------------------------------------+
52
53if (isset($_POST['falsify'])
54    and isset($_POST['cat_true'])
55    and count($_POST['cat_true']) > 0)
[393]56{
[657]57  // if you forbid access to a category, all sub-categories become
58  // automatically forbidden
59  $subcats = get_subcat_ids($_POST['cat_true']);
60  $query = '
61DELETE FROM '.USER_ACCESS_TABLE.'
[815]62  WHERE user_id = '.$page['user'].'
[657]63    AND cat_id IN ('.implode(',', $subcats).')
64;';
65  pwg_query($query);
66}
[22950]67elseif (isset($_POST['trueify'])
68    and isset($_POST['cat_false'])
69    and count($_POST['cat_false']) > 0)
[657]70{
[11729]71  add_permission_on_category($_POST['cat_false'], $page['user']);
[21]72}
[655]73
[817]74// +-----------------------------------------------------------------------+
75// |                             template init                             |
76// +-----------------------------------------------------------------------+
77
78$template->set_filenames(
79  array(
[2530]80    'user_perm' => 'user_perm.tpl',
81    'double_select' => 'double_select.tpl'
[817]82    )
83  );
84
[2225]85$template->assign(
[815]86  array(
[817]87    'TITLE' =>
88      sprintf(
[5206]89        l10n('Manage permissions for user "%s"'),
[817]90        get_username($page['user']
91          )
92        ),
[5021]93    'L_CAT_OPTIONS_TRUE'=>l10n('Authorized'),
94    'L_CAT_OPTIONS_FALSE'=>l10n('Forbidden'),
[1092]95
[815]96    'F_ACTION' =>
97        PHPWG_ROOT_PATH.
98        'admin.php?page=user_perm'.
99        '&amp;user_id='.$page['user']
100    )
101  );
[655]102
[818]103
104// retrieve category ids authorized to the groups the user belongs to
105$group_authorized = array();
106
107$query = '
108SELECT DISTINCT cat_id, c.uppercats, c.global_rank
109  FROM '.USER_GROUP_TABLE.' AS ug
110    INNER JOIN '.GROUP_ACCESS_TABLE.' AS ga
111      ON ug.group_id = ga.group_id
112    INNER JOIN '.CATEGORIES_TABLE.' AS c
113      ON c.id = ga.cat_id
114  WHERE ug.user_id = '.$page['user'].'
115;';
116$result = pwg_query($query);
117
[4325]118if (pwg_db_num_rows($result) > 0)
[818]119{
120  $cats = array();
[4325]121  while ($row = pwg_db_fetch_assoc($result))
[818]122  {
123    array_push($cats, $row);
124    array_push($group_authorized, $row['cat_id']);
125  }
126  usort($cats, 'global_rank_compare');
127
128  foreach ($cats as $category)
129  {
[2225]130    $template->append(
131      'categories_because_of_groups',
132      get_cat_display_name_cache($category['uppercats'], null, false)
[818]133      );
134  }
135}
136
[815]137// only private categories are listed
138$query_true = '
[657]139SELECT id,name,uppercats,global_rank
140  FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_ACCESS_TABLE.' ON cat_id = id
141  WHERE status = \'private\'
[818]142    AND user_id = '.$page['user'];
143if (count($group_authorized) > 0)
144{
145  $query_true.= '
146    AND cat_id NOT IN ('.implode(',', $group_authorized).')';
147}
148$query_true.= '
[657]149;';
[815]150display_select_cat_wrapper($query_true,array(),'category_option_true');
[1092]151
[815]152$result = pwg_query($query_true);
153$authorized_ids = array();
[4325]154while ($row = pwg_db_fetch_assoc($result))
[815]155{
156  array_push($authorized_ids, $row['id']);
157}
158
159$query_false = '
[657]160SELECT id,name,uppercats,global_rank
161  FROM '.CATEGORIES_TABLE.'
162  WHERE status = \'private\'';
[815]163if (count($authorized_ids) > 0)
164{
165  $query_false.= '
[657]166    AND id NOT IN ('.implode(',', $authorized_ids).')';
[815]167}
[818]168if (count($group_authorized) > 0)
169{
170  $query_false.= '
171    AND id NOT IN ('.implode(',', $group_authorized).')';
172}
[815]173$query_false.= '
[657]174;';
[815]175display_select_cat_wrapper($query_false,array(),'category_option_false');
176
[817]177// +-----------------------------------------------------------------------+
178// |                           sending html code                           |
179// +-----------------------------------------------------------------------+
[815]180
[817]181$template->assign_var_from_handle('DOUBLE_SELECT', 'double_select');
[815]182$template->assign_var_from_handle('ADMIN_CONTENT', 'user_perm');
[362]183?>
Note: See TracBrowser for help on using the repository browser.