source: trunk/admin/picture_modify.php @ 29969

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

feature 3138: Add photo zoom when editing a photo

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