source: branches/1.4/admin/picture_modify.php @ 4975

Last change on this file since 4975 was 782, checked in by plg, 20 years ago
  • bug 110 fixed : "return to element view from element edition fails depending on permissions". Correction is partial for branch 1.4 : a linked category is randomly chosen but if no linked category is authorized for the admin user, then the link is to the storage category (which can be forbidden).
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.8 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-05-01 14:16:43 +0000 (Sun, 01 May 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 782 $
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
163$query = '
164SELECT category_id
165  FROM '.IMAGE_CATEGORY_TABLE.'
166  WHERE image_id = '.$_GET['image_id'];
167
168if (isset($user['forbidden_categories'])
169    and !empty($user['forbidden_categories']))
170{
171  $query.= '
172    AND category_id NOT IN ('.$user['forbidden_categories'].')';
173}
174$query.= '
175  ORDER BY RAND()
176;';
177$result = pwg_query($query);
178
179if (mysql_num_rows($result) > 0)
180{
181  list($category_id) = mysql_fetch_array($result);
182  $url_img .= '&amp;cat='.$category_id;
183}
184else
185{
186  $url_img .= '&amp;cat='.$row['storage_category_id'];
187}
188
189$date = isset($_POST['date_creation']) && empty($errors)
190?$_POST['date_creation']:date_convert_back(@$row['date_creation']);
191
192$url = PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id=';
193$storage_category = get_cat_display_name_cache($row['uppercats'],
194                                               $url,
195                                               false);
196//----------------------------------------------------- template initialization
197$template->set_filenames(array('picture_modify'=>'admin/picture_modify.tpl'));
198$template->assign_vars(array(
199  'TITLE_IMG'=>$title,
200  'STORAGE_CATEGORY_IMG'=>$storage_category,
201  'PATH_IMG'=>$row['path'],
202  'FILE_IMG'=>$row['file'],
203  'TN_URL_IMG'=>$thumbnail_url,
204  'URL_IMG'=>add_session_id($url_img),
205  'DEFAULT_NAME_IMG'=>str_replace('_',' ',get_filename_wo_extension($row['file'])),
206  'FILE_IMG'=>$row['file'],
207  'NAME_IMG'=>isset($_POST['name'])?$_POST['name']:@$row['name'],
208  'SIZE_IMG'=>@$row['width'].' * '.@$row['height'],
209  'FILESIZE_IMG'=>@$row['filesize'].' KB',
210  'REGISTRATION_DATE_IMG'=> format_date($row['date_available']),
211  'AUTHOR_IMG'=>isset($_POST['author'])?$_POST['author']:@$row['author'],
212  'CREATION_DATE_IMG'=>$date,
213  'KEYWORDS_IMG'=>isset($_POST['keywords'])?$_POST['keywords']:@$row['keywords'],
214  'COMMENT_IMG'=>isset($_POST['comment'])?$_POST['comment']:@$row['comment'],
215 
216  'L_UPLOAD_NAME'=>$lang['upload_name'],
217  'L_DEFAULT'=>$lang['default'],
218  'L_FILE'=>$lang['file'],
219  'L_SIZE'=>$lang['size'],
220  'L_FILESIZE'=>$lang['filesize'],
221  'L_REGISTRATION_DATE'=>$lang['registration_date'],
222  'L_AUTHOR'=>$lang['author'],
223  'L_CREATION_DATE'=>$lang['creation_date'],
224  'L_KEYWORDS'=>$lang['keywords'],
225  'L_COMMENT'=>$lang['description'],
226  'L_CATEGORIES'=>$lang['categories'],
227  'L_DISSOCIATE'=>$lang['dissociate'],
228  'L_INFOIMAGE_ASSOCIATE'=>$lang['infoimage_associate'],
229  'L_SUBMIT'=>$lang['submit'],
230  'L_RESET'=>$lang['reset'],
231  'L_CAT_ASSOCIATED'=>$lang['infoimage_associated'],
232  'L_CAT_DISSOCIATED'=>$lang['infoimage_dissociated'],
233  'L_PATH'=>$lang['path'],
234  'L_STORAGE_CATEGORY'=>$lang['storage_category'],
235  'L_REPRESENTS'=>$lang['represents'],
236  'L_DOESNT_REPRESENT'=>$lang['doesnt_represent'],
237 
238  'F_ACTION'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?'.$_SERVER['QUERY_STRING'])
239 ));
240 
241//-------------------------------------------------------------- errors display
242if (count($errors) != 0)
243{
244  $template->assign_block_vars('errors',array());
245  foreach ($errors as $error)
246  {
247    $template->assign_block_vars('errors.error',array('ERROR'=>$error));
248  }
249}
250
251// associate to another category ?
252$query = '
253SELECT id,name,uppercats,global_rank
254  FROM '.CATEGORIES_TABLE.'
255    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
256  WHERE image_id = '.$_GET['image_id'].'
257    AND id != '.$storage_category_id.'
258;';
259display_select_cat_wrapper($query,array(),'associated_option');
260
261$result = pwg_query($query);
262$associateds = array($storage_category_id);
263while ($row = mysql_fetch_array($result))
264{
265  array_push($associateds, $row['id']);
266}
267$query = '
268SELECT id,name,uppercats,global_rank
269  FROM '.CATEGORIES_TABLE.'
270  WHERE id NOT IN ('.implode(',', $associateds).')
271;';
272display_select_cat_wrapper($query,array(),'dissociated_option');
273// representing
274$query = '
275SELECT id,name,uppercats,global_rank
276  FROM '.CATEGORIES_TABLE.'
277  WHERE representative_picture_id = '.$_GET['image_id'].'
278;';
279display_select_cat_wrapper($query,array(),'elected_option');
280
281$query = '
282SELECT id,name,uppercats,global_rank
283  FROM '.CATEGORIES_TABLE.'
284  WHERE id IN ('.implode(',', $associateds).')
285    AND representative_picture_id != '.$_GET['image_id'].'
286;';
287display_select_cat_wrapper($query,array(),'dismissed_option');
288//----------------------------------------------------------- sending html code
289$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
290?>
Note: See TracBrowser for help on using the repository browser.