source: trunk/admin/cat_perm.php @ 226

Last change on this file since 226 was 226, checked in by z0rglub, 20 years ago

Modifying ./include/isadmin.inc.php in ./admin/include/isadmin.inc.php since admin.php has moved to the PhpWebGallery root directory

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.9 KB
Line 
1<?php
2/***************************************************************************
3 *                               cat_perm.php                              *
4 *                            ------------------                           *
5 *   application   : PhpWebGallery 1.3 <http://phpwebgallery.net>          *
6 *   author        : Pierrick LE GALL <pierrick@z0rglub.com>               *
7 *                                                                         *
8 *   $Id: cat_perm.php 226 2003-11-03 20:59:40Z z0rglub $
9 *                                                                         *
10 ***************************************************************************/
11
12/***************************************************************************
13 *                                                                         *
14 *   This program is free software; you can redistribute it and/or modify  *
15 *   it under the terms of the GNU General Public License as published by  *
16 *   the Free Software Foundation;                                         *
17 *                                                                         *
18 ***************************************************************************/
19include_once( './admin/include/isadmin.inc.php' );
20//----------------------------------------------------- template initialization
21$sub = $vtp->Open( './template/'.$user['template'].'/admin/cat_perm.vtp' );
22$error = array();
23$tpl = array( 'permuser_authorized','permuser_forbidden','menu_groups',
24              'submit','menu_users','permuser_parent_forbidden' );
25templatize_array( $tpl, 'lang', $sub );
26$vtp->setGlobalVar( $sub, 'user_template', $user['template'] );
27//-------------------------------------------------------------- category infos
28if ( isset( $_GET['cat_id'] ) )
29{
30  check_cat_id( $_GET['cat_id'] );
31  if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) )
32  {
33    $result = get_cat_info( $page['cat'] );
34    $page['cat_name']    = $result['name'];
35    $page['id_uppercat'] = $result['id_uppercat'];
36  }
37}
38//---------------------------------------------------------- permission updates
39if ( isset( $_POST['submit'] ) )
40{
41  // groups access update
42  $query = 'DELETE';
43  $query.= ' FROM '.PREFIX_TABLE.'group_access';
44  $query.= ' WHERE cat_id = '.$page['cat'];
45  $query.= ';';
46  mysql_query( $query );
47  $query = 'SELECT id';
48  $query.= ' FROM '.PREFIX_TABLE.'groups';
49  $query.= ';';
50  $result = mysql_query( $query );
51  while ( $row = mysql_fetch_array( $result ) )
52  {
53    $radioname = 'groupaccess-'.$row['id'];
54    if ( $_POST[$radioname] == 0 )
55    {
56      $query = 'INSERT INTO '.PREFIX_TABLE.'group_access';
57      $query.= ' (cat_id,group_id) VALUES';
58      $query.= ' ('.$page['cat'].','.$row['id'].')';
59      $query.= ';';
60      mysql_query( $query );
61    }
62  }
63  // users access update
64  $query = 'DELETE';
65  $query.= ' FROM '.PREFIX_TABLE.'user_access';
66  $query.= ' WHERE cat_id = '.$page['cat'];
67  $query.= ';';
68  mysql_query( $query );
69  $query = 'SELECT id';
70  $query.= ' FROM '.PREFIX_TABLE.'users';
71  $query.= ';';
72  $result = mysql_query( $query );
73  while ( $row = mysql_fetch_array( $result ) )
74  {
75    $radioname = 'useraccess-'.$row['id'];
76    if ( $_POST[$radioname] == 0 )
77    {
78      $query = 'INSERT INTO '.PREFIX_TABLE.'user_access';
79      $query.= ' (cat_id,user_id) VALUES';
80      $query.= ' ('.$page['cat'].','.$row['id'].')';
81      $query.= ';';
82      mysql_query( $query );
83    }
84    check_favorites( $row['id'] );
85  }
86}
87//---------------------------------------------------------------------- groups
88$query = 'SELECT id,name';
89$query.= ' FROM '.PREFIX_TABLE.'groups';
90$query. ';';
91$result = mysql_query( $query );
92if ( mysql_num_rows( $result ) > 0 )
93{
94  $vtp->addSession( $sub, 'groups' );
95  // creating an array with all authorized groups for this category
96  $query = 'SELECT group_id';
97  $query.= ' FROM '.PREFIX_TABLE.'group_access';
98  $query.= ' WHERE cat_id = '.$_GET['cat_id'];
99  $query.= ';';
100  $subresult = mysql_query( $query );
101  $authorized_groups = array();
102  while ( $subrow = mysql_fetch_array( $subresult ) )
103  {
104    array_push( $authorized_groups, $subrow['group_id'] );
105  }
106  // displaying each group
107  while( $row = mysql_fetch_array( $result ) )
108  {
109    $vtp->addSession( $sub, 'group' );
110    if ( in_array( $row['id'], $authorized_groups ) )
111    {
112      $vtp->setVar( $sub, 'group.color', 'green' );
113      $vtp->setVar( $sub, 'group.authorized_checked', ' checked="checked"' );
114    }
115    else
116    {
117      $vtp->setVar( $sub, 'group.color', 'red' );
118      $vtp->setVar( $sub, 'group.forbidden_checked', ' checked="checked"' );
119    }
120    $vtp->setVar( $sub, 'group.groupname', $row['name'] );
121    $vtp->setVar( $sub, 'group.id', $row['id'] );
122    $url = './admin.php?page=group_perm&amp;group_id='.$row['id'];
123    $vtp->setVar( $sub, 'group.group_perm_link', add_session_id( $url ) );
124    $vtp->closeSession( $sub, 'group' );
125  }
126  $vtp->closeSession( $sub, 'groups' );
127}
128//----------------------------------------------------------------------- users
129$query = 'SELECT id,username,status';
130$query.= ' FROM '.PREFIX_TABLE.'users';
131// only the webmaster can modify webmaster's permissions
132if ( $user['username'] != $conf['webmaster'] )
133{
134  $query.= " WHERE username != '".$conf['webmaster']."'";
135}
136$query.= ';';
137$result = mysql_query( $query );
138while ( $row = mysql_fetch_array( $result ) )
139{
140  $vtp->addSession( $sub, 'user' );
141  $vtp->setVar( $sub, 'user.id', $row['id'] );
142  $url = add_session_id( './admin.php?page=user_perm&amp;user_id='.$row['id']);
143  $vtp->setVar( $sub, 'user.user_perm_link', $url);
144  if ( $row['username'] == 'guest' )
145  {
146    $row['username'] = $lang['guest'];
147  }
148  $vtp->setVar( $sub, 'user.username', $row['username'] );
149
150  // for color of user : (red means access forbidden, green authorized) we
151  // ask all forbidden categories, including the groups rights
152  $restrictions = get_restrictions( $row['id'], $row['status'], false );
153  $is_user_allowed = is_user_allowed( $page['cat'], $restrictions );
154  if ( $is_user_allowed == 0 )
155  {
156    $vtp->setVar( $sub, 'user.color', 'green' );
157  }
158  else
159  {
160    $vtp->setVar( $sub, 'user.color', 'red' );
161  }
162  // for permission update button, we only ask forbidden categories for the
163  // user, not taking into account the groups the user belongs to
164  $restrictions = get_restrictions( $row['id'], $row['status'], false, false );
165  $is_user_allowed = is_user_allowed( $page['cat'], $restrictions );
166  if ( $is_user_allowed == 2 )
167  {
168    $vtp->addSession( $sub, 'parent_forbidden' );
169    $url = './admin.php?page=cat_perm&amp;cat_id='.$page['id_uppercat'];
170    $vtp->setVar( $sub, 'parent_forbidden.url', add_session_id( $url ) );
171    $vtp->closeSession( $sub, 'parent_forbidden' );
172  }
173  if ( $is_user_allowed == 0 )
174  {
175    $vtp->setVar( $sub, 'user.authorized_checked', ' checked="checked"' );
176  }
177  else
178  {
179    $vtp->setVar( $sub, 'user.forbidden_checked', ' checked="checked"' );
180  }
181  // user's group(s)
182  $query = 'SELECT g.name as groupname, g.id as groupid';
183  $query.= ' FROM '.PREFIX_TABLE.'groups as g';
184  $query.= ', '.PREFIX_TABLE.'user_group as ug';
185  $query.= ' WHERE ug.group_id = g.id';
186  $query.= ' AND ug.user_id = '.$row['id'];
187  $query.= ';';
188  $subresult = mysql_query( $query );
189  if ( mysql_num_rows( $subresult ) > 0 )
190  {
191    $vtp->addSession( $sub, 'usergroups' );
192    $i = 0;
193    while( $subrow = mysql_fetch_array( $subresult ) )
194    {
195      $vtp->addSession( $sub, 'usergroup' );
196      if ( in_array( $subrow['groupid'], $authorized_groups ) )
197      {
198        $vtp->setVar( $sub, 'usergroup.color', 'green' );
199      }
200      else
201      {
202        $vtp->setVar( $sub, 'usergroup.color', 'red' );
203      }
204      $vtp->setVar( $sub, 'usergroup.name', $subrow['groupname'] );
205      if ( $i < mysql_num_rows( $subresult ) - 1 )
206      {
207        $vtp->setVar( $sub, 'usergroup.separation', ',' );
208      }
209      $vtp->closeSession( $sub, 'usergroup' );
210      $i++;
211    }
212    $vtp->closeSession( $sub, 'usergroups' );
213  }
214  $vtp->closeSession( $sub, 'user' );
215}
216//----------------------------------------------------------- sending html code
217$vtp->Parse( $handle , 'sub', $sub );
218?>
Note: See TracBrowser for help on using the repository browser.