source: trunk/admin/element_set.php @ 766

Last change on this file since 766 was 764, checked in by plg, 19 years ago
  • elements batch management : element_set page becomes the frontend to element_set_global and element_set_unit, infos_images (after a long time of use) become deprecated : the more powerful element_set is used instead. Consequently, batch management concerns caddie but also "normal categories".
  • refactoring code in admin.php to include the sub-file (clearer)
  • caddie : function fill_caddie replaces the code in category.php and can be used in admin/element_set.php
  • caddie : caddie table is added in delete_elements function
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.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-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2005-04-16 16:56:32 +0000 (Sat, 16 Apr 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 764 $
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}
38include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
39
40// +-----------------------------------------------------------------------+
41// |                          caddie management                            |
42// +-----------------------------------------------------------------------+
43
44if (isset($_POST['submit_caddie']))
45{
46  if (isset($_POST['caddie_action']))
47  {
48    switch ($_POST['caddie_action'])
49    {
50      case 'empty_all' :
51      {
52          $query = '
53DELETE FROM '.CADDIE_TABLE.'
54  WHERE user_id = '.$user['id'].'
55;';
56          pwg_query($query);
57          break;
58      }
59      case 'empty_selected' :
60      {
61        if (isset($_POST['selection']) and count($_POST['selection']) > 0)
62        {
63          $query = '
64DELETE
65  FROM '.CADDIE_TABLE.'
66  WHERE element_id IN ('.implode(',', $_POST['selection']).')
67    AND user_id = '.$user['id'].'
68;';
69          pwg_query($query);
70        }
71        else
72        {
73          // TODO : add error
74        }
75        break;
76      }
77      case 'add_selected' :
78      {
79        if (isset($_POST['selection']) and count($_POST['selection']) > 0)
80        {
81          fill_caddie($_POST['selection']);
82        }
83        else
84        {
85          // TODO : add error
86        }
87        break;
88      }
89    }
90  }
91  else
92  {
93    // TODO : add error
94  }
95}
96
97// +-----------------------------------------------------------------------+
98// |                    initialize info about category                     |
99// +-----------------------------------------------------------------------+
100
101// To element_set_(global|unit).php, we must provide the elements id of the
102// managed category in $page['cat_elements_id'] array.
103
104if (is_numeric($_GET['cat']))
105{
106  $cat_infos = get_cat_info($_GET['cat']);
107  $page['title'] = get_cat_display_name($cat_infos['name'], '', false);
108 
109  $query = '
110SELECT image_id
111  FROM '.IMAGE_CATEGORY_TABLE.'
112  WHERE category_id = '.$_GET['cat'].'
113;';
114  $page['cat_elements_id'] = array_from_query($query, 'image_id');
115}
116else if ('caddie' == $_GET['cat'])
117{
118  $page['title'] = 'caddie';
119 
120  $query = '
121SELECT element_id
122  FROM '.CADDIE_TABLE.'
123  WHERE user_id = '.$user['id'].'
124;';
125  $page['cat_elements_id'] = array_from_query($query, 'element_id');
126}
127else if ('not_linked' == $_GET['cat'])
128{
129  $page['title'] = 'elements not linked to any virtual categories';
130 
131  // we are searching elements not linked to any virtual category
132  $query = '
133SELECT id
134  FROM '.CATEGORIES_TABLE.'
135  WHERE dir IS NULL
136;';
137  $virtual_categories = array_from_query($query, 'id');
138
139  $query = '
140SELECT DISTINCT(image_id)
141  FROM '.IMAGE_CATEGORY_TABLE.'
142;';
143  $all_elements = array_from_query($query, 'image_id');
144 
145  $query = '
146SELECT DISTINCT(image_id)
147  FROM '.IMAGE_CATEGORY_TABLE.'
148  WHERE category_id IN ('.implode(',', $virtual_categories).')
149;';
150  $linked_to_virtual = array_from_query($query, 'image_id');
151
152  $page['cat_elements_id'] = array_diff($all_elements, $linked_to_virtual);
153}
154
155// +-----------------------------------------------------------------------+
156// |                       first element to display                        |
157// +-----------------------------------------------------------------------+
158
159// $page['start'] contains the number of the first element in its
160// category. For exampe, $page['start'] = 12 means we must show elements #12
161// and $page['nb_images'] next elements
162
163if (!isset($_GET['start'])
164    or !is_numeric($_GET['start'])
165    or $_GET['start'] < 0)
166{
167  $page['start'] = 0;
168}
169else
170{
171  $page['start'] = $_GET['start'];
172}
173
174// +-----------------------------------------------------------------------+
175// |                         open specific mode                            |
176// +-----------------------------------------------------------------------+
177
178$_GET['mode'] = !empty($_GET['mode']) ? $_GET['mode'] : 'global';
179
180switch ($_GET['mode'])
181{
182  case 'global' :
183  {
184    include(PHPWG_ROOT_PATH.'admin/element_set_global.php');
185    break;
186  }
187  case 'unit' :
188  {
189    include(PHPWG_ROOT_PATH.'admin/element_set_unit.php');
190    break;
191  }
192}
193?>
Note: See TracBrowser for help on using the repository browser.