source: trunk/admin/element_set_global.php @ 1958

Last change on this file since 1958 was 1958, checked in by rub, 17 years ago

Caddie:

Fix issue when the are not pictures attached to disassociated categories

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 10.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-2007 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | file          : $Id: element_set_global.php 1958 2007-04-14 12:32:01Z rub $
8// | last update   : $Date: 2007-04-14 12:32:01 +0000 (Sat, 14 Apr 2007) $
9// | last modifier : $Author: rub $
10// | revision      : $Revision: 1958 $
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
128    update_category($_POST['dissociate']);
129  }
130
131  $datas = array();
132  $dbfields = array('primary' => array('id'), 'update' => array());
133
134  $formfields = array('author', 'name', 'date_creation');
135  foreach ($formfields as $formfield)
136  {
137    if ($_POST[$formfield.'_action'] != 'leave')
138    {
139      array_push($dbfields['update'], $formfield);
140    }
141  }
142
143  // updating elements is useful only if needed...
144  if (count($dbfields['update']) > 0 and count($collection) > 0)
145  {
146    $query = '
147SELECT id
148  FROM '.IMAGES_TABLE.'
149  WHERE id IN ('.implode(',', $collection).')
150;';
151    $result = pwg_query($query);
152
153    while ($row = mysql_fetch_array($result))
154    {
155      $data = array();
156      $data['id'] = $row['id'];
157
158      if ('set' == $_POST['author_action'])
159      {
160        $data['author'] = $_POST['author'];
161
162        if ('' == $data['author'])
163        {
164          unset($data['author']);
165        }
166      }
167
168      if ('set' == $_POST['name_action'])
169      {
170        $data['name'] = $_POST['name'];
171
172        if ('' == $data['name'])
173        {
174          unset($data['name']);
175        }
176      }
177
178      if ('set' == $_POST['date_creation_action'])
179      {
180        $data['date_creation'] =
181          $_POST['date_creation_year']
182          .'-'.$_POST['date_creation_month']
183          .'-'.$_POST['date_creation_day']
184          ;
185      }
186
187      array_push($datas, $data);
188    }
189    // echo '<pre>'; print_r($datas); echo '</pre>';
190    mass_updates(IMAGES_TABLE, $dbfields, $datas);
191  }
192}
193
194// +-----------------------------------------------------------------------+
195// |                             template init                             |
196// +-----------------------------------------------------------------------+
197$template->set_filenames(
198  array('element_set_global' => 'admin/element_set_global.tpl'));
199
200$base_url = PHPWG_ROOT_PATH.'admin.php';
201
202// $form_action = $base_url.'?page=element_set_global';
203
204$template->assign_vars(
205  array(
206    'CATEGORIES_NAV'=>$page['title'],
207
208    'L_SUBMIT'=>$lang['submit'],
209
210    'U_DISPLAY'=>$base_url.get_query_string_diff(array('display')),
211
212    'U_UNIT_MODE'
213    =>
214    $base_url
215    .get_query_string_diff(array('mode','display'))
216    .'&amp;mode=unit',
217
218    'F_ACTION'=>$base_url.get_query_string_diff(array()),
219   )
220 );
221
222// +-----------------------------------------------------------------------+
223// |                            caddie options                             |
224// +-----------------------------------------------------------------------+
225
226if ('caddie' == $_GET['cat'])
227{
228  $template->assign_block_vars('in_caddie', array());
229}
230else
231{
232  $template->assign_block_vars('not_in_caddie', array());
233}
234
235// +-----------------------------------------------------------------------+
236// |                           global mode form                            |
237// +-----------------------------------------------------------------------+
238
239// Virtualy associate a picture to a category
240$blockname = 'associate_option';
241
242$template->assign_block_vars(
243  $blockname,
244  array('SELECTED' => '',
245        'VALUE'=> 0,
246        'OPTION' => '------------'
247    ));
248
249$query = '
250SELECT id,name,uppercats,global_rank
251  FROM '.CATEGORIES_TABLE.'
252;';
253display_select_cat_wrapper($query, array(), $blockname, true);
254
255// Dissociate from a category : categories listed for dissociation can
256// only represent virtual links. Links to physical categories can't be
257// broken
258$blockname = 'dissociate_option';
259
260$template->assign_block_vars(
261  $blockname,
262  array('SELECTED' => '',
263        'VALUE'=> 0,
264        'OPTION' => '------------'
265    ));
266
267if (count($page['cat_elements_id']) > 0)
268{
269  $query = '
270SELECT DISTINCT(category_id) AS id, c.name, uppercats, global_rank
271  FROM '.IMAGE_CATEGORY_TABLE.' AS ic,
272       '.CATEGORIES_TABLE.' AS c,
273       '.IMAGES_TABLE.' AS i
274  WHERE ic.image_id IN ('.implode(',', $page['cat_elements_id']).')
275    AND ic.category_id = c.id
276    AND ic.image_id = i.id
277    AND ic.category_id != i.storage_category_id
278;';
279  display_select_cat_wrapper($query, array(), $blockname, true);
280}
281
282$all_tags = get_all_tags();
283
284if (count($all_tags) == 0)
285{
286  $add_tag_selection =
287    '<p>'.
288    l10n('No tag defined. Use Administration>Pictures>Tags').
289    '</p>';
290}
291else
292{
293  $add_tag_selection = get_html_tag_selection(
294    $all_tags,
295    'add_tags'
296    );
297}
298
299// add tags
300$template->assign_vars(
301  array(
302    'ADD_TAG_SELECTION' => $add_tag_selection,
303    )
304  );
305
306if (count($page['cat_elements_id']) > 0)
307{
308  // remove tags
309  $tags = get_common_tags($page['cat_elements_id'], -1);
310  usort($tags, 'name_compare');
311
312  $template->assign_vars(
313    array(
314      'DEL_TAG_SELECTION' => get_html_tag_selection($tags, 'del_tags'),
315      )
316    );
317}
318// creation date
319$day =
320empty($_POST['date_creation_day']) ? date('j') : $_POST['date_creation_day'];
321get_day_list('date_creation_day', $day);
322
323if (!empty($_POST['date_creation_month']))
324{
325  $month = $_POST['date_creation_month'];
326}
327else
328{
329  $month = date('n');
330}
331get_month_list('date_creation_month', $month);
332
333if (!empty($_POST['date_creation_year']))
334{
335  $year = $_POST['date_creation_year'];
336}
337else
338{
339  $year = date('Y');
340}
341$template->assign_vars(array('DATE_CREATION_YEAR_VALUE'=>$year));
342
343// +-----------------------------------------------------------------------+
344// |                        global mode thumbnails                         |
345// +-----------------------------------------------------------------------+
346
347// how many items to display on this page
348if (!empty($_GET['display']))
349{
350  if ('all' == $_GET['display'])
351  {
352    $page['nb_images'] = count($page['cat_elements_id']);
353  }
354  else
355  {
356    $page['nb_images'] = intval($_GET['display']);
357  }
358}
359else
360{
361  $page['nb_images'] = 20;
362}
363
364if (count($page['cat_elements_id']) > 0)
365{
366  $nav_bar = create_navigation_bar(
367    $base_url.get_query_string_diff(array('start')),
368    count($page['cat_elements_id']),
369    $page['start'],
370    $page['nb_images']
371    );
372  $template->assign_vars(array('NAV_BAR' => $nav_bar));
373
374  $query = '
375SELECT id,path,tn_ext,file,filesize
376  FROM '.IMAGES_TABLE.'
377  WHERE id IN ('.implode(',', $page['cat_elements_id']).')
378  '.$conf['order_by'].'
379  LIMIT '.$page['start'].', '.$page['nb_images'].'
380;';
381  //echo '<pre>'.$query.'</pre>';
382  $result = pwg_query($query);
383
384  // template thumbnail initialization
385  if (mysql_num_rows($result) > 0)
386  {
387    $template->assign_block_vars('thumbnails', array());
388  }
389
390  while ($row = mysql_fetch_assoc($result))
391  {
392    $src = get_thumbnail_url($row);
393
394    $template->assign_block_vars(
395      'thumbnails.thumbnail',
396      array(
397        'ID' => $row['id'],
398        'SRC' => $src,
399        'ALT' => $row['file'],
400        'TITLE' => get_thumbnail_title($row)
401        )
402      );
403  }
404}
405
406//----------------------------------------------------------- sending html code
407$template->assign_var_from_handle('ADMIN_CONTENT', 'element_set_global');
408?>
Note: See TracBrowser for help on using the repository browser.