source: trunk/admin/picture_modify.php @ 24946

Last change on this file since 24946 was 24946, checked in by rvelices, 11 years ago

fix picture modify create date for days/months on two digits starting with 0

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