source: tags/release-1_6_0RC1/admin/element_set_global.php @ 26789

Last change on this file since 26789 was 1121, checked in by plg, 18 years ago

feature deleted: code for categories link was too complicated for such a
simple fature. Replaced by static association. Links are not persistent
anymore.

modification removed: #image_category.is_storage replaced by
#images.storage_category_id as in branche 1.5..

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