source: trunk/admin/picture_modify.php @ 13461

Last change on this file since 13461 was 13086, checked in by mistic100, 12 years ago

feature 2564: small changes in infos list

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