source: trunk/admin/picture_modify.php @ 13077

Last change on this file since 13077 was 13077, checked in by plg, 12 years ago

feature 2564: redesign on photo administration screen.

  • one screen with several tabs (for now: properties + coi)
  • double select boxes for album associations and representation have been converted to simple multiple select boxes with jQuery Chosen
  • more details about the photo in an introduction text
  • Property svn:eol-style set to LF
File size: 12.8 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{
299  $added_by = $user_row['username'];
300}
301
302$intro = sprintf(
303  l10n('This photo was posted on %s by %s.'),
304  format_date($row['date_available']),
305  $added_by
306  );
307
308$intro.= ' ';
309
310$intro.= sprintf(
311  l10n('Original file is %s, %ux%u pixels, %.2fMB.'),
312  $row['file'],
313  $row['width'],
314  $row['height'],
315  $row['filesize']/1024
316  );
317
318$intro.= ' ';
319
320$intro.= sprintf(
321  l10n('%u visits'),
322  $row['hit']
323  );
324
325if ($conf['rate'] and !empty($row['rating_score']))
326{
327  $query = '
328SELECT
329    COUNT(*)
330  FROM '.RATE_TABLE.'
331  WHERE element_id = '.$_GET['image_id'].'
332;';
333  list($nb_rates) = pwg_db_fetch_row(pwg_query($query));
334 
335  $intro.= sprintf(
336    l10n(', %u rates, rating score %s'),
337    $nb_rates,
338    $row['rating_score']
339    );
340}
341
342$intro.= '. ';
343
344$intro.= sprintf(
345  l10n('Numeric identifier is %u.'),
346  $row['id']
347  );
348
349$template->assign('INTRO', $intro);
350
[13038]351if (in_array(get_extension($row['path']),$conf['picture_ext']))
352{
353  $template->assign('U_COI', get_root_url().'admin.php?page=picture_coi&amp;image_id='.$_GET['image_id']);
354}
355
[2090]356// image level options
[2227]357$selected_level = isset($_POST['level']) ? $_POST['level'] : $row['level'];
358$template->assign(
[2090]359    array(
[6025]360      'level_options'=> get_privacy_level_options(),
[2227]361      'level_options_selected' => array($selected_level)
362    )
363  );
[2090]364
[825]365// creation date
366unset($day, $month, $year);
367
368if (isset($_POST['date_creation_action'])
369    and 'set' == $_POST['date_creation_action'])
370{
371  foreach (array('day', 'month', 'year') as $varname)
372  {
373    $$varname = $_POST['date_creation_'.$varname];
374  }
375}
376else if (isset($row['date_creation']) and !empty($row['date_creation']))
377{
378  list($year, $month, $day) = explode('-', $row['date_creation']);
379}
380else
381{
382  list($year, $month, $day) = array('', 0, 0);
383}
[2227]384
385
386$month_list = $lang['month'];
387$month_list[0]='------------';
388ksort($month_list);
[1092]389
[2227]390$template->assign(
391    array(
392      'DATE_CREATION_DAY_VALUE' => $day,
393      'DATE_CREATION_MONTH_VALUE' => $month,
394      'DATE_CREATION_YEAR_VALUE' => $year,
395      'month_list' => $month_list,
396      )
397    );
398
[825]399$query = '
400SELECT category_id, uppercats
401  FROM '.IMAGE_CATEGORY_TABLE.' AS ic
402    INNER JOIN '.CATEGORIES_TABLE.' AS c
403      ON c.id = ic.category_id
404  WHERE image_id = '.$_GET['image_id'].'
405;';
406$result = pwg_query($query);
407
[4325]408while ($row = pwg_db_fetch_assoc($result))
[825]409{
410  $name =
411    get_cat_display_name_cache(
412      $row['uppercats'],
[13013]413      get_root_url().'admin.php?page=album-',
[825]414      false
415      );
[1092]416
[825]417  if ($row['category_id'] == $storage_category_id)
418  {
[2227]419    $template->assign('STORAGE_CATEGORY', $name);
[825]420  }
421  else
422  {
[2227]423    $template->append('related_categories', $name);
[825]424  }
425}
426
427// jump to link
428//
429// 1. find all linked categories that are reachable for the current user.
430// 2. if a category is available in the URL, use it if reachable
431// 3. if URL category not available or reachable, use the first reachable
432//    linked category
433// 4. if no category reachable, no jumpto link
434
435$query = '
436SELECT category_id
437  FROM '.IMAGE_CATEGORY_TABLE.'
438  WHERE image_id = '.$_GET['image_id'].'
439;';
[1082]440
[825]441$authorizeds = array_diff(
442  array_from_query($query, 'category_id'),
[1082]443  explode(
444    ',',
445    calculate_permissions($user['id'], $user['status'])
446    )
[825]447  );
448
449if (isset($_GET['cat_id'])
450    and in_array($_GET['cat_id'], $authorizeds))
451{
[1503]452  $url_img = make_picture_url(
[1082]453    array(
454      'image_id' => $_GET['image_id'],
[1092]455      'image_file' => $image_file,
[1861]456      'category' => $cache['cat_names'][ $_GET['cat_id'] ],
[1082]457      )
458    );
[825]459}
460else
461{
462  foreach ($authorizeds as $category)
463  {
[1503]464    $url_img = make_picture_url(
[1082]465      array(
466        'image_id' => $_GET['image_id'],
[1092]467        'image_file' => $image_file,
[1861]468        'category' => $cache['cat_names'][ $category ],
[1082]469        )
470      );
[825]471    break;
472  }
473}
474
475if (isset($url_img))
476{
[2227]477  $template->assign( 'U_JUMPTO', $url_img );
[825]478}
[1092]479
[13077]480// associate to albums
[635]481$query = '
[13077]482SELECT id
[635]483  FROM '.CATEGORIES_TABLE.'
484    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
[13077]485  WHERE image_id = '.$_GET['image_id'].'
[635]486;';
[13077]487$associate_options_selected = array_from_query($query, 'id');
[635]488
489$query = '
490SELECT id,name,uppercats,global_rank
491  FROM '.CATEGORIES_TABLE.'
492;';
[13077]493display_select_cat_wrapper($query, $associate_options_selected, 'associate_options');
494display_select_cat_wrapper($query, $represent_options_selected, 'represent_options');
[809]495
[61]496//----------------------------------------------------------- sending html code
[817]497
[509]498$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
[362]499?>
Note: See TracBrowser for help on using the repository browser.