source: trunk/admin/cat_perm.php @ 27

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

* empty log message *

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