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=0'); |
---|
23 | } catch (Exception $e) { |
---|
24 | $core->error->add($e->getMessage()); |
---|
25 | } |
---|
26 | } |
---|
27 | # Getting categories |
---|
28 | try { |
---|
29 | $categories = $core->blog->getCategories(array('post_type'=>'map')); |
---|
30 | } catch (Exception $e) { |
---|
31 | $core->error->add($e->getMessage()); |
---|
32 | } |
---|
33 | |
---|
34 | # Getting authors |
---|
35 | try { |
---|
36 | $users = $core->blog->getPostsUsers(); |
---|
37 | } catch (Exception $e) { |
---|
38 | $core->error->add($e->getMessage()); |
---|
39 | } |
---|
40 | |
---|
41 | # Getting dates |
---|
42 | try { |
---|
43 | $dates = $core->blog->getDates(array('type'=>'month','post_type'=>'map')); |
---|
44 | } catch (Exception $e) { |
---|
45 | $core->error->add($e->getMessage()); |
---|
46 | } |
---|
47 | |
---|
48 | # Creating filter combo boxes |
---|
49 | if (!$core->error->flag()) |
---|
50 | { |
---|
51 | # Filter form we'll put in html_block |
---|
52 | $users_combo = $categories_combo = array(); |
---|
53 | $users_combo['-'] = $categories_combo['-'] = ''; |
---|
54 | while ($users->fetch()) |
---|
55 | { |
---|
56 | $user_cn = dcUtils::getUserCN($users->user_id,$users->user_name, |
---|
57 | $users->user_firstname,$users->user_displayname); |
---|
58 | |
---|
59 | if ($user_cn != $users->user_id) { |
---|
60 | $user_cn .= ' ('.$users->user_id.')'; |
---|
61 | } |
---|
62 | |
---|
63 | $users_combo[$user_cn] = $users->user_id; |
---|
64 | } |
---|
65 | |
---|
66 | $categories_combo[__('None')] = 'NULL'; |
---|
67 | while ($categories->fetch()) { |
---|
68 | $categories_combo[str_repeat(' ',$categories->level-1).'• '. |
---|
69 | html::escapeHTML($categories->cat_title). |
---|
70 | ' ('.$categories->nb_post.')'] = $categories->cat_id; |
---|
71 | } |
---|
72 | |
---|
73 | $status_combo = array( |
---|
74 | '-' => '', |
---|
75 | __('pending') => '-2', |
---|
76 | __('online') => '1' |
---|
77 | ); |
---|
78 | |
---|
79 | $post_maps_combo = array( |
---|
80 | '-' => '', |
---|
81 | __('None') => '', |
---|
82 | __('Point of interest') => 'marker', |
---|
83 | __('Polyline') => 'polyline', |
---|
84 | __('Polygon') => 'polygon', |
---|
85 | __('Included kml file') => 'kml' |
---|
86 | ); |
---|
87 | |
---|
88 | # Months array |
---|
89 | $dt_m_combo['-'] = ''; |
---|
90 | while ($dates->fetch()) { |
---|
91 | $dt_m_combo[dt::str('%B %Y',$dates->ts())] = $dates->year().$dates->month(); |
---|
92 | } |
---|
93 | |
---|
94 | $sortby_combo = array( |
---|
95 | __('Date') => 'post_dt', |
---|
96 | __('Title') => 'post_title', |
---|
97 | __('Category') => 'cat_title', |
---|
98 | __('Author') => 'user_id', |
---|
99 | __('Status') => 'post_status' |
---|
100 | ); |
---|
101 | |
---|
102 | $order_combo = array( |
---|
103 | __('Descending') => 'desc', |
---|
104 | __('Ascending') => 'asc' |
---|
105 | ); |
---|
106 | } |
---|
107 | |
---|
108 | # Actions combo box |
---|
109 | $combo_action = array(); |
---|
110 | if ($core->auth->check('publish,contentadmin',$core->blog->id)) |
---|
111 | { |
---|
112 | $combo_action[__('Status')] = array( |
---|
113 | __('Publish') => 'publish', |
---|
114 | __('Mark as pending') => 'pending' |
---|
115 | ); |
---|
116 | } |
---|
117 | |
---|
118 | $combo_action[__('Change')] = array(__('Change category') => 'category'); |
---|
119 | if ($core->auth->check('admin',$core->blog->id)) |
---|
120 | { |
---|
121 | $combo_action[__('Change')] = array_merge($combo_action[__('Change')], |
---|
122 | array(__('Change author') => 'author')); |
---|
123 | } |
---|
124 | if ($core->auth->check('delete,contentadmin',$core->blog->id)) |
---|
125 | { |
---|
126 | $combo_action[__('Delete')] = array(__('Delete') => 'delete'); |
---|
127 | } |
---|
128 | |
---|
129 | /* Get posts |
---|
130 | -------------------------------------------------------- */ |
---|
131 | $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : ''; |
---|
132 | $cat_id = !empty($_GET['cat_id']) ? $_GET['cat_id'] : ''; |
---|
133 | $status = isset($_GET['status']) ? $_GET['status'] : ''; |
---|
134 | $month = !empty($_GET['month']) ? $_GET['month'] : ''; |
---|
135 | $post_maps = !empty($_GET['post_maps']) ? $_GET['post_maps'] : ''; |
---|
136 | $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'post_dt'; |
---|
137 | $order = !empty($_GET['order']) ? $_GET['order'] : 'desc'; |
---|
138 | |
---|
139 | $show_filters = false; |
---|
140 | |
---|
141 | $page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1; |
---|
142 | $nb_per_page = 30; |
---|
143 | |
---|
144 | if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { |
---|
145 | if ($nb_per_page != $_GET['nb']) { |
---|
146 | $show_filters = true; |
---|
147 | } |
---|
148 | $nb_per_page = (integer) $_GET['nb']; |
---|
149 | } |
---|
150 | |
---|
151 | $params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); |
---|
152 | $params['no_content'] = true; |
---|
153 | $params['post_type'] = 'map'; |
---|
154 | //$params['columns'] = array('post_maps'); |
---|
155 | |
---|
156 | # - User filter |
---|
157 | if ($user_id !== '' && in_array($user_id,$users_combo)) { |
---|
158 | $params['user_id'] = $user_id; |
---|
159 | $show_filters = true; |
---|
160 | } |
---|
161 | |
---|
162 | # - Categories filter |
---|
163 | if ($cat_id !== '' && in_array($cat_id,$categories_combo)) { |
---|
164 | $params['cat_id'] = $cat_id; |
---|
165 | $show_filters = true; |
---|
166 | } |
---|
167 | |
---|
168 | # - Status filter |
---|
169 | if ($status !== '' && in_array($status,$status_combo)) { |
---|
170 | $params['post_status'] = $status; |
---|
171 | $show_filters = true; |
---|
172 | } |
---|
173 | |
---|
174 | # - Month filter |
---|
175 | if ($month !== '' && in_array($month,$dt_m_combo)) { |
---|
176 | $params['post_month'] = substr($month,4,2); |
---|
177 | $params['post_year'] = substr($month,0,4); |
---|
178 | $show_filters = true; |
---|
179 | } |
---|
180 | |
---|
181 | # - Map type filter |
---|
182 | if ($post_maps != '' && in_array($post_maps,$post_maps_combo)) { |
---|
183 | $params['sql'] .= "AND post_meta LIKE '%".$post_maps."%' "; |
---|
184 | $show_filters = true; |
---|
185 | } |
---|
186 | |
---|
187 | # - Sortby and order filter |
---|
188 | if ($sortby !== '' && in_array($sortby,$sortby_combo)) { |
---|
189 | if ($order !== '' && in_array($order,$order_combo)) { |
---|
190 | $params['order'] = $sortby.' '.$order; |
---|
191 | } |
---|
192 | |
---|
193 | if ($sortby != 'post_dt' || $order != 'desc') { |
---|
194 | $show_filters = true; |
---|
195 | } |
---|
196 | } |
---|
197 | |
---|
198 | # Get posts |
---|
199 | try { |
---|
200 | $posts = $core->blog->getPosts($params); |
---|
201 | $counter = $core->blog->getPosts($params,true); |
---|
202 | $post_list = new adminMyGmapsList($core,$posts,$counter->f(0)); |
---|
203 | } catch (Exception $e) { |
---|
204 | $core->error->add($e->getMessage()); |
---|
205 | } |
---|
206 | |
---|
207 | /* DISPLAY |
---|
208 | -------------------------------------------------------- */ |
---|
209 | |
---|
210 | echo |
---|
211 | '<html>'. |
---|
212 | '<head>'. |
---|
213 | '<title>'.__('Google Maps').'</title>'. |
---|
214 | dcPage::jsPageTabs($tab). |
---|
215 | dcPage::jsLoad('http://maps.google.com/maps/api/js?sensor=false'). |
---|
216 | dcPage::jsLoad(DC_ADMIN_URL.'?pf=myGmaps/js/myGmaps.js'). |
---|
217 | dcPage::jsLoad(DC_ADMIN_URL.'?pf=myGmaps/js/_maps.js'). |
---|
218 | '<link type="text/css" rel="stylesheet" href="'.DC_ADMIN_URL.'?pf=myGmaps/style.css" />'. |
---|
219 | '</head>'. |
---|
220 | '<body>'; |
---|
221 | |
---|
222 | # Display messages |
---|
223 | if (isset($_GET['upd']) && $_GET['upd'] === '0') { |
---|
224 | echo '<p class="message">'.__('Configuration has been successfully saved').'</p>'; |
---|
225 | } |
---|
226 | |
---|
227 | if (!$core->error->flag()) |
---|
228 | { |
---|
229 | echo |
---|
230 | '<h2>'.html::escapeHTML($core->blog->name).' › '.__('Google Maps').' - '. |
---|
231 | '<a href="'.$p_url.'&go=map" class="button">'.__('New element').'</a></h2>'; |
---|
232 | |
---|
233 | echo '<div class="multi-part" id="list" title="'.__('Map elements').'">'; |
---|
234 | |
---|
235 | if (!$show_filters) { |
---|
236 | echo |
---|
237 | dcPage::jsLoad('js/filter-controls.js'). |
---|
238 | '<p><a id="filter-control" class="form-control" href="#">'. |
---|
239 | __('Filters').'</a></p>'; |
---|
240 | } |
---|
241 | |
---|
242 | echo |
---|
243 | '<form action="'.$p_url.'" method="get" id="filters-form">'. |
---|
244 | '<fieldset><legend>'.__('Filters').'</legend>'. |
---|
245 | '<div class="three-cols">'. |
---|
246 | '<div class="col">'. |
---|
247 | '<label>'.__('Author:'). |
---|
248 | form::combo('user_id',$users_combo,$user_id).'</label> '. |
---|
249 | '<label>'.__('Category:'). |
---|
250 | form::combo('cat_id',$categories_combo,$cat_id).'</label> '. |
---|
251 | '<label>'.__('Status:'). |
---|
252 | form::combo('status',$status_combo,$status).'</label> '. |
---|
253 | '</div>'. |
---|
254 | |
---|
255 | '<div class="col">'. |
---|
256 | '<label>'.__('Month:'). |
---|
257 | form::combo('month',$dt_m_combo,$month).'</label> '. |
---|
258 | '<label>'.__('Map element type:'). |
---|
259 | form::combo('post_maps',$post_maps_combo,$post_maps).'</label> '. |
---|
260 | '</div>'. |
---|
261 | |
---|
262 | '<div class="col">'. |
---|
263 | '<p><label>'.__('Order by:'). |
---|
264 | form::combo('sortby',$sortby_combo,$sortby).'</label> '. |
---|
265 | '<label>'.__('Sort:'). |
---|
266 | form::combo('order',$order_combo,$order).'</label></p>'. |
---|
267 | '<p><label class="classic">'. form::field('nb',3,3,$nb_per_page).' '. |
---|
268 | __('Map elements per page').'</label> '. |
---|
269 | $core->formNonce(). |
---|
270 | '<input type="submit" name="maps_filters" value="'.__('filter').'" /></p>'. |
---|
271 | form::hidden(array('p'),'myGmaps'). |
---|
272 | '</div>'. |
---|
273 | '</div>'. |
---|
274 | '<br class="clear" />'. //Opera sucks |
---|
275 | '</fieldset>'. |
---|
276 | '</form>'; |
---|
277 | |
---|
278 | # Show posts |
---|
279 | $post_list->display($page,$nb_per_page,$p_url, |
---|
280 | '<form action="'.$p_url.'" method="post" id="form-entries">'. |
---|
281 | |
---|
282 | '%s'. |
---|
283 | |
---|
284 | '<div class="two-cols">'. |
---|
285 | '<p class="col checkboxes-helpers"></p>'. |
---|
286 | |
---|
287 | '<p class="col right">'.__('Selected map elements action:').' '. |
---|
288 | form::combo('action',$combo_action). |
---|
289 | '<input type="submit" value="'.__('ok').'" /></p>'. |
---|
290 | form::hidden(array('user_id'),$user_id). |
---|
291 | form::hidden(array('cat_id'),$cat_id). |
---|
292 | form::hidden(array('status'),$status). |
---|
293 | form::hidden(array('month'),$month). |
---|
294 | form::hidden(array('sortby'),$sortby). |
---|
295 | form::hidden(array('order'),$order). |
---|
296 | form::hidden(array('page'),$page). |
---|
297 | form::hidden(array('nb'),$nb_per_page). |
---|
298 | $core->formNonce(). |
---|
299 | '</div>'. |
---|
300 | '</form>' |
---|
301 | ); |
---|
302 | |
---|
303 | echo '</div>'; |
---|
304 | |
---|
305 | echo |
---|
306 | '<div class="multi-part" id="config" title="'.__('Configuration').'">'. |
---|
307 | '<form method="post" action="'.$p_url.'" id="settings-form">'. |
---|
308 | '<fieldset><legend>'.__('Default map options').'</legend>'. |
---|
309 | '<p class="field"><label>'.__('Use scrollwheel'). |
---|
310 | form::checkbox('scrollwheel',1,$core->blog->settings->myGmaps->scrollwheel). |
---|
311 | '</label></p>'. |
---|
312 | '<p>'.__('Choose map center, zoom level and map type.').'</p>'. |
---|
313 | '<div class="area" id="map_canvas"></div>'. |
---|
314 | '</fieldset>'. |
---|
315 | '<p class="area" id="map-details-area" >'. |
---|
316 | '<label class="infowindow" for="map-details">'.__('Map details:').'</label>'. |
---|
317 | '<div id="map-details"></div>'. |
---|
318 | '</p>'. |
---|
319 | '<p>'. |
---|
320 | form::hidden('center',$core->blog->settings->myGmaps->center). |
---|
321 | form::hidden('zoom',$core->blog->settings->myGmaps->zoom). |
---|
322 | form::hidden('map_type',$core->blog->settings->myGmaps->map_type). |
---|
323 | $core->formNonce(). |
---|
324 | '<input type="submit" name="save" value="'.__('Save configuration').'" />'. |
---|
325 | '</p>'. |
---|
326 | '</form>'. |
---|
327 | '</div>'; |
---|
328 | } |
---|
329 | |
---|
330 | dcPage::helpBlock('myGmaps'); |
---|
331 | |
---|
332 | echo |
---|
333 | '</body>'. |
---|
334 | '</html>'; |
---|
335 | |
---|
336 | ?> |
---|