source: trunk/admin/picture_modify.php @ 13077

Revision 13077, 12.8 KB checked in by plg, 8 years ago (diff)

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
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
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// +-----------------------------------------------------------------------+
23
24if(!defined("PHPWG_ROOT_PATH"))
25{
26  die('Hacking attempt!');
27}
28
29include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
30
31// +-----------------------------------------------------------------------+
32// | Check Access and exit when user status is not ok                      |
33// +-----------------------------------------------------------------------+
34check_status(ACCESS_ADMINISTRATOR);
35
36check_input_parameter('image_id', $_GET, false, PATTERN_ID);
37check_input_parameter('cat_id', $_GET, false, PATTERN_ID);
38
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
47// +-----------------------------------------------------------------------+
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
63  if (isset($_GET['cat_id']) and !empty($_GET['cat_id']))
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// +-----------------------------------------------------------------------+
100// |                          synchronize metadata                         |
101// +-----------------------------------------------------------------------+
102
103if (isset($_GET['sync_metadata']))
104{
105  sync_metadata(array( intval($_GET['image_id'])));
106  array_push($page['infos'], l10n('Metadata synchronized from file'));
107}
108
109//--------------------------------------------------------- update informations
110
111// first, we verify whether there is a mistake on the given creation date
112if (isset($_POST['date_creation_action'])
113    and 'set' == $_POST['date_creation_action'])
114{
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'])
120    )
121  {
122    array_push($page['errors'], l10n('wrong date'));
123  }
124}
125
126if (isset($_POST['submit']) and count($page['errors']) == 0)
127{
128  $data = array();
129  $data{'id'} = $_GET['image_id'];
130  $data{'name'} = $_POST['name'];
131  $data{'author'} = $_POST['author'];
132  $data['level'] = $_POST['level'];
133
134  if ($conf['allow_html_descriptions'])
135  {
136    $data{'comment'} = @$_POST['description'];
137  }
138  else
139  {
140    $data{'comment'} = strip_tags(@$_POST['description']);
141  }
142
143  if (!empty($_POST['date_creation_year']))
144  {
145    $data{'date_creation'} =
146      $_POST['date_creation_year']
147      .'-'.$_POST['date_creation_month']
148      .'-'.$_POST['date_creation_day'];
149  }
150  else
151  {
152    $data{'date_creation'} = null;
153  }
154
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
164  // time to deal with tags
165  $tag_ids = array();
166  if (!empty($_POST['tags']))
167  {
168    $tag_ids = get_tag_ids($_POST['tags']);
169  }
170  set_tags($tag_ids, $_GET['image_id']);
171
172  // association to albums
173  move_images_to_categories(array($_GET['image_id']), $_POST['associate']);
174
175  // thumbnail for albums
176  if (!isset($_POST['represent']))
177  {
178    $_POST['represent'] = array();
179  }
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'));
201}
202
203// tags
204$query = '
205SELECT
206    id,
207    name
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;';
212$tag_selection = get_taglist($query);
213
214$query = '
215SELECT
216    id,
217    name
218  FROM '.TAGS_TABLE.'
219;';
220$tags = get_taglist($query, false);
221
222// retrieving direct information about picture
223$query = '
224SELECT *
225  FROM '.IMAGES_TABLE.'
226  WHERE id = '.$_GET['image_id'].'
227;';
228$row = pwg_db_fetch_assoc(pwg_query($query));
229
230$storage_category_id = null;
231if (!empty($row['storage_category_id']))
232{
233  $storage_category_id = $row['storage_category_id'];
234}
235
236$image_file = $row['file'];
237
238// +-----------------------------------------------------------------------+
239// |                             template init                             |
240// +-----------------------------------------------------------------------+
241
242$template->set_filenames(
243  array(
244    'picture_modify' => 'picture_modify.tpl'
245    )
246  );
247
248$admin_url_start = $admin_photo_base_url.'-properties';
249$admin_url_start.= isset($_GET['cat_id']) ? '&amp;cat_id='.$_GET['cat_id'] : '';
250
251$template->assign(
252  array(
253    'tag_selection' => $tag_selection,
254    'tags' => $tags,
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(),
257
258    'PATH'=>$row['path'],
259
260    'TN_SRC' => DerivativeImage::thumb_url($row),
261
262    'NAME' =>
263      isset($_POST['name']) ?
264        stripslashes($_POST['name']) : @$row['name'],
265
266    'TITLE' => render_element_name($row),
267
268    'DIMENSIONS' => @$row['width'].' * '.@$row['height'],
269
270    'FILESIZE' => @$row['filesize'].' KB',
271
272    'REGISTRATION_DATE' => format_date($row['date_available']),
273
274    'AUTHOR' => htmlspecialchars(
275      isset($_POST['author'])
276        ? stripslashes($_POST['author'])
277        : @$row['author']
278      ),
279
280    'DESCRIPTION' =>
281      htmlspecialchars( isset($_POST['description']) ?
282        stripslashes($_POST['description']) : @$row['comment'] ),
283
284    'F_ACTION' =>
285        get_root_url().'admin.php'
286        .get_query_string_diff(array('sync_metadata'))
287    )
288  );
289
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
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
356// image level options
357$selected_level = isset($_POST['level']) ? $_POST['level'] : $row['level'];
358$template->assign(
359    array(
360      'level_options'=> get_privacy_level_options(),
361      'level_options_selected' => array($selected_level)
362    )
363  );
364
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}
384
385
386$month_list = $lang['month'];
387$month_list[0]='------------';
388ksort($month_list);
389
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
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
408while ($row = pwg_db_fetch_assoc($result))
409{
410  $name =
411    get_cat_display_name_cache(
412      $row['uppercats'],
413      get_root_url().'admin.php?page=album-',
414      false
415      );
416
417  if ($row['category_id'] == $storage_category_id)
418  {
419    $template->assign('STORAGE_CATEGORY', $name);
420  }
421  else
422  {
423    $template->append('related_categories', $name);
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;';
440
441$authorizeds = array_diff(
442  array_from_query($query, 'category_id'),
443  explode(
444    ',',
445    calculate_permissions($user['id'], $user['status'])
446    )
447  );
448
449if (isset($_GET['cat_id'])
450    and in_array($_GET['cat_id'], $authorizeds))
451{
452  $url_img = make_picture_url(
453    array(
454      'image_id' => $_GET['image_id'],
455      'image_file' => $image_file,
456      'category' => $cache['cat_names'][ $_GET['cat_id'] ],
457      )
458    );
459}
460else
461{
462  foreach ($authorizeds as $category)
463  {
464    $url_img = make_picture_url(
465      array(
466        'image_id' => $_GET['image_id'],
467        'image_file' => $image_file,
468        'category' => $cache['cat_names'][ $category ],
469        )
470      );
471    break;
472  }
473}
474
475if (isset($url_img))
476{
477  $template->assign( 'U_JUMPTO', $url_img );
478}
479
480// associate to albums
481$query = '
482SELECT id
483  FROM '.CATEGORIES_TABLE.'
484    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
485  WHERE image_id = '.$_GET['image_id'].'
486;';
487$associate_options_selected = array_from_query($query, 'id');
488
489$query = '
490SELECT id,name,uppercats,global_rank
491  FROM '.CATEGORIES_TABLE.'
492;';
493display_select_cat_wrapper($query, $associate_options_selected, 'associate_options');
494display_select_cat_wrapper($query, $represent_options_selected, 'represent_options');
495
496//----------------------------------------------------------- sending html code
497
498$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
499?>
Note: See TracBrowser for help on using the repository browser.