source: extensions/community/admin_pendings.php @ 23744

Last change on this file since 23744 was 23744, checked in by plg, 7 years ago

bug fixed when pending photo has a representative

File size: 7.7 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture 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
24if( !defined("PHPWG_ROOT_PATH") )
25{
26  die ("Hacking attempt!");
27}
28
29include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
30include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
31load_language('plugin.lang', COMMUNITY_PATH);
32
33$admin_base_url = get_root_url().'admin.php?page=plugin-community-pendings';
34
35// +-----------------------------------------------------------------------+
36// | Check Access and exit when user status is not ok                      |
37// +-----------------------------------------------------------------------+
38
39check_status(ACCESS_ADMINISTRATOR);
40
41// +-----------------------------------------------------------------------+
42// |                                actions                                |
43// +-----------------------------------------------------------------------+
44
45if (!empty($_POST))
46{
47  if (empty($_POST['photos']))
48  {
49    array_push(
50      $page['errors'],
51      l10n('Select at least one photo')
52      );
53  }
54  else
55  {
56    check_input_parameter('photos', $_POST, true, PATTERN_ID);
57    check_input_parameter('level', $_POST, false, PATTERN_ID);
58   
59    if (isset($_POST['validate']))
60    {
61      $query = '
62UPDATE '.COMMUNITY_PENDINGS_TABLE.'
63  SET state = \'validated\',
64      validated_by = '.$user['id'].'
65  WHERE image_id IN ('.implode(',', $_POST['photos']).')
66;';
67      pwg_query($query);
68
69      $query = '
70UPDATE '.IMAGES_TABLE.'
71  SET level = '.$_POST['level'].',
72      date_available = NOW()
73  WHERE id IN ('.implode(',', $_POST['photos']).')
74;';
75      pwg_query($query);
76
77      array_push(
78        $page['infos'],
79        sprintf(
80          l10n('%d photos validated'),
81          count($_POST['photos'])
82          )
83        );
84    }
85
86    if (isset($_POST['reject']))
87    {
88      $query = '
89DELETE
90  FROM '.COMMUNITY_PENDINGS_TABLE.'
91  WHERE image_id IN ('.implode(',', $_POST['photos']).')
92;';
93      pwg_query($query);
94
95      delete_elements($_POST['photos'], true);
96
97      array_push(
98        $page['infos'],
99        sprintf(
100          l10n('%d photos rejected'),
101          count($_POST['photos'])
102          )
103        );
104    }
105
106    invalidate_user_cache();
107  }
108}
109
110// +-----------------------------------------------------------------------+
111// | template init                                                         |
112// +-----------------------------------------------------------------------+
113
114$template->set_filenames(
115  array(
116    'plugin_admin_content' => dirname(__FILE__).'/admin_pendings.tpl'
117    )
118  );
119
120// +-----------------------------------------------------------------------+
121// | pending photos list                                                   |
122// +-----------------------------------------------------------------------+
123
124$list = array();
125
126$query = '
127SELECT
128    image_id,
129    added_on,
130
131    i.id,
132    path,
133    date_creation,
134    name,
135    comment,
136    added_by,
137    file,
138    name,
139    filesize,
140    width,
141    height,
142    rotation,
143    representative_ext,
144
145    '.$conf['user_fields']['username'].' AS username
146
147  FROM '.COMMUNITY_PENDINGS_TABLE.' AS cp
148    INNER JOIN '.IMAGES_TABLE.' AS i ON i.id = cp.image_id
149    LEFT JOIN '.USERS_TABLE.' AS u ON u.'.$conf['user_fields']['id'].' = i.added_by
150
151  WHERE state = \'moderation_pending\'
152
153  ORDER BY image_id DESC
154;';
155$result = pwg_query($query);
156$rows = array();
157$image_ids = array();
158while ($row = pwg_db_fetch_assoc($result))
159{
160  array_push($rows, $row);
161  array_push($image_ids, $row['id']);
162}
163
164$category_for_image = array();
165
166if (count($image_ids) > 0)
167{
168  $query = '
169SELECT
170    id,
171    image_id,
172    uppercats
173  FROM '.IMAGE_CATEGORY_TABLE.'
174    JOIN '.CATEGORIES_TABLE.' ON id = category_id
175  WHERE image_id IN ('.implode(',', $image_ids).')
176;';
177  $result = pwg_query($query);
178
179  while ($row = pwg_db_fetch_assoc($result))
180  {
181    $category_for_image[ $row['image_id'] ] = get_cat_display_name_cache(
182      $row['uppercats'],
183      'admin.php?page=album-',
184      false,
185      true,
186      'externalLink'
187      );
188  }
189}
190
191foreach ($rows as $row)
192{
193  $src_image = new SrcImage($row);
194  $thumb_url = DerivativeImage::url(IMG_THUMB, $src_image);
195  $medium_url = DerivativeImage::url(IMG_MEDIUM, $src_image);
196 
197  // file properties
198  $dimensions = null;
199  $websize_props = $row['width'].'x'.$row['height'].' '.l10n('pixels').', '.sprintf(l10n('%d Kb'), $row['filesize']);
200  if (!empty($row['has_high']) and get_boolean($row['has_high']))
201  {
202    $high_path = get_high_path($row);
203    list($high_width, $high_height) = getimagesize($high_path);
204    $high_props = $high_width.'x'.$high_height.' '.l10n('pixels').', '.sprintf(l10n('%d Kb'), $row['high_filesize']);
205   
206    $dimensions = $high_props.' ('.l10n('web size').' '.$websize_props.')';
207  }
208  else
209  {
210    $dimensions = $websize_props;
211  }
212
213  $album = null;
214  if (isset($category_for_image[ $row['id'] ]))
215  {
216    $album = $category_for_image[ $row['id'] ];
217  }
218  else
219  {
220    $album = '<em>'.l10n('No album, this photo is orphan').'</em>';
221  }
222 
223  $template->append(
224    'photos',
225    array(
226      'U_EDIT' => get_root_url().'admin.php?page=photo-'.$row['image_id'],
227      'ID' => $row['image_id'],
228      'TN_SRC' => $thumb_url,
229      'MEDIUM_SRC' => $medium_url,
230      'ADDED_BY' => $row['username'],
231      'ADDED_ON' => format_date($row['added_on'], true),
232      'NAME' => $row['name'],
233      'DIMENSIONS' => $dimensions,
234      'FILE' => $row['file'],
235      'DATE_CREATION' => format_date($row['date_creation']),
236      'ALBUM' => $album,
237      )
238    );
239}
240
241// +-----------------------------------------------------------------------+
242// | form options                                                          |
243// +-----------------------------------------------------------------------+
244
245// image level options
246$selected_level = isset($_POST['level']) ? $_POST['level'] : 0;
247$template->assign(
248    array(
249      'level_options'=> get_privacy_level_options(),
250      'level_options_selected' => array($selected_level)
251    )
252  );
253
254
255// +-----------------------------------------------------------------------+
256// | sending html code                                                     |
257// +-----------------------------------------------------------------------+
258
259$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
260?>
Note: See TracBrowser for help on using the repository browser.