source: trunk/admin/element_set.php @ 1831

Last change on this file since 1831 was 1831, checked in by rub, 17 years ago

Fix Issue 0000605: Not linked elements failure with no virtual categories galleries

Add missing translations

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.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: 2007-02-16 23:13:01 +0000 (Fri, 16 Feb 2007) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1831 $
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'] = l10n('Elements_not_linked');
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  if (!empty($virtual_categories))
151  {
152    $query = '
153SELECT DISTINCT(image_id)
154  FROM '.IMAGE_CATEGORY_TABLE.'
155;';
156    $all_elements = array_from_query($query, 'image_id');
157
158    $query = '
159SELECT DISTINCT(image_id)
160  FROM '.IMAGE_CATEGORY_TABLE.'
161  WHERE category_id IN ('.implode(',', $virtual_categories).')
162;';
163    $linked_to_virtual = array_from_query($query, 'image_id');
164
165    $page['cat_elements_id'] = array_diff($all_elements, $linked_to_virtual);
166  }
167  else
168  {
169    $page['cat_elements_id'] = array();
170  }
171}
172else if ('duplicates' == $_GET['cat'])
173{
174  $page['title'] = l10n('Duplicates');
175 
176  // we are searching related elements twice or more to physical categories
177  // 1 - Retrieve Files
178  $query = '
179SELECT DISTINCT(file)
180  FROM '.IMAGES_TABLE.'
181 GROUP BY file
182HAVING COUNT(DISTINCT storage_category_id) > 1
183;'; 
184
185  $duplicate_files = array_from_query($query, 'file');
186  $duplicate_files[]='Nofiles';
187  // 2 - Retrives related picture ids
188  $query = '
189SELECT id, file
190  FROM '.IMAGES_TABLE.'
191WHERE file IN (\''.implode("','", $duplicate_files).'\')
192ORDER BY file, id
193;';
194
195  $page['cat_elements_id'] = array_from_query($query, 'id');
196  $page['cat_elements_id'][] = 0;
197}
198// +-----------------------------------------------------------------------+
199// |                       first element to display                        |
200// +-----------------------------------------------------------------------+
201
202// $page['start'] contains the number of the first element in its
203// category. For exampe, $page['start'] = 12 means we must show elements #12
204// and $page['nb_images'] next elements
205
206if (!isset($_GET['start'])
207    or !is_numeric($_GET['start'])
208    or $_GET['start'] < 0
209    or (isset($_GET['display']) and 'all' == $_GET['display']))
210{
211  $page['start'] = 0;
212}
213else
214{
215  $page['start'] = $_GET['start'];
216}
217
218// +-----------------------------------------------------------------------+
219// |                         open specific mode                            |
220// +-----------------------------------------------------------------------+
221
222$_GET['mode'] = !empty($_GET['mode']) ? $_GET['mode'] : 'global';
223
224switch ($_GET['mode'])
225{
226  case 'global' :
227  {
228    include(PHPWG_ROOT_PATH.'admin/element_set_global.php');
229    break;
230  }
231  case 'unit' :
232  {
233    include(PHPWG_ROOT_PATH.'admin/element_set_unit.php');
234    break;
235  }
236}
237?>
Note: See TracBrowser for help on using the repository browser.