Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
6 kaklik 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: user_perm.php,v $
9
// | last update   : $Date: 2005/01/19 23:36:43 $
10
// | last modifier : $Author: plg $
11
// | revision      : $Revision: 1.18 $
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
 
28
if (!defined('IN_ADMIN'))
29
{
30
  die('Hacking attempt!');
31
}
32
include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
33
 
34
$userdata = array();
35
if (isset($_POST['submituser']))
36
{
37
  $userdata = getuserdata($_POST['username']);
38
}
39
else if (isset($_GET['user_id']))
40
{
41
  $userdata = getuserdata(intval($_GET['user_id']));
42
}
43
else if (isset($_POST['falsify'])
44
         and isset($_POST['cat_true'])
45
         and count($_POST['cat_true']) > 0)
46
{
47
  $userdata = getuserdata(intval($_POST['userid']));
48
  // if you forbid access to a category, all sub-categories become
49
  // automatically forbidden
50
  $subcats = get_subcat_ids($_POST['cat_true']);
51
  $query = '
52
DELETE FROM '.USER_ACCESS_TABLE.'
53
  WHERE user_id = '.$userdata['id'].'
54
    AND cat_id IN ('.implode(',', $subcats).')
55
;';
56
  pwg_query($query);
57
}
58
else if (isset($_POST['trueify'])
59
         and isset($_POST['cat_false'])
60
         and count($_POST['cat_false']) > 0)
61
{
62
  $userdata = getuserdata(intval($_POST['userid']));
63
 
64
  $uppercats = get_uppercat_ids($_POST['cat_false']);
65
  $private_uppercats = array();
66
 
67
  $query = '
68
SELECT id
69
  FROM '.CATEGORIES_TABLE.'
70
  WHERE id IN ('.implode(',', $uppercats).')
71
    AND status = \'private\'
72
;';
73
  $result = pwg_query($query);
74
  while ($row = mysql_fetch_array($result))
75
  {
76
    array_push($private_uppercats, $row['id']);
77
  }
78
 
79
  // retrying to authorize a category which is already authorized may cause
80
  // an error (in SQL statement), so we need to know which categories are
81
  // accesible
82
  $authorized_ids = array();
83
 
84
  $query = '
85
SELECT cat_id
86
  FROM '.USER_ACCESS_TABLE.'
87
  WHERE user_id = '.$userdata['id'].'
88
;';
89
  $result = pwg_query($query);
90
 
91
  while ($row = mysql_fetch_array($result))
92
  {
93
    array_push($authorized_ids, $row['cat_id']);
94
  }
95
 
96
  $inserts = array();
97
  $to_autorize_ids = array_diff($private_uppercats, $authorized_ids);
98
  foreach ($to_autorize_ids as $to_autorize_id)
99
  {
100
    array_push($inserts, array('user_id' => $userdata['id'],
101
                               'cat_id' => $to_autorize_id));
102
  }
103
 
104
  mass_inserts(USER_ACCESS_TABLE, array('user_id','cat_id'), $inserts);
105
}
106
//----------------------------------------------------- template initialization
107
if (empty($userdata))
108
{
109
  $template->set_filenames(array('user' => 'admin/user_perm.tpl'));
110
 
111
  $base_url = PHPWG_ROOT_PATH.'admin.php?page=';
112
 
113
  $template->assign_vars(array(
114
    'L_SELECT_USERNAME'=>$lang['Select_username'],
115
    'L_LOOKUP_USER'=>$lang['Look_up_user'],
116
    'L_FIND_USERNAME'=>$lang['Find_username'],
117
    'L_AUTH_USER'=>$lang['permuser_only_private'],
118
    'L_SUBMIT'=>$lang['submit'],
119
 
120
    'F_SEARCH_USER_ACTION' => add_session_id($base_url.'user_perm'),
121
    'U_SEARCH_USER' => add_session_id(PHPWG_ROOT_PATH.'admin/search.php')
122
    ));
123
}
124
else
125
{
126
  $template->set_filenames(array('user'=>'admin/cat_options.tpl'));
127
  $template->assign_vars(
128
    array(
129
      'L_RESET'=>$lang['reset'],
130
      'L_CAT_OPTIONS_TRUE'=>$lang['authorized'],
131
      'L_CAT_OPTIONS_FALSE'=>$lang['forbidden'],
132
      'L_CAT_OPTIONS_INFO'=>$lang['permuser_info'],
133
 
134
      'HIDDEN_NAME'=> 'userid',
135
      'HIDDEN_VALUE'=>$userdata['id'],
136
      'F_ACTION' => add_session_id(PHPWG_ROOT_PATH.'admin.php?page=user_perm'),
137
      ));
138
 
139
  // only private categories are listed
140
  $query_true = '
141
SELECT id,name,uppercats,global_rank
142
  FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_ACCESS_TABLE.' ON cat_id = id
143
  WHERE status = \'private\'
144
    AND user_id = '.$userdata['id'].'
145
;';
146
  display_select_cat_wrapper($query_true,array(),'category_option_true');
147
 
148
  $result = pwg_query($query_true);
149
  $authorized_ids = array();
150
  while ($row = mysql_fetch_array($result))
151
  {
152
    array_push($authorized_ids, $row['id']);
153
  }
154
 
155
  $query_false = '
156
SELECT id,name,uppercats,global_rank
157
  FROM '.CATEGORIES_TABLE.'
158
  WHERE status = \'private\'';
159
  if (count($authorized_ids) > 0)
160
  {
161
    $query_false.= '
162
    AND id NOT IN ('.implode(',', $authorized_ids).')';
163
  }
164
  $query_false.= '
165
;';
166
  display_select_cat_wrapper($query_false,array(),'category_option_false');
167
}
168
//----------------------------------------------------------- sending html code
169
$template->assign_var_from_handle('ADMIN_CONTENT', 'user');
170
?>