source: trunk/admin/picture_modify.php @ 768

Last change on this file since 768 was 732, checked in by plg, 20 years ago
  • bug fixed : even with a wrong date given, tries to update (should not)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.3 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-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2005-02-09 21:46:28 +0000 (Wed, 09 Feb 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 732 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28if(!defined("PHPWG_ROOT_PATH"))
29{
30  die ("Hacking attempt!");
31}
32include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
33//--------------------------------------------------------- update informations
34$errors = array();
35// first, we verify whether there is a mistake on the given creation date
36if (isset($_POST['date_creation']) and !empty($_POST['date_creation']))
37{
38  if (!check_date_format($_POST['date_creation']))
39  {
40    array_push($errors, $lang['err_date']);
41  }
42}
43if (isset($_POST['submit']) and count($errors) == 0)
44{
45  $query = 'UPDATE '.IMAGES_TABLE.' SET name = ';
46  if ($_POST['name'] == '')
47    $query.= 'NULL';
48  else
49    $query.= "'".htmlentities($_POST['name'], ENT_QUOTES)."'";
50 
51  $query.= ', author = ';
52  if ($_POST['author'] == '')
53    $query.= 'NULL';
54  else
55    $query.= "'".htmlentities($_POST['author'],ENT_QUOTES)."'";
56
57  $query.= ', comment = ';
58  if ($_POST['comment'] == '')
59    $query.= 'NULL';
60  else
61    $query.= "'".htmlentities($_POST['comment'],ENT_QUOTES)."'";
62
63  $query.= ', date_creation = ';
64  if (!empty($_POST['date_creation']))
65    $query.= "'".date_convert($_POST['date_creation'])."'";
66  else if ($_POST['date_creation'] == '')
67    $query.= 'NULL';
68
69  $query.= ', keywords = ';
70  $keywords_array = get_keywords($_POST['keywords']);
71  if (count($keywords_array) == 0)
72    $query.= 'NULL';
73  else
74  {
75    $query.= "'";
76    foreach ($keywords_array as $i => $keyword) {
77      if ($i > 0) $query.= ',';
78      $query.= $keyword;
79    }
80    $query.= "'";
81  }
82
83  $query.= ' WHERE id = '.$_GET['image_id'];
84  $query.= ';';
85  pwg_query($query);
86}
87// associate the element to other categories than its storage category
88if (isset($_POST['associate'])
89    and isset($_POST['cat_dissociated'])
90    and count($_POST['cat_dissociated']) > 0)
91{
92  $datas = array();
93  foreach ($_POST['cat_dissociated'] as $category_id)
94  {
95    array_push($datas, array('image_id' => $_GET['image_id'],
96                             'category_id' => $category_id));
97  }
98  mass_inserts(IMAGE_CATEGORY_TABLE, array('image_id', 'category_id'), $datas);
99
100  update_category($_POST['cat_dissociated']);
101}
102// dissociate the element from categories (but not from its storage category)
103if (isset($_POST['dissociate'])
104    and isset($_POST['cat_associated'])
105    and count($_POST['cat_associated']) > 0)
106{
107  $query = '
108DELETE FROM '.IMAGE_CATEGORY_TABLE.'
109  WHERE image_id = '.$_GET['image_id'].'
110    AND category_id IN ('.implode(',',$_POST['cat_associated'] ).')
111';
112  pwg_query($query);
113  update_category($_POST['cat_associated']);
114}
115// elect the element to represent the given categories
116if (isset($_POST['elect'])
117    and isset($_POST['cat_dismissed'])
118    and count($_POST['cat_dismissed']) > 0)
119{
120  $datas = array();
121  foreach ($_POST['cat_dismissed'] as $category_id)
122  {
123    array_push($datas,
124               array('id' => $category_id,
125                     'representative_picture_id' => $_GET['image_id']));
126  }
127  $fields = array('primary' => array('id'),
128                  'update' => array('representative_picture_id'));
129  mass_updates(CATEGORIES_TABLE, $fields, $datas);
130}
131// dismiss the element as representant of the given categories
132if (isset($_POST['dismiss'])
133    and isset($_POST['cat_elected'])
134    and count($_POST['cat_elected']) > 0)
135{
136  set_random_representant($_POST['cat_elected']);
137}
138
139// retrieving direct information about picture
140$query = '
141SELECT i.*, c.uppercats
142  FROM '.IMAGES_TABLE.' AS i
143   INNER JOIN '.CATEGORIES_TABLE.' AS c ON i.storage_category_id = c.id
144  WHERE i.id = '.$_GET['image_id'].'
145;';
146$row = mysql_fetch_array(pwg_query($query));
147
148$storage_category_id = $row['storage_category_id'];
149
150if (empty($row['name']))
151{
152  $title = str_replace('_', ' ',get_filename_wo_extension($row['file']));
153}
154else
155{
156  $title = $row['name'];
157}
158// Navigation path
159$thumbnail_url = get_thumbnail_src($row['path'], @$row['tn_ext']);
160
161$url_img = PHPWG_ROOT_PATH.'picture.php?image_id='.$_GET['image_id'];
162$url_img .= '&amp;cat='.$row['storage_category_id'];
163$date = isset($_POST['date_creation']) && empty($errors)
164?$_POST['date_creation']:date_convert_back(@$row['date_creation']);
165
166$url = PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id=';
167$storage_category = get_cat_display_name_cache($row['uppercats'],
168                                               $url,
169                                               false);
170//----------------------------------------------------- template initialization
171$template->set_filenames(array('picture_modify'=>'admin/picture_modify.tpl'));
172$template->assign_vars(array(
173  'TITLE_IMG'=>$title,
174  'STORAGE_CATEGORY_IMG'=>$storage_category,
175  'PATH_IMG'=>$row['path'],
176  'FILE_IMG'=>$row['file'],
177  'TN_URL_IMG'=>$thumbnail_url,
178  'URL_IMG'=>add_session_id($url_img),
179  'DEFAULT_NAME_IMG'=>str_replace('_',' ',get_filename_wo_extension($row['file'])),
180  'FILE_IMG'=>$row['file'],
181  'NAME_IMG'=>isset($_POST['name'])?$_POST['name']:@$row['name'],
182  'SIZE_IMG'=>@$row['width'].' * '.@$row['height'],
183  'FILESIZE_IMG'=>@$row['filesize'].' KB',
184  'REGISTRATION_DATE_IMG'=> format_date($row['date_available']),
185  'AUTHOR_IMG'=>isset($_POST['author'])?$_POST['author']:@$row['author'],
186  'CREATION_DATE_IMG'=>$date,
187  'KEYWORDS_IMG'=>isset($_POST['keywords'])?$_POST['keywords']:@$row['keywords'],
188  'COMMENT_IMG'=>isset($_POST['comment'])?$_POST['comment']:@$row['comment'],
189 
190  'L_UPLOAD_NAME'=>$lang['upload_name'],
191  'L_DEFAULT'=>$lang['default'],
192  'L_FILE'=>$lang['file'],
193  'L_SIZE'=>$lang['size'],
194  'L_FILESIZE'=>$lang['filesize'],
195  'L_REGISTRATION_DATE'=>$lang['registration_date'],
196  'L_AUTHOR'=>$lang['author'],
197  'L_CREATION_DATE'=>$lang['creation_date'],
198  'L_KEYWORDS'=>$lang['keywords'],
199  'L_COMMENT'=>$lang['description'],
200  'L_CATEGORIES'=>$lang['categories'],
201  'L_DISSOCIATE'=>$lang['dissociate'],
202  'L_INFOIMAGE_ASSOCIATE'=>$lang['infoimage_associate'],
203  'L_SUBMIT'=>$lang['submit'],
204  'L_RESET'=>$lang['reset'],
205  'L_CAT_ASSOCIATED'=>$lang['infoimage_associated'],
206  'L_CAT_DISSOCIATED'=>$lang['infoimage_dissociated'],
207  'L_PATH'=>$lang['path'],
208  'L_STORAGE_CATEGORY'=>$lang['storage_category'],
209  'L_REPRESENTS'=>$lang['represents'],
210  'L_DOESNT_REPRESENT'=>$lang['doesnt_represent'],
211 
212  'F_ACTION'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?'.$_SERVER['QUERY_STRING'])
213 ));
214 
215//-------------------------------------------------------------- errors display
216if (count($errors) != 0)
217{
218  $template->assign_block_vars('errors',array());
219  foreach ($errors as $error)
220  {
221    $template->assign_block_vars('errors.error',array('ERROR'=>$error));
222  }
223}
224
225// associate to another category ?
226$query = '
227SELECT id,name,uppercats,global_rank
228  FROM '.CATEGORIES_TABLE.'
229    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
230  WHERE image_id = '.$_GET['image_id'].'
231    AND id != '.$storage_category_id.'
232;';
233display_select_cat_wrapper($query,array(),'associated_option');
234
235$result = pwg_query($query);
236$associateds = array($storage_category_id);
237while ($row = mysql_fetch_array($result))
238{
239  array_push($associateds, $row['id']);
240}
241$query = '
242SELECT id,name,uppercats,global_rank
243  FROM '.CATEGORIES_TABLE.'
244  WHERE id NOT IN ('.implode(',', $associateds).')
245;';
246display_select_cat_wrapper($query,array(),'dissociated_option');
247// representing
248$query = '
249SELECT id,name,uppercats,global_rank
250  FROM '.CATEGORIES_TABLE.'
251  WHERE representative_picture_id = '.$_GET['image_id'].'
252;';
253display_select_cat_wrapper($query,array(),'elected_option');
254
255$query = '
256SELECT id,name,uppercats,global_rank
257  FROM '.CATEGORIES_TABLE.'
258  WHERE id IN ('.implode(',', $associateds).')
259    AND representative_picture_id != '.$_GET['image_id'].'
260;';
261display_select_cat_wrapper($query,array(),'dismissed_option');
262//----------------------------------------------------------- sending html code
263$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
264?>
Note: See TracBrowser for help on using the repository browser.