source: trunk/admin/user_perm.php @ 57

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

improve the header of each file

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