source: trunk/admin/picture_modify.php @ 13018

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

feature 2561: redesign on album administration screen.

  • only one form on the screen and several tabs
  • simpler URL pattern : page=album-123-properties / page=album-123-sort_order / page=album-123-permissions
  • action to associate all photos of an album to another (new) virtual album was removed. This can be easily done with the new Batch Manager
  • notification by email on an album still has to be moved on a new dedicated tab
  • action icons (jump to album, manage photos, manage sub-albums, delete album...) replaced by plain text links
  • Property svn:eol-style set to LF
File size: 13.0 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// +-----------------------------------------------------------------------+
40// |                             delete photo                              |
41// +-----------------------------------------------------------------------+
42
43if (isset($_GET['delete']))
44{
45  check_pwg_token();
46
47  delete_elements(array($_GET['image_id']), true);
48
49  // where to redirect the user now?
50  //
51  // 1. if a category is available in the URL, use it
52  // 2. else use the first reachable linked category
53  // 3. redirect to gallery root
54
55  if (isset($_GET['cat_id']) and !empty($_GET['cat_id']))
56  {
57    redirect(
58      make_index_url(
59        array(
60          'category' => get_cat_info($_GET['cat_id'])
61          )
62        )
63      );
64  }
65
66  $query = '
67SELECT category_id
68  FROM '.IMAGE_CATEGORY_TABLE.'
69  WHERE image_id = '.$_GET['image_id'].'
70;';
71
72  $authorizeds = array_diff(
73    array_from_query($query, 'category_id'),
74    explode(',', calculate_permissions($user['id'], $user['status']))
75    );
76 
77  foreach ($authorizeds as $category_id)
78  {
79    redirect(
80      make_index_url(
81        array(
82          'category' => get_cat_info($category_id)
83          )
84        )
85      );
86  }
87
88  redirect(make_index_url());
89}
90
91// +-----------------------------------------------------------------------+
92// |                          synchronize metadata                         |
93// +-----------------------------------------------------------------------+
94
95if (isset($_GET['sync_metadata']))
96{
97  sync_metadata(array( intval($_GET['image_id'])));
98  array_push($page['infos'], l10n('Metadata synchronized from file'));
99}
100
101//--------------------------------------------------------- update informations
102
103// first, we verify whether there is a mistake on the given creation date
104if (isset($_POST['date_creation_action'])
105    and 'set' == $_POST['date_creation_action'])
106{
107  if (!is_numeric($_POST['date_creation_year'])
108    or !checkdate(
109          $_POST['date_creation_month'],
110          $_POST['date_creation_day'],
111          $_POST['date_creation_year'])
112    )
113  {
114    array_push($page['errors'], l10n('wrong date'));
115  }
116}
117
118if (isset($_POST['submit']) and count($page['errors']) == 0)
119{
120  $data = array();
121  $data{'id'} = $_GET['image_id'];
122  $data{'name'} = $_POST['name'];
123  $data{'author'} = $_POST['author'];
124  $data['level'] = $_POST['level'];
125
126  if ($conf['allow_html_descriptions'])
127  {
128    $data{'comment'} = @$_POST['description'];
129  }
130  else
131  {
132    $data{'comment'} = strip_tags(@$_POST['description']);
133  }
134
135  if (isset($_POST['date_creation_action']))
136  {
137    if ('set' == $_POST['date_creation_action'])
138    {
139      $data{'date_creation'} = $_POST['date_creation_year']
140                                 .'-'.$_POST['date_creation_month']
141                                 .'-'.$_POST['date_creation_day'];
142    }
143    else if ('unset' == $_POST['date_creation_action'])
144    {
145      $data{'date_creation'} = '';
146    }
147  }
148
149  mass_updates(
150    IMAGES_TABLE,
151    array(
152      'primary' => array('id'),
153      'update' => array_diff(array_keys($data), array('id'))
154      ),
155    array($data)
156    );
157
158  // time to deal with tags
159  $tag_ids = array();
160  if (!empty($_POST['tags']))
161  {
162    $tag_ids = get_tag_ids($_POST['tags']);
163  }
164  set_tags($tag_ids, $_GET['image_id']);
165
166  array_push($page['infos'], l10n('Photo informations updated'));
167}
168// associate the element to other categories than its storage category
169if (isset($_POST['associate'])
170    and isset($_POST['cat_dissociated'])
171    and count($_POST['cat_dissociated']) > 0
172  )
173{
174  associate_images_to_categories(
175    array($_GET['image_id']),
176    $_POST['cat_dissociated']
177    );
178}
179// dissociate the element from categories (but not from its storage category)
180if (isset($_POST['dissociate'])
181    and isset($_POST['cat_associated'])
182    and count($_POST['cat_associated']) > 0
183  )
184{
185  $query = '
186DELETE FROM '.IMAGE_CATEGORY_TABLE.'
187  WHERE image_id = '.$_GET['image_id'].'
188    AND category_id IN ('.implode(',', $_POST['cat_associated']).')
189';
190  pwg_query($query);
191
192  update_category($_POST['cat_associated']);
193}
194// elect the element to represent the given categories
195if (isset($_POST['elect'])
196    and isset($_POST['cat_dismissed'])
197    and count($_POST['cat_dismissed']) > 0
198  )
199{
200  $datas = array();
201  foreach ($_POST['cat_dismissed'] as $category_id)
202  {
203    array_push($datas,
204               array('id' => $category_id,
205                     'representative_picture_id' => $_GET['image_id']));
206  }
207  $fields = array('primary' => array('id'),
208                  'update' => array('representative_picture_id'));
209  mass_updates(CATEGORIES_TABLE, $fields, $datas);
210}
211// dismiss the element as representant of the given categories
212if (isset($_POST['dismiss'])
213    and isset($_POST['cat_elected'])
214    and count($_POST['cat_elected']) > 0
215  )
216{
217  set_random_representant($_POST['cat_elected']);
218}
219
220// tags
221$query = '
222SELECT
223    id,
224    name
225  FROM '.IMAGE_TAG_TABLE.' AS it
226    JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id
227  WHERE image_id = '.$_GET['image_id'].'
228;';
229$tag_selection = get_taglist($query);
230
231$query = '
232SELECT
233    id,
234    name
235  FROM '.TAGS_TABLE.'
236;';
237$tags = get_taglist($query, false);
238
239// retrieving direct information about picture
240$query = '
241SELECT *
242  FROM '.IMAGES_TABLE.'
243  WHERE id = '.$_GET['image_id'].'
244;';
245$row = pwg_db_fetch_assoc(pwg_query($query));
246
247$storage_category_id = null;
248if (!empty($row['storage_category_id']))
249{
250  $storage_category_id = $row['storage_category_id'];
251}
252
253$image_file = $row['file'];
254
255// +-----------------------------------------------------------------------+
256// |                             template init                             |
257// +-----------------------------------------------------------------------+
258
259$template->set_filenames(
260  array(
261    'picture_modify' => 'picture_modify.tpl'
262    )
263  );
264
265$admin_url_start = get_root_url().'admin.php?page=picture_modify';
266$admin_url_start.= '&amp;image_id='.$_GET['image_id'];
267$admin_url_start.= isset($_GET['cat_id']) ? '&amp;cat_id='.$_GET['cat_id'] : '';
268
269$template->assign(
270  array(
271    'tag_selection' => $tag_selection,
272    'tags' => $tags,
273    'U_SYNC' => $admin_url_start.'&amp;sync_metadata=1',
274    'U_DELETE' => $admin_url_start.'&amp;delete=1&amp;pwg_token='.get_pwg_token(),
275
276    'PATH'=>$row['path'],
277
278    'TN_SRC' => DerivativeImage::thumb_url($row),
279
280    'NAME' =>
281      isset($_POST['name']) ?
282        stripslashes($_POST['name']) : @$row['name'],
283
284    'DIMENSIONS' => @$row['width'].' * '.@$row['height'],
285
286    'FILESIZE' => @$row['filesize'].' KB',
287
288    'REGISTRATION_DATE' => format_date($row['date_available']),
289
290    'AUTHOR' => htmlspecialchars(
291      isset($_POST['author'])
292        ? stripslashes($_POST['author'])
293        : @$row['author']
294      ),
295
296    'DESCRIPTION' =>
297      htmlspecialchars( isset($_POST['description']) ?
298        stripslashes($_POST['description']) : @$row['comment'] ),
299
300    'F_ACTION' =>
301        get_root_url().'admin.php'
302        .get_query_string_diff(array('sync_metadata'))
303    )
304  );
305
306// image level options
307$selected_level = isset($_POST['level']) ? $_POST['level'] : $row['level'];
308$template->assign(
309    array(
310      'level_options'=> get_privacy_level_options(),
311      'level_options_selected' => array($selected_level)
312    )
313  );
314
315// creation date
316unset($day, $month, $year);
317
318if (isset($_POST['date_creation_action'])
319    and 'set' == $_POST['date_creation_action'])
320{
321  foreach (array('day', 'month', 'year') as $varname)
322  {
323    $$varname = $_POST['date_creation_'.$varname];
324  }
325}
326else if (isset($row['date_creation']) and !empty($row['date_creation']))
327{
328  list($year, $month, $day) = explode('-', $row['date_creation']);
329}
330else
331{
332  list($year, $month, $day) = array('', 0, 0);
333}
334
335
336$month_list = $lang['month'];
337$month_list[0]='------------';
338ksort($month_list);
339
340$template->assign(
341    array(
342      'DATE_CREATION_DAY_VALUE' => $day,
343      'DATE_CREATION_MONTH_VALUE' => $month,
344      'DATE_CREATION_YEAR_VALUE' => $year,
345      'month_list' => $month_list,
346      )
347    );
348
349$query = '
350SELECT category_id, uppercats
351  FROM '.IMAGE_CATEGORY_TABLE.' AS ic
352    INNER JOIN '.CATEGORIES_TABLE.' AS c
353      ON c.id = ic.category_id
354  WHERE image_id = '.$_GET['image_id'].'
355;';
356$result = pwg_query($query);
357
358while ($row = pwg_db_fetch_assoc($result))
359{
360  $name =
361    get_cat_display_name_cache(
362      $row['uppercats'],
363      get_root_url().'admin.php?page=album-',
364      false
365      );
366
367  if ($row['category_id'] == $storage_category_id)
368  {
369    $template->assign('STORAGE_CATEGORY', $name);
370  }
371  else
372  {
373    $template->append('related_categories', $name);
374  }
375}
376
377// jump to link
378//
379// 1. find all linked categories that are reachable for the current user.
380// 2. if a category is available in the URL, use it if reachable
381// 3. if URL category not available or reachable, use the first reachable
382//    linked category
383// 4. if no category reachable, no jumpto link
384
385$query = '
386SELECT category_id
387  FROM '.IMAGE_CATEGORY_TABLE.'
388  WHERE image_id = '.$_GET['image_id'].'
389;';
390
391$authorizeds = array_diff(
392  array_from_query($query, 'category_id'),
393  explode(
394    ',',
395    calculate_permissions($user['id'], $user['status'])
396    )
397  );
398
399if (isset($_GET['cat_id'])
400    and in_array($_GET['cat_id'], $authorizeds))
401{
402  $url_img = make_picture_url(
403    array(
404      'image_id' => $_GET['image_id'],
405      'image_file' => $image_file,
406      'category' => $cache['cat_names'][ $_GET['cat_id'] ],
407      )
408    );
409}
410else
411{
412  foreach ($authorizeds as $category)
413  {
414    $url_img = make_picture_url(
415      array(
416        'image_id' => $_GET['image_id'],
417        'image_file' => $image_file,
418        'category' => $cache['cat_names'][ $category ],
419        )
420      );
421    break;
422  }
423}
424
425if (isset($url_img))
426{
427  $template->assign( 'U_JUMPTO', $url_img );
428}
429
430// associate to another category ?
431$query = '
432SELECT id,name,uppercats,global_rank
433  FROM '.CATEGORIES_TABLE.'
434    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
435  WHERE image_id = '.$_GET['image_id'];
436if (isset($storage_category_id))
437{
438  $query.= '
439    AND id != '.$storage_category_id;
440}
441$query.= '
442;';
443display_select_cat_wrapper($query, array(), 'associated_options');
444
445$result = pwg_query($query);
446$associateds = array(-1);
447if (isset($storage_category_id))
448{
449  array_push($associateds, $storage_category_id);
450}
451while ($row = pwg_db_fetch_assoc($result))
452{
453  array_push($associateds, $row['id']);
454}
455$query = '
456SELECT id,name,uppercats,global_rank
457  FROM '.CATEGORIES_TABLE.'
458  WHERE id NOT IN ('.implode(',', $associateds).')
459;';
460display_select_cat_wrapper($query, array(), 'dissociated_options');
461
462// representing
463$query = '
464SELECT id,name,uppercats,global_rank
465  FROM '.CATEGORIES_TABLE.'
466  WHERE representative_picture_id = '.$_GET['image_id'].'
467;';
468display_select_cat_wrapper($query, array(), 'elected_options');
469
470$query = '
471SELECT id,name,uppercats,global_rank
472  FROM '.CATEGORIES_TABLE.'
473  WHERE representative_picture_id != '.$_GET['image_id'].'
474    OR representative_picture_id IS NULL
475;';
476display_select_cat_wrapper($query, array(), 'dismissed_options');
477
478//----------------------------------------------------------- sending html code
479
480$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
481?>
Note: See TracBrowser for help on using the repository browser.