source: trunk/admin/picture_modify.php @ 1082

Last change on this file since 1082 was 1082, checked in by plg, 19 years ago

new: cleaner URL. Instead of category.php?cat=search&search=123&start=42,
you now have category.php?/search/123/start-42. Functions make_index_url and
make_picture_url build these new URLs. Functions duplicate_picture_url and
duplicate_index_url provide shortcuts to URL creation. The current main page
page is still category.php but this can be modified easily in make_index_url
function. In this first version, no backward compatibility. Calendar
definition in URL must be discussed with rvelices.

improvement: picture.php redesigned. First actions like "set as
representative" or "delete a comment" which all lead to a redirection. Then
the page (the big mess) and includes of new sub pages to manage specific
parts of the page (metadata, user comments, rates).

new: with the cleaner URL comes a new terminology. $pagecat doesn't
exist anymore. $pagesection is among 'categories', 'tags' (TODO),
'list', 'most_seen'... And sub parameters are set : $pagecategory if
$pagesection is "categories". See URL analyse in
include/section_init.inc.php for details.

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