source: trunk/admin/element_set_global.php @ 2032

Last change on this file since 2032 was 2003, checked in by plg, 17 years ago

Bug 538 fixed: when managing elements of a virtual category, dissociating
some elements of the current category now instantly removes the elements of
the element list.

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