source: trunk/admin/infos_images.php @ 521

Last change on this file since 521 was 509, checked in by gweltas, 20 years ago

Template migration : picture_modify.php

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