source: trunk/admin/picture_modify.php @ 28587

Last change on this file since 28587 was 28587, checked in by mistic100, 10 years ago

feature 3010 : replace trigger_action/event by trigger_notify/change

  • Property svn:eol-style set to LF
File size: 11.6 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2014 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');
30
31// +-----------------------------------------------------------------------+
32// | Check Access and exit when user status is not ok                      |
33// +-----------------------------------------------------------------------+
34check_status(ACCESS_ADMINISTRATOR);
35
36check_input_parameter('image_id', $_GET, false, PATTERN_ID);
37check_input_parameter('cat_id', $_GET, false, PATTERN_ID);
38
39// represent
40$query = '
41SELECT id
42  FROM '.CATEGORIES_TABLE.'
43  WHERE representative_picture_id = '.$_GET['image_id'].'
44;';
45$represented_albums = query2array($query, null, 'id');
46
47// +-----------------------------------------------------------------------+
48// |                             delete photo                              |
49// +-----------------------------------------------------------------------+
50
51if (isset($_GET['delete']))
52{
53  check_pwg_token();
54
55  delete_elements(array($_GET['image_id']), true);
56  invalidate_user_cache();
57
58  // where to redirect the user now?
59  //
60  // 1. if a category is available in the URL, use it
61  // 2. else use the first reachable linked category
62  // 3. redirect to gallery root
63
64  if (isset($_GET['cat_id']) and !empty($_GET['cat_id']))
65  {
66    redirect(
67      make_index_url(
68        array(
69          'category' => get_cat_info($_GET['cat_id'])
70          )
71        )
72      );
73  }
74
75  $query = '
76SELECT category_id
77  FROM '.IMAGE_CATEGORY_TABLE.'
78  WHERE image_id = '.$_GET['image_id'].'
79;';
80
81  $authorizeds = array_diff(
82    array_from_query($query, 'category_id'),
83    explode(',', calculate_permissions($user['id'], $user['status']))
84    );
85
86  foreach ($authorizeds as $category_id)
87  {
88    redirect(
89      make_index_url(
90        array(
91          'category' => get_cat_info($category_id)
92          )
93        )
94      );
95  }
96
97  redirect(make_index_url());
98}
99
100// +-----------------------------------------------------------------------+
101// |                          synchronize metadata                         |
102// +-----------------------------------------------------------------------+
103
104if (isset($_GET['sync_metadata']))
105{
106  sync_metadata(array( intval($_GET['image_id'])));
107  $page['infos'][] = l10n('Metadata synchronized from file');
108}
109
110//--------------------------------------------------------- update informations
111if (isset($_POST['submit']))
112{
113  $data = array();
114  $data['id'] = $_GET['image_id'];
115  $data['name'] = $_POST['name'];
116  $data['author'] = $_POST['author'];
117  $data['level'] = $_POST['level'];
118
119  if ($conf['allow_html_descriptions'])
120  {
121    $data['comment'] = @$_POST['description'];
122  }
123  else
124  {
125    $data['comment'] = strip_tags(@$_POST['description']);
126  }
127
128  if (!empty($_POST['date_creation']))
129  {
130    $data['date_creation'] = $_POST['date_creation'];
131  }
132  else
133  {
134    $data['date_creation'] = null;
135  }
136
137  $data = trigger_change('picture_modify_before_update', $data);
138 
139  single_update(
140    IMAGES_TABLE,
141    $data,
142    array('id' => $data['id'])
143    );
144
145  // time to deal with tags
146  $tag_ids = array();
147  if (!empty($_POST['tags']))
148  {
149    $tag_ids = get_tag_ids($_POST['tags']);
150  }
151  set_tags($tag_ids, $_GET['image_id']);
152
153  // association to albums
154  if (!isset($_POST['associate']))
155  {
156    $_POST['associate'] = array();
157  }
158  move_images_to_categories(array($_GET['image_id']), $_POST['associate']);
159
160  invalidate_user_cache();
161
162  // thumbnail for albums
163  if (!isset($_POST['represent']))
164  {
165    $_POST['represent'] = array();
166  }
167
168  $no_longer_thumbnail_for = array_diff($represented_albums, $_POST['represent']);
169  if (count($no_longer_thumbnail_for) > 0)
170  {
171    set_random_representant($no_longer_thumbnail_for);
172  }
173
174  $new_thumbnail_for = array_diff($_POST['represent'], $represented_albums);
175  if (count($new_thumbnail_for) > 0)
176  {
177    $query = '
178UPDATE '.CATEGORIES_TABLE.'
179  SET representative_picture_id = '.$_GET['image_id'].'
180  WHERE id IN ('.implode(',', $new_thumbnail_for).')
181;';
182    pwg_query($query);
183  }
184
185  $represented_albums = $_POST['represent'];
186
187  $page['infos'][] = l10n('Photo informations updated');
188}
189
190// tags
191$query = '
192SELECT
193    id,
194    name
195  FROM '.IMAGE_TAG_TABLE.' AS it
196    JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id
197  WHERE image_id = '.$_GET['image_id'].'
198;';
199$tag_selection = get_taglist($query);
200
201// retrieving direct information about picture
202$query = '
203SELECT *
204  FROM '.IMAGES_TABLE.'
205  WHERE id = '.$_GET['image_id'].'
206;';
207$row = pwg_db_fetch_assoc(pwg_query($query));
208
209$storage_category_id = null;
210if (!empty($row['storage_category_id']))
211{
212  $storage_category_id = $row['storage_category_id'];
213}
214
215$image_file = $row['file'];
216
217// +-----------------------------------------------------------------------+
218// |                             template init                             |
219// +-----------------------------------------------------------------------+
220
221$template->set_filenames(
222  array(
223    'picture_modify' => 'picture_modify.tpl'
224    )
225  );
226
227$admin_url_start = $admin_photo_base_url.'-properties';
228$admin_url_start.= isset($_GET['cat_id']) ? '&amp;cat_id='.$_GET['cat_id'] : '';
229
230$template->assign(
231  array(
232    'tag_selection' => $tag_selection,
233    'U_SYNC' => $admin_url_start.'&amp;sync_metadata=1',
234    'U_DELETE' => $admin_url_start.'&amp;delete=1&amp;pwg_token='.get_pwg_token(),
235
236    'PATH'=>$row['path'],
237
238    'TN_SRC' => DerivativeImage::thumb_url($row),
239
240    'NAME' =>
241      isset($_POST['name']) ?
242        stripslashes($_POST['name']) : @$row['name'],
243
244    'TITLE' => render_element_name($row),
245
246    'DIMENSIONS' => @$row['width'].' * '.@$row['height'],
247
248    'FILESIZE' => @$row['filesize'].' KB',
249
250    'REGISTRATION_DATE' => format_date($row['date_available']),
251
252    'AUTHOR' => htmlspecialchars(
253      isset($_POST['author'])
254        ? stripslashes($_POST['author'])
255        : @$row['author']
256      ),
257
258    'DATE_CREATION' => $row['date_creation'],
259
260    'DESCRIPTION' =>
261      htmlspecialchars( isset($_POST['description']) ?
262        stripslashes($_POST['description']) : @$row['comment'] ),
263
264    'F_ACTION' =>
265        get_root_url().'admin.php'
266        .get_query_string_diff(array('sync_metadata'))
267    )
268  );
269
270$added_by = 'N/A';
271$query = '
272SELECT '.$conf['user_fields']['username'].' AS username
273  FROM '.USERS_TABLE.'
274  WHERE '.$conf['user_fields']['id'].' = '.$row['added_by'].'
275;';
276$result = pwg_query($query);
277while ($user_row = pwg_db_fetch_assoc($result))
278{
279  $row['added_by'] = $user_row['username'];
280}
281
282$intro_vars = array(
283  'file' => l10n('Original file : %s', $row['file']),
284  'add_date' => l10n('Posted %s on %s', time_since($row['date_available'], 'year'), format_date($row['date_available'], false, false)),
285  'added_by' => l10n('Added by %s', $row['added_by']),
286  'size' => $row['width'].'&times;'.$row['height'].' pixels, '.sprintf('%.2f', $row['filesize']/1024).'MB',
287  'stats' => l10n('Visited %d times', $row['hit']),
288  'id' => l10n('Numeric identifier : %d', $row['id']),
289  );
290
291if ($conf['rate'] and !empty($row['rating_score']))
292{
293  $query = '
294SELECT
295    COUNT(*)
296  FROM '.RATE_TABLE.'
297  WHERE element_id = '.$_GET['image_id'].'
298;';
299  list($row['nb_rates']) = pwg_db_fetch_row(pwg_query($query));
300
301  $intro_vars['stats'].= ', '.sprintf(l10n('Rated %d times, score : %.2f'), $row['nb_rates'], $row['rating_score']);
302}
303
304$template->assign('INTRO', $intro_vars);
305
306
307if (in_array(get_extension($row['path']),$conf['picture_ext']))
308{
309  $template->assign('U_COI', get_root_url().'admin.php?page=picture_coi&amp;image_id='.$_GET['image_id']);
310}
311
312// image level options
313$selected_level = isset($_POST['level']) ? $_POST['level'] : $row['level'];
314$template->assign(
315    array(
316      'level_options'=> get_privacy_level_options(),
317      'level_options_selected' => array($selected_level)
318    )
319  );
320
321// categories
322$query = '
323SELECT category_id, uppercats
324  FROM '.IMAGE_CATEGORY_TABLE.' AS ic
325    INNER JOIN '.CATEGORIES_TABLE.' AS c
326      ON c.id = ic.category_id
327  WHERE image_id = '.$_GET['image_id'].'
328;';
329$result = pwg_query($query);
330
331while ($row = pwg_db_fetch_assoc($result))
332{
333  $name =
334    get_cat_display_name_cache(
335      $row['uppercats'],
336      get_root_url().'admin.php?page=album-'
337      );
338
339  if ($row['category_id'] == $storage_category_id)
340  {
341    $template->assign('STORAGE_CATEGORY', $name);
342  }
343  else
344  {
345    $template->append('related_categories', $name);
346  }
347}
348
349// jump to link
350//
351// 1. find all linked categories that are reachable for the current user.
352// 2. if a category is available in the URL, use it if reachable
353// 3. if URL category not available or reachable, use the first reachable
354//    linked category
355// 4. if no category reachable, no jumpto link
356
357$query = '
358SELECT category_id
359  FROM '.IMAGE_CATEGORY_TABLE.'
360  WHERE image_id = '.$_GET['image_id'].'
361;';
362
363$authorizeds = array_diff(
364  array_from_query($query, 'category_id'),
365  explode(
366    ',',
367    calculate_permissions($user['id'], $user['status'])
368    )
369  );
370
371if (isset($_GET['cat_id'])
372    and in_array($_GET['cat_id'], $authorizeds))
373{
374  $url_img = make_picture_url(
375    array(
376      'image_id' => $_GET['image_id'],
377      'image_file' => $image_file,
378      'category' => $cache['cat_names'][ $_GET['cat_id'] ],
379      )
380    );
381}
382else
383{
384  foreach ($authorizeds as $category)
385  {
386    $url_img = make_picture_url(
387      array(
388        'image_id' => $_GET['image_id'],
389        'image_file' => $image_file,
390        'category' => $cache['cat_names'][ $category ],
391        )
392      );
393    break;
394  }
395}
396
397if (isset($url_img))
398{
399  $template->assign( 'U_JUMPTO', $url_img );
400}
401
402// associate to albums
403$query = '
404SELECT id
405  FROM '.CATEGORIES_TABLE.'
406    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
407  WHERE image_id = '.$_GET['image_id'].'
408;';
409$associated_albums = query2array($query, null, 'id');
410
411$template->assign(array(
412  'associated_albums' => $associated_albums,
413  'represented_albums' => $represented_albums,
414  'STORAGE_ALBUM' => $storage_category_id,
415  'CACHE_KEYS' => get_admin_client_cache_keys(array('tags', 'categories')),
416  ));
417
418trigger_notify('loc_end_picture_modify');
419
420//----------------------------------------------------------- sending html code
421
422$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
423?>
Note: See TracBrowser for help on using the repository browser.