source: trunk/admin/picture_modify.php @ 1119

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

improvement: tags replace keywords. Better data model, less
limitations. Each image can be associated to as many tag as needed. Tags can
contain non ASCII characters. Oriented navigation with tags by association.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.1 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-04-02 22:26:19 +0000 (Sun, 02 Apr 2006) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 1119 $
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  $datas = array();
125
126  foreach ($_POST['cat_dissociated'] as $category_id)
127  {
128    array_push(
129      $datas,
130      array(
131        'image_id' => $_GET['image_id'],
132        'category_id' => $category_id
133        )
134      );
135  }
136
137  mass_inserts(
138    IMAGE_CATEGORY_TABLE,
139    array('image_id', 'category_id'),
140    $datas
141    );
142
143  check_links();
144  update_category($_POST['cat_dissociated']);
145}
146// dissociate the element from categories (but not from its storage category)
147if (isset($_POST['dissociate'])
148    and isset($_POST['cat_associated'])
149    and count($_POST['cat_associated']) > 0)
150{
151  $associated_categories = $_POST['cat_associated'];
152
153  // If the same element is associated to a source and its destinations,
154  // dissociating the element with the source implies dissociating the
155  // element fwith the destination.
156  $destinations_of = get_destinations($_POST['cat_associated']);
157  foreach ($destinations_of as $source => $destinations)
158  {
159    $associated_categories = array_merge(
160      $associated_categories,
161      $destinations
162      );
163  }
164
165  $query = '
166DELETE FROM '.IMAGE_CATEGORY_TABLE.'
167  WHERE image_id = '.$_GET['image_id'].'
168    AND category_id IN ('.implode(',', $associated_categories).')
169    AND is_storage = \'false\'
170';
171  pwg_query($query);
172
173  check_links();
174  update_category($_POST['cat_associated']);
175}
176// elect the element to represent the given categories
177if (isset($_POST['elect'])
178    and isset($_POST['cat_dismissed'])
179    and count($_POST['cat_dismissed']) > 0)
180{
181  $datas = array();
182  foreach ($_POST['cat_dismissed'] as $category_id)
183  {
184    array_push($datas,
185               array('id' => $category_id,
186                     'representative_picture_id' => $_GET['image_id']));
187  }
188  $fields = array('primary' => array('id'),
189                  'update' => array('representative_picture_id'));
190  mass_updates(CATEGORIES_TABLE, $fields, $datas);
191}
192// dismiss the element as representant of the given categories
193if (isset($_POST['dismiss'])
194    and isset($_POST['cat_elected'])
195    and count($_POST['cat_elected']) > 0)
196{
197  set_random_representant($_POST['cat_elected']);
198}
199
200// retrieving direct information about picture
201$query = '
202SELECT *
203  FROM '.IMAGES_TABLE.'
204    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id
205  WHERE id = '.$_GET['image_id'].'
206    AND is_storage = \'true\'
207;';
208$row = mysql_fetch_array(pwg_query($query));
209
210$storage_category_id = $row['category_id'];
211$image_file = $row['file'];
212
213// tags
214$query = '
215SELECT tag_id
216  FROM '.IMAGE_TAG_TABLE.'
217  WHERE image_id = '.$_GET['image_id'].'
218;';
219$selected_tags = array_from_query($query, 'tag_id');
220
221// Navigation path
222
223$date = isset($_POST['date_creation']) && empty($page['errors'])
224?$_POST['date_creation']:date_convert_back(@$row['date_creation']);
225
226// +-----------------------------------------------------------------------+
227// |                             template init                             |
228// +-----------------------------------------------------------------------+
229
230$template->set_filenames(
231  array(
232    'picture_modify' => 'admin/picture_modify.tpl'
233    )
234  );
235
236$template->assign_vars(
237  array(
238    'U_SYNC' =>
239        PHPWG_ROOT_PATH.'admin.php?page=picture_modify'.
240        '&amp;image_id='.$_GET['image_id'].
241        (isset($_GET['cat_id']) ? '&amp;cat_id='.$_GET['cat_id'] : '').
242        '&amp;sync_metadata=1',
243
244    'PATH'=>$row['path'],
245
246    'TN_SRC' => get_thumbnail_src($row['path'], @$row['tn_ext']),
247
248    'NAME' =>
249      isset($_POST['name']) ?
250        stripslashes($_POST['name']) : @$row['name'],
251
252    'DIMENSIONS' => @$row['width'].' * '.@$row['height'],
253
254    'FILESIZE' => @$row['filesize'].' KB',
255
256    'REGISTRATION_DATE' =>
257      format_date($row['date_available'], 'mysql_datetime', false),
258
259    'AUTHOR' => isset($_POST['author']) ? $_POST['author'] : @$row['author'],
260
261    'CREATION_DATE' => $date,
262
263    'TAG_SELECTION' => get_html_tag_selection(
264      get_all_tags(),
265      'tags',
266      $selected_tags
267      ),
268
269    'DESCRIPTION' =>
270      isset($_POST['description']) ?
271        stripslashes($_POST['description']) : @$row['comment'],
272
273    'F_ACTION' =>
274        PHPWG_ROOT_PATH.'admin.php'
275        .get_query_string_diff(array('sync_metadata'))
276    )
277  );
278
279// creation date
280unset($day, $month, $year);
281
282if (isset($_POST['date_creation_action'])
283    and 'set' == $_POST['date_creation_action'])
284{
285  foreach (array('day', 'month', 'year') as $varname)
286  {
287    $$varname = $_POST['date_creation_'.$varname];
288  }
289}
290else if (isset($row['date_creation']) and !empty($row['date_creation']))
291{
292  list($year, $month, $day) = explode('-', $row['date_creation']);
293}
294else
295{
296  list($year, $month, $day) = array('', 0, 0);
297}
298get_day_list('date_creation_day', $day);
299get_month_list('date_creation_month', $month);
300$template->assign_vars(array('DATE_CREATION_YEAR_VALUE' => $year));
301
302$query = '
303SELECT category_id, uppercats
304  FROM '.IMAGE_CATEGORY_TABLE.' AS ic
305    INNER JOIN '.CATEGORIES_TABLE.' AS c
306      ON c.id = ic.category_id
307  WHERE image_id = '.$_GET['image_id'].'
308;';
309$result = pwg_query($query);
310
311if (mysql_num_rows($result) > 1)
312{
313  $template->assign_block_vars('links', array());
314}
315
316while ($row = mysql_fetch_array($result))
317{
318  $name =
319    get_cat_display_name_cache(
320      $row['uppercats'],
321      PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id=',
322      false
323      );
324
325  if ($row['category_id'] == $storage_category_id)
326  {
327    $template->assign_vars(array('STORAGE_CATEGORY' => $name));
328  }
329  else
330  {
331    $template->assign_block_vars('links.category', array('NAME' => $name));
332  }
333}
334
335// jump to link
336//
337// 1. find all linked categories that are reachable for the current user.
338// 2. if a category is available in the URL, use it if reachable
339// 3. if URL category not available or reachable, use the first reachable
340//    linked category
341// 4. if no category reachable, no jumpto link
342
343$query = '
344SELECT category_id
345  FROM '.IMAGE_CATEGORY_TABLE.'
346  WHERE image_id = '.$_GET['image_id'].'
347;';
348
349$authorizeds = array_diff(
350  array_from_query($query, 'category_id'),
351  explode(
352    ',',
353    calculate_permissions($user['id'], $user['status'])
354    )
355  );
356
357if (isset($_GET['cat_id'])
358    and in_array($_GET['cat_id'], $authorizeds))
359{
360  $url_img = make_picture_URL(
361    array(
362      'image_id' => $_GET['image_id'],
363      'image_file' => $image_file,
364      'category' => $_GET['cat_id'],
365      )
366    );
367}
368else
369{
370  foreach ($authorizeds as $category)
371  {
372    $url_img = make_picture_URL(
373      array(
374        'image_id' => $_GET['image_id'],
375        'image_file' => $image_file,
376        'category' => $category,
377        )
378      );
379    break;
380  }
381}
382
383if (isset($url_img))
384{
385  $template->assign_block_vars(
386    'jumpto',
387    array(
388      'URL' => $url_img
389      )
390    );
391}
392
393// associate to another category ?
394$query = '
395SELECT id,name,uppercats,global_rank
396  FROM '.CATEGORIES_TABLE.'
397    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
398  WHERE image_id = '.$_GET['image_id'].'
399    AND is_storage = \'false\'
400;';
401display_select_cat_wrapper($query, array(), 'associated_option');
402
403$result = pwg_query($query);
404$associateds = array($storage_category_id);
405while ($row = mysql_fetch_array($result))
406{
407  array_push($associateds, $row['id']);
408}
409$query = '
410SELECT id,name,uppercats,global_rank
411  FROM '.CATEGORIES_TABLE.'
412  WHERE id NOT IN ('.implode(',', $associateds).')
413;';
414display_select_cat_wrapper($query, array(), 'dissociated_option');
415
416// representing
417$query = '
418SELECT id,name,uppercats,global_rank
419  FROM '.CATEGORIES_TABLE.'
420  WHERE representative_picture_id = '.$_GET['image_id'].'
421;';
422display_select_cat_wrapper($query, array(), 'elected_option');
423
424$query = '
425SELECT id,name,uppercats,global_rank
426  FROM '.CATEGORIES_TABLE.'
427  WHERE representative_picture_id != '.$_GET['image_id'].'
428    OR representative_picture_id IS NULL
429;';
430display_select_cat_wrapper($query, array(), 'dismissed_option');
431
432//----------------------------------------------------------- sending html code
433
434$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
435?>
Note: See TracBrowser for help on using the repository browser.