source: trunk/admin/picture_modify.php @ 2227

Last change on this file since 2227 was 2227, checked in by rvelices, 16 years ago

picture, footer and picture modify template migration

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 12.2 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | file          : $Id: picture_modify.php 2227 2008-02-29 01:25:13Z rvelices $
8// | last update   : $Date: 2008-02-29 01:25:13 +0000 (Fri, 29 Feb 2008) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Revision: 2227 $
11// +-----------------------------------------------------------------------+
12// | This program is free software; you can redistribute it and/or modify  |
13// | it under the terms of the GNU General Public License as published by  |
14// | the Free Software Foundation                                          |
15// |                                                                       |
16// | This program is distributed in the hope that it will be useful, but   |
17// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
18// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
19// | General Public License for more details.                              |
20// |                                                                       |
21// | You should have received a copy of the GNU General Public License     |
22// | along with this program; if not, write to the Free Software           |
23// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
24// | USA.                                                                  |
25// +-----------------------------------------------------------------------+
26
27if(!defined("PHPWG_ROOT_PATH"))
28{
29  die('Hacking attempt!');
30}
31
32include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
33
34// +-----------------------------------------------------------------------+
35// | Check Access and exit when user status is not ok                      |
36// +-----------------------------------------------------------------------+
37check_status(ACCESS_ADMINISTRATOR);
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) = mysql_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('err_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  set_tags(
113    isset($_POST['tags']) ? $_POST['tags'] : array(),
114    $_GET['image_id']
115    );
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// retrieving direct information about picture
176$query = '
177SELECT *
178  FROM '.IMAGES_TABLE.'
179  WHERE id = '.$_GET['image_id'].'
180;';
181$row = mysql_fetch_array(pwg_query($query));
182
183$storage_category_id = $row['storage_category_id'];
184$image_file = $row['file'];
185
186// tags
187$query = '
188SELECT tag_id
189  FROM '.IMAGE_TAG_TABLE.'
190  WHERE image_id = '.$_GET['image_id'].'
191;';
192$selected_tags = array_from_query($query, 'tag_id');
193
194// Navigation path
195
196$date = isset($_POST['date_creation']) && empty($page['errors'])
197?$_POST['date_creation']:date_convert_back(@$row['date_creation']);
198
199// +-----------------------------------------------------------------------+
200// |                             template init                             |
201// +-----------------------------------------------------------------------+
202
203$template->set_filenames(
204  array(
205    'picture_modify' => 'admin/picture_modify.tpl'
206    )
207  );
208
209$all_tags = get_all_tags();
210
211if (count($all_tags) > 0)
212{
213  $tag_selection = get_html_tag_selection(
214    $all_tags,
215    'tags',
216    $selected_tags
217    );
218}
219else
220{
221  $tag_selection =
222    '<p>'.
223    l10n('No tag defined. Use Administration>Pictures>Tags').
224    '</p>';
225}
226
227$template->assign(
228  array(
229    'U_SYNC' =>
230        PHPWG_ROOT_PATH.'admin.php?page=picture_modify'.
231        '&amp;image_id='.$_GET['image_id'].
232        (isset($_GET['cat_id']) ? '&amp;cat_id='.$_GET['cat_id'] : '').
233        '&amp;sync_metadata=1',
234
235    'PATH'=>$row['path'],
236
237    'TN_SRC' => get_thumbnail_url($row),
238
239    'NAME' =>
240      isset($_POST['name']) ?
241        stripslashes($_POST['name']) : @$row['name'],
242
243    'DIMENSIONS' => @$row['width'].' * '.@$row['height'],
244
245    'FILESIZE' => @$row['filesize'].' KB',
246
247    'REGISTRATION_DATE' =>
248      format_date($row['date_available'], 'mysql_datetime', false),
249
250    'AUTHOR' => isset($_POST['author']) ? $_POST['author'] : @$row['author'],
251
252    'CREATION_DATE' => $date,
253
254    'TAG_SELECTION' => $tag_selection,
255
256    'DESCRIPTION' =>
257      htmlspecialchars( isset($_POST['description']) ?
258        stripslashes($_POST['description']) : @$row['comment'] ),
259
260    'F_ACTION' =>
261        PHPWG_ROOT_PATH.'admin.php'
262        .get_query_string_diff(array('sync_metadata'))
263    )
264  );
265
266if ($row['has_high'] == 'true')
267{
268  $template->assign(
269    'HIGH_FILESIZE',
270    isset($row['high_filesize'])
271        ? $row['high_filesize'].' KB'
272        : l10n('unknown')
273    );
274}
275
276// image level options
277$tpl_options = array();
278foreach ($conf['available_permission_levels'] as $level)
279{
280  $tpl_options[$level] = l10n( sprintf('Level %d', $level) ).' ('.$level.')';
281}
282$selected_level = isset($_POST['level']) ? $_POST['level'] : $row['level'];
283$template->assign(
284    array(
285      'level_options'=> $tpl_options,
286      'level_options_selected' => array($selected_level)
287    )
288  );
289
290// creation date
291unset($day, $month, $year);
292
293if (isset($_POST['date_creation_action'])
294    and 'set' == $_POST['date_creation_action'])
295{
296  foreach (array('day', 'month', 'year') as $varname)
297  {
298    $$varname = $_POST['date_creation_'.$varname];
299  }
300}
301else if (isset($row['date_creation']) and !empty($row['date_creation']))
302{
303  list($year, $month, $day) = explode('-', $row['date_creation']);
304}
305else
306{
307  list($year, $month, $day) = array('', 0, 0);
308}
309
310
311get_month_list('date_creation_month', $month);
312$month_list = $lang['month'];
313$month_list[0]='------------';
314ksort($month_list);
315
316$template->assign(
317    array(
318      'DATE_CREATION_DAY_VALUE' => $day,
319      'DATE_CREATION_MONTH_VALUE' => $month,
320      'DATE_CREATION_YEAR_VALUE' => $year,
321      'month_list' => $month_list,
322      )
323    );
324
325$query = '
326SELECT category_id, uppercats
327  FROM '.IMAGE_CATEGORY_TABLE.' AS ic
328    INNER JOIN '.CATEGORIES_TABLE.' AS c
329      ON c.id = ic.category_id
330  WHERE image_id = '.$_GET['image_id'].'
331;';
332$result = pwg_query($query);
333
334while ($row = mysql_fetch_array($result))
335{
336  $name =
337    get_cat_display_name_cache(
338      $row['uppercats'],
339      get_root_url().'admin.php?page=cat_modify&amp;cat_id=',
340      false
341      );
342
343  if ($row['category_id'] == $storage_category_id)
344  {
345    $template->assign('STORAGE_CATEGORY', $name);
346  }
347  else
348  {
349    $template->append('related_categories', $name);
350  }
351}
352
353// jump to link
354//
355// 1. find all linked categories that are reachable for the current user.
356// 2. if a category is available in the URL, use it if reachable
357// 3. if URL category not available or reachable, use the first reachable
358//    linked category
359// 4. if no category reachable, no jumpto link
360
361$query = '
362SELECT category_id
363  FROM '.IMAGE_CATEGORY_TABLE.'
364  WHERE image_id = '.$_GET['image_id'].'
365;';
366
367$authorizeds = array_diff(
368  array_from_query($query, 'category_id'),
369  explode(
370    ',',
371    calculate_permissions($user['id'], $user['status'])
372    )
373  );
374
375if (isset($_GET['cat_id'])
376    and in_array($_GET['cat_id'], $authorizeds))
377{
378  $url_img = make_picture_url(
379    array(
380      'image_id' => $_GET['image_id'],
381      'image_file' => $image_file,
382      'category' => $cache['cat_names'][ $_GET['cat_id'] ],
383      )
384    );
385}
386else
387{
388  foreach ($authorizeds as $category)
389  {
390    $url_img = make_picture_url(
391      array(
392        'image_id' => $_GET['image_id'],
393        'image_file' => $image_file,
394        'category' => $cache['cat_names'][ $category ],
395        )
396      );
397    break;
398  }
399}
400
401if (isset($url_img))
402{
403  $template->assign( 'U_JUMPTO', $url_img );
404}
405
406// associate to another category ?
407$query = '
408SELECT id,name,uppercats,global_rank
409  FROM '.CATEGORIES_TABLE.'
410    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
411  WHERE image_id = '.$_GET['image_id'].'
412    AND id != '.$storage_category_id.'
413;';
414display_select_cat_wrapper($query, array(), 'associated_options');
415
416$result = pwg_query($query);
417$associateds = array($storage_category_id);
418while ($row = mysql_fetch_array($result))
419{
420  array_push($associateds, $row['id']);
421}
422$query = '
423SELECT id,name,uppercats,global_rank
424  FROM '.CATEGORIES_TABLE.'
425  WHERE id NOT IN ('.implode(',', $associateds).')
426;';
427display_select_cat_wrapper($query, array(), 'dissociated_options');
428
429// representing
430$query = '
431SELECT id,name,uppercats,global_rank
432  FROM '.CATEGORIES_TABLE.'
433  WHERE representative_picture_id = '.$_GET['image_id'].'
434;';
435display_select_cat_wrapper($query, array(), 'elected_options');
436
437$query = '
438SELECT id,name,uppercats,global_rank
439  FROM '.CATEGORIES_TABLE.'
440  WHERE representative_picture_id != '.$_GET['image_id'].'
441    OR representative_picture_id IS NULL
442;';
443display_select_cat_wrapper($query, array(), 'dismissed_options');
444
445//----------------------------------------------------------- sending html code
446
447$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
448?>
Note: See TracBrowser for help on using the repository browser.