source: tags/release-1_6_2/admin/element_set_global.php @ 5650

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

bug 373 fixed: if there is no tag defined, an explicit message is displayed
in the administration section. In the public search screen, tag fieldset is
not displayed if no reachable tag.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.1 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-05-15 22:19:48 +0000 (Mon, 15 May 2006) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 1313 $
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// |                       global mode form submission                     |
48// +-----------------------------------------------------------------------+
49
50if (isset($_POST['submit']))
51{
52  $collection = array();
53
54//   echo '<pre>';
55//   print_r($_POST);
56//   echo '</pre>';
57//   exit();
58
59  switch ($_POST['target'])
60  {
61    case 'all' :
62    {
63      $collection = $page['cat_elements_id'];
64      break;
65    }
66    case 'selection' :
67    {
68      if (!isset($_POST['selection']) or count($_POST['selection']) == 0)
69      {
70        array_push($page['errors'], l10n('Select at least one picture'));
71      }
72      else
73      {
74        $collection = $_POST['selection'];
75      }
76      break;
77    }
78  }
79
80  if (isset($_POST['add_tags']) and count($collection) > 0)
81  {
82    add_tags($_POST['add_tags'], $collection);
83  }
84
85  if (isset($_POST['del_tags']) and count($collection) > 0)
86  {
87    $query = '
88DELETE
89  FROM '.IMAGE_TAG_TABLE.'
90  WHERE image_id IN ('.implode(',', $collection).')
91    AND tag_id IN ('.implode(',', $_POST['del_tags']).')
92;';
93    pwg_query($query);
94  }
95
96  if ($_POST['associate'] != 0 and count($collection) > 0)
97  {
98    associate_images_to_categories(
99      $collection,
100      array($_POST['associate'])
101      );
102  }
103
104  if ($_POST['dissociate'] != 0 and count($collection) > 0)
105  {
106    // physical links must not be broken, so we must first retrieve image_id
107    // which create virtual links with the category to "dissociate from".
108    $query = '
109SELECT id
110  FROM '.IMAGE_CATEGORY_TABLE.'
111    INNER JOIN '.IMAGES_TABLE.' ON image_id = id
112  WHERE category_id = '.$_POST['dissociate'].'
113    AND id IN ('.implode(',', $collection).')
114    AND category_id != storage_category_id
115;';
116    $dissociables = array_from_query($query, 'id');
117
118    $query = '
119DELETE
120  FROM '.IMAGE_CATEGORY_TABLE.'
121  WHERE category_id = '.$_POST['dissociate'].'
122    AND image_id IN ('.implode(',', $dissociables).')
123';
124    pwg_query($query);
125   
126    update_category($_POST['dissociate']);
127  }
128
129  $datas = array();
130  $dbfields = array('primary' => array('id'), 'update' => array());
131
132  $formfields = array('author', 'name', 'date_creation');
133  foreach ($formfields as $formfield)
134  {
135    if ($_POST[$formfield.'_action'] != 'leave')
136    {
137      array_push($dbfields['update'], $formfield);
138    }
139  }
140
141  // updating elements is useful only if needed...
142  if (count($dbfields['update']) > 0 and count($collection) > 0)
143  {
144    $query = '
145SELECT id
146  FROM '.IMAGES_TABLE.'
147  WHERE id IN ('.implode(',', $collection).')
148;';
149    $result = pwg_query($query);
150
151    while ($row = mysql_fetch_array($result))
152    {
153      $data = array();
154      $data['id'] = $row['id'];
155
156      if ('set' == $_POST['author_action'])
157      {
158        $data['author'] = $_POST['author'];
159
160        if ('' == $data['author'])
161        {
162          unset($data['author']);
163        }
164      }
165
166      if ('set' == $_POST['name_action'])
167      {
168        $data['name'] = $_POST['name'];
169
170        if ('' == $data['name'])
171        {
172          unset($data['name']);
173        }
174      }
175
176      if ('set' == $_POST['date_creation_action'])
177      {
178        $data['date_creation'] =
179          $_POST['date_creation_year']
180          .'-'.$_POST['date_creation_month']
181          .'-'.$_POST['date_creation_day']
182          ;
183      }
184
185      array_push($datas, $data);
186    }
187    // echo '<pre>'; print_r($datas); echo '</pre>';
188    mass_updates(IMAGES_TABLE, $dbfields, $datas);
189  }
190}
191
192// +-----------------------------------------------------------------------+
193// |                             template init                             |
194// +-----------------------------------------------------------------------+
195$template->set_filenames(
196  array('element_set_global' => 'admin/element_set_global.tpl'));
197
198$base_url = PHPWG_ROOT_PATH.'admin.php';
199
200// $form_action = $base_url.'?page=element_set_global';
201
202$template->assign_vars(
203  array(
204    'CATEGORIES_NAV'=>$page['title'],
205
206    'L_SUBMIT'=>$lang['submit'],
207
208    'U_DISPLAY'=>$base_url.get_query_string_diff(array('display')),
209
210    'U_UNIT_MODE'
211    =>
212    $base_url
213    .get_query_string_diff(array('mode','display'))
214    .'&amp;mode=unit',
215
216    'F_ACTION'=>$base_url.get_query_string_diff(array()),
217   )
218 );
219
220// +-----------------------------------------------------------------------+
221// |                            caddie options                             |
222// +-----------------------------------------------------------------------+
223
224if ('caddie' == $_GET['cat'])
225{
226  $template->assign_block_vars('in_caddie', array());
227}
228else
229{
230  $template->assign_block_vars('not_in_caddie', array());
231}
232
233// +-----------------------------------------------------------------------+
234// |                           global mode form                            |
235// +-----------------------------------------------------------------------+
236
237// Virtualy associate a picture to a category
238$blockname = 'associate_option';
239
240$template->assign_block_vars(
241  $blockname,
242  array('SELECTED' => '',
243        'VALUE'=> 0,
244        'OPTION' => '------------'
245    ));
246
247$query = '
248SELECT id,name,uppercats,global_rank
249  FROM '.CATEGORIES_TABLE.'
250;';
251display_select_cat_wrapper($query, array(), $blockname, true);
252
253// Dissociate from a category : categories listed for dissociation can
254// only represent virtual links. Links to physical categories can't be
255// broken
256$blockname = 'dissociate_option';
257
258$template->assign_block_vars(
259  $blockname,
260  array('SELECTED' => '',
261        'VALUE'=> 0,
262        'OPTION' => '------------'
263    ));
264
265if (count($page['cat_elements_id']) > 0)
266{
267  $query = '
268SELECT DISTINCT(category_id) AS id, c.name, uppercats, global_rank
269  FROM '.IMAGE_CATEGORY_TABLE.' AS ic,
270       '.CATEGORIES_TABLE.' AS c,
271       '.IMAGES_TABLE.' AS i
272  WHERE ic.image_id IN ('.implode(',', $page['cat_elements_id']).')
273    AND ic.category_id = c.id
274    AND ic.image_id = i.id
275    AND ic.category_id != i.storage_category_id
276;';
277  display_select_cat_wrapper($query, array(), $blockname, true);
278}
279
280$all_tags = get_all_tags();
281
282if (count($all_tags) == 0)
283{
284  $add_tag_selection =
285    '<p>'.
286    l10n('No tag defined. Use Administration>Pictures>Tags').
287    '</p>';
288}
289else
290{
291  $add_tag_selection = get_html_tag_selection(
292    get_all_tags(),
293    'add_tags'
294    );
295}
296
297// add tags
298$template->assign_vars(
299  array(
300    'ADD_TAG_SELECTION' => $add_tag_selection,
301    )
302  );
303
304if (count($page['cat_elements_id']) > 0)
305{
306  // remove tags
307  $query = '
308  SELECT tag_id, name, url_name, count(*) counter
309    FROM '.IMAGE_TAG_TABLE.'
310      INNER JOIN '.TAGS_TABLE.' ON tag_id = id
311    WHERE image_id IN ('.implode(',', $page['cat_elements_id']).')
312    GROUP BY tag_id
313  ;';
314  $result = pwg_query($query);
315
316  $tags = array();
317  while($row = mysql_fetch_array($result))
318  {
319    array_push($tags, $row);
320  }
321
322  usort($tags, 'name_compare');
323
324  $template->assign_vars(
325    array(
326      'DEL_TAG_SELECTION' => get_html_tag_selection($tags, 'del_tags'),
327      )
328    );
329}
330// creation date
331$day =
332empty($_POST['date_creation_day']) ? date('j') : $_POST['date_creation_day'];
333get_day_list('date_creation_day', $day);
334
335if (!empty($_POST['date_creation_month']))
336{
337  $month = $_POST['date_creation_month'];
338}
339else
340{
341  $month = date('n');
342}
343get_month_list('date_creation_month', $month);
344
345if (!empty($_POST['date_creation_year']))
346{
347  $year = $_POST['date_creation_year'];
348}
349else
350{
351  $year = date('Y');
352}
353$template->assign_vars(array('DATE_CREATION_YEAR_VALUE'=>$year));
354
355// +-----------------------------------------------------------------------+
356// |                        global mode thumbnails                         |
357// +-----------------------------------------------------------------------+
358
359// how many items to display on this page
360if (!empty($_GET['display']))
361{
362  if ('all' == $_GET['display'])
363  {
364    $page['nb_images'] = count($page['cat_elements_id']);
365  }
366  else
367  {
368    $page['nb_images'] = intval($_GET['display']);
369  }
370}
371else
372{
373  $page['nb_images'] = 20;
374}
375
376if (count($page['cat_elements_id']) > 0)
377{
378  $nav_bar = create_navigation_bar(
379    $base_url.get_query_string_diff(array('start')),
380    count($page['cat_elements_id']),
381    $page['start'],
382    $page['nb_images']
383    );
384  $template->assign_vars(array('NAV_BAR' => $nav_bar));
385
386  $query = '
387SELECT id,path,tn_ext
388  FROM '.IMAGES_TABLE.'
389  WHERE id IN ('.implode(',', $page['cat_elements_id']).')
390  '.$conf['order_by'].'
391  LIMIT '.$page['start'].', '.$page['nb_images'].'
392;';
393  //echo '<pre>'.$query.'</pre>';
394  $result = pwg_query($query);
395
396  // template thumbnail initialization
397  if (mysql_num_rows($result) > 0)
398  {
399    $template->assign_block_vars('thumbnails', array());
400  }
401
402  while ($row = mysql_fetch_array($result))
403  {
404    $src = get_thumbnail_src($row['path'], @$row['tn_ext']);
405
406    $template->assign_block_vars(
407      'thumbnails.thumbnail',
408      array(
409        'ID' => $row['id'],
410        'SRC' => $src,
411        'ALT' => 'TODO',
412        'TITLE' => 'TODO'
413        )
414      );
415  }
416}
417
418//----------------------------------------------------------- sending html code
419$template->assign_var_from_handle('ADMIN_CONTENT', 'element_set_global');
420?>
Note: See TracBrowser for help on using the repository browser.