source: trunk/admin/batch_manager_unit.php @ 28490

Last change on this file since 28490 was 28490, checked in by rvelices, 10 years ago
  • dont't invalidate_user_cache on batch manager refresh photo set or add/remove caddie or generate/delete derivatives
  • removed double sql query from batch_manager_global
File size: 8.4 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2014 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
42trigger_action('loc_begin_element_set_unit');
43
44// +-----------------------------------------------------------------------+
45// |                        unit mode form submission                      |
46// +-----------------------------------------------------------------------+
47
48if (isset($_POST['submit']))
49{
50  $collection = explode(',', $_POST['element_ids']);
51
52  $datas = array();
53
54  $query = '
55SELECT id, date_creation
56  FROM '.IMAGES_TABLE.'
57  WHERE id IN ('.implode(',', $collection).')
58;';
59  $result = pwg_query($query);
60
61  while ($row = pwg_db_fetch_assoc($result))
62  {
63    $data = array();
64
65    $data['id'] = $row['id'];
66    $data['name'] = $_POST['name-'.$row['id']];
67    $data['author'] = $_POST['author-'.$row['id']];
68    $data['level'] = $_POST['level-'.$row['id']];
69
70    if ($conf['allow_html_descriptions'])
71    {
72      $data['comment'] = @$_POST['description-'.$row['id']];
73    }
74    else
75    {
76      $data['comment'] = strip_tags(@$_POST['description-'.$row['id']]);
77    }
78
79    if (isset($_POST['date_creation_action-'.$row['id']]))
80    {
81      if ('set' == $_POST['date_creation_action-'.$row['id']])
82      {
83        $data['date_creation'] =
84          $_POST['date_creation_year-'.$row['id']]
85            .'-'.$_POST['date_creation_month-'.$row['id']]
86            .'-'.$_POST['date_creation_day-'.$row['id']];
87      }
88      else if ('unset' == $_POST['date_creation_action-'.$row['id']])
89      {
90        $data['date_creation'] = '';
91      }
92    }
93    else
94    {
95      $data['date_creation'] = $row['date_creation'];
96    }
97
98    $datas[] = $data;
99
100    // tags management
101    $tag_ids = array();
102    if (!empty($_POST[ 'tags-'.$row['id'] ]))
103    {
104      $tag_ids = get_tag_ids($_POST[ 'tags-'.$row['id'] ]);
105    }
106    set_tags($tag_ids, $row['id']);
107  }
108
109  mass_updates(
110    IMAGES_TABLE,
111    array(
112      'primary' => array('id'),
113      'update' => array('name','author','level','comment','date_creation')
114      ),
115    $datas
116    );
117
118  $page['infos'][] = l10n('Photo informations updated');
119  invalidate_user_cache();
120}
121
122// +-----------------------------------------------------------------------+
123// |                             template init                             |
124// +-----------------------------------------------------------------------+
125
126$template->set_filenames(
127  array('batch_manager_unit' => 'batch_manager_unit.tpl'));
128
129$base_url = PHPWG_ROOT_PATH.'admin.php';
130
131$month_list = $lang['month'];
132$month_list[0]='------------';
133ksort($month_list);
134
135$template->assign(
136  array(
137    'U_ELEMENTS_PAGE' => $base_url.get_query_string_diff(array('display','start')),
138    'F_ACTION'=>$base_url.get_query_string_diff(array()),
139    'month_list' => $month_list,
140    'level_options' => get_privacy_level_options(),
141    )
142  );
143
144// +-----------------------------------------------------------------------+
145// |                        global mode thumbnails                         |
146// +-----------------------------------------------------------------------+
147
148// how many items to display on this page
149if (!empty($_GET['display']))
150{
151  if ('all' == $_GET['display'])
152  {
153    $page['nb_images'] = count($page['cat_elements_id']);
154  }
155  else
156  {
157    $page['nb_images'] = intval($_GET['display']);
158  }
159}
160else
161{
162  $page['nb_images'] = 5;
163}
164
165
166
167if (count($page['cat_elements_id']) > 0)
168{
169  $nav_bar = create_navigation_bar(
170    $base_url.get_query_string_diff(array('start')),
171    count($page['cat_elements_id']),
172    $page['start'],
173    $page['nb_images']
174    );
175  $template->assign(array('navbar' => $nav_bar));
176
177  $element_ids = array();
178
179  $is_category = false;
180  if (isset($_SESSION['bulk_manager_filter']['category'])
181      and !isset($_SESSION['bulk_manager_filter']['category_recursive']))
182  {
183    $is_category = true;
184  }
185
186  if (isset($_SESSION['bulk_manager_filter']['prefilter'])
187      and 'duplicates' == $_SESSION['bulk_manager_filter']['prefilter'])
188  {
189    $conf['order_by'] = ' ORDER BY file, id';
190  }
191
192
193  $query = '
194SELECT *
195  FROM '.IMAGES_TABLE;
196
197  if ($is_category)
198  {
199    $category_info = get_cat_info($_SESSION['bulk_manager_filter']['category']);
200
201    $conf['order_by'] = $conf['order_by_inside_category'];
202    if (!empty($category_info['image_order']))
203    {
204      $conf['order_by'] = ' ORDER BY '.$category_info['image_order'];
205    }
206
207    $query.= '
208    JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id';
209  }
210
211  $query.= '
212  WHERE id IN ('.implode(',', $page['cat_elements_id']).')';
213
214  if ($is_category)
215  {
216    $query.= '
217    AND category_id = '.$_SESSION['bulk_manager_filter']['category'];
218  }
219
220  $query.= '
221  '.$conf['order_by'].'
222  LIMIT '.$page['nb_images'].' OFFSET '.$page['start'].'
223;';
224  $result = pwg_query($query);
225
226  while ($row = pwg_db_fetch_assoc($result))
227  {
228    $element_ids[] = $row['id'];
229
230    $src_image = new SrcImage($row);
231
232    // creation date
233    if (!empty($row['date_creation']))
234    {
235      list($year,$month,$day) = explode('-', $row['date_creation']);
236    }
237    else
238    {
239      list($year,$month,$day) = array('',0,0);
240    }
241
242    $query = '
243SELECT
244    id,
245    name
246  FROM '.IMAGE_TAG_TABLE.' AS it
247    JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id
248  WHERE image_id = '.$row['id'].'
249;';
250    $tag_selection = get_taglist($query);
251
252    $legend = render_element_name($row);
253    if ($legend != get_name_from_file($row['file']))
254    {
255      $legend.= ' ('.$row['file'].')';
256    }
257
258    $template->append(
259      'elements', array_merge($row,
260      array(
261        'ID' => $row['id'],
262        'TN_SRC' => DerivativeImage::url(IMG_THUMB, $src_image),
263        'FILE_SRC' => DerivativeImage::url(IMG_LARGE, $src_image),
264        'LEGEND' => $legend,
265        'U_EDIT' => get_root_url().'admin.php?page=photo-'.$row['id'],
266        'NAME' => htmlspecialchars(@$row['name']),
267        'AUTHOR' => htmlspecialchars(@$row['author']),
268        'LEVEL' => !empty($row['level'])?$row['level']:'0',
269        'DESCRIPTION' => htmlspecialchars(@$row['comment']),
270        'DATE_CREATION_YEAR' => $year,
271        'DATE_CREATION_MONTH' => (int)$month,
272        'DATE_CREATION_DAY' => (int)$day,
273        'TAGS' => $tag_selection,
274        )
275      ));
276  }
277
278  $template->assign('ELEMENT_IDS', implode(',', $element_ids));
279}
280
281trigger_action('loc_end_element_set_unit');
282
283// +-----------------------------------------------------------------------+
284// |                           sending html code                           |
285// +-----------------------------------------------------------------------+
286
287$template->assign_var_from_handle('ADMIN_CONTENT', 'batch_manager_unit');
288?>
Note: See TracBrowser for help on using the repository browser.