source: trunk/admin/element_set_global.php @ 2632

Last change on this file since 2632 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
RevLine 
[755]1<?php
2// +-----------------------------------------------------------------------+
[2297]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// +-----------------------------------------------------------------------+
[755]23
24/**
25 * Management of elements set. Elements can belong to a category or to the
26 * user caddie.
[1092]27 *
[755]28 */
[1092]29
[755]30if (!defined('PHPWG_ROOT_PATH'))
31{
32  die('Hacking attempt!');
33}
34
[1072]35include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
36
[755]37// +-----------------------------------------------------------------------+
[1072]38// | Check Access and exit when user status is not ok                      |
39// +-----------------------------------------------------------------------+
40check_status(ACCESS_ADMINISTRATOR);
41
42// +-----------------------------------------------------------------------+
[755]43// |                       global mode form submission                     |
44// +-----------------------------------------------------------------------+
45
46if (isset($_POST['submit']))
47{
48  $collection = array();
[1092]49
[755]50//   echo '<pre>';
[762]51//   print_r($_POST);
[755]52//   echo '</pre>';
53//   exit();
54
55  switch ($_POST['target'])
56  {
57    case 'all' :
58    {
[764]59      $collection = $page['cat_elements_id'];
[755]60      break;
61    }
62    case 'selection' :
63    {
[875]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      }
[755]72      break;
73    }
74  }
75
[1119]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  }
[1120]91
[875]92  if ($_POST['associate'] != 0 and count($collection) > 0)
[755]93  {
[1121]94    associate_images_to_categories(
95      $collection,
96      array($_POST['associate'])
97      );
[755]98  }
99
[875]100  if ($_POST['dissociate'] != 0 and count($collection) > 0)
[755]101  {
[1121]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".
[755]104    $query = '
[1121]105SELECT id
[1065]106  FROM '.IMAGE_CATEGORY_TABLE.'
[1121]107    INNER JOIN '.IMAGES_TABLE.' ON image_id = id
[755]108  WHERE category_id = '.$_POST['dissociate'].'
[1121]109    AND id IN ('.implode(',', $collection).')
[2575]110    AND (
111      category_id != storage_category_id
112      OR storage_category_id IS NULL
113    )
[755]114;';
[1121]115    $dissociables = array_from_query($query, 'id');
[755]116
[2003]117    if (!empty($dissociables))
118    {
119      $query = '
[1065]120DELETE
121  FROM '.IMAGE_CATEGORY_TABLE.'
[1121]122  WHERE category_id = '.$_POST['dissociate'].'
123    AND image_id IN ('.implode(',', $dissociables).')
[755]124';
[2003]125      pwg_query($query);
[1609]126
[2576]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      }
[2003]136    }
137
[1121]138    update_category($_POST['dissociate']);
[755]139  }
[762]140
141  $datas = array();
142  $dbfields = array('primary' => array('id'), 'update' => array());
143
[2084]144  $formfields = array('author', 'name', 'date_creation', 'level');
[762]145  foreach ($formfields as $formfield)
146  {
147    if ($_POST[$formfield.'_action'] != 'leave')
148    {
149      array_push($dbfields['update'], $formfield);
150    }
151  }
[1092]152
[762]153  // updating elements is useful only if needed...
[875]154  if (count($dbfields['update']) > 0 and count($collection) > 0)
[762]155  {
156    $query = '
[1119]157SELECT id
[762]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'];
[1092]167
[762]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      }
[1092]194
[2084]195      if ('set' == $_POST['level_action'])
196      {
197        $data['level'] = $_POST['level'];
198      }
199
[762]200      array_push($datas, $data);
201    }
[763]202    // echo '<pre>'; print_r($datas); echo '</pre>';
[762]203    mass_updates(IMAGES_TABLE, $dbfields, $datas);
204  }
[755]205}
206
207// +-----------------------------------------------------------------------+
208// |                             template init                             |
209// +-----------------------------------------------------------------------+
210$template->set_filenames(
[2530]211  array('element_set_global' => 'element_set_global.tpl'));
[755]212
[2249]213$base_url = get_root_url().'admin.php';
[755]214
[762]215// $form_action = $base_url.'?page=element_set_global';
216
[2249]217$template->assign(
[755]218  array(
[834]219    'CATEGORIES_NAV'=>$page['title'],
[1092]220
[764]221    'U_DISPLAY'=>$base_url.get_query_string_diff(array('display')),
[1092]222
[764]223    'U_UNIT_MODE'
224    =>
225    $base_url
226    .get_query_string_diff(array('mode','display'))
227    .'&amp;mode=unit',
[1092]228
[762]229    'F_ACTION'=>$base_url.get_query_string_diff(array()),
[755]230   )
231 );
[764]232
[755]233// +-----------------------------------------------------------------------+
[764]234// |                            caddie options                             |
235// +-----------------------------------------------------------------------+
236
[2249]237$template->assign('IN_CADDIE', 'caddie' == $_GET['cat'] ? true : false );
[764]238
239// +-----------------------------------------------------------------------+
[755]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;';
[2249]248display_select_cat_wrapper($query, array(), 'associate_options', true);
[755]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
[764]253if (count($page['cat_elements_id']) > 0)
254{
255  $query = '
[2575]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
[764]264  WHERE ic.image_id IN ('.implode(',', $page['cat_elements_id']).')
[2575]265    AND (
266      ic.category_id != i.storage_category_id
267      OR i.storage_category_id IS NULL
268    )
[755]269;';
[2249]270  display_select_cat_wrapper($query, array(), 'dissociate_options', true);
[764]271}
[755]272
[1314]273$all_tags = get_all_tags();
274
[2249]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      )
[1314]284    );
285}
286
[1120]287if (count($page['cat_elements_id']) > 0)
[762]288{
[1120]289  // remove tags
[1815]290  $tags = get_common_tags($page['cat_elements_id'], -1);
[1310]291
[2249]292  $template->assign(
[1120]293    array(
294      'DEL_TAG_SELECTION' => get_html_tag_selection($tags, 'del_tags'),
295      )
296    );
297}
[2249]298
[762]299// creation date
300$day =
301empty($_POST['date_creation_day']) ? date('j') : $_POST['date_creation_day'];
302
[2249]303$month =
304empty($_POST['date_creation_month']) ? date('n') : $_POST['date_creation_month'];
[762]305
[2249]306$year =
307empty($_POST['date_creation_year']) ? date('Y') : $_POST['date_creation_year'];
[762]308
[2249]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
[2084]320// image level options
[2249]321$tpl_options = array();
[2084]322foreach ($conf['available_permission_levels'] as $level)
323{
[2249]324  $tpl_options[$level] = l10n( sprintf('Level %d', $level) );
325}
326$template->assign(
[2084]327    array(
[2249]328      'level_options'=> $tpl_options,
329    )
330  );
[2084]331
[755]332// +-----------------------------------------------------------------------+
333// |                        global mode thumbnails                         |
334// +-----------------------------------------------------------------------+
335
[875]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
[764]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'],
[1084]359    $page['nb_images']
360    );
[2249]361  $template->assign('NAV_BAR', $nav_bar);
[764]362
363  $query = '
[2084]364SELECT id,path,tn_ext,file,filesize,level
[764]365  FROM '.IMAGES_TABLE.'
366  WHERE id IN ('.implode(',', $page['cat_elements_id']).')
[755]367  '.$conf['order_by'].'
[764]368  LIMIT '.$page['start'].', '.$page['nb_images'].'
[755]369;';
[764]370  //echo '<pre>'.$query.'</pre>';
371  $result = pwg_query($query);
[755]372
[764]373  // template thumbnail initialization
[755]374
[1609]375  while ($row = mysql_fetch_assoc($result))
[755]376  {
[1609]377    $src = get_thumbnail_url($row);
[1092]378
[2249]379    $template->append(
380      'thumbnails',
[764]381      array(
382        'ID' => $row['id'],
[2249]383        'TN_SRC' => $src,
384        'FILE' => $row['file'],
385        'TITLE' => get_thumbnail_title($row),
386        'LEVEL' => $row['level']
[764]387        )
388      );
[755]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.