source: trunk/admin/picture_modify.php @ 1900

Last change on this file since 1900 was 1900, checked in by rub, 17 years ago

Apply property svn:eol-style Value: LF

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 11.8 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-2007 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | file          : $Id: picture_modify.php 1900 2007-03-12 22:33:53Z rub $
8// | last update   : $Date: 2007-03-12 22:33:53 +0000 (Mon, 12 Mar 2007) $
9// | last modifier : $Author: rub $
10// | revision      : $Revision: 1900 $
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// +-----------------------------------------------------------------------+
26
27if(!defined("PHPWG_ROOT_PATH"))
28{
29  die('Hacking attempt!');
30}
31
32include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
33
34// +-----------------------------------------------------------------------+
35// | Check Access and exit when user status is not ok                      |
36// +-----------------------------------------------------------------------+
37check_status(ACCESS_ADMINISTRATOR);
38
39// +-----------------------------------------------------------------------+
40// |                          synchronize metadata                         |
41// +-----------------------------------------------------------------------+
42
43if (isset($_GET['sync_metadata']) and !is_adviser())
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
56//--------------------------------------------------------- update informations
57
58// first, we verify whether there is a mistake on the given creation date
59if (isset($_POST['date_creation_action'])
60    and 'set' == $_POST['date_creation_action'])
61{
62  if (!checkdate(
63        $_POST['date_creation_month'],
64        $_POST['date_creation_day'],
65        $_POST['date_creation_year'])
66    )
67  {
68    array_push($page['errors'], $lang['err_date']);
69  }
70}
71
72if (isset($_POST['submit']) and count($page['errors']) == 0 and !is_adviser())
73{
74  $data = array();
75  $data{'id'} = $_GET['image_id'];
76  $data{'name'} = $_POST['name'];
77  $data{'author'} = $_POST['author'];
78
79  if ($conf['allow_html_descriptions'])
80  {
81    $data{'comment'} = @$_POST['description'];
82  }
83  else
84  {
85    $data{'comment'} = strip_tags(@$_POST['description']);
86  }
87
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  }
101
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
111  set_tags(
112    isset($_POST['tags']) ? $_POST['tags'] : array(),
113    $_GET['image_id']
114    );
115
116  array_push($page['infos'], l10n('Picture informations updated'));
117}
118// associate the element to other categories than its storage category
119if (isset($_POST['associate'])
120    and isset($_POST['cat_dissociated'])
121    and count($_POST['cat_dissociated']) > 0
122    and !is_adviser()
123  )
124{
125  associate_images_to_categories(
126    array($_GET['image_id']),
127    $_POST['cat_dissociated']
128    );
129}
130// dissociate the element from categories (but not from its storage category)
131if (isset($_POST['dissociate'])
132    and isset($_POST['cat_associated'])
133    and count($_POST['cat_associated']) > 0
134    and !is_adviser()
135  )
136{
137  $query = '
138DELETE FROM '.IMAGE_CATEGORY_TABLE.'
139  WHERE image_id = '.$_GET['image_id'].'
140    AND category_id IN ('.implode(',', $_POST['cat_associated']).')
141';
142  pwg_query($query);
143
144  update_category($_POST['cat_associated']);
145}
146// elect the element to represent the given categories
147if (isset($_POST['elect'])
148    and isset($_POST['cat_dismissed'])
149    and count($_POST['cat_dismissed']) > 0
150    and !is_adviser()
151  )
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'])
167    and count($_POST['cat_elected']) > 0
168    and !is_adviser()
169  )
170{
171  set_random_representant($_POST['cat_elected']);
172}
173
174// retrieving direct information about picture
175$query = '
176SELECT *
177  FROM '.IMAGES_TABLE.'
178  WHERE id = '.$_GET['image_id'].'
179;';
180$row = mysql_fetch_array(pwg_query($query));
181
182$storage_category_id = $row['storage_category_id'];
183$image_file = $row['file'];
184
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
193// Navigation path
194
195$date = isset($_POST['date_creation']) && empty($page['errors'])
196?$_POST['date_creation']:date_convert_back(@$row['date_creation']);
197
198// +-----------------------------------------------------------------------+
199// |                             template init                             |
200// +-----------------------------------------------------------------------+
201
202$template->set_filenames(
203  array(
204    'picture_modify' => 'admin/picture_modify.tpl'
205    )
206  );
207
208$all_tags = get_all_tags();
209
210if (count($all_tags) > 0)
211{
212  $tag_selection = get_html_tag_selection(
213    $all_tags,
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}
225
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'] : '').
232        '&amp;sync_metadata=1',
233
234    'PATH'=>$row['path'],
235
236    'TN_SRC' => get_thumbnail_url($row),
237
238    'NAME' =>
239      isset($_POST['name']) ?
240        stripslashes($_POST['name']) : @$row['name'],
241
242    'DIMENSIONS' => @$row['width'].' * '.@$row['height'],
243
244    'FILESIZE' => @$row['filesize'].' KB',
245
246    'REGISTRATION_DATE' =>
247      format_date($row['date_available'], 'mysql_datetime', false),
248
249    'AUTHOR' => isset($_POST['author']) ? $_POST['author'] : @$row['author'],
250
251    'CREATION_DATE' => $date,
252
253    'TAG_SELECTION' => $tag_selection,
254
255    'DESCRIPTION' =>
256      htmlspecialchars( isset($_POST['description']) ?
257        stripslashes($_POST['description']) : @$row['comment'] ),
258
259    'F_ACTION' =>
260        PHPWG_ROOT_PATH.'admin.php'
261        .get_query_string_diff(array('sync_metadata'))
262    )
263  );
264
265if ($row['has_high'] == 'true')
266{
267  $template->assign_block_vars(
268    'high',
269    array(
270      'FILESIZE' => isset($row['high_filesize'])
271        ? $row['high_filesize'].' KB'
272        : l10n('unknown'),
273      )
274    );
275}
276
277// creation date
278unset($day, $month, $year);
279
280if (isset($_POST['date_creation_action'])
281    and 'set' == $_POST['date_creation_action'])
282{
283  foreach (array('day', 'month', 'year') as $varname)
284  {
285    $$varname = $_POST['date_creation_'.$varname];
286  }
287}
288else if (isset($row['date_creation']) and !empty($row['date_creation']))
289{
290  list($year, $month, $day) = explode('-', $row['date_creation']);
291}
292else
293{
294  list($year, $month, $day) = array('', 0, 0);
295}
296get_day_list('date_creation_day', $day);
297get_month_list('date_creation_month', $month);
298$template->assign_vars(array('DATE_CREATION_YEAR_VALUE' => $year));
299
300$query = '
301SELECT category_id, uppercats
302  FROM '.IMAGE_CATEGORY_TABLE.' AS ic
303    INNER JOIN '.CATEGORIES_TABLE.' AS c
304      ON c.id = ic.category_id
305  WHERE image_id = '.$_GET['image_id'].'
306;';
307$result = pwg_query($query);
308
309if (mysql_num_rows($result) > 1)
310{
311  $template->assign_block_vars('links', array());
312}
313
314while ($row = mysql_fetch_array($result))
315{
316  $name =
317    get_cat_display_name_cache(
318      $row['uppercats'],
319      PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id=',
320      false
321      );
322
323  if ($row['category_id'] == $storage_category_id)
324  {
325    $template->assign_vars(array('STORAGE_CATEGORY' => $name));
326  }
327  else
328  {
329    $template->assign_block_vars('links.category', array('NAME' => $name));
330  }
331}
332
333// jump to link
334//
335// 1. find all linked categories that are reachable for the current user.
336// 2. if a category is available in the URL, use it if reachable
337// 3. if URL category not available or reachable, use the first reachable
338//    linked category
339// 4. if no category reachable, no jumpto link
340
341$query = '
342SELECT category_id
343  FROM '.IMAGE_CATEGORY_TABLE.'
344  WHERE image_id = '.$_GET['image_id'].'
345;';
346
347$authorizeds = array_diff(
348  array_from_query($query, 'category_id'),
349  explode(
350    ',',
351    calculate_permissions($user['id'], $user['status'])
352    )
353  );
354
355if (isset($_GET['cat_id'])
356    and in_array($_GET['cat_id'], $authorizeds))
357{
358  $url_img = make_picture_url(
359    array(
360      'image_id' => $_GET['image_id'],
361      'image_file' => $image_file,
362      'category' => $cache['cat_names'][ $_GET['cat_id'] ],
363      )
364    );
365}
366else
367{
368  foreach ($authorizeds as $category)
369  {
370    $url_img = make_picture_url(
371      array(
372        'image_id' => $_GET['image_id'],
373        'image_file' => $image_file,
374        'category' => $cache['cat_names'][ $category ],
375        )
376      );
377    break;
378  }
379}
380
381if (isset($url_img))
382{
383  $template->assign_block_vars(
384    'jumpto',
385    array(
386      'URL' => $url_img
387      )
388    );
389}
390
391// associate to another category ?
392$query = '
393SELECT id,name,uppercats,global_rank
394  FROM '.CATEGORIES_TABLE.'
395    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
396  WHERE image_id = '.$_GET['image_id'].'
397    AND id != '.$storage_category_id.'
398;';
399display_select_cat_wrapper($query, array(), 'associated_option');
400
401$result = pwg_query($query);
402$associateds = array($storage_category_id);
403while ($row = mysql_fetch_array($result))
404{
405  array_push($associateds, $row['id']);
406}
407$query = '
408SELECT id,name,uppercats,global_rank
409  FROM '.CATEGORIES_TABLE.'
410  WHERE id NOT IN ('.implode(',', $associateds).')
411;';
412display_select_cat_wrapper($query, array(), 'dissociated_option');
413
414// representing
415$query = '
416SELECT id,name,uppercats,global_rank
417  FROM '.CATEGORIES_TABLE.'
418  WHERE representative_picture_id = '.$_GET['image_id'].'
419;';
420display_select_cat_wrapper($query, array(), 'elected_option');
421
422$query = '
423SELECT id,name,uppercats,global_rank
424  FROM '.CATEGORIES_TABLE.'
425  WHERE representative_picture_id != '.$_GET['image_id'].'
426    OR representative_picture_id IS NULL
427;';
428display_select_cat_wrapper($query, array(), 'dismissed_option');
429
430//----------------------------------------------------------- sending html code
431
432$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
433?>
Note: See TracBrowser for help on using the repository browser.