source: trunk/admin/element_set_global.php @ 2641

Last change on this file since 2641 was 2576, checked in by plg, 16 years ago

bug 867 fixed: if the caddie is under management in admin/element_set,
dissociating any image from a category doesn't hide from the caddie.

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