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

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

bug fixed: deleting a user also deletes upload permissions linked to this user and reject pending photos added by this user

File size: 4.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  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
120function community_reject_pendings($image_ids)
121{
122  if (count($image_ids) == 0)
123  {
124    return;
125  }
126 
127  $query = '
128DELETE
129  FROM '.COMMUNITY_PENDINGS_TABLE.'
130  WHERE image_id IN ('.implode(',', $image_ids).')
131;';
132  pwg_query($query);
133
134  // needs to be in administration panel
135  delete_elements($image_ids, true);
136}
137
138function community_reject_user_pendings($user_id)
139{
140  $query = '
141SELECT
142    image_id
143  FROM '.COMMUNITY_PENDINGS_TABLE.' AS cp
144    INNER JOIN '.IMAGES_TABLE.' AS i ON i.id = cp.image_id
145  WHERE state != \'validated\'
146    AND added_by = '.$user_id.'
147;';
148  $result = pwg_query($query);
149  $image_ids = array();
150  while ($row = pwg_db_fetch_assoc($result))
151  {
152    array_push($image_ids, $row['image_id']);
153  }
154
155  community_reject_pendings($image_ids);
156}
157
158?>
Note: See TracBrowser for help on using the repository browser.