source: trunk/admin/picture_modify.php @ 13084

Revision 13084, 12.8 KB checked in by mistic100, 8 years ago (diff)

feature 2564: display picture infos as list

  • 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  $row['added_by'] = $user_row['username'];
300}
301
302$intro_vars = array(
303  'file' => sprintf(l10n('Original file : %s'), $row['file']),
304  'added' => sprintf(l10n('Posted %s on %s by %s'), time_since($row['date_available'], 'month'), format_date($row['date_available'], false, false), $row['added_by']),
305  'size' => $row['width'].'&times;'.$row['height'].' pixels, '.sprintf('%.2f', $row['filesize']/1024).'MB',
306  'hits' => sprintf(l10n('%d visits'), $row['hit']),
307  'id' => sprintf(l10n('Numeric identifier : %d'), $row['id']),
308  );
309
310if ($conf['rate'] and !empty($row['rating_score']))
311{
312  $query = '
313SELECT
314    COUNT(*)
315  FROM '.RATE_TABLE.'
316  WHERE element_id = '.$_GET['image_id'].'
317;';
318  list($row['nb_rates']) = pwg_db_fetch_row(pwg_query($query));
319 
320  $intro_vars['rate'] = sprintf(l10n('Rated %d times, score : %f'), $row['nb_rates'], $row['rating_score']);
321}
322
323$template->assign('INTRO', $intro_vars);
324 
325
326if (in_array(get_extension($row['path']),$conf['picture_ext']))
327{
328  $template->assign('U_COI', get_root_url().'admin.php?page=picture_coi&amp;image_id='.$_GET['image_id']);
329}
330
331// image level options
332$selected_level = isset($_POST['level']) ? $_POST['level'] : $row['level'];
333$template->assign(
334    array(
335      'level_options'=> get_privacy_level_options(),
336      'level_options_selected' => array($selected_level)
337    )
338  );
339
340// creation date
341unset($day, $month, $year);
342
343if (isset($_POST['date_creation_action'])
344    and 'set' == $_POST['date_creation_action'])
345{
346  foreach (array('day', 'month', 'year') as $varname)
347  {
348    $$varname = $_POST['date_creation_'.$varname];
349  }
350}
351else if (isset($row['date_creation']) and !empty($row['date_creation']))
352{
353  list($year, $month, $day) = explode('-', $row['date_creation']);
354}
355else
356{
357  list($year, $month, $day) = array('', 0, 0);
358}
359
360
361$month_list = $lang['month'];
362$month_list[0]='------------';
363ksort($month_list);
364
365$template->assign(
366    array(
367      'DATE_CREATION_DAY_VALUE' => $day,
368      'DATE_CREATION_MONTH_VALUE' => $month,
369      'DATE_CREATION_YEAR_VALUE' => $year,
370      'month_list' => $month_list,
371      )
372    );
373
374$query = '
375SELECT category_id, uppercats
376  FROM '.IMAGE_CATEGORY_TABLE.' AS ic
377    INNER JOIN '.CATEGORIES_TABLE.' AS c
378      ON c.id = ic.category_id
379  WHERE image_id = '.$_GET['image_id'].'
380;';
381$result = pwg_query($query);
382
383while ($row = pwg_db_fetch_assoc($result))
384{
385  $name =
386    get_cat_display_name_cache(
387      $row['uppercats'],
388      get_root_url().'admin.php?page=album-',
389      false
390      );
391
392  if ($row['category_id'] == $storage_category_id)
393  {
394    $template->assign('STORAGE_CATEGORY', $name);
395  }
396  else
397  {
398    $template->append('related_categories', $name);
399  }
400}
401
402// jump to link
403//
404// 1. find all linked categories that are reachable for the current user.
405// 2. if a category is available in the URL, use it if reachable
406// 3. if URL category not available or reachable, use the first reachable
407//    linked category
408// 4. if no category reachable, no jumpto link
409
410$query = '
411SELECT category_id
412  FROM '.IMAGE_CATEGORY_TABLE.'
413  WHERE image_id = '.$_GET['image_id'].'
414;';
415
416$authorizeds = array_diff(
417  array_from_query($query, 'category_id'),
418  explode(
419    ',',
420    calculate_permissions($user['id'], $user['status'])
421    )
422  );
423
424if (isset($_GET['cat_id'])
425    and in_array($_GET['cat_id'], $authorizeds))
426{
427  $url_img = make_picture_url(
428    array(
429      'image_id' => $_GET['image_id'],
430      'image_file' => $image_file,
431      'category' => $cache['cat_names'][ $_GET['cat_id'] ],
432      )
433    );
434}
435else
436{
437  foreach ($authorizeds as $category)
438  {
439    $url_img = make_picture_url(
440      array(
441        'image_id' => $_GET['image_id'],
442        'image_file' => $image_file,
443        'category' => $cache['cat_names'][ $category ],
444        )
445      );
446    break;
447  }
448}
449
450if (isset($url_img))
451{
452  $template->assign( 'U_JUMPTO', $url_img );
453}
454
455// associate to albums
456$query = '
457SELECT id
458  FROM '.CATEGORIES_TABLE.'
459    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
460  WHERE image_id = '.$_GET['image_id'].'
461;';
462$associate_options_selected = array_from_query($query, 'id');
463
464$query = '
465SELECT id,name,uppercats,global_rank
466  FROM '.CATEGORIES_TABLE.'
467;';
468display_select_cat_wrapper($query, $associate_options_selected, 'associate_options');
469display_select_cat_wrapper($query, $represent_options_selected, 'represent_options');
470
471//----------------------------------------------------------- sending html code
472
473$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
474?>
Note: See TracBrowser for help on using the repository browser.