source: trunk/admin/user_perm.php @ 21

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