source: trunk/admin/picture_modify.php @ 1092

Last change on this file since 1092 was 1092, checked in by rvelices, 18 years ago

URL rewriting: capable of fully working with urls without ?

URL rewriting: works with image file instead of image id (change
make_picture_url to generate urls with file name instead of image id)

URL rewriting: completely works with category/best_rated and
picture/best_rated/534 (change 'category.php?' to 'category' in make_index_url
and 'picture.php?' to 'picture' in make_picture_url to see it)

fix: picture category display in upper bar

fix: function rate_picture variables and use of the new user type

fix: caddie icon appears now on category page

fix: admin element_set sql query was using storage_category_id column
(column has moved to #image_categories)

fix: replaced some old $_GET[xxx] with $page[xxx]

fix: pictures have metadata url (use ? parameter - might change later)

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