source: trunk/admin/element_set_unit.php @ 1119

Last change on this file since 1119 was 1119, checked in by plg, 18 years ago

improvement: tags replace keywords. Better data model, less
limitations. Each image can be associated to as many tag as needed. Tags can
contain non ASCII characters. Oriented navigation with tags by association.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 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-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-04-02 22:26:19 +0000 (Sun, 02 Apr 2006) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 1119 $
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
28/**
29 * Management of elements set. Elements can belong to a category or to the
30 * user caddie.
31 *
32 */
33 
34if (!defined('PHPWG_ROOT_PATH'))
35{
36  die('Hacking attempt!');
37}
38
39include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
40
41// +-----------------------------------------------------------------------+
42// | Check Access and exit when user status is not ok                      |
43// +-----------------------------------------------------------------------+
44check_status(ACCESS_ADMINISTRATOR);
45
46// +-----------------------------------------------------------------------+
47// |                        unit mode form submission                      |
48// +-----------------------------------------------------------------------+
49
50if (isset($_POST['submit']))
51{
52  $collection = explode(',', $_POST['list']);
53 
54  $datas = array();
55 
56  $query = '
57SELECT id, date_creation
58  FROM '.IMAGES_TABLE.'
59  WHERE id IN ('.implode(',', $collection).')
60;';
61  $result = pwg_query($query);
62
63  while ($row = mysql_fetch_array($result))
64  {
65    $data = array();
66
67    $data{'id'} = $row['id'];
68    $data{'name'} = $_POST['name-'.$row['id']];
69    $data{'author'} = $_POST['author-'.$row['id']];
70
71    foreach (array('name', 'author') as $field)
72    {
73      if (!empty($_POST[$field.'-'.$row['id']]))
74      {
75        $data{$field} = strip_tags($_POST[$field.'-'.$row['id']]);
76      }
77    }
78   
79    if ($conf['allow_html_descriptions'])
80    {
81      $data{'comment'} = @$_POST['description-'.$row['id']];
82    }
83    else
84    {
85      $data{'comment'} = strip_tags(@$_POST['description-'.$row['id']]);
86    }
87
88    if (isset($_POST['date_creation_action-'.$row['id']]))
89    {
90      if ('set' == $_POST['date_creation_action-'.$row['id']])
91      {
92        $data{'date_creation'} =
93          $_POST['date_creation_year-'.$row['id']]
94            .'-'.$_POST['date_creation_month-'.$row['id']]
95            .'-'.$_POST['date_creation_day-'.$row['id']];
96      }
97      else if ('unset' == $_POST['date_creation_action-'.$row['id']])
98      {
99        $data{'date_creation'} = '';
100      }
101    }
102    else
103    {
104      $data{'date_creation'} = $row['date_creation'];
105    }
106   
107    array_push($datas, $data);
108
109    // tags management
110    if (isset($_POST[ 'tags-'.$row['id'] ]))
111    {
112      set_tags($_POST[ 'tags-'.$row['id'] ], $row['id']);
113    }
114  }
115 
116  mass_updates(
117    IMAGES_TABLE,
118    array(
119      'primary' => array('id'),
120      'update' => array('name','author','comment','date_creation')
121      ),
122    $datas
123    );
124 
125  array_push($page['infos'], l10n('Picture informations updated'));
126}
127
128// +-----------------------------------------------------------------------+
129// |                             template init                             |
130// +-----------------------------------------------------------------------+
131
132$template->set_filenames(
133  array('element_set_unit' => 'admin/element_set_unit.tpl'));
134
135$base_url = PHPWG_ROOT_PATH.'admin.php';
136
137// $form_action = $base_url.'?page=element_set_global';
138
139$template->assign_vars(
140  array(
141    'CATEGORIES_NAV'=>$page['title'],
142
143    'L_SUBMIT'=>$lang['submit'],
144   
145    'U_ELEMENTS_PAGE'
146    =>$base_url.get_query_string_diff(array('display','start')),
147   
148    'U_GLOBAL_MODE'
149    =>
150    $base_url
151    .get_query_string_diff(array('mode','display'))
152    .'&amp;mode=global',
153   
154    'F_ACTION'=>$base_url.get_query_string_diff(array()),
155    )
156  );
157
158// +-----------------------------------------------------------------------+
159// |                        global mode thumbnails                         |
160// +-----------------------------------------------------------------------+
161
162// how many items to display on this page
163if (!empty($_GET['display']))
164{
165  if ('all' == $_GET['display'])
166  {
167    $page['nb_images'] = count($page['cat_elements_id']);
168  }
169  else
170  {
171    $page['nb_images'] = intval($_GET['display']);
172  }
173}
174else
175{
176  $page['nb_images'] = 5;
177}
178
179
180
181if (count($page['cat_elements_id']) > 0)
182{
183  $nav_bar = create_navigation_bar(
184    $base_url.get_query_string_diff(array('start')),
185    count($page['cat_elements_id']),
186    $page['start'],
187    $page['nb_images']
188    );
189  $template->assign_vars(array('NAV_BAR' => $nav_bar));
190
191  // tags
192  $all_tags = get_all_tags();
193 
194  $element_ids = array();
195
196  $query = '
197SELECT id,path,tn_ext,name,date_creation,comment,author,file
198  FROM '.IMAGES_TABLE.'
199  WHERE id IN ('.implode(',', $page['cat_elements_id']).')
200  '.$conf['order_by'].'
201  LIMIT '.$page['start'].', '.$page['nb_images'].'
202;';
203  $result = pwg_query($query);
204
205  while ($row = mysql_fetch_array($result))
206  {
207    // echo '<pre>'; print_r($row); echo '</pre>';
208    array_push($element_ids, $row['id']);
209   
210    $src = get_thumbnail_src($row['path'], @$row['tn_ext']);
211
212    $query = '
213SELECT tag_id
214  FROM '.IMAGE_TAG_TABLE.'
215  WHERE image_id = '.$row['id'].'
216;';
217    $selected_tags = array_from_query($query, 'tag_id');
218   
219    // creation date
220    if (!empty($row['date_creation']))
221    {
222      list($year,$month,$day) = explode('-', $row['date_creation']);
223    }
224    else
225    {
226      list($year,$month,$day) = array('','','');
227    }
228   
229    $template->assign_block_vars(
230      'element',
231      array(
232        'LEGEND' =>
233          !empty($row['name']) ?
234            $row['name'] : get_name_from_file($row['file']),
235        'U_EDIT' =>
236            PHPWG_ROOT_PATH.'admin.php?page=picture_modify'.
237            '&amp;image_id='.$row['id'],
238        'ID' => $row['id'],
239        'FILENAME' => $row['path'],
240        'TN_SRC' => $src,
241        'NAME' => @$row['name'],
242        'AUTHOR' => @$row['author'],
243        'DESCRIPTION' => @$row['comment'],
244        'DATE_CREATION_YEAR' => $year,
245       
246        'TAG_SELECTION' => get_html_tag_selection(
247          $all_tags,
248          'tags-'.$row['id'],
249          $selected_tags
250          ),
251        )
252      );
253   
254    get_day_list('element.date_creation_day', $day);
255    get_month_list('element.date_creation_month', $month);
256  }
257
258  $template->assign_vars(array('IDS_LIST' => implode(',', $element_ids)));
259}
260
261// +-----------------------------------------------------------------------+
262// |                           sending html code                           |
263// +-----------------------------------------------------------------------+
264
265$template->assign_var_from_handle('ADMIN_CONTENT', 'element_set_unit');
266?>
Note: See TracBrowser for help on using the repository browser.