source: tags/release-1_6_1/admin/picture_modify.php @ 6883

Last change on this file since 6883 was 1313, checked in by plg, 18 years ago

bug 373 fixed: if there is no tag defined, an explicit message is displayed
in the administration section. In the public search screen, tag fieldset is
not displayed if no reachable tag.

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