source: branches/branch-1_6-hk/admin/element_set.php @ 2431

Last change on this file since 2431 was 1072, checked in by rub, 19 years ago

Step 2 improvement issue 0000301:

o Add and use Functions Check of status
o Restricted Access for user generic

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 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-03-09 22:46:28 +0000 (Thu, 09 Mar 2006) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1072 $
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// |                          caddie management                            |
48// +-----------------------------------------------------------------------+
49
50if (isset($_POST['submit_caddie']))
51{
52  if (isset($_POST['caddie_action']))
53  {
54    switch ($_POST['caddie_action'])
55    {
56      case 'empty_all' :
57      {
58          $query = '
59DELETE FROM '.CADDIE_TABLE.'
60  WHERE user_id = '.$user['id'].'
61;';
62          pwg_query($query);
63          break;
64      }
65      case 'empty_selected' :
66      {
67        if (isset($_POST['selection']) and count($_POST['selection']) > 0)
68        {
69          $query = '
70DELETE
71  FROM '.CADDIE_TABLE.'
72  WHERE element_id IN ('.implode(',', $_POST['selection']).')
73    AND user_id = '.$user['id'].'
74;';
75          pwg_query($query);
76        }
77        else
78        {
79          // TODO : add error
80        }
81        break;
82      }
83      case 'add_selected' :
84      {
85        if (isset($_POST['selection']) and count($_POST['selection']) > 0)
86        {
87          fill_caddie($_POST['selection']);
88        }
89        else
90        {
91          // TODO : add error
92        }
93        break;
94      }
95    }
96  }
97  else
98  {
99    // TODO : add error
100  }
101}
102
103// +-----------------------------------------------------------------------+
104// |                    initialize info about category                     |
105// +-----------------------------------------------------------------------+
106
107// To element_set_(global|unit).php, we must provide the elements id of the
108// managed category in $page['cat_elements_id'] array.
109
110if (is_numeric($_GET['cat']))
111{
112  $cat_infos = get_cat_info($_GET['cat']);
113  $page['title'] =
114    get_cat_display_name(
115      $cat_infos['name'],
116      PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id=',
117      false
118      );
119 
120  $query = '
121SELECT image_id
122  FROM '.IMAGE_CATEGORY_TABLE.'
123  WHERE category_id = '.$_GET['cat'].'
124;';
125  $page['cat_elements_id'] = array_from_query($query, 'image_id');
126}
127else if ('caddie' == $_GET['cat'])
128{
129  $page['title'] = $lang['caddie'];
130 
131  $query = '
132SELECT element_id
133  FROM '.CADDIE_TABLE.'
134  WHERE user_id = '.$user['id'].'
135;';
136  $page['cat_elements_id'] = array_from_query($query, 'element_id');
137}
138else if ('not_linked' == $_GET['cat'])
139{
140  $page['title'] = 'elements not linked to any virtual categories';
141 
142  // we are searching elements not linked to any virtual category
143  $query = '
144SELECT id
145  FROM '.CATEGORIES_TABLE.'
146  WHERE dir IS NULL
147;';
148  $virtual_categories = array_from_query($query, 'id');
149
150  $query = '
151SELECT DISTINCT(image_id)
152  FROM '.IMAGE_CATEGORY_TABLE.'
153;';
154  $all_elements = array_from_query($query, 'image_id');
155 
156  $query = '
157SELECT DISTINCT(image_id)
158  FROM '.IMAGE_CATEGORY_TABLE.'
159  WHERE category_id IN ('.implode(',', $virtual_categories).')
160;';
161  $linked_to_virtual = array_from_query($query, 'image_id');
162
163  $page['cat_elements_id'] = array_diff($all_elements, $linked_to_virtual);
164}
165
166// +-----------------------------------------------------------------------+
167// |                       first element to display                        |
168// +-----------------------------------------------------------------------+
169
170// $page['start'] contains the number of the first element in its
171// category. For exampe, $page['start'] = 12 means we must show elements #12
172// and $page['nb_images'] next elements
173
174if (!isset($_GET['start'])
175    or !is_numeric($_GET['start'])
176    or $_GET['start'] < 0
177    or (isset($_GET['display']) and 'all' == $_GET['display']))
178{
179  $page['start'] = 0;
180}
181else
182{
183  $page['start'] = $_GET['start'];
184}
185
186// +-----------------------------------------------------------------------+
187// |                         open specific mode                            |
188// +-----------------------------------------------------------------------+
189
190$_GET['mode'] = !empty($_GET['mode']) ? $_GET['mode'] : 'global';
191
192switch ($_GET['mode'])
193{
194  case 'global' :
195  {
196    include(PHPWG_ROOT_PATH.'admin/element_set_global.php');
197    break;
198  }
199  case 'unit' :
200  {
201    include(PHPWG_ROOT_PATH.'admin/element_set_unit.php');
202    break;
203  }
204}
205?>
Note: See TracBrowser for help on using the repository browser.