source: trunk/admin/picture_modify.php @ 1064

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

new feature: source/destination links between categories. Will we keep this
feature? Code is complicated and very few people will understand how it
works...

modification: #images.storage_category_id replaced by
#image_category.is_storage

improvement: many code refactoring to improve readibility

improvement: virtual category creation code was moved to a dedicated
function in order to be called from admin/cat_list.php and
admin/cat_modify.php (create a new destination category)

  • 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: 2006-03-04 23:31:46 +0000 (Sat, 04 Mar 2006) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 1064 $
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    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id
175  WHERE id = '.$_GET['image_id'].'
176    AND is_storage = \'true\'
177;';
178$row = mysql_fetch_array(pwg_query($query));
179
180$storage_category_id = $row['category_id'];
181
182// Navigation path
183
184$date = isset($_POST['date_creation']) && empty($page['errors'])
185?$_POST['date_creation']:date_convert_back(@$row['date_creation']);
186
187// +-----------------------------------------------------------------------+
188// |                             template init                             |
189// +-----------------------------------------------------------------------+
190
191$template->set_filenames(
192  array(
193    'picture_modify' => 'admin/picture_modify.tpl'
194    )
195  );
196
197$template->assign_vars(
198  array(
199    'U_SYNC' =>
200        PHPWG_ROOT_PATH.'admin.php?page=picture_modify'.
201        '&amp;image_id='.$_GET['image_id'].
202        (isset($_GET['cat_id']) ? '&amp;cat_id='.$_GET['cat_id'] : '').
203        '&amp;sync_metadata=1',
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        PHPWG_ROOT_PATH.'admin.php'
234        .get_query_string_diff(array('sync_metadata'))
235    )
236  );
237
238// creation date
239unset($day, $month, $year);
240
241if (isset($_POST['date_creation_action'])
242    and 'set' == $_POST['date_creation_action'])
243{
244  foreach (array('day', 'month', 'year') as $varname)
245  {
246    $$varname = $_POST['date_creation_'.$varname];
247  }
248}
249else if (isset($row['date_creation']) and !empty($row['date_creation']))
250{
251  list($year, $month, $day) = explode('-', $row['date_creation']);
252}
253else
254{
255  list($year, $month, $day) = array('', 0, 0);
256}
257get_day_list('date_creation_day', $day);
258get_month_list('date_creation_month', $month);
259$template->assign_vars(array('DATE_CREATION_YEAR_VALUE' => $year));
260 
261$query = '
262SELECT category_id, uppercats
263  FROM '.IMAGE_CATEGORY_TABLE.' AS ic
264    INNER JOIN '.CATEGORIES_TABLE.' AS c
265      ON c.id = ic.category_id
266  WHERE image_id = '.$_GET['image_id'].'
267;';
268$result = pwg_query($query);
269
270if (mysql_num_rows($result) > 1)
271{
272  $template->assign_block_vars('links', array());
273}
274
275while ($row = mysql_fetch_array($result))
276{
277  $name =
278    get_cat_display_name_cache(
279      $row['uppercats'],
280      PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id=',
281      false
282      );
283   
284  if ($row['category_id'] == $storage_category_id)
285  {
286    $template->assign_vars(array('STORAGE_CATEGORY' => $name));
287  }
288  else
289  {
290    $template->assign_block_vars('links.category', array('NAME' => $name));
291  }
292}
293
294// jump to link
295//
296// 1. find all linked categories that are reachable for the current user.
297// 2. if a category is available in the URL, use it if reachable
298// 3. if URL category not available or reachable, use the first reachable
299//    linked category
300// 4. if no category reachable, no jumpto link
301$base_url_img = PHPWG_ROOT_PATH.'picture.php';
302$base_url_img.= '?image_id='.$_GET['image_id'];
303$base_url_img.= '&amp;cat=';
304unset($url_img);
305
306$query = '
307SELECT category_id
308  FROM '.IMAGE_CATEGORY_TABLE.'
309  WHERE image_id = '.$_GET['image_id'].'
310;';
311$authorizeds = array_diff(
312  array_from_query($query, 'category_id'),
313  explode(',', calculate_permissions($user['id'], $user['status']))
314  );
315
316if (isset($_GET['cat_id'])
317    and in_array($_GET['cat_id'], $authorizeds))
318{
319  $url_img = $base_url_img.$_GET['cat_id'];
320}
321else
322{
323  foreach ($authorizeds as $category)
324  {
325    $url_img = $base_url_img.$category;
326    break;
327  }
328}
329
330if (isset($url_img))
331{
332  $template->assign_block_vars(
333    'jumpto',
334    array(
335      'URL' => $url_img
336      )
337    );
338}
339 
340// associate to another category ?
341$query = '
342SELECT id,name,uppercats,global_rank
343  FROM '.CATEGORIES_TABLE.'
344    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
345  WHERE image_id = '.$_GET['image_id'].'
346    AND is_storage = \'false\'
347;';
348display_select_cat_wrapper($query, array(), 'associated_option');
349
350$result = pwg_query($query);
351$associateds = array($storage_category_id);
352while ($row = mysql_fetch_array($result))
353{
354  array_push($associateds, $row['id']);
355}
356$query = '
357SELECT id,name,uppercats,global_rank
358  FROM '.CATEGORIES_TABLE.'
359  WHERE id NOT IN ('.implode(',', $associateds).')
360;';
361display_select_cat_wrapper($query, array(), 'dissociated_option');
362
363// representing
364$query = '
365SELECT id,name,uppercats,global_rank
366  FROM '.CATEGORIES_TABLE.'
367  WHERE representative_picture_id = '.$_GET['image_id'].'
368;';
369display_select_cat_wrapper($query, array(), 'elected_option');
370
371$query = '
372SELECT id,name,uppercats,global_rank
373  FROM '.CATEGORIES_TABLE.'
374  WHERE representative_picture_id != '.$_GET['image_id'].'
375    OR representative_picture_id IS NULL
376;';
377display_select_cat_wrapper($query, array(), 'dismissed_option');
378
379//----------------------------------------------------------- sending html code
380
381$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
382?>
Note: See TracBrowser for help on using the repository browser.