source: extensions/community/admin_pendings.php @ 12153

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

if a pending photo belongs to an album that has been deleted, the photo becomes orphan and it does not display an error on admin_pendings, but a message "no album, this photo is orphan"

File size: 7.8 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    tn_ext,
134    date_creation,
135    name,
136    comment,
137    added_by,
138    file,
139    name,
140    filesize,
141    width,
142    height,
143    has_high,
144    high_filesize,
145
146    '.$conf['user_fields']['username'].' AS username
147
148  FROM '.COMMUNITY_PENDINGS_TABLE.' AS cp
149    INNER JOIN '.IMAGES_TABLE.' AS i ON i.id = cp.image_id
150    LEFT JOIN '.USERS_TABLE.' AS u ON u.'.$conf['user_fields']['id'].' = i.added_by
151
152  WHERE state = \'moderation_pending\'
153
154  ORDER BY image_id DESC
155;';
156$result = pwg_query($query);
157$rows = array();
158$image_ids = array();
159while ($row = pwg_db_fetch_assoc($result))
160{
161  array_push($rows, $row);
162  array_push($image_ids, $row['id']);
163}
164
165$category_for_image = array();
166
167if (count($image_ids) > 0)
168{
169  $query = '
170SELECT
171    id,
172    image_id,
173    uppercats
174  FROM '.IMAGE_CATEGORY_TABLE.'
175    JOIN '.CATEGORIES_TABLE.' ON id = category_id
176  WHERE image_id IN ('.implode(',', $image_ids).')
177;';
178  $result = pwg_query($query);
179
180  while ($row = pwg_db_fetch_assoc($result))
181  {
182    $category_for_image[ $row['image_id'] ] = get_cat_display_name_cache(
183      $row['uppercats'],
184      'admin.php?page=cat_modify&amp;cat_id=',
185      false,
186      true,
187      'externalLink'
188      );
189  }
190}
191
192foreach ($rows as $row)
193{
194  $thumb = get_thumbnail_url(
195    array(
196      'id' => $row['image_id'],
197      'path' => $row['path'],
198      'tn_ext' => @$row['tn_ext']
199      )
200    );
201
202  // file properties
203  $dimensions = null;
204  $websize_props = $row['width'].'x'.$row['height'].' '.l10n('pixels').', '.sprintf(l10n('%d Kb'), $row['filesize']);
205  if (!empty($row['has_high']) and get_boolean($row['has_high']))
206  {
207    $high_path = get_high_path($row);
208    list($high_width, $high_height) = getimagesize($high_path);
209    $high_props = $high_width.'x'.$high_height.' '.l10n('pixels').', '.sprintf(l10n('%d Kb'), $row['high_filesize']);
210   
211    $dimensions = $high_props.' ('.l10n('web size').' '.$websize_props.')';
212  }
213  else
214  {
215    $dimensions = $websize_props;
216  }
217
218  $album = null;
219  if (isset($category_for_image[ $row['id'] ]))
220  {
221    $album = $category_for_image[ $row['id'] ];
222  }
223  else
224  {
225    $album = '<em>'.l10n('No album, this photo is orphan').'</em>';
226  }
227 
228  $template->append(
229    'photos',
230    array(
231      'U_EDIT' => get_root_url().'admin.php?page=picture_modify&amp;image_id='.$row['image_id'],
232      'ID' => $row['image_id'],
233      'TN_SRC' => $thumb,
234      'WEBSIZE_SRC' => $row['path'],
235      'ADDED_BY' => $row['username'],
236      'ADDED_ON' => format_date($row['added_on'], true),
237      'NAME' => get_image_name($row['name'], $row['file']),
238      'DIMENSIONS' => $dimensions,
239      'FILE' => $row['file'],
240      'DATE_CREATION' => format_date($row['date_creation']),
241      'ALBUM' => $album,
242      )
243    );
244}
245
246// +-----------------------------------------------------------------------+
247// | form options                                                          |
248// +-----------------------------------------------------------------------+
249
250// image level options
251$selected_level = isset($_POST['level']) ? $_POST['level'] : 0;
252$template->assign(
253    array(
254      'level_options'=> get_privacy_level_options(),
255      'level_options_selected' => array($selected_level)
256    )
257  );
258
259
260// +-----------------------------------------------------------------------+
261// | sending html code                                                     |
262// +-----------------------------------------------------------------------+
263
264$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
265?>
Note: See TracBrowser for help on using the repository browser.