source: trunk/admin/picture_modify.php @ 5188

Last change on this file since 5188 was 5188, checked in by plg, 14 years ago

feature 724: FCBKcomplete propagated to element_set_global and
element_set_unit to manage tags.

Note: multiple instances of FCBKcomplete on the same page does not work as
good as a single instance.

  • Property svn:eol-style set to LF
File size: 11.9 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24if(!defined("PHPWG_ROOT_PATH"))
25{
26  die('Hacking attempt!');
27}
28
29include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
30
31// +-----------------------------------------------------------------------+
32// | Check Access and exit when user status is not ok                      |
33// +-----------------------------------------------------------------------+
34check_status(ACCESS_ADMINISTRATOR);
35
36// +-----------------------------------------------------------------------+
37// |                          synchronize metadata                         |
38// +-----------------------------------------------------------------------+
39
40if (isset($_GET['sync_metadata']) and !is_adviser())
41{
42  $query = '
43SELECT path
44  FROM '.IMAGES_TABLE.'
45  WHERE id = '.$_GET['image_id'].'
46;';
47  list($path) = pwg_db_fetch_row(pwg_query($query));
48  update_metadata(array($_GET['image_id'] => $path));
49
50  array_push($page['infos'], l10n('Metadata synchronized from file'));
51}
52
53//--------------------------------------------------------- update informations
54
55// first, we verify whether there is a mistake on the given creation date
56if (isset($_POST['date_creation_action'])
57    and 'set' == $_POST['date_creation_action'])
58{
59  if (!checkdate(
60        $_POST['date_creation_month'],
61        $_POST['date_creation_day'],
62        $_POST['date_creation_year'])
63    )
64  {
65    array_push($page['errors'], l10n('wrong date'));
66  }
67}
68
69if (isset($_POST['submit']) and count($page['errors']) == 0 and !is_adviser())
70{
71  $data = array();
72  $data{'id'} = $_GET['image_id'];
73  $data{'name'} = $_POST['name'];
74  $data{'author'} = $_POST['author'];
75  $data['level'] = $_POST['level'];
76
77  if ($conf['allow_html_descriptions'])
78  {
79    $data{'comment'} = @$_POST['description'];
80  }
81  else
82  {
83    $data{'comment'} = strip_tags(@$_POST['description']);
84  }
85
86  if (isset($_POST['date_creation_action']))
87  {
88    if ('set' == $_POST['date_creation_action'])
89    {
90      $data{'date_creation'} = $_POST['date_creation_year']
91                                 .'-'.$_POST['date_creation_month']
92                                 .'-'.$_POST['date_creation_day'];
93    }
94    else if ('unset' == $_POST['date_creation_action'])
95    {
96      $data{'date_creation'} = '';
97    }
98  }
99
100  mass_updates(
101    IMAGES_TABLE,
102    array(
103      'primary' => array('id'),
104      'update' => array_diff(array_keys($data), array('id'))
105      ),
106    array($data)
107    );
108
109  // time to deal with tags
110  $tag_ids = array();
111  if (isset($_POST['tags']))
112  {
113    $tag_ids = get_fckb_tag_ids($_POST['tags']);
114  }
115  set_tags($tag_ids, $_GET['image_id']);
116
117  array_push($page['infos'], l10n('Picture informations updated'));
118}
119// associate the element to other categories than its storage category
120if (isset($_POST['associate'])
121    and isset($_POST['cat_dissociated'])
122    and count($_POST['cat_dissociated']) > 0
123    and !is_adviser()
124  )
125{
126  associate_images_to_categories(
127    array($_GET['image_id']),
128    $_POST['cat_dissociated']
129    );
130}
131// dissociate the element from categories (but not from its storage category)
132if (isset($_POST['dissociate'])
133    and isset($_POST['cat_associated'])
134    and count($_POST['cat_associated']) > 0
135    and !is_adviser()
136  )
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
145  update_category($_POST['cat_associated']);
146}
147// elect the element to represent the given categories
148if (isset($_POST['elect'])
149    and isset($_POST['cat_dismissed'])
150    and count($_POST['cat_dismissed']) > 0
151    and !is_adviser()
152  )
153{
154  $datas = array();
155  foreach ($_POST['cat_dismissed'] as $category_id)
156  {
157    array_push($datas,
158               array('id' => $category_id,
159                     'representative_picture_id' => $_GET['image_id']));
160  }
161  $fields = array('primary' => array('id'),
162                  'update' => array('representative_picture_id'));
163  mass_updates(CATEGORIES_TABLE, $fields, $datas);
164}
165// dismiss the element as representant of the given categories
166if (isset($_POST['dismiss'])
167    and isset($_POST['cat_elected'])
168    and count($_POST['cat_elected']) > 0
169    and !is_adviser()
170  )
171{
172  set_random_representant($_POST['cat_elected']);
173}
174
175// tags
176$query = '
177SELECT
178    tag_id,
179    name AS tag_name
180  FROM '.IMAGE_TAG_TABLE.' AS it
181    JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id
182  WHERE image_id = '.$_GET['image_id'].'
183;';
184$tags = get_fckb_taglist($query);
185
186// retrieving direct information about picture
187$query = '
188SELECT *
189  FROM '.IMAGES_TABLE.'
190  WHERE id = '.$_GET['image_id'].'
191;';
192$row = pwg_db_fetch_assoc(pwg_query($query));
193
194$storage_category_id = null;
195if (!empty($row['storage_category_id']))
196{
197  $storage_category_id = $row['storage_category_id'];
198}
199
200$image_file = $row['file'];
201
202// +-----------------------------------------------------------------------+
203// |                             template init                             |
204// +-----------------------------------------------------------------------+
205
206$template->set_filenames(
207  array(
208    'picture_modify' => 'picture_modify.tpl'
209    )
210  );
211
212$template->assign(
213  array(
214    'tags' => $tags,
215    'U_SYNC' =>
216        get_root_url().'admin.php?page=picture_modify'.
217        '&amp;image_id='.$_GET['image_id'].
218        (isset($_GET['cat_id']) ? '&amp;cat_id='.$_GET['cat_id'] : '').
219        '&amp;sync_metadata=1',
220
221    'PATH'=>$row['path'],
222
223    'TN_SRC' => get_thumbnail_url($row),
224
225    'NAME' =>
226      isset($_POST['name']) ?
227        stripslashes($_POST['name']) : @$row['name'],
228
229    'DIMENSIONS' => @$row['width'].' * '.@$row['height'],
230
231    'FILESIZE' => @$row['filesize'].' KB',
232
233    'REGISTRATION_DATE' => format_date($row['date_available']),
234
235    'AUTHOR' => isset($_POST['author']) ? $_POST['author'] : @$row['author'],
236
237    'DESCRIPTION' =>
238      htmlspecialchars( isset($_POST['description']) ?
239        stripslashes($_POST['description']) : @$row['comment'] ),
240
241    'F_ACTION' =>
242        get_root_url().'admin.php'
243        .get_query_string_diff(array('sync_metadata'))
244    )
245  );
246
247if ($row['has_high'] == 'true')
248{
249  $template->assign(
250    'HIGH_FILESIZE',
251    isset($row['high_filesize'])
252        ? $row['high_filesize'].' KB'
253        : l10n('unknown')
254    );
255}
256
257// image level options
258$tpl_options = array();
259foreach ($conf['available_permission_levels'] as $level)
260{
261  $tpl_options[$level] = l10n( sprintf('Level %d', $level) ).' ('.$level.')';
262}
263$selected_level = isset($_POST['level']) ? $_POST['level'] : $row['level'];
264$template->assign(
265    array(
266      'level_options'=> $tpl_options,
267      'level_options_selected' => array($selected_level)
268    )
269  );
270
271// creation date
272unset($day, $month, $year);
273
274if (isset($_POST['date_creation_action'])
275    and 'set' == $_POST['date_creation_action'])
276{
277  foreach (array('day', 'month', 'year') as $varname)
278  {
279    $$varname = $_POST['date_creation_'.$varname];
280  }
281}
282else if (isset($row['date_creation']) and !empty($row['date_creation']))
283{
284  list($year, $month, $day) = explode('-', $row['date_creation']);
285}
286else
287{
288  list($year, $month, $day) = array('', 0, 0);
289}
290
291
292$month_list = $lang['month'];
293$month_list[0]='------------';
294ksort($month_list);
295
296$template->assign(
297    array(
298      'DATE_CREATION_DAY_VALUE' => $day,
299      'DATE_CREATION_MONTH_VALUE' => $month,
300      'DATE_CREATION_YEAR_VALUE' => $year,
301      'month_list' => $month_list,
302      )
303    );
304
305$query = '
306SELECT category_id, uppercats
307  FROM '.IMAGE_CATEGORY_TABLE.' AS ic
308    INNER JOIN '.CATEGORIES_TABLE.' AS c
309      ON c.id = ic.category_id
310  WHERE image_id = '.$_GET['image_id'].'
311;';
312$result = pwg_query($query);
313
314while ($row = pwg_db_fetch_assoc($result))
315{
316  $name =
317    get_cat_display_name_cache(
318      $row['uppercats'],
319      get_root_url().'admin.php?page=cat_modify&amp;cat_id=',
320      false
321      );
322
323  if ($row['category_id'] == $storage_category_id)
324  {
325    $template->assign('STORAGE_CATEGORY', $name);
326  }
327  else
328  {
329    $template->append('related_categories', $name);
330  }
331}
332
333// jump to link
334//
335// 1. find all linked categories that are reachable for the current user.
336// 2. if a category is available in the URL, use it if reachable
337// 3. if URL category not available or reachable, use the first reachable
338//    linked category
339// 4. if no category reachable, no jumpto link
340
341$query = '
342SELECT category_id
343  FROM '.IMAGE_CATEGORY_TABLE.'
344  WHERE image_id = '.$_GET['image_id'].'
345;';
346
347$authorizeds = array_diff(
348  array_from_query($query, 'category_id'),
349  explode(
350    ',',
351    calculate_permissions($user['id'], $user['status'])
352    )
353  );
354
355if (isset($_GET['cat_id'])
356    and in_array($_GET['cat_id'], $authorizeds))
357{
358  $url_img = make_picture_url(
359    array(
360      'image_id' => $_GET['image_id'],
361      'image_file' => $image_file,
362      'category' => $cache['cat_names'][ $_GET['cat_id'] ],
363      )
364    );
365}
366else
367{
368  foreach ($authorizeds as $category)
369  {
370    $url_img = make_picture_url(
371      array(
372        'image_id' => $_GET['image_id'],
373        'image_file' => $image_file,
374        'category' => $cache['cat_names'][ $category ],
375        )
376      );
377    break;
378  }
379}
380
381if (isset($url_img))
382{
383  $template->assign( 'U_JUMPTO', $url_img );
384}
385
386// associate to another category ?
387$query = '
388SELECT id,name,uppercats,global_rank
389  FROM '.CATEGORIES_TABLE.'
390    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
391  WHERE image_id = '.$_GET['image_id'];
392if (isset($storage_category_id))
393{
394  $query.= '
395    AND id != '.$storage_category_id;
396}
397$query.= '
398;';
399display_select_cat_wrapper($query, array(), 'associated_options');
400
401$result = pwg_query($query);
402$associateds = array(-1);
403if (isset($storage_category_id))
404{
405  array_push($associateds, $storage_category_id);
406}
407while ($row = pwg_db_fetch_assoc($result))
408{
409  array_push($associateds, $row['id']);
410}
411$query = '
412SELECT id,name,uppercats,global_rank
413  FROM '.CATEGORIES_TABLE.'
414  WHERE id NOT IN ('.implode(',', $associateds).')
415;';
416display_select_cat_wrapper($query, array(), 'dissociated_options');
417
418// representing
419$query = '
420SELECT id,name,uppercats,global_rank
421  FROM '.CATEGORIES_TABLE.'
422  WHERE representative_picture_id = '.$_GET['image_id'].'
423;';
424display_select_cat_wrapper($query, array(), 'elected_options');
425
426$query = '
427SELECT id,name,uppercats,global_rank
428  FROM '.CATEGORIES_TABLE.'
429  WHERE representative_picture_id != '.$_GET['image_id'].'
430    OR representative_picture_id IS NULL
431;';
432display_select_cat_wrapper($query, array(), 'dismissed_options');
433
434//----------------------------------------------------------- sending html code
435
436$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
437?>
Note: See TracBrowser for help on using the repository browser.