Subversion Repositories svnkaklik

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
6 kaklik 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: functions_group.inc.php,v $
9
// | last update   : $Date: 2005/01/07 23:10:51 $
10
// | last modifier : $Author: plg $
11
// | revision      : $Revision: 1.8 $
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.
30
function 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
66
function 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
82
function 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
?>