source: tags/release-1_3_2/admin/infos_images.php @ 27538

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

Php warnings correction

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