source: branches/branch-1_7/admin/element_set.php @ 2183

Last change on this file since 2183 was 1900, checked in by rub, 18 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: 6.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.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// |                          caddie management                            |
47// +-----------------------------------------------------------------------+
48
49if (isset($_POST['submit_caddie']))
50{
51  if (isset($_POST['caddie_action']))
52  {
53    switch ($_POST['caddie_action'])
54    {
55      case 'empty_all' :
56      {
57          $query = '
58DELETE FROM '.CADDIE_TABLE.'
59  WHERE user_id = '.$user['id'].'
60;';
61          pwg_query($query);
62          break;
63      }
64      case 'empty_selected' :
65      {
66        if (isset($_POST['selection']) and count($_POST['selection']) > 0)
67        {
68          $query = '
69DELETE
70  FROM '.CADDIE_TABLE.'
71  WHERE element_id IN ('.implode(',', $_POST['selection']).')
72    AND user_id = '.$user['id'].'
73;';
74          pwg_query($query);
75        }
76        else
77        {
78          // TODO : add error
79        }
80        break;
81      }
82      case 'add_selected' :
83      {
84        if (isset($_POST['selection']) and count($_POST['selection']) > 0)
85        {
86          fill_caddie($_POST['selection']);
87        }
88        else
89        {
90          // TODO : add error
91        }
92        break;
93      }
94    }
95  }
96  else
97  {
98    // TODO : add error
99  }
100}
101
102// +-----------------------------------------------------------------------+
103// |                    initialize info about category                     |
104// +-----------------------------------------------------------------------+
105
106// To element_set_(global|unit).php, we must provide the elements id of the
107// managed category in $page['cat_elements_id'] array.
108
109if (is_numeric($_GET['cat']))
110{
111  $page['title'] =
112    get_cat_display_name_from_id(
113      $_GET['cat'],
114      PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id=',
115      false
116      );
117 
118  $query = '
119SELECT image_id
120  FROM '.IMAGE_CATEGORY_TABLE.'
121  WHERE category_id = '.$_GET['cat'].'
122;';
123  $page['cat_elements_id'] = array_from_query($query, 'image_id');
124}
125else if ('caddie' == $_GET['cat'])
126{
127  $page['title'] = $lang['caddie'];
128 
129  $query = '
130SELECT element_id
131  FROM '.CADDIE_TABLE.'
132  WHERE user_id = '.$user['id'].'
133;';
134  $page['cat_elements_id'] = array_from_query($query, 'element_id');
135}
136else if ('not_linked' == $_GET['cat'])
137{
138  $page['title'] = l10n('Elements_not_linked');
139 
140  // we are searching elements not linked to any virtual category
141  $query = '
142SELECT id
143  FROM '.CATEGORIES_TABLE.'
144  WHERE dir IS NULL
145;';
146  $virtual_categories = array_from_query($query, 'id');
147
148  if (!empty($virtual_categories))
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  else
166  {
167    $page['cat_elements_id'] = array();
168  }
169}
170else if ('duplicates' == $_GET['cat'])
171{
172  $page['title'] = l10n('Duplicates');
173 
174  // we are searching related elements twice or more to physical categories
175  // 1 - Retrieve Files
176  $query = '
177SELECT DISTINCT(file)
178  FROM '.IMAGES_TABLE.'
179 GROUP BY file
180HAVING COUNT(DISTINCT storage_category_id) > 1
181;'; 
182
183  $duplicate_files = array_from_query($query, 'file');
184  $duplicate_files[]='Nofiles';
185  // 2 - Retrives related picture ids
186  $query = '
187SELECT id, file
188  FROM '.IMAGES_TABLE.'
189WHERE file IN (\''.implode("','", $duplicate_files).'\')
190ORDER BY file, id
191;';
192
193  $page['cat_elements_id'] = array_from_query($query, 'id');
194  $page['cat_elements_id'][] = 0;
195}
196// +-----------------------------------------------------------------------+
197// |                       first element to display                        |
198// +-----------------------------------------------------------------------+
199
200// $page['start'] contains the number of the first element in its
201// category. For exampe, $page['start'] = 12 means we must show elements #12
202// and $page['nb_images'] next elements
203
204if (!isset($_GET['start'])
205    or !is_numeric($_GET['start'])
206    or $_GET['start'] < 0
207    or (isset($_GET['display']) and 'all' == $_GET['display']))
208{
209  $page['start'] = 0;
210}
211else
212{
213  $page['start'] = $_GET['start'];
214}
215
216// +-----------------------------------------------------------------------+
217// |                         open specific mode                            |
218// +-----------------------------------------------------------------------+
219
220$_GET['mode'] = !empty($_GET['mode']) ? $_GET['mode'] : 'global';
221
222switch ($_GET['mode'])
223{
224  case 'global' :
225  {
226    include(PHPWG_ROOT_PATH.'admin/element_set_global.php');
227    break;
228  }
229  case 'unit' :
230  {
231    include(PHPWG_ROOT_PATH.'admin/element_set_unit.php');
232    break;
233  }
234}
235?>
Note: See TracBrowser for help on using the repository browser.