source: trunk/admin/picture_modify.php @ 11853

Last change on this file since 11853 was 11853, checked in by rvelices, 13 years ago

feature 2387: addd a filter by tag in the batch manager

  • Property svn:eol-style set to LF
File size: 13.3 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{
97  $query = '
98SELECT path
99  FROM '.IMAGES_TABLE.'
100  WHERE id = '.$_GET['image_id'].'
101;';
[4325]102  list($path) = pwg_db_fetch_row(pwg_query($query));
[825]103  update_metadata(array($_GET['image_id'] => $path));
104
105  array_push($page['infos'], l10n('Metadata synchronized from file'));
106}
107
[61]108//--------------------------------------------------------- update informations
[825]109
[61]110// first, we verify whether there is a mistake on the given creation date
[825]111if (isset($_POST['date_creation_action'])
112    and 'set' == $_POST['date_creation_action'])
[61]113{
[5288]114  if (!is_numeric($_POST['date_creation_year'])
115    or !checkdate(
116          $_POST['date_creation_month'],
117          $_POST['date_creation_day'],
118          $_POST['date_creation_year'])
[825]119    )
[575]120  {
[5021]121    array_push($page['errors'], l10n('wrong date'));
[575]122  }
[61]123}
[825]124
[8126]125if (isset($_POST['submit']) and count($page['errors']) == 0)
[61]126{
[825]127  $data = array();
128  $data{'id'} = $_GET['image_id'];
129  $data{'name'} = $_POST['name'];
130  $data{'author'} = $_POST['author'];
[2090]131  $data['level'] = $_POST['level'];
[61]132
[825]133  if ($conf['allow_html_descriptions'])
134  {
135    $data{'comment'} = @$_POST['description'];
136  }
[61]137  else
[825]138  {
139    $data{'comment'} = strip_tags(@$_POST['description']);
140  }
[61]141
[825]142  if (isset($_POST['date_creation_action']))
143  {
144    if ('set' == $_POST['date_creation_action'])
145    {
146      $data{'date_creation'} = $_POST['date_creation_year']
147                                 .'-'.$_POST['date_creation_month']
148                                 .'-'.$_POST['date_creation_day'];
149    }
150    else if ('unset' == $_POST['date_creation_action'])
151    {
152      $data{'date_creation'} = '';
153    }
154  }
[61]155
[825]156  mass_updates(
157    IMAGES_TABLE,
158    array(
159      'primary' => array('id'),
160      'update' => array_diff(array_keys($data), array('id'))
161      ),
162    array($data)
163    );
164
[5188]165  // time to deal with tags
[5067]166  $tag_ids = array();
[11220]167  if (!empty($_POST['tags']))
[5067]168  {
[11039]169    $tag_ids = get_tag_ids($_POST['tags']);
[5067]170  }
[5188]171  set_tags($tag_ids, $_GET['image_id']);
[1119]172
[8727]173  array_push($page['infos'], l10n('Photo informations updated'));
[635]174}
175// associate the element to other categories than its storage category
176if (isset($_POST['associate'])
177    and isset($_POST['cat_dissociated'])
[1571]178    and count($_POST['cat_dissociated']) > 0
179  )
[635]180{
[1121]181  associate_images_to_categories(
182    array($_GET['image_id']),
183    $_POST['cat_dissociated']
[1065]184    );
[635]185}
186// dissociate the element from categories (but not from its storage category)
187if (isset($_POST['dissociate'])
188    and isset($_POST['cat_associated'])
[1571]189    and count($_POST['cat_associated']) > 0
190  )
[635]191{
[575]192  $query = '
193DELETE FROM '.IMAGE_CATEGORY_TABLE.'
194  WHERE image_id = '.$_GET['image_id'].'
[1121]195    AND category_id IN ('.implode(',', $_POST['cat_associated']).')
[635]196';
197  pwg_query($query);
[1609]198
[635]199  update_category($_POST['cat_associated']);
[61]200}
[640]201// elect the element to represent the given categories
202if (isset($_POST['elect'])
203    and isset($_POST['cat_dismissed'])
[1571]204    and count($_POST['cat_dismissed']) > 0
205  )
[640]206{
207  $datas = array();
208  foreach ($_POST['cat_dismissed'] as $category_id)
209  {
210    array_push($datas,
211               array('id' => $category_id,
212                     'representative_picture_id' => $_GET['image_id']));
213  }
214  $fields = array('primary' => array('id'),
215                  'update' => array('representative_picture_id'));
216  mass_updates(CATEGORIES_TABLE, $fields, $datas);
217}
218// dismiss the element as representant of the given categories
219if (isset($_POST['dismiss'])
220    and isset($_POST['cat_elected'])
[1571]221    and count($_POST['cat_elected']) > 0
222  )
[640]223{
224  set_random_representant($_POST['cat_elected']);
225}
[61]226
[5067]227// tags
228$query = '
229SELECT
[11853]230    id,
231    name
[5067]232  FROM '.IMAGE_TAG_TABLE.' AS it
233    JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id
234  WHERE image_id = '.$_GET['image_id'].'
235;';
[11039]236$tag_selection = get_taglist($query);
[5067]237
[11039]238$query = '
239SELECT
[11853]240    id,
241    name
[11039]242  FROM '.TAGS_TABLE.'
243;';
244$tags = get_taglist($query);
245
[61]246// retrieving direct information about picture
[575]247$query = '
[825]248SELECT *
249  FROM '.IMAGES_TABLE.'
250  WHERE id = '.$_GET['image_id'].'
[575]251;';
[4325]252$row = pwg_db_fetch_assoc(pwg_query($query));
[345]253
[2575]254$storage_category_id = null;
255if (!empty($row['storage_category_id']))
256{
257  $storage_category_id = $row['storage_category_id'];
258}
259
[1092]260$image_file = $row['file'];
[635]261
[825]262// +-----------------------------------------------------------------------+
263// |                             template init                             |
264// +-----------------------------------------------------------------------+
265
[817]266$template->set_filenames(
267  array(
[2530]268    'picture_modify' => 'picture_modify.tpl'
[817]269    )
270  );
271
[8764]272$admin_url_start = get_root_url().'admin.php?page=picture_modify';
273$admin_url_start.= '&amp;image_id='.$_GET['image_id'];
274$admin_url_start.= isset($_GET['cat_id']) ? '&amp;cat_id='.$_GET['cat_id'] : '';
275
[2227]276$template->assign(
[825]277  array(
[11039]278    'tag_selection' => $tag_selection,
[5067]279    'tags' => $tags,
[8764]280    'U_SYNC' => $admin_url_start.'&amp;sync_metadata=1',
281    'U_DELETE' => $admin_url_start.'&amp;delete=1&amp;pwg_token='.get_pwg_token(),
[1092]282
[825]283    'PATH'=>$row['path'],
[1092]284
[1609]285    'TN_SRC' => get_thumbnail_url($row),
[1092]286
[825]287    'NAME' =>
288      isset($_POST['name']) ?
289        stripslashes($_POST['name']) : @$row['name'],
[1092]290
[825]291    'DIMENSIONS' => @$row['width'].' * '.@$row['height'],
[1092]292
[825]293    'FILESIZE' => @$row['filesize'].' KB',
[1092]294
[3122]295    'REGISTRATION_DATE' => format_date($row['date_available']),
[1092]296
[6714]297    'AUTHOR' => htmlspecialchars(
298      isset($_POST['author'])
299        ? stripslashes($_POST['author'])
300        : @$row['author']
301      ),
[1092]302
[825]303    'DESCRIPTION' =>
[1861]304      htmlspecialchars( isset($_POST['description']) ?
305        stripslashes($_POST['description']) : @$row['comment'] ),
[1092]306
[825]307    'F_ACTION' =>
[2304]308        get_root_url().'admin.php'
[825]309        .get_query_string_diff(array('sync_metadata'))
310    )
311  );
312
[1883]313if ($row['has_high'] == 'true')
314{
[2227]315  $template->assign(
316    'HIGH_FILESIZE',
317    isset($row['high_filesize'])
[1883]318        ? $row['high_filesize'].' KB'
[2227]319        : l10n('unknown')
[1883]320    );
321}
322
[2090]323// image level options
[2227]324$selected_level = isset($_POST['level']) ? $_POST['level'] : $row['level'];
325$template->assign(
[2090]326    array(
[6025]327      'level_options'=> get_privacy_level_options(),
[2227]328      'level_options_selected' => array($selected_level)
329    )
330  );
[2090]331
[825]332// creation date
333unset($day, $month, $year);
334
335if (isset($_POST['date_creation_action'])
336    and 'set' == $_POST['date_creation_action'])
337{
338  foreach (array('day', 'month', 'year') as $varname)
339  {
340    $$varname = $_POST['date_creation_'.$varname];
341  }
342}
343else if (isset($row['date_creation']) and !empty($row['date_creation']))
344{
345  list($year, $month, $day) = explode('-', $row['date_creation']);
346}
347else
348{
349  list($year, $month, $day) = array('', 0, 0);
350}
[2227]351
352
353$month_list = $lang['month'];
354$month_list[0]='------------';
355ksort($month_list);
[1092]356
[2227]357$template->assign(
358    array(
359      'DATE_CREATION_DAY_VALUE' => $day,
360      'DATE_CREATION_MONTH_VALUE' => $month,
361      'DATE_CREATION_YEAR_VALUE' => $year,
362      'month_list' => $month_list,
363      )
364    );
365
[825]366$query = '
367SELECT category_id, uppercats
368  FROM '.IMAGE_CATEGORY_TABLE.' AS ic
369    INNER JOIN '.CATEGORIES_TABLE.' AS c
370      ON c.id = ic.category_id
371  WHERE image_id = '.$_GET['image_id'].'
372;';
373$result = pwg_query($query);
374
[4325]375while ($row = pwg_db_fetch_assoc($result))
[825]376{
377  $name =
378    get_cat_display_name_cache(
379      $row['uppercats'],
[2227]380      get_root_url().'admin.php?page=cat_modify&amp;cat_id=',
[825]381      false
382      );
[1092]383
[825]384  if ($row['category_id'] == $storage_category_id)
385  {
[2227]386    $template->assign('STORAGE_CATEGORY', $name);
[825]387  }
388  else
389  {
[2227]390    $template->append('related_categories', $name);
[825]391  }
392}
393
394// jump to link
395//
396// 1. find all linked categories that are reachable for the current user.
397// 2. if a category is available in the URL, use it if reachable
398// 3. if URL category not available or reachable, use the first reachable
399//    linked category
400// 4. if no category reachable, no jumpto link
401
402$query = '
403SELECT category_id
404  FROM '.IMAGE_CATEGORY_TABLE.'
405  WHERE image_id = '.$_GET['image_id'].'
406;';
[1082]407
[825]408$authorizeds = array_diff(
409  array_from_query($query, 'category_id'),
[1082]410  explode(
411    ',',
412    calculate_permissions($user['id'], $user['status'])
413    )
[825]414  );
415
416if (isset($_GET['cat_id'])
417    and in_array($_GET['cat_id'], $authorizeds))
418{
[1503]419  $url_img = make_picture_url(
[1082]420    array(
421      'image_id' => $_GET['image_id'],
[1092]422      'image_file' => $image_file,
[1861]423      'category' => $cache['cat_names'][ $_GET['cat_id'] ],
[1082]424      )
425    );
[825]426}
427else
428{
429  foreach ($authorizeds as $category)
430  {
[1503]431    $url_img = make_picture_url(
[1082]432      array(
433        'image_id' => $_GET['image_id'],
[1092]434        'image_file' => $image_file,
[1861]435        'category' => $cache['cat_names'][ $category ],
[1082]436        )
437      );
[825]438    break;
439  }
440}
441
442if (isset($url_img))
443{
[2227]444  $template->assign( 'U_JUMPTO', $url_img );
[825]445}
[1092]446
[61]447// associate to another category ?
[635]448$query = '
449SELECT id,name,uppercats,global_rank
450  FROM '.CATEGORIES_TABLE.'
451    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
[2575]452  WHERE image_id = '.$_GET['image_id'];
453if (isset($storage_category_id))
454{
455  $query.= '
456    AND id != '.$storage_category_id;
457}
458$query.= '
[635]459;';
[2227]460display_select_cat_wrapper($query, array(), 'associated_options');
[635]461
462$result = pwg_query($query);
[3390]463$associateds = array(-1);
[2575]464if (isset($storage_category_id))
465{
466  array_push($associateds, $storage_category_id);
467}
[4325]468while ($row = pwg_db_fetch_assoc($result))
[345]469{
[635]470  array_push($associateds, $row['id']);
[345]471}
[635]472$query = '
473SELECT id,name,uppercats,global_rank
474  FROM '.CATEGORIES_TABLE.'
475  WHERE id NOT IN ('.implode(',', $associateds).')
476;';
[2227]477display_select_cat_wrapper($query, array(), 'dissociated_options');
[809]478
[640]479// representing
480$query = '
481SELECT id,name,uppercats,global_rank
482  FROM '.CATEGORIES_TABLE.'
483  WHERE representative_picture_id = '.$_GET['image_id'].'
484;';
[2227]485display_select_cat_wrapper($query, array(), 'elected_options');
[640]486
487$query = '
488SELECT id,name,uppercats,global_rank
489  FROM '.CATEGORIES_TABLE.'
[809]490  WHERE representative_picture_id != '.$_GET['image_id'].'
491    OR representative_picture_id IS NULL
[640]492;';
[2227]493display_select_cat_wrapper($query, array(), 'dismissed_options');
[817]494
[61]495//----------------------------------------------------------- sending html code
[817]496
[509]497$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
[362]498?>
Note: See TracBrowser for help on using the repository browser.