source: trunk/admin/group_perm.php @ 27558

Last change on this file since 27558 was 26461, checked in by mistic100, 10 years ago

Update headers to 2014. Happy new year!!

  • 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// +-----------------------------------------------------------------------+
[26461]5// | Copyright(C) 2008-2014 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// +-----------------------------------------------------------------------+
[815]23
[671]24if( !defined("PHPWG_ROOT_PATH") )
25{
[815]26  die ("Hacking attempt!");
[671]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['group_id']) and is_numeric($_GET['group_id']))
41{
42  $page['group'] = $_GET['group_id'];
43}
44else
45{
[2268]46  die('group_id URL parameter is missing');
[815]47}
48
49// +-----------------------------------------------------------------------+
50// |                                updates                                |
51// +-----------------------------------------------------------------------+
52
[671]53if (isset($_POST['falsify'])
[815]54    and isset($_POST['cat_true'])
55    and count($_POST['cat_true']) > 0)
[21]56{
[671]57  // if you forbid access to a category, all sub-categories become
58  // automatically forbidden
59  $subcats = get_subcat_ids($_POST['cat_true']);
[815]60  $query = '
61DELETE
62  FROM '.GROUP_ACCESS_TABLE.'
63  WHERE group_id = '.$page['group'].'
64  AND cat_id IN ('.implode(',', $subcats).')
65;';
[671]66  pwg_query($query);
67}
68else if (isset($_POST['trueify'])
69         and isset($_POST['cat_false'])
70         and count($_POST['cat_false']) > 0)
71{
72  $uppercats = get_uppercat_ids($_POST['cat_false']);
73  $private_uppercats = array();
74
[815]75  $query = '
76SELECT id
77  FROM '.CATEGORIES_TABLE.'
78  WHERE id IN ('.implode(',', $uppercats).')
79  AND status = \'private\'
80;';
[671]81  $result = pwg_query($query);
[4325]82  while ($row = pwg_db_fetch_assoc($result))
[21]83  {
[25018]84    $private_uppercats[] = $row['id'];
[21]85  }
[671]86
87  // retrying to authorize a category which is already authorized may cause
88  // an error (in SQL statement), so we need to know which categories are
89  // accesible
90  $authorized_ids = array();
[2268]91
[815]92  $query = '
93SELECT cat_id
[671]94  FROM '.GROUP_ACCESS_TABLE.'
[815]95  WHERE group_id = '.$page['group'].'
96;';
[671]97  $result = pwg_query($query);
[2268]98
[4325]99  while ($row = pwg_db_fetch_assoc($result))
[170]100  {
[25018]101    $authorized_ids[] = $row['cat_id'];
[170]102  }
[2268]103
[671]104  $inserts = array();
105  $to_autorize_ids = array_diff($private_uppercats, $authorized_ids);
106  foreach ($to_autorize_ids as $to_autorize_id)
107  {
[25018]108    $inserts[] = array(
109      'group_id' => $page['group'],
110      'cat_id' => $to_autorize_id
[815]111      );
[671]112  }
113
114  mass_inserts(GROUP_ACCESS_TABLE, array('group_id','cat_id'), $inserts);
[25975]115  invalidate_user_cache();
[21]116}
[671]117
[815]118// +-----------------------------------------------------------------------+
119// |                             template init                             |
120// +-----------------------------------------------------------------------+
[671]121
[817]122$template->set_filenames(
123  array(
[2530]124    'group_perm' => 'group_perm.tpl',
125    'double_select' => 'double_select.tpl'
[817]126    )
127  );
[671]128
[2273]129$template->assign(
[815]130  array(
[817]131    'TITLE' =>
[25005]132      l10n(
133        'Manage permissions for group "%s"',
134        get_groupname($page['group'])
[817]135        ),
[5021]136    'L_CAT_OPTIONS_TRUE'=>l10n('Authorized'),
137    'L_CAT_OPTIONS_FALSE'=>l10n('Forbidden'),
[2268]138
[815]139    'F_ACTION' =>
[2273]140        get_root_url().
[817]141        'admin.php?page=group_perm&amp;group_id='.
142        $page['group']
[815]143    )
144  );
[2268]145
[815]146// only private categories are listed
147$query_true = '
[671]148SELECT id,name,uppercats,global_rank
149  FROM '.CATEGORIES_TABLE.' INNER JOIN '.GROUP_ACCESS_TABLE.' ON cat_id = id
150  WHERE status = \'private\'
[815]151    AND group_id = '.$page['group'].'
[671]152;';
[815]153display_select_cat_wrapper($query_true,array(),'category_option_true');
154
155$result = pwg_query($query_true);
156$authorized_ids = array();
[4325]157while ($row = pwg_db_fetch_assoc($result))
[815]158{
[25018]159  $authorized_ids[] = $row['id'];
[815]160}
161
162$query_false = '
[671]163SELECT id,name,uppercats,global_rank
164  FROM '.CATEGORIES_TABLE.'
165  WHERE status = \'private\'';
[815]166if (count($authorized_ids) > 0)
167{
168  $query_false.= '
[671]169    AND id NOT IN ('.implode(',', $authorized_ids).')';
[815]170}
171$query_false.= '
[671]172;';
[815]173display_select_cat_wrapper($query_false,array(),'category_option_false');
[671]174
[815]175// +-----------------------------------------------------------------------+
176// |                           html code display                           |
177// +-----------------------------------------------------------------------+
178
[817]179$template->assign_var_from_handle('DOUBLE_SELECT', 'double_select');
[815]180$template->assign_var_from_handle('ADMIN_CONTENT', 'group_perm');
181
[362]182?>
Note: See TracBrowser for help on using the repository browser.