source: trunk/admin/picture_modify.php @ 792

Last change on this file since 792 was 792, checked in by plg, 19 years ago
  • errors and informations boxes : management centralized in admin.php, $errors and $infos arrays replaced by $pageerrors and $pageinfos, special management for admin/update.php (more complex management)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.1 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-06-11 14:10:04 +0000 (Sat, 11 Jun 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 792 $
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// first, we verify whether there is a mistake on the given creation date
35if (isset($_POST['date_creation']) and !empty($_POST['date_creation']))
36{
37  if (!check_date_format($_POST['date_creation']))
38  {
39    array_push($page['errors'], $lang['err_date']);
40  }
41}
42if (isset($_POST['submit']) and count($page['errors']) == 0)
43{
44  $query = 'UPDATE '.IMAGES_TABLE.' SET name = ';
45  if ($_POST['name'] == '')
46    $query.= 'NULL';
47  else
48    $query.= "'".htmlentities($_POST['name'], ENT_QUOTES)."'";
49 
50  $query.= ', author = ';
51  if ($_POST['author'] == '')
52    $query.= 'NULL';
53  else
54    $query.= "'".htmlentities($_POST['author'],ENT_QUOTES)."'";
55
56  $query.= ', comment = ';
57  if ($_POST['comment'] == '')
58    $query.= 'NULL';
59  else
60    $query.= "'".htmlentities($_POST['comment'],ENT_QUOTES)."'";
61
62  $query.= ', date_creation = ';
63  if (!empty($_POST['date_creation']))
64    $query.= "'".date_convert($_POST['date_creation'])."'";
65  else if ($_POST['date_creation'] == '')
66    $query.= 'NULL';
67
68  $query.= ', keywords = ';
69  $keywords_array = get_keywords($_POST['keywords']);
70  if (count($keywords_array) == 0)
71    $query.= 'NULL';
72  else
73  {
74    $query.= "'";
75    foreach ($keywords_array as $i => $keyword) {
76      if ($i > 0) $query.= ',';
77      $query.= $keyword;
78    }
79    $query.= "'";
80  }
81
82  $query.= ' WHERE id = '.$_GET['image_id'];
83  $query.= ';';
84  pwg_query($query);
85}
86// associate the element to other categories than its storage category
87if (isset($_POST['associate'])
88    and isset($_POST['cat_dissociated'])
89    and count($_POST['cat_dissociated']) > 0)
90{
91  $datas = array();
92  foreach ($_POST['cat_dissociated'] as $category_id)
93  {
94    array_push($datas, array('image_id' => $_GET['image_id'],
95                             'category_id' => $category_id));
96  }
97  mass_inserts(IMAGE_CATEGORY_TABLE, array('image_id', 'category_id'), $datas);
98
99  update_category($_POST['cat_dissociated']);
100}
101// dissociate the element from categories (but not from its storage category)
102if (isset($_POST['dissociate'])
103    and isset($_POST['cat_associated'])
104    and count($_POST['cat_associated']) > 0)
105{
106  $query = '
107DELETE FROM '.IMAGE_CATEGORY_TABLE.'
108  WHERE image_id = '.$_GET['image_id'].'
109    AND category_id IN ('.implode(',',$_POST['cat_associated'] ).')
110';
111  pwg_query($query);
112  update_category($_POST['cat_associated']);
113}
114// elect the element to represent the given categories
115if (isset($_POST['elect'])
116    and isset($_POST['cat_dismissed'])
117    and count($_POST['cat_dismissed']) > 0)
118{
119  $datas = array();
120  foreach ($_POST['cat_dismissed'] as $category_id)
121  {
122    array_push($datas,
123               array('id' => $category_id,
124                     'representative_picture_id' => $_GET['image_id']));
125  }
126  $fields = array('primary' => array('id'),
127                  'update' => array('representative_picture_id'));
128  mass_updates(CATEGORIES_TABLE, $fields, $datas);
129}
130// dismiss the element as representant of the given categories
131if (isset($_POST['dismiss'])
132    and isset($_POST['cat_elected'])
133    and count($_POST['cat_elected']) > 0)
134{
135  set_random_representant($_POST['cat_elected']);
136}
137
138// retrieving direct information about picture
139$query = '
140SELECT i.*, c.uppercats
141  FROM '.IMAGES_TABLE.' AS i
142   INNER JOIN '.CATEGORIES_TABLE.' AS c ON i.storage_category_id = c.id
143  WHERE i.id = '.$_GET['image_id'].'
144;';
145$row = mysql_fetch_array(pwg_query($query));
146
147$storage_category_id = $row['storage_category_id'];
148
149if (empty($row['name']))
150{
151  $title = str_replace('_', ' ',get_filename_wo_extension($row['file']));
152}
153else
154{
155  $title = $row['name'];
156}
157// Navigation path
158$thumbnail_url = get_thumbnail_src($row['path'], @$row['tn_ext']);
159
160$url_img = PHPWG_ROOT_PATH.'picture.php?image_id='.$_GET['image_id'];
161$url_img .= '&amp;cat='.$row['storage_category_id'];
162$date = isset($_POST['date_creation']) && empty($page['errors'])
163?$_POST['date_creation']:date_convert_back(@$row['date_creation']);
164
165$url = PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id=';
166$storage_category = get_cat_display_name_cache($row['uppercats'],
167                                               $url,
168                                               false);
169//----------------------------------------------------- template initialization
170$template->set_filenames(array('picture_modify'=>'admin/picture_modify.tpl'));
171$template->assign_vars(array(
172  'TITLE_IMG'=>$title,
173  'STORAGE_CATEGORY_IMG'=>$storage_category,
174  'PATH_IMG'=>$row['path'],
175  'FILE_IMG'=>$row['file'],
176  'TN_URL_IMG'=>$thumbnail_url,
177  'URL_IMG'=>add_session_id($url_img),
178  'DEFAULT_NAME_IMG'=>str_replace('_',' ',get_filename_wo_extension($row['file'])),
179  'FILE_IMG'=>$row['file'],
180  'NAME_IMG'=>isset($_POST['name'])?$_POST['name']:@$row['name'],
181  'SIZE_IMG'=>@$row['width'].' * '.@$row['height'],
182  'FILESIZE_IMG'=>@$row['filesize'].' KB',
183  'REGISTRATION_DATE_IMG'=> format_date($row['date_available']),
184  'AUTHOR_IMG'=>isset($_POST['author'])?$_POST['author']:@$row['author'],
185  'CREATION_DATE_IMG'=>$date,
186  'KEYWORDS_IMG'=>isset($_POST['keywords'])?$_POST['keywords']:@$row['keywords'],
187  'COMMENT_IMG'=>isset($_POST['comment'])?$_POST['comment']:@$row['comment'],
188 
189  'L_UPLOAD_NAME'=>$lang['upload_name'],
190  'L_DEFAULT'=>$lang['default'],
191  'L_FILE'=>$lang['file'],
192  'L_SIZE'=>$lang['size'],
193  'L_FILESIZE'=>$lang['filesize'],
194  'L_REGISTRATION_DATE'=>$lang['registration_date'],
195  'L_AUTHOR'=>$lang['author'],
196  'L_CREATION_DATE'=>$lang['creation_date'],
197  'L_KEYWORDS'=>$lang['keywords'],
198  'L_COMMENT'=>$lang['description'],
199  'L_CATEGORIES'=>$lang['categories'],
200  'L_DISSOCIATE'=>$lang['dissociate'],
201  'L_INFOIMAGE_ASSOCIATE'=>$lang['infoimage_associate'],
202  'L_SUBMIT'=>$lang['submit'],
203  'L_RESET'=>$lang['reset'],
204  'L_CAT_ASSOCIATED'=>$lang['infoimage_associated'],
205  'L_CAT_DISSOCIATED'=>$lang['infoimage_dissociated'],
206  'L_PATH'=>$lang['path'],
207  'L_STORAGE_CATEGORY'=>$lang['storage_category'],
208  'L_REPRESENTS'=>$lang['represents'],
209  'L_DOESNT_REPRESENT'=>$lang['doesnt_represent'],
210 
211  'F_ACTION'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?'.$_SERVER['QUERY_STRING'])
212 ));
213 
214// associate to another category ?
215$query = '
216SELECT id,name,uppercats,global_rank
217  FROM '.CATEGORIES_TABLE.'
218    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
219  WHERE image_id = '.$_GET['image_id'].'
220    AND id != '.$storage_category_id.'
221;';
222display_select_cat_wrapper($query,array(),'associated_option');
223
224$result = pwg_query($query);
225$associateds = array($storage_category_id);
226while ($row = mysql_fetch_array($result))
227{
228  array_push($associateds, $row['id']);
229}
230$query = '
231SELECT id,name,uppercats,global_rank
232  FROM '.CATEGORIES_TABLE.'
233  WHERE id NOT IN ('.implode(',', $associateds).')
234;';
235display_select_cat_wrapper($query,array(),'dissociated_option');
236// representing
237$query = '
238SELECT id,name,uppercats,global_rank
239  FROM '.CATEGORIES_TABLE.'
240  WHERE representative_picture_id = '.$_GET['image_id'].'
241;';
242display_select_cat_wrapper($query,array(),'elected_option');
243
244$query = '
245SELECT id,name,uppercats,global_rank
246  FROM '.CATEGORIES_TABLE.'
247  WHERE id IN ('.implode(',', $associateds).')
248    AND representative_picture_id != '.$_GET['image_id'].'
249;';
250display_select_cat_wrapper($query,array(),'dismissed_option');
251//----------------------------------------------------------- sending html code
252$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
253?>
Note: See TracBrowser for help on using the repository browser.