source: trunk/admin/user_perm.php @ 29

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

template as user_template for displaying pictures in the template

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