1<?php
2// +-----------------------------------------------------------------------+
3// | This file is part of Piwigo.                                          |
4// |                                                                       |
5// | For copyright and license information, please view the COPYING.txt    |
6// | file that was distributed with this source code.                      |
7// +-----------------------------------------------------------------------+
8
9/**
10 * Management of elements set. Elements can belong to a category or to the
11 * user caddie.
12 *
13 */
14
15if (!defined('PHPWG_ROOT_PATH'))
16{
17  die('Hacking attempt!');
18}
19
20include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
21
22// +-----------------------------------------------------------------------+
23// | Check Access and exit when user status is not ok                      |
24// +-----------------------------------------------------------------------+
25check_status(ACCESS_ADMINISTRATOR);
26
27trigger_notify('loc_begin_element_set_unit');
28
29// +-----------------------------------------------------------------------+
30// |                        unit mode form submission                      |
31// +-----------------------------------------------------------------------+
32
33if (isset($_POST['submit']))
34{
35  check_input_parameter('element_ids', $_POST, false, '/^\d+(,\d+)*$/');
36  $collection = explode(',', $_POST['element_ids']);
37
38  $datas = array();
39
40  $query = '
41SELECT id, date_creation
42  FROM '.IMAGES_TABLE.'
43  WHERE id IN ('.implode(',', $collection).')
44;';
45  $result = pwg_query($query);
46
47  while ($row = pwg_db_fetch_assoc($result))
48  {
49    $data = array();
50
51    $data['id'] = $row['id'];
52    $data['name'] = $_POST['name-'.$row['id']];
53    $data['author'] = $_POST['author-'.$row['id']];
54    $data['level'] = $_POST['level-'.$row['id']];
55
56    if ($conf['allow_html_descriptions'])
57    {
58      $data['comment'] = @$_POST['description-'.$row['id']];
59    }
60    else
61    {
62      $data['comment'] = strip_tags(@$_POST['description-'.$row['id']]);
63    }
64
65    if (!empty($_POST['date_creation-'.$row['id']]))
66    {
67      $data['date_creation'] = $_POST['date_creation-'.$row['id']];
68    }
69    else
70    {
71      $data['date_creation'] = null;
72    }
73
74    $datas[] = $data;
75
76    // tags management
77    $tag_ids = array();
78    if (!empty($_POST[ 'tags-'.$row['id'] ]))
79    {
80      $tag_ids = get_tag_ids($_POST[ 'tags-'.$row['id'] ]);
81    }
82    set_tags($tag_ids, $row['id']);
83  }
84
85  mass_updates(
86    IMAGES_TABLE,
87    array(
88      'primary' => array('id'),
89      'update' => array('name','author','level','comment','date_creation')
90      ),
91    $datas
92    );
93
94  $page['infos'][] = l10n('Photo informations updated');
95  invalidate_user_cache();
96}
97
98// +-----------------------------------------------------------------------+
99// |                             template init                             |
100// +-----------------------------------------------------------------------+
101
102$template->set_filenames(
103  array('batch_manager_unit' => 'batch_manager_unit.tpl'));
104
105$base_url = PHPWG_ROOT_PATH.'admin.php';
106
107$template->assign(
108  array(
109    'U_ELEMENTS_PAGE' => $base_url.get_query_string_diff(array('display','start')),
110    'F_ACTION' => $base_url.get_query_string_diff(array()),
111    'level_options' => get_privacy_level_options(),
112    )
113  );
114
115// +-----------------------------------------------------------------------+
116// |                        global mode thumbnails                         |
117// +-----------------------------------------------------------------------+
118
119// how many items to display on this page
120if (!empty($_GET['display']))
121{
122  $page['nb_images'] = intval($_GET['display']);
123}
124elseif (in_array($conf['batch_manager_images_per_page_unit'], array(5, 10, 50)))
125{
126  $page['nb_images'] = $conf['batch_manager_images_per_page_unit'];
127}
128else
129{
130  $page['nb_images'] = 5;
131}
132
133
134
135if (count($page['cat_elements_id']) > 0)
136{
137  $nav_bar = create_navigation_bar(
138    $base_url.get_query_string_diff(array('start')),
139    count($page['cat_elements_id']),
140    $page['start'],
141    $page['nb_images']
142    );
143  $template->assign(array('navbar' => $nav_bar));
144
145  $element_ids = array();
146
147  $is_category = false;
148  if (isset($_SESSION['bulk_manager_filter']['category'])
149      and !isset($_SESSION['bulk_manager_filter']['category_recursive']))
150  {
151    $is_category = true;
152  }
153
154  if (isset($_SESSION['bulk_manager_filter']['prefilter'])
155      and 'duplicates' == $_SESSION['bulk_manager_filter']['prefilter'])
156  {
157    $conf['order_by'] = ' ORDER BY file, id';
158  }
159
160
161  $query = '
162SELECT *
163  FROM '.IMAGES_TABLE;
164
165  if ($is_category)
166  {
167    $category_info = get_cat_info($_SESSION['bulk_manager_filter']['category']);
168
169    $conf['order_by'] = $conf['order_by_inside_category'];
170    if (!empty($category_info['image_order']))
171    {
172      $conf['order_by'] = ' ORDER BY '.$category_info['image_order'];
173    }
174
175    $query.= '
176    JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id';
177  }
178
179  $query.= '
180  WHERE id IN ('.implode(',', $page['cat_elements_id']).')';
181
182  if ($is_category)
183  {
184    $query.= '
185    AND category_id = '.$_SESSION['bulk_manager_filter']['category'];
186  }
187
188  $query.= '
189  '.$conf['order_by'].'
190  LIMIT '.$page['nb_images'].' OFFSET '.$page['start'].'
191;';
192  $result = pwg_query($query);
193
194  while ($row = pwg_db_fetch_assoc($result))
195  {
196    $element_ids[] = $row['id'];
197
198    $src_image = new SrcImage($row);
199
200    $query = '
201SELECT
202    id,
203    name
204  FROM '.IMAGE_TAG_TABLE.' AS it
205    JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id
206  WHERE image_id = '.$row['id'].'
207;';
208    $tag_selection = get_taglist($query);
209
210    $legend = render_element_name($row);
211    if ($legend != get_name_from_file($row['file']))
212    {
213      $legend.= ' ('.$row['file'].')';
214    }
215
216    $template->append(
217      'elements', array_merge($row,
218      array(
219        'ID' => $row['id'],
220        'TN_SRC' => DerivativeImage::url(IMG_THUMB, $src_image),
221        'FILE_SRC' => DerivativeImage::url(IMG_LARGE, $src_image),
222        'LEGEND' => $legend,
223        'U_EDIT' => get_root_url().'admin.php?page=photo-'.$row['id'],
224        'NAME' => htmlspecialchars(@$row['name']),
225        'AUTHOR' => htmlspecialchars(@$row['author']),
226        'LEVEL' => !empty($row['level'])?$row['level']:'0',
227        'DESCRIPTION' => htmlspecialchars(@$row['comment']),
228        'DATE_CREATION' => $row['date_creation'],
229        'TAGS' => $tag_selection,
230        )
231      ));
232  }
233
234  $template->assign(array(
235    'ELEMENT_IDS' => implode(',', $element_ids),
236    'CACHE_KEYS' => get_admin_client_cache_keys(array('tags')),
237    ));
238}
239
240trigger_notify('loc_end_element_set_unit');
241
242// +-----------------------------------------------------------------------+
243// |                           sending html code                           |
244// +-----------------------------------------------------------------------+
245
246$template->assign_var_from_handle('ADMIN_CONTENT', 'batch_manager_unit');
247?>
248