source: trunk/admin/element_set_global.php @ 2417

Last change on this file since 2417 was 2409, checked in by rvelices, 16 years ago
  • remember me cookie security improvement (the time when the cookie was generated is saved and checked in range [now-remember_me_length; now]
  • tags improvements
    • pass to templates all fields in table #tags (handy for plugins such as type tags)
    • fix issue with tag letter when first letter is accentuated (utf-8)
    • tags are sorted on url_name instead of name (accentuated first letter chars are the same as without accent)
    • better use of columns in by letter display mode
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 10.7 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008      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// |                       global mode form submission                     |
44// +-----------------------------------------------------------------------+
45
46if (isset($_POST['submit']))
47{
48  $collection = array();
49
50//   echo '<pre>';
51//   print_r($_POST);
52//   echo '</pre>';
53//   exit();
54
55  switch ($_POST['target'])
56  {
57    case 'all' :
58    {
59      $collection = $page['cat_elements_id'];
60      break;
61    }
62    case 'selection' :
63    {
64      if (!isset($_POST['selection']) or count($_POST['selection']) == 0)
65      {
66        array_push($page['errors'], l10n('Select at least one picture'));
67      }
68      else
69      {
70        $collection = $_POST['selection'];
71      }
72      break;
73    }
74  }
75
76  if (isset($_POST['add_tags']) and count($collection) > 0)
77  {
78    add_tags($_POST['add_tags'], $collection);
79  }
80
81  if (isset($_POST['del_tags']) and count($collection) > 0)
82  {
83    $query = '
84DELETE
85  FROM '.IMAGE_TAG_TABLE.'
86  WHERE image_id IN ('.implode(',', $collection).')
87    AND tag_id IN ('.implode(',', $_POST['del_tags']).')
88;';
89    pwg_query($query);
90  }
91
92  if ($_POST['associate'] != 0 and count($collection) > 0)
93  {
94    associate_images_to_categories(
95      $collection,
96      array($_POST['associate'])
97      );
98  }
99
100  if ($_POST['dissociate'] != 0 and count($collection) > 0)
101  {
102    // physical links must not be broken, so we must first retrieve image_id
103    // which create virtual links with the category to "dissociate from".
104    $query = '
105SELECT id
106  FROM '.IMAGE_CATEGORY_TABLE.'
107    INNER JOIN '.IMAGES_TABLE.' ON image_id = id
108  WHERE category_id = '.$_POST['dissociate'].'
109    AND id IN ('.implode(',', $collection).')
110    AND category_id != storage_category_id
111;';
112    $dissociables = array_from_query($query, 'id');
113
114    if (!empty($dissociables))
115    {
116      $query = '
117DELETE
118  FROM '.IMAGE_CATEGORY_TABLE.'
119  WHERE category_id = '.$_POST['dissociate'].'
120    AND image_id IN ('.implode(',', $dissociables).')
121';
122      pwg_query($query);
123
124      $page['cat_elements_id'] = array_diff(
125        $page['cat_elements_id'],
126        $dissociables
127      );
128    }
129
130    update_category($_POST['dissociate']);
131  }
132
133  $datas = array();
134  $dbfields = array('primary' => array('id'), 'update' => array());
135
136  $formfields = array('author', 'name', 'date_creation', 'level');
137  foreach ($formfields as $formfield)
138  {
139    if ($_POST[$formfield.'_action'] != 'leave')
140    {
141      array_push($dbfields['update'], $formfield);
142    }
143  }
144
145  // updating elements is useful only if needed...
146  if (count($dbfields['update']) > 0 and count($collection) > 0)
147  {
148    $query = '
149SELECT id
150  FROM '.IMAGES_TABLE.'
151  WHERE id IN ('.implode(',', $collection).')
152;';
153    $result = pwg_query($query);
154
155    while ($row = mysql_fetch_array($result))
156    {
157      $data = array();
158      $data['id'] = $row['id'];
159
160      if ('set' == $_POST['author_action'])
161      {
162        $data['author'] = $_POST['author'];
163        if ('' == $data['author'])
164        {
165          unset($data['author']);
166        }
167      }
168
169      if ('set' == $_POST['name_action'])
170      {
171        $data['name'] = $_POST['name'];
172        if ('' == $data['name'])
173        {
174          unset($data['name']);
175        }
176      }
177
178      if ('set' == $_POST['date_creation_action'])
179      {
180        $data['date_creation'] =
181          $_POST['date_creation_year']
182          .'-'.$_POST['date_creation_month']
183          .'-'.$_POST['date_creation_day']
184          ;
185      }
186
187      if ('set' == $_POST['level_action'])
188      {
189        $data['level'] = $_POST['level'];
190      }
191
192      array_push($datas, $data);
193    }
194    // echo '<pre>'; print_r($datas); echo '</pre>';
195    mass_updates(IMAGES_TABLE, $dbfields, $datas);
196  }
197}
198
199// +-----------------------------------------------------------------------+
200// |                             template init                             |
201// +-----------------------------------------------------------------------+
202$template->set_filenames(
203  array('element_set_global' => 'admin/element_set_global.tpl'));
204
205$base_url = get_root_url().'admin.php';
206
207// $form_action = $base_url.'?page=element_set_global';
208
209$template->assign(
210  array(
211    'CATEGORIES_NAV'=>$page['title'],
212
213    'U_DISPLAY'=>$base_url.get_query_string_diff(array('display')),
214
215    'U_UNIT_MODE'
216    =>
217    $base_url
218    .get_query_string_diff(array('mode','display'))
219    .'&amp;mode=unit',
220
221    'F_ACTION'=>$base_url.get_query_string_diff(array()),
222   )
223 );
224
225// +-----------------------------------------------------------------------+
226// |                            caddie options                             |
227// +-----------------------------------------------------------------------+
228
229$template->assign('IN_CADDIE', 'caddie' == $_GET['cat'] ? true : false );
230
231// +-----------------------------------------------------------------------+
232// |                           global mode form                            |
233// +-----------------------------------------------------------------------+
234
235// Virtualy associate a picture to a category
236$query = '
237SELECT id,name,uppercats,global_rank
238  FROM '.CATEGORIES_TABLE.'
239;';
240display_select_cat_wrapper($query, array(), 'associate_options', true);
241
242// Dissociate from a category : categories listed for dissociation can
243// only represent virtual links. Links to physical categories can't be
244// broken
245if (count($page['cat_elements_id']) > 0)
246{
247  $query = '
248SELECT DISTINCT(category_id) AS id, c.name, uppercats, global_rank
249  FROM '.IMAGE_CATEGORY_TABLE.' AS ic,
250       '.CATEGORIES_TABLE.' AS c,
251       '.IMAGES_TABLE.' AS i
252  WHERE ic.image_id IN ('.implode(',', $page['cat_elements_id']).')
253    AND ic.category_id = c.id
254    AND ic.image_id = i.id
255    AND ic.category_id != i.storage_category_id
256;';
257  display_select_cat_wrapper($query, array(), 'dissociate_options', true);
258}
259
260$all_tags = get_all_tags();
261
262if (count($all_tags) > 0)
263{// add tags
264  $template->assign(
265    array(
266      'ADD_TAG_SELECTION' => get_html_tag_selection(
267                              $all_tags,
268                              'add_tags'
269                              ),
270      )
271    );
272}
273
274if (count($page['cat_elements_id']) > 0)
275{
276  // remove tags
277  $tags = get_common_tags($page['cat_elements_id'], -1);
278
279  $template->assign(
280    array(
281      'DEL_TAG_SELECTION' => get_html_tag_selection($tags, 'del_tags'),
282      )
283    );
284}
285
286// creation date
287$day =
288empty($_POST['date_creation_day']) ? date('j') : $_POST['date_creation_day'];
289
290$month =
291empty($_POST['date_creation_month']) ? date('n') : $_POST['date_creation_month'];
292
293$year =
294empty($_POST['date_creation_year']) ? date('Y') : $_POST['date_creation_year'];
295
296$month_list = $lang['month'];
297$month_list[0]='------------';
298ksort($month_list);
299$template->assign( array(
300      'month_list'         => $month_list,
301      'DATE_CREATION_DAY'  => (int)$day,
302      'DATE_CREATION_MONTH'=> (int)$month,
303      'DATE_CREATION_YEAR' => (int)$year,
304    )
305  );
306
307// image level options
308$tpl_options = array();
309foreach ($conf['available_permission_levels'] as $level)
310{
311  $tpl_options[$level] = l10n( sprintf('Level %d', $level) );
312}
313$template->assign(
314    array(
315      'level_options'=> $tpl_options,
316    )
317  );
318
319// +-----------------------------------------------------------------------+
320// |                        global mode thumbnails                         |
321// +-----------------------------------------------------------------------+
322
323// how many items to display on this page
324if (!empty($_GET['display']))
325{
326  if ('all' == $_GET['display'])
327  {
328    $page['nb_images'] = count($page['cat_elements_id']);
329  }
330  else
331  {
332    $page['nb_images'] = intval($_GET['display']);
333  }
334}
335else
336{
337  $page['nb_images'] = 20;
338}
339
340if (count($page['cat_elements_id']) > 0)
341{
342  $nav_bar = create_navigation_bar(
343    $base_url.get_query_string_diff(array('start')),
344    count($page['cat_elements_id']),
345    $page['start'],
346    $page['nb_images']
347    );
348  $template->assign('NAV_BAR', $nav_bar);
349
350  $query = '
351SELECT id,path,tn_ext,file,filesize,level
352  FROM '.IMAGES_TABLE.'
353  WHERE id IN ('.implode(',', $page['cat_elements_id']).')
354  '.$conf['order_by'].'
355  LIMIT '.$page['start'].', '.$page['nb_images'].'
356;';
357  //echo '<pre>'.$query.'</pre>';
358  $result = pwg_query($query);
359
360  // template thumbnail initialization
361
362  while ($row = mysql_fetch_assoc($result))
363  {
364    $src = get_thumbnail_url($row);
365
366    $template->append(
367      'thumbnails',
368      array(
369        'ID' => $row['id'],
370        'TN_SRC' => $src,
371        'FILE' => $row['file'],
372        'TITLE' => get_thumbnail_title($row),
373        'LEVEL' => $row['level']
374        )
375      );
376  }
377}
378
379//----------------------------------------------------------- sending html code
380$template->assign_var_from_handle('ADMIN_CONTENT', 'element_set_global');
381?>
Note: See TracBrowser for help on using the repository browser.