source: trunk/admin/picture_modify.php @ 133

Last change on this file since 133 was 133, checked in by z0rglub, 21 years ago

A category can have its representative picture

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.3 KB
Line 
1<?php
2/***************************************************************************
3 *                            picture_modify.php                           *
4 *                            ------------------                           *
5 *   application   : PhpWebGallery 1.3 <http://phpwebgallery.net>          *
6 *   author        : Pierrick LE GALL <pierrick@z0rglub.com>               *
7 *                                                                         *
8 *   $Id: picture_modify.php 133 2003-09-19 21:40:52Z z0rglub $
9 *                                                                         *
10 ***************************************************************************/
11
12/***************************************************************************
13 *                                                                         *
14 *   This program is free software; you can redistribute it and/or modify  *
15 *   it under the terms of the GNU General Public License as published by  *
16 *   the Free Software Foundation;                                         *
17 *                                                                         *
18 ***************************************************************************/
19
20include_once( './include/isadmin.inc.php' );
21//----------------------------------------- categories structure initialization
22$page['plain_structure'] = get_plain_structure();
23//--------------------------------------------------------- update informations
24$errors = array();
25// first, we verify whether there is a mistake on the given creation date
26if ( isset( $_POST['creation_date'] ) and $_POST['creation_date'] != '' )
27{
28  if ( !check_date_format( $_POST['creation_date'] ) )
29    array_push( $errors, $lang['err_date'] );
30}
31if ( isset( $_POST['submit'] ) )
32{
33  $query = 'UPDATE '.PREFIX_TABLE.'images';
34 
35  $query.= ' SET name = ';
36  if ( $_POST['name'] == '' )
37    $query.= 'NULL';
38  else
39    $query.= "'".htmlentities( $_POST['name'], ENT_QUOTES )."'";
40 
41  $query.= ', author = ';
42  if ( $_POST['author'] == '' )
43    $query.= 'NULL';
44  else
45    $query.= "'".htmlentities($_POST['author'],ENT_QUOTES)."'";
46
47  $query.= ', comment = ';
48  if ( $_POST['comment'] == '' )
49    $query.= 'NULL';
50  else
51    $query.= "'".htmlentities($_POST['comment'],ENT_QUOTES)."'";
52
53  $query.= ', date_creation = ';
54  if ( check_date_format( $_POST['creation_date'] ) )
55    $query.= "'".date_convert( $_POST['creation_date'] )."'";
56  else if ( $_POST['creation_date'] == '' )
57    $query.= 'NULL';
58
59  $query.= ', keywords = ';
60  $keywords_array = get_keywords( $_POST['keywords'] );
61  if ( count( $keywords_array ) == 0 )
62    $query.= 'NULL';
63  else
64  {
65    $query.= "'";
66    foreach ( $keywords_array as $i => $keyword ) {
67      if ( $i > 0 ) $query.= ',';
68      $query.= $keyword;
69    }
70    $query.= "'";
71  }
72
73  $query.= ' WHERE id = '.$_GET['image_id'];
74  $query.= ';';
75  mysql_query( $query );
76  // make the picture representative of a category ?
77  $query = 'SELECT DISTINCT(category_id) as category_id';
78  $query.= ',representative_picture_id';
79  $query.= ' FROM '.PREFIX_TABLE.'image_category AS ic';
80  $query.= ', '.PREFIX_TABLE.'categories AS c';
81  $query.= ' WHERE c.id = ic.category_id';
82  $query.= ' AND image_id = '.$_GET['image_id'];
83  $query.= ';';
84  $result = mysql_query( $query );
85  while ( $row = mysql_fetch_array( $result ) )
86  {
87    // if the user ask the picture to be the representative picture of its
88    // category, the category is updated in the database (without wondering
89    // if this picture was already the representative one)
90    if ( $_POST['representative-'.$row['category_id']] == 1 )
91    {
92      $query = 'UPDATE '.PREFIX_TABLE.'categories';
93      $query.= ' SET representative_picture_id = '.$_GET['image_id'];
94      $query.= ' WHERE id = '.$row['category_id'];
95      $query.= ';';
96      mysql_query( $query );
97    }
98    // if the user ask this picture to be not any more the representative,
99    // we have to set the representative_picture_id of this category to NULL
100    else if ( $row['representative_picture_id'] == $_GET['image_id'] )
101    {
102      $query = 'UPDATE '.PREFIX_TABLE.'categories';
103      $query.= ' SET representative_picture_id = NULL';
104      $query.= ' WHERE id = '.$row['category_id'];
105      $query.= ';';
106      mysql_query( $query );
107    }
108  }
109  // associate with a new category ?
110  if ( $_POST['associate'] != '-1' )
111  {
112    $query = 'INSERT INTO '.PREFIX_TABLE.'image_category';
113    $query.= ' (category_id,image_id) VALUES ';
114    $query.= '('.$_POST['associate'].','.$_GET['image_id'].')';
115    $query.= ';';
116    mysql_query( $query);
117    update_category( $_POST['associate'] );
118  }
119  // dissociate any category ?
120  // retrieving all the linked categories
121  $query = 'SELECT DISTINCT(category_id) as category_id';
122  $query.= ' FROM '.PREFIX_TABLE.'image_category';
123  $query.= ' WHERE image_id = '.$_GET['image_id'];
124  $query.= ';';
125  $result = mysql_query( $query );
126  while ( $row = mysql_fetch_array( $result ) )
127  {
128    if ( $_POST['dissociate-'.$row['category_id']] == 1 )
129    {
130      $query = 'DELETE FROM '.PREFIX_TABLE.'image_category';
131      $query.= ' WHERE image_id = '.$_GET['image_id'];
132      $query.= ' AND category_id = '.$row['category_id'];
133      $query.= ';';
134      mysql_query( $query );
135      update_category( $row['category_id'] );
136    }
137  }
138}
139//----------------------------------------------------- template initialization
140$sub = $vtp->Open(
141  '../template/'.$user['template'].'/admin/picture_modify.vtp' );
142
143$tpl = array( 'submit','errors_title','picmod_update','picmod_back',
144              'default','file','size','filesize','registration_date',
145              'author','creation_date','keywords','comment', 'upload_name',
146              'dissociate','categories','infoimage_associate',
147              'cat_image_info','category_representative' );
148templatize_array( $tpl, 'lang', $sub );
149$vtp->setGlobalVar( $sub, 'user_template', $user['template'] );
150//-------------------------------------------------------------- errors display
151if ( count( $errors ) != 0 )
152{
153  $vtp->addSession( $sub, 'errors' );
154  foreach ( $errors as $error ) {
155    $vtp->addSession( $sub, 'li' );
156    $vtp->setVar( $sub, 'li.content', $error );
157    $vtp->closeSession( $sub, 'li' );
158  }
159  $vtp->closeSession( $sub, 'errors' );
160}
161//-------------------------------------------- displaying informations and form
162$action = './admin.php?'.$_SERVER['QUERY_STRING'];
163$vtp->setVar( $sub, 'form_action', $action );
164// retrieving direct information about picture
165$query = 'SELECT file,date_available,date_creation,tn_ext,name,filesize';
166$query.= ',width,height,author,comment,keywords,storage_category_id';
167$query.= ' FROM '.PREFIX_TABLE.'images';
168$query.= ' WHERE id = '.$_GET['image_id'];
169$query.= ';';
170$row = mysql_fetch_array( mysql_query( $query ) );
171// picture title
172if ( $row['name'] == '' )
173{
174  $title = str_replace( '_',' ',get_filename_wo_extension($row['file']) );
175}
176else
177{
178  $title = $row['name'];
179}
180$vtp->setVar( $sub, 'title', $title );
181$vtp->setVar( $sub, 'f_file', $row['file'] );
182$vtp->setVar( $sub, 'f_size', $row['width'].' * '.$row['height'] );
183$vtp->setVar( $sub, 'f_filesize', $row['filesize'].' KB' );
184$vtp->setVar( $sub, 'f_registration_date',format_date($row['date_available']));
185$default_name = str_replace( '_',' ',get_filename_wo_extension($row['file']) );
186$vtp->setVar( $sub, 'default_name', $default_name );
187// if this form is displayed after an unsucceeded submit, we have to display
188// the values filled by the user (wright or wrong).
189if ( count( $errors ) > 0 )
190{
191  $name            = $_POST['name'];
192  $author          = $_POST['author'];
193  $creation_date   = $_POST['creation_date'];
194  $keywords        = $_POST['keywords'];
195  $comment         = $_POST['comment'];
196}
197else
198{
199  $name            = $row['name'];
200  $author          = $row['author'];
201  $creation_date   = date_convert_back( $row['date_creation'] );
202  $keywords        = $row['keywords'];
203  $comment         = $row['comment'];
204}
205$vtp->setVar( $sub, 'f_name',            $name );
206$vtp->setVar( $sub, 'f_author',          $author );
207$vtp->setVar( $sub, 'f_creation_date',   $creation_date );
208$vtp->setVar( $sub, 'f_keywords',        $keywords );
209$vtp->setVar( $sub, 'f_comment',         $comment );
210// retrieving directory where picture is stored (for displaying the
211// thumbnail)
212$thumbnail_url = get_complete_dir( $row['storage_category_id'] );
213$result = get_cat_info( $row['storage_category_id'] );
214$cat_name = get_cat_display_name( $result['name'], ' &gt; ', '' );
215$vtp->setVar( $sub, 'dir', $cat_name );
216if ( $result['site_id'] == 1 ) $thumbnail_url = '.'.$thumbnail_url;
217$file_wo_ext = get_filename_wo_extension( $row['file'] );
218$thumbnail_url.= '/thumbnail/';
219$thumbnail_url.= $conf['prefix_thumbnail'].$file_wo_ext.'.'.$row['tn_ext'];
220$vtp->setVar( $sub, 'thumbnail_url', $thumbnail_url );
221// storage category is linked by default
222$vtp->addSession( $sub, 'linked_category' );
223$vtp->setVar( $sub, 'linked_category.name', $cat_name );
224$url = '../picture.php?image_id='.$_GET['image_id'];
225$url.= '&amp;cat='.$row['storage_category_id'];
226$vtp->setVar( $sub, 'linked_category.url',add_session_id( $url));
227$url = './admin.php?page=infos_images&amp;cat_id='.$row['storage_category_id'];
228$vtp->setVar( $sub, 'linked_category.infos_images_link',add_session_id( $url));
229if ( $result['status'] == 'private' )
230{
231  $private_string = '<span style="color:red;font-weight:bold;">';
232  $private_string.= $lang['private'].'</span>';
233  $vtp->setVar( $sub, 'linked_category.private', $private_string );
234}
235if ( !$result['visible'] )
236{
237  $invisible_string = '<span style="color:red;">';
238  $invisible_string.= $lang['cat_invisible'].'</span>';
239  $vtp->setVar( $sub, 'linked_category.invisible', $invisible_string );
240}
241$vtp->setVar( $sub, 'linked_category.id', $row['storage_category_id'] );
242if ( $result['representative_picture_id'] == $_GET['image_id'] )
243{
244  $vtp->setVar( $sub, 'linked_category.representative_checked',
245                ' checked="checked"' );
246}
247$vtp->closeSession( $sub, 'linked_category' );
248// retrieving all the linked categories
249$query = 'SELECT DISTINCT(category_id) as category_id,status,visible';
250$query.= ',representative_picture_id';
251$query.= ' FROM '.PREFIX_TABLE.'image_category';
252$query.= ','.PREFIX_TABLE.'categories';
253$query.= ' WHERE image_id = '.$_GET['image_id'];
254$query.= ' AND category_id != '.$row['storage_category_id'];
255$query.= ' AND category_id = id';
256$query.= ';';
257$result = mysql_query( $query );
258while ( $row = mysql_fetch_array( $result ) )
259{
260  $vtp->addSession( $sub, 'linked_category' );
261  $vtp->setVar( $sub, 'linked_category.id', $row['category_id'] );
262
263  $vtp->addSession( $sub, 'checkbox' );
264  $vtp->setVar( $sub, 'checkbox.id', $row['category_id'] );
265  $vtp->closeSession( $sub, 'checkbox' );
266
267  $cat_infos = get_cat_info( $row['category_id'] );
268  $cat_name = get_cat_display_name( $cat_infos['name'], ' &gt; ', '' );
269  $vtp->setVar( $sub, 'linked_category.name', $cat_name );
270
271  $url = '../picture.php?image_id='.$_GET['image_id'];
272  $url.= '&amp;cat='.$row['category_id'];
273  $vtp->setVar( $sub, 'linked_category.url',add_session_id( $url));
274
275  $url = './admin.php?page=infos_images&amp;cat_id='.$row['category_id'];
276  $vtp->setVar( $sub, 'linked_category.infos_images_link',
277                add_session_id( $url));
278
279  if ( $row['status'] == 'private' )
280  {
281    $private_string = '<span style="color:red;font-weight:bold;">';
282    $private_string.= $lang['private'].'</span>';
283    $vtp->setVar( $sub, 'linked_category.private', $private_string );
284  }
285
286  if ( !get_boolean( $row['visible'] ) )
287  {
288    $invisible_string = '<span style="color:red;">';
289    $invisible_string.= $lang['cat_invisible'].'</span>';
290    $vtp->setVar( $sub, 'linked_category.invisible', $invisible_string );
291  }
292
293  if ( $row['representative_picture_id'] == $_GET['image_id'] )
294  {
295    $vtp->setVar( $sub, 'linked_category.representative_checked',
296                  ' checked="checked"' );
297  }
298 
299  $vtp->closeSession( $sub, 'linked_category' );
300}
301// if there are linked category other than the storage category, we show
302// propose the dissociate text
303if ( mysql_num_rows( $result ) > 0 )
304{
305  $vtp->addSession( $sub, 'dissociate' );
306  $vtp->closeSession( $sub, 'dissociate' );
307}
308// associate to another category ?
309$vtp->addSession( $sub, 'associate_cat' );
310$vtp->setVar( $sub, 'associate_cat.value', '-1' );
311$vtp->setVar( $sub, 'associate_cat.content', '' );
312$vtp->closeSession( $sub, 'associate_cat' );
313$structure = create_structure( '', array() );
314display_categories( $structure, '&nbsp;' );
315//----------------------------------------------------------- sending html code
316$vtp->Parse( $handle , 'sub', $sub );
317?>
Note: See TracBrowser for help on using the repository browser.