source: branches/release-1_3/admin/infos_images.php @ 259

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

for virtual category to picture association, if the number of categories is
more than $confmax_LOV_categories, we only show a text box asking parent
category id

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.9 KB
Line 
1<?php
2/***************************************************************************
3 *                             infos_images.php                            *
4 *                            ------------------                           *
5 *   application   : PhpWebGallery 1.3 <http://phpwebgallery.net>          *
6 *   author        : Pierrick LE GALL <pierrick@z0rglub.com>               *
7 *                                                                         *
8 *   $Id: infos_images.php 258 2004-01-03 21:36:59Z 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' );
21include_once( '../template/'.$user['template'].'/htmlfunctions.inc.php' );
22//-------------------------------------------------------------- initialization
23$page['nb_image_page'] = 5;
24
25check_cat_id( $_GET['cat_id'] );
26if ( isset( $page['cat'] ) )
27{
28//--------------------------------------------------- update individual options
29  if ( isset( $_POST['submit'] ) )
30  {
31    $errors = array();
32    if ( isset( $_POST['associate'] ) )
33    {
34      // does the uppercat id exists in the database ?
35      if ( !is_numeric( $_POST['associate'] ) )
36      {
37        array_push( $errors, $lang['cat_unknown_id'] );
38      }
39      else
40      {
41        $query = 'SELECT id';
42        $query.= ' FROM '.PREFIX_TABLE.'categories';
43        $query.= ' WHERE id = '.$_POST['associate'];
44        $query.= ';';
45        if ( mysql_num_rows( mysql_query( $query ) ) == 0 )
46          array_push( $errors, $lang['cat_unknown_id'] );
47      }
48    }
49
50    $query = 'SELECT id,file';
51    $query.= ' FROM '.PREFIX_TABLE.'images';
52    $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
53    $query.= ' WHERE category_id = '.$page['cat'];
54    $query.= ';';
55    $result = mysql_query( $query );
56    $i = 1;
57    while ( $row = mysql_fetch_array( $result ) )
58    {
59      $name          = 'name-'.$row['id'];
60      $author        = 'author-'.$row['id'];
61      $comment       = 'comment-'.$row['id'];
62      $date_creation = 'date_creation-'.$row['id'];
63      $keywords      = 'keywords-'.$row['id'];
64      if ( isset( $_POST[$name] ) )
65      {
66        $query = 'UPDATE '.PREFIX_TABLE.'images';
67
68        $query.= ' SET name = ';
69        if ( $_POST[$name] == '' )
70          $query.= 'NULL';
71        else
72          $query.= "'".htmlentities( $_POST[$name], ENT_QUOTES )."'";
73
74        $query.= ', author = ';
75        if ( $_POST[$author] == '' )
76          $query.= 'NULL';
77        else
78          $query.= "'".htmlentities($_POST[$author],ENT_QUOTES)."'";
79
80        $query.= ', comment = ';
81        if ( $_POST[$comment] == '' )
82          $query.= 'NULL';
83        else
84          $query.= "'".htmlentities($_POST[$comment],ENT_QUOTES)."'";
85
86        $query.= ', date_creation = ';
87        if ( check_date_format( $_POST[$date_creation] ) )
88          $query.= "'".date_convert( $_POST[$date_creation] )."'";
89        else if ( $_POST[$date_creation] == '' )
90          $query.= 'NULL';
91
92        $query.= ', keywords = ';
93        $keywords_array = get_keywords( $_POST[$keywords] );
94        if ( count( $keywords_array ) == 0 )
95          $query.= 'NULL';
96        else
97        {
98          $query.= "'";
99          foreach ( $keywords_array as $i => $keyword ) {
100            if ( $i > 0 ) $query.= ',';
101            $query.= $keyword;
102          }
103          $query.= "'";
104        }
105
106        $query.= ' WHERE id = '.$row['id'];
107        $query.= ';';
108        mysql_query( $query );
109      }
110      // add link to another category
111      if ( $_POST['check-'.$row['id']] == 1 and count( $errors ) == 0 )
112      {
113        $query = 'INSERT INTO '.PREFIX_TABLE.'image_category';
114        $query.= ' (image_id,category_id) VALUES';
115        $query.= ' ('.$row['id'].','.$_POST['associate'].')';
116        $query.= ';';
117        mysql_query( $query );
118      }
119    }
120    update_category( $_POST['associate'] );
121//------------------------------------------------------ update general options
122    if ( $_POST['use_common_author'] == 1 )
123    {
124      $query = 'SELECT image_id';
125      $query.= ' FROM '.PREFIX_TABLE.'image_category';
126      $query.= ' WHERE category_id = '.$page['cat'];
127      $result = mysql_query( $query );
128      while ( $row = mysql_fetch_array( $result ) )
129      {
130        $query = 'UPDATE '.PREFIX_TABLE.'images';
131        if ( $_POST['author_cat'] == '' )
132        {
133          $query.= ' SET author = NULL';
134        }
135        else
136        {
137          $query.= ' SET author = ';
138          $query.= "'".htmlentities( $_POST['author_cat'], ENT_QUOTES )."'";
139        }
140        $query.= ' WHERE id = '.$row['image_id'];
141        $query.= ';';
142        mysql_query( $query );
143      }
144    }
145    if ( $_POST['use_common_date_creation'] == 1 )
146    {
147      if ( check_date_format( $_POST['date_creation_cat'] ) )
148      {
149        $date = date_convert( $_POST['date_creation_cat'] );
150        $query = 'SELECT image_id';
151        $query.= ' FROM '.PREFIX_TABLE.'image_category';
152        $query.= ' WHERE category_id = '.$page['cat'];
153        $result = mysql_query( $query );
154        while ( $row = mysql_fetch_array( $result ) )
155        {
156          $query = 'UPDATE '.PREFIX_TABLE.'images';
157          if ( $_POST['date_creation_cat'] == '' )
158          {
159            $query.= ' SET date_creation = NULL';
160          }
161          else
162          {
163            $query.= " SET date_creation = '".$date."'";
164          }
165          $query.= ' WHERE id = '.$row['image_id'];
166          $query.= ';';
167          mysql_query( $query );
168        }
169      }
170      else
171      {
172        array_push( $errors, $lang['err_date'] );
173      }
174    }
175    if ( isset( $_POST['common_keywords'] ) and $_POST['keywords_cat'] != '' )
176    {
177      $query = 'SELECT id,keywords';
178      $query.= ' FROM '.PREFIX_TABLE.'images';
179      $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
180      $query.= ' WHERE category_id = '.$page['cat'];
181      $query.= ';';
182      $result = mysql_query( $query );
183      while ( $row = mysql_fetch_array( $result ) )
184      {
185        $specific_keywords = explode( ',', $row['keywords'] );
186        $common_keywords   = get_keywords( $_POST['keywords_cat'] );
187        // first possiblity : adding the given keywords to all the pictures
188        if ( $_POST['common_keywords'] == 'add' )
189        {
190          $keywords = array_merge( $specific_keywords, $common_keywords );
191          $keywords = array_unique( $keywords );
192        }
193        // second possiblity : removing the given keywords from all pictures
194        // (without deleting the other specific keywords
195        if ( $_POST['common_keywords'] == 'remove' )
196        {
197          $keywords = array_diff( $specific_keywords, $common_keywords );
198        }
199        // cleaning the keywords array, sometimes, an empty value still remain
200        $keywords = array_remove( $keywords, '' );
201        // updating the picture with new keywords array
202        $query = 'UPDATE '.PREFIX_TABLE.'images';
203        $query.= ' SET keywords = ';
204        if ( count( $keywords ) == 0 )
205        {
206          $query.= 'NULL';
207        }
208        else
209        {
210          $query.= '"';
211          $i = 0;
212          foreach ( $keywords as $keyword ) {
213            if ( $i++ > 0 ) $query.= ',';
214            $query.= $keyword;
215          }
216          $query.= '"';
217        }
218        $query.= ' WHERE id = '.$row['id'];
219        $query.= ';';
220        mysql_query( $query );
221      }
222    }
223  }
224//--------------------------------------------------------- form initialization
225  if( !isset( $_GET['start'] )
226      or !is_numeric( $_GET['start'] )
227      or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
228  {
229    $page['start'] = 0;
230  }
231  else
232  {
233    $page['start'] = $_GET['start'];
234  }
235
236  if ( is_numeric( $_GET['num'] ) and $_GET['num'] >= 0 )
237  {
238    $page['start'] =
239      floor( $_GET['num'] / $page['nb_image_page'] ) * $page['nb_image_page'];
240  }
241  // retrieving category information
242  $result = get_cat_info( $page['cat'] );
243  $cat['name'] = $result['name'];
244  $cat['nb_images'] = $result['nb_images'];
245//----------------------------------------------------- template initialization
246  $sub = $vtp->Open('../template/'.$user['template'].'/admin/infos_image.vtp');
247  $tpl = array( 'infoimage_general','author','infoimage_useforall','submit',
248                'infoimage_creation_date','infoimage_detailed','thumbnail',
249                'infoimage_title','infoimage_comment',
250                'infoimage_creation_date','keywords',
251                'infoimage_addtoall','infoimage_removefromall',
252                'infoimage_keyword_separation','infoimage_associate',
253                'errors_title' );
254  templatize_array( $tpl, 'lang', $sub );
255  $vtp->setGlobalVar( $sub, 'user_template',   $user['template'] );
256//-------------------------------------------------------------- errors display
257if ( count( $errors ) != 0 )
258{
259  $vtp->addSession( $sub, 'errors' );
260  foreach ( $errors as $error ) {
261    $vtp->addSession( $sub, 'li' );
262    $vtp->setVar( $sub, 'li.content', $error );
263    $vtp->closeSession( $sub, 'li' );
264  }
265  $vtp->closeSession( $sub, 'errors' );
266}
267//------------------------------------------------------------------------ form
268  $url = './admin.php?page=infos_images&amp;cat_id='.$page['cat'];
269  $url.= '&amp;start='.$page['start'];
270  $vtp->setVar( $sub, 'form_action', add_session_id( $url ) ); 
271  $page['navigation_bar'] = create_navigation_bar(
272    $url, $cat['nb_images'],$page['start'], $page['nb_image_page'], '' );
273  $vtp->setVar( $sub, 'navigation_bar', $page['navigation_bar'] );
274  $cat_name = get_cat_display_name( $cat['name'], ' - ', 'font-style:italic;');
275  $vtp->setVar( $sub, 'cat_name', $cat_name );
276
277  $array_cat_directories = array();
278
279  $query = 'SELECT id,file,comment,author,tn_ext,name,date_creation,keywords';
280  $query.= ',storage_category_id,category_id';
281  $query.= ' FROM '.PREFIX_TABLE.'images';
282  $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
283  $query.= ' WHERE category_id = '.$page['cat'];
284  $query.= $conf['order_by'];
285  $query.= ' LIMIT '.$page['start'].','.$page['nb_image_page'];
286  $query.= ';';
287  $result = mysql_query( $query );
288  while ( $row = mysql_fetch_array( $result ) )
289  {
290    $vtp->addSession( $sub, 'picture' );
291    $vtp->setVar( $sub, 'picture.id', $row['id'] );
292    $vtp->setVar( $sub, 'picture.filename', $row['file'] );
293    $vtp->setVar( $sub, 'picture.name', $row['name'] );
294    $vtp->setVar( $sub, 'picture.author', $row['author'] );
295    $vtp->setVar( $sub, 'picture.comment', $row['comment'] );
296    $vtp->setVar( $sub, 'picture.keywords', $row['keywords'] );
297    $vtp->setVar( $sub, 'picture.date_creation',
298                  date_convert_back( $row['date_creation'] ) );
299    $file = get_filename_wo_extension( $row['file'] );
300    $vtp->setVar( $sub, 'picture.default_name', $file );
301    // creating url to thumbnail
302    if ( $array_cat_directories[$row['storage_category_id']] == '' )
303    {
304      $array_cat_directories[$row['storage_category_id']] =
305        get_complete_dir( $row['storage_category_id'] );
306    }
307    $thumbnail_url = $array_cat_directories[$row['storage_category_id']];
308    if ( preg_match( '/^\.\/galleries/', $thumbnail_url ) )
309    {
310      $thumbnail_url = '.'.$thumbnail_url;
311    }
312    $thumbnail_url.= 'thumbnail/';
313    $thumbnail_url.= $conf['prefix_thumbnail'].$file.".".$row['tn_ext'];
314    $vtp->setVar( $sub, 'picture.thumbnail_url', $thumbnail_url );
315    $url = './admin.php?page=picture_modify&amp;image_id='.$row['id'];
316    $vtp->setVar( $sub, 'picture.url', add_session_id( $url ) );
317    $vtp->closeSession( $sub, 'picture' );
318  }
319  // Virtualy associate a picture to a category
320  //
321  // We only show a List Of Values if the number of categories is less than
322  // $conf['max_LOV_categories']
323  $query = 'SELECT COUNT(id) AS nb_total_categories';
324  $query.= ' FROM '.PREFIX_TABLE.'categories';
325  $query.= ';';
326  $row = mysql_fetch_array( mysql_query( $query ) );
327  if ( $row['nb_total_categories'] < $conf['max_LOV_categories'] )
328  {
329    $vtp->addSession( $sub, 'associate_LOV' );
330    $page['plain_structure'] = get_plain_structure( true );
331    $structure = create_structure( '', array() );
332    display_categories( $structure, '&nbsp;' );
333    $vtp->closeSession( $sub, 'associate_LOV' );
334  }
335  // else, we only display a small text field, we suppose the administrator
336  // knows the id of its category
337  else
338  {
339    $vtp->addSession( $sub, 'associate_text' );
340    $vtp->closeSession( $sub, 'associate_text' );
341  }
342}
343//----------------------------------------------------------- sending html code
344$vtp->Parse( $handle , 'sub', $sub );
345?>
Note: See TracBrowser for help on using the repository browser.