1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # |
---|
4 | # This file is part of myGmaps, a plugin for Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2010 Philippe aka amalgame |
---|
7 | # Licensed under the GPL version 2.0 license. |
---|
8 | # See LICENSE file or |
---|
9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
10 | # |
---|
11 | # -- END LICENSE BLOCK ------------------------------------ |
---|
12 | |
---|
13 | $tab = isset($_GET['tab']) ? $_GET['tab'] : 'list'; |
---|
14 | |
---|
15 | # Save config |
---|
16 | if (!empty($_POST['save'])) { |
---|
17 | try { |
---|
18 | $core->blog->settings->myGmaps->put('center',$_POST['center']); |
---|
19 | $core->blog->settings->myGmaps->put('zoom',$_POST['zoom']); |
---|
20 | $core->blog->settings->myGmaps->put('map_type',$_POST['map_type']); |
---|
21 | $core->blog->settings->myGmaps->put('scrollwheel',$_POST['scrollwheel']); |
---|
22 | http::redirect($p_url.'&go=maps&tab=config&upd=1'); |
---|
23 | } catch (Exception $e) { |
---|
24 | $core->error->add($e->getMessage()); |
---|
25 | } |
---|
26 | } |
---|
27 | # Add icon |
---|
28 | if (!empty($_POST['send'])) { |
---|
29 | try{ |
---|
30 | files::uploadStatus($_FILES['upfile']); |
---|
31 | $fm = new filemanager(dirname(__FILE__).'/icons'); |
---|
32 | $fm->uploadFile($_FILES['upfile']['tmp_name'],$_FILES['upfile']['name']); |
---|
33 | http::redirect($p_url.'&go=maps&tab=icons&add=1'); |
---|
34 | } catch (Exception $e) { |
---|
35 | $core->error->add($e->getMessage()); |
---|
36 | } |
---|
37 | } |
---|
38 | # Delete icons |
---|
39 | if (!empty($_POST['delete'])) { |
---|
40 | try { |
---|
41 | foreach ($_POST['ids'] as $filename) { |
---|
42 | unlink(dirname(__FILE__).'/icons/'.$filename); |
---|
43 | } |
---|
44 | http::redirect($p_url.'&go=maps&tab=icons&del=1'); |
---|
45 | } catch (Exception $e) { |
---|
46 | $core->error->add($e->getMessage()); |
---|
47 | } |
---|
48 | } |
---|
49 | # Getting categories |
---|
50 | try { |
---|
51 | $categories = $core->blog->getCategories(array('post_type'=>'map')); |
---|
52 | } catch (Exception $e) { |
---|
53 | $core->error->add($e->getMessage()); |
---|
54 | } |
---|
55 | |
---|
56 | # Getting authors |
---|
57 | try { |
---|
58 | $users = $core->blog->getPostsUsers(); |
---|
59 | } catch (Exception $e) { |
---|
60 | $core->error->add($e->getMessage()); |
---|
61 | } |
---|
62 | |
---|
63 | # Getting dates |
---|
64 | try { |
---|
65 | $dates = $core->blog->getDates(array('type'=>'month','post_type'=>'map')); |
---|
66 | } catch (Exception $e) { |
---|
67 | $core->error->add($e->getMessage()); |
---|
68 | } |
---|
69 | |
---|
70 | # Creating filter combo boxes |
---|
71 | if (!$core->error->flag()) |
---|
72 | { |
---|
73 | # Filter form we'll put in html_block |
---|
74 | $users_combo = $categories_combo = array(); |
---|
75 | $users_combo['-'] = $categories_combo['-'] = ''; |
---|
76 | while ($users->fetch()) |
---|
77 | { |
---|
78 | $user_cn = dcUtils::getUserCN($users->user_id,$users->user_name, |
---|
79 | $users->user_firstname,$users->user_displayname); |
---|
80 | |
---|
81 | if ($user_cn != $users->user_id) { |
---|
82 | $user_cn .= ' ('.$users->user_id.')'; |
---|
83 | } |
---|
84 | |
---|
85 | $users_combo[$user_cn] = $users->user_id; |
---|
86 | } |
---|
87 | |
---|
88 | $categories_combo[__('None')] = 'NULL'; |
---|
89 | while ($categories->fetch()) { |
---|
90 | $categories_combo[str_repeat(' ',$categories->level-1).'• '. |
---|
91 | html::escapeHTML($categories->cat_title). |
---|
92 | ' ('.$categories->nb_post.')'] = $categories->cat_id; |
---|
93 | } |
---|
94 | |
---|
95 | $status_combo = array( |
---|
96 | '-' => '', |
---|
97 | __('published') => '1', |
---|
98 | __('pending') => '-2', |
---|
99 | __('unpublished') => '0' |
---|
100 | ); |
---|
101 | |
---|
102 | $post_maps_combo = array( |
---|
103 | '-' => '', |
---|
104 | __('None') => 'none', |
---|
105 | __('Point of interest') => 'marker', |
---|
106 | __('Polyline') => 'polyline', |
---|
107 | __('Polygon') => 'polygon', |
---|
108 | __('Included kml file') => 'kml' |
---|
109 | ); |
---|
110 | |
---|
111 | # Months array |
---|
112 | $dt_m_combo['-'] = ''; |
---|
113 | while ($dates->fetch()) { |
---|
114 | $dt_m_combo[dt::str('%B %Y',$dates->ts())] = $dates->year().$dates->month(); |
---|
115 | } |
---|
116 | |
---|
117 | $sortby_combo = array( |
---|
118 | __('Date') => 'post_dt', |
---|
119 | __('Title') => 'post_title', |
---|
120 | __('Category') => 'cat_title', |
---|
121 | __('Author') => 'user_id', |
---|
122 | __('Status') => 'post_status' |
---|
123 | ); |
---|
124 | |
---|
125 | $order_combo = array( |
---|
126 | __('Descending') => 'desc', |
---|
127 | __('Ascending') => 'asc' |
---|
128 | ); |
---|
129 | } |
---|
130 | |
---|
131 | # Actions combo box |
---|
132 | $combo_action = array(); |
---|
133 | if ($core->auth->check('publish,contentadmin',$core->blog->id)) |
---|
134 | { |
---|
135 | $combo_action[__('Status')] = array( |
---|
136 | __('Published') => 'published', |
---|
137 | __('Pending') => 'pending', |
---|
138 | __('Unpublished') => 'unpublished' |
---|
139 | ); |
---|
140 | } |
---|
141 | |
---|
142 | $combo_action[__('Change')] = array(__('Change category') => 'category'); |
---|
143 | if ($core->auth->check('admin',$core->blog->id)) |
---|
144 | { |
---|
145 | $combo_action[__('Change')] = array_merge($combo_action[__('Change')], |
---|
146 | array(__('Change author') => 'author')); |
---|
147 | } |
---|
148 | if ($core->auth->check('delete,contentadmin',$core->blog->id)) |
---|
149 | { |
---|
150 | $combo_action[__('Delete')] = array(__('Delete') => 'delete'); |
---|
151 | } |
---|
152 | |
---|
153 | /* Get posts |
---|
154 | -------------------------------------------------------- */ |
---|
155 | $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : ''; |
---|
156 | $cat_id = !empty($_GET['cat_id']) ? $_GET['cat_id'] : ''; |
---|
157 | $status = isset($_GET['status']) ? $_GET['status'] : ''; |
---|
158 | $month = !empty($_GET['month']) ? $_GET['month'] : ''; |
---|
159 | $post_maps = !empty($_GET['post_maps']) ? $_GET['post_maps'] : ''; |
---|
160 | $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'post_dt'; |
---|
161 | $order = !empty($_GET['order']) ? $_GET['order'] : 'desc'; |
---|
162 | |
---|
163 | $show_filters = false; |
---|
164 | |
---|
165 | $page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1; |
---|
166 | $nb_per_page = 30; |
---|
167 | |
---|
168 | if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { |
---|
169 | if ($nb_per_page != $_GET['nb']) { |
---|
170 | $show_filters = true; |
---|
171 | } |
---|
172 | $nb_per_page = (integer) $_GET['nb']; |
---|
173 | } |
---|
174 | |
---|
175 | $params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); |
---|
176 | $params['no_content'] = true; |
---|
177 | $params['post_type'] = 'map'; |
---|
178 | //$params['columns'] = array('post_maps'); |
---|
179 | |
---|
180 | # - User filter |
---|
181 | if ($user_id !== '' && in_array($user_id,$users_combo)) { |
---|
182 | $params['user_id'] = $user_id; |
---|
183 | $show_filters = true; |
---|
184 | } |
---|
185 | |
---|
186 | # - Categories filter |
---|
187 | if ($cat_id !== '' && in_array($cat_id,$categories_combo)) { |
---|
188 | $params['cat_id'] = $cat_id; |
---|
189 | $show_filters = true; |
---|
190 | } |
---|
191 | |
---|
192 | # - Status filter |
---|
193 | if ($status !== '' && in_array($status,$status_combo)) { |
---|
194 | $params['post_status'] = $status; |
---|
195 | $show_filters = true; |
---|
196 | } |
---|
197 | |
---|
198 | # - Month filter |
---|
199 | if ($month !== '' && in_array($month,$dt_m_combo)) { |
---|
200 | $params['post_month'] = substr($month,4,2); |
---|
201 | $params['post_year'] = substr($month,0,4); |
---|
202 | $show_filters = true; |
---|
203 | } |
---|
204 | |
---|
205 | # - Map type filter |
---|
206 | if ($post_maps != '' && in_array($post_maps,$post_maps_combo)) { |
---|
207 | $params['sql'] .= "AND post_meta LIKE '%".$post_maps."%' "; |
---|
208 | $show_filters = true; |
---|
209 | } |
---|
210 | |
---|
211 | # - Sortby and order filter |
---|
212 | if ($sortby !== '' && in_array($sortby,$sortby_combo)) { |
---|
213 | if ($order !== '' && in_array($order,$order_combo)) { |
---|
214 | $params['order'] = $sortby.' '.$order; |
---|
215 | } |
---|
216 | |
---|
217 | if ($sortby != 'post_dt' || $order != 'desc') { |
---|
218 | $show_filters = true; |
---|
219 | } |
---|
220 | } |
---|
221 | |
---|
222 | # Get posts |
---|
223 | try { |
---|
224 | $posts = $core->blog->getPosts($params); |
---|
225 | $counter = $core->blog->getPosts($params,true); |
---|
226 | $post_list = new adminMyGmapsList($core,$posts,$counter->f(0)); |
---|
227 | } catch (Exception $e) { |
---|
228 | $core->error->add($e->getMessage()); |
---|
229 | } |
---|
230 | |
---|
231 | /* DISPLAY |
---|
232 | -------------------------------------------------------- */ |
---|
233 | |
---|
234 | echo |
---|
235 | '<html>'. |
---|
236 | '<head>'. |
---|
237 | '<title>'.__('Google Maps').'</title>'. |
---|
238 | dcPage::jsPageTabs($tab). |
---|
239 | dcPage::jsLoad('http://maps.google.com/maps/api/js?sensor=false'). |
---|
240 | dcPage::jsLoad(DC_ADMIN_URL.'?pf=myGmaps/js/myGmaps.js'). |
---|
241 | dcPage::jsLoad(DC_ADMIN_URL.'?pf=myGmaps/js/_maps.js'). |
---|
242 | '<link type="text/css" rel="stylesheet" href="'.DC_ADMIN_URL.'?pf=myGmaps/css/style.css" />'. |
---|
243 | '<link type="text/css" rel="stylesheet" href="'.DC_ADMIN_URL.'?pf=myGmaps/css/ui.theme.css" />'. |
---|
244 | '<script type="text/javascript">'. |
---|
245 | dcPage::jsVar('myGmaps.msg.geocoder_error',__('Geocode was not successful for the following reason:')). |
---|
246 | dcPage::jsVar('myGmaps.msg.type',__('Type')). |
---|
247 | dcPage::jsVar('myGmaps.msg.coordinates',__('Coordinates')). |
---|
248 | dcPage::jsVar('myGmaps.msg.no_icon_selected',__('Please, select at leat one icon')). |
---|
249 | '</script>'. |
---|
250 | '</head>'. |
---|
251 | '<body>'; |
---|
252 | |
---|
253 | # Display messages |
---|
254 | $msg = ''; |
---|
255 | if (isset($_GET['upd']) && $_GET['upd'] === '1') { |
---|
256 | $msg = __('Configuration has been successfully saved'); |
---|
257 | } |
---|
258 | if (isset($_GET['add']) && $_GET['add'] === '1') { |
---|
259 | $msg = __('Icon has been successfully added'); |
---|
260 | } |
---|
261 | if (isset($_GET['del']) && $_GET['del'] === '1') { |
---|
262 | $msg = __('Selected icons have been successfully deleted'); |
---|
263 | } |
---|
264 | if (isset($_GET['act']) && $_GET['act'] === '1') { |
---|
265 | $msg = __('Selected map posts status have been successfully changed'); |
---|
266 | } |
---|
267 | if (isset($_GET['act']) && $_GET['act'] === '2') { |
---|
268 | $msg = __('Selected map posts categories have been successfully changed'); |
---|
269 | } |
---|
270 | if (isset($_GET['act']) && $_GET['act'] === '3') { |
---|
271 | $msg = __('Selected map posts authors have been successfully changed'); |
---|
272 | } |
---|
273 | if (isset($_GET['act']) && $_GET['act'] === '4') { |
---|
274 | $msg = __('Selected map posts have been successfully deleted'); |
---|
275 | } |
---|
276 | echo $msg !== '' ? sprintf('<p class="message">%s</p>',$msg) : ''; |
---|
277 | |
---|
278 | if (!$core->error->flag()) |
---|
279 | { |
---|
280 | echo |
---|
281 | '<h2>'.html::escapeHTML($core->blog->name).' › '.__('Google Maps').' - '. |
---|
282 | '<a href="'.$p_url.'&go=map" class="button">'.__('New element').'</a></h2>'; |
---|
283 | |
---|
284 | echo '<div class="multi-part" id="list" title="'.__('Map elements').'">'; |
---|
285 | |
---|
286 | if (!$show_filters) { |
---|
287 | echo |
---|
288 | dcPage::jsLoad('js/filter-controls.js'). |
---|
289 | '<p><a id="filter-control" class="form-control" href="#">'. |
---|
290 | __('Filters').'</a></p>'; |
---|
291 | } |
---|
292 | |
---|
293 | echo |
---|
294 | '<form action="'.$p_url.'" method="get" id="filters-form">'. |
---|
295 | '<fieldset><legend>'.__('Filters').'</legend>'. |
---|
296 | '<div class="three-cols">'. |
---|
297 | '<div class="col">'. |
---|
298 | '<label>'.__('Author:'). |
---|
299 | form::combo('user_id',$users_combo,$user_id).'</label> '. |
---|
300 | '<label>'.__('Category:'). |
---|
301 | form::combo('cat_id',$categories_combo,$cat_id).'</label> '. |
---|
302 | '<label>'.__('Status:'). |
---|
303 | form::combo('status',$status_combo,$status).'</label> '. |
---|
304 | '</div>'. |
---|
305 | |
---|
306 | '<div class="col">'. |
---|
307 | '<label>'.__('Month:'). |
---|
308 | form::combo('month',$dt_m_combo,$month).'</label> '. |
---|
309 | '<label>'.__('Map element type:'). |
---|
310 | form::combo('post_maps',$post_maps_combo,$post_maps).'</label> '. |
---|
311 | '</div>'. |
---|
312 | |
---|
313 | '<div class="col">'. |
---|
314 | '<p><label>'.__('Order by:'). |
---|
315 | form::combo('sortby',$sortby_combo,$sortby).'</label> '. |
---|
316 | '<label>'.__('Sort:'). |
---|
317 | form::combo('order',$order_combo,$order).'</label></p>'. |
---|
318 | '<p><label class="classic">'. form::field('nb',3,3,$nb_per_page).' '. |
---|
319 | __('Map elements per page').'</label> '. |
---|
320 | $core->formNonce(). |
---|
321 | '<input type="submit" name="maps_filters" value="'.__('filter').'" /></p>'. |
---|
322 | form::hidden(array('p'),'myGmaps'). |
---|
323 | '</div>'. |
---|
324 | '</div>'. |
---|
325 | '<br class="clear" />'. //Opera sucks |
---|
326 | '</fieldset>'. |
---|
327 | '</form>'; |
---|
328 | |
---|
329 | $hidden_fields = ''; |
---|
330 | foreach ($filters as $k) { |
---|
331 | if (array_key_exists($k,$_GET)) { |
---|
332 | $hidden_fields .= form::hidden(array($k),$_GET[$k]); |
---|
333 | } |
---|
334 | } |
---|
335 | # Show posts |
---|
336 | $post_list->display($page,$nb_per_page,$p_url, |
---|
337 | '<form action="'.$p_url.'&go=maps_actions" method="post" id="form-entries">'. |
---|
338 | |
---|
339 | '%s'. |
---|
340 | |
---|
341 | '<div class="two-cols">'. |
---|
342 | '<p class="col checkboxes-helpers"></p>'. |
---|
343 | |
---|
344 | '<p class="col right">'.__('Selected map elements action:').' '. |
---|
345 | form::combo('action',$combo_action). |
---|
346 | $hidden_fields. |
---|
347 | '<input type="submit" value="'.__('ok').'" /></p>'. |
---|
348 | $core->formNonce(). |
---|
349 | '</div>'. |
---|
350 | '</form>' |
---|
351 | ); |
---|
352 | |
---|
353 | echo '</div>'; |
---|
354 | |
---|
355 | echo |
---|
356 | '<div class="multi-part" id="config" title="'.__('Configuration').'">'. |
---|
357 | '<form method="post" action="'.$p_url.'" id="settings-form">'. |
---|
358 | '<fieldset><legend>'.__('Default map options').'</legend>'. |
---|
359 | '<p class="field"><label>'.__('Use scrollwheel'). |
---|
360 | form::checkbox('scrollwheel',1,$core->blog->settings->myGmaps->scrollwheel). |
---|
361 | '</label></p>'. |
---|
362 | '<p>'.__('Choose map center, zoom level and map type.').'</p>'. |
---|
363 | '<p>'. |
---|
364 | form::field('q',50,255). |
---|
365 | '<input type="button" class="submit" name="mq" id="search" value="'.__('Search').'" />'. |
---|
366 | '</p>'. |
---|
367 | '<div class="area" id="map_canvas"></div>'. |
---|
368 | '</fieldset>'. |
---|
369 | '<p class="area" id="map-details-area" >'. |
---|
370 | '<label class="infowindow" for="map-details">'.__('Map details:').'</label>'. |
---|
371 | '<div id="map-details"></div>'. |
---|
372 | '</p>'. |
---|
373 | '<p>'. |
---|
374 | form::hidden('center',$core->blog->settings->myGmaps->center). |
---|
375 | form::hidden('zoom',$core->blog->settings->myGmaps->zoom). |
---|
376 | form::hidden('map_type',$core->blog->settings->myGmaps->map_type). |
---|
377 | $core->formNonce(). |
---|
378 | '<input type="submit" name="save" value="'.__('Save configuration').'" />'. |
---|
379 | '</p>'. |
---|
380 | '</form>'. |
---|
381 | '</div>'; |
---|
382 | |
---|
383 | echo |
---|
384 | '<div class="multi-part" id="icons" title="'.__('Icons').'">'. |
---|
385 | '<form method="post" action="'.$p_url.'&tab=icons" id="icons-form" enctype="multipart/form-data">'. |
---|
386 | '<fieldset><legend>'.__('Add icon').'</legend>'. |
---|
387 | '<p><label>'.__('Choose a file:'). |
---|
388 | ' ('.sprintf(__('Maximum size %s'),files::size(DC_MAX_UPLOAD_SIZE)).')'. |
---|
389 | '<input type="file" name="upfile" size="20" />'. |
---|
390 | '</label></p>'. |
---|
391 | '<p><input type="submit" name="send" value="'.__('send').'" /></p>'. |
---|
392 | '</fieldset>'. |
---|
393 | '<fieldset><legend>'.__('Delete icons').'</legend>'. |
---|
394 | '<p>'.__('Select icons to delete by clicking on them').'</p>'. |
---|
395 | '<ul>'; |
---|
396 | foreach (myGmapsUtils::getMapIcons() as $icon) { |
---|
397 | echo sprintf( |
---|
398 | '<li class="ui-corner-top ui-corner-bottom" style="background-image: url(%1$s); background-repeat: no-repeat; background-position: top center;">%2$s</li>', |
---|
399 | myGmapsUtils::getAdminIconURL(basename($icon)), |
---|
400 | form::checkbox(array('ids[]'),basename($icon),false) |
---|
401 | ); |
---|
402 | } |
---|
403 | echo |
---|
404 | '</ul>'. |
---|
405 | '<p>'. |
---|
406 | $core->formNonce(). |
---|
407 | '<input type="submit" name="delete" value="'.__('Delete selected icons').'" />'. |
---|
408 | '</p>'. |
---|
409 | '</fieldset>'. |
---|
410 | '</form>'. |
---|
411 | '</div>'; |
---|
412 | } |
---|
413 | |
---|
414 | dcPage::helpBlock('myGmaps'); |
---|
415 | |
---|
416 | echo |
---|
417 | '</body>'. |
---|
418 | '</html>'; |
---|
419 | |
---|
420 | ?> |
---|