source: trunk/admin/element_set_global.php @ 2408

Last change on this file since 2408 was 2299, checked in by plg, 16 years ago

Bug fixed: as rvelices notified me by email, my header replacement script was
bugged (r2297 was repeating new and old header).

By the way, I've also removed the replacement keywords. We were using them
because it was a common usage with CVS but it is advised not to use them with
Subversion. Personnaly, it is a problem when I search differences between 2
Piwigo installations outside Subversion.

  • 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  usort($tags, 'name_compare');
279
280  $template->assign(
281    array(
282      'DEL_TAG_SELECTION' => get_html_tag_selection($tags, 'del_tags'),
283      )
284    );
285}
286
287// creation date
288$day =
289empty($_POST['date_creation_day']) ? date('j') : $_POST['date_creation_day'];
290
291$month =
292empty($_POST['date_creation_month']) ? date('n') : $_POST['date_creation_month'];
293
294$year =
295empty($_POST['date_creation_year']) ? date('Y') : $_POST['date_creation_year'];
296
297$month_list = $lang['month'];
298$month_list[0]='------------';
299ksort($month_list);
300$template->assign( array(
301      'month_list'         => $month_list,
302      'DATE_CREATION_DAY'  => (int)$day,
303      'DATE_CREATION_MONTH'=> (int)$month,
304      'DATE_CREATION_YEAR' => (int)$year,
305    )
306  );
307
308// image level options
309$tpl_options = array();
310foreach ($conf['available_permission_levels'] as $level)
311{
312  $tpl_options[$level] = l10n( sprintf('Level %d', $level) );
313}
314$template->assign(
315    array(
316      'level_options'=> $tpl_options,
317    )
318  );
319
320// +-----------------------------------------------------------------------+
321// |                        global mode thumbnails                         |
322// +-----------------------------------------------------------------------+
323
324// how many items to display on this page
325if (!empty($_GET['display']))
326{
327  if ('all' == $_GET['display'])
328  {
329    $page['nb_images'] = count($page['cat_elements_id']);
330  }
331  else
332  {
333    $page['nb_images'] = intval($_GET['display']);
334  }
335}
336else
337{
338  $page['nb_images'] = 20;
339}
340
341if (count($page['cat_elements_id']) > 0)
342{
343  $nav_bar = create_navigation_bar(
344    $base_url.get_query_string_diff(array('start')),
345    count($page['cat_elements_id']),
346    $page['start'],
347    $page['nb_images']
348    );
349  $template->assign('NAV_BAR', $nav_bar);
350
351  $query = '
352SELECT id,path,tn_ext,file,filesize,level
353  FROM '.IMAGES_TABLE.'
354  WHERE id IN ('.implode(',', $page['cat_elements_id']).')
355  '.$conf['order_by'].'
356  LIMIT '.$page['start'].', '.$page['nb_images'].'
357;';
358  //echo '<pre>'.$query.'</pre>';
359  $result = pwg_query($query);
360
361  // template thumbnail initialization
362
363  while ($row = mysql_fetch_assoc($result))
364  {
365    $src = get_thumbnail_url($row);
366
367    $template->append(
368      'thumbnails',
369      array(
370        'ID' => $row['id'],
371        'TN_SRC' => $src,
372        'FILE' => $row['file'],
373        'TITLE' => get_thumbnail_title($row),
374        'LEVEL' => $row['level']
375        )
376      );
377  }
378}
379
380//----------------------------------------------------------- sending html code
381$template->assign_var_from_handle('ADMIN_CONTENT', 'element_set_global');
382?>
Note: See TracBrowser for help on using the repository browser.