source: trunk/admin/picture_modify.php @ 606

Last change on this file since 606 was 606, checked in by plg, 19 years ago
  • images.path column added to reduce database access
  • function mass_inserts moved from admin/remote_sites.php to admin/include/function.php
  • function mass_inserts used in admin/update.php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.4 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-2004 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-11-16 23:38:34 +0000 (Tue, 16 Nov 2004) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 606 $
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']))
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 (check_date_format($_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  // make the picture representative of a category ?
87  $query = '
88SELECT DISTINCT(category_id) as category_id,representative_picture_id
89  FROM '.IMAGE_CATEGORY_TABLE.' AS ic, '.CATEGORIES_TABLE.' AS c
90  WHERE c.id = ic.category_id
91    AND image_id = '.$_GET['image_id'].'
92;';
93  $result = pwg_query($query);
94  while ($row = mysql_fetch_array($result))
95  {
96    // if the user ask the picture to be the representative picture of its
97    // category, the category is updated in the database (without wondering
98    // if this picture was already the representative one)
99    if (isset($_POST['representative-'.$row['category_id']]))
100    {
101      $query = 'UPDATE '.CATEGORIES_TABLE;
102      $query.= ' SET representative_picture_id = '.$_GET['image_id'];
103      $query.= ' WHERE id = '.$row['category_id'];
104      $query.= ';';
105      pwg_query($query);
106    }
107    // if the user ask this picture to be not any more the representative,
108    // we have to set the representative_picture_id of this category to NULL
109    else if (isset($row['representative_picture_id'])
110             and $row['representative_picture_id'] == $_GET['image_id'])
111    {
112      $query = '
113UPDATE '.CATEGORIES_TABLE.'
114  SET representative_picture_id = NULL
115  WHERE id = '.$row['category_id'].'
116;';
117      pwg_query($query);
118    }
119  }
120  $associate_or_dissociate = false;
121  // associate with a new category ?
122  if ($_POST['associate'] != '-1' and $_POST['associate'] != '')
123  {
124    // does the uppercat id exists in the database ?
125    if (!is_numeric($_POST['associate']))
126    {
127      array_push($errors, $lang['cat_unknown_id']);
128    }
129    else
130    {
131      $query = '
132SELECT id
133  FROM '.CATEGORIES_TABLE.'
134  WHERE id = '.$_POST['associate'].'
135;';
136      if (mysql_num_rows(pwg_query($query)) == 0)
137        array_push($errors, $lang['cat_unknown_id']);
138    }
139  }
140  if ($_POST['associate'] != '-1'
141       and $_POST['associate'] != ''
142       and count($errors) == 0)
143  {
144    $query = '
145INSERT INTO '.IMAGE_CATEGORY_TABLE.'
146  (category_id,image_id)
147  VALUES
148  ('.$_POST['associate'].','.$_GET['image_id'].')
149;';
150    pwg_query($query);
151    $associate_or_dissociate = true;
152    update_category($_POST['associate']);
153  }
154  // dissociate any category ?
155  // retrieving all the linked categories
156  $query = '
157SELECT DISTINCT(category_id) as category_id
158  FROM '.IMAGE_CATEGORY_TABLE.'
159  WHERE image_id = '.$_GET['image_id'].'
160;';
161  $result = pwg_query($query);
162  while ($row = mysql_fetch_array($result))
163  {
164    if (isset($_POST['dissociate-'.$row['category_id']]))
165    {
166      $query = '
167DELETE FROM '.IMAGE_CATEGORY_TABLE.'
168  WHERE image_id = '.$_GET['image_id'].'
169  AND category_id = '.$row['category_id'].'
170;';
171      pwg_query($query);
172      $associate_or_dissociate = true;
173      update_category($row['category_id']);
174    }
175  }
176  if ($associate_or_dissociate)
177  {
178    synchronize_all_users();
179  }
180}
181
182// retrieving direct information about picture
183$query = '
184SELECT *
185  FROM '.IMAGES_TABLE.'
186  WHERE id = '.$_GET['image_id'].'
187;';
188$row = mysql_fetch_array(pwg_query($query));
189
190if (empty($row['name']))
191{
192  $title = str_replace('_', ' ',get_filename_wo_extension($row['file']));
193}
194else
195{
196  $title = $row['name'];
197}
198// Navigation path
199$current_category = get_cat_info($row['storage_category_id']);
200$dir_path = get_cat_display_name($current_category['name'], '-&gt;', '');
201
202$thumbnail_url = get_thumbnail_src($row['path'], @$row['tn_ext']);
203
204$url_img = PHPWG_ROOT_PATH.'picture.php?image_id='.$_GET['image_id'];
205$url_img .= '&amp;cat='.$row['storage_category_id'];
206$date = isset($_POST['date_creation']) && empty($errors)
207          ?$_POST['date_creation']:date_convert_back(@$row['date_creation']);
208
209// retrieving all the linked categories
210$query = '
211SELECT DISTINCT(category_id) AS category_id,status,visible
212       ,representative_picture_id
213  FROM '.IMAGE_CATEGORY_TABLE.','.CATEGORIES_TABLE.'
214  WHERE image_id = '.$_GET['image_id'].'
215    AND category_id = id
216;';
217$result = pwg_query($query);
218$categories = '';
219while ($cat_row = mysql_fetch_array($result))
220{
221  $cat_infos = get_cat_info($cat_row['category_id']);
222  $cat_name = get_cat_display_name($cat_infos['name'], ' &gt; ', '');
223  $categories.='<option value="'.$cat_row['category_id'].'">'.$cat_name.'</option>';
224}
225
226//----------------------------------------------------- template initialization
227$template->set_filenames(array('picture_modify'=>'admin/picture_modify.tpl'));
228$template->assign_vars(array(
229  'TITLE_IMG'=>$title,
230  'DIR_IMG'=>$dir_path,
231  'FILE_IMG'=>$row['file'],
232  'TN_URL_IMG'=>$thumbnail_url,
233  'URL_IMG'=>add_session_id($url_img),
234  'DEFAULT_NAME_IMG'=>str_replace('_',' ',get_filename_wo_extension($row['file'])),
235  'FILE_IMG'=>$row['file'],
236  'NAME_IMG'=>isset($_POST['name'])?$_POST['name']:@$row['name'],
237  'SIZE_IMG'=>@$row['width'].' * '.@$row['height'],
238  'FILESIZE_IMG'=>@$row['filesize'].' KB',
239  'REGISTRATION_DATE_IMG'=> format_date($row['date_available']),
240  'AUTHOR_IMG'=>isset($_POST['author'])?$_POST['author']:@$row['author'],
241  'CREATION_DATE_IMG'=>$date,
242  'KEYWORDS_IMG'=>isset($_POST['keywords'])?$_POST['keywords']:@$row['keywords'],
243  'COMMENT_IMG'=>isset($_POST['comment'])?$_POST['comment']:@$row['comment'],
244  'ASSOCIATED_CATEGORIES'=>$categories,
245 
246  'L_UPLOAD_NAME'=>$lang['upload_name'],
247  'L_DEFAULT'=>$lang['default'],
248  'L_FILE'=>$lang['file'],
249  'L_SIZE'=>$lang['size'],
250  'L_FILESIZE'=>$lang['filesize'],
251  'L_REGISTRATION_DATE'=>$lang['registration_date'],
252  'L_AUTHOR'=>$lang['author'],
253  'L_CREATION_DATE'=>$lang['creation_date'],
254  'L_KEYWORDS'=>$lang['keywords'],
255  'L_COMMENT'=>$lang['comment'],
256  'L_CATEGORIES'=>$lang['categories'],
257  'L_DISSOCIATE'=>$lang['dissociate'],
258  'L_INFOIMAGE_ASSOCIATE'=>$lang['infoimage_associate'],
259  'L_SUBMIT'=>$lang['submit'],
260 
261  'F_ACTION'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?'.$_SERVER['QUERY_STRING'])
262 ));
263 
264//-------------------------------------------------------------- errors display
265if (sizeof($errors) != 0)
266{
267  $template->assign_block_vars('errors',array());
268  for ($i = 0; $i < sizeof($errors); $i++)
269  {
270    $template->assign_block_vars('errors.error',array('ERROR'=>$errors[$i]));
271  }
272}
273
274// if there are linked category other than the storage category, we show
275// propose the dissociate text
276if (mysql_num_rows($result) > 0)
277{
278  //$vtp->addSession($sub, 'dissociate');
279  //$vtp->closeSession($sub, 'dissociate');
280}
281// associate to another category ?
282//
283// We only show a List Of Values if the number of categories is less than
284// $conf['max_LOV_categories']
285$query = 'SELECT COUNT(id) AS nb_total_categories';
286$query.= ' FROM '.CATEGORIES_TABLE.';';
287$row = mysql_fetch_array(pwg_query($query));
288if ($row['nb_total_categories'] < $conf['max_LOV_categories'])
289{
290  $template->assign_block_vars('associate_LOV',array());
291  $template->assign_block_vars('associate_LOV.associate_cat',array(
292        ));
293  /*$vtp->addSession($sub, 'associate_LOV');
294  $vtp->addSession($sub, 'associate_cat');
295  $vtp->setVar($sub, 'associate_cat.value', '-1');
296  $vtp->setVar($sub, 'associate_cat.content', '');
297  $vtp->closeSession($sub, 'associate_cat');
298  $page['plain_structure'] = get_plain_structure(true);
299  $structure = create_structure('', array());
300  display_categories($structure, '&nbsp;');
301  $vtp->closeSession($sub, 'associate_LOV');*/
302}
303
304//----------------------------------------------------------- sending html code
305$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
306?>
Note: See TracBrowser for help on using the repository browser.