source: trunk/admin/picture_modify.php @ 8126

Last change on this file since 8126 was 8126, checked in by patdenice, 13 years ago

feature 2060: Remove adviser mode.
First commit: only php files.

  • 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-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']))
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 (!is_numeric($_POST['date_creation_year'])
63    or !checkdate(
64          $_POST['date_creation_month'],
65          $_POST['date_creation_day'],
66          $_POST['date_creation_year'])
67    )
68  {
69    array_push($page['errors'], l10n('wrong date'));
70  }
71}
72
73if (isset($_POST['submit']) and count($page['errors']) == 0)
74{
75  $data = array();
76  $data{'id'} = $_GET['image_id'];
77  $data{'name'} = $_POST['name'];
78  $data{'author'} = $_POST['author'];
79  $data['level'] = $_POST['level'];
80
81  if ($conf['allow_html_descriptions'])
82  {
83    $data{'comment'} = @$_POST['description'];
84  }
85  else
86  {
87    $data{'comment'} = strip_tags(@$_POST['description']);
88  }
89
90  if (isset($_POST['date_creation_action']))
91  {
92    if ('set' == $_POST['date_creation_action'])
93    {
94      $data{'date_creation'} = $_POST['date_creation_year']
95                                 .'-'.$_POST['date_creation_month']
96                                 .'-'.$_POST['date_creation_day'];
97    }
98    else if ('unset' == $_POST['date_creation_action'])
99    {
100      $data{'date_creation'} = '';
101    }
102  }
103
104  mass_updates(
105    IMAGES_TABLE,
106    array(
107      'primary' => array('id'),
108      'update' => array_diff(array_keys($data), array('id'))
109      ),
110    array($data)
111    );
112
113  // time to deal with tags
114  $tag_ids = array();
115  if (isset($_POST['tags']))
116  {
117    $tag_ids = get_fckb_tag_ids($_POST['tags']);
118  }
119  set_tags($tag_ids, $_GET['image_id']);
120
121  array_push($page['infos'], l10n('Picture informations updated'));
122}
123// associate the element to other categories than its storage category
124if (isset($_POST['associate'])
125    and isset($_POST['cat_dissociated'])
126    and count($_POST['cat_dissociated']) > 0
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  )
139{
140  $query = '
141DELETE FROM '.IMAGE_CATEGORY_TABLE.'
142  WHERE image_id = '.$_GET['image_id'].'
143    AND category_id IN ('.implode(',', $_POST['cat_associated']).')
144';
145  pwg_query($query);
146
147  update_category($_POST['cat_associated']);
148}
149// elect the element to represent the given categories
150if (isset($_POST['elect'])
151    and isset($_POST['cat_dismissed'])
152    and count($_POST['cat_dismissed']) > 0
153  )
154{
155  $datas = array();
156  foreach ($_POST['cat_dismissed'] as $category_id)
157  {
158    array_push($datas,
159               array('id' => $category_id,
160                     'representative_picture_id' => $_GET['image_id']));
161  }
162  $fields = array('primary' => array('id'),
163                  'update' => array('representative_picture_id'));
164  mass_updates(CATEGORIES_TABLE, $fields, $datas);
165}
166// dismiss the element as representant of the given categories
167if (isset($_POST['dismiss'])
168    and isset($_POST['cat_elected'])
169    and count($_POST['cat_elected']) > 0
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' => htmlspecialchars(
236      isset($_POST['author'])
237        ? stripslashes($_POST['author'])
238        : @$row['author']
239      ),
240
241    'DESCRIPTION' =>
242      htmlspecialchars( isset($_POST['description']) ?
243        stripslashes($_POST['description']) : @$row['comment'] ),
244
245    'F_ACTION' =>
246        get_root_url().'admin.php'
247        .get_query_string_diff(array('sync_metadata'))
248    )
249  );
250
251if ($row['has_high'] == 'true')
252{
253  $template->assign(
254    'HIGH_FILESIZE',
255    isset($row['high_filesize'])
256        ? $row['high_filesize'].' KB'
257        : l10n('unknown')
258    );
259}
260
261// image level options
262$selected_level = isset($_POST['level']) ? $_POST['level'] : $row['level'];
263$template->assign(
264    array(
265      'level_options'=> get_privacy_level_options(),
266      'level_options_selected' => array($selected_level)
267    )
268  );
269
270// creation date
271unset($day, $month, $year);
272
273if (isset($_POST['date_creation_action'])
274    and 'set' == $_POST['date_creation_action'])
275{
276  foreach (array('day', 'month', 'year') as $varname)
277  {
278    $$varname = $_POST['date_creation_'.$varname];
279  }
280}
281else if (isset($row['date_creation']) and !empty($row['date_creation']))
282{
283  list($year, $month, $day) = explode('-', $row['date_creation']);
284}
285else
286{
287  list($year, $month, $day) = array('', 0, 0);
288}
289
290
291$month_list = $lang['month'];
292$month_list[0]='------------';
293ksort($month_list);
294
295$template->assign(
296    array(
297      'DATE_CREATION_DAY_VALUE' => $day,
298      'DATE_CREATION_MONTH_VALUE' => $month,
299      'DATE_CREATION_YEAR_VALUE' => $year,
300      'month_list' => $month_list,
301      )
302    );
303
304$query = '
305SELECT category_id, uppercats
306  FROM '.IMAGE_CATEGORY_TABLE.' AS ic
307    INNER JOIN '.CATEGORIES_TABLE.' AS c
308      ON c.id = ic.category_id
309  WHERE image_id = '.$_GET['image_id'].'
310;';
311$result = pwg_query($query);
312
313while ($row = pwg_db_fetch_assoc($result))
314{
315  $name =
316    get_cat_display_name_cache(
317      $row['uppercats'],
318      get_root_url().'admin.php?page=cat_modify&amp;cat_id=',
319      false
320      );
321
322  if ($row['category_id'] == $storage_category_id)
323  {
324    $template->assign('STORAGE_CATEGORY', $name);
325  }
326  else
327  {
328    $template->append('related_categories', $name);
329  }
330}
331
332// jump to link
333//
334// 1. find all linked categories that are reachable for the current user.
335// 2. if a category is available in the URL, use it if reachable
336// 3. if URL category not available or reachable, use the first reachable
337//    linked category
338// 4. if no category reachable, no jumpto link
339
340$query = '
341SELECT category_id
342  FROM '.IMAGE_CATEGORY_TABLE.'
343  WHERE image_id = '.$_GET['image_id'].'
344;';
345
346$authorizeds = array_diff(
347  array_from_query($query, 'category_id'),
348  explode(
349    ',',
350    calculate_permissions($user['id'], $user['status'])
351    )
352  );
353
354if (isset($_GET['cat_id'])
355    and in_array($_GET['cat_id'], $authorizeds))
356{
357  $url_img = make_picture_url(
358    array(
359      'image_id' => $_GET['image_id'],
360      'image_file' => $image_file,
361      'category' => $cache['cat_names'][ $_GET['cat_id'] ],
362      )
363    );
364}
365else
366{
367  foreach ($authorizeds as $category)
368  {
369    $url_img = make_picture_url(
370      array(
371        'image_id' => $_GET['image_id'],
372        'image_file' => $image_file,
373        'category' => $cache['cat_names'][ $category ],
374        )
375      );
376    break;
377  }
378}
379
380if (isset($url_img))
381{
382  $template->assign( 'U_JUMPTO', $url_img );
383}
384
385// associate to another category ?
386$query = '
387SELECT id,name,uppercats,global_rank
388  FROM '.CATEGORIES_TABLE.'
389    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
390  WHERE image_id = '.$_GET['image_id'];
391if (isset($storage_category_id))
392{
393  $query.= '
394    AND id != '.$storage_category_id;
395}
396$query.= '
397;';
398display_select_cat_wrapper($query, array(), 'associated_options');
399
400$result = pwg_query($query);
401$associateds = array(-1);
402if (isset($storage_category_id))
403{
404  array_push($associateds, $storage_category_id);
405}
406while ($row = pwg_db_fetch_assoc($result))
407{
408  array_push($associateds, $row['id']);
409}
410$query = '
411SELECT id,name,uppercats,global_rank
412  FROM '.CATEGORIES_TABLE.'
413  WHERE id NOT IN ('.implode(',', $associateds).')
414;';
415display_select_cat_wrapper($query, array(), 'dissociated_options');
416
417// representing
418$query = '
419SELECT id,name,uppercats,global_rank
420  FROM '.CATEGORIES_TABLE.'
421  WHERE representative_picture_id = '.$_GET['image_id'].'
422;';
423display_select_cat_wrapper($query, array(), 'elected_options');
424
425$query = '
426SELECT id,name,uppercats,global_rank
427  FROM '.CATEGORIES_TABLE.'
428  WHERE representative_picture_id != '.$_GET['image_id'].'
429    OR representative_picture_id IS NULL
430;';
431display_select_cat_wrapper($query, array(), 'dismissed_options');
432
433//----------------------------------------------------------- sending html code
434
435$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
436?>
Note: See TracBrowser for help on using the repository browser.