source: trunk/admin/element_set_unit.php @ 4331

Last change on this file since 4331 was 4331, checked in by nikrou, 14 years ago

Feature 1255 : improve sql
Replace in queries LIMIT N,M by LIMIT N OFFSET M

  • Property svn:eol-style set to LF
File size: 7.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2009 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
42// +-----------------------------------------------------------------------+
43// |                        unit mode form submission                      |
44// +-----------------------------------------------------------------------+
45
46if (isset($_POST['submit']))
47{
48  $collection = explode(',', $_POST['element_ids']);
49
50  $datas = array();
51
52  $query = '
53SELECT id, date_creation
54  FROM '.IMAGES_TABLE.'
55  WHERE id IN ('.implode(',', $collection).')
56;';
57  $result = pwg_query($query);
58
59  while ($row = pwg_db_fetch_assoc($result))
60  {
61    $data = array();
62
63    $data{'id'} = $row['id'];
64    $data{'name'} = $_POST['name-'.$row['id']];
65    $data{'author'} = $_POST['author-'.$row['id']];
66
67    foreach (array('name', 'author') as $field)
68    {
69      if (!empty($_POST[$field.'-'.$row['id']]))
70      {
71        $data{$field} = strip_tags($_POST[$field.'-'.$row['id']]);
72      }
73    }
74
75    if ($conf['allow_html_descriptions'])
76    {
77      $data{'comment'} = @$_POST['description-'.$row['id']];
78    }
79    else
80    {
81      $data{'comment'} = strip_tags(@$_POST['description-'.$row['id']]);
82    }
83
84    if (isset($_POST['date_creation_action-'.$row['id']]))
85    {
86      if ('set' == $_POST['date_creation_action-'.$row['id']])
87      {
88        $data{'date_creation'} =
89          $_POST['date_creation_year-'.$row['id']]
90            .'-'.$_POST['date_creation_month-'.$row['id']]
91            .'-'.$_POST['date_creation_day-'.$row['id']];
92      }
93      else if ('unset' == $_POST['date_creation_action-'.$row['id']])
94      {
95        $data{'date_creation'} = '';
96      }
97    }
98    else
99    {
100      $data{'date_creation'} = $row['date_creation'];
101    }
102
103    array_push($datas, $data);
104
105    // tags management
106    if (isset($_POST[ 'tags-'.$row['id'] ]))
107    {
108      set_tags($_POST[ 'tags-'.$row['id'] ], $row['id']);
109    }
110  }
111
112  mass_updates(
113    IMAGES_TABLE,
114    array(
115      'primary' => array('id'),
116      'update' => array('name','author','comment','date_creation')
117      ),
118    $datas
119    );
120
121  array_push($page['infos'], l10n('Picture informations updated'));
122}
123
124// +-----------------------------------------------------------------------+
125// |                             template init                             |
126// +-----------------------------------------------------------------------+
127
128$template->set_filenames(
129  array('element_set_unit' => 'element_set_unit.tpl'));
130
131$base_url = PHPWG_ROOT_PATH.'admin.php';
132
133$month_list = $lang['month'];
134$month_list[0]='------------';
135ksort($month_list);
136
137$template->assign(
138  array(
139    'CATEGORIES_NAV'=>$page['title'],
140
141    'U_ELEMENTS_PAGE'
142    =>$base_url.get_query_string_diff(array('display','start')),
143
144    'U_GLOBAL_MODE'
145    =>
146    $base_url
147    .get_query_string_diff(array('mode','display'))
148    .'&amp;mode=global',
149
150    'F_ACTION'=>$base_url.get_query_string_diff(array()),
151   
152    'month_list' => $month_list
153    )
154  );
155
156// +-----------------------------------------------------------------------+
157// |                        global mode thumbnails                         |
158// +-----------------------------------------------------------------------+
159
160// how many items to display on this page
161if (!empty($_GET['display']))
162{
163  if ('all' == $_GET['display'])
164  {
165    $page['nb_images'] = count($page['cat_elements_id']);
166  }
167  else
168  {
169    $page['nb_images'] = intval($_GET['display']);
170  }
171}
172else
173{
174  $page['nb_images'] = 5;
175}
176
177
178
179if (count($page['cat_elements_id']) > 0)
180{
181  $nav_bar = create_navigation_bar(
182    $base_url.get_query_string_diff(array('start')),
183    count($page['cat_elements_id']),
184    $page['start'],
185    $page['nb_images']
186    );
187  $template->assign(array('navbar' => $nav_bar));
188
189  // tags
190  $all_tags = get_all_tags();
191
192  $element_ids = array();
193
194  $query = '
195SELECT id,path,tn_ext,name,date_creation,comment,author,file
196  FROM '.IMAGES_TABLE.'
197  WHERE id IN ('.implode(',', $page['cat_elements_id']).')
198  '.$conf['order_by'].'
199  LIMIT '.$page['start'].' OFFSET '.$page['nb_images'].'
200;';
201  $result = pwg_query($query);
202
203  while ($row = pwg_db_fetch_assoc($result))
204  {
205    // echo '<pre>'; print_r($row); echo '</pre>';
206    array_push($element_ids, $row['id']);
207
208    $src = get_thumbnail_url($row);
209
210    $query = '
211SELECT tag_id
212  FROM '.IMAGE_TAG_TABLE.'
213  WHERE image_id = '.$row['id'].'
214;';
215    $selected_tags = array_from_query($query, 'tag_id');
216
217    // creation date
218    if (!empty($row['date_creation']))
219    {
220      list($year,$month,$day) = explode('-', $row['date_creation']);
221    }
222    else
223    {
224      list($year,$month,$day) = array('',0,0);
225    }
226
227    if (count($all_tags) > 0)
228    {
229      $tag_selection = get_html_tag_selection(
230        $all_tags,
231        'tags-'.$row['id'],
232        $selected_tags
233        );
234    }
235    else
236    {
237      $tag_selection =
238        '<p>'.
239        l10n('No tag defined. Use Administration>Pictures>Tags').
240        '</p>';
241    }
242
243    $template->append(
244      'elements',
245      array(
246        'ID' => $row['id'],
247        'TN_SRC' => $src,
248        'LEGEND' =>
249          !empty($row['name']) ?
250            $row['name'] : get_name_from_file($row['file']),
251        'U_EDIT' =>
252            PHPWG_ROOT_PATH.'admin.php?page=picture_modify'.
253            '&amp;image_id='.$row['id'],
254        'NAME' => @$row['name'],
255        'AUTHOR' => @$row['author'],
256        'DESCRIPTION' => @$row['comment'],
257        'DATE_CREATION_YEAR' => $year,
258        'DATE_CREATION_MONTH' => (int)$month,
259        'DATE_CREATION_DAY' => (int)$day,
260
261        'TAG_SELECTION' => $tag_selection,
262        )
263      );
264  }
265
266  $template->assign('ELEMENT_IDS', implode(',', $element_ids));
267}
268
269// +-----------------------------------------------------------------------+
270// |                           sending html code                           |
271// +-----------------------------------------------------------------------+
272
273$template->assign_var_from_handle('ADMIN_CONTENT', 'element_set_unit');
274?>
Note: See TracBrowser for help on using the repository browser.