source: trunk/admin/infos_images.php @ 606

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