1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2010 Piwigo Team http://piwigo.org | |
---|
6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | /** |
---|
25 | * Management of elements set. Elements can belong to a category or to the |
---|
26 | * user caddie. |
---|
27 | * |
---|
28 | */ |
---|
29 | |
---|
30 | if (!defined('PHPWG_ROOT_PATH')) |
---|
31 | { |
---|
32 | die('Hacking attempt!'); |
---|
33 | } |
---|
34 | |
---|
35 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
36 | |
---|
37 | // +-----------------------------------------------------------------------+ |
---|
38 | // | Check Access and exit when user status is not ok | |
---|
39 | // +-----------------------------------------------------------------------+ |
---|
40 | check_status(ACCESS_ADMINISTRATOR); |
---|
41 | |
---|
42 | check_input_parameter('selection', $_POST, true, PATTERN_ID); |
---|
43 | |
---|
44 | // +-----------------------------------------------------------------------+ |
---|
45 | // | caddie management | |
---|
46 | // +-----------------------------------------------------------------------+ |
---|
47 | |
---|
48 | if (isset($_POST['submit_caddie'])) |
---|
49 | { |
---|
50 | if (isset($_POST['caddie_action'])) |
---|
51 | { |
---|
52 | switch ($_POST['caddie_action']) |
---|
53 | { |
---|
54 | case 'empty_all' : |
---|
55 | { |
---|
56 | $query = ' |
---|
57 | DELETE FROM '.CADDIE_TABLE.' |
---|
58 | WHERE user_id = '.$user['id'].' |
---|
59 | ;'; |
---|
60 | pwg_query($query); |
---|
61 | break; |
---|
62 | } |
---|
63 | case 'empty_selected' : |
---|
64 | { |
---|
65 | if (isset($_POST['selection']) and count($_POST['selection']) > 0) |
---|
66 | { |
---|
67 | $query = ' |
---|
68 | DELETE |
---|
69 | FROM '.CADDIE_TABLE.' |
---|
70 | WHERE element_id IN ('.implode(',', $_POST['selection']).') |
---|
71 | AND user_id = '.$user['id'].' |
---|
72 | ;'; |
---|
73 | pwg_query($query); |
---|
74 | } |
---|
75 | else |
---|
76 | { |
---|
77 | // TODO : add error |
---|
78 | } |
---|
79 | break; |
---|
80 | } |
---|
81 | case 'add_selected' : |
---|
82 | { |
---|
83 | if (isset($_POST['selection']) and count($_POST['selection']) > 0) |
---|
84 | { |
---|
85 | fill_caddie($_POST['selection']); |
---|
86 | } |
---|
87 | else |
---|
88 | { |
---|
89 | // TODO : add error |
---|
90 | } |
---|
91 | break; |
---|
92 | } |
---|
93 | } |
---|
94 | } |
---|
95 | else |
---|
96 | { |
---|
97 | // TODO : add error |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | // +-----------------------------------------------------------------------+ |
---|
102 | // | initialize info about category | |
---|
103 | // +-----------------------------------------------------------------------+ |
---|
104 | |
---|
105 | // To element_set_(global|unit).php, we must provide the elements id of the |
---|
106 | // managed category in $page['cat_elements_id'] array. |
---|
107 | $page['cat_elements_id'] = array(); |
---|
108 | if (is_numeric($_GET['cat'])) |
---|
109 | { |
---|
110 | $page['title'] = |
---|
111 | get_cat_display_name_from_id( |
---|
112 | $_GET['cat'], |
---|
113 | PHPWG_ROOT_PATH.'admin.php?page=cat_modify&cat_id=', |
---|
114 | false |
---|
115 | ); |
---|
116 | |
---|
117 | $query = ' |
---|
118 | SELECT image_id |
---|
119 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
120 | WHERE category_id = '.$_GET['cat'].' |
---|
121 | ;'; |
---|
122 | $page['cat_elements_id'] = array_from_query($query, 'image_id'); |
---|
123 | } |
---|
124 | else if ('caddie' == $_GET['cat']) |
---|
125 | { |
---|
126 | $page['title'] = l10n('caddie'); |
---|
127 | |
---|
128 | $query = ' |
---|
129 | SELECT element_id |
---|
130 | FROM '.CADDIE_TABLE.' |
---|
131 | WHERE user_id = '.$user['id'].' |
---|
132 | ;'; |
---|
133 | $page['cat_elements_id'] = array_from_query($query, 'element_id'); |
---|
134 | } |
---|
135 | else if ('not_linked' == $_GET['cat']) |
---|
136 | { |
---|
137 | $page['title'] = l10n('Not linked elements'); |
---|
138 | $template->assign(array('U_ACTIVE_MENU' => 5 )); |
---|
139 | |
---|
140 | // we are searching elements not linked to any virtual category |
---|
141 | $query = ' |
---|
142 | SELECT id |
---|
143 | FROM '.IMAGES_TABLE.' |
---|
144 | ;'; |
---|
145 | $all_elements = array_from_query($query, 'id'); |
---|
146 | |
---|
147 | $linked_to_virtual = array(); |
---|
148 | |
---|
149 | $query = ' |
---|
150 | SELECT id |
---|
151 | FROM '.CATEGORIES_TABLE.' |
---|
152 | WHERE dir IS NULL |
---|
153 | ;'; |
---|
154 | $virtual_categories = array_from_query($query, 'id'); |
---|
155 | if (!empty($virtual_categories)) |
---|
156 | { |
---|
157 | $query = ' |
---|
158 | SELECT DISTINCT(image_id) |
---|
159 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
160 | WHERE category_id IN ('.implode(',', $virtual_categories).') |
---|
161 | ;'; |
---|
162 | $linked_to_virtual = array_from_query($query, 'image_id'); |
---|
163 | } |
---|
164 | |
---|
165 | $page['cat_elements_id'] = array_diff($all_elements, $linked_to_virtual); |
---|
166 | } |
---|
167 | else if ('duplicates' == $_GET['cat']) |
---|
168 | { |
---|
169 | $page['title'] = l10n('Files with same name in more than one physical album'); |
---|
170 | $template->assign(array('U_ACTIVE_MENU' => 5 )); |
---|
171 | |
---|
172 | // we are searching related elements twice or more to physical categories |
---|
173 | // 1 - Retrieve Files |
---|
174 | $query = ' |
---|
175 | SELECT DISTINCT(file) |
---|
176 | FROM '.IMAGES_TABLE.' |
---|
177 | GROUP BY file |
---|
178 | HAVING COUNT(DISTINCT storage_category_id) > 1 |
---|
179 | ;'; |
---|
180 | |
---|
181 | $duplicate_files = array_from_query($query, 'file'); |
---|
182 | $duplicate_files[]='Nofiles'; |
---|
183 | // 2 - Retrives related picture ids |
---|
184 | $query = ' |
---|
185 | SELECT id, file |
---|
186 | FROM '.IMAGES_TABLE.' |
---|
187 | WHERE file IN (\''.implode("','", $duplicate_files).'\') |
---|
188 | ORDER BY file, id |
---|
189 | ;'; |
---|
190 | |
---|
191 | $page['cat_elements_id'] = array_from_query($query, 'id'); |
---|
192 | } |
---|
193 | elseif ('recent'== $_GET['cat']) |
---|
194 | { |
---|
195 | $page['title'] = l10n('Recent pictures'); |
---|
196 | $query = 'SELECT MAX(date_available) AS date |
---|
197 | FROM '.IMAGES_TABLE; |
---|
198 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
199 | if (!empty($row['date'])) |
---|
200 | { |
---|
201 | $query = 'SELECT id |
---|
202 | FROM '.IMAGES_TABLE.' |
---|
203 | WHERE date_available BETWEEN '.pwg_db_get_recent_period_expression(1, $row['date']).' AND \''.$row['date'].'\''; |
---|
204 | $page['cat_elements_id'] = array_from_query($query, 'id'); |
---|
205 | } |
---|
206 | } |
---|
207 | |
---|
208 | // +-----------------------------------------------------------------------+ |
---|
209 | // | first element to display | |
---|
210 | // +-----------------------------------------------------------------------+ |
---|
211 | |
---|
212 | // $page['start'] contains the number of the first element in its |
---|
213 | // category. For exampe, $page['start'] = 12 means we must show elements #12 |
---|
214 | // and $page['nb_images'] next elements |
---|
215 | |
---|
216 | if (!isset($_GET['start']) |
---|
217 | or !is_numeric($_GET['start']) |
---|
218 | or $_GET['start'] < 0 |
---|
219 | or (isset($_GET['display']) and 'all' == $_GET['display'])) |
---|
220 | { |
---|
221 | $page['start'] = 0; |
---|
222 | } |
---|
223 | else |
---|
224 | { |
---|
225 | $page['start'] = $_GET['start']; |
---|
226 | } |
---|
227 | |
---|
228 | // +-----------------------------------------------------------------------+ |
---|
229 | // | open specific mode | |
---|
230 | // +-----------------------------------------------------------------------+ |
---|
231 | |
---|
232 | $_GET['mode'] = !empty($_GET['mode']) ? $_GET['mode'] : 'global'; |
---|
233 | |
---|
234 | switch ($_GET['mode']) |
---|
235 | { |
---|
236 | case 'global' : |
---|
237 | { |
---|
238 | include(PHPWG_ROOT_PATH.'admin/element_set_global.php'); |
---|
239 | break; |
---|
240 | } |
---|
241 | case 'unit' : |
---|
242 | { |
---|
243 | include(PHPWG_ROOT_PATH.'admin/element_set_unit.php'); |
---|
244 | break; |
---|
245 | } |
---|
246 | } |
---|
247 | ?> |
---|