source: trunk/admin/picture_modify.php @ 1861

Last change on this file since 1861 was 1861, checked in by rvelices, 17 years ago
  • refactoring pagecategory before 1.7 release

pagecategory is not an id anymore, but an associative array of category info
all of pagecat_xxx or pageuppercats merged into one
simplifies calls to make_index_url
give plugins a clean start for page variables for version 1.7

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.6 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 1861 2007-02-27 01:56:16Z rvelices $
8// | last update   : $Date: 2007-02-27 01:56:16 +0000 (Tue, 27 Feb 2007) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Revision: 1861 $
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
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));
287
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      );
310
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;';
334
335$authorizeds = array_diff(
336  array_from_query($query, 'category_id'),
337  explode(
338    ',',
339    calculate_permissions($user['id'], $user['status'])
340    )
341  );
342
343if (isset($_GET['cat_id'])
344    and in_array($_GET['cat_id'], $authorizeds))
345{
346  $url_img = make_picture_url(
347    array(
348      'image_id' => $_GET['image_id'],
349      'image_file' => $image_file,
350      'category' => $cache['cat_names'][ $_GET['cat_id'] ],
351      )
352    );
353}
354else
355{
356  foreach ($authorizeds as $category)
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'][ $category ],
363        )
364      );
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}
378
379// associate to another category ?
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'].'
385    AND id != '.$storage_category_id.'
386;';
387display_select_cat_wrapper($query, array(), 'associated_option');
388
389$result = pwg_query($query);
390$associateds = array($storage_category_id);
391while ($row = mysql_fetch_array($result))
392{
393  array_push($associateds, $row['id']);
394}
395$query = '
396SELECT id,name,uppercats,global_rank
397  FROM '.CATEGORIES_TABLE.'
398  WHERE id NOT IN ('.implode(',', $associateds).')
399;';
400display_select_cat_wrapper($query, array(), 'dissociated_option');
401
402// representing
403$query = '
404SELECT id,name,uppercats,global_rank
405  FROM '.CATEGORIES_TABLE.'
406  WHERE representative_picture_id = '.$_GET['image_id'].'
407;';
408display_select_cat_wrapper($query, array(), 'elected_option');
409
410$query = '
411SELECT id,name,uppercats,global_rank
412  FROM '.CATEGORIES_TABLE.'
413  WHERE representative_picture_id != '.$_GET['image_id'].'
414    OR representative_picture_id IS NULL
415;';
416display_select_cat_wrapper($query, array(), 'dismissed_option');
417
418//----------------------------------------------------------- sending html code
419
420$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
421?>
Note: See TracBrowser for help on using the repository browser.