source: trunk/admin/picture_modify.php @ 575

Last change on this file since 575 was 575, checked in by z0rglub, 20 years ago
  • refactoring
  • PHP Warnings correction
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.9 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// |                          picture_modify.php                           |
4// +-----------------------------------------------------------------------+
5// | application   : PhpWebGallery <http://phpwebgallery.net>              |
6// | branch        : BSF (Best So Far)                                     |
7// +-----------------------------------------------------------------------+
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-10-23 09:58:28 +0000 (Sat, 23 Oct 2004) $
10// | last modifier : $Author: z0rglub $
11// | revision      : $Revision: 575 $
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  mysql_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 = mysql_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      mysql_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      mysql_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(mysql_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    mysql_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 = mysql_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      mysql_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(mysql_query($query));
189
190// some fields are nullable in the images table
191$nullables = array('name','author','keywords','date_creation','comment');
192foreach ($nullables as $field)
193{
194  if (!isset($row[$field]))
195  {
196    $row[$field] = '';
197  }
198}
199
200if (empty($row['name']))
201{
202  $title = str_replace('_', ' ',get_filename_wo_extension($row['file']));
203}
204else
205{
206  $title = $row['name'];
207}
208// Navigation path
209$current_category = get_cat_info($row['storage_category_id']);
210$dir_path = get_cat_display_name($current_category['name'], '-&gt;', '');
211
212$thumbnail_url = get_complete_dir($row['storage_category_id']);
213$file_wo_ext = get_filename_wo_extension($row['file']);
214$thumbnail_url.= '/thumbnail/';
215$thumbnail_url.= $conf['prefix_thumbnail'].$file_wo_ext.'.'.$row['tn_ext'];
216$url_img = PHPWG_ROOT_PATH.'picture.php?image_id='.$_GET['image_id'];
217$url_img .= '&amp;cat='.$row['storage_category_id'];
218$date = isset($_POST['date_creation']) && empty($errors)
219          ?$_POST['date_creation']:date_convert_back($row['date_creation']);
220
221// retrieving all the linked categories
222$query = '
223SELECT DISTINCT(category_id) AS category_id,status,visible
224       ,representative_picture_id
225  FROM '.IMAGE_CATEGORY_TABLE.','.CATEGORIES_TABLE.'
226  WHERE image_id = '.$_GET['image_id'].'
227    AND category_id = id
228;';
229$result = mysql_query($query);
230$categories = '';
231while ($cat_row = mysql_fetch_array($result))
232{
233  $cat_infos = get_cat_info($cat_row['category_id']);
234  $cat_name = get_cat_display_name($cat_infos['name'], ' &gt; ', '');
235  $categories.='<option value="'.$cat_row['category_id'].'">'.$cat_name.'</option>';
236}
237
238//----------------------------------------------------- template initialization
239$template->set_filenames(array('picture_modify'=>'admin/picture_modify.tpl'));
240$template->assign_vars(array(
241  'TITLE_IMG'=>$title,
242  'DIR_IMG'=>$dir_path,
243  'FILE_IMG'=>$row['file'],
244  'TN_URL_IMG'=>$thumbnail_url,
245  'URL_IMG'=>add_session_id($url_img),
246  'DEFAULT_NAME_IMG'=>str_replace('_',' ',get_filename_wo_extension($row['file'])),
247  'FILE_IMG'=>$row['file'],
248  'NAME_IMG'=>isset($_POST['name'])?$_POST['name']:$row['name'],
249  'SIZE_IMG'=>$row['width'].' * '.$row['height'],
250  'FILESIZE_IMG'=>$row['filesize'].' KB',
251  'REGISTRATION_DATE_IMG'=> format_date($row['date_available']),
252  'AUTHOR_IMG'=>isset($_POST['author'])?$_POST['author']:$row['author'],
253  'CREATION_DATE_IMG'=>$date,
254  'KEYWORDS_IMG'=>isset($_POST['keywords'])?$_POST['keywords']:$row['keywords'],
255  'COMMENT_IMG'=>isset($_POST['comment'])?$_POST['comment']:$row['comment'],
256  'ASSOCIATED_CATEGORIES'=>$categories,
257 
258  'L_UPLOAD_NAME'=>$lang['upload_name'],
259  'L_DEFAULT'=>$lang['default'],
260  'L_FILE'=>$lang['file'],
261  'L_SIZE'=>$lang['size'],
262  'L_FILESIZE'=>$lang['filesize'],
263  'L_REGISTRATION_DATE'=>$lang['registration_date'],
264  'L_AUTHOR'=>$lang['author'],
265  'L_CREATION_DATE'=>$lang['creation_date'],
266  'L_KEYWORDS'=>$lang['keywords'],
267  'L_COMMENT'=>$lang['comment'],
268  'L_CATEGORIES'=>$lang['categories'],
269  'L_DISSOCIATE'=>$lang['dissociate'],
270  'L_INFOIMAGE_ASSOCIATE'=>$lang['infoimage_associate'],
271  'L_SUBMIT'=>$lang['submit'],
272 
273  'F_ACTION'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?'.$_SERVER['QUERY_STRING'])
274 ));
275 
276//-------------------------------------------------------------- errors display
277if (sizeof($errors) != 0)
278{
279  $template->assign_block_vars('errors',array());
280  for ($i = 0; $i < sizeof($errors); $i++)
281  {
282    $template->assign_block_vars('errors.error',array('ERROR'=>$errors[$i]));
283  }
284}
285
286// if there are linked category other than the storage category, we show
287// propose the dissociate text
288if (mysql_num_rows($result) > 0)
289{
290  //$vtp->addSession($sub, 'dissociate');
291  //$vtp->closeSession($sub, 'dissociate');
292}
293// associate to another category ?
294//
295// We only show a List Of Values if the number of categories is less than
296// $conf['max_LOV_categories']
297$query = 'SELECT COUNT(id) AS nb_total_categories';
298$query.= ' FROM '.CATEGORIES_TABLE.';';
299$row = mysql_fetch_array(mysql_query($query));
300if ($row['nb_total_categories'] < $conf['max_LOV_categories'])
301{
302  $template->assign_block_vars('associate_LOV',array());
303  $template->assign_block_vars('associate_LOV.associate_cat',array(
304        ));
305  /*$vtp->addSession($sub, 'associate_LOV');
306  $vtp->addSession($sub, 'associate_cat');
307  $vtp->setVar($sub, 'associate_cat.value', '-1');
308  $vtp->setVar($sub, 'associate_cat.content', '');
309  $vtp->closeSession($sub, 'associate_cat');
310  $page['plain_structure'] = get_plain_structure(true);
311  $structure = create_structure('', array());
312  display_categories($structure, '&nbsp;');
313  $vtp->closeSession($sub, 'associate_LOV');*/
314}
315
316//----------------------------------------------------------- sending html code
317$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
318?>
Note: See TracBrowser for help on using the repository browser.