Changeset 862 for trunk/include/functions_group.inc.php
- Timestamp:
- Sep 14, 2005, 11:57:05 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/functions_group.inc.php
r675 r862 26 26 // +-----------------------------------------------------------------------+ 27 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 } 28 // with 1.5 preparation, no group dedicated function is used. 52 29 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 unaccessible65 // category ids, including sub-categories66 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 array80 // - 1 : if this category is not allowed81 // - 2 : if an uppercat category is not allowed82 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 category107 return 0;108 }109 30 ?>
Note: See TracChangeset
for help on using the changeset viewer.