source: trunk/admin/infos_images.php @ 766

Last change on this file since 766 was 675, checked in by plg, 20 years ago

all headers adapted to new year 2005, happy new year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.0 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 |
[675]5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
[362]6// +-----------------------------------------------------------------------+
[593]7// | branch        : BSF (Best So Far)
[362]8// | file          : $RCSfile$
9// | last update   : $Date: 2005-01-07 23:10:51 +0000 (Fri, 07 Jan 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 675 $
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
[506]63    $query = 'SELECT id,file FROM '.IMAGES_TABLE;
64    $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id';
[61]65    $query.= ' WHERE category_id = '.$page['cat'];
[345]66    $query.= ';';
[587]67    $result = pwg_query($query);
[570]68    while ($row = mysql_fetch_array($result))
[14]69    {
[345]70      $name          = 'name-'.$row['id'];
71      $author        = 'author-'.$row['id'];
72      $comment       = 'comment-'.$row['id'];
73      $date_creation = 'date_creation-'.$row['id'];
74      $keywords      = 'keywords-'.$row['id'];
[570]75      if (isset($_POST[$name]))
[61]76      {
[506]77        $query = 'UPDATE '.IMAGES_TABLE.' SET name = ';
[570]78        if ($_POST[$name] == '')
[345]79          $query.= 'NULL';
80        else
[570]81          $query.= "'".htmlentities($_POST[$name], ENT_QUOTES)."'";
[345]82
83        $query.= ', author = ';
[570]84        if ($_POST[$author] == '')
[345]85          $query.= 'NULL';
86        else
87          $query.= "'".htmlentities($_POST[$author],ENT_QUOTES)."'";
88
89        $query.= ', comment = ';
[570]90        if ($_POST[$comment] == '')
[345]91          $query.= 'NULL';
92        else
93          $query.= "'".htmlentities($_POST[$comment],ENT_QUOTES)."'";
94
95        $query.= ', date_creation = ';
[570]96        if (check_date_format($_POST[$date_creation]))
97          $query.= "'".date_convert($_POST[$date_creation])."'";
98        else if ($_POST[$date_creation] == '')
[345]99          $query.= 'NULL';
100
101        $query.= ', keywords = ';
102
[570]103        $keywords_array = get_keywords($_POST[$keywords]);
104        if (count($keywords_array) == 0) $query.= 'NULL';
105        else $query.= "'".implode(',', $keywords_array)."'";
[345]106
107        $query.= ' WHERE id = '.$row['id'];
108        $query.= ';';
[587]109        pwg_query($query);
[61]110      }
[345]111      // add link to another category
[647]112      if (isset($_POST['check-'.$row['id']])
113          and isset($_POST['associate'])
114          and $_POST['associate'] != '')
[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);
[61]121      }
[14]122    }
[647]123    if (isset($_POST['associate']) and $_POST['associate'] != '')
124    {
125      update_category(array($_POST['associate']));
126    }
[570]127// +-----------------------------------------------------------------------+
128// |                        update general options                         |
129// +-----------------------------------------------------------------------+
130    if (isset($_POST['use_common_author']))
[14]131    {
[506]132      $query = 'SELECT image_id FROM '.IMAGE_CATEGORY_TABLE;
[61]133      $query.= ' WHERE category_id = '.$page['cat'];
[587]134      $result = pwg_query($query);
[570]135      while ($row = mysql_fetch_array($result))
[14]136      {
[506]137        $query = 'UPDATE '.IMAGES_TABLE;
[570]138        if ($_POST['author_cat'] == '')
[61]139        {
[345]140          $query.= ' SET author = NULL';
[61]141        }
142        else
143        {
[345]144          $query.= ' SET author = ';
[570]145          $query.= "'".htmlentities($_POST['author_cat'], ENT_QUOTES)."'";
[61]146        }
147        $query.= ' WHERE id = '.$row['image_id'];
148        $query.= ';';
[587]149        pwg_query($query);
[14]150      }
151    }
[570]152    if (isset($_POST['use_common_date_creation']))
[14]153    {
[570]154      if (check_date_format($_POST['date_creation_cat']))
[40]155      {
[570]156        $date = date_convert($_POST['date_creation_cat']);
[506]157        $query = 'SELECT image_id FROM '.IMAGE_CATEGORY_TABLE;
[345]158        $query.= ' WHERE category_id = '.$page['cat'];
[587]159        $result = pwg_query($query);
[570]160        while ($row = mysql_fetch_array($result))
[345]161        {
[506]162          $query = 'UPDATE '.IMAGES_TABLE;
[570]163          if ($_POST['date_creation_cat'] == '')
[345]164          {
165            $query.= ' SET date_creation = NULL';
166          }
167          else
168          {
169            $query.= " SET date_creation = '".$date."'";
170          }
171          $query.= ' WHERE id = '.$row['image_id'];
172          $query.= ';';
[587]173          pwg_query($query);
[345]174        }
[33]175      }
[345]176      else
[40]177      {
[570]178        array_push($errors, $lang['err_date']);
[40]179      }
[345]180    }
[570]181    if (isset($_POST['common_keywords']) and $_POST['keywords_cat'] != '')
[345]182    {
[506]183      $query = 'SELECT id,keywords FROM '.IMAGES_TABLE;
184      $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id';
[345]185      $query.= ' WHERE category_id = '.$page['cat'];
186      $query.= ';';
[587]187      $result = pwg_query($query);
[570]188      while ($row = mysql_fetch_array($result))
[40]189      {
[570]190        if (!isset($row['keywords'])) $specific_keywords = array();
191        else $specific_keywords = explode(',', $row['keywords']);
[345]192       
[570]193        $common_keywords   = get_keywords($_POST['keywords_cat']);
[345]194        // first possiblity : adding the given keywords to all the pictures
[570]195        if ($_POST['common_keywords'] == 'add')
[345]196        {
[570]197          $keywords = array_merge($specific_keywords, $common_keywords);
198          $keywords = array_unique($keywords);
[40]199        }
[345]200        // second possiblity : removing the given keywords from all pictures
201        // (without deleting the other specific keywords
[570]202        if ($_POST['common_keywords'] == 'remove')
[345]203        {
[570]204          $keywords = array_diff($specific_keywords, $common_keywords);
[345]205        }
206        // cleaning the keywords array, sometimes, an empty value still remain
[570]207        $keywords = array_remove($keywords, '');
[345]208        // updating the picture with new keywords array
[506]209        $query = 'UPDATE '.IMAGES_TABLE.' SET keywords = ';
[570]210        if (count($keywords) == 0)
[345]211        {
212          $query.= 'NULL';
213        }
214        else
215        {
216          $query.= '"';
217          $i = 0;
[570]218          foreach ($keywords as $keyword) {
219            if ($i++ > 0) $query.= ',';
[345]220            $query.= $keyword;
221          }
222          $query.= '"';
223        }
224        $query.= ' WHERE id = '.$row['id'];
225        $query.= ';';
[587]226        pwg_query($query);
[40]227      }
[33]228    }
229  }
[570]230// +-----------------------------------------------------------------------+
231// |                           form initialization                         |
232// +-----------------------------------------------------------------------+
233  if (!isset($_GET['start'])
234      or !is_numeric($_GET['start'])
235      or (is_numeric($_GET['start']) and $_GET['start'] < 0))
[14]236  {
237    $page['start'] = 0;
238  }
239  else
240  {
241    $page['start'] = $_GET['start'];
242  }
243
[570]244  if (isset($_GET['num']) and is_numeric($_GET['num']) and $_GET['num'] >= 0)
[14]245  {
[570]246    $max = $conf['info_nb_elements_page'];
247    $page['start'] = floor($_GET['num'] / $max) * $max;
[14]248  }
[506]249  // Navigation path
250  $current_category = get_cat_info($_GET['cat_id']);
251  $url = PHPWG_ROOT_PATH.'admin.php?page=infos_images&amp;cat_id=';
[642]252  $category_path = get_cat_display_name($current_category['name'], $url);
[506]253 
[577]254  $form_action = PHPWG_ROOT_PATH.'admin.php';
255  $form_action.= '?page=infos_images&amp;cat_id='.$_GET['cat_id'];
[570]256  if($page['start'])
[506]257  {
258    $form_action.= '&amp;start='.$_GET['start'];
259  }
260 
[570]261  $nav_bar = create_navigation_bar($form_action,
262                                   $current_category['nb_images'],
263                                   $page['start'],
264                                   $conf['info_nb_elements_page'],
265                                   '');
266// +-----------------------------------------------------------------------+
267// |                         template initialization                       |
268// +-----------------------------------------------------------------------+
269  $template->set_filenames(array('infos_images'=>'admin/infos_images.tpl'));
270  $template->assign_vars(
271    array(
272      'CATEGORY'=>$category_path,
273      'NAV_BAR'=>$nav_bar,
274     
275      'L_INFOS_TITLE'=>$lang['infoimage_general'],
276      'L_AUTHOR'=>$lang['author'],
277      'L_INFOS_OVERALL_USE'=>$lang['infoimage_useforall'],
278      'L_INFOS_CREATION_DATE'=>$lang['infoimage_creation_date'],
279      'L_KEYWORD'=>$lang['keywords'],
280      'L_KEYWORD_SEPARATION'=>$lang['infoimage_keyword_separation'],
281      'L_INFOS_ADDTOALL'=>$lang['infoimage_addtoall'],
282      'L_INFOS_REMOVEFROMALL'=>$lang['infoimage_removefromall'],
283      'L_INFOS_DETAIL'=>$lang['infoimage_detailed'],
284      'L_THUMBNAIL'=>$lang['thumbnail'],
285      'L_INFOS_IMG'=>$lang['infoimage_title'],
[649]286      'L_INFOS_COMMENT'=>$lang['description'],
[570]287      'L_INFOS_ASSOCIATE'=>$lang['infoimage_associate'],
288      'L_SUBMIT'=>$lang['submit'],
289     
290      'F_ACTION'=>add_session_id($form_action)
291      ));
292// +-----------------------------------------------------------------------+
293// |                            errors display                             |
294// +-----------------------------------------------------------------------+
295  if (count($errors) != 0)
[506]296  {
[570]297    $template->assign_block_vars('errors',array());
298    foreach ($errors as $error)
299    {
300      $template->assign_block_vars('errors.error',array('ERROR'=>$error));
301    }
[345]302  }
[570]303// +-----------------------------------------------------------------------+
304// |                                 form                                  |
305// +-----------------------------------------------------------------------+
306  $array_cat_directories = array();
[14]307
[570]308  $pic_mod_base_url = PHPWG_ROOT_PATH.'admin.php';
309  $pic_mod_base_url = '?page=picture_modify&amp;image_id=';
310 
311  $query = '
312SELECT *
313  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id
314  WHERE category_id = '.$page['cat'].'
315  '.$conf['order_by'].'
316  LIMIT '.$page['start'].','.$conf['info_nb_elements_page'].'
317;';
[587]318  $result = pwg_query($query);
[570]319  while ($row = mysql_fetch_array($result))
[14]320  {
[606]321    $thumbnail_url = get_thumbnail_src($row['path'], @$row['tn_ext']);
[570]322
323    $template->assign_block_vars(
324      'picture',
325      array(
326        'ID_IMG'=>$row['id'],
327        'URL_IMG'=>add_session_id($pic_mod_base_url.$row['id']),
328        'TN_URL_IMG'=>$thumbnail_url,
329        'FILENAME_IMG'=>$row['file'],
330        'DEFAULTNAME_IMG'=>get_filename_wo_extension($row['file']),
[579]331        'NAME_IMG'=>@$row['name'],
332        'DATE_IMG'=>date_convert_back(@$row['date_creation']),
333        'AUTHOR_IMG'=>@$row['author'],
334        'KEYWORDS_IMG'=>@$row['keywords'],
335        'COMMENT_IMG'=>@$row['comment']
[570]336       ));
[14]337  }
[506]338 
[345]339  // Virtualy associate a picture to a category
[647]340  $query = '
341SELECT id,name,uppercats,global_rank
342  FROM '.CATEGORIES_TABLE.'
343;';
344  display_select_cat_wrapper($query,
345                             array(),
346                             'associate_option',
347                             true);
[14]348}
349//----------------------------------------------------------- sending html code
[506]350$template->assign_var_from_handle('ADMIN_CONTENT', 'infos_images');
[362]351?>
Note: See TracBrowser for help on using the repository browser.