source: trunk/include/functions_group.inc.php @ 362

Last change on this file since 362 was 362, checked in by z0rglub, 20 years ago

header global refactoring

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// |                        functions_group.inc.php                        |
4// +-----------------------------------------------------------------------+
5// | application   : PhpWebGallery <http://phpwebgallery.net>              |
6// | branch        : BSF (Best So Far)                                     |
7// +-----------------------------------------------------------------------+
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-02-11 23:20:38 +0000 (Wed, 11 Feb 2004) $
10// | last modifier : $Author: z0rglub $
11// | revision      : $Revision: 362 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28// get_group_restrictions returns an array containing all unaccessible
29// category ids.
30function get_group_restrictions( $group_id )
31{
32  // 1. retrieving ids of private categories
33  $query = 'SELECT id';
34  $query.= ' FROM '.PREFIX_TABLE.'categories';
35  $query.= " WHERE status = 'private'";
36  $query.= ';';
37  $result = mysql_query( $query );
38  $privates = array();
39  while ( $row = mysql_fetch_array( $result ) )
40  {
41    array_push( $privates, $row['id'] );
42  }
43  // 2. retrieving all authorized categories for the group
44  $authorized = array();
45  $query = 'SELECT cat_id';
46  $query.= ' FROM '.PREFIX_TABLE.'group_access';
47  $query.= ' WHERE group_id = '.$group_id;
48  $query.= ';';
49  $result = mysql_query( $query );
50  while ( $row = mysql_fetch_array( $result ) )
51  {
52    array_push( $authorized, $row['cat_id'] );
53  }
54
55  $forbidden = array();
56  foreach ( $privates as $private ) {
57    if ( !in_array( $private, $authorized ) )
58    {
59      array_push( $forbidden, $private );
60    }
61  }
62
63  return $forbidden;
64}
65
66// get_all_group_restrictions returns an array with ALL unaccessible
67// category ids, including sub-categories
68function get_all_group_restrictions( $group_id )
69{
70  $restricted_cats = get_group_restrictions( $group_id );
71  foreach ( $restricted_cats as $restricted_cat ) {
72    $sub_restricted_cats = get_subcats_id( $restricted_cat );
73    foreach ( $sub_restricted_cats as $sub_restricted_cat ) {
74      array_push( $restricted_cats, $sub_restricted_cat );
75    }
76  }
77  return $restricted_cats;
78}
79
80// The function is_group_allowed returns :
81//      - 0 : if the category is allowed with this $restrictions array
82//      - 1 : if this category is not allowed
83//      - 2 : if an uppercat category is not allowed
84function is_group_allowed( $category_id, $restrictions )
85{
86  $lowest_category_id = $category_id;
87               
88  $is_root = false;
89  while ( !$is_root and !in_array( $category_id, $restrictions ) )
90  {
91    $query = 'SELECT id_uppercat';
92    $query.= ' FROM '.PREFIX_TABLE.'categories';
93    $query.= ' WHERE id = '.$category_id;
94    $query.= ';';
95    $row = mysql_fetch_array( mysql_query( $query ) );
96    if ( !isset( $row['id_uppercat'] ) ) $row['id_uppercat'] = '';
97    if ( $row['id_uppercat'] == '' ) $is_root = true;
98    $category_id = $row['id_uppercat'];
99  }
100               
101  if ( in_array( $lowest_category_id, $restrictions ) )
102  {
103    return 1;
104  }
105  if ( in_array( $category_id, $restrictions ) )
106  {
107    return 2;
108  }
109  // this group is allowed to go in this category
110  return 0;
111}
112?>
Note: See TracBrowser for help on using the repository browser.