1 | <?php |
---|
2 | defined('USER_COLLEC_PATH') or die('Hacking attempt!'); |
---|
3 | |
---|
4 | # this file is called on basket public page # |
---|
5 | |
---|
6 | global $page, $template, $conf, $user, $tokens; |
---|
7 | |
---|
8 | switch ($page['sub_section']) |
---|
9 | { |
---|
10 | case 'list': |
---|
11 | { |
---|
12 | $template->set_filename('index', dirname(__FILE__) . '/../template/list.tpl'); |
---|
13 | |
---|
14 | if ( isset($_GET['action']) and filter_var($_GET['col_id'], FILTER_VALIDATE_INT) !== false ) |
---|
15 | { |
---|
16 | switch ($_GET['action']) |
---|
17 | { |
---|
18 | // new |
---|
19 | case 'new': |
---|
20 | { |
---|
21 | new UserCollection('new', array(), empty($_GET['name']) ? 'temp' : $_GET['name'], 1); |
---|
22 | redirect(USER_COLLEC_PUBLIC); |
---|
23 | break; |
---|
24 | } |
---|
25 | |
---|
26 | // clear |
---|
27 | case 'clear': |
---|
28 | { |
---|
29 | $query = ' |
---|
30 | DELETE ci |
---|
31 | FROM '.COLLECTION_IMAGES_TABLE.' AS ci |
---|
32 | INNER JOIN '.COLLECTIONS_TABLE.' AS c |
---|
33 | ON ci.col_id = c.id |
---|
34 | WHERE |
---|
35 | c.user_id = '.$user['id'].' |
---|
36 | AND c.id = '.$_GET['col_id'].' |
---|
37 | ;'; |
---|
38 | pwg_query($query); |
---|
39 | |
---|
40 | if (!empty($_SERVER['HTTP_REFERER'])) |
---|
41 | { |
---|
42 | redirect($_SERVER['HTTP_REFERER']); |
---|
43 | } |
---|
44 | break; |
---|
45 | } |
---|
46 | |
---|
47 | // delete |
---|
48 | case 'delete': |
---|
49 | { |
---|
50 | $query = ' |
---|
51 | DELETE ci, c |
---|
52 | FROM '.COLLECTION_IMAGES_TABLE.' AS ci |
---|
53 | RIGHT JOIN '.COLLECTIONS_TABLE.' AS c |
---|
54 | ON ci.col_id = c.id |
---|
55 | WHERE |
---|
56 | c.user_id = '.$user['id'].' |
---|
57 | AND c.id = '.$_GET['col_id'].' |
---|
58 | ;'; |
---|
59 | pwg_query($query); |
---|
60 | |
---|
61 | redirect(USER_COLLEC_PUBLIC); |
---|
62 | break; |
---|
63 | } |
---|
64 | |
---|
65 | // save |
---|
66 | case 'save': |
---|
67 | { |
---|
68 | if (empty($_GET['name'])) |
---|
69 | { |
---|
70 | array_push($page['errors'], l10n('Please give a name')); |
---|
71 | } |
---|
72 | else |
---|
73 | { |
---|
74 | $query = ' |
---|
75 | UPDATE '.COLLECTIONS_TABLE.' |
---|
76 | SET |
---|
77 | name = "'.pwg_db_real_escape_string($_GET['name']).'", |
---|
78 | active = 0 |
---|
79 | WHERE |
---|
80 | user_id = '.$user['id'].' |
---|
81 | AND id = '.$_GET['col_id'].' |
---|
82 | ;'; |
---|
83 | pwg_query($query); |
---|
84 | |
---|
85 | redirect(USER_COLLEC_PUBLIC); |
---|
86 | } |
---|
87 | break; |
---|
88 | } |
---|
89 | |
---|
90 | // set active |
---|
91 | case 'set_active': |
---|
92 | { |
---|
93 | $query = ' |
---|
94 | UPDATE '.COLLECTIONS_TABLE.' |
---|
95 | SET active = 0 |
---|
96 | WHERE user_id = '.$user['id'].' |
---|
97 | ;'; |
---|
98 | pwg_query($query); |
---|
99 | |
---|
100 | $query = ' |
---|
101 | UPDATE '.COLLECTIONS_TABLE.' |
---|
102 | SET active = 1 |
---|
103 | WHERE |
---|
104 | user_id = '.$user['id'].' |
---|
105 | AND id = '.$_GET['col_id'].' |
---|
106 | ;'; |
---|
107 | pwg_query($query); |
---|
108 | |
---|
109 | redirect(USER_COLLEC_PUBLIC); |
---|
110 | break; |
---|
111 | } |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | // get collections |
---|
116 | $query = ' |
---|
117 | SELECT * |
---|
118 | FROM '.COLLECTIONS_TABLE.' |
---|
119 | WHERE user_id = '.$user['id'].' |
---|
120 | ORDER BY date_creation DESC |
---|
121 | '; |
---|
122 | $collections = hash_from_query($query, 'id'); |
---|
123 | |
---|
124 | foreach ($collections as $col) |
---|
125 | { |
---|
126 | $col['date_creation'] = format_date($col['date_creation'], true); |
---|
127 | $col['U_VIEW'] = USER_COLLEC_PUBLIC.'view/'.$col['id']; |
---|
128 | $col['U_EDIT'] = USER_COLLEC_PUBLIC.'edit/'.$col['id']; |
---|
129 | $col['U_ACTIVE'] = USER_COLLEC_PUBLIC.'&action=set_active&col_id='.$col['id']; |
---|
130 | $col['U_DELETE'] = USER_COLLEC_PUBLIC.'&action=delete&col_id='.$col['id']; |
---|
131 | |
---|
132 | if ($col['name'] == 'temp') |
---|
133 | { |
---|
134 | $col['name'] = 'temp #'.$col['id']; |
---|
135 | $col['U_SAVE'] = USER_COLLEC_PUBLIC.'&action=save&col_id='.$col['id']; |
---|
136 | $template->append('temp_col', $col); |
---|
137 | } |
---|
138 | else |
---|
139 | { |
---|
140 | $template->append('collections', $col); |
---|
141 | } |
---|
142 | } |
---|
143 | |
---|
144 | $template->assign('U_CREATE', USER_COLLEC_PUBLIC.'&action=new&col_id=0'); |
---|
145 | break; |
---|
146 | } |
---|
147 | |
---|
148 | case 'edit': |
---|
149 | { |
---|
150 | if (empty($page['col_id'])) |
---|
151 | { |
---|
152 | $_SESSION['page_errors'][] = l10n('Invalid collection'); |
---|
153 | redirect(USER_COLLEC_PUBLIC); |
---|
154 | } |
---|
155 | |
---|
156 | $self_url = USER_COLLEC_PUBLIC . 'edit/'.$page['col_id']; |
---|
157 | |
---|
158 | $template->set_filename('index', dirname(__FILE__).'/../template/edit.tpl'); |
---|
159 | $template->assign(array( |
---|
160 | 'USER_COLLEC_PATH' => USER_COLLEC_PATH, |
---|
161 | 'U_VIEW' => $self_url, |
---|
162 | 'U_LIST' => USER_COLLEC_PUBLIC, |
---|
163 | )); |
---|
164 | |
---|
165 | try { |
---|
166 | $UserCollection = new UserCollection($page['col_id']); |
---|
167 | |
---|
168 | // save properties |
---|
169 | if (isset($_POST['save_col'])) |
---|
170 | { |
---|
171 | $UserCollection->updateParam('name', $_POST['name']); |
---|
172 | $UserCollection->updateParam('public', $_POST['public']); |
---|
173 | } |
---|
174 | |
---|
175 | // remove an element |
---|
176 | if ( isset($_GET['remove']) and preg_match('#^[0-9]+$#', $_GET['remove']) ) |
---|
177 | { |
---|
178 | $UserCollection->removeImages(array($_GET['remove'])); |
---|
179 | } |
---|
180 | |
---|
181 | $template->assign('collection', $UserCollection->getCollectionInfo()); |
---|
182 | |
---|
183 | $template->set_prefilter('index_thumbnails', 'user_collection_thumbnails_list_prefilter'); |
---|
184 | |
---|
185 | $page['start'] = isset($_GET['start']) ? $_GET['start'] : 0; |
---|
186 | $page['items'] = $UserCollection->getImages(); |
---|
187 | |
---|
188 | if (count($page['items']) > $page['nb_image_page']) |
---|
189 | { |
---|
190 | $page['navigation_bar'] = create_navigation_bar( |
---|
191 | $self_url, |
---|
192 | count($page['items']), |
---|
193 | $page['start'], |
---|
194 | $page['nb_image_page'], |
---|
195 | false |
---|
196 | ); |
---|
197 | $template->assign('navbar', $page['navigation_bar']); |
---|
198 | } |
---|
199 | |
---|
200 | include(PHPWG_ROOT_PATH . 'include/category_default.inc.php'); |
---|
201 | } |
---|
202 | catch (Exception $e) |
---|
203 | { |
---|
204 | array_push($page['errors'], $e->getMessage()); |
---|
205 | } |
---|
206 | |
---|
207 | break; |
---|
208 | } |
---|
209 | |
---|
210 | case 'view': |
---|
211 | { |
---|
212 | if (empty($page['col_id'])) |
---|
213 | { |
---|
214 | $_SESSION['page_errors'][] = l10n('Invalid collection'); |
---|
215 | redirect(get_home_url()); |
---|
216 | } |
---|
217 | |
---|
218 | $self_url = USER_COLLEC_PUBLIC . 'view/'.$page['col_id']; |
---|
219 | |
---|
220 | $template->set_filename('index', dirname(__FILE__).'/../template/view.tpl'); |
---|
221 | $template->assign(array( |
---|
222 | 'USER_COLLEC_PATH' => USER_COLLEC_PATH, |
---|
223 | 'U_VIEW' => $self_url, |
---|
224 | )); |
---|
225 | |
---|
226 | try |
---|
227 | { |
---|
228 | $UserCollection = new UserCollection($page['col_id']); |
---|
229 | |
---|
230 | if ($UserCollection->getParam('user_id') == $user['id']) |
---|
231 | { |
---|
232 | $template->assign('U_LIST', USER_COLLEC_PUBLIC); |
---|
233 | } |
---|
234 | |
---|
235 | $template->assign('collection', $UserCollection->getCollectionInfo()); |
---|
236 | |
---|
237 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
238 | $template->assign('OWNER', get_username($UserCollection->getParam('user_id'))); |
---|
239 | |
---|
240 | $page['start'] = isset($_GET['start']) ? $_GET['start'] : 0; |
---|
241 | $page['items'] = $UserCollection->getImages(); |
---|
242 | |
---|
243 | if (count($page['items']) > $page['nb_image_page']) |
---|
244 | { |
---|
245 | $page['navigation_bar'] = create_navigation_bar( |
---|
246 | $self_url, |
---|
247 | count($page['items']), |
---|
248 | $page['start'], |
---|
249 | $page['nb_image_page'], |
---|
250 | false |
---|
251 | ); |
---|
252 | $template->assign('navbar', $page['navigation_bar']); |
---|
253 | } |
---|
254 | |
---|
255 | include(PHPWG_ROOT_PATH . 'include/category_default.inc.php'); |
---|
256 | } |
---|
257 | catch (Exception $e) |
---|
258 | { |
---|
259 | array_push($page['errors'], $e->getMessage()); |
---|
260 | } |
---|
261 | |
---|
262 | break; |
---|
263 | } |
---|
264 | |
---|
265 | // case 'send': |
---|
266 | // { |
---|
267 | |
---|
268 | // break; |
---|
269 | // } |
---|
270 | } |
---|
271 | |
---|
272 | $template->assign('USER_COLLEC_PATH', USER_COLLEC_PATH); |
---|
273 | |
---|
274 | function user_collection_thumbnails_list_prefilter($content, &$smarty) |
---|
275 | { |
---|
276 | $search = '<span class="thumbName">'; |
---|
277 | |
---|
278 | $add = '<a href="{$U_VIEW}&remove={$thumbnail.id}" rel="nofollow"> |
---|
279 | <img src="{$USER_COLLEC_PATH}template/image_delete.png" title="{\'Remove from collection\'|@translate}"> |
---|
280 | </a> '; |
---|
281 | |
---|
282 | return str_replace($search, $search.$add, $content); |
---|
283 | } |
---|
284 | |
---|
285 | ?> |
---|