source: branches/2.2/admin/batch_manager_unit.php @ 11193

Last change on this file since 11193 was 11193, checked in by mistic100, 13 years ago

merge r11192 from trunk : mysql warning if tag field is empty

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