source: branches/release-1_3/include/functions_group.inc.php @ 335

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

Php Warning correction

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 KB
Line 
1<?php
2/***************************************************************************
3 *                           functions_group.inc.php                       *
4 *                            --------------------                         *
5 *   application   : PhpWebGallery 1.3 <http://phpwebgallery.net>          *
6 *   author        : Pierrick LE GALL <pierrick@z0rglub.com>               *
7 *                                                                         *
8 *   $Id: functions_group.inc.php 335 2004-01-30 22:49:59Z z0rglub $
9 *                                                                         *
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 ***************************************************************************/
19
20// get_group_restrictions returns an array containing all unaccessible
21// category ids.
22function get_group_restrictions( $group_id )
23{
24  // 1. retrieving ids of private categories
25  $query = 'SELECT id';
26  $query.= ' FROM '.PREFIX_TABLE.'categories';
27  $query.= " WHERE status = 'private'";
28  $query.= ';';
29  $result = mysql_query( $query );
30  $privates = array();
31  while ( $row = mysql_fetch_array( $result ) )
32  {
33    array_push( $privates, $row['id'] );
34  }
35  // 2. retrieving all authorized categories for the group
36  $authorized = array();
37  $query = 'SELECT cat_id';
38  $query.= ' FROM '.PREFIX_TABLE.'group_access';
39  $query.= ' WHERE group_id = '.$group_id;
40  $query.= ';';
41  $result = mysql_query( $query );
42  while ( $row = mysql_fetch_array( $result ) )
43  {
44    array_push( $authorized, $row['cat_id'] );
45  }
46
47  $forbidden = array();
48  foreach ( $privates as $private ) {
49    if ( !in_array( $private, $authorized ) )
50    {
51      array_push( $forbidden, $private );
52    }
53  }
54
55  return $forbidden;
56}
57
58// get_all_group_restrictions returns an array with ALL unaccessible
59// category ids, including sub-categories
60function get_all_group_restrictions( $group_id )
61{
62  $restricted_cats = get_group_restrictions( $group_id );
63  foreach ( $restricted_cats as $restricted_cat ) {
64    $sub_restricted_cats = get_subcats_id( $restricted_cat );
65    foreach ( $sub_restricted_cats as $sub_restricted_cat ) {
66      array_push( $restricted_cats, $sub_restricted_cat );
67    }
68  }
69  return $restricted_cats;
70}
71
72// The function is_group_allowed returns :
73//      - 0 : if the category is allowed with this $restrictions array
74//      - 1 : if this category is not allowed
75//      - 2 : if an uppercat category is not allowed
76function is_group_allowed( $category_id, $restrictions )
77{
78  $lowest_category_id = $category_id;
79               
80  $is_root = false;
81  while ( !$is_root and !in_array( $category_id, $restrictions ) )
82  {
83    $query = 'SELECT id_uppercat';
84    $query.= ' FROM '.PREFIX_TABLE.'categories';
85    $query.= ' WHERE id = '.$category_id;
86    $query.= ';';
87    $row = mysql_fetch_array( mysql_query( $query ) );
88    if ( !isset( $row['id_uppercat'] ) ) $row['id_uppercat'] = '';
89    if ( $row['id_uppercat'] == '' ) $is_root = true;
90    $category_id = $row['id_uppercat'];
91  }
92               
93  if ( in_array( $lowest_category_id, $restrictions ) )
94  {
95    return 1;
96  }
97  if ( in_array( $category_id, $restrictions ) )
98  {
99    return 2;
100  }
101  // this group is allowed to go in this category
102  return 0;
103}
104?>
Note: See TracBrowser for help on using the repository browser.