source: trunk/admin/element_set.php @ 849

Last change on this file since 849 was 834, checked in by plg, 19 years ago
  • improvement : standardization of categories navigation bar on top of administration screen element_set_(global|unit), cat_modify, cat_list, cat_perm.
  • new : direct link to admin/cat_modify from category.php.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 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-08-19 17:00:20 +0000 (Fri, 19 Aug 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 834 $
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'] =
108    get_cat_display_name(
109      $cat_infos['name'],
110      PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id=',
111      false
112      );
113 
114  $query = '
115SELECT image_id
116  FROM '.IMAGE_CATEGORY_TABLE.'
117  WHERE category_id = '.$_GET['cat'].'
118;';
119  $page['cat_elements_id'] = array_from_query($query, 'image_id');
120}
121else if ('caddie' == $_GET['cat'])
122{
123  $page['title'] = 'caddie';
124 
125  $query = '
126SELECT element_id
127  FROM '.CADDIE_TABLE.'
128  WHERE user_id = '.$user['id'].'
129;';
130  $page['cat_elements_id'] = array_from_query($query, 'element_id');
131}
132else if ('not_linked' == $_GET['cat'])
133{
134  $page['title'] = 'elements not linked to any virtual categories';
135 
136  // we are searching elements not linked to any virtual category
137  $query = '
138SELECT id
139  FROM '.CATEGORIES_TABLE.'
140  WHERE dir IS NULL
141;';
142  $virtual_categories = array_from_query($query, 'id');
143
144  $query = '
145SELECT DISTINCT(image_id)
146  FROM '.IMAGE_CATEGORY_TABLE.'
147;';
148  $all_elements = array_from_query($query, 'image_id');
149 
150  $query = '
151SELECT DISTINCT(image_id)
152  FROM '.IMAGE_CATEGORY_TABLE.'
153  WHERE category_id IN ('.implode(',', $virtual_categories).')
154;';
155  $linked_to_virtual = array_from_query($query, 'image_id');
156
157  $page['cat_elements_id'] = array_diff($all_elements, $linked_to_virtual);
158}
159
160// +-----------------------------------------------------------------------+
161// |                       first element to display                        |
162// +-----------------------------------------------------------------------+
163
164// $page['start'] contains the number of the first element in its
165// category. For exampe, $page['start'] = 12 means we must show elements #12
166// and $page['nb_images'] next elements
167
168if (!isset($_GET['start'])
169    or !is_numeric($_GET['start'])
170    or $_GET['start'] < 0)
171{
172  $page['start'] = 0;
173}
174else
175{
176  $page['start'] = $_GET['start'];
177}
178
179// +-----------------------------------------------------------------------+
180// |                         open specific mode                            |
181// +-----------------------------------------------------------------------+
182
183$_GET['mode'] = !empty($_GET['mode']) ? $_GET['mode'] : 'global';
184
185switch ($_GET['mode'])
186{
187  case 'global' :
188  {
189    include(PHPWG_ROOT_PATH.'admin/element_set_global.php');
190    break;
191  }
192  case 'unit' :
193  {
194    include(PHPWG_ROOT_PATH.'admin/element_set_unit.php');
195    break;
196  }
197}
198?>
Note: See TracBrowser for help on using the repository browser.