source: branches/2.4/admin/picture_modify.php @ 16335

Last change on this file since 16335 was 16335, checked in by rvelices, 12 years ago

user_cache was not invalidated on photo deletion (merge from trunk to branch 2.4)

  • Property svn:eol-style set to LF
File size: 12.9 KB
RevLine 
[61]1<?php
[362]2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[12922]5// | Copyright(C) 2008-2012 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;';
45$represent_options_selected = array_from_query($query, 'id');
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);
[16335]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    );
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// +-----------------------------------------------------------------------+
[825]101// |                          synchronize metadata                         |
102// +-----------------------------------------------------------------------+
103
[8126]104if (isset($_GET['sync_metadata']))
[825]105{
[12831]106  sync_metadata(array( intval($_GET['image_id'])));
[825]107  array_push($page['infos'], l10n('Metadata synchronized from file'));
108}
109
[61]110//--------------------------------------------------------- update informations
[825]111
[61]112// first, we verify whether there is a mistake on the given creation date
[825]113if (isset($_POST['date_creation_action'])
114    and 'set' == $_POST['date_creation_action'])
[61]115{
[5288]116  if (!is_numeric($_POST['date_creation_year'])
117    or !checkdate(
118          $_POST['date_creation_month'],
119          $_POST['date_creation_day'],
120          $_POST['date_creation_year'])
[825]121    )
[575]122  {
[5021]123    array_push($page['errors'], l10n('wrong date'));
[575]124  }
[61]125}
[825]126
[8126]127if (isset($_POST['submit']) and count($page['errors']) == 0)
[61]128{
[825]129  $data = array();
130  $data{'id'} = $_GET['image_id'];
131  $data{'name'} = $_POST['name'];
132  $data{'author'} = $_POST['author'];
[2090]133  $data['level'] = $_POST['level'];
[61]134
[825]135  if ($conf['allow_html_descriptions'])
136  {
137    $data{'comment'} = @$_POST['description'];
138  }
[61]139  else
[825]140  {
141    $data{'comment'} = strip_tags(@$_POST['description']);
142  }
[61]143
[13077]144  if (!empty($_POST['date_creation_year']))
[825]145  {
[13077]146    $data{'date_creation'} =
147      $_POST['date_creation_year']
148      .'-'.$_POST['date_creation_month']
149      .'-'.$_POST['date_creation_day'];
[825]150  }
[13077]151  else
152  {
153    $data{'date_creation'} = null;
154  }
[61]155
[825]156  mass_updates(
157    IMAGES_TABLE,
158    array(
159      'primary' => array('id'),
160      'update' => array_diff(array_keys($data), array('id'))
161      ),
162    array($data)
163    );
164
[5188]165  // time to deal with tags
[5067]166  $tag_ids = array();
[11220]167  if (!empty($_POST['tags']))
[5067]168  {
[11039]169    $tag_ids = get_tag_ids($_POST['tags']);
[5067]170  }
[5188]171  set_tags($tag_ids, $_GET['image_id']);
[1119]172
[13077]173  // association to albums
174  move_images_to_categories(array($_GET['image_id']), $_POST['associate']);
[1609]175
[13077]176  // thumbnail for albums
177  if (!isset($_POST['represent']))
[640]178  {
[13077]179    $_POST['represent'] = array();
[640]180  }
[13077]181 
182  $no_longer_thumbnail_for = array_diff($represent_options_selected, $_POST['represent']);
183  if (count($no_longer_thumbnail_for) > 0)
184  {
185    set_random_representant($no_longer_thumbnail_for);
186  }
187
188  $new_thumbnail_for = array_diff($_POST['represent'], $represent_options_selected);
189  if (count($new_thumbnail_for) > 0)
190  {
191    $query = '
192UPDATE '.CATEGORIES_TABLE.'
193  SET representative_picture_id = '.$_GET['image_id'].'
194  WHERE id IN ('.implode(',', $new_thumbnail_for).')
195;';
196    pwg_query($query);
197  }
198
199  $represent_options_selected = $_POST['represent'];
200 
201  array_push($page['infos'], l10n('Photo informations updated'));
[640]202}
[61]203
[5067]204// tags
205$query = '
206SELECT
[11853]207    id,
208    name
[5067]209  FROM '.IMAGE_TAG_TABLE.' AS it
210    JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id
211  WHERE image_id = '.$_GET['image_id'].'
212;';
[11039]213$tag_selection = get_taglist($query);
[5067]214
[11039]215$query = '
216SELECT
[11853]217    id,
218    name
[11039]219  FROM '.TAGS_TABLE.'
220;';
[12259]221$tags = get_taglist($query, false);
[11039]222
[61]223// retrieving direct information about picture
[575]224$query = '
[825]225SELECT *
226  FROM '.IMAGES_TABLE.'
227  WHERE id = '.$_GET['image_id'].'
[575]228;';
[4325]229$row = pwg_db_fetch_assoc(pwg_query($query));
[345]230
[2575]231$storage_category_id = null;
232if (!empty($row['storage_category_id']))
233{
234  $storage_category_id = $row['storage_category_id'];
235}
236
[1092]237$image_file = $row['file'];
[635]238
[825]239// +-----------------------------------------------------------------------+
240// |                             template init                             |
241// +-----------------------------------------------------------------------+
242
[817]243$template->set_filenames(
244  array(
[2530]245    'picture_modify' => 'picture_modify.tpl'
[817]246    )
247  );
248
[13077]249$admin_url_start = $admin_photo_base_url.'-properties';
[8764]250$admin_url_start.= isset($_GET['cat_id']) ? '&amp;cat_id='.$_GET['cat_id'] : '';
251
[2227]252$template->assign(
[825]253  array(
[11039]254    'tag_selection' => $tag_selection,
[5067]255    'tags' => $tags,
[8764]256    'U_SYNC' => $admin_url_start.'&amp;sync_metadata=1',
257    'U_DELETE' => $admin_url_start.'&amp;delete=1&amp;pwg_token='.get_pwg_token(),
[1092]258
[825]259    'PATH'=>$row['path'],
[1092]260
[12796]261    'TN_SRC' => DerivativeImage::thumb_url($row),
[1092]262
[825]263    'NAME' =>
264      isset($_POST['name']) ?
265        stripslashes($_POST['name']) : @$row['name'],
[1092]266
[13077]267    'TITLE' => render_element_name($row),
268
[825]269    'DIMENSIONS' => @$row['width'].' * '.@$row['height'],
[1092]270
[825]271    'FILESIZE' => @$row['filesize'].' KB',
[1092]272
[3122]273    'REGISTRATION_DATE' => format_date($row['date_available']),
[1092]274
[6714]275    'AUTHOR' => htmlspecialchars(
276      isset($_POST['author'])
277        ? stripslashes($_POST['author'])
278        : @$row['author']
279      ),
[1092]280
[825]281    'DESCRIPTION' =>
[1861]282      htmlspecialchars( isset($_POST['description']) ?
283        stripslashes($_POST['description']) : @$row['comment'] ),
[1092]284
[825]285    'F_ACTION' =>
[2304]286        get_root_url().'admin.php'
[825]287        .get_query_string_diff(array('sync_metadata'))
288    )
289  );
290
[13077]291$added_by = 'N/A';
292$query = '
293SELECT '.$conf['user_fields']['username'].' AS username
294  FROM '.USERS_TABLE.'
295  WHERE '.$conf['user_fields']['id'].' = '.$row['added_by'].'
296;';
297$result = pwg_query($query);
298while ($user_row = pwg_db_fetch_assoc($result))
299{
[13084]300  $row['added_by'] = $user_row['username'];
[13077]301}
302
[13084]303$intro_vars = array(
304  'file' => sprintf(l10n('Original file : %s'), $row['file']),
[13086]305  'add_date' => sprintf(l10n('Posted %s on %s'), time_since($row['date_available'], 'year'), format_date($row['date_available'], false, false)),
306  'added_by' => sprintf(l10n('Added by %s'), $row['added_by']),
[13084]307  'size' => $row['width'].'&times;'.$row['height'].' pixels, '.sprintf('%.2f', $row['filesize']/1024).'MB',
[13086]308  'stats' => sprintf(l10n('Visited %d times'), $row['hit']),
[13084]309  'id' => sprintf(l10n('Numeric identifier : %d'), $row['id']),
[13077]310  );
311
312if ($conf['rate'] and !empty($row['rating_score']))
313{
314  $query = '
315SELECT
316    COUNT(*)
317  FROM '.RATE_TABLE.'
318  WHERE element_id = '.$_GET['image_id'].'
319;';
[13084]320  list($row['nb_rates']) = pwg_db_fetch_row(pwg_query($query));
[13077]321 
[13086]322  $intro_vars['stats'].= ', '.sprintf(l10n('Rated %d times, score : %.2f'), $row['nb_rates'], $row['rating_score']);
[13077]323}
324
[13084]325$template->assign('INTRO', $intro_vars);
326 
[13077]327
[13038]328if (in_array(get_extension($row['path']),$conf['picture_ext']))
329{
330  $template->assign('U_COI', get_root_url().'admin.php?page=picture_coi&amp;image_id='.$_GET['image_id']);
331}
332
[2090]333// image level options
[2227]334$selected_level = isset($_POST['level']) ? $_POST['level'] : $row['level'];
335$template->assign(
[2090]336    array(
[6025]337      'level_options'=> get_privacy_level_options(),
[2227]338      'level_options_selected' => array($selected_level)
339    )
340  );
[2090]341
[825]342// creation date
343unset($day, $month, $year);
344
345if (isset($_POST['date_creation_action'])
346    and 'set' == $_POST['date_creation_action'])
347{
348  foreach (array('day', 'month', 'year') as $varname)
349  {
350    $$varname = $_POST['date_creation_'.$varname];
351  }
352}
353else if (isset($row['date_creation']) and !empty($row['date_creation']))
354{
355  list($year, $month, $day) = explode('-', $row['date_creation']);
356}
357else
358{
359  list($year, $month, $day) = array('', 0, 0);
360}
[2227]361
362
363$month_list = $lang['month'];
364$month_list[0]='------------';
365ksort($month_list);
[1092]366
[2227]367$template->assign(
368    array(
369      'DATE_CREATION_DAY_VALUE' => $day,
370      'DATE_CREATION_MONTH_VALUE' => $month,
371      'DATE_CREATION_YEAR_VALUE' => $year,
372      'month_list' => $month_list,
373      )
374    );
375
[825]376$query = '
377SELECT category_id, uppercats
378  FROM '.IMAGE_CATEGORY_TABLE.' AS ic
379    INNER JOIN '.CATEGORIES_TABLE.' AS c
380      ON c.id = ic.category_id
381  WHERE image_id = '.$_GET['image_id'].'
382;';
383$result = pwg_query($query);
384
[4325]385while ($row = pwg_db_fetch_assoc($result))
[825]386{
387  $name =
388    get_cat_display_name_cache(
389      $row['uppercats'],
[13013]390      get_root_url().'admin.php?page=album-',
[825]391      false
392      );
[1092]393
[825]394  if ($row['category_id'] == $storage_category_id)
395  {
[2227]396    $template->assign('STORAGE_CATEGORY', $name);
[825]397  }
398  else
399  {
[2227]400    $template->append('related_categories', $name);
[825]401  }
402}
403
404// jump to link
405//
406// 1. find all linked categories that are reachable for the current user.
407// 2. if a category is available in the URL, use it if reachable
408// 3. if URL category not available or reachable, use the first reachable
409//    linked category
410// 4. if no category reachable, no jumpto link
411
412$query = '
413SELECT category_id
414  FROM '.IMAGE_CATEGORY_TABLE.'
415  WHERE image_id = '.$_GET['image_id'].'
416;';
[1082]417
[825]418$authorizeds = array_diff(
419  array_from_query($query, 'category_id'),
[1082]420  explode(
421    ',',
422    calculate_permissions($user['id'], $user['status'])
423    )
[825]424  );
425
426if (isset($_GET['cat_id'])
427    and in_array($_GET['cat_id'], $authorizeds))
428{
[1503]429  $url_img = make_picture_url(
[1082]430    array(
431      'image_id' => $_GET['image_id'],
[1092]432      'image_file' => $image_file,
[1861]433      'category' => $cache['cat_names'][ $_GET['cat_id'] ],
[1082]434      )
435    );
[825]436}
437else
438{
439  foreach ($authorizeds as $category)
440  {
[1503]441    $url_img = make_picture_url(
[1082]442      array(
443        'image_id' => $_GET['image_id'],
[1092]444        'image_file' => $image_file,
[1861]445        'category' => $cache['cat_names'][ $category ],
[1082]446        )
447      );
[825]448    break;
449  }
450}
451
452if (isset($url_img))
453{
[2227]454  $template->assign( 'U_JUMPTO', $url_img );
[825]455}
[1092]456
[13077]457// associate to albums
[635]458$query = '
[13077]459SELECT id
[635]460  FROM '.CATEGORIES_TABLE.'
461    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
[13077]462  WHERE image_id = '.$_GET['image_id'].'
[635]463;';
[13077]464$associate_options_selected = array_from_query($query, 'id');
[635]465
466$query = '
467SELECT id,name,uppercats,global_rank
468  FROM '.CATEGORIES_TABLE.'
469;';
[13077]470display_select_cat_wrapper($query, $associate_options_selected, 'associate_options');
471display_select_cat_wrapper($query, $represent_options_selected, 'represent_options');
[809]472
[61]473//----------------------------------------------------------- sending html code
[817]474
[509]475$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
[362]476?>
Note: See TracBrowser for help on using the repository browser.