source: trunk/admin/picture_modify.php @ 635

Last change on this file since 635 was 635, checked in by plg, 19 years ago
  • on picture.php, related categories under the element are displayed in global_rank order
  • when adding a new virtual category, initializes its global_rank
  • bug fixed : in admin/cat_list, false next rank
  • in admin/cat_modify, complete directory is calculated only if category is not virtual
  • admin/picture_modify rewritten : graphically nearer to admin/cat_modify, virtual associations are back
  • update_category partially rewritten : take an array of categories in parameter, becomes optionnaly recursive, use the set_random_representant function, set a random representant for categories with elements and no representant
  • bug fixed : on a search results screen, elements belonging to more than 1 category were shown more than once
  • bug fixed : in admin/cat_modify, changing a value in a textefield and hitting enter was setting a new random representant
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.0 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-12-05 21:28:40 +0000 (Sun, 05 Dec 2004) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 635 $
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}
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
116// retrieving direct information about picture
117$query = '
118SELECT i.*, c.uppercats
119  FROM '.IMAGES_TABLE.' AS i
120   INNER JOIN '.CATEGORIES_TABLE.' AS c ON i.storage_category_id = c.id
121  WHERE i.id = '.$_GET['image_id'].'
122;';
123$row = mysql_fetch_array(pwg_query($query));
124
125$storage_category_id = $row['storage_category_id'];
126
127if (empty($row['name']))
128{
129  $title = str_replace('_', ' ',get_filename_wo_extension($row['file']));
130}
131else
132{
133  $title = $row['name'];
134}
135// Navigation path
136$thumbnail_url = get_thumbnail_src($row['path'], @$row['tn_ext']);
137
138$url_img = PHPWG_ROOT_PATH.'picture.php?image_id='.$_GET['image_id'];
139$url_img .= '&amp;cat='.$row['storage_category_id'];
140$date = isset($_POST['date_creation']) && empty($errors)
141?$_POST['date_creation']:date_convert_back(@$row['date_creation']);
142         
143$storage_category = get_cat_display_name_cache($row['uppercats'],
144                                               ' &rarr; ',
145                                               '',
146                                               false);
147//----------------------------------------------------- template initialization
148$template->set_filenames(array('picture_modify'=>'admin/picture_modify.tpl'));
149$template->assign_vars(array(
150  'TITLE_IMG'=>$title,
151  'STORAGE_CATEGORY_IMG'=>$storage_category,
152  'PATH_IMG'=>$row['path'],
153  'FILE_IMG'=>$row['file'],
154  'TN_URL_IMG'=>$thumbnail_url,
155  'URL_IMG'=>add_session_id($url_img),
156  'DEFAULT_NAME_IMG'=>str_replace('_',' ',get_filename_wo_extension($row['file'])),
157  'FILE_IMG'=>$row['file'],
158  'NAME_IMG'=>isset($_POST['name'])?$_POST['name']:@$row['name'],
159  'SIZE_IMG'=>@$row['width'].' * '.@$row['height'],
160  'FILESIZE_IMG'=>@$row['filesize'].' KB',
161  'REGISTRATION_DATE_IMG'=> format_date($row['date_available']),
162  'AUTHOR_IMG'=>isset($_POST['author'])?$_POST['author']:@$row['author'],
163  'CREATION_DATE_IMG'=>$date,
164  'KEYWORDS_IMG'=>isset($_POST['keywords'])?$_POST['keywords']:@$row['keywords'],
165  'COMMENT_IMG'=>isset($_POST['comment'])?$_POST['comment']:@$row['comment'],
166 
167  'L_UPLOAD_NAME'=>$lang['upload_name'],
168  'L_DEFAULT'=>$lang['default'],
169  'L_FILE'=>$lang['file'],
170  'L_SIZE'=>$lang['size'],
171  'L_FILESIZE'=>$lang['filesize'],
172  'L_REGISTRATION_DATE'=>$lang['registration_date'],
173  'L_AUTHOR'=>$lang['author'],
174  'L_CREATION_DATE'=>$lang['creation_date'],
175  'L_KEYWORDS'=>$lang['keywords'],
176  'L_COMMENT'=>$lang['comment'],
177  'L_CATEGORIES'=>$lang['categories'],
178  'L_DISSOCIATE'=>$lang['dissociate'],
179  'L_INFOIMAGE_ASSOCIATE'=>$lang['infoimage_associate'],
180  'L_SUBMIT'=>$lang['submit'],
181  'L_RESET'=>$lang['reset'],
182  'L_CAT_ASSOCIATED'=>$lang['cat_associated'],
183  'L_CAT_DISSOCIATED'=>$lang['cat_dissociated'],
184  'L_PATH'=>$lang['path'],
185  'L_STORAGE_CATEGORY'=>$lang['storage_category'],
186 
187  'F_ACTION'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?'.$_SERVER['QUERY_STRING'])
188 ));
189 
190//-------------------------------------------------------------- errors display
191if (count($errors) != 0)
192{
193  $template->assign_block_vars('errors',array());
194  foreach ($errors as $error)
195  {
196    $template->assign_block_vars('errors.error',array('ERROR'=>$error));
197  }
198}
199
200// associate to another category ?
201$query = '
202SELECT id,name,uppercats,global_rank
203  FROM '.CATEGORIES_TABLE.'
204    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
205  WHERE image_id = '.$_GET['image_id'].'
206    AND id != '.$storage_category_id.'
207;';
208display_select_cat_wrapper($query,array(),'associated_option');
209
210$result = pwg_query($query);
211$associateds = array($storage_category_id);
212while ($row = mysql_fetch_array($result))
213{
214  array_push($associateds, $row['id']);
215}
216$query = '
217SELECT id,name,uppercats,global_rank
218  FROM '.CATEGORIES_TABLE.'
219  WHERE id NOT IN ('.implode(',', $associateds).')
220;';
221display_select_cat_wrapper($query,array(),'dissociated_option');
222//----------------------------------------------------------- sending html code
223$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
224?>
Note: See TracBrowser for help on using the repository browser.