[21] | 1 | <?php |
---|
| 2 | /*************************************************************************** |
---|
[57] | 3 | * group_perm.php * |
---|
[21] | 4 | * ------------------ * |
---|
[57] | 5 | * application : PhpWebGallery 1.3 <http://phpwebgallery.net> * |
---|
| 6 | * author : Pierrick LE GALL <pierrick@z0rglub.com> * |
---|
[21] | 7 | * * |
---|
[57] | 8 | * $Id: group_perm.php 345 2004-02-02 00:55:18Z gweltas $ |
---|
| 9 | * * |
---|
[21] | 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 | ***************************************************************************/ |
---|
[226] | 19 | include_once( './admin/include/isadmin.inc.php' ); |
---|
[21] | 20 | //----------------------------------------------------- template initialization |
---|
[225] | 21 | $sub = $vtp->Open( './template/'.$user['template'].'/admin/group_perm.vtp' ); |
---|
[21] | 22 | $error = array(); |
---|
| 23 | $tpl = array( 'permuser_authorized','permuser_forbidden','submit', |
---|
| 24 | 'permuser_parent_forbidden','permuser_info_message', |
---|
[146] | 25 | 'adduser_info_back','permuser_only_private' ); |
---|
[21] | 26 | templatize_array( $tpl, 'lang', $sub ); |
---|
[29] | 27 | $vtp->setGlobalVar( $sub, 'user_template', $user['template'] ); |
---|
[21] | 28 | //--------------------------------------------------------------------- updates |
---|
| 29 | if ( isset( $_POST['submit'] ) ) |
---|
| 30 | { |
---|
| 31 | // cleaning the user_access table for this group |
---|
| 32 | $query = 'DELETE FROM '.PREFIX_TABLE.'group_access'; |
---|
| 33 | $query.= ' WHERE group_id = '.$_GET['group_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.'group_access'; |
---|
| 48 | $query.= ' (group_id,cat_id) VALUES'; |
---|
| 49 | $query.= ' ('.$_GET['group_id'].','.$row['id'].')'; |
---|
| 50 | $query.= ';'; |
---|
| 51 | mysql_query ( $query ); |
---|
| 52 | } |
---|
| 53 | } |
---|
[170] | 54 | // checking users favorites |
---|
| 55 | $query = 'SELECT id'; |
---|
| 56 | $query.= ' FROM '.PREFIX_TABLE.'users'; |
---|
| 57 | $query.= ';'; |
---|
| 58 | $result = mysql_query( $query ); |
---|
| 59 | while ( $row = mysql_fetch_array( $result ) ) |
---|
| 60 | { |
---|
| 61 | check_favorites( $row['id'] ); |
---|
| 62 | } |
---|
[345] | 63 | // synchronization of calculated data |
---|
| 64 | synchronize_group( $_GET['group_id'] ); |
---|
[170] | 65 | // confirmation display |
---|
[21] | 66 | $vtp->addSession( $sub, 'confirmation' ); |
---|
| 67 | $url = './admin.php?page=group_list'; |
---|
| 68 | $vtp->setVar( $sub, 'confirmation.back_url', add_session_id( $url ) ); |
---|
| 69 | $vtp->closeSession( $sub, 'confirmation' ); |
---|
| 70 | } |
---|
| 71 | //---------------------------------------------------------------- form display |
---|
| 72 | $restrictions = get_group_restrictions( $_GET['group_id'] ); |
---|
| 73 | $action = './admin.php?page=group_perm&group_id='.$_GET['group_id']; |
---|
| 74 | $vtp->setVar( $sub, 'action', add_session_id( $action ) ); |
---|
| 75 | // only private categories are listed |
---|
| 76 | $query = 'SELECT id'; |
---|
| 77 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
| 78 | $query.= " WHERE status = 'private'"; |
---|
| 79 | $query.= ';'; |
---|
| 80 | $result = mysql_query( $query ); |
---|
| 81 | while ( $row = mysql_fetch_array( $result ) ) |
---|
| 82 | { |
---|
| 83 | $vtp->addSession( $sub, 'category' ); |
---|
| 84 | $vtp->setVar( $sub, 'category.id', $row['id'] ); |
---|
[102] | 85 | $url = './admin.php?page=cat_perm&cat_id='.$row['id']; |
---|
| 86 | $vtp->setVar( $sub, 'category.cat_perm_link', add_session_id( $url ) ); |
---|
[21] | 87 | // Is the group allowed to access this category |
---|
| 88 | $is_group_allowed = is_group_allowed( $row['id'], $restrictions ); |
---|
| 89 | if ( $is_group_allowed == 0 ) |
---|
| 90 | { |
---|
| 91 | $vtp->setVar( $sub, 'category.color', 'green' ); |
---|
| 92 | } |
---|
| 93 | else |
---|
| 94 | { |
---|
| 95 | $vtp->setVar( $sub, 'category.color', 'red' ); |
---|
| 96 | } |
---|
| 97 | // category name |
---|
| 98 | $cat_infos = get_cat_info( $row['id'] ); |
---|
| 99 | $name = get_cat_display_name( $cat_infos['name'],' > ', |
---|
| 100 | 'font-weight:bold;' ); |
---|
| 101 | $vtp->setVar( $sub, 'category.name', $name ); |
---|
| 102 | // any subcat forbidden for this group ? |
---|
| 103 | if ( $is_group_allowed == 2 ) |
---|
| 104 | { |
---|
| 105 | $vtp->addSession( $sub, 'parent_forbidden' ); |
---|
| 106 | $vtp->closeSession( $sub, 'parent_forbidden' ); |
---|
| 107 | } |
---|
| 108 | // forbidden or authorized access ? |
---|
| 109 | if ( $is_group_allowed == 0 or $is_group_allowed == 2 ) |
---|
| 110 | { |
---|
| 111 | $vtp->setVar( $sub, 'category.authorized_checked', ' checked="checked"' ); |
---|
| 112 | } |
---|
| 113 | else |
---|
| 114 | { |
---|
| 115 | $vtp->setVar( $sub, 'category.forbidden_checked', ' checked="checked"' ); |
---|
| 116 | } |
---|
| 117 | $vtp->closeSession( $sub, 'category' ); |
---|
| 118 | } |
---|
| 119 | //----------------------------------------------------------- sending html code |
---|
| 120 | $vtp->Parse( $handle , 'sub', $sub ); |
---|
| 121 | ?> |
---|