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

Last change on this file since 9444 was 9444, checked in by plg, 13 years ago

bug fixed: use the same function to check permissions on menubar and on upload
form (groups where not fixed for menubar)

bug fixed: if no permission defined, the upload_categories was empty and SQL
query was crashing Piwigo

admins get automatically full permissions

File size: 3.7 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  if (is_admin())
29  {
30    return array(
31      'upload_whole_gallery' => true,
32      'create_whole_gallery' => true,
33      'create_categories' => array(),
34      'upload_categories' => array(),
35      'permission_ids' => array(),
36      );
37  }
38
39  $return = array(
40    'upload_whole_gallery' => false,
41    'create_whole_gallery' => false,
42    'create_categories' => array(),
43    'upload_categories' => array(),
44    'permission_ids' => array(),
45    );
46 
47  // what are the user groups?
48  $query = '
49SELECT
50    group_id
51  FROM '.USER_GROUP_TABLE.'
52  WHERE user_id = '.$user_id.'
53;';
54  $user_group_ids = array_from_query($query, 'group_id');
55
56  $query = '
57SELECT
58    id,
59    category_id,
60    create_subcategories
61  FROM '.COMMUNITY_PERMISSIONS_TABLE.'
62  WHERE (type = \'any_visitor\')';
63
64  if ($user_id != $conf['guest_id'])
65  {
66    $query.= '
67    OR (type = \'any_registered_user\')
68    OR (type = \'user\' AND user_id = '.$user_id.')';
69
70    if (count($user_group_ids) > 0)
71    {
72      $query.= '
73    OR (type = \'group\' AND group_id IN ('.implode(',', $user_group_ids).'))';
74    }
75  }
76   
77  $query.= '
78;';
79
80  $result = pwg_query($query);
81  while ($row = pwg_db_fetch_assoc($result))
82  {
83    array_push($return['permission_ids'], $row['id']);
84   
85    if (empty($row['category_id']))
86    {
87      $return ['upload_whole_gallery'] = true;
88    }
89    else
90    {
91      array_push($return['upload_categories'], $row['category_id']);
92    }
93
94    if ('true' == $row['create_subcategories'])
95    {
96      if (empty($row['category_id']))
97      {
98        $return ['create_whole_gallery'] = true;
99      }
100      else
101      {
102        array_push($return['create_categories'], $row['category_id']);
103      }
104    }
105  }
106
107  if (!$return['upload_whole_gallery'] and count($return['upload_categories']) > 0)
108  {
109    $return['upload_categories'] = get_subcat_ids($return['upload_categories']);
110  }
111
112  if (!$return ['create_whole_gallery'] and count($return['create_categories']) > 0)
113  {
114    $return['create_categories'] = get_subcat_ids($return['create_categories']);
115  }
116
117  return $return;
118}
119
120?>
Note: See TracBrowser for help on using the repository browser.