source: branches/2.6/admin/batch_manager_unit.php @ 26927

Last change on this file since 26927 was 26927, checked in by mistic100, 11 years ago

Merged revision(s) 26926 from trunk:
bug 3033: allow HTML in photo names from Batch Manager

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}
120
121// +-----------------------------------------------------------------------+
122// |                             template init                             |
123// +-----------------------------------------------------------------------+
124
125$template->set_filenames(
126  array('batch_manager_unit' => 'batch_manager_unit.tpl'));
127
128$base_url = PHPWG_ROOT_PATH.'admin.php';
129
130$month_list = $lang['month'];
131$month_list[0]='------------';
132ksort($month_list);
133
134$template->assign(
135  array(
136    'U_ELEMENTS_PAGE' => $base_url.get_query_string_diff(array('display','start')),
137    'F_ACTION'=>$base_url.get_query_string_diff(array()),   
138    'month_list' => $month_list,
139    'level_options' => get_privacy_level_options(),
140    )
141  );
142
143// +-----------------------------------------------------------------------+
144// |                        global mode thumbnails                         |
145// +-----------------------------------------------------------------------+
146
147// how many items to display on this page
148if (!empty($_GET['display']))
149{
150  if ('all' == $_GET['display'])
151  {
152    $page['nb_images'] = count($page['cat_elements_id']);
153  }
154  else
155  {
156    $page['nb_images'] = intval($_GET['display']);
157  }
158}
159else
160{
161  $page['nb_images'] = 5;
162}
163
164
165
166if (count($page['cat_elements_id']) > 0)
167{
168  $nav_bar = create_navigation_bar(
169    $base_url.get_query_string_diff(array('start')),
170    count($page['cat_elements_id']),
171    $page['start'],
172    $page['nb_images']
173    );
174  $template->assign(array('navbar' => $nav_bar));
175
176  $element_ids = array();
177
178  $is_category = false;
179  if (isset($_SESSION['bulk_manager_filter']['category'])
180      and !isset($_SESSION['bulk_manager_filter']['category_recursive']))
181  {
182    $is_category = true;
183  }
184
185  if (isset($_SESSION['bulk_manager_filter']['prefilter'])
186      and 'duplicates' == $_SESSION['bulk_manager_filter']['prefilter'])
187  {
188    $conf['order_by'] = ' ORDER BY file, id';
189  }
190
191
192  $query = '
193SELECT *
194  FROM '.IMAGES_TABLE;
195 
196  if ($is_category)
197  {
198    $category_info = get_cat_info($_SESSION['bulk_manager_filter']['category']);
199   
200    $conf['order_by'] = $conf['order_by_inside_category'];
201    if (!empty($category_info['image_order']))
202    {
203      $conf['order_by'] = ' ORDER BY '.$category_info['image_order'];
204    }
205
206    $query.= '
207    JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id';
208  }
209
210  $query.= '
211  WHERE id IN ('.implode(',', $page['cat_elements_id']).')';
212
213  if ($is_category)
214  {
215    $query.= '
216    AND category_id = '.$_SESSION['bulk_manager_filter']['category'];
217  }
218
219  $query.= '
220  '.$conf['order_by'].'
221  LIMIT '.$page['nb_images'].' OFFSET '.$page['start'].'
222;';
223  $result = pwg_query($query);
224
225  while ($row = pwg_db_fetch_assoc($result))
226  {
227    $element_ids[] = $row['id'];
228
229    $src_image = new SrcImage($row);
230
231    // creation date
232    if (!empty($row['date_creation']))
233    {
234      list($year,$month,$day) = explode('-', $row['date_creation']);
235    }
236    else
237    {
238      list($year,$month,$day) = array('',0,0);
239    }
240
241    $query = '
242SELECT
243    id,
244    name
245  FROM '.IMAGE_TAG_TABLE.' AS it
246    JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id
247  WHERE image_id = '.$row['id'].'
248;';
249    $tag_selection = get_taglist($query);
250
251    $legend = render_element_name($row);
252    if ($legend != get_name_from_file($row['file']))
253    {
254      $legend.= ' ('.$row['file'].')';
255    }
256
257    $template->append(
258      'elements', array_merge($row,
259      array(
260        'ID' => $row['id'],
261        'TN_SRC' => DerivativeImage::url(IMG_THUMB, $src_image),
262        'FILE_SRC' => DerivativeImage::url(IMG_LARGE, $src_image),
263        'LEGEND' => $legend,
264        'U_EDIT' => get_root_url().'admin.php?page=photo-'.$row['id'],
265        'NAME' => htmlspecialchars(@$row['name']),
266        'AUTHOR' => htmlspecialchars(@$row['author']),
267        'LEVEL' => !empty($row['level'])?$row['level']:'0',
268        'DESCRIPTION' => htmlspecialchars(@$row['comment']),
269        'DATE_CREATION_YEAR' => $year,
270        'DATE_CREATION_MONTH' => (int)$month,
271        'DATE_CREATION_DAY' => (int)$day,
272        'TAGS' => $tag_selection,
273        )
274      ));
275  }
276
277  $template->assign('ELEMENT_IDS', implode(',', $element_ids));
278}
279
280trigger_action('loc_end_element_set_unit');
281
282// +-----------------------------------------------------------------------+
283// |                           sending html code                           |
284// +-----------------------------------------------------------------------+
285
286$template->assign_var_from_handle('ADMIN_CONTENT', 'batch_manager_unit');
287?>
Note: See TracBrowser for help on using the repository browser.