source: trunk/admin/element_set.php @ 1738

Last change on this file since 1738 was 1688, checked in by vdigital, 17 years ago

Physical duplicate files in Admin Advanced Functions

  • Property svn:eol-style set to native
  • 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-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2007-01-02 09:02:39 +0000 (Tue, 02 Jan 2007) $
10// | last modifier : $Author: vdigital $
11// | revision      : $Revision: 1688 $
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  $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}
165else if ('duplicates' == $_GET['cat'])
166{
167  $page['title'] = l10n('Duplicates');
168 
169  // we are searching related elements twice or more to physical categories
170  // 1 - Retrieve Files
171  $query = '
172SELECT DISTINCT(file)
173  FROM '.IMAGES_TABLE.'
174 GROUP BY file
175HAVING COUNT(DISTINCT storage_category_id) > 1
176;'; 
177
178  $duplicate_files = array_from_query($query, 'file');
179  $duplicate_files[]='Nofiles';
180  // 2 - Retrives related picture ids
181  $query = '
182SELECT id, file
183  FROM '.IMAGES_TABLE.'
184WHERE file IN (\''.implode("','", $duplicate_files).'\')
185ORDER BY file, id
186;';
187
188  $page['cat_elements_id'] = array_from_query($query, 'id');
189  $page['cat_elements_id'][] = 0;
190}
191// +-----------------------------------------------------------------------+
192// |                       first element to display                        |
193// +-----------------------------------------------------------------------+
194
195// $page['start'] contains the number of the first element in its
196// category. For exampe, $page['start'] = 12 means we must show elements #12
197// and $page['nb_images'] next elements
198
199if (!isset($_GET['start'])
200    or !is_numeric($_GET['start'])
201    or $_GET['start'] < 0
202    or (isset($_GET['display']) and 'all' == $_GET['display']))
203{
204  $page['start'] = 0;
205}
206else
207{
208  $page['start'] = $_GET['start'];
209}
210
211// +-----------------------------------------------------------------------+
212// |                         open specific mode                            |
213// +-----------------------------------------------------------------------+
214
215$_GET['mode'] = !empty($_GET['mode']) ? $_GET['mode'] : 'global';
216
217switch ($_GET['mode'])
218{
219  case 'global' :
220  {
221    include(PHPWG_ROOT_PATH.'admin/element_set_global.php');
222    break;
223  }
224  case 'unit' :
225  {
226    include(PHPWG_ROOT_PATH.'admin/element_set_unit.php');
227    break;
228  }
229}
230?>
Note: See TracBrowser for help on using the repository browser.