source: trunk/admin/cat_perm.php @ 168

Last change on this file since 168 was 168, checked in by z0rglub, 21 years ago

Deleting dead code

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 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 168 2003-10-05 10:40:53Z 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( './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$query.= " WHERE username != '".$conf['webmaster']."'";
132$query.= ';';
133$result = mysql_query( $query );
134while ( $row = mysql_fetch_array( $result ) )
135{
136  $vtp->addSession( $sub, 'user' );
137  $vtp->setVar( $sub, 'user.id', $row['id'] );
138  $url = add_session_id( './admin.php?page=user_perm&amp;user_id='.$row['id']);
139  $vtp->setVar( $sub, 'user.user_perm_link', $url);
140  if ( $row['username'] == 'guest' )
141  {
142    $row['username'] = $lang['guest'];
143  }
144  $vtp->setVar( $sub, 'user.username', $row['username'] );
145
146  // for color of user : (red means access forbidden, green authorized) we
147  // ask all forbidden categories, including the groups rights
148  $restrictions = get_restrictions( $row['id'], $row['status'], false );
149  $is_user_allowed = is_user_allowed( $page['cat'], $restrictions );
150  if ( $is_user_allowed == 0 )
151  {
152    $vtp->setVar( $sub, 'user.color', 'green' );
153  }
154  else
155  {
156    $vtp->setVar( $sub, 'user.color', 'red' );
157  }
158  // for permission update button, we only ask forbidden categories for the
159  // user, not taking into account the groups the user belongs to
160  $restrictions = get_restrictions( $row['id'], $row['status'], false, false );
161  $is_user_allowed = is_user_allowed( $page['cat'], $restrictions );
162  if ( $is_user_allowed == 2 )
163  {
164    $vtp->addSession( $sub, 'parent_forbidden' );
165    $url = './admin.php?page=cat_perm&amp;cat_id='.$page['id_uppercat'];
166    $vtp->setVar( $sub, 'parent_forbidden.url', add_session_id( $url ) );
167    $vtp->closeSession( $sub, 'parent_forbidden' );
168  }
169  if ( $is_user_allowed == 0 )
170  {
171    $vtp->setVar( $sub, 'user.authorized_checked', ' checked="checked"' );
172  }
173  else
174  {
175    $vtp->setVar( $sub, 'user.forbidden_checked', ' checked="checked"' );
176  }
177  // user's group(s)
178  $query = 'SELECT g.name as groupname, g.id as groupid';
179  $query.= ' FROM '.PREFIX_TABLE.'groups as g';
180  $query.= ', '.PREFIX_TABLE.'user_group as ug';
181  $query.= ' WHERE ug.group_id = g.id';
182  $query.= ' AND ug.user_id = '.$row['id'];
183  $query.= ';';
184  $subresult = mysql_query( $query );
185  if ( mysql_num_rows( $subresult ) > 0 )
186  {
187    $vtp->addSession( $sub, 'usergroups' );
188    $i = 0;
189    while( $subrow = mysql_fetch_array( $subresult ) )
190    {
191      $vtp->addSession( $sub, 'usergroup' );
192      if ( in_array( $subrow['groupid'], $authorized_groups ) )
193      {
194        $vtp->setVar( $sub, 'usergroup.color', 'green' );
195      }
196      else
197      {
198        $vtp->setVar( $sub, 'usergroup.color', 'red' );
199      }
200      $vtp->setVar( $sub, 'usergroup.name', $subrow['groupname'] );
201      if ( $i < mysql_num_rows( $subresult ) - 1 )
202      {
203        $vtp->setVar( $sub, 'usergroup.separation', ',' );
204      }
205      $vtp->closeSession( $sub, 'usergroup' );
206      $i++;
207    }
208    $vtp->closeSession( $sub, 'usergroups' );
209  }
210  $vtp->closeSession( $sub, 'user' );
211}
212//----------------------------------------------------------- sending html code
213$vtp->Parse( $handle , 'sub', $sub );
214?>
Note: See TracBrowser for help on using the repository browser.