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
RevLine 
[2]1<?php
[362]2// +-----------------------------------------------------------------------+
[593]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 |
[362]6// +-----------------------------------------------------------------------+
[593]7// | branch        : BSF (Best So Far)
[362]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// +-----------------------------------------------------------------------+
[2]27
[570]28if(!defined("PHPWG_ROOT_PATH"))
[496]29{
[570]30  die ("Hacking attempt!");
[496]31}
[570]32include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
33// +-----------------------------------------------------------------------+
34// |                             initialization                            |
35// +-----------------------------------------------------------------------+
36check_cat_id($_GET['cat_id']);
[345]37$errors = array();
38
[570]39if (isset($page['cat']))
[14]40{
[570]41// +-----------------------------------------------------------------------+
42// |                       update individual options                       |
43// +-----------------------------------------------------------------------+
44  if (isset($_POST['submit']))
[14]45  {
[570]46    if (isset($_POST['associate']) and $_POST['associate'] != '')
[14]47    {
[345]48      // does the uppercat id exists in the database ?
[570]49      if (!is_numeric($_POST['associate']))
[345]50      {
[570]51        array_push($errors, $lang['cat_unknown_id']);
[345]52      }
[14]53      else
54      {
[506]55        $query = 'SELECT id FROM '.CATEGORIES_TABLE;
[345]56        $query.= ' WHERE id = '.$_POST['associate'];
57        $query.= ';';
[587]58        if (mysql_num_rows(pwg_query($query)) == 0)
[570]59          array_push($errors, $lang['cat_unknown_id']);
[14]60      }
[345]61    }
[33]62
[345]63    $associate = false;
64   
[506]65    $query = 'SELECT id,file FROM '.IMAGES_TABLE;
66    $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id';
[61]67    $query.= ' WHERE category_id = '.$page['cat'];
[345]68    $query.= ';';
[587]69    $result = pwg_query($query);
[570]70    while ($row = mysql_fetch_array($result))
[14]71    {
[345]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'];
[570]77      if (isset($_POST[$name]))
[61]78      {
[506]79        $query = 'UPDATE '.IMAGES_TABLE.' SET name = ';
[570]80        if ($_POST[$name] == '')
[345]81          $query.= 'NULL';
82        else
[570]83          $query.= "'".htmlentities($_POST[$name], ENT_QUOTES)."'";
[345]84
85        $query.= ', author = ';
[570]86        if ($_POST[$author] == '')
[345]87          $query.= 'NULL';
88        else
89          $query.= "'".htmlentities($_POST[$author],ENT_QUOTES)."'";
90
91        $query.= ', comment = ';
[570]92        if ($_POST[$comment] == '')
[345]93          $query.= 'NULL';
94        else
95          $query.= "'".htmlentities($_POST[$comment],ENT_QUOTES)."'";
96
97        $query.= ', date_creation = ';
[570]98        if (check_date_format($_POST[$date_creation]))
99          $query.= "'".date_convert($_POST[$date_creation])."'";
100        else if ($_POST[$date_creation] == '')
[345]101          $query.= 'NULL';
102
103        $query.= ', keywords = ';
104
[570]105        $keywords_array = get_keywords($_POST[$keywords]);
106        if (count($keywords_array) == 0) $query.= 'NULL';
107        else $query.= "'".implode(',', $keywords_array)."'";
[345]108
109        $query.= ' WHERE id = '.$row['id'];
110        $query.= ';';
[587]111        pwg_query($query);
[61]112      }
[345]113      // add link to another category
[570]114      if (isset($_POST['check-'.$row['id']]) and count($errors) == 0)
[61]115      {
[506]116        $query = 'INSERT INTO '.IMAGE_CATEGORY_TABLE;
[345]117        $query.= ' (image_id,category_id) VALUES';
118        $query.= ' ('.$row['id'].','.$_POST['associate'].')';
119        $query.= ';';
[587]120        pwg_query($query);
[345]121        $associate = true;
[61]122      }
[14]123    }
[570]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']))
[14]130    {
[506]131      $query = 'SELECT image_id FROM '.IMAGE_CATEGORY_TABLE;
[61]132      $query.= ' WHERE category_id = '.$page['cat'];
[587]133      $result = pwg_query($query);
[570]134      while ($row = mysql_fetch_array($result))
[14]135      {
[506]136        $query = 'UPDATE '.IMAGES_TABLE;
[570]137        if ($_POST['author_cat'] == '')
[61]138        {
[345]139          $query.= ' SET author = NULL';
[61]140        }
141        else
142        {
[345]143          $query.= ' SET author = ';
[570]144          $query.= "'".htmlentities($_POST['author_cat'], ENT_QUOTES)."'";
[61]145        }
146        $query.= ' WHERE id = '.$row['image_id'];
147        $query.= ';';
[587]148        pwg_query($query);
[14]149      }
150    }
[570]151    if (isset($_POST['use_common_date_creation']))
[14]152    {
[570]153      if (check_date_format($_POST['date_creation_cat']))
[40]154      {
[570]155        $date = date_convert($_POST['date_creation_cat']);
[506]156        $query = 'SELECT image_id FROM '.IMAGE_CATEGORY_TABLE;
[345]157        $query.= ' WHERE category_id = '.$page['cat'];
[587]158        $result = pwg_query($query);
[570]159        while ($row = mysql_fetch_array($result))
[345]160        {
[506]161          $query = 'UPDATE '.IMAGES_TABLE;
[570]162          if ($_POST['date_creation_cat'] == '')
[345]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.= ';';
[587]172          pwg_query($query);
[345]173        }
[33]174      }
[345]175      else
[40]176      {
[570]177        array_push($errors, $lang['err_date']);
[40]178      }
[345]179    }
[570]180    if (isset($_POST['common_keywords']) and $_POST['keywords_cat'] != '')
[345]181    {
[506]182      $query = 'SELECT id,keywords FROM '.IMAGES_TABLE;
183      $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id';
[345]184      $query.= ' WHERE category_id = '.$page['cat'];
185      $query.= ';';
[587]186      $result = pwg_query($query);
[570]187      while ($row = mysql_fetch_array($result))
[40]188      {
[570]189        if (!isset($row['keywords'])) $specific_keywords = array();
190        else $specific_keywords = explode(',', $row['keywords']);
[345]191       
[570]192        $common_keywords   = get_keywords($_POST['keywords_cat']);
[345]193        // first possiblity : adding the given keywords to all the pictures
[570]194        if ($_POST['common_keywords'] == 'add')
[345]195        {
[570]196          $keywords = array_merge($specific_keywords, $common_keywords);
197          $keywords = array_unique($keywords);
[40]198        }
[345]199        // second possiblity : removing the given keywords from all pictures
200        // (without deleting the other specific keywords
[570]201        if ($_POST['common_keywords'] == 'remove')
[345]202        {
[570]203          $keywords = array_diff($specific_keywords, $common_keywords);
[345]204        }
205        // cleaning the keywords array, sometimes, an empty value still remain
[570]206        $keywords = array_remove($keywords, '');
[345]207        // updating the picture with new keywords array
[506]208        $query = 'UPDATE '.IMAGES_TABLE.' SET keywords = ';
[570]209        if (count($keywords) == 0)
[345]210        {
211          $query.= 'NULL';
212        }
213        else
214        {
215          $query.= '"';
216          $i = 0;
[570]217          foreach ($keywords as $keyword) {
218            if ($i++ > 0) $query.= ',';
[345]219            $query.= $keyword;
220          }
221          $query.= '"';
222        }
223        $query.= ' WHERE id = '.$row['id'];
224        $query.= ';';
[587]225        pwg_query($query);
[40]226      }
[33]227    }
228  }
[570]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))
[14]235  {
236    $page['start'] = 0;
237  }
238  else
239  {
240    $page['start'] = $_GET['start'];
241  }
242
[570]243  if (isset($_GET['num']) and is_numeric($_GET['num']) and $_GET['num'] >= 0)
[14]244  {
[570]245    $max = $conf['info_nb_elements_page'];
246    $page['start'] = floor($_GET['num'] / $max) * $max;
[14]247  }
[506]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=';
[577]251  $category_path = get_cat_display_name($current_category['name'],
252                                        '-&gt;',
253                                        $url);
[506]254 
[577]255  $form_action = PHPWG_ROOT_PATH.'admin.php';
256  $form_action.= '?page=infos_images&amp;cat_id='.$_GET['cat_id'];
[570]257  if($page['start'])
[506]258  {
259    $form_action.= '&amp;start='.$_GET['start'];
260  }
261 
[570]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)
[506]297  {
[570]298    $template->assign_block_vars('errors',array());
299    foreach ($errors as $error)
300    {
301      $template->assign_block_vars('errors.error',array('ERROR'=>$error));
302    }
[345]303  }
[570]304// +-----------------------------------------------------------------------+
305// |                                 form                                  |
306// +-----------------------------------------------------------------------+
307  $array_cat_directories = array();
[14]308
[570]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;';
[587]319  $result = pwg_query($query);
[570]320  while ($row = mysql_fetch_array($result))
[14]321  {
[606]322    $thumbnail_url = get_thumbnail_src($row['path'], @$row['tn_ext']);
[570]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']),
[579]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']
[570]337       ));
[14]338  }
[506]339 
[345]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';
[506]345  $query.= ' FROM '.CATEGORIES_TABLE.';';
[587]346  $row = mysql_fetch_array(pwg_query($query));
[570]347  if ($row['nb_total_categories'] < $conf['max_LOV_categories'])
[345]348  {
[570]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');*/
[345]354  }
355  // else, we only display a small text field, we suppose the administrator
356  // knows the id of its category
357  else
358  {
[570]359    //$vtp->addSession($sub, 'associate_text');
360    //$vtp->closeSession($sub, 'associate_text');
[345]361  }
[14]362}
363//----------------------------------------------------------- sending html code
[506]364$template->assign_var_from_handle('ADMIN_CONTENT', 'infos_images');
[362]365?>
Note: See TracBrowser for help on using the repository browser.