source: trunk/admin/group_perm.php @ 25785

Last change on this file since 25785 was 25018, checked in by mistic100, 11 years ago

remove all array_push (50% slower than []) + some changes missing for feature:2978

  • Property svn:eol-style set to LF
File size: 6.0 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2013 Piwigo Team                  http://piwigo.org |
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// +-----------------------------------------------------------------------+
23
24if( !defined("PHPWG_ROOT_PATH") )
25{
26  die ("Hacking attempt!");
27}
28
29include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
30
31// +-----------------------------------------------------------------------+
32// | Check Access and exit when user status is not ok                      |
33// +-----------------------------------------------------------------------+
34check_status(ACCESS_ADMINISTRATOR);
35
36// +-----------------------------------------------------------------------+
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{
46  die('group_id URL parameter is missing');
47}
48
49// +-----------------------------------------------------------------------+
50// |                                updates                                |
51// +-----------------------------------------------------------------------+
52
53if (isset($_POST['falsify'])
54    and isset($_POST['cat_true'])
55    and count($_POST['cat_true']) > 0)
56{
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
62  FROM '.GROUP_ACCESS_TABLE.'
63  WHERE group_id = '.$page['group'].'
64  AND cat_id IN ('.implode(',', $subcats).')
65;';
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
75  $query = '
76SELECT id
77  FROM '.CATEGORIES_TABLE.'
78  WHERE id IN ('.implode(',', $uppercats).')
79  AND status = \'private\'
80;';
81  $result = pwg_query($query);
82  while ($row = pwg_db_fetch_assoc($result))
83  {
84    $private_uppercats[] = $row['id'];
85  }
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();
91
92  $query = '
93SELECT cat_id
94  FROM '.GROUP_ACCESS_TABLE.'
95  WHERE group_id = '.$page['group'].'
96;';
97  $result = pwg_query($query);
98
99  while ($row = pwg_db_fetch_assoc($result))
100  {
101    $authorized_ids[] = $row['cat_id'];
102  }
103
104  $inserts = array();
105  $to_autorize_ids = array_diff($private_uppercats, $authorized_ids);
106  foreach ($to_autorize_ids as $to_autorize_id)
107  {
108    $inserts[] = array(
109      'group_id' => $page['group'],
110      'cat_id' => $to_autorize_id
111      );
112  }
113
114  mass_inserts(GROUP_ACCESS_TABLE, array('group_id','cat_id'), $inserts);
115}
116
117// +-----------------------------------------------------------------------+
118// |                             template init                             |
119// +-----------------------------------------------------------------------+
120
121$template->set_filenames(
122  array(
123    'group_perm' => 'group_perm.tpl',
124    'double_select' => 'double_select.tpl'
125    )
126  );
127
128$template->assign(
129  array(
130    'TITLE' =>
131      l10n(
132        'Manage permissions for group "%s"',
133        get_groupname($page['group'])
134        ),
135    'L_CAT_OPTIONS_TRUE'=>l10n('Authorized'),
136    'L_CAT_OPTIONS_FALSE'=>l10n('Forbidden'),
137
138    'F_ACTION' =>
139        get_root_url().
140        'admin.php?page=group_perm&amp;group_id='.
141        $page['group']
142    )
143  );
144
145// only private categories are listed
146$query_true = '
147SELECT id,name,uppercats,global_rank
148  FROM '.CATEGORIES_TABLE.' INNER JOIN '.GROUP_ACCESS_TABLE.' ON cat_id = id
149  WHERE status = \'private\'
150    AND group_id = '.$page['group'].'
151;';
152display_select_cat_wrapper($query_true,array(),'category_option_true');
153
154$result = pwg_query($query_true);
155$authorized_ids = array();
156while ($row = pwg_db_fetch_assoc($result))
157{
158  $authorized_ids[] = $row['id'];
159}
160
161$query_false = '
162SELECT id,name,uppercats,global_rank
163  FROM '.CATEGORIES_TABLE.'
164  WHERE status = \'private\'';
165if (count($authorized_ids) > 0)
166{
167  $query_false.= '
168    AND id NOT IN ('.implode(',', $authorized_ids).')';
169}
170$query_false.= '
171;';
172display_select_cat_wrapper($query_false,array(),'category_option_false');
173
174// +-----------------------------------------------------------------------+
175// |                           html code display                           |
176// +-----------------------------------------------------------------------+
177
178$template->assign_var_from_handle('DOUBLE_SELECT', 'double_select');
179$template->assign_var_from_handle('ADMIN_CONTENT', 'group_perm');
180
181?>
Note: See TracBrowser for help on using the repository browser.