1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based photo gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2014 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 | trigger_notify('loc_begin_element_set_unit'); |
---|
43 | |
---|
44 | // +-----------------------------------------------------------------------+ |
---|
45 | // | unit mode form submission | |
---|
46 | // +-----------------------------------------------------------------------+ |
---|
47 | |
---|
48 | if (isset($_POST['submit'])) |
---|
49 | { |
---|
50 | $collection = explode(',', $_POST['element_ids']); |
---|
51 | |
---|
52 | $datas = array(); |
---|
53 | |
---|
54 | $query = ' |
---|
55 | SELECT id, date_creation |
---|
56 | FROM '.IMAGES_TABLE.' |
---|
57 | WHERE id IN ('.implode(',', $collection).') |
---|
58 | ;'; |
---|
59 | $result = pwg_query($query); |
---|
60 | |
---|
61 | while ($row = pwg_db_fetch_assoc($result)) |
---|
62 | { |
---|
63 | $data = array(); |
---|
64 | |
---|
65 | $data['id'] = $row['id']; |
---|
66 | $data['name'] = $_POST['name-'.$row['id']]; |
---|
67 | $data['author'] = $_POST['author-'.$row['id']]; |
---|
68 | $data['level'] = $_POST['level-'.$row['id']]; |
---|
69 | |
---|
70 | if ($conf['allow_html_descriptions']) |
---|
71 | { |
---|
72 | $data['comment'] = @$_POST['description-'.$row['id']]; |
---|
73 | } |
---|
74 | else |
---|
75 | { |
---|
76 | $data['comment'] = strip_tags(@$_POST['description-'.$row['id']]); |
---|
77 | } |
---|
78 | |
---|
79 | if (!empty($_POST['date_creation-'.$row['id']])) |
---|
80 | { |
---|
81 | $data['date_creation'] = $_POST['date_creation-'.$row['id']]; |
---|
82 | } |
---|
83 | else |
---|
84 | { |
---|
85 | $data['date_creation'] = null; |
---|
86 | } |
---|
87 | |
---|
88 | $datas[] = $data; |
---|
89 | |
---|
90 | // tags management |
---|
91 | $tag_ids = array(); |
---|
92 | if (!empty($_POST[ 'tags-'.$row['id'] ])) |
---|
93 | { |
---|
94 | $tag_ids = get_tag_ids($_POST[ 'tags-'.$row['id'] ]); |
---|
95 | } |
---|
96 | set_tags($tag_ids, $row['id']); |
---|
97 | } |
---|
98 | |
---|
99 | mass_updates( |
---|
100 | IMAGES_TABLE, |
---|
101 | array( |
---|
102 | 'primary' => array('id'), |
---|
103 | 'update' => array('name','author','level','comment','date_creation') |
---|
104 | ), |
---|
105 | $datas |
---|
106 | ); |
---|
107 | |
---|
108 | $page['infos'][] = l10n('Photo informations updated'); |
---|
109 | invalidate_user_cache(); |
---|
110 | } |
---|
111 | |
---|
112 | // +-----------------------------------------------------------------------+ |
---|
113 | // | template init | |
---|
114 | // +-----------------------------------------------------------------------+ |
---|
115 | |
---|
116 | $template->set_filenames( |
---|
117 | array('batch_manager_unit' => 'batch_manager_unit.tpl')); |
---|
118 | |
---|
119 | $base_url = PHPWG_ROOT_PATH.'admin.php'; |
---|
120 | |
---|
121 | $template->assign( |
---|
122 | array( |
---|
123 | 'U_ELEMENTS_PAGE' => $base_url.get_query_string_diff(array('display','start')), |
---|
124 | 'F_ACTION' => $base_url.get_query_string_diff(array()), |
---|
125 | 'level_options' => get_privacy_level_options(), |
---|
126 | ) |
---|
127 | ); |
---|
128 | |
---|
129 | // +-----------------------------------------------------------------------+ |
---|
130 | // | global mode thumbnails | |
---|
131 | // +-----------------------------------------------------------------------+ |
---|
132 | |
---|
133 | // how many items to display on this page |
---|
134 | if (!empty($_GET['display'])) |
---|
135 | { |
---|
136 | $page['nb_images'] = intval($_GET['display']); |
---|
137 | } |
---|
138 | else |
---|
139 | { |
---|
140 | $page['nb_images'] = 5; |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | |
---|
145 | if (count($page['cat_elements_id']) > 0) |
---|
146 | { |
---|
147 | $nav_bar = create_navigation_bar( |
---|
148 | $base_url.get_query_string_diff(array('start')), |
---|
149 | count($page['cat_elements_id']), |
---|
150 | $page['start'], |
---|
151 | $page['nb_images'] |
---|
152 | ); |
---|
153 | $template->assign(array('navbar' => $nav_bar)); |
---|
154 | |
---|
155 | $element_ids = array(); |
---|
156 | |
---|
157 | $is_category = false; |
---|
158 | if (isset($_SESSION['bulk_manager_filter']['category']) |
---|
159 | and !isset($_SESSION['bulk_manager_filter']['category_recursive'])) |
---|
160 | { |
---|
161 | $is_category = true; |
---|
162 | } |
---|
163 | |
---|
164 | if (isset($_SESSION['bulk_manager_filter']['prefilter']) |
---|
165 | and 'duplicates' == $_SESSION['bulk_manager_filter']['prefilter']) |
---|
166 | { |
---|
167 | $conf['order_by'] = ' ORDER BY file, id'; |
---|
168 | } |
---|
169 | |
---|
170 | |
---|
171 | $query = ' |
---|
172 | SELECT * |
---|
173 | FROM '.IMAGES_TABLE; |
---|
174 | |
---|
175 | if ($is_category) |
---|
176 | { |
---|
177 | $category_info = get_cat_info($_SESSION['bulk_manager_filter']['category']); |
---|
178 | |
---|
179 | $conf['order_by'] = $conf['order_by_inside_category']; |
---|
180 | if (!empty($category_info['image_order'])) |
---|
181 | { |
---|
182 | $conf['order_by'] = ' ORDER BY '.$category_info['image_order']; |
---|
183 | } |
---|
184 | |
---|
185 | $query.= ' |
---|
186 | JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id'; |
---|
187 | } |
---|
188 | |
---|
189 | $query.= ' |
---|
190 | WHERE id IN ('.implode(',', $page['cat_elements_id']).')'; |
---|
191 | |
---|
192 | if ($is_category) |
---|
193 | { |
---|
194 | $query.= ' |
---|
195 | AND category_id = '.$_SESSION['bulk_manager_filter']['category']; |
---|
196 | } |
---|
197 | |
---|
198 | $query.= ' |
---|
199 | '.$conf['order_by'].' |
---|
200 | LIMIT '.$page['nb_images'].' OFFSET '.$page['start'].' |
---|
201 | ;'; |
---|
202 | $result = pwg_query($query); |
---|
203 | |
---|
204 | while ($row = pwg_db_fetch_assoc($result)) |
---|
205 | { |
---|
206 | $element_ids[] = $row['id']; |
---|
207 | |
---|
208 | $src_image = new SrcImage($row); |
---|
209 | |
---|
210 | $query = ' |
---|
211 | SELECT |
---|
212 | id, |
---|
213 | name |
---|
214 | FROM '.IMAGE_TAG_TABLE.' AS it |
---|
215 | JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id |
---|
216 | WHERE image_id = '.$row['id'].' |
---|
217 | ;'; |
---|
218 | $tag_selection = get_taglist($query); |
---|
219 | |
---|
220 | $legend = render_element_name($row); |
---|
221 | if ($legend != get_name_from_file($row['file'])) |
---|
222 | { |
---|
223 | $legend.= ' ('.$row['file'].')'; |
---|
224 | } |
---|
225 | |
---|
226 | $template->append( |
---|
227 | 'elements', array_merge($row, |
---|
228 | array( |
---|
229 | 'ID' => $row['id'], |
---|
230 | 'TN_SRC' => DerivativeImage::url(IMG_THUMB, $src_image), |
---|
231 | 'FILE_SRC' => DerivativeImage::url(IMG_LARGE, $src_image), |
---|
232 | 'LEGEND' => $legend, |
---|
233 | 'U_EDIT' => get_root_url().'admin.php?page=photo-'.$row['id'], |
---|
234 | 'NAME' => htmlspecialchars(@$row['name']), |
---|
235 | 'AUTHOR' => htmlspecialchars(@$row['author']), |
---|
236 | 'LEVEL' => !empty($row['level'])?$row['level']:'0', |
---|
237 | 'DESCRIPTION' => htmlspecialchars(@$row['comment']), |
---|
238 | 'DATE_CREATION' => $row['date_creation'], |
---|
239 | 'TAGS' => $tag_selection, |
---|
240 | ) |
---|
241 | )); |
---|
242 | } |
---|
243 | |
---|
244 | $template->assign(array( |
---|
245 | 'ELEMENT_IDS' => implode(',', $element_ids), |
---|
246 | 'CACHE_KEYS' => get_admin_client_cache_keys(array('tags')), |
---|
247 | )); |
---|
248 | } |
---|
249 | |
---|
250 | trigger_notify('loc_end_element_set_unit'); |
---|
251 | |
---|
252 | // +-----------------------------------------------------------------------+ |
---|
253 | // | sending html code | |
---|
254 | // +-----------------------------------------------------------------------+ |
---|
255 | |
---|
256 | $template->assign_var_from_handle('ADMIN_CONTENT', 'batch_manager_unit'); |
---|
257 | ?> |
---|