source: trunk/admin/element_set_global.php @ 1900

Last change on this file since 1900 was 1900, checked in by rub, 17 years ago

Apply property svn:eol-style Value: LF

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 10.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | file          : $Id: element_set_global.php 1900 2007-03-12 22:33:53Z rub $
8// | last update   : $Date: 2007-03-12 22:33:53 +0000 (Mon, 12 Mar 2007) $
9// | last modifier : $Author: rub $
10// | revision      : $Revision: 1900 $
11// +-----------------------------------------------------------------------+
12// | This program is free software; you can redistribute it and/or modify  |
13// | it under the terms of the GNU General Public License as published by  |
14// | the Free Software Foundation                                          |
15// |                                                                       |
16// | This program is distributed in the hope that it will be useful, but   |
17// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
18// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
19// | General Public License for more details.                              |
20// |                                                                       |
21// | You should have received a copy of the GNU General Public License     |
22// | along with this program; if not, write to the Free Software           |
23// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
24// | USA.                                                                  |
25// +-----------------------------------------------------------------------+
26
27/**
28 * Management of elements set. Elements can belong to a category or to the
29 * user caddie.
30 *
31 */
32
33if (!defined('PHPWG_ROOT_PATH'))
34{
35  die('Hacking attempt!');
36}
37
38include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
39
40// +-----------------------------------------------------------------------+
41// | Check Access and exit when user status is not ok                      |
42// +-----------------------------------------------------------------------+
43check_status(ACCESS_ADMINISTRATOR);
44
45// +-----------------------------------------------------------------------+
46// |                       global mode form submission                     |
47// +-----------------------------------------------------------------------+
48
49if (isset($_POST['submit']))
50{
51  $collection = array();
52
53//   echo '<pre>';
54//   print_r($_POST);
55//   echo '</pre>';
56//   exit();
57
58  switch ($_POST['target'])
59  {
60    case 'all' :
61    {
62      $collection = $page['cat_elements_id'];
63      break;
64    }
65    case 'selection' :
66    {
67      if (!isset($_POST['selection']) or count($_POST['selection']) == 0)
68      {
69        array_push($page['errors'], l10n('Select at least one picture'));
70      }
71      else
72      {
73        $collection = $_POST['selection'];
74      }
75      break;
76    }
77  }
78
79  if (isset($_POST['add_tags']) and count($collection) > 0)
80  {
81    add_tags($_POST['add_tags'], $collection);
82  }
83
84  if (isset($_POST['del_tags']) and count($collection) > 0)
85  {
86    $query = '
87DELETE
88  FROM '.IMAGE_TAG_TABLE.'
89  WHERE image_id IN ('.implode(',', $collection).')
90    AND tag_id IN ('.implode(',', $_POST['del_tags']).')
91;';
92    pwg_query($query);
93  }
94
95  if ($_POST['associate'] != 0 and count($collection) > 0)
96  {
97    associate_images_to_categories(
98      $collection,
99      array($_POST['associate'])
100      );
101  }
102
103  if ($_POST['dissociate'] != 0 and count($collection) > 0)
104  {
105    // physical links must not be broken, so we must first retrieve image_id
106    // which create virtual links with the category to "dissociate from".
107    $query = '
108SELECT id
109  FROM '.IMAGE_CATEGORY_TABLE.'
110    INNER JOIN '.IMAGES_TABLE.' ON image_id = id
111  WHERE category_id = '.$_POST['dissociate'].'
112    AND id IN ('.implode(',', $collection).')
113    AND category_id != storage_category_id
114;';
115    $dissociables = array_from_query($query, 'id');
116
117    $query = '
118DELETE
119  FROM '.IMAGE_CATEGORY_TABLE.'
120  WHERE category_id = '.$_POST['dissociate'].'
121    AND image_id IN ('.implode(',', $dissociables).')
122';
123    pwg_query($query);
124
125    update_category($_POST['dissociate']);
126  }
127
128  $datas = array();
129  $dbfields = array('primary' => array('id'), 'update' => array());
130
131  $formfields = array('author', 'name', 'date_creation');
132  foreach ($formfields as $formfield)
133  {
134    if ($_POST[$formfield.'_action'] != 'leave')
135    {
136      array_push($dbfields['update'], $formfield);
137    }
138  }
139
140  // updating elements is useful only if needed...
141  if (count($dbfields['update']) > 0 and count($collection) > 0)
142  {
143    $query = '
144SELECT id
145  FROM '.IMAGES_TABLE.'
146  WHERE id IN ('.implode(',', $collection).')
147;';
148    $result = pwg_query($query);
149
150    while ($row = mysql_fetch_array($result))
151    {
152      $data = array();
153      $data['id'] = $row['id'];
154
155      if ('set' == $_POST['author_action'])
156      {
157        $data['author'] = $_POST['author'];
158
159        if ('' == $data['author'])
160        {
161          unset($data['author']);
162        }
163      }
164
165      if ('set' == $_POST['name_action'])
166      {
167        $data['name'] = $_POST['name'];
168
169        if ('' == $data['name'])
170        {
171          unset($data['name']);
172        }
173      }
174
175      if ('set' == $_POST['date_creation_action'])
176      {
177        $data['date_creation'] =
178          $_POST['date_creation_year']
179          .'-'.$_POST['date_creation_month']
180          .'-'.$_POST['date_creation_day']
181          ;
182      }
183
184      array_push($datas, $data);
185    }
186    // echo '<pre>'; print_r($datas); echo '</pre>';
187    mass_updates(IMAGES_TABLE, $dbfields, $datas);
188  }
189}
190
191// +-----------------------------------------------------------------------+
192// |                             template init                             |
193// +-----------------------------------------------------------------------+
194$template->set_filenames(
195  array('element_set_global' => 'admin/element_set_global.tpl'));
196
197$base_url = PHPWG_ROOT_PATH.'admin.php';
198
199// $form_action = $base_url.'?page=element_set_global';
200
201$template->assign_vars(
202  array(
203    'CATEGORIES_NAV'=>$page['title'],
204
205    'L_SUBMIT'=>$lang['submit'],
206
207    'U_DISPLAY'=>$base_url.get_query_string_diff(array('display')),
208
209    'U_UNIT_MODE'
210    =>
211    $base_url
212    .get_query_string_diff(array('mode','display'))
213    .'&amp;mode=unit',
214
215    'F_ACTION'=>$base_url.get_query_string_diff(array()),
216   )
217 );
218
219// +-----------------------------------------------------------------------+
220// |                            caddie options                             |
221// +-----------------------------------------------------------------------+
222
223if ('caddie' == $_GET['cat'])
224{
225  $template->assign_block_vars('in_caddie', array());
226}
227else
228{
229  $template->assign_block_vars('not_in_caddie', array());
230}
231
232// +-----------------------------------------------------------------------+
233// |                           global mode form                            |
234// +-----------------------------------------------------------------------+
235
236// Virtualy associate a picture to a category
237$blockname = 'associate_option';
238
239$template->assign_block_vars(
240  $blockname,
241  array('SELECTED' => '',
242        'VALUE'=> 0,
243        'OPTION' => '------------'
244    ));
245
246$query = '
247SELECT id,name,uppercats,global_rank
248  FROM '.CATEGORIES_TABLE.'
249;';
250display_select_cat_wrapper($query, array(), $blockname, true);
251
252// Dissociate from a category : categories listed for dissociation can
253// only represent virtual links. Links to physical categories can't be
254// broken
255$blockname = 'dissociate_option';
256
257$template->assign_block_vars(
258  $blockname,
259  array('SELECTED' => '',
260        'VALUE'=> 0,
261        'OPTION' => '------------'
262    ));
263
264if (count($page['cat_elements_id']) > 0)
265{
266  $query = '
267SELECT DISTINCT(category_id) AS id, c.name, uppercats, global_rank
268  FROM '.IMAGE_CATEGORY_TABLE.' AS ic,
269       '.CATEGORIES_TABLE.' AS c,
270       '.IMAGES_TABLE.' AS i
271  WHERE ic.image_id IN ('.implode(',', $page['cat_elements_id']).')
272    AND ic.category_id = c.id
273    AND ic.image_id = i.id
274    AND ic.category_id != i.storage_category_id
275;';
276  display_select_cat_wrapper($query, array(), $blockname, true);
277}
278
279$all_tags = get_all_tags();
280
281if (count($all_tags) == 0)
282{
283  $add_tag_selection =
284    '<p>'.
285    l10n('No tag defined. Use Administration>Pictures>Tags').
286    '</p>';
287}
288else
289{
290  $add_tag_selection = get_html_tag_selection(
291    $all_tags,
292    'add_tags'
293    );
294}
295
296// add tags
297$template->assign_vars(
298  array(
299    'ADD_TAG_SELECTION' => $add_tag_selection,
300    )
301  );
302
303if (count($page['cat_elements_id']) > 0)
304{
305  // remove tags
306  $tags = get_common_tags($page['cat_elements_id'], -1);
307  usort($tags, 'name_compare');
308
309  $template->assign_vars(
310    array(
311      'DEL_TAG_SELECTION' => get_html_tag_selection($tags, 'del_tags'),
312      )
313    );
314}
315// creation date
316$day =
317empty($_POST['date_creation_day']) ? date('j') : $_POST['date_creation_day'];
318get_day_list('date_creation_day', $day);
319
320if (!empty($_POST['date_creation_month']))
321{
322  $month = $_POST['date_creation_month'];
323}
324else
325{
326  $month = date('n');
327}
328get_month_list('date_creation_month', $month);
329
330if (!empty($_POST['date_creation_year']))
331{
332  $year = $_POST['date_creation_year'];
333}
334else
335{
336  $year = date('Y');
337}
338$template->assign_vars(array('DATE_CREATION_YEAR_VALUE'=>$year));
339
340// +-----------------------------------------------------------------------+
341// |                        global mode thumbnails                         |
342// +-----------------------------------------------------------------------+
343
344// how many items to display on this page
345if (!empty($_GET['display']))
346{
347  if ('all' == $_GET['display'])
348  {
349    $page['nb_images'] = count($page['cat_elements_id']);
350  }
351  else
352  {
353    $page['nb_images'] = intval($_GET['display']);
354  }
355}
356else
357{
358  $page['nb_images'] = 20;
359}
360
361if (count($page['cat_elements_id']) > 0)
362{
363  $nav_bar = create_navigation_bar(
364    $base_url.get_query_string_diff(array('start')),
365    count($page['cat_elements_id']),
366    $page['start'],
367    $page['nb_images']
368    );
369  $template->assign_vars(array('NAV_BAR' => $nav_bar));
370
371  $query = '
372SELECT id,path,tn_ext,file,filesize
373  FROM '.IMAGES_TABLE.'
374  WHERE id IN ('.implode(',', $page['cat_elements_id']).')
375  '.$conf['order_by'].'
376  LIMIT '.$page['start'].', '.$page['nb_images'].'
377;';
378  //echo '<pre>'.$query.'</pre>';
379  $result = pwg_query($query);
380
381  // template thumbnail initialization
382  if (mysql_num_rows($result) > 0)
383  {
384    $template->assign_block_vars('thumbnails', array());
385  }
386
387  while ($row = mysql_fetch_assoc($result))
388  {
389    $src = get_thumbnail_url($row);
390
391    $template->assign_block_vars(
392      'thumbnails.thumbnail',
393      array(
394        'ID' => $row['id'],
395        'SRC' => $src,
396        'ALT' => $row['file'],
397        'TITLE' => get_thumbnail_title($row)
398        )
399      );
400  }
401}
402
403//----------------------------------------------------------- sending html code
404$template->assign_var_from_handle('ADMIN_CONTENT', 'element_set_global');
405?>
Note: See TracBrowser for help on using the repository browser.