source: trunk/admin/batch_manager_unit.php @ 28980

Last change on this file since 28980 was 28587, checked in by mistic100, 10 years ago

feature 3010 : replace trigger_action/event by trigger_notify/change

File size: 7.8 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_notify('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 (!empty($_POST['date_creation-'.$row['id']]))
80    {
81      $data['date_creation'] = $_POST['date_creation-'.$row['id']];
82    }
83    else
84    {
85      $data['date_creation'] = null;
86    }
87
88    $datas[] = $data;
89
90    // tags management
91    $tag_ids = array();
92    if (!empty($_POST[ 'tags-'.$row['id'] ]))
93    {
94      $tag_ids = get_tag_ids($_POST[ 'tags-'.$row['id'] ]);
95    }
96    set_tags($tag_ids, $row['id']);
97  }
98
99  mass_updates(
100    IMAGES_TABLE,
101    array(
102      'primary' => array('id'),
103      'update' => array('name','author','level','comment','date_creation')
104      ),
105    $datas
106    );
107
108  $page['infos'][] = l10n('Photo informations updated');
109  invalidate_user_cache();
110}
111
112// +-----------------------------------------------------------------------+
113// |                             template init                             |
114// +-----------------------------------------------------------------------+
115
116$template->set_filenames(
117  array('batch_manager_unit' => 'batch_manager_unit.tpl'));
118
119$base_url = PHPWG_ROOT_PATH.'admin.php';
120
121$template->assign(
122  array(
123    'U_ELEMENTS_PAGE' => $base_url.get_query_string_diff(array('display','start')),
124    'F_ACTION' => $base_url.get_query_string_diff(array()),
125    'level_options' => get_privacy_level_options(),
126    )
127  );
128
129// +-----------------------------------------------------------------------+
130// |                        global mode thumbnails                         |
131// +-----------------------------------------------------------------------+
132
133// how many items to display on this page
134if (!empty($_GET['display']))
135{
136  if ('all' == $_GET['display'])
137  {
138    $page['nb_images'] = count($page['cat_elements_id']);
139  }
140  else
141  {
142    $page['nb_images'] = intval($_GET['display']);
143  }
144}
145else
146{
147  $page['nb_images'] = 5;
148}
149
150
151
152if (count($page['cat_elements_id']) > 0)
153{
154  $nav_bar = create_navigation_bar(
155    $base_url.get_query_string_diff(array('start')),
156    count($page['cat_elements_id']),
157    $page['start'],
158    $page['nb_images']
159    );
160  $template->assign(array('navbar' => $nav_bar));
161
162  $element_ids = array();
163
164  $is_category = false;
165  if (isset($_SESSION['bulk_manager_filter']['category'])
166      and !isset($_SESSION['bulk_manager_filter']['category_recursive']))
167  {
168    $is_category = true;
169  }
170
171  if (isset($_SESSION['bulk_manager_filter']['prefilter'])
172      and 'duplicates' == $_SESSION['bulk_manager_filter']['prefilter'])
173  {
174    $conf['order_by'] = ' ORDER BY file, id';
175  }
176
177
178  $query = '
179SELECT *
180  FROM '.IMAGES_TABLE;
181
182  if ($is_category)
183  {
184    $category_info = get_cat_info($_SESSION['bulk_manager_filter']['category']);
185
186    $conf['order_by'] = $conf['order_by_inside_category'];
187    if (!empty($category_info['image_order']))
188    {
189      $conf['order_by'] = ' ORDER BY '.$category_info['image_order'];
190    }
191
192    $query.= '
193    JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id';
194  }
195
196  $query.= '
197  WHERE id IN ('.implode(',', $page['cat_elements_id']).')';
198
199  if ($is_category)
200  {
201    $query.= '
202    AND category_id = '.$_SESSION['bulk_manager_filter']['category'];
203  }
204
205  $query.= '
206  '.$conf['order_by'].'
207  LIMIT '.$page['nb_images'].' OFFSET '.$page['start'].'
208;';
209  $result = pwg_query($query);
210
211  while ($row = pwg_db_fetch_assoc($result))
212  {
213    $element_ids[] = $row['id'];
214
215    $src_image = new SrcImage($row);
216
217    $query = '
218SELECT
219    id,
220    name
221  FROM '.IMAGE_TAG_TABLE.' AS it
222    JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id
223  WHERE image_id = '.$row['id'].'
224;';
225    $tag_selection = get_taglist($query);
226
227    $legend = render_element_name($row);
228    if ($legend != get_name_from_file($row['file']))
229    {
230      $legend.= ' ('.$row['file'].')';
231    }
232
233    $template->append(
234      'elements', array_merge($row,
235      array(
236        'ID' => $row['id'],
237        'TN_SRC' => DerivativeImage::url(IMG_THUMB, $src_image),
238        'FILE_SRC' => DerivativeImage::url(IMG_LARGE, $src_image),
239        'LEGEND' => $legend,
240        'U_EDIT' => get_root_url().'admin.php?page=photo-'.$row['id'],
241        'NAME' => htmlspecialchars(@$row['name']),
242        'AUTHOR' => htmlspecialchars(@$row['author']),
243        'LEVEL' => !empty($row['level'])?$row['level']:'0',
244        'DESCRIPTION' => htmlspecialchars(@$row['comment']),
245        'DATE_CREATION' => $row['date_creation'],
246        'TAGS' => $tag_selection,
247        )
248      ));
249  }
250
251  $template->assign(array(
252    'ELEMENT_IDS' => implode(',', $element_ids),
253    'CACHE_KEYS' => get_admin_client_cache_keys(array('tags')),
254    ));
255}
256
257trigger_notify('loc_end_element_set_unit');
258
259// +-----------------------------------------------------------------------+
260// |                           sending html code                           |
261// +-----------------------------------------------------------------------+
262
263$template->assign_var_from_handle('ADMIN_CONTENT', 'batch_manager_unit');
264?>
Note: See TracBrowser for help on using the repository browser.