source: trunk/admin/group_perm.php @ 1878

Last change on this file since 1878 was 1072, checked in by rub, 19 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: 6.2 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("PHPWG_ROOT_PATH") )
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['group_id']) and is_numeric($_GET['group_id']))
45{
46  $page['group'] = $_GET['group_id'];
47}
48else
49{
50  echo l10n('group_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
67  FROM '.GROUP_ACCESS_TABLE.'
68  WHERE group_id = '.$page['group'].'
69  AND cat_id IN ('.implode(',', $subcats).')
70;';
71  pwg_query($query);
72}
73else if (isset($_POST['trueify'])
74         and isset($_POST['cat_false'])
75         and count($_POST['cat_false']) > 0)
76{
77  $uppercats = get_uppercat_ids($_POST['cat_false']);
78  $private_uppercats = array();
79
80  $query = '
81SELECT id
82  FROM '.CATEGORIES_TABLE.'
83  WHERE id IN ('.implode(',', $uppercats).')
84  AND status = \'private\'
85;';
86  $result = pwg_query($query);
87  while ($row = mysql_fetch_array($result))
88  {
89    array_push($private_uppercats, $row['id']);
90  }
91
92  // retrying to authorize a category which is already authorized may cause
93  // an error (in SQL statement), so we need to know which categories are
94  // accesible
95  $authorized_ids = array();
96   
97  $query = '
98SELECT cat_id
99  FROM '.GROUP_ACCESS_TABLE.'
100  WHERE group_id = '.$page['group'].'
101;';
102  $result = pwg_query($query);
103 
104  while ($row = mysql_fetch_array($result))
105  {
106    array_push($authorized_ids, $row['cat_id']);
107  }
108 
109  $inserts = array();
110  $to_autorize_ids = array_diff($private_uppercats, $authorized_ids);
111  foreach ($to_autorize_ids as $to_autorize_id)
112  {
113    array_push(
114      $inserts,
115      array(
116        'group_id' => $page['group'],
117        'cat_id' => $to_autorize_id
118        )
119      );
120  }
121
122  mass_inserts(GROUP_ACCESS_TABLE, array('group_id','cat_id'), $inserts);
123}
124
125// +-----------------------------------------------------------------------+
126// |                             template init                             |
127// +-----------------------------------------------------------------------+
128
129$template->set_filenames(
130  array(
131    'group_perm' => 'admin/group_perm.tpl',
132    'double_select' => 'admin/double_select.tpl'
133    )
134  );
135
136$template->assign_vars(
137  array(
138    'TITLE' =>
139      sprintf(
140        l10n('Manage permissions for group "%s"'),
141        get_groupname($page['group']
142          )
143        ),
144    'L_CAT_OPTIONS_TRUE'=>$lang['authorized'],
145    'L_CAT_OPTIONS_FALSE'=>$lang['forbidden'],
146    'L_CAT_OPTIONS_INFO'=>$lang['permuser_info'],
147   
148    'F_ACTION' =>
149        PHPWG_ROOT_PATH.
150        'admin.php?page=group_perm&amp;group_id='.
151        $page['group']
152    )
153  );
154 
155// only private categories are listed
156$query_true = '
157SELECT id,name,uppercats,global_rank
158  FROM '.CATEGORIES_TABLE.' INNER JOIN '.GROUP_ACCESS_TABLE.' ON cat_id = id
159  WHERE status = \'private\'
160    AND group_id = '.$page['group'].'
161;';
162display_select_cat_wrapper($query_true,array(),'category_option_true');
163
164$result = pwg_query($query_true);
165$authorized_ids = array();
166while ($row = mysql_fetch_array($result))
167{
168  array_push($authorized_ids, $row['id']);
169}
170
171$query_false = '
172SELECT id,name,uppercats,global_rank
173  FROM '.CATEGORIES_TABLE.'
174  WHERE status = \'private\'';
175if (count($authorized_ids) > 0)
176{
177  $query_false.= '
178    AND id NOT IN ('.implode(',', $authorized_ids).')';
179}
180$query_false.= '
181;';
182display_select_cat_wrapper($query_false,array(),'category_option_false');
183
184// +-----------------------------------------------------------------------+
185// |                           html code display                           |
186// +-----------------------------------------------------------------------+
187
188$template->assign_var_from_handle('DOUBLE_SELECT', 'double_select');
189$template->assign_var_from_handle('ADMIN_CONTENT', 'group_perm');
190
191?>
Note: See TracBrowser for help on using the repository browser.