1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
<?php
/***************************************************************************
* user_perm.php *
* ------------------ *
* application : PhpWebGallery 1.3 *
* author : Pierrick LE GALL <pierrick@z0rglub.com> *
* *
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; *
* *
***************************************************************************/
include_once( './include/isadmin.inc.php' );
//----------------------------------------------------- template initialization
$sub = $vtp->Open( '../template/'.$user['template'].'/admin/user_perm.vtp' );
$error = array();
$tpl = array( 'permuser_authorized','permuser_forbidden','submit',
'permuser_parent_forbidden','permuser_info_message',
'adduser_info_back' );
templatize_array( $tpl, 'lang', $sub );
$vtp->setGlobalVar( $sub, 'user_template', $user['template'] );
//--------------------------------------------------------------------- updates
if ( isset( $_POST['submit'] ) )
{
// cleaning the user_access table for this user
$query = 'DELETE FROM '.PREFIX_TABLE.'user_access';
$query.= ' WHERE user_id = '.$_GET['user_id'];
$query.= ';';
mysql_query( $query );
// selecting all private categories
$query = 'SELECT id';
$query.= ' FROM '.PREFIX_TABLE.'categories';
$query.= " WHERE status = 'private'";
$query.= ';';
$result = mysql_query( $query );
while ( $row = mysql_fetch_array( $result ) )
{
$radioname = 'access-'.$row['id'];
if ( $_POST[$radioname] == 0 )
{
$query = 'INSERT INTO '.PREFIX_TABLE.'user_access';
$query.= ' (user_id,cat_id) VALUES';
$query.= ' ('.$_GET['user_id'].','.$row['id'].')';
$query.= ';';
mysql_query ( $query );
}
}
check_favorites( $_GET['user_id'] );
$vtp->addSession( $sub, 'confirmation' );
$url = './admin.php?page=user_list';
$vtp->setVar( $sub, 'confirmation.back_url', add_session_id( $url ) );
$vtp->closeSession( $sub, 'confirmation' );
}
//---------------------------------------------------------------- form display
$restrictions = get_restrictions( $_GET['user_id'], $page['user_status'],
false, false );
$action = './admin.php?page=user_perm&user_id='.$_GET['user_id'];
$vtp->setVar( $sub, 'action', add_session_id( $action ) );
// Association of group_ids with group_names -> caching informations
$query = 'SELECT id,name';
$query.= ' FROM '.PREFIX_TABLE.'groups';
$query.= ';';
$result = mysql_query( $query );
$groups = array();
while ( $row = mysql_fetch_array( $result ) )
{
$groups[$row['id']] = $row['name'];
}
// Listing of groups the user belongs to
$query = 'SELECT ug.group_id as groupid';
$query.= ' FROM '.PREFIX_TABLE.'user_group as ug';
$query.= ' WHERE user_id = '.$_GET['user_id'];
$query.= ';';
$result = mysql_query( $query );
$usergroups = array();
while ( $row = mysql_fetch_array( $result ) )
{
array_push( $usergroups, $row['groupid'] );
}
// only private categories are listed
$query = 'SELECT id';
$query.= ' FROM '.PREFIX_TABLE.'categories';
$query.= " WHERE status = 'private'";
$query.= ';';
$result = mysql_query( $query );
while ( $row = mysql_fetch_array( $result ) )
{
$vtp->addSession( $sub, 'category' );
$vtp->setVar( $sub, 'category.id', $row['id'] );
// we have to know whether the user is authorized to access this
// category. The category can be accessible for this user thanks to his
// personnal access rights OR thanks to the access rights of a group he
// belongs to.
// 1. group access :
// retrieving all authorized groups for this category and for this user
$query = 'SELECT ga.group_id as groupid';
$query.= ' FROM '.PREFIX_TABLE.'group_access as ga';
$query.= ', '.PREFIX_TABLE.'user_group as ug';
$query.= ' WHERE ga.group_id = ug.group_id';
$query.= ' AND ug.user_id = '.$_GET['user_id'];
$query.= ' AND cat_id = '.$row['id'];
$query.= ';';
$subresult = mysql_query( $query );
$authorized_groups = array();
while ( $subrow = mysql_fetch_array( $subresult ) )
{
array_push( $authorized_groups, $subrow['groupid'] );
}
// 2. personnal access
$is_user_allowed = is_user_allowed( $row['id'], $restrictions );
// link to the category permission management
$url = './admin.php?page=cat_perm&cat_id='.$row['id'];
$vtp->setVar( $sub, 'category.cat_perm_link', add_session_id( $url ) );
// color of the category : green if the user is allowed by himself or
// thanks to a group he belongs to
if ( $is_user_allowed == 0 or count( $authorized_groups ) > 0 )
{
$vtp->setVar( $sub, 'category.color', 'green' );
}
else
{
$vtp->setVar( $sub, 'category.color', 'red' );
}
// category name
$cat_infos = get_cat_info( $row['id'] );
$name = get_cat_display_name( $cat_infos['name'],' > ',
'font-weight:bold;' );
$vtp->setVar( $sub, 'category.name', $name );
// usergroups
if ( count( $usergroups ) > 0 )
{
$vtp->addSession( $sub, 'usergroups' );
foreach ( $usergroups as $i => $usergroup ) {
$vtp->addSession( $sub, 'usergroup' );
$vtp->setVar( $sub, 'usergroup.name', $groups[$usergroup] );
$url = './admin.php?page=group_perm&group_id='.$usergroup;
$vtp->setVar( $sub, 'usergroup.url', add_session_id( $url ) );
if ( in_array( $usergroup, $authorized_groups ) )
{
$vtp->setVar( $sub, 'usergroup.color', 'green' );
}
else
{
$vtp->setVar( $sub, 'usergroup.color', 'red' );
}
if ( $i < count( $usergroups ) - 1 )
{
$vtp->setVar( $sub, 'usergroup.separation', ',' );
}
$vtp->closeSession( $sub, 'usergroup' );
}
$vtp->closeSession( $sub, 'usergroups' );
}
// any subcat forbidden for this user ?
if ( $is_user_allowed == 2 )
{
$vtp->addSession( $sub, 'parent_forbidden' );
$vtp->closeSession( $sub, 'parent_forbidden' );
}
// personnal forbidden or authorized access ?
if ( $is_user_allowed == 0 )
{
$vtp->setVar( $sub, 'category.authorized_checked', ' checked="checked"' );
}
else
{
$vtp->setVar( $sub, 'category.forbidden_checked', ' checked="checked"' );
}
$vtp->closeSession( $sub, 'category' );
}
//----------------------------------------------------------- sending html code
$vtp->Parse( $handle , 'sub', $sub );
?>
|