source: extensions/community/include/functions_community.inc.php @ 9376

Last change on this file since 9376 was 9376, checked in by plg, 10 years ago

bug fixed: the group list for a given user may be empty

File size: 3.4 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24function community_get_user_permissions($user_id)
25{
26  global $conf;
27
28  $return = array(
29    'upload_whole_gallery' => false,
30    'create_whole_gallery' => false,
31    'create_categories' => array(),
32    'upload_categories' => array(),
33    'permission_ids' => array(),
34    );
35
36  $user_permissions = array();
37 
38  // what are the user groups?
39  $query = '
40SELECT
41    group_id
42  FROM '.USER_GROUP_TABLE.'
43  WHERE user_id = '.$user_id.'
44;';
45  $user_group_ids = array_from_query($query, 'group_id');
46
47  $query = '
48SELECT
49    id,
50    category_id,
51    create_subcategories
52  FROM '.COMMUNITY_PERMISSIONS_TABLE.'
53  WHERE (type = \'any_visitor\')';
54
55  if ($user_id != $conf['guest_id'])
56  {
57    $query.= '
58    OR (type = \'any_registered_user\')
59    OR (type = \'user\' AND user_id = '.$user_id.')';
60
61    if (count($user_group_ids) > 0)
62    {
63      $query.= '
64    OR (type = \'group\' AND group_id IN ('.implode(',', $user_group_ids).'))';
65    }
66  }
67   
68  $query.= '
69;';
70
71  $result = pwg_query($query);
72  while ($row = pwg_db_fetch_assoc($result))
73  {
74    array_push($return['permission_ids'], $row['id']);
75   
76    if (empty($row['category_id']))
77    {
78      $return ['upload_whole_gallery'] = true;
79    }
80    else
81    {
82      array_push($return['upload_categories'], $row['category_id']);
83    }
84
85    if ('true' == $row['create_subcategories'])
86    {
87      if (empty($row['category_id']))
88      {
89        $return ['create_whole_gallery'] = true;
90      }
91      else
92      {
93        array_push($return['create_categories'], $row['category_id']);
94      }
95    }
96  }
97
98  if (!$return['upload_whole_gallery'])
99  {
100    $return['upload_categories'] = get_subcat_ids($return['upload_categories']);
101  }
102
103  if (!$return ['create_whole_gallery'] and count($return['create_categories']) > 0)
104  {
105    $return['create_categories'] = get_subcat_ids($return['create_categories']);
106  }
107
108  return $return;
109}
110
111?>
Note: See TracBrowser for help on using the repository browser.