source: trunk/admin/picture_modify.php @ 825

Last change on this file since 825 was 825, checked in by plg, 19 years ago
  • improvement : screen admin/picture_modify rewritten. Presentation copied from admin/cat_modify : fieldsets regroup fields. Ability to synchronize metadata for the displayed item.
  • bug 110 fixed : "return to element view from element edition fails depending on permissions". If a reachable (for the connected admin) category is available, a "jump to" link is displayed, by default, using the category given in URL.
  • bug fixed : in mass_updates function, the first item of $fieldsupdate has not always 0 for id (as in any array).
  • modification : get_keywords function understands spaces as separator, allow less than 3 chars keywords, allow quotes.
  • new : ability to allow HTML in picture or category description (false by default)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.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: 2005-08-18 17:59:00 +0000 (Thu, 18 Aug 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 825 $
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}
32include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
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
51//--------------------------------------------------------- update informations
52
53// first, we verify whether there is a mistake on the given creation date
54if (isset($_POST['date_creation_action'])
55    and 'set' == $_POST['date_creation_action'])
56{
57  if (!checkdate(
58        $_POST['date_creation_month'],
59        $_POST['date_creation_day'],
60        $_POST['date_creation_year'])
61    )
62  {
63    array_push($page['errors'], $lang['err_date']);
64  }
65}
66
67if (isset($_POST['submit']) and count($page['errors']) == 0)
68{
69  $data = array();
70  $data{'id'} = $_GET['image_id'];
71  $data{'name'} = $_POST['name'];
72  $data{'author'} = $_POST['author'];
73
74  if ($conf['allow_html_descriptions'])
75  {
76    $data{'comment'} = @$_POST['description'];
77  }
78  else
79  {
80    $data{'comment'} = strip_tags(@$_POST['description']);
81  }
82
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  }
96
97  $keywords = get_keywords($_POST['keywords']);
98  if (count($keywords) > 0)
99  {
100    $data{'keywords'} = implode(',', $keywords);
101  }
102  else
103  {
104    $data{'keywords'} = '';
105  }
106
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'));
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();
124  foreach ($_POST['cat_dissociated'] as $category_id)
125  {
126    array_push($datas, array('image_id' => $_GET['image_id'],
127                             'category_id' => $category_id));
128  }
129  mass_inserts(IMAGE_CATEGORY_TABLE, array('image_id', 'category_id'), $datas);
130
131  update_category($_POST['cat_dissociated']);
132}
133// dissociate the element from categories (but not from its storage category)
134if (isset($_POST['dissociate'])
135    and isset($_POST['cat_associated'])
136    and count($_POST['cat_associated']) > 0)
137{
138  $query = '
139DELETE FROM '.IMAGE_CATEGORY_TABLE.'
140  WHERE image_id = '.$_GET['image_id'].'
141    AND category_id IN ('.implode(',',$_POST['cat_associated'] ).')
142';
143  pwg_query($query);
144  update_category($_POST['cat_associated']);
145}
146// elect the element to represent the given categories
147if (isset($_POST['elect'])
148    and isset($_POST['cat_dismissed'])
149    and count($_POST['cat_dismissed']) > 0)
150{
151  $datas = array();
152  foreach ($_POST['cat_dismissed'] as $category_id)
153  {
154    array_push($datas,
155               array('id' => $category_id,
156                     'representative_picture_id' => $_GET['image_id']));
157  }
158  $fields = array('primary' => array('id'),
159                  'update' => array('representative_picture_id'));
160  mass_updates(CATEGORIES_TABLE, $fields, $datas);
161}
162// dismiss the element as representant of the given categories
163if (isset($_POST['dismiss'])
164    and isset($_POST['cat_elected'])
165    and count($_POST['cat_elected']) > 0)
166{
167  set_random_representant($_POST['cat_elected']);
168}
169
170// retrieving direct information about picture
171$query = '
172SELECT *
173  FROM '.IMAGES_TABLE.'
174  WHERE id = '.$_GET['image_id'].'
175;';
176$row = mysql_fetch_array(pwg_query($query));
177
178$storage_category_id = $row['storage_category_id'];
179
180// Navigation path
181
182$date = isset($_POST['date_creation']) && empty($page['errors'])
183?$_POST['date_creation']:date_convert_back(@$row['date_creation']);
184
185// +-----------------------------------------------------------------------+
186// |                             template init                             |
187// +-----------------------------------------------------------------------+
188
189$template->set_filenames(
190  array(
191    'picture_modify' => 'admin/picture_modify.tpl'
192    )
193  );
194
195$template->assign_vars(
196  array(
197    'U_SYNC' =>
198      add_session_id(
199        PHPWG_ROOT_PATH.'admin.php?page=picture_modify'.
200        '&amp;image_id='.$_GET['image_id'].
201        (isset($_GET['cat_id']) ? '&amp;cat_id='.$_GET['cat_id'] : '').
202        '&amp;sync_metadata=1'
203        ),
204   
205    'PATH'=>$row['path'],
206   
207    'TN_SRC' => get_thumbnail_src($row['path'], @$row['tn_ext']),
208   
209    'NAME' =>
210      isset($_POST['name']) ?
211        stripslashes($_POST['name']) : @$row['name'],
212   
213    'DIMENSIONS' => @$row['width'].' * '.@$row['height'],
214   
215    'FILESIZE' => @$row['filesize'].' KB',
216   
217    'REGISTRATION_DATE' =>
218      format_date($row['date_available'], 'mysql_datetime', false),
219   
220    'AUTHOR' => isset($_POST['author']) ? $_POST['author'] : @$row['author'],
221   
222    'CREATION_DATE' => $date,
223   
224    'KEYWORDS' =>
225      isset($_POST['keywords']) ?
226        stripslashes($_POST['keywords']) : @$row['keywords'],
227   
228    'DESCRIPTION' =>
229      isset($_POST['description']) ?
230        stripslashes($_POST['description']) : @$row['comment'],
231 
232    'F_ACTION' =>
233      add_session_id(
234        PHPWG_ROOT_PATH.'admin.php'
235        .get_query_string_diff(array('sync_metadata'))
236        )
237    )
238  );
239
240// creation date
241unset($day, $month, $year);
242
243if (isset($_POST['date_creation_action'])
244    and 'set' == $_POST['date_creation_action'])
245{
246  foreach (array('day', 'month', 'year') as $varname)
247  {
248    $$varname = $_POST['date_creation_'.$varname];
249  }
250}
251else if (isset($row['date_creation']) and !empty($row['date_creation']))
252{
253  list($year, $month, $day) = explode('-', $row['date_creation']);
254}
255else
256{
257  list($year, $month, $day) = array('', 0, 0);
258}
259get_day_list('date_creation_day', $day);
260get_month_list('date_creation_month', $month);
261$template->assign_vars(array('DATE_CREATION_YEAR_VALUE' => $year));
262 
263$query = '
264SELECT category_id, uppercats
265  FROM '.IMAGE_CATEGORY_TABLE.' AS ic
266    INNER JOIN '.CATEGORIES_TABLE.' AS c
267      ON c.id = ic.category_id
268  WHERE image_id = '.$_GET['image_id'].'
269;';
270$result = pwg_query($query);
271
272if (mysql_num_rows($result) > 1)
273{
274  $template->assign_block_vars('links', array());
275}
276
277while ($row = mysql_fetch_array($result))
278{
279  $name =
280    get_cat_display_name_cache(
281      $row['uppercats'],
282      PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id=',
283      false
284      );
285   
286  if ($row['category_id'] == $storage_category_id)
287  {
288    $template->assign_vars(array('STORAGE_CATEGORY' => $name));
289  }
290  else
291  {
292    $template->assign_block_vars('links.category', array('NAME' => $name));
293  }
294}
295
296// jump to link
297//
298// 1. find all linked categories that are reachable for the current user.
299// 2. if a category is available in the URL, use it if reachable
300// 3. if URL category not available or reachable, use the first reachable
301//    linked category
302// 4. if no category reachable, no jumpto link
303$base_url_img = PHPWG_ROOT_PATH.'picture.php';
304$base_url_img.= '?image_id='.$_GET['image_id'];
305$base_url_img.= '&amp;cat=';
306unset($url_img);
307
308$query = '
309SELECT category_id
310  FROM '.IMAGE_CATEGORY_TABLE.'
311  WHERE image_id = '.$_GET['image_id'].'
312;';
313$authorizeds = array_diff(
314  array_from_query($query, 'category_id'),
315  explode(',', calculate_permissions($user['id'], $user['status']))
316  );
317
318if (isset($_GET['cat_id'])
319    and in_array($_GET['cat_id'], $authorizeds))
320{
321  $url_img = $base_url_img.$_GET['cat_id'];
322}
323else
324{
325  foreach ($authorizeds as $category)
326  {
327    $url_img = $base_url_img.$category;
328    break;
329  }
330}
331
332if (isset($url_img))
333{
334  $template->assign_block_vars(
335    'jumpto',
336    array(
337      'URL' => $url_img
338      )
339    );
340}
341 
342// associate to another category ?
343$query = '
344SELECT id,name,uppercats,global_rank
345  FROM '.CATEGORIES_TABLE.'
346    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
347  WHERE image_id = '.$_GET['image_id'].'
348    AND id != '.$storage_category_id.'
349;';
350display_select_cat_wrapper($query, array(), 'associated_option');
351
352$result = pwg_query($query);
353$associateds = array($storage_category_id);
354while ($row = mysql_fetch_array($result))
355{
356  array_push($associateds, $row['id']);
357}
358$query = '
359SELECT id,name,uppercats,global_rank
360  FROM '.CATEGORIES_TABLE.'
361  WHERE id NOT IN ('.implode(',', $associateds).')
362;';
363display_select_cat_wrapper($query, array(), 'dissociated_option');
364
365// representing
366$query = '
367SELECT id,name,uppercats,global_rank
368  FROM '.CATEGORIES_TABLE.'
369  WHERE representative_picture_id = '.$_GET['image_id'].'
370;';
371display_select_cat_wrapper($query, array(), 'elected_option');
372
373$query = '
374SELECT id,name,uppercats,global_rank
375  FROM '.CATEGORIES_TABLE.'
376  WHERE representative_picture_id != '.$_GET['image_id'].'
377    OR representative_picture_id IS NULL
378;';
379display_select_cat_wrapper($query, array(), 'dismissed_option');
380
381//----------------------------------------------------------- sending html code
382
383$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
384?>
Note: See TracBrowser for help on using the repository browser.