source: trunk/admin/picture_modify.php @ 1065

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

bug fixed: table #categories_link was created with an hardcoded prefix

bug fixed: on source/destination links, if an image/category association is
added to a source, destinations must be filled. If an image/category
association is delete from a source, the same association must be deleted in
the destinations.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.7 KB
RevLine 
[61]1<?php
[362]2// +-----------------------------------------------------------------------+
[593]3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
[675]5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
[362]6// +-----------------------------------------------------------------------+
[593]7// | branch        : BSF (Best So Far)
[362]8// | file          : $RCSfile$
9// | last update   : $Date: 2006-03-05 22:44:32 +0000 (Sun, 05 Mar 2006) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 1065 $
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// +-----------------------------------------------------------------------+
[61]27
[575]28if(!defined("PHPWG_ROOT_PATH"))
[509]29{
[825]30  die('Hacking attempt!');
[509]31}
[575]32include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
[825]33
34// +-----------------------------------------------------------------------+
35// |                          synchronize metadata                         |
36// +-----------------------------------------------------------------------+
37
38if (isset($_GET['sync_metadata']))
39{
40  $query = '
41SELECT path
42  FROM '.IMAGES_TABLE.'
43  WHERE id = '.$_GET['image_id'].'
44;';
45  list($path) = mysql_fetch_row(pwg_query($query));
46  update_metadata(array($_GET['image_id'] => $path));
47
48  array_push($page['infos'], l10n('Metadata synchronized from file'));
49}
50
[61]51//--------------------------------------------------------- update informations
[825]52
[61]53// first, we verify whether there is a mistake on the given creation date
[825]54if (isset($_POST['date_creation_action'])
55    and 'set' == $_POST['date_creation_action'])
[61]56{
[825]57  if (!checkdate(
58        $_POST['date_creation_month'],
59        $_POST['date_creation_day'],
60        $_POST['date_creation_year'])
61    )
[575]62  {
[792]63    array_push($page['errors'], $lang['err_date']);
[575]64  }
[61]65}
[825]66
[792]67if (isset($_POST['submit']) and count($page['errors']) == 0)
[61]68{
[825]69  $data = array();
70  $data{'id'} = $_GET['image_id'];
71  $data{'name'} = $_POST['name'];
72  $data{'author'} = $_POST['author'];
[61]73
[825]74  if ($conf['allow_html_descriptions'])
75  {
76    $data{'comment'} = @$_POST['description'];
77  }
[61]78  else
[825]79  {
80    $data{'comment'} = strip_tags(@$_POST['description']);
81  }
[61]82
[825]83  if (isset($_POST['date_creation_action']))
84  {
85    if ('set' == $_POST['date_creation_action'])
86    {
87      $data{'date_creation'} = $_POST['date_creation_year']
88                                 .'-'.$_POST['date_creation_month']
89                                 .'-'.$_POST['date_creation_day'];
90    }
91    else if ('unset' == $_POST['date_creation_action'])
92    {
93      $data{'date_creation'} = '';
94    }
95  }
[61]96
[825]97  $keywords = get_keywords($_POST['keywords']);
98  if (count($keywords) > 0)
99  {
100    $data{'keywords'} = implode(',', $keywords);
101  }
[61]102  else
103  {
[825]104    $data{'keywords'} = '';
[61]105  }
106
[825]107  mass_updates(
108    IMAGES_TABLE,
109    array(
110      'primary' => array('id'),
111      'update' => array_diff(array_keys($data), array('id'))
112      ),
113    array($data)
114    );
115
116  array_push($page['infos'], l10n('Picture informations updated'));
[635]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{
123  $datas = array();
[1065]124 
[635]125  foreach ($_POST['cat_dissociated'] as $category_id)
[133]126  {
[1065]127    array_push(
128      $datas,
129      array(
130        'image_id' => $_GET['image_id'],
131        'category_id' => $category_id
132        )
133      );
[133]134  }
[1065]135 
136  mass_inserts(
137    IMAGE_CATEGORY_TABLE,
138    array('image_id', 'category_id'),
139    $datas
140    );
[635]141
[1065]142  check_links();
[635]143  update_category($_POST['cat_dissociated']);
144}
145// dissociate the element from categories (but not from its storage category)
146if (isset($_POST['dissociate'])
147    and isset($_POST['cat_associated'])
148    and count($_POST['cat_associated']) > 0)
149{
[1065]150  $associated_categories = $_POST['cat_associated'];
151
152  // If the same element is associated to a source and its destinations,
153  // dissociating the element with the source implies dissociating the
154  // element fwith the destination.
155  $destinations_of = get_destinations($_POST['cat_associated']);
156  foreach ($destinations_of as $source => $destinations)
157  {
158    $associated_categories = array_merge(
159      $associated_categories,
160      $destinations
161      );
162  }
163 
[575]164  $query = '
165DELETE FROM '.IMAGE_CATEGORY_TABLE.'
166  WHERE image_id = '.$_GET['image_id'].'
[1065]167    AND category_id IN ('.implode(',', $associated_categories).')
168    AND is_storage = \'false\'
[635]169';
170  pwg_query($query);
[1065]171
172  check_links();
[635]173  update_category($_POST['cat_associated']);
[61]174}
[640]175// elect the element to represent the given categories
176if (isset($_POST['elect'])
177    and isset($_POST['cat_dismissed'])
178    and count($_POST['cat_dismissed']) > 0)
179{
180  $datas = array();
181  foreach ($_POST['cat_dismissed'] as $category_id)
182  {
183    array_push($datas,
184               array('id' => $category_id,
185                     'representative_picture_id' => $_GET['image_id']));
186  }
187  $fields = array('primary' => array('id'),
188                  'update' => array('representative_picture_id'));
189  mass_updates(CATEGORIES_TABLE, $fields, $datas);
190}
191// dismiss the element as representant of the given categories
192if (isset($_POST['dismiss'])
193    and isset($_POST['cat_elected'])
194    and count($_POST['cat_elected']) > 0)
195{
196  set_random_representant($_POST['cat_elected']);
197}
[61]198
199// retrieving direct information about picture
[575]200$query = '
[825]201SELECT *
202  FROM '.IMAGES_TABLE.'
[1064]203    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id
[825]204  WHERE id = '.$_GET['image_id'].'
[1064]205    AND is_storage = \'true\'
[575]206;';
[587]207$row = mysql_fetch_array(pwg_query($query));
[345]208
[1064]209$storage_category_id = $row['category_id'];
[635]210
[509]211// Navigation path
[577]212
[792]213$date = isset($_POST['date_creation']) && empty($page['errors'])
[635]214?$_POST['date_creation']:date_convert_back(@$row['date_creation']);
[642]215
[825]216// +-----------------------------------------------------------------------+
217// |                             template init                             |
218// +-----------------------------------------------------------------------+
219
[817]220$template->set_filenames(
221  array(
222    'picture_modify' => 'admin/picture_modify.tpl'
223    )
224  );
225
[825]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'] : '').
[1004]232        '&amp;sync_metadata=1',
[825]233   
234    'PATH'=>$row['path'],
235   
236    'TN_SRC' => get_thumbnail_src($row['path'], @$row['tn_ext']),
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    'KEYWORDS' =>
254      isset($_POST['keywords']) ?
255        stripslashes($_POST['keywords']) : @$row['keywords'],
256   
257    'DESCRIPTION' =>
258      isset($_POST['description']) ?
259        stripslashes($_POST['description']) : @$row['comment'],
[509]260 
[825]261    'F_ACTION' =>
262        PHPWG_ROOT_PATH.'admin.php'
263        .get_query_string_diff(array('sync_metadata'))
264    )
265  );
266
267// creation date
268unset($day, $month, $year);
269
270if (isset($_POST['date_creation_action'])
271    and 'set' == $_POST['date_creation_action'])
272{
273  foreach (array('day', 'month', 'year') as $varname)
274  {
275    $$varname = $_POST['date_creation_'.$varname];
276  }
277}
278else if (isset($row['date_creation']) and !empty($row['date_creation']))
279{
280  list($year, $month, $day) = explode('-', $row['date_creation']);
281}
282else
283{
284  list($year, $month, $day) = array('', 0, 0);
285}
286get_day_list('date_creation_day', $day);
287get_month_list('date_creation_month', $month);
288$template->assign_vars(array('DATE_CREATION_YEAR_VALUE' => $year));
[509]289 
[825]290$query = '
291SELECT category_id, uppercats
292  FROM '.IMAGE_CATEGORY_TABLE.' AS ic
293    INNER JOIN '.CATEGORIES_TABLE.' AS c
294      ON c.id = ic.category_id
295  WHERE image_id = '.$_GET['image_id'].'
296;';
297$result = pwg_query($query);
298
299if (mysql_num_rows($result) > 1)
300{
301  $template->assign_block_vars('links', array());
302}
303
304while ($row = mysql_fetch_array($result))
305{
306  $name =
307    get_cat_display_name_cache(
308      $row['uppercats'],
309      PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id=',
310      false
311      );
312   
313  if ($row['category_id'] == $storage_category_id)
314  {
315    $template->assign_vars(array('STORAGE_CATEGORY' => $name));
316  }
317  else
318  {
319    $template->assign_block_vars('links.category', array('NAME' => $name));
320  }
321}
322
323// jump to link
324//
325// 1. find all linked categories that are reachable for the current user.
326// 2. if a category is available in the URL, use it if reachable
327// 3. if URL category not available or reachable, use the first reachable
328//    linked category
329// 4. if no category reachable, no jumpto link
330$base_url_img = PHPWG_ROOT_PATH.'picture.php';
331$base_url_img.= '?image_id='.$_GET['image_id'];
332$base_url_img.= '&amp;cat=';
333unset($url_img);
334
335$query = '
336SELECT category_id
337  FROM '.IMAGE_CATEGORY_TABLE.'
338  WHERE image_id = '.$_GET['image_id'].'
339;';
340$authorizeds = array_diff(
341  array_from_query($query, 'category_id'),
342  explode(',', calculate_permissions($user['id'], $user['status']))
343  );
344
345if (isset($_GET['cat_id'])
346    and in_array($_GET['cat_id'], $authorizeds))
347{
348  $url_img = $base_url_img.$_GET['cat_id'];
349}
350else
351{
352  foreach ($authorizeds as $category)
353  {
354    $url_img = $base_url_img.$category;
355    break;
356  }
357}
358
359if (isset($url_img))
360{
361  $template->assign_block_vars(
362    'jumpto',
363    array(
364      'URL' => $url_img
365      )
366    );
367}
[509]368 
[61]369// associate to another category ?
[635]370$query = '
371SELECT id,name,uppercats,global_rank
372  FROM '.CATEGORIES_TABLE.'
373    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
374  WHERE image_id = '.$_GET['image_id'].'
[1064]375    AND is_storage = \'false\'
[635]376;';
[817]377display_select_cat_wrapper($query, array(), 'associated_option');
[635]378
379$result = pwg_query($query);
380$associateds = array($storage_category_id);
381while ($row = mysql_fetch_array($result))
[345]382{
[635]383  array_push($associateds, $row['id']);
[345]384}
[635]385$query = '
386SELECT id,name,uppercats,global_rank
387  FROM '.CATEGORIES_TABLE.'
388  WHERE id NOT IN ('.implode(',', $associateds).')
389;';
[817]390display_select_cat_wrapper($query, array(), 'dissociated_option');
[809]391
[640]392// representing
393$query = '
394SELECT id,name,uppercats,global_rank
395  FROM '.CATEGORIES_TABLE.'
396  WHERE representative_picture_id = '.$_GET['image_id'].'
397;';
[817]398display_select_cat_wrapper($query, array(), 'elected_option');
[640]399
400$query = '
401SELECT id,name,uppercats,global_rank
402  FROM '.CATEGORIES_TABLE.'
[809]403  WHERE representative_picture_id != '.$_GET['image_id'].'
404    OR representative_picture_id IS NULL
[640]405;';
[817]406display_select_cat_wrapper($query, array(), 'dismissed_option');
407
[61]408//----------------------------------------------------------- sending html code
[817]409
[509]410$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
[362]411?>
Note: See TracBrowser for help on using the repository browser.