source: trunk/admin/picture_modify.php @ 13038

Revision 13038, 13.2 KB checked in by rvelices, 8 years ago (diff)

multisize - added the coi (still to affine the admin ui + language)
multisize - derivatives can be revuild from a larger derviative instead of the original

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