source: trunk/admin/picture_modify.php @ 2297

Last change on this file since 2297 was 2297, checked in by plg, 16 years ago

Modification: new header on PHP files, PhpWebGallery renamed Piwigo.

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