source: trunk/admin/picture_modify.php @ 362

Last change on this file since 362 was 362, checked in by z0rglub, 20 years ago

header global refactoring

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.5 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-02-11 23:20:38 +0000 (Wed, 11 Feb 2004) $
10// | last modifier : $Author: z0rglub $
11// | revision      : $Revision: 362 $
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
28include_once( './admin/include/isadmin.inc.php' );
29//--------------------------------------------------------- update informations
30$errors = array();
31// first, we verify whether there is a mistake on the given creation date
32if ( isset( $_POST['creation_date'] ) and $_POST['creation_date'] != '' )
33{
34  if ( !check_date_format( $_POST['creation_date'] ) )
35    array_push( $errors, $lang['err_date'] );
36}
37if ( isset( $_POST['submit'] ) )
38{
39  $query = 'UPDATE '.PREFIX_TABLE.'images';
40 
41  $query.= ' SET name = ';
42  if ( $_POST['name'] == '' )
43    $query.= 'NULL';
44  else
45    $query.= "'".htmlentities( $_POST['name'], ENT_QUOTES )."'";
46 
47  $query.= ', author = ';
48  if ( $_POST['author'] == '' )
49    $query.= 'NULL';
50  else
51    $query.= "'".htmlentities($_POST['author'],ENT_QUOTES)."'";
52
53  $query.= ', comment = ';
54  if ( $_POST['comment'] == '' )
55    $query.= 'NULL';
56  else
57    $query.= "'".htmlentities($_POST['comment'],ENT_QUOTES)."'";
58
59  $query.= ', date_creation = ';
60  if ( check_date_format( $_POST['creation_date'] ) )
61    $query.= "'".date_convert( $_POST['creation_date'] )."'";
62  else if ( $_POST['creation_date'] == '' )
63    $query.= 'NULL';
64
65  $query.= ', keywords = ';
66  $keywords_array = get_keywords( $_POST['keywords'] );
67  if ( count( $keywords_array ) == 0 )
68    $query.= 'NULL';
69  else
70  {
71    $query.= "'";
72    foreach ( $keywords_array as $i => $keyword ) {
73      if ( $i > 0 ) $query.= ',';
74      $query.= $keyword;
75    }
76    $query.= "'";
77  }
78
79  $query.= ' WHERE id = '.$_GET['image_id'];
80  $query.= ';';
81  mysql_query( $query );
82  // make the picture representative of a category ?
83  $query = 'SELECT DISTINCT(category_id) as category_id';
84  $query.= ',representative_picture_id';
85  $query.= ' FROM '.PREFIX_TABLE.'image_category AS ic';
86  $query.= ', '.PREFIX_TABLE.'categories AS c';
87  $query.= ' WHERE c.id = ic.category_id';
88  $query.= ' AND image_id = '.$_GET['image_id'];
89  $query.= ';';
90  $result = mysql_query( $query );
91  while ( $row = mysql_fetch_array( $result ) )
92  {
93    // if the user ask the picture to be the representative picture of its
94    // category, the category is updated in the database (without wondering
95    // if this picture was already the representative one)
96    if ( isset($_POST['representative-'.$row['category_id']]) )
97    {
98      $query = 'UPDATE '.PREFIX_TABLE.'categories';
99      $query.= ' SET representative_picture_id = '.$_GET['image_id'];
100      $query.= ' WHERE id = '.$row['category_id'];
101      $query.= ';';
102      mysql_query( $query );
103    }
104    // if the user ask this picture to be not any more the representative,
105    // we have to set the representative_picture_id of this category to NULL
106    else if ( isset( $row['representative_picture_id'] )
107              and $row['representative_picture_id'] == $_GET['image_id'] )
108    {
109      $query = 'UPDATE '.PREFIX_TABLE.'categories';
110      $query.= ' SET representative_picture_id = NULL';
111      $query.= ' WHERE id = '.$row['category_id'];
112      $query.= ';';
113      mysql_query( $query );
114    }
115  }
116  $associate_or_dissociate = false;
117  // associate with a new category ?
118  if ( $_POST['associate'] != '-1' and $_POST['associate'] != '' )
119  {
120    // does the uppercat id exists in the database ?
121    if ( !is_numeric( $_POST['associate'] ) )
122    {
123      array_push( $errors, $lang['cat_unknown_id'] );
124    }
125    else
126    {
127      $query = 'SELECT id';
128      $query.= ' FROM '.PREFIX_TABLE.'categories';
129      $query.= ' WHERE id = '.$_POST['associate'];
130      $query.= ';';
131      if ( mysql_num_rows( mysql_query( $query ) ) == 0 )
132        array_push( $errors, $lang['cat_unknown_id'] );
133    }
134  }
135  if ( $_POST['associate'] != '-1'
136       and $_POST['associate'] != ''
137       and count( $errors ) == 0 )
138  {
139    $query = 'INSERT INTO '.PREFIX_TABLE.'image_category';
140    $query.= ' (category_id,image_id) VALUES ';
141    $query.= '('.$_POST['associate'].','.$_GET['image_id'].')';
142    $query.= ';';
143    mysql_query( $query);
144    $associate_or_dissociate = true;
145    update_category( $_POST['associate'] );
146  }
147  // dissociate any category ?
148  // retrieving all the linked categories
149  $query = 'SELECT DISTINCT(category_id) as category_id';
150  $query.= ' FROM '.PREFIX_TABLE.'image_category';
151  $query.= ' WHERE image_id = '.$_GET['image_id'];
152  $query.= ';';
153  $result = mysql_query( $query );
154  while ( $row = mysql_fetch_array( $result ) )
155  {
156    if ( isset($_POST['dissociate-'.$row['category_id']]) )
157    {
158      $query = 'DELETE FROM '.PREFIX_TABLE.'image_category';
159      $query.= ' WHERE image_id = '.$_GET['image_id'];
160      $query.= ' AND category_id = '.$row['category_id'];
161      $query.= ';';
162      mysql_query( $query );
163      $associate_or_dissociate = true;
164      update_category( $row['category_id'] );
165    }
166  }
167  if ( $associate_or_dissociate )
168  {
169    synchronize_all_users();
170  }
171}
172//----------------------------------------------------- template initialization
173$sub = $vtp->Open(
174  './template/'.$user['template'].'/admin/picture_modify.vtp' );
175
176$tpl = array( 'submit','errors_title','picmod_update','picmod_back',
177              'default','file','size','filesize','registration_date',
178              'author','creation_date','keywords','comment', 'upload_name',
179              'dissociate','categories','infoimage_associate',
180              'cat_image_info','category_representative' );
181templatize_array( $tpl, 'lang', $sub );
182$vtp->setGlobalVar( $sub, 'user_template', $user['template'] );
183//-------------------------------------------------------------- errors display
184if ( count( $errors ) != 0 )
185{
186  $vtp->addSession( $sub, 'errors' );
187  foreach ( $errors as $error ) {
188    $vtp->addSession( $sub, 'li' );
189    $vtp->setVar( $sub, 'li.content', $error );
190    $vtp->closeSession( $sub, 'li' );
191  }
192  $vtp->closeSession( $sub, 'errors' );
193}
194//-------------------------------------------- displaying informations and form
195$action = './admin.php?'.$_SERVER['QUERY_STRING'];
196$vtp->setVar( $sub, 'form_action', $action );
197// retrieving direct information about picture
198$infos = array( 'file','date_available','date_creation','tn_ext','name'
199                ,'filesize','width','height','author','comment','keywords'
200                ,'storage_category_id' );
201$query = 'SELECT '. implode( ',', $infos );
202$query.= ' FROM '.PREFIX_TABLE.'images';
203$query.= ' WHERE id = '.$_GET['image_id'];
204$query.= ';';
205$row = mysql_fetch_array( mysql_query( $query ) );
206
207foreach ( $infos as $info ) {
208  if ( !isset( $row[$info] ) ) $row[$info] = '';
209}
210
211// picture title
212if ( $row['name'] == '' )
213{
214  $title = str_replace( '_',' ',get_filename_wo_extension($row['file']) );
215}
216else
217{
218  $title = $row['name'];
219}
220$vtp->setVar( $sub, 'title', $title );
221$vtp->setVar( $sub, 'f_file', $row['file'] );
222$vtp->setVar( $sub, 'f_size', $row['width'].' * '.$row['height'] );
223$vtp->setVar( $sub, 'f_filesize', $row['filesize'].' KB' );
224$vtp->setVar( $sub, 'f_registration_date',format_date($row['date_available']));
225$default_name = str_replace( '_',' ',get_filename_wo_extension($row['file']) );
226$vtp->setVar( $sub, 'default_name', $default_name );
227// if this form is displayed after an unsucceeded submit, we have to display
228// the values filled by the user (wright or wrong).
229if ( count( $errors ) > 0 )
230{
231  $name            = $_POST['name'];
232  $author          = $_POST['author'];
233  $creation_date   = $_POST['creation_date'];
234  $keywords        = $_POST['keywords'];
235  $comment         = $_POST['comment'];
236}
237else
238{
239  $name            = $row['name'];
240  $author          = $row['author'];
241  $creation_date   = date_convert_back( $row['date_creation'] );
242  $keywords        = $row['keywords'];
243  $comment         = $row['comment'];
244}
245$vtp->setVar( $sub, 'f_name',            $name );
246$vtp->setVar( $sub, 'f_author',          $author );
247$vtp->setVar( $sub, 'f_creation_date',   $creation_date );
248$vtp->setVar( $sub, 'f_keywords',        $keywords );
249$vtp->setVar( $sub, 'f_comment',         $comment );
250// retrieving directory where picture is stored (for displaying the
251// thumbnail)
252$thumbnail_url = get_complete_dir( $row['storage_category_id'] );
253$result = get_cat_info( $row['storage_category_id'] );
254$cat_name = get_cat_display_name( $result['name'], ' &gt; ', '' );
255$vtp->setVar( $sub, 'dir', $cat_name );
256if ( $result['site_id'] == 1 ) $thumbnail_url = '.'.$thumbnail_url;
257$file_wo_ext = get_filename_wo_extension( $row['file'] );
258$thumbnail_url.= '/thumbnail/';
259$thumbnail_url.= $conf['prefix_thumbnail'].$file_wo_ext.'.'.$row['tn_ext'];
260$vtp->setVar( $sub, 'thumbnail_url', $thumbnail_url );
261// storage category is linked by default
262$vtp->addSession( $sub, 'linked_category' );
263$vtp->setVar( $sub, 'linked_category.name', $cat_name );
264$url = '../picture.php?image_id='.$_GET['image_id'];
265$url.= '&amp;cat='.$row['storage_category_id'];
266$vtp->setVar( $sub, 'linked_category.url',add_session_id( $url));
267$url = './admin.php?page=infos_images&amp;cat_id='.$row['storage_category_id'];
268$vtp->setVar( $sub, 'linked_category.infos_images_link',add_session_id( $url));
269if ( $result['status'] == 'private' )
270{
271  $private_string = '<span style="color:red;font-weight:bold;">';
272  $private_string.= $lang['private'].'</span>';
273  $vtp->setVar( $sub, 'linked_category.private', $private_string );
274}
275if ( !$result['visible'] )
276{
277  $invisible_string = '<span style="color:red;">';
278  $invisible_string.= $lang['cat_invisible'].'</span>';
279  $vtp->setVar( $sub, 'linked_category.invisible', $invisible_string );
280}
281$vtp->setVar( $sub, 'linked_category.id', $row['storage_category_id'] );
282if ( $result['representative_picture_id'] == $_GET['image_id'] )
283{
284  $vtp->setVar( $sub, 'linked_category.representative_checked',
285                ' checked="checked"' );
286}
287$vtp->closeSession( $sub, 'linked_category' );
288// retrieving all the linked categories
289$query = 'SELECT DISTINCT(category_id) as category_id,status,visible';
290$query.= ',representative_picture_id';
291$query.= ' FROM '.PREFIX_TABLE.'image_category';
292$query.= ','.PREFIX_TABLE.'categories';
293$query.= ' WHERE image_id = '.$_GET['image_id'];
294$query.= ' AND category_id != '.$row['storage_category_id'];
295$query.= ' AND category_id = id';
296$query.= ';';
297$result = mysql_query( $query );
298while ( $row = mysql_fetch_array( $result ) )
299{
300  $vtp->addSession( $sub, 'linked_category' );
301  $vtp->setVar( $sub, 'linked_category.id', $row['category_id'] );
302
303  $vtp->addSession( $sub, 'checkbox' );
304  $vtp->setVar( $sub, 'checkbox.id', $row['category_id'] );
305  $vtp->closeSession( $sub, 'checkbox' );
306
307  $cat_infos = get_cat_info( $row['category_id'] );
308  $cat_name = get_cat_display_name( $cat_infos['name'], ' &gt; ', '' );
309  $vtp->setVar( $sub, 'linked_category.name', $cat_name );
310
311  $url = '../picture.php?image_id='.$_GET['image_id'];
312  $url.= '&amp;cat='.$row['category_id'];
313  $vtp->setVar( $sub, 'linked_category.url',add_session_id( $url));
314
315  $url = './admin.php?page=infos_images&amp;cat_id='.$row['category_id'];
316  $vtp->setVar( $sub, 'linked_category.infos_images_link',
317                add_session_id( $url));
318
319  if ( $row['status'] == 'private' )
320  {
321    $private_string = '<span style="color:red;font-weight:bold;">';
322    $private_string.= $lang['private'].'</span>';
323    $vtp->setVar( $sub, 'linked_category.private', $private_string );
324  }
325
326  if ( !get_boolean( $row['visible'] ) )
327  {
328    $invisible_string = '<span style="color:red;">';
329    $invisible_string.= $lang['cat_invisible'].'</span>';
330    $vtp->setVar( $sub, 'linked_category.invisible', $invisible_string );
331  }
332
333  if ( isset( $row['representative_picture_id'] )
334       and $row['representative_picture_id'] == $_GET['image_id'] )
335  {
336    $vtp->setVar( $sub, 'linked_category.representative_checked',
337                  ' checked="checked"' );
338  }
339 
340  $vtp->closeSession( $sub, 'linked_category' );
341}
342// if there are linked category other than the storage category, we show
343// propose the dissociate text
344if ( mysql_num_rows( $result ) > 0 )
345{
346  $vtp->addSession( $sub, 'dissociate' );
347  $vtp->closeSession( $sub, 'dissociate' );
348}
349// associate to another category ?
350//
351// We only show a List Of Values if the number of categories is less than
352// $conf['max_LOV_categories']
353$query = 'SELECT COUNT(id) AS nb_total_categories';
354$query.= ' FROM '.PREFIX_TABLE.'categories';
355$query.= ';';
356$row = mysql_fetch_array( mysql_query( $query ) );
357if ( $row['nb_total_categories'] < $conf['max_LOV_categories'] )
358{
359  $vtp->addSession( $sub, 'associate_LOV' );
360  $vtp->addSession( $sub, 'associate_cat' );
361  $vtp->setVar( $sub, 'associate_cat.value', '-1' );
362  $vtp->setVar( $sub, 'associate_cat.content', '' );
363  $vtp->closeSession( $sub, 'associate_cat' );
364  $page['plain_structure'] = get_plain_structure( true );
365  $structure = create_structure( '', array() );
366  display_categories( $structure, '&nbsp;' );
367  $vtp->closeSession( $sub, 'associate_LOV' );
368}
369// else, we only display a small text field, we suppose the administrator
370// knows the id of its category
371else
372{
373  $vtp->addSession( $sub, 'associate_text' );
374  $vtp->closeSession( $sub, 'associate_text' );
375}
376//----------------------------------------------------------- sending html code
377$vtp->Parse( $handle , 'sub', $sub );
378?>
Note: See TracBrowser for help on using the repository browser.