source: trunk/admin/picture_modify.php @ 1121

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

feature deleted: code for categories link was too complicated for such a
simple fature. Replaced by static association. Links are not persistent
anymore.

modification removed: #image_category.is_storage replaced by
#images.storage_category_id as in branche 1.5..

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.3 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-04 22:29:35 +0000 (Tue, 04 Apr 2006) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 1121 $
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$template->assign_vars(
202  array(
203    'U_SYNC' =>
204        PHPWG_ROOT_PATH.'admin.php?page=picture_modify'.
205        '&amp;image_id='.$_GET['image_id'].
206        (isset($_GET['cat_id']) ? '&amp;cat_id='.$_GET['cat_id'] : '').
207        '&amp;sync_metadata=1',
208
209    'PATH'=>$row['path'],
210
211    'TN_SRC' => get_thumbnail_src($row['path'], @$row['tn_ext']),
212
213    'NAME' =>
214      isset($_POST['name']) ?
215        stripslashes($_POST['name']) : @$row['name'],
216
217    'DIMENSIONS' => @$row['width'].' * '.@$row['height'],
218
219    'FILESIZE' => @$row['filesize'].' KB',
220
221    'REGISTRATION_DATE' =>
222      format_date($row['date_available'], 'mysql_datetime', false),
223
224    'AUTHOR' => isset($_POST['author']) ? $_POST['author'] : @$row['author'],
225
226    'CREATION_DATE' => $date,
227
228    'TAG_SELECTION' => get_html_tag_selection(
229      get_all_tags(),
230      'tags',
231      $selected_tags
232      ),
233
234    'DESCRIPTION' =>
235      isset($_POST['description']) ?
236        stripslashes($_POST['description']) : @$row['comment'],
237
238    'F_ACTION' =>
239        PHPWG_ROOT_PATH.'admin.php'
240        .get_query_string_diff(array('sync_metadata'))
241    )
242  );
243
244// creation date
245unset($day, $month, $year);
246
247if (isset($_POST['date_creation_action'])
248    and 'set' == $_POST['date_creation_action'])
249{
250  foreach (array('day', 'month', 'year') as $varname)
251  {
252    $$varname = $_POST['date_creation_'.$varname];
253  }
254}
255else if (isset($row['date_creation']) and !empty($row['date_creation']))
256{
257  list($year, $month, $day) = explode('-', $row['date_creation']);
258}
259else
260{
261  list($year, $month, $day) = array('', 0, 0);
262}
263get_day_list('date_creation_day', $day);
264get_month_list('date_creation_month', $month);
265$template->assign_vars(array('DATE_CREATION_YEAR_VALUE' => $year));
266
267$query = '
268SELECT category_id, uppercats
269  FROM '.IMAGE_CATEGORY_TABLE.' AS ic
270    INNER JOIN '.CATEGORIES_TABLE.' AS c
271      ON c.id = ic.category_id
272  WHERE image_id = '.$_GET['image_id'].'
273;';
274$result = pwg_query($query);
275
276if (mysql_num_rows($result) > 1)
277{
278  $template->assign_block_vars('links', array());
279}
280
281while ($row = mysql_fetch_array($result))
282{
283  $name =
284    get_cat_display_name_cache(
285      $row['uppercats'],
286      PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id=',
287      false
288      );
289
290  if ($row['category_id'] == $storage_category_id)
291  {
292    $template->assign_vars(array('STORAGE_CATEGORY' => $name));
293  }
294  else
295  {
296    $template->assign_block_vars('links.category', array('NAME' => $name));
297  }
298}
299
300// jump to link
301//
302// 1. find all linked categories that are reachable for the current user.
303// 2. if a category is available in the URL, use it if reachable
304// 3. if URL category not available or reachable, use the first reachable
305//    linked category
306// 4. if no category reachable, no jumpto link
307
308$query = '
309SELECT category_id
310  FROM '.IMAGE_CATEGORY_TABLE.'
311  WHERE image_id = '.$_GET['image_id'].'
312;';
313
314$authorizeds = array_diff(
315  array_from_query($query, 'category_id'),
316  explode(
317    ',',
318    calculate_permissions($user['id'], $user['status'])
319    )
320  );
321
322if (isset($_GET['cat_id'])
323    and in_array($_GET['cat_id'], $authorizeds))
324{
325  $url_img = make_picture_URL(
326    array(
327      'image_id' => $_GET['image_id'],
328      'image_file' => $image_file,
329      'category' => $_GET['cat_id'],
330      )
331    );
332}
333else
334{
335  foreach ($authorizeds as $category)
336  {
337    $url_img = make_picture_URL(
338      array(
339        'image_id' => $_GET['image_id'],
340        'image_file' => $image_file,
341        'category' => $category,
342        )
343      );
344    break;
345  }
346}
347
348if (isset($url_img))
349{
350  $template->assign_block_vars(
351    'jumpto',
352    array(
353      'URL' => $url_img
354      )
355    );
356}
357
358// associate to another category ?
359$query = '
360SELECT id,name,uppercats,global_rank
361  FROM '.CATEGORIES_TABLE.'
362    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
363  WHERE image_id = '.$_GET['image_id'].'
364    AND id != '.$storage_category_id.'
365;';
366display_select_cat_wrapper($query, array(), 'associated_option');
367
368$result = pwg_query($query);
369$associateds = array($storage_category_id);
370while ($row = mysql_fetch_array($result))
371{
372  array_push($associateds, $row['id']);
373}
374$query = '
375SELECT id,name,uppercats,global_rank
376  FROM '.CATEGORIES_TABLE.'
377  WHERE id NOT IN ('.implode(',', $associateds).')
378;';
379display_select_cat_wrapper($query, array(), 'dissociated_option');
380
381// representing
382$query = '
383SELECT id,name,uppercats,global_rank
384  FROM '.CATEGORIES_TABLE.'
385  WHERE representative_picture_id = '.$_GET['image_id'].'
386;';
387display_select_cat_wrapper($query, array(), 'elected_option');
388
389$query = '
390SELECT id,name,uppercats,global_rank
391  FROM '.CATEGORIES_TABLE.'
392  WHERE representative_picture_id != '.$_GET['image_id'].'
393    OR representative_picture_id IS NULL
394;';
395display_select_cat_wrapper($query, array(), 'dismissed_option');
396
397//----------------------------------------------------------- sending html code
398
399$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
400?>
Note: See TracBrowser for help on using the repository browser.