source: trunk/admin/picture_modify.php @ 12855

Last change on this file since 12855 was 12855, checked in by rvelices, 12 years ago

feature 2548 multisize - improved picture.php display (original...) + code cleanup

  • Property svn:eol-style set to LF
File size: 13.0 KB
RevLine 
[61]1<?php
[362]2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[8728]5// | Copyright(C) 2008-2011 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
[1072]39// +-----------------------------------------------------------------------+
[8764]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
[9943]55  if (isset($_GET['cat_id']) and !empty($_GET['cat_id']))
[8764]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// +-----------------------------------------------------------------------+
[825]92// |                          synchronize metadata                         |
93// +-----------------------------------------------------------------------+
94
[8126]95if (isset($_GET['sync_metadata']))
[825]96{
[12831]97  sync_metadata(array( intval($_GET['image_id'])));
[825]98  array_push($page['infos'], l10n('Metadata synchronized from file'));
99}
100
[61]101//--------------------------------------------------------- update informations
[825]102
[61]103// first, we verify whether there is a mistake on the given creation date
[825]104if (isset($_POST['date_creation_action'])
105    and 'set' == $_POST['date_creation_action'])
[61]106{
[5288]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'])
[825]112    )
[575]113  {
[5021]114    array_push($page['errors'], l10n('wrong date'));
[575]115  }
[61]116}
[825]117
[8126]118if (isset($_POST['submit']) and count($page['errors']) == 0)
[61]119{
[825]120  $data = array();
121  $data{'id'} = $_GET['image_id'];
122  $data{'name'} = $_POST['name'];
123  $data{'author'} = $_POST['author'];
[2090]124  $data['level'] = $_POST['level'];
[61]125
[825]126  if ($conf['allow_html_descriptions'])
127  {
128    $data{'comment'} = @$_POST['description'];
129  }
[61]130  else
[825]131  {
132    $data{'comment'} = strip_tags(@$_POST['description']);
133  }
[61]134
[825]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  }
[61]148
[825]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
[5188]158  // time to deal with tags
[5067]159  $tag_ids = array();
[11220]160  if (!empty($_POST['tags']))
[5067]161  {
[11039]162    $tag_ids = get_tag_ids($_POST['tags']);
[5067]163  }
[5188]164  set_tags($tag_ids, $_GET['image_id']);
[1119]165
[8727]166  array_push($page['infos'], l10n('Photo informations updated'));
[635]167}
168// associate the element to other categories than its storage category
169if (isset($_POST['associate'])
170    and isset($_POST['cat_dissociated'])
[1571]171    and count($_POST['cat_dissociated']) > 0
172  )
[635]173{
[1121]174  associate_images_to_categories(
175    array($_GET['image_id']),
176    $_POST['cat_dissociated']
[1065]177    );
[635]178}
179// dissociate the element from categories (but not from its storage category)
180if (isset($_POST['dissociate'])
181    and isset($_POST['cat_associated'])
[1571]182    and count($_POST['cat_associated']) > 0
183  )
[635]184{
[575]185  $query = '
186DELETE FROM '.IMAGE_CATEGORY_TABLE.'
187  WHERE image_id = '.$_GET['image_id'].'
[1121]188    AND category_id IN ('.implode(',', $_POST['cat_associated']).')
[635]189';
190  pwg_query($query);
[1609]191
[635]192  update_category($_POST['cat_associated']);
[61]193}
[640]194// elect the element to represent the given categories
195if (isset($_POST['elect'])
196    and isset($_POST['cat_dismissed'])
[1571]197    and count($_POST['cat_dismissed']) > 0
198  )
[640]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'])
[1571]214    and count($_POST['cat_elected']) > 0
215  )
[640]216{
217  set_random_representant($_POST['cat_elected']);
218}
[61]219
[5067]220// tags
221$query = '
222SELECT
[11853]223    id,
224    name
[5067]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;';
[11039]229$tag_selection = get_taglist($query);
[5067]230
[11039]231$query = '
232SELECT
[11853]233    id,
234    name
[11039]235  FROM '.TAGS_TABLE.'
236;';
[12259]237$tags = get_taglist($query, false);
[11039]238
[61]239// retrieving direct information about picture
[575]240$query = '
[825]241SELECT *
242  FROM '.IMAGES_TABLE.'
243  WHERE id = '.$_GET['image_id'].'
[575]244;';
[4325]245$row = pwg_db_fetch_assoc(pwg_query($query));
[345]246
[2575]247$storage_category_id = null;
248if (!empty($row['storage_category_id']))
249{
250  $storage_category_id = $row['storage_category_id'];
251}
252
[1092]253$image_file = $row['file'];
[635]254
[825]255// +-----------------------------------------------------------------------+
256// |                             template init                             |
257// +-----------------------------------------------------------------------+
258
[817]259$template->set_filenames(
260  array(
[2530]261    'picture_modify' => 'picture_modify.tpl'
[817]262    )
263  );
264
[8764]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
[2227]269$template->assign(
[825]270  array(
[11039]271    'tag_selection' => $tag_selection,
[5067]272    'tags' => $tags,
[8764]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(),
[1092]275
[825]276    'PATH'=>$row['path'],
[1092]277
[12796]278    'TN_SRC' => DerivativeImage::thumb_url($row),
[1092]279
[825]280    'NAME' =>
281      isset($_POST['name']) ?
282        stripslashes($_POST['name']) : @$row['name'],
[1092]283
[825]284    'DIMENSIONS' => @$row['width'].' * '.@$row['height'],
[1092]285
[825]286    'FILESIZE' => @$row['filesize'].' KB',
[1092]287
[3122]288    'REGISTRATION_DATE' => format_date($row['date_available']),
[1092]289
[6714]290    'AUTHOR' => htmlspecialchars(
291      isset($_POST['author'])
292        ? stripslashes($_POST['author'])
293        : @$row['author']
294      ),
[1092]295
[825]296    'DESCRIPTION' =>
[1861]297      htmlspecialchars( isset($_POST['description']) ?
298        stripslashes($_POST['description']) : @$row['comment'] ),
[1092]299
[825]300    'F_ACTION' =>
[2304]301        get_root_url().'admin.php'
[825]302        .get_query_string_diff(array('sync_metadata'))
303    )
304  );
305
[2090]306// image level options
[2227]307$selected_level = isset($_POST['level']) ? $_POST['level'] : $row['level'];
308$template->assign(
[2090]309    array(
[6025]310      'level_options'=> get_privacy_level_options(),
[2227]311      'level_options_selected' => array($selected_level)
312    )
313  );
[2090]314
[825]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}
[2227]334
335
336$month_list = $lang['month'];
337$month_list[0]='------------';
338ksort($month_list);
[1092]339
[2227]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
[825]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
[4325]358while ($row = pwg_db_fetch_assoc($result))
[825]359{
360  $name =
361    get_cat_display_name_cache(
362      $row['uppercats'],
[2227]363      get_root_url().'admin.php?page=cat_modify&amp;cat_id=',
[825]364      false
365      );
[1092]366
[825]367  if ($row['category_id'] == $storage_category_id)
368  {
[2227]369    $template->assign('STORAGE_CATEGORY', $name);
[825]370  }
371  else
372  {
[2227]373    $template->append('related_categories', $name);
[825]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;';
[1082]390
[825]391$authorizeds = array_diff(
392  array_from_query($query, 'category_id'),
[1082]393  explode(
394    ',',
395    calculate_permissions($user['id'], $user['status'])
396    )
[825]397  );
398
399if (isset($_GET['cat_id'])
400    and in_array($_GET['cat_id'], $authorizeds))
401{
[1503]402  $url_img = make_picture_url(
[1082]403    array(
404      'image_id' => $_GET['image_id'],
[1092]405      'image_file' => $image_file,
[1861]406      'category' => $cache['cat_names'][ $_GET['cat_id'] ],
[1082]407      )
408    );
[825]409}
410else
411{
412  foreach ($authorizeds as $category)
413  {
[1503]414    $url_img = make_picture_url(
[1082]415      array(
416        'image_id' => $_GET['image_id'],
[1092]417        'image_file' => $image_file,
[1861]418        'category' => $cache['cat_names'][ $category ],
[1082]419        )
420      );
[825]421    break;
422  }
423}
424
425if (isset($url_img))
426{
[2227]427  $template->assign( 'U_JUMPTO', $url_img );
[825]428}
[1092]429
[61]430// associate to another category ?
[635]431$query = '
432SELECT id,name,uppercats,global_rank
433  FROM '.CATEGORIES_TABLE.'
434    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
[2575]435  WHERE image_id = '.$_GET['image_id'];
436if (isset($storage_category_id))
437{
438  $query.= '
439    AND id != '.$storage_category_id;
440}
441$query.= '
[635]442;';
[2227]443display_select_cat_wrapper($query, array(), 'associated_options');
[635]444
445$result = pwg_query($query);
[3390]446$associateds = array(-1);
[2575]447if (isset($storage_category_id))
448{
449  array_push($associateds, $storage_category_id);
450}
[4325]451while ($row = pwg_db_fetch_assoc($result))
[345]452{
[635]453  array_push($associateds, $row['id']);
[345]454}
[635]455$query = '
456SELECT id,name,uppercats,global_rank
457  FROM '.CATEGORIES_TABLE.'
458  WHERE id NOT IN ('.implode(',', $associateds).')
459;';
[2227]460display_select_cat_wrapper($query, array(), 'dissociated_options');
[809]461
[640]462// representing
463$query = '
464SELECT id,name,uppercats,global_rank
465  FROM '.CATEGORIES_TABLE.'
466  WHERE representative_picture_id = '.$_GET['image_id'].'
467;';
[2227]468display_select_cat_wrapper($query, array(), 'elected_options');
[640]469
470$query = '
471SELECT id,name,uppercats,global_rank
472  FROM '.CATEGORIES_TABLE.'
[809]473  WHERE representative_picture_id != '.$_GET['image_id'].'
474    OR representative_picture_id IS NULL
[640]475;';
[2227]476display_select_cat_wrapper($query, array(), 'dismissed_options');
[817]477
[61]478//----------------------------------------------------------- sending html code
[817]479
[509]480$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
[362]481?>
Note: See TracBrowser for help on using the repository browser.