source: tags/release-1_4_1/include/functions_group.inc.php @ 27601

Last change on this file since 27601 was 675, checked in by plg, 19 years ago

all headers adapted to new year 2005, happy new year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2005-01-07 23:10:51 +0000 (Fri, 07 Jan 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 675 $
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 FROM '.CATEGORIES_TABLE;
34  $query.= " WHERE status = 'private'";
35  $query.= ';';
36  $result = pwg_query( $query );
37  $privates = array();
38  while ( $row = mysql_fetch_array( $result ) )
39  {
40    array_push( $privates, $row['id'] );
41  }
42  // 2. retrieving all authorized categories for the group
43  $authorized = array();
44  $query = 'SELECT cat_id FROM '.GROUP_ACCESS_TABLE;
45  $query.= ' WHERE group_id = '.$group_id;
46  $query.= ';';
47  $result = pwg_query( $query );
48  while ( $row = mysql_fetch_array( $result ) )
49  {
50    array_push( $authorized, $row['cat_id'] );
51  }
52
53  $forbidden = array();
54  foreach ( $privates as $private ) {
55    if ( !in_array( $private, $authorized ) )
56    {
57      array_push( $forbidden, $private );
58    }
59  }
60
61  return $forbidden;
62}
63
64// get_all_group_restrictions returns an array with ALL unaccessible
65// category ids, including sub-categories
66function get_all_group_restrictions( $group_id )
67{
68  $restricted_cats = get_group_restrictions( $group_id );
69  foreach ( $restricted_cats as $restricted_cat ) {
70    $sub_restricted_cats = get_subcats_id( $restricted_cat );
71    foreach ( $sub_restricted_cats as $sub_restricted_cat ) {
72      array_push( $restricted_cats, $sub_restricted_cat );
73    }
74  }
75  return $restricted_cats;
76}
77
78// The function is_group_allowed returns :
79//      - 0 : if the category is allowed with this $restrictions array
80//      - 1 : if this category is not allowed
81//      - 2 : if an uppercat category is not allowed
82function is_group_allowed( $category_id, $restrictions )
83{
84  $lowest_category_id = $category_id;
85               
86  $is_root = false;
87  while ( !$is_root and !in_array( $category_id, $restrictions ) )
88  {
89    $query = 'SELECT id_uppercat FROM '.CATEGORIES_TABLE;
90    $query.= ' WHERE id = '.$category_id;
91    $query.= ';';
92    $row = mysql_fetch_array( pwg_query( $query ) );
93    if ( !isset( $row['id_uppercat'] ) ) $row['id_uppercat'] = '';
94    if ( $row['id_uppercat'] == '' ) $is_root = true;
95    $category_id = $row['id_uppercat'];
96  }
97               
98  if ( in_array( $lowest_category_id, $restrictions ) )
99  {
100    return 1;
101  }
102  if ( in_array( $category_id, $restrictions ) )
103  {
104    return 2;
105  }
106  // this group is allowed to go in this category
107  return 0;
108}
109?>
Note: See TracBrowser for help on using the repository browser.