source: trunk/admin/picture_modify.php @ 5196

Last change on this file since 5196 was 5196, checked in by plg, 15 years ago

increase copyright year to 2010

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