source: trunk/admin/group_perm.php @ 1565

Last change on this file since 1565 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
RevLine 
[21]1<?php
[362]2// +-----------------------------------------------------------------------+
[593]3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
[675]5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
[362]6// +-----------------------------------------------------------------------+
[593]7// | branch        : BSF (Best So Far)
[362]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// +-----------------------------------------------------------------------+
[815]27
[671]28if( !defined("PHPWG_ROOT_PATH") )
29{
[815]30  die ("Hacking attempt!");
[671]31}
32
[1072]33include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
34
[815]35// +-----------------------------------------------------------------------+
[1072]36// | Check Access and exit when user status is not ok                      |
37// +-----------------------------------------------------------------------+
38check_status(ACCESS_ADMINISTRATOR);
39
40// +-----------------------------------------------------------------------+
[815]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
[671]58if (isset($_POST['falsify'])
[815]59    and isset($_POST['cat_true'])
60    and count($_POST['cat_true']) > 0)
[21]61{
[671]62  // if you forbid access to a category, all sub-categories become
63  // automatically forbidden
64  $subcats = get_subcat_ids($_POST['cat_true']);
[815]65  $query = '
66DELETE
67  FROM '.GROUP_ACCESS_TABLE.'
68  WHERE group_id = '.$page['group'].'
69  AND cat_id IN ('.implode(',', $subcats).')
70;';
[671]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
[815]80  $query = '
81SELECT id
82  FROM '.CATEGORIES_TABLE.'
83  WHERE id IN ('.implode(',', $uppercats).')
84  AND status = \'private\'
85;';
[671]86  $result = pwg_query($query);
87  while ($row = mysql_fetch_array($result))
[21]88  {
[671]89    array_push($private_uppercats, $row['id']);
[21]90  }
[671]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   
[815]97  $query = '
98SELECT cat_id
[671]99  FROM '.GROUP_ACCESS_TABLE.'
[815]100  WHERE group_id = '.$page['group'].'
101;';
[671]102  $result = pwg_query($query);
103 
104  while ($row = mysql_fetch_array($result))
[170]105  {
[671]106    array_push($authorized_ids, $row['cat_id']);
[170]107  }
[671]108 
109  $inserts = array();
110  $to_autorize_ids = array_diff($private_uppercats, $authorized_ids);
111  foreach ($to_autorize_ids as $to_autorize_id)
112  {
[815]113    array_push(
114      $inserts,
115      array(
116        'group_id' => $page['group'],
117        'cat_id' => $to_autorize_id
118        )
119      );
[671]120  }
121
122  mass_inserts(GROUP_ACCESS_TABLE, array('group_id','cat_id'), $inserts);
[21]123}
[671]124
[815]125// +-----------------------------------------------------------------------+
126// |                             template init                             |
127// +-----------------------------------------------------------------------+
[671]128
[817]129$template->set_filenames(
130  array(
131    'group_perm' => 'admin/group_perm.tpl',
132    'double_select' => 'admin/double_select.tpl'
133    )
134  );
[671]135
[815]136$template->assign_vars(
137  array(
[817]138    'TITLE' =>
139      sprintf(
140        l10n('Manage permissions for group "%s"'),
141        get_groupname($page['group']
142          )
143        ),
[815]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' =>
[817]149        PHPWG_ROOT_PATH.
150        'admin.php?page=group_perm&amp;group_id='.
151        $page['group']
[815]152    )
153  );
[671]154 
[815]155// only private categories are listed
156$query_true = '
[671]157SELECT id,name,uppercats,global_rank
158  FROM '.CATEGORIES_TABLE.' INNER JOIN '.GROUP_ACCESS_TABLE.' ON cat_id = id
159  WHERE status = \'private\'
[815]160    AND group_id = '.$page['group'].'
[671]161;';
[815]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 = '
[671]172SELECT id,name,uppercats,global_rank
173  FROM '.CATEGORIES_TABLE.'
174  WHERE status = \'private\'';
[815]175if (count($authorized_ids) > 0)
176{
177  $query_false.= '
[671]178    AND id NOT IN ('.implode(',', $authorized_ids).')';
[815]179}
180$query_false.= '
[671]181;';
[815]182display_select_cat_wrapper($query_false,array(),'category_option_false');
[671]183
[815]184// +-----------------------------------------------------------------------+
185// |                           html code display                           |
186// +-----------------------------------------------------------------------+
187
[817]188$template->assign_var_from_handle('DOUBLE_SELECT', 'double_select');
[815]189$template->assign_var_from_handle('ADMIN_CONTENT', 'group_perm');
190
[362]191?>
Note: See TracBrowser for help on using the repository browser.