source: trunk/admin/picture_modify.php @ 14015

Last change on this file since 14015 was 13086, checked in by mistic100, 13 years ago

feature 2564: small changes in infos list

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