source: trunk/admin/picture_modify.php @ 25867

Last change on this file since 25867 was 25425, checked in by mistic100, 11 years ago

delete replace_space function, modify get_cat_display_name_* functions

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