source: trunk/admin/picture_modify.php @ 1846

Last change on this file since 1846 was 1815, checked in by rvelices, 17 years ago

tags returned by get_all_tags, get_available_tags contain id key instead of tag_id
(as expected by make_index_url, as $pagetags was and as the database model is)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.5 KB
RevLine 
[61]1<?php
[362]2// +-----------------------------------------------------------------------+
[593]3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
[1815]5// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
[362]6// +-----------------------------------------------------------------------+
[1815]7// | file          : $Id: picture_modify.php 1815 2007-02-14 01:37:38Z rvelices $
[362]8// | last update   : $Date: 2007-02-14 01:37:38 +0000 (Wed, 14 Feb 2007) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Revision: 1815 $
11// +-----------------------------------------------------------------------+
12// | This program is free software; you can redistribute it and/or modify  |
13// | it under the terms of the GNU General Public License as published by  |
14// | the Free Software Foundation                                          |
15// |                                                                       |
16// | This program is distributed in the hope that it will be useful, but   |
17// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
18// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
19// | General Public License for more details.                              |
20// |                                                                       |
21// | You should have received a copy of the GNU General Public License     |
22// | along with this program; if not, write to the Free Software           |
23// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
24// | USA.                                                                  |
25// +-----------------------------------------------------------------------+
[61]26
[575]27if(!defined("PHPWG_ROOT_PATH"))
[509]28{
[825]29  die('Hacking attempt!');
[509]30}
[825]31
[1072]32include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
33
[825]34// +-----------------------------------------------------------------------+
[1072]35// | Check Access and exit when user status is not ok                      |
36// +-----------------------------------------------------------------------+
37check_status(ACCESS_ADMINISTRATOR);
38
39// +-----------------------------------------------------------------------+
[825]40// |                          synchronize metadata                         |
41// +-----------------------------------------------------------------------+
42
[1085]43if (isset($_GET['sync_metadata']) and !is_adviser())
[825]44{
45  $query = '
46SELECT path
47  FROM '.IMAGES_TABLE.'
48  WHERE id = '.$_GET['image_id'].'
49;';
50  list($path) = mysql_fetch_row(pwg_query($query));
51  update_metadata(array($_GET['image_id'] => $path));
52
53  array_push($page['infos'], l10n('Metadata synchronized from file'));
54}
55
[61]56//--------------------------------------------------------- update informations
[825]57
[61]58// first, we verify whether there is a mistake on the given creation date
[825]59if (isset($_POST['date_creation_action'])
60    and 'set' == $_POST['date_creation_action'])
[61]61{
[825]62  if (!checkdate(
63        $_POST['date_creation_month'],
64        $_POST['date_creation_day'],
65        $_POST['date_creation_year'])
66    )
[575]67  {
[792]68    array_push($page['errors'], $lang['err_date']);
[575]69  }
[61]70}
[825]71
[1571]72if (isset($_POST['submit']) and count($page['errors']) == 0 and !is_adviser())
[61]73{
[825]74  $data = array();
75  $data{'id'} = $_GET['image_id'];
76  $data{'name'} = $_POST['name'];
77  $data{'author'} = $_POST['author'];
[61]78
[825]79  if ($conf['allow_html_descriptions'])
80  {
81    $data{'comment'} = @$_POST['description'];
82  }
[61]83  else
[825]84  {
85    $data{'comment'} = strip_tags(@$_POST['description']);
86  }
[61]87
[825]88  if (isset($_POST['date_creation_action']))
89  {
90    if ('set' == $_POST['date_creation_action'])
91    {
92      $data{'date_creation'} = $_POST['date_creation_year']
93                                 .'-'.$_POST['date_creation_month']
94                                 .'-'.$_POST['date_creation_day'];
95    }
96    else if ('unset' == $_POST['date_creation_action'])
97    {
98      $data{'date_creation'} = '';
99    }
100  }
[61]101
[825]102  mass_updates(
103    IMAGES_TABLE,
104    array(
105      'primary' => array('id'),
106      'update' => array_diff(array_keys($data), array('id'))
107      ),
108    array($data)
109    );
110
[1119]111  set_tags(
112    isset($_POST['tags']) ? $_POST['tags'] : array(),
113    $_GET['image_id']
114    );
115
[825]116  array_push($page['infos'], l10n('Picture informations updated'));
[635]117}
118// associate the element to other categories than its storage category
119if (isset($_POST['associate'])
120    and isset($_POST['cat_dissociated'])
[1571]121    and count($_POST['cat_dissociated']) > 0
122    and !is_adviser()
123  )
[635]124{
[1121]125  associate_images_to_categories(
126    array($_GET['image_id']),
127    $_POST['cat_dissociated']
[1065]128    );
[635]129}
130// dissociate the element from categories (but not from its storage category)
131if (isset($_POST['dissociate'])
132    and isset($_POST['cat_associated'])
[1571]133    and count($_POST['cat_associated']) > 0
134    and !is_adviser()
135  )
[635]136{
[575]137  $query = '
138DELETE FROM '.IMAGE_CATEGORY_TABLE.'
139  WHERE image_id = '.$_GET['image_id'].'
[1121]140    AND category_id IN ('.implode(',', $_POST['cat_associated']).')
[635]141';
142  pwg_query($query);
[1609]143
[635]144  update_category($_POST['cat_associated']);
[61]145}
[640]146// elect the element to represent the given categories
147if (isset($_POST['elect'])
148    and isset($_POST['cat_dismissed'])
[1571]149    and count($_POST['cat_dismissed']) > 0
150    and !is_adviser()
151  )
[640]152{
153  $datas = array();
154  foreach ($_POST['cat_dismissed'] as $category_id)
155  {
156    array_push($datas,
157               array('id' => $category_id,
158                     'representative_picture_id' => $_GET['image_id']));
159  }
160  $fields = array('primary' => array('id'),
161                  'update' => array('representative_picture_id'));
162  mass_updates(CATEGORIES_TABLE, $fields, $datas);
163}
164// dismiss the element as representant of the given categories
165if (isset($_POST['dismiss'])
166    and isset($_POST['cat_elected'])
[1571]167    and count($_POST['cat_elected']) > 0
168    and !is_adviser()
169  )
[640]170{
171  set_random_representant($_POST['cat_elected']);
172}
[61]173
174// retrieving direct information about picture
[575]175$query = '
[825]176SELECT *
177  FROM '.IMAGES_TABLE.'
178  WHERE id = '.$_GET['image_id'].'
[575]179;';
[587]180$row = mysql_fetch_array(pwg_query($query));
[345]181
[1121]182$storage_category_id = $row['storage_category_id'];
[1092]183$image_file = $row['file'];
[635]184
[1119]185// tags
186$query = '
187SELECT tag_id
188  FROM '.IMAGE_TAG_TABLE.'
189  WHERE image_id = '.$_GET['image_id'].'
190;';
191$selected_tags = array_from_query($query, 'tag_id');
192
[509]193// Navigation path
[577]194
[792]195$date = isset($_POST['date_creation']) && empty($page['errors'])
[635]196?$_POST['date_creation']:date_convert_back(@$row['date_creation']);
[642]197
[825]198// +-----------------------------------------------------------------------+
199// |                             template init                             |
200// +-----------------------------------------------------------------------+
201
[817]202$template->set_filenames(
203  array(
204    'picture_modify' => 'admin/picture_modify.tpl'
205    )
206  );
207
[1314]208$all_tags = get_all_tags();
209
210if (count($all_tags) > 0)
211{
212  $tag_selection = get_html_tag_selection(
[1815]213    $all_tags,
[1314]214    'tags',
215    $selected_tags
216    );
217}
218else
219{
220  $tag_selection =
221    '<p>'.
222    l10n('No tag defined. Use Administration>Pictures>Tags').
223    '</p>';
224}
[1609]225
[825]226$template->assign_vars(
227  array(
228    'U_SYNC' =>
229        PHPWG_ROOT_PATH.'admin.php?page=picture_modify'.
230        '&amp;image_id='.$_GET['image_id'].
231        (isset($_GET['cat_id']) ? '&amp;cat_id='.$_GET['cat_id'] : '').
[1004]232        '&amp;sync_metadata=1',
[1092]233
[825]234    'PATH'=>$row['path'],
[1092]235
[1609]236    'TN_SRC' => get_thumbnail_url($row),
[1092]237
[825]238    'NAME' =>
239      isset($_POST['name']) ?
240        stripslashes($_POST['name']) : @$row['name'],
[1092]241
[825]242    'DIMENSIONS' => @$row['width'].' * '.@$row['height'],
[1092]243
[825]244    'FILESIZE' => @$row['filesize'].' KB',
[1092]245
[825]246    'REGISTRATION_DATE' =>
247      format_date($row['date_available'], 'mysql_datetime', false),
[1092]248
[825]249    'AUTHOR' => isset($_POST['author']) ? $_POST['author'] : @$row['author'],
[1092]250
[825]251    'CREATION_DATE' => $date,
[1092]252
[1314]253    'TAG_SELECTION' => $tag_selection,
[1092]254
[825]255    'DESCRIPTION' =>
256      isset($_POST['description']) ?
257        stripslashes($_POST['description']) : @$row['comment'],
[1092]258
[825]259    'F_ACTION' =>
260        PHPWG_ROOT_PATH.'admin.php'
261        .get_query_string_diff(array('sync_metadata'))
262    )
263  );
264
265// creation date
266unset($day, $month, $year);
267
268if (isset($_POST['date_creation_action'])
269    and 'set' == $_POST['date_creation_action'])
270{
271  foreach (array('day', 'month', 'year') as $varname)
272  {
273    $$varname = $_POST['date_creation_'.$varname];
274  }
275}
276else if (isset($row['date_creation']) and !empty($row['date_creation']))
277{
278  list($year, $month, $day) = explode('-', $row['date_creation']);
279}
280else
281{
282  list($year, $month, $day) = array('', 0, 0);
283}
284get_day_list('date_creation_day', $day);
285get_month_list('date_creation_month', $month);
286$template->assign_vars(array('DATE_CREATION_YEAR_VALUE' => $year));
[1092]287
[825]288$query = '
289SELECT category_id, uppercats
290  FROM '.IMAGE_CATEGORY_TABLE.' AS ic
291    INNER JOIN '.CATEGORIES_TABLE.' AS c
292      ON c.id = ic.category_id
293  WHERE image_id = '.$_GET['image_id'].'
294;';
295$result = pwg_query($query);
296
297if (mysql_num_rows($result) > 1)
298{
299  $template->assign_block_vars('links', array());
300}
301
302while ($row = mysql_fetch_array($result))
303{
304  $name =
305    get_cat_display_name_cache(
306      $row['uppercats'],
307      PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id=',
308      false
309      );
[1092]310
[825]311  if ($row['category_id'] == $storage_category_id)
312  {
313    $template->assign_vars(array('STORAGE_CATEGORY' => $name));
314  }
315  else
316  {
317    $template->assign_block_vars('links.category', array('NAME' => $name));
318  }
319}
320
321// jump to link
322//
323// 1. find all linked categories that are reachable for the current user.
324// 2. if a category is available in the URL, use it if reachable
325// 3. if URL category not available or reachable, use the first reachable
326//    linked category
327// 4. if no category reachable, no jumpto link
328
329$query = '
330SELECT category_id
331  FROM '.IMAGE_CATEGORY_TABLE.'
332  WHERE image_id = '.$_GET['image_id'].'
333;';
[1082]334
[825]335$authorizeds = array_diff(
336  array_from_query($query, 'category_id'),
[1082]337  explode(
338    ',',
339    calculate_permissions($user['id'], $user['status'])
340    )
[825]341  );
342
343if (isset($_GET['cat_id'])
344    and in_array($_GET['cat_id'], $authorizeds))
345{
[1503]346  $url_img = make_picture_url(
[1082]347    array(
348      'image_id' => $_GET['image_id'],
[1092]349      'image_file' => $image_file,
[1082]350      'category' => $_GET['cat_id'],
351      )
352    );
[825]353}
354else
355{
356  foreach ($authorizeds as $category)
357  {
[1503]358    $url_img = make_picture_url(
[1082]359      array(
360        'image_id' => $_GET['image_id'],
[1092]361        'image_file' => $image_file,
[1082]362        'category' => $category,
363        )
364      );
[825]365    break;
366  }
367}
368
369if (isset($url_img))
370{
371  $template->assign_block_vars(
372    'jumpto',
373    array(
374      'URL' => $url_img
375      )
376    );
377}
[1092]378
[61]379// associate to another category ?
[635]380$query = '
381SELECT id,name,uppercats,global_rank
382  FROM '.CATEGORIES_TABLE.'
383    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
384  WHERE image_id = '.$_GET['image_id'].'
[1121]385    AND id != '.$storage_category_id.'
[635]386;';
[817]387display_select_cat_wrapper($query, array(), 'associated_option');
[635]388
389$result = pwg_query($query);
390$associateds = array($storage_category_id);
391while ($row = mysql_fetch_array($result))
[345]392{
[635]393  array_push($associateds, $row['id']);
[345]394}
[635]395$query = '
396SELECT id,name,uppercats,global_rank
397  FROM '.CATEGORIES_TABLE.'
398  WHERE id NOT IN ('.implode(',', $associateds).')
399;';
[817]400display_select_cat_wrapper($query, array(), 'dissociated_option');
[809]401
[640]402// representing
403$query = '
404SELECT id,name,uppercats,global_rank
405  FROM '.CATEGORIES_TABLE.'
406  WHERE representative_picture_id = '.$_GET['image_id'].'
407;';
[817]408display_select_cat_wrapper($query, array(), 'elected_option');
[640]409
410$query = '
411SELECT id,name,uppercats,global_rank
412  FROM '.CATEGORIES_TABLE.'
[809]413  WHERE representative_picture_id != '.$_GET['image_id'].'
414    OR representative_picture_id IS NULL
[640]415;';
[817]416display_select_cat_wrapper($query, array(), 'dismissed_option');
417
[61]418//----------------------------------------------------------- sending html code
[817]419
[509]420$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
[362]421?>
Note: See TracBrowser for help on using the repository browser.