source: trunk/admin/picture_modify.php @ 2403

Last change on this file since 2403 was 2304, checked in by rvelices, 17 years ago

merge -r 2303 from branch-1_7 to trunk

  • removed some unused code
  • mass_updates function does not need SELECT VERSION()
  • rewrote update_uppercats to avoid db update if no change
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 11.9 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008      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) = mysql_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('err_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  set_tags(
110    isset($_POST['tags']) ? $_POST['tags'] : array(),
111    $_GET['image_id']
112    );
113
114  array_push($page['infos'], l10n('Picture informations updated'));
115}
116// associate the element to other categories than its storage category
117if (isset($_POST['associate'])
118    and isset($_POST['cat_dissociated'])
119    and count($_POST['cat_dissociated']) > 0
120    and !is_adviser()
121  )
122{
123  associate_images_to_categories(
124    array($_GET['image_id']),
125    $_POST['cat_dissociated']
126    );
127}
128// dissociate the element from categories (but not from its storage category)
129if (isset($_POST['dissociate'])
130    and isset($_POST['cat_associated'])
131    and count($_POST['cat_associated']) > 0
132    and !is_adviser()
133  )
134{
135  $query = '
136DELETE FROM '.IMAGE_CATEGORY_TABLE.'
137  WHERE image_id = '.$_GET['image_id'].'
138    AND category_id IN ('.implode(',', $_POST['cat_associated']).')
139';
140  pwg_query($query);
141
142  update_category($_POST['cat_associated']);
143}
144// elect the element to represent the given categories
145if (isset($_POST['elect'])
146    and isset($_POST['cat_dismissed'])
147    and count($_POST['cat_dismissed']) > 0
148    and !is_adviser()
149  )
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    and !is_adviser()
167  )
168{
169  set_random_representant($_POST['cat_elected']);
170}
171
172// retrieving direct information about picture
173$query = '
174SELECT *
175  FROM '.IMAGES_TABLE.'
176  WHERE id = '.$_GET['image_id'].'
177;';
178$row = mysql_fetch_array(pwg_query($query));
179
180$storage_category_id = $row['storage_category_id'];
181$image_file = $row['file'];
182
183// tags
184$query = '
185SELECT tag_id
186  FROM '.IMAGE_TAG_TABLE.'
187  WHERE image_id = '.$_GET['image_id'].'
188;';
189$selected_tags = array_from_query($query, 'tag_id');
190
191// +-----------------------------------------------------------------------+
192// |                             template init                             |
193// +-----------------------------------------------------------------------+
194
195$template->set_filenames(
196  array(
197    'picture_modify' => 'admin/picture_modify.tpl'
198    )
199  );
200
201$all_tags = get_all_tags();
202
203if (count($all_tags) > 0)
204{
205  $tag_selection = get_html_tag_selection(
206    $all_tags,
207    'tags',
208    $selected_tags
209    );
210}
211else
212{
213  $tag_selection =
214    '<p>'.
215    l10n('No tag defined. Use Administration>Pictures>Tags').
216    '</p>';
217}
218
219$template->assign(
220  array(
221    'U_SYNC' =>
222        get_root_url().'admin.php?page=picture_modify'.
223        '&amp;image_id='.$_GET['image_id'].
224        (isset($_GET['cat_id']) ? '&amp;cat_id='.$_GET['cat_id'] : '').
225        '&amp;sync_metadata=1',
226
227    'PATH'=>$row['path'],
228
229    'TN_SRC' => get_thumbnail_url($row),
230
231    'NAME' =>
232      isset($_POST['name']) ?
233        stripslashes($_POST['name']) : @$row['name'],
234
235    'DIMENSIONS' => @$row['width'].' * '.@$row['height'],
236
237    'FILESIZE' => @$row['filesize'].' KB',
238
239    'REGISTRATION_DATE' =>
240      format_date($row['date_available'], 'mysql_datetime', false),
241
242    'AUTHOR' => isset($_POST['author']) ? $_POST['author'] : @$row['author'],
243
244    'TAG_SELECTION' => $tag_selection,
245
246    'DESCRIPTION' =>
247      htmlspecialchars( isset($_POST['description']) ?
248        stripslashes($_POST['description']) : @$row['comment'] ),
249
250    'F_ACTION' =>
251        get_root_url().'admin.php'
252        .get_query_string_diff(array('sync_metadata'))
253    )
254  );
255
256if ($row['has_high'] == 'true')
257{
258  $template->assign(
259    'HIGH_FILESIZE',
260    isset($row['high_filesize'])
261        ? $row['high_filesize'].' KB'
262        : l10n('unknown')
263    );
264}
265
266// image level options
267$tpl_options = array();
268foreach ($conf['available_permission_levels'] as $level)
269{
270  $tpl_options[$level] = l10n( sprintf('Level %d', $level) ).' ('.$level.')';
271}
272$selected_level = isset($_POST['level']) ? $_POST['level'] : $row['level'];
273$template->assign(
274    array(
275      'level_options'=> $tpl_options,
276      'level_options_selected' => array($selected_level)
277    )
278  );
279
280// creation date
281unset($day, $month, $year);
282
283if (isset($_POST['date_creation_action'])
284    and 'set' == $_POST['date_creation_action'])
285{
286  foreach (array('day', 'month', 'year') as $varname)
287  {
288    $$varname = $_POST['date_creation_'.$varname];
289  }
290}
291else if (isset($row['date_creation']) and !empty($row['date_creation']))
292{
293  list($year, $month, $day) = explode('-', $row['date_creation']);
294}
295else
296{
297  list($year, $month, $day) = array('', 0, 0);
298}
299
300
301$month_list = $lang['month'];
302$month_list[0]='------------';
303ksort($month_list);
304
305$template->assign(
306    array(
307      'DATE_CREATION_DAY_VALUE' => $day,
308      'DATE_CREATION_MONTH_VALUE' => $month,
309      'DATE_CREATION_YEAR_VALUE' => $year,
310      'month_list' => $month_list,
311      )
312    );
313
314$query = '
315SELECT category_id, uppercats
316  FROM '.IMAGE_CATEGORY_TABLE.' AS ic
317    INNER JOIN '.CATEGORIES_TABLE.' AS c
318      ON c.id = ic.category_id
319  WHERE image_id = '.$_GET['image_id'].'
320;';
321$result = pwg_query($query);
322
323while ($row = mysql_fetch_array($result))
324{
325  $name =
326    get_cat_display_name_cache(
327      $row['uppercats'],
328      get_root_url().'admin.php?page=cat_modify&amp;cat_id=',
329      false
330      );
331
332  if ($row['category_id'] == $storage_category_id)
333  {
334    $template->assign('STORAGE_CATEGORY', $name);
335  }
336  else
337  {
338    $template->append('related_categories', $name);
339  }
340}
341
342// jump to link
343//
344// 1. find all linked categories that are reachable for the current user.
345// 2. if a category is available in the URL, use it if reachable
346// 3. if URL category not available or reachable, use the first reachable
347//    linked category
348// 4. if no category reachable, no jumpto link
349
350$query = '
351SELECT category_id
352  FROM '.IMAGE_CATEGORY_TABLE.'
353  WHERE image_id = '.$_GET['image_id'].'
354;';
355
356$authorizeds = array_diff(
357  array_from_query($query, 'category_id'),
358  explode(
359    ',',
360    calculate_permissions($user['id'], $user['status'])
361    )
362  );
363
364if (isset($_GET['cat_id'])
365    and in_array($_GET['cat_id'], $authorizeds))
366{
367  $url_img = make_picture_url(
368    array(
369      'image_id' => $_GET['image_id'],
370      'image_file' => $image_file,
371      'category' => $cache['cat_names'][ $_GET['cat_id'] ],
372      )
373    );
374}
375else
376{
377  foreach ($authorizeds as $category)
378  {
379    $url_img = make_picture_url(
380      array(
381        'image_id' => $_GET['image_id'],
382        'image_file' => $image_file,
383        'category' => $cache['cat_names'][ $category ],
384        )
385      );
386    break;
387  }
388}
389
390if (isset($url_img))
391{
392  $template->assign( 'U_JUMPTO', $url_img );
393}
394
395// associate to another category ?
396$query = '
397SELECT id,name,uppercats,global_rank
398  FROM '.CATEGORIES_TABLE.'
399    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
400  WHERE image_id = '.$_GET['image_id'].'
401    AND id != '.$storage_category_id.'
402;';
403display_select_cat_wrapper($query, array(), 'associated_options');
404
405$result = pwg_query($query);
406$associateds = array($storage_category_id);
407while ($row = mysql_fetch_array($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.