1 | <?php |
---|
2 | /* |
---|
3 | * ----------------------------------------------------------------------------- |
---|
4 | * Plugin Name: GMaps |
---|
5 | * ----------------------------------------------------------------------------- |
---|
6 | * Author : Grum |
---|
7 | * email : grum@piwigo.org |
---|
8 | * website : http://photos.grum.fr |
---|
9 | * PWG user : http://forum.piwigo.org/profile.php?id=3706 |
---|
10 | * |
---|
11 | * << May the Little SpaceFrog be with you ! >> |
---|
12 | * |
---|
13 | * ----------------------------------------------------------------------------- |
---|
14 | * |
---|
15 | * See main.inc.php for release information |
---|
16 | * |
---|
17 | * manage all the ajax requests |
---|
18 | * ----------------------------------------------------------------------------- |
---|
19 | */ |
---|
20 | |
---|
21 | define('PHPWG_ROOT_PATH',dirname(dirname(dirname(__FILE__))).'/'); |
---|
22 | |
---|
23 | /* |
---|
24 | * set ajax module in admin mode if request is used for admin interface |
---|
25 | */ |
---|
26 | if(!isset($_REQUEST['ajaxfct'])) $_REQUEST['ajaxfct']=''; |
---|
27 | if(preg_match('/^admin\./i', $_REQUEST['ajaxfct'])) |
---|
28 | { |
---|
29 | define('IN_ADMIN', true); |
---|
30 | } |
---|
31 | |
---|
32 | // the common.inc.php file loads all the main.inc.php plugins files |
---|
33 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
34 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCAjax.class.inc.php'); |
---|
35 | include_once('gmaps_root.class.inc.php'); |
---|
36 | |
---|
37 | load_language('plugin.lang', GMAPS_PATH); |
---|
38 | |
---|
39 | |
---|
40 | class GMaps_Ajax extends GMaps_root |
---|
41 | { |
---|
42 | /** |
---|
43 | * constructor |
---|
44 | */ |
---|
45 | public function __construct($prefixeTable, $filelocation) |
---|
46 | { |
---|
47 | parent::__construct($prefixeTable, $filelocation); |
---|
48 | $this->loadConfig(); |
---|
49 | $this->checkRequest(); |
---|
50 | $this->returnAjaxContent(); |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | * check the $_REQUEST values and set default values |
---|
55 | * |
---|
56 | */ |
---|
57 | protected function checkRequest() |
---|
58 | { |
---|
59 | global $user; |
---|
60 | |
---|
61 | if(!isset($_REQUEST['ajaxfct'])) $_REQUEST['ajaxfct']=''; |
---|
62 | if(!isset($_REQUEST['errcode'])) $_REQUEST['errcode']=''; |
---|
63 | |
---|
64 | // check if asked function is valid |
---|
65 | if(!($_REQUEST['ajaxfct']=='admin.maps.getList' or |
---|
66 | $_REQUEST['ajaxfct']=='admin.maps.setMap' or |
---|
67 | $_REQUEST['ajaxfct']=='admin.maps.getMap' or |
---|
68 | $_REQUEST['ajaxfct']=='admin.maps.deleteMap' or |
---|
69 | $_REQUEST['ajaxfct']=='admin.assoc.getList' or |
---|
70 | $_REQUEST['ajaxfct']=='admin.assoc.setAssoc' or |
---|
71 | $_REQUEST['ajaxfct']=='admin.assoc.getAssoc' or |
---|
72 | $_REQUEST['ajaxfct']=='admin.assoc.deleteAssoc' or |
---|
73 | $_REQUEST['ajaxfct']=='admin.kmlFiles.getList' or |
---|
74 | $_REQUEST['ajaxfct']=='admin.kmlFiles.setFile' or |
---|
75 | $_REQUEST['ajaxfct']=='admin.kmlFiles.getFile' or |
---|
76 | $_REQUEST['ajaxfct']=='admin.kmlFiles.deleteFile' or |
---|
77 | |
---|
78 | $_REQUEST['ajaxfct']=='public.maps.init' or |
---|
79 | $_REQUEST['ajaxfct']=='public.maps.getMarkers' |
---|
80 | )) $_REQUEST['ajaxfct']=''; |
---|
81 | |
---|
82 | if(preg_match('/^admin\./i', $_REQUEST['ajaxfct']) and !is_admin()) $_REQUEST['ajaxfct']=''; |
---|
83 | |
---|
84 | |
---|
85 | if($_REQUEST['ajaxfct']!='') |
---|
86 | { |
---|
87 | /* |
---|
88 | * no check for admin.maps.getList & admin.assoc.getList requests |
---|
89 | */ |
---|
90 | |
---|
91 | |
---|
92 | /* |
---|
93 | * check values for |
---|
94 | * admin.maps.getMap |
---|
95 | * admin.assoc.getAssoc |
---|
96 | * admin.kmlFiles.getFile |
---|
97 | */ |
---|
98 | if($_REQUEST['ajaxfct']=="admin.maps.getMap" or |
---|
99 | $_REQUEST['ajaxfct']=="admin.assoc.getAssoc" or |
---|
100 | $_REQUEST['ajaxfct']=="admin.kmlFiles.getFile") |
---|
101 | { |
---|
102 | if(!isset($_REQUEST['id']) or |
---|
103 | !is_numeric($_REQUEST['id']) or |
---|
104 | $_REQUEST['id']=='') $_REQUEST['ajaxfct']=''; |
---|
105 | } |
---|
106 | |
---|
107 | /* |
---|
108 | * check values for |
---|
109 | * admin.maps.deleteMap |
---|
110 | * admin.assoc.deleteAssoc |
---|
111 | * admin.kmlFiles.deleteFile |
---|
112 | */ |
---|
113 | if($_REQUEST['ajaxfct']=="admin.maps.deleteMap" or |
---|
114 | $_REQUEST['ajaxfct']=="admin.assoc.deleteAssoc" or |
---|
115 | $_REQUEST['ajaxfct']=="admin.kmlFiles.deleteFile") |
---|
116 | { |
---|
117 | if(!isset($_REQUEST['id']) or |
---|
118 | !is_numeric($_REQUEST['id']) or |
---|
119 | $_REQUEST['id']=='') $_REQUEST['ajaxfct']=''; |
---|
120 | } |
---|
121 | |
---|
122 | /* |
---|
123 | * check admin.maps.setMap values |
---|
124 | */ |
---|
125 | if($_REQUEST['ajaxfct']=="admin.maps.setMap") |
---|
126 | { |
---|
127 | if(!isset($_REQUEST['id']) or |
---|
128 | !isset($_REQUEST['datas']) or !is_array($_REQUEST['datas'])) |
---|
129 | { |
---|
130 | $_REQUEST['ajaxfct']=''; |
---|
131 | } |
---|
132 | else |
---|
133 | { |
---|
134 | if(!(isset($_REQUEST['datas']['displayType']) and |
---|
135 | isset($_REQUEST['datas']['sizeMode']) and |
---|
136 | isset($_REQUEST['datas']['name']) and |
---|
137 | isset($_REQUEST['datas']['width']) and |
---|
138 | isset($_REQUEST['datas']['height']) and |
---|
139 | isset($_REQUEST['datas']['zoomLevel']) and |
---|
140 | isset($_REQUEST['datas']['mapType']) and |
---|
141 | isset($_REQUEST['datas']['mapTypeControl']) and |
---|
142 | isset($_REQUEST['datas']['navigationControl']) and |
---|
143 | isset($_REQUEST['datas']['scaleControl']) and |
---|
144 | isset($_REQUEST['datas']['streetViewControl']) and |
---|
145 | isset($_REQUEST['datas']['style']) and |
---|
146 | isset($_REQUEST['datas']['zoomLevelMaxActivated']) |
---|
147 | )) |
---|
148 | { |
---|
149 | $_REQUEST['ajaxfct']=''; |
---|
150 | } |
---|
151 | else |
---|
152 | { |
---|
153 | if(!($_REQUEST['datas']['displayType']=='IC' or |
---|
154 | $_REQUEST['datas']['displayType']=='IP' or |
---|
155 | $_REQUEST['datas']['displayType']=='MP')) $_REQUEST['ajaxfct']=''; |
---|
156 | |
---|
157 | if(!($_REQUEST['datas']['sizeMode']=='A' or |
---|
158 | $_REQUEST['datas']['sizeMode']=='F')) $_REQUEST['ajaxfct']=''; |
---|
159 | |
---|
160 | if(!is_numeric($_REQUEST['datas']['width']) or |
---|
161 | $_REQUEST['datas']['width']<100 or |
---|
162 | $_REQUEST['datas']['width']>1280) $_REQUEST['datas']['width']=470; |
---|
163 | |
---|
164 | if(!is_numeric($_REQUEST['datas']['height']) or |
---|
165 | $_REQUEST['datas']['height']<100 or |
---|
166 | $_REQUEST['datas']['height']>1280) $_REQUEST['datas']['height']=210; |
---|
167 | |
---|
168 | if(!is_numeric($_REQUEST['datas']['zoomLevel']) or |
---|
169 | $_REQUEST['datas']['zoomLevel']<1 or |
---|
170 | $_REQUEST['datas']['zoomLevel']>20) $_REQUEST['datas']['zoomLevel']=4; |
---|
171 | |
---|
172 | if(!($_REQUEST['datas']['mapType']=='hybrid' or |
---|
173 | $_REQUEST['datas']['mapType']=='terrain' or |
---|
174 | $_REQUEST['datas']['mapType']=='roadmap' or |
---|
175 | $_REQUEST['datas']['mapType']=='satellite')) $_REQUEST['datas']['mapType']='hybrid'; |
---|
176 | |
---|
177 | if(!is_numeric($_REQUEST['datas']['mapTypeControl']) or |
---|
178 | $_REQUEST['datas']['mapTypeControl']<-1 or |
---|
179 | $_REQUEST['datas']['mapTypeControl']>2) $_REQUEST['datas']['mapTypeControl']=0; |
---|
180 | |
---|
181 | if(!is_numeric($_REQUEST['datas']['navigationControl']) or |
---|
182 | $_REQUEST['datas']['navigationControl']<-1 or |
---|
183 | $_REQUEST['datas']['navigationControl']>3) $_REQUEST['datas']['navigationControl']=0; |
---|
184 | |
---|
185 | if(!($_REQUEST['datas']['scaleControl']=='y' or |
---|
186 | $_REQUEST['datas']['scaleControl']=='n')) $_REQUEST['datas']['scaleControl']='y'; |
---|
187 | |
---|
188 | if(!($_REQUEST['datas']['streetViewControl']=='y' or |
---|
189 | $_REQUEST['datas']['streetViewControl']=='n')) $_REQUEST['datas']['streetViewControl']='n'; |
---|
190 | |
---|
191 | if(!($_REQUEST['datas']['zoomLevelMaxActivated']=='y' or |
---|
192 | $_REQUEST['datas']['zoomLevelMaxActivated']=='n')) $_REQUEST['datas']['zoomLevelMaxActivated']='n'; |
---|
193 | } |
---|
194 | } |
---|
195 | } |
---|
196 | |
---|
197 | |
---|
198 | /* |
---|
199 | * check admin.maps.setAssoc values |
---|
200 | */ |
---|
201 | if($_REQUEST['ajaxfct']=="admin.assoc.setAssoc") |
---|
202 | { |
---|
203 | if(!isset($_REQUEST['id']) or |
---|
204 | !isset($_REQUEST['datas']) or !is_array($_REQUEST['datas'])) |
---|
205 | { |
---|
206 | $_REQUEST['ajaxfct']=''; |
---|
207 | } |
---|
208 | else |
---|
209 | { |
---|
210 | if(!(isset($_REQUEST['datas']['categoryId']) and |
---|
211 | isset($_REQUEST['datas']['mapId']) and |
---|
212 | isset($_REQUEST['datas']['applySubCat']) and |
---|
213 | isset($_REQUEST['datas']['kmlFileId']) and |
---|
214 | isset($_REQUEST['datas']['kmlFileUrl']) and |
---|
215 | isset($_REQUEST['datas']['icon']) and |
---|
216 | isset($_REQUEST['datas']['marker']) and |
---|
217 | isset($_REQUEST['datas']['title']) )) |
---|
218 | { |
---|
219 | $_REQUEST['ajaxfct']=''; |
---|
220 | } |
---|
221 | else |
---|
222 | { |
---|
223 | if($_REQUEST['datas']['categoryId']=='' or |
---|
224 | $_REQUEST['datas']['categoryId']<0) $_REQUEST['ajaxfct']=''; |
---|
225 | |
---|
226 | if($_REQUEST['datas']['mapId']=='') $_REQUEST['ajaxfct']=''; |
---|
227 | |
---|
228 | if(!($_REQUEST['datas']['applySubCat']=='y' or |
---|
229 | $_REQUEST['datas']['applySubCat']=='n')) $_REQUEST['datas']['applySubCat']='y'; |
---|
230 | |
---|
231 | if(!isset($_REQUEST['datas']['forceDisplay'])) $_REQUEST['datas']['forceDisplay']='n'; |
---|
232 | if(!($_REQUEST['datas']['forceDisplay']=='y' or |
---|
233 | $_REQUEST['datas']['forceDisplay']=='n')) $_REQUEST['datas']['forceDisplay']='n'; |
---|
234 | } |
---|
235 | } |
---|
236 | } |
---|
237 | |
---|
238 | |
---|
239 | /* |
---|
240 | * check admin.kmlFiles.setFile values |
---|
241 | */ |
---|
242 | if($_REQUEST['ajaxfct']=="admin.kmlFiles.setFile") |
---|
243 | { |
---|
244 | if(!isset($_REQUEST['id']) ) |
---|
245 | { |
---|
246 | $_REQUEST['ajaxfct']=''; |
---|
247 | } |
---|
248 | else |
---|
249 | { |
---|
250 | if($_REQUEST['id']=='') |
---|
251 | { |
---|
252 | if(!(isset($_FILES['file']['name']) and |
---|
253 | isset($_FILES['file']['tmp_name']))) $_REQUEST['ajaxfct']=''; |
---|
254 | } |
---|
255 | } |
---|
256 | } |
---|
257 | |
---|
258 | |
---|
259 | |
---|
260 | /* |
---|
261 | * check public.maps.getMarkers values |
---|
262 | */ |
---|
263 | if($_REQUEST['ajaxfct']=="public.maps.getMarkers") |
---|
264 | { |
---|
265 | if(!isset($_REQUEST['datas']) or |
---|
266 | !is_array($_REQUEST['datas'])) |
---|
267 | { |
---|
268 | $_REQUEST['ajaxfct']=''; |
---|
269 | } |
---|
270 | else |
---|
271 | { |
---|
272 | if(!(isset($_REQUEST['datas']['requestId']) and |
---|
273 | isset($_REQUEST['datas']['callId']) and |
---|
274 | isset($_REQUEST['datas']['bounds']) and |
---|
275 | isset($_REQUEST['datas']['width']) and |
---|
276 | isset($_REQUEST['datas']['height']) and |
---|
277 | isset($_REQUEST['datas']['distanceTreshold']) and |
---|
278 | isset($_REQUEST['datas']['bounds']['north']) and |
---|
279 | isset($_REQUEST['datas']['bounds']['south']) and |
---|
280 | isset($_REQUEST['datas']['bounds']['east']) and |
---|
281 | isset($_REQUEST['datas']['bounds']['west']) )) |
---|
282 | { |
---|
283 | $_REQUEST['ajaxfct']=''; |
---|
284 | } |
---|
285 | if(!isset($_REQUEST['datas']['loadIndex'])) $_REQUEST['datas']['loadIndex']=''; |
---|
286 | } |
---|
287 | } |
---|
288 | |
---|
289 | /* |
---|
290 | * check public.maps.getMarkerInfos values |
---|
291 | */ |
---|
292 | if($_REQUEST['ajaxfct']=="public.maps.init") |
---|
293 | { |
---|
294 | if(!isset($_REQUEST['category'])) $_REQUEST['ajaxfct']=''; |
---|
295 | if(!isset($_REQUEST['mapId'])) $_REQUEST['mapId']=null; |
---|
296 | } |
---|
297 | } |
---|
298 | } //checkRequest |
---|
299 | |
---|
300 | |
---|
301 | /** |
---|
302 | * return ajax content |
---|
303 | */ |
---|
304 | protected function returnAjaxContent() |
---|
305 | { |
---|
306 | $result="<p class='errors'>An error has occured</p>"; |
---|
307 | switch($_REQUEST['ajaxfct']) |
---|
308 | { |
---|
309 | case 'admin.maps.getList': |
---|
310 | $result=$this->ajax_gmaps_admin_mapsGetList(); |
---|
311 | break; |
---|
312 | case 'admin.maps.getMap': |
---|
313 | $result=$this->ajax_gmaps_admin_mapsGetMap($_REQUEST['id']); |
---|
314 | break; |
---|
315 | case 'admin.maps.setMap': |
---|
316 | $result=$this->ajax_gmaps_admin_mapsSetMap($_REQUEST['id'], $_REQUEST['datas']); |
---|
317 | break; |
---|
318 | case 'admin.maps.deleteMap': |
---|
319 | $result=$this->ajax_gmaps_admin_mapsDeleteMap($_REQUEST['id']); |
---|
320 | break; |
---|
321 | case 'admin.assoc.getList': |
---|
322 | $result=$this->ajax_gmaps_admin_assocGetList(); |
---|
323 | break; |
---|
324 | case 'admin.assoc.getAssoc': |
---|
325 | $result=$this->ajax_gmaps_admin_assocGetAssoc($_REQUEST['id']); |
---|
326 | break; |
---|
327 | case 'admin.assoc.setAssoc': |
---|
328 | $result=$this->ajax_gmaps_admin_assocSetAssoc($_REQUEST['id'], $_REQUEST['datas']); |
---|
329 | break; |
---|
330 | case 'admin.assoc.deleteAssoc': |
---|
331 | $result=$this->ajax_gmaps_admin_assocDeleteAssoc($_REQUEST['id']); |
---|
332 | break; |
---|
333 | case 'admin.kmlFiles.getList': |
---|
334 | $result=$this->ajax_gmaps_admin_kmlFilesGetList(); |
---|
335 | break; |
---|
336 | case 'admin.kmlFiles.getFile': |
---|
337 | $result=$this->ajax_gmaps_admin_kmlFilesGetFile($_REQUEST['id']); |
---|
338 | break; |
---|
339 | case 'admin.kmlFiles.setFile': |
---|
340 | $result=$this->ajax_gmaps_admin_kmlFilesSetFile($_REQUEST['id'], $_REQUEST['name']); |
---|
341 | break; |
---|
342 | case 'admin.kmlFiles.deleteFile': |
---|
343 | $result=$this->ajax_gmaps_admin_kmlFilesDeleteFile($_REQUEST['id']); |
---|
344 | break; |
---|
345 | |
---|
346 | |
---|
347 | case 'public.maps.init': |
---|
348 | $result=$this->ajax_gmaps_public_mapsInit($_REQUEST['category'], $_REQUEST['mapId']); |
---|
349 | break; |
---|
350 | case 'public.maps.getMarkers': |
---|
351 | $result=$this->ajax_gmaps_public_mapsGetMarkers($_REQUEST['datas']); |
---|
352 | break; |
---|
353 | case 'public.maps.getMarkersInfos': |
---|
354 | $result=$this->ajax_gmaps_public_mapsGetMarkersInfos($_REQUEST['datas']); |
---|
355 | break; |
---|
356 | } |
---|
357 | GPCAjax::returnResult($result); |
---|
358 | } |
---|
359 | |
---|
360 | |
---|
361 | /*------------------------------------------------------------------------* |
---|
362 | * |
---|
363 | * ADMIN FUNCTIONS |
---|
364 | * |
---|
365 | *----------------------------------------------------------------------- */ |
---|
366 | |
---|
367 | /** |
---|
368 | * return a HTML list of defined maps |
---|
369 | * |
---|
370 | * @return String |
---|
371 | */ |
---|
372 | private function ajax_gmaps_admin_mapsGetList() |
---|
373 | { |
---|
374 | global $template; |
---|
375 | |
---|
376 | $template->set_filename('list_page', |
---|
377 | dirname($this->getFileLocation()).'/admin/gmaps_maps_iListMaps.tpl'); |
---|
378 | |
---|
379 | $datas=Array(); |
---|
380 | |
---|
381 | $sql="SELECT id, name, displayType, sizeMode, width, height, zoomLevel, |
---|
382 | mapType, mapTypeControl, navigationControl, scaleControl, |
---|
383 | streetViewControl, zoomLevelMaxActivated |
---|
384 | FROM ".$this->tables['maps']." |
---|
385 | ORDER BY displayType ASC, name ASC"; |
---|
386 | $result=pwg_query($sql); |
---|
387 | if($result) |
---|
388 | { |
---|
389 | while($row=pwg_db_fetch_assoc($result)) |
---|
390 | { |
---|
391 | if($row['displayType']=='IC') |
---|
392 | { |
---|
393 | $row['zoomLevel']=l10n('gmaps_auto'); |
---|
394 | } |
---|
395 | |
---|
396 | $row['displayType']=l10n('gmaps_displayTypeShort'.$row['displayType']); |
---|
397 | |
---|
398 | if($row['sizeMode']=='A') |
---|
399 | { |
---|
400 | $row['dimensions']=l10n('gmaps_auto'); |
---|
401 | } |
---|
402 | else |
---|
403 | { |
---|
404 | $row['dimensions']=$row['width'].'x'.$row['height']; |
---|
405 | } |
---|
406 | |
---|
407 | $row['mapType']=l10n('gmaps_googleMapType_'.$row['mapType']); |
---|
408 | $row['mapTypeControl']=l10n('gmaps_googleMapTypeControl_'.$row['mapTypeControl']); |
---|
409 | $row['navigationControl']=l10n('gmaps_googleMapNavigationControl_'.$row['navigationControl']); |
---|
410 | $row['scaleControl']=($row['scaleControl']=='y')?l10n('gmaps_display_visible'):l10n('gmaps_display_hidden'); |
---|
411 | $row['streetViewControl']=($row['streetViewControl']=='y')?l10n('gmaps_display_visible'):l10n('gmaps_display_hidden'); |
---|
412 | $datas[]=$row; |
---|
413 | } |
---|
414 | } |
---|
415 | |
---|
416 | $template->assign('datas', $datas); |
---|
417 | return($template->parse('list_page', true)); |
---|
418 | } //ajax_gmaps_admin_mapsGetList |
---|
419 | |
---|
420 | |
---|
421 | /** |
---|
422 | * set properties for a given map id ; if no map id is given, create a new |
---|
423 | * map |
---|
424 | * |
---|
425 | * @param String id : the map Id |
---|
426 | * @param Array datas : properties of the map (assuming array index were |
---|
427 | * checked by the checkRequest function) |
---|
428 | * @return String : the num id, or an error message |
---|
429 | */ |
---|
430 | private function ajax_gmaps_admin_mapsSetMap($id, $properties) |
---|
431 | { |
---|
432 | global $template; |
---|
433 | |
---|
434 | if($id=='') |
---|
435 | { |
---|
436 | $sql="INSERT INTO ".$this->tables['maps']." |
---|
437 | VALUES ('', '".mysql_escape_string($properties['name'])."', '". |
---|
438 | $properties['displayType']."', '". |
---|
439 | $properties['sizeMode']."', '". |
---|
440 | $properties['width']."', '". |
---|
441 | $properties['height']."', '". |
---|
442 | $properties['zoomLevel']."', '". |
---|
443 | $properties['mapType']."', '". |
---|
444 | $properties['mapTypeControl']."', '". |
---|
445 | $properties['navigationControl']."', '". |
---|
446 | $properties['scaleControl']."', '". |
---|
447 | $properties['streetViewControl']."', '". |
---|
448 | mysql_escape_string($properties['style'])."', '". |
---|
449 | $properties['zoomLevelMaxActivated']."');"; |
---|
450 | $result=pwg_query($sql); |
---|
451 | $id=pwg_db_insert_id(); |
---|
452 | } |
---|
453 | else |
---|
454 | { |
---|
455 | $sql="UPDATE ".$this->tables['maps']." |
---|
456 | SET name='".mysql_escape_string($properties['name'])."', displayType='". |
---|
457 | $properties['displayType']."', sizeMode='". |
---|
458 | $properties['sizeMode']."', width='". |
---|
459 | $properties['width']."', height='". |
---|
460 | $properties['height']."', zoomLevel='". |
---|
461 | $properties['zoomLevel']."', mapType='". |
---|
462 | $properties['mapType']."', mapTypeControl='". |
---|
463 | $properties['mapTypeControl']."', navigationControl='". |
---|
464 | $properties['navigationControl']."', scaleControl='". |
---|
465 | $properties['scaleControl']."', streetViewControl='". |
---|
466 | $properties['streetViewControl']."', style='". |
---|
467 | mysql_escape_string($properties['style'])."', zoomLevelMaxActivated='". |
---|
468 | $properties['zoomLevelMaxActivated']."' |
---|
469 | WHERE id='$id';"; |
---|
470 | $result=pwg_query($sql); |
---|
471 | } |
---|
472 | |
---|
473 | return($id); |
---|
474 | } //ajax_gmaps_admin_mapsSetMap |
---|
475 | |
---|
476 | |
---|
477 | /** |
---|
478 | * get properties for a given map id |
---|
479 | * |
---|
480 | * @param String id : the map Id |
---|
481 | * @return String : data formatted in a JSON string |
---|
482 | */ |
---|
483 | private function ajax_gmaps_admin_mapsGetMap($id) |
---|
484 | { |
---|
485 | $returned=array( |
---|
486 | 'id' => '', |
---|
487 | 'name' => '', |
---|
488 | 'displayType' => '', |
---|
489 | 'sizeMode' => '', |
---|
490 | 'width' => 470, |
---|
491 | 'height' => 210, |
---|
492 | 'zoomLevel' => 4, |
---|
493 | 'mapType' => 'hybrid', |
---|
494 | 'mapTypeControl' => 0, |
---|
495 | 'navigationControl' => 0, |
---|
496 | 'scaleControl' => 'y', |
---|
497 | 'streetViewControl' => 'n', |
---|
498 | 'zoomLevelMaxActivated' => 'n', |
---|
499 | 'associations' => 0, |
---|
500 | ); |
---|
501 | |
---|
502 | $sql="SELECT pgmm.id, pgmm.displayType, pgmm.sizeMode, pgmm.name, |
---|
503 | pgmm.width, pgmm.height, pgmm.zoomLevel, pgmm.mapType, |
---|
504 | pgmm.mapTypeControl, pgmm.navigationControl, |
---|
505 | pgmm.scaleControl, pgmm.streetViewControl, |
---|
506 | pgmm.zoomLevelMaxActivated, |
---|
507 | COUNT(pgcm.id) AS nbAssoc |
---|
508 | FROM ".$this->tables['maps']." pgmm |
---|
509 | LEFT JOIN ".$this->tables['category_maps']." pgcm |
---|
510 | ON pgcm.mapId=pgmm.id |
---|
511 | WHERE pgmm.id='$id' |
---|
512 | GROUP BY pgmm.id;"; |
---|
513 | $result=pwg_query($sql); |
---|
514 | if($result) |
---|
515 | { |
---|
516 | while($row=pwg_db_fetch_assoc($result)) |
---|
517 | { |
---|
518 | $returned=$row; |
---|
519 | } |
---|
520 | } |
---|
521 | |
---|
522 | return(json_encode($returned)); |
---|
523 | } //ajax_gmaps_admin_mapsGetMap |
---|
524 | |
---|
525 | |
---|
526 | |
---|
527 | /** |
---|
528 | * delete a map |
---|
529 | * |
---|
530 | * @param String id : if of the map to delete |
---|
531 | * @return String : ok or ko |
---|
532 | */ |
---|
533 | private function ajax_gmaps_admin_mapsDeleteMap($id) |
---|
534 | { |
---|
535 | $sql="DELETE FROM ".$this->tables['maps']." |
---|
536 | WHERE id='$id';"; |
---|
537 | $result=pwg_query($sql); |
---|
538 | if($result) |
---|
539 | { |
---|
540 | $sql="DELETE FROM ".$this->tables['category_maps']." |
---|
541 | WHERE map_id='$id';"; |
---|
542 | $result=pwg_query($sql); |
---|
543 | if($result) return('ok'); |
---|
544 | } |
---|
545 | |
---|
546 | return('ko!unknown error'); |
---|
547 | } //ajax_gmaps_admin_mapsDeleteMap |
---|
548 | |
---|
549 | |
---|
550 | |
---|
551 | |
---|
552 | |
---|
553 | /** |
---|
554 | * return a HTML list of defined associations |
---|
555 | * |
---|
556 | * @return String |
---|
557 | */ |
---|
558 | private function ajax_gmaps_admin_assocGetList() |
---|
559 | { |
---|
560 | global $template; |
---|
561 | |
---|
562 | $template->set_filename('list_page', |
---|
563 | dirname($this->getFileLocation()).'/admin/gmaps_category_maps_iListMaps.tpl'); |
---|
564 | |
---|
565 | $datas=Array(); |
---|
566 | |
---|
567 | $sql="SELECT pgcm.id, pgcm.categoryId, pct.name AS catName, |
---|
568 | pgmm.name AS mapName, pgmm.displayType, |
---|
569 | pgcm.kmlFileId, pgcm.kmlFileUrl, pgcm.imgSort, pgcm.applySubCat, pgcm.icon, |
---|
570 | pgcm.title, pgkf.name AS kmlName, pgcm.forceDisplay |
---|
571 | FROM ((".$this->tables['category_maps']." pgcm |
---|
572 | LEFT JOIN ".CATEGORIES_TABLE." pct ON pct.id=pgcm.categoryId) |
---|
573 | LEFT JOIN ".$this->tables['maps']." pgmm ON pgcm.mapId = pgmm.id) |
---|
574 | LEFT JOIN ".$this->tables['kmlfiles']." pgkf ON pgkf.id = pgcm.kmlFileId |
---|
575 | ORDER BY pct.name, pgmm.displayType, pgcm.imgSort"; |
---|
576 | $result=pwg_query($sql); |
---|
577 | if($result) |
---|
578 | { |
---|
579 | $keys=array( |
---|
580 | 'prev' => '', |
---|
581 | 'curr' => '' |
---|
582 | ); |
---|
583 | while($row=pwg_db_fetch_assoc($result)) |
---|
584 | { |
---|
585 | $keys['prev']=$keys['curr']; |
---|
586 | |
---|
587 | if($row['kmlFileId']>0) |
---|
588 | { |
---|
589 | $mapKmlFile=$row['kmlName']; |
---|
590 | } |
---|
591 | elseif($row['kmlFileUrl']!='') |
---|
592 | { |
---|
593 | $mapKmlFile='URL'; |
---|
594 | } |
---|
595 | else |
---|
596 | { |
---|
597 | $mapKmlFile=''; |
---|
598 | } |
---|
599 | |
---|
600 | |
---|
601 | $tmp=array( |
---|
602 | 'id' => $row['id'], |
---|
603 | 'catName' => ($row['categoryId']==0)?l10n('gmaps_applyForAllTheGallery'):$row['catName'], |
---|
604 | 'applySubCat' => l10n('gmaps_'.$row['applySubCat']), |
---|
605 | 'mapName' => $row['mapName'], |
---|
606 | 'mapKmlFile' => $mapKmlFile, |
---|
607 | 'icon' => $row['icon'], |
---|
608 | 'displayType' => l10n('gmaps_displayTypeShort'.$row['displayType']), |
---|
609 | 'title' => $row['title'], |
---|
610 | 'forceDisplay' => l10n('gmaps_'.$row['forceDisplay']), |
---|
611 | ); |
---|
612 | |
---|
613 | $keys['curr']=$row['categoryId'].$row['displayType']; |
---|
614 | |
---|
615 | if($keys['curr']==$keys['prev']) |
---|
616 | { |
---|
617 | $tmp['catName']=''; |
---|
618 | $tmp['displayType']=''; |
---|
619 | $tmp['applySubCat']=''; |
---|
620 | } |
---|
621 | |
---|
622 | $datas[]=$tmp; |
---|
623 | } |
---|
624 | } |
---|
625 | |
---|
626 | $template->assign('datas', $datas); |
---|
627 | return($template->parse('list_page', true)); |
---|
628 | } //ajax_gmaps_admin_assocGetList |
---|
629 | |
---|
630 | |
---|
631 | |
---|
632 | |
---|
633 | /** |
---|
634 | * set properties for a given association id ; if no association id is given |
---|
635 | * create a new association |
---|
636 | * |
---|
637 | * @param String id : the association Id |
---|
638 | * @param Array datas : properties of the association (assuming array index |
---|
639 | * were checked by the checkRequest function) |
---|
640 | * @return String : the num id, or an error message |
---|
641 | */ |
---|
642 | private function ajax_gmaps_admin_assocSetAssoc($id, $properties) |
---|
643 | { |
---|
644 | global $template; |
---|
645 | |
---|
646 | // if create a new assoc, get the last imgSort |
---|
647 | $db=array( |
---|
648 | 'nbId' => 0, |
---|
649 | 'displayType' => '', |
---|
650 | 'maxImgSort' => 0 |
---|
651 | ); |
---|
652 | |
---|
653 | $sql="SELECT MAX(imgSort) AS maxImgSort, pgmm.displayType, COUNT(pgcm.id) AS nbId |
---|
654 | FROM (".$this->tables['category_maps']." pgcm |
---|
655 | LEFT JOIN ".$this->tables['maps']." pgmm ON pgmm.id = pgcm.mapId) |
---|
656 | LEFT JOIN ".$this->tables['maps']." pgmm2 ON pgmm2.displayType=pgmm.displayType |
---|
657 | |
---|
658 | WHERE categoryId='".$properties['categoryId']."' |
---|
659 | AND pgmm2.id='".$properties['mapId']."' |
---|
660 | GROUP BY pgmm.displayType;"; |
---|
661 | $result=pwg_query($sql); |
---|
662 | if($result) |
---|
663 | { |
---|
664 | while($row=pwg_db_fetch_assoc($result)) |
---|
665 | { |
---|
666 | $db=$row; |
---|
667 | } |
---|
668 | } |
---|
669 | |
---|
670 | if($id=='' and |
---|
671 | ($db['displayType']=='IC' or $db['displayType']=='IP') and |
---|
672 | $db['nbId']>0 |
---|
673 | ) |
---|
674 | { |
---|
675 | return('!'.l10n('gmaps_only_one_map_is_allowed_for_this_mode')); |
---|
676 | } |
---|
677 | |
---|
678 | |
---|
679 | if($id=='') |
---|
680 | { |
---|
681 | $sql="INSERT INTO ".$this->tables['category_maps']." |
---|
682 | VALUES ('', '". |
---|
683 | $properties['categoryId']."', '". |
---|
684 | $properties['mapId']."', '". |
---|
685 | ($db['maxImgSort']+1)."', '". |
---|
686 | $properties['applySubCat']."', '". |
---|
687 | $properties['kmlFileId']."', '". |
---|
688 | $properties['kmlFileUrl']."', '". |
---|
689 | basename($properties['icon'])."', '". |
---|
690 | basename($properties['marker'])."', '". |
---|
691 | mysql_escape_string($properties['title'])."', '". |
---|
692 | $properties['forceDisplay']."');"; |
---|
693 | $result=pwg_query($sql); |
---|
694 | $id=pwg_db_insert_id(); |
---|
695 | } |
---|
696 | else |
---|
697 | { |
---|
698 | $sql="UPDATE ".$this->tables['category_maps']." |
---|
699 | SET categoryId='". |
---|
700 | $properties['categoryId']."', mapId='". |
---|
701 | $properties['mapId']."', applySubCat='". |
---|
702 | $properties['applySubCat']."', kmlFileUrl='". |
---|
703 | $properties['kmlFileUrl']."', kmlFileId='". |
---|
704 | $properties['kmlFileId']."', icon='". |
---|
705 | basename($properties['icon'])."', marker='". |
---|
706 | basename($properties['marker'])."', title='". |
---|
707 | mysql_escape_string($properties['title'])."', forceDisplay='". |
---|
708 | $properties['forceDisplay']."' |
---|
709 | WHERE id='$id';"; |
---|
710 | $result=pwg_query($sql); |
---|
711 | } |
---|
712 | |
---|
713 | return($id); |
---|
714 | } //ajax_gmaps_admin_assocSetAssoc |
---|
715 | |
---|
716 | |
---|
717 | |
---|
718 | |
---|
719 | /** |
---|
720 | * get properties for a given association id |
---|
721 | * |
---|
722 | * @param String id : the association Id |
---|
723 | * @return String : data formatted in a JSON string |
---|
724 | */ |
---|
725 | private function ajax_gmaps_admin_assocGetAssoc($id) |
---|
726 | { |
---|
727 | $returned=array( |
---|
728 | 'id' => '', |
---|
729 | 'categoryId' => 0, |
---|
730 | 'mapId' => '', |
---|
731 | 'applySubCat'=> 'y', |
---|
732 | 'kmlFileId' => 0, |
---|
733 | 'kmlFileUrl' => '', |
---|
734 | 'icon' => '', |
---|
735 | 'marker' => '', |
---|
736 | 'title' => '', |
---|
737 | 'forceDisplay' => 'n' |
---|
738 | ); |
---|
739 | |
---|
740 | $sql="SELECT id, categoryId, mapId, applySubCat, kmlFileId, kmlFileUrl, |
---|
741 | icon, marker, title, forceDisplay |
---|
742 | FROM ".$this->tables['category_maps']." |
---|
743 | WHERE id='$id';"; |
---|
744 | $result=pwg_query($sql); |
---|
745 | if($result) |
---|
746 | { |
---|
747 | while($row=pwg_db_fetch_assoc($result)) |
---|
748 | { |
---|
749 | $returned=$row; |
---|
750 | } |
---|
751 | } |
---|
752 | |
---|
753 | return(json_encode($returned)); |
---|
754 | } //ajax_gmaps_admin_assocGetAssoc |
---|
755 | |
---|
756 | |
---|
757 | |
---|
758 | |
---|
759 | /** |
---|
760 | * delete an association |
---|
761 | * |
---|
762 | * @param String id : if of the association to delete |
---|
763 | * @return String : ok or ko |
---|
764 | */ |
---|
765 | private function ajax_gmaps_admin_assocDeleteAssoc($id) |
---|
766 | { |
---|
767 | $sql="DELETE FROM ".$this->tables['category_maps']." |
---|
768 | WHERE id='$id';"; |
---|
769 | $result=pwg_query($sql); |
---|
770 | if($result) return('ok'); |
---|
771 | |
---|
772 | return('ko!unknown error'); |
---|
773 | } //ajax_gmaps_admin_assocDeleteAssoc |
---|
774 | |
---|
775 | |
---|
776 | |
---|
777 | /** |
---|
778 | * return a HTML list of referenced kml files |
---|
779 | * |
---|
780 | * @return String |
---|
781 | */ |
---|
782 | private function ajax_gmaps_admin_kmlFilesGetList() |
---|
783 | { |
---|
784 | global $template; |
---|
785 | |
---|
786 | $template->set_filename('list_page', |
---|
787 | dirname($this->getFileLocation()).'/admin/gmaps_kmlfiles_iListFiles.tpl'); |
---|
788 | |
---|
789 | $datas=Array(); |
---|
790 | |
---|
791 | $sql="SELECT pgkf.id, pgkf.file, pgkf.name, pgkf.fileDate, pgkf.fileSize, COUNT(pgcm.id) AS nbAssoc |
---|
792 | FROM ".$this->tables['kmlfiles']." pgkf |
---|
793 | LEFT JOIN ".$this->tables['category_maps']." pgcm ON pgcm.kmlFileId = pgkf.id |
---|
794 | GROUP BY pgkf.id |
---|
795 | ORDER BY pgkf.name"; |
---|
796 | |
---|
797 | $result=pwg_query($sql); |
---|
798 | if($result) |
---|
799 | { |
---|
800 | while($row=pwg_db_fetch_assoc($result)) |
---|
801 | { |
---|
802 | $row['fileSize']=GPCCore::formatOctet($row['fileSize']); |
---|
803 | $datas[]=$row; |
---|
804 | } |
---|
805 | } |
---|
806 | |
---|
807 | $template->assign('datas', $datas); |
---|
808 | return($template->parse('list_page', true)); |
---|
809 | } //ajax_gmaps_admin_kmlFilesGetList |
---|
810 | |
---|
811 | |
---|
812 | |
---|
813 | |
---|
814 | /** |
---|
815 | * set properties for a given file id ; if no file id is given create a new |
---|
816 | * file |
---|
817 | * |
---|
818 | * @param String $id : the file Id |
---|
819 | * @param String $name : the name |
---|
820 | * @param String $file : the file name |
---|
821 | * @return String : the num id, or an error message |
---|
822 | */ |
---|
823 | private function ajax_gmaps_admin_kmlFilesSetFile($id, $name) |
---|
824 | { |
---|
825 | global $template; |
---|
826 | |
---|
827 | if(isset($_FILES['file']['name'])) |
---|
828 | { |
---|
829 | $file=$_FILES['file']['name']; |
---|
830 | } |
---|
831 | else |
---|
832 | { |
---|
833 | $file=''; |
---|
834 | } |
---|
835 | |
---|
836 | if($file=='' and $id!='') |
---|
837 | { |
---|
838 | // update name for an existing file |
---|
839 | $sql="UPDATE ".$this->tables['kmlfiles']." |
---|
840 | SET name='".mysql_escape_string($name)."' |
---|
841 | WHERE id='$id';"; |
---|
842 | $result=pwg_query($sql); |
---|
843 | } |
---|
844 | elseif($file!='') |
---|
845 | { |
---|
846 | // check if this file is not already used by an another file id |
---|
847 | $sql="SELECT file |
---|
848 | FROM ".$this->tables['kmlfiles']." |
---|
849 | WHERE file='".mysql_escape_string($_FILES['file']['name'])."'"; |
---|
850 | if($id!='') $sql.=" AND id!='$id'"; |
---|
851 | $result=pwg_query($sql); |
---|
852 | if($result) |
---|
853 | { |
---|
854 | $ok=''; |
---|
855 | while($row=pwg_db_fetch_assoc($result)) |
---|
856 | { |
---|
857 | $ok=$row['file']; |
---|
858 | } |
---|
859 | if($ok!='') |
---|
860 | { |
---|
861 | //file already used by another file id |
---|
862 | header("Location: ".$_SERVER['HTTP_REFERER']."&errcode=aksf10"); |
---|
863 | exit(); |
---|
864 | } |
---|
865 | } |
---|
866 | else |
---|
867 | { |
---|
868 | //unknown error |
---|
869 | header("Location: ".$_SERVER['HTTP_REFERER']."&errcode=aksf01"); |
---|
870 | exit(); |
---|
871 | } |
---|
872 | |
---|
873 | $file=GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY.$file; |
---|
874 | |
---|
875 | if(file_exists($file)) unlink($file); |
---|
876 | if($id!='') |
---|
877 | { |
---|
878 | $currentInfo=$this->ajax_gmaps_admin_kmlFilesGetFile($id, false); |
---|
879 | if(file_exists(self::KML_DIRECTORY.$currentInfo['file'])) unlink(GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY.$currentInfo['file']); |
---|
880 | } |
---|
881 | |
---|
882 | |
---|
883 | if(!move_uploaded_file($_FILES['file']['tmp_name'], $file)) |
---|
884 | { |
---|
885 | /* |
---|
886 | * something was wrong, previous file was deleted, so delete the file |
---|
887 | * from the database |
---|
888 | */ |
---|
889 | if($id!='') $this->ajax_gmaps_admin_kmlFilesDeleteFile($id); |
---|
890 | // error when trying to copy the uploaded file |
---|
891 | header("Location: ".$_SERVER['HTTP_REFERER']."&errcode=aksf02"); |
---|
892 | exit(); |
---|
893 | } |
---|
894 | |
---|
895 | if($id!='') |
---|
896 | { |
---|
897 | // update file & name for an existing file |
---|
898 | $sql="UPDATE ".$this->tables['kmlfiles']." |
---|
899 | SET name='".mysql_escape_string($name)."', |
---|
900 | file='".mysql_escape_string($_FILES['file']['name'])."', |
---|
901 | fileSize=".filesize($file).", |
---|
902 | fileDate='".date('Y-m-d H:i:s', filemtime($file))."' |
---|
903 | WHERE id='$id';"; |
---|
904 | $result=pwg_query($sql); |
---|
905 | } |
---|
906 | else |
---|
907 | { |
---|
908 | $sql="INSERT INTO ".$this->tables['kmlfiles']." |
---|
909 | VALUES ('', '".mysql_escape_string($_FILES['file']['name'])."', |
---|
910 | '".mysql_escape_string($name)."', |
---|
911 | '".date('Y-m-d H:i:s', filemtime($file))."', |
---|
912 | '".filesize($file)."')"; |
---|
913 | $result=pwg_query($sql); |
---|
914 | $id=pwg_db_insert_id(); |
---|
915 | } |
---|
916 | |
---|
917 | header("Location: ".$_SERVER['HTTP_REFERER']); |
---|
918 | exit(); |
---|
919 | } |
---|
920 | |
---|
921 | |
---|
922 | |
---|
923 | return($id); |
---|
924 | } //ajax_gmaps_admin_kmlFilesSetFile |
---|
925 | |
---|
926 | |
---|
927 | |
---|
928 | /** |
---|
929 | * get properties for a given file id |
---|
930 | * |
---|
931 | * @param String id : the file Id |
---|
932 | * @param Bool $json : if true, return a json string, otherwise an array |
---|
933 | * @return String : data formatted in a JSON string |
---|
934 | */ |
---|
935 | private function ajax_gmaps_admin_kmlFilesGetFile($id, $json=true) |
---|
936 | { |
---|
937 | $returned=array( |
---|
938 | 'id' => '', |
---|
939 | 'file' => '', |
---|
940 | 'name' => '', |
---|
941 | 'fileDate'=> '', |
---|
942 | 'fileSize' => 0, |
---|
943 | 'fileSizeUnits' => 0, |
---|
944 | ); |
---|
945 | |
---|
946 | $sql="SELECT id, file, name, fileDate, fileSize |
---|
947 | FROM ".$this->tables['kmlfiles']." |
---|
948 | WHERE id='$id';"; |
---|
949 | $result=pwg_query($sql); |
---|
950 | if($result) |
---|
951 | { |
---|
952 | while($row=pwg_db_fetch_assoc($result)) |
---|
953 | { |
---|
954 | $row['fileSizeUnits']=GPCCore::formatOctet($row['fileSize']); |
---|
955 | $returned=$row; |
---|
956 | } |
---|
957 | } |
---|
958 | |
---|
959 | if($json) |
---|
960 | { |
---|
961 | return(json_encode($returned)); |
---|
962 | } |
---|
963 | else |
---|
964 | { |
---|
965 | return($returned); |
---|
966 | } |
---|
967 | } //ajax_gmaps_admin_kmlFilesGetFile |
---|
968 | |
---|
969 | |
---|
970 | |
---|
971 | |
---|
972 | /** |
---|
973 | * delete a file |
---|
974 | * |
---|
975 | * @param String id : if of the file to delete |
---|
976 | * @return String : ok or ko |
---|
977 | */ |
---|
978 | private function ajax_gmaps_admin_kmlFilesDeleteFile($id) |
---|
979 | { |
---|
980 | $file=''; |
---|
981 | |
---|
982 | /* |
---|
983 | * before deleting record in the table, get the associated file name stored |
---|
984 | * on the server |
---|
985 | */ |
---|
986 | $sql="SELECT file |
---|
987 | FROM ".$this->tables['kmlfiles']." |
---|
988 | WHERE id='$id';"; |
---|
989 | $result=pwg_query($sql); |
---|
990 | if($result) |
---|
991 | { |
---|
992 | while($row=pwg_db_fetch_assoc($result)) |
---|
993 | { |
---|
994 | $file=$row['file']; |
---|
995 | } |
---|
996 | } |
---|
997 | |
---|
998 | // reset kmlFileId for assocation |
---|
999 | $sql="UPDATE ".$this->tables['category_maps']." |
---|
1000 | SET kmlFileId='0' |
---|
1001 | WHERE kmlFileId='$id'"; |
---|
1002 | pwg_query($sql); |
---|
1003 | |
---|
1004 | // delete the file |
---|
1005 | $sql="DELETE FROM ".$this->tables['kmlfiles']." |
---|
1006 | WHERE id='$id';"; |
---|
1007 | $result=pwg_query($sql); |
---|
1008 | if($result) |
---|
1009 | { |
---|
1010 | if($file!='' and file_exists(GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY.$file)) |
---|
1011 | { |
---|
1012 | unlink(GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY.$file); |
---|
1013 | } |
---|
1014 | return('ok'); |
---|
1015 | } |
---|
1016 | return('ko!unknown error'); |
---|
1017 | } //ajax_gmaps_admin_kmlFilesDeleteFile |
---|
1018 | |
---|
1019 | |
---|
1020 | |
---|
1021 | |
---|
1022 | /** |
---|
1023 | * prepare the cache for the user / category |
---|
1024 | * |
---|
1025 | * |
---|
1026 | * @param Integer $category : the category Id, 0 if want to init map for all |
---|
1027 | * the gallery |
---|
1028 | * @return String : the requestId |
---|
1029 | */ |
---|
1030 | private function ajax_gmaps_public_mapsInit($category, $mapId) |
---|
1031 | { |
---|
1032 | global $prefixeTable, $user; |
---|
1033 | |
---|
1034 | $requestId=''; |
---|
1035 | |
---|
1036 | if($mapId==null) |
---|
1037 | { |
---|
1038 | $this->buildMapList($category, 'C', self::ID_MODE_CATEGORY); |
---|
1039 | } |
---|
1040 | if($category>0) |
---|
1041 | { |
---|
1042 | $sqlCatRestrict="AND FIND_IN_SET($category, pct.uppercats)!=0"; |
---|
1043 | } |
---|
1044 | else |
---|
1045 | { |
---|
1046 | $sqlCatRestrict=""; |
---|
1047 | } |
---|
1048 | |
---|
1049 | if(count($this->maps)>0 or $mapId!=null) |
---|
1050 | { |
---|
1051 | $scripts=array(); |
---|
1052 | $bounds=array( |
---|
1053 | 'N' => -90, |
---|
1054 | 'S' => 90, |
---|
1055 | 'E' => -180, |
---|
1056 | 'W' => 180 |
---|
1057 | ); |
---|
1058 | |
---|
1059 | // there is some maps to display |
---|
1060 | $requestId=$this->getCacheRequestId(); |
---|
1061 | |
---|
1062 | $this->cleanCache(); |
---|
1063 | |
---|
1064 | // prepare the cache (same request in the 'GMaps_pip->displayCategoryPageMap' function) |
---|
1065 | $sql="SELECT DISTINCT pic.image_id, GROUP_CONCAT(DISTINCT pait.value ORDER BY pait.numID ASC SEPARATOR ';') AS coords |
---|
1066 | FROM (((".USER_CACHE_CATEGORIES_TABLE." pucc |
---|
1067 | LEFT JOIN ".CATEGORIES_TABLE." pct ON pucc.cat_id = pct.id) |
---|
1068 | LEFT JOIN ".IMAGE_CATEGORY_TABLE." pic ON pic.category_id = pucc.cat_id) |
---|
1069 | LEFT JOIN ".$prefixeTable."amd_images_tags pait ON pait.imageId = pic.image_id) |
---|
1070 | LEFT JOIN ".$prefixeTable."amd_used_tags paut ON pait.numId = paut.numId |
---|
1071 | WHERE pucc.user_id = '".$user['id']."' |
---|
1072 | AND (paut.tagId = 'magic.GPS.LatitudeNum' OR paut.tagId = 'magic.GPS.LongitudeNum') |
---|
1073 | AND pic.image_id IS NOT NULL |
---|
1074 | $sqlCatRestrict |
---|
1075 | GROUP BY pic.image_id"; |
---|
1076 | /* |
---|
1077 | * get_sql_condition_FandF( |
---|
1078 | array |
---|
1079 | ( |
---|
1080 | 'forbidden_categories' => 'pic.category_id', |
---|
1081 | 'visible_categories' => 'pic.category_id', |
---|
1082 | 'visible_images' => 'pic.image_id' |
---|
1083 | ), |
---|
1084 | 'AND' |
---|
1085 | ); |
---|
1086 | */ |
---|
1087 | |
---|
1088 | $result=pwg_query($sql); |
---|
1089 | if($result) |
---|
1090 | { |
---|
1091 | $massInsert=array(); |
---|
1092 | |
---|
1093 | while($row=pwg_db_fetch_assoc($result)) |
---|
1094 | { |
---|
1095 | $coords=explode(';', $row['coords']); |
---|
1096 | $this->updateBounds($bounds, array( |
---|
1097 | 'lat' => $coords[0], |
---|
1098 | 'lng' => $coords[1] |
---|
1099 | ) |
---|
1100 | ); |
---|
1101 | |
---|
1102 | $massInsert[]=array( |
---|
1103 | 'requestId' => $requestId, |
---|
1104 | 'imageId' => $row['image_id'], |
---|
1105 | 'latitude' => $coords[0], |
---|
1106 | 'longitude' => $coords[1] |
---|
1107 | ); |
---|
1108 | } |
---|
1109 | |
---|
1110 | mass_inserts($this->tables['cache'], array('requestId', 'imageId', 'latitude', 'longitude'), $massInsert); |
---|
1111 | |
---|
1112 | $returned=$requestId; |
---|
1113 | } |
---|
1114 | } |
---|
1115 | |
---|
1116 | return($requestId); |
---|
1117 | } |
---|
1118 | |
---|
1119 | |
---|
1120 | /** |
---|
1121 | * returns a list of markers |
---|
1122 | * |
---|
1123 | * |
---|
1124 | * @param Array $datas : 'requestId' id of the request |
---|
1125 | * 'bounds' (north, east, west, south) : only markers |
---|
1126 | * inside the given bounds are returned |
---|
1127 | * 'width' : width of maps in pixels |
---|
1128 | * 'height' : height of maps in pixels |
---|
1129 | * @return Array|String : a JSON string of an array of points (nbPictures, lat, lng) |
---|
1130 | */ |
---|
1131 | private function ajax_gmaps_public_mapsGetMarkers($datas) |
---|
1132 | { |
---|
1133 | global $user, $page, $conf; |
---|
1134 | |
---|
1135 | $returned=array( |
---|
1136 | 'loadIndex' => $datas['loadIndex'], |
---|
1137 | 'callId' => $datas['callId'], |
---|
1138 | 'markers' => array(), |
---|
1139 | 'datas' => array( |
---|
1140 | 'nbPhotos' => 0 |
---|
1141 | ) |
---|
1142 | ); |
---|
1143 | |
---|
1144 | $this->updateCacheRequestId($datas['requestId']); |
---|
1145 | $this->cleanCache(); |
---|
1146 | |
---|
1147 | /* |
---|
1148 | * the 'make_picture_url' function use the 'get_root_url' function which |
---|
1149 | * use the $page['root_path'] value |
---|
1150 | * |
---|
1151 | * here, this $page index doesn't exist, so we need to initialize it |
---|
1152 | */ |
---|
1153 | $page['root_path']=''; |
---|
1154 | |
---|
1155 | if($datas['bounds']['east']<$datas['bounds']['west']) |
---|
1156 | { |
---|
1157 | /* E = -xxx W = +xxx |
---|
1158 | * a(lng E:+x) |
---|
1159 | * b(lng W:-x) |
---|
1160 | * |
---|
1161 | * E +180/-180 W |
---|
1162 | * (+) (-) |
---|
1163 | * +-------------+---------+ |
---|
1164 | * | : | |
---|
1165 | * | : b | |
---|
1166 | * | a : | |
---|
1167 | * | : | |
---|
1168 | * +-------------+---------+ |
---|
1169 | * |
---|
1170 | */ |
---|
1171 | $lngClause=" |
---|
1172 | longitude <= ".$datas['bounds']['east']." |
---|
1173 | OR longitude >= ".$datas['bounds']['west']." "; |
---|
1174 | } |
---|
1175 | else |
---|
1176 | { |
---|
1177 | /* E = -xxx W = +xxx |
---|
1178 | * a(lng W:-x) |
---|
1179 | * b(lng E:+x) |
---|
1180 | * |
---|
1181 | * W 0 E |
---|
1182 | * (-) (+) |
---|
1183 | * +-------------+---------+ |
---|
1184 | * | : | |
---|
1185 | * | : b | |
---|
1186 | * | a : | |
---|
1187 | * | : | |
---|
1188 | * +-------------+---------+ |
---|
1189 | * |
---|
1190 | */ |
---|
1191 | $lngClause=" |
---|
1192 | longitude >= ".$datas['bounds']['west']." |
---|
1193 | AND longitude <= ".$datas['bounds']['east']." "; |
---|
1194 | } |
---|
1195 | |
---|
1196 | $sql="SELECT DISTINCT pgc.latitude, pgc.longitude, pgc.imageId, |
---|
1197 | GROUP_CONCAT(DISTINCT pic.category_id ORDER BY pic.category_id SEPARATOR ';') AS imageCatsId, |
---|
1198 | GROUP_CONCAT(DISTINCT pct.name ORDER BY pct.id SEPARATOR ';') AS imageCatsNames, |
---|
1199 | GROUP_CONCAT(DISTINCT IF(pct.permalink IS NULL, CONCAT('*', pct.id), pct.permalink) ORDER BY pct.id SEPARATOR ';') AS imageCatsPLink, |
---|
1200 | pit.name AS imageName, |
---|
1201 | pit.path, pit.tn_ext |
---|
1202 | FROM (((".$this->tables['cache']." pgc |
---|
1203 | LEFT JOIN ".IMAGE_CATEGORY_TABLE." pic ON pic.image_id = pgc.imageId) |
---|
1204 | LEFT JOIN ".USER_CACHE_CATEGORIES_TABLE." pucc ON pucc.cat_id = pic.category_id) |
---|
1205 | LEFT JOIN ".CATEGORIES_TABLE." pct ON pucc.cat_id = pct.id) |
---|
1206 | LEFT JOIN ".IMAGES_TABLE." pit ON pit.id = pgc.imageId |
---|
1207 | WHERE pucc.user_id = '".$user['id']."' |
---|
1208 | AND requestId='".$datas['requestId']."' |
---|
1209 | AND ($lngClause) |
---|
1210 | AND latitude >= ".$datas['bounds']['south']." |
---|
1211 | AND latitude <= ".$datas['bounds']['north']." |
---|
1212 | GROUP BY pgc.imageId |
---|
1213 | ORDER BY latitude, longitude;"; |
---|
1214 | $result=pwg_query($sql); |
---|
1215 | if($result) |
---|
1216 | { |
---|
1217 | // compute ratio map size / bound size |
---|
1218 | $ratioW=($datas['bounds']['east']-$datas['bounds']['west'])/$datas['width']; |
---|
1219 | $ratioH=($datas['bounds']['north']-$datas['bounds']['south'])/$datas['height']; |
---|
1220 | // works with the highest ratio |
---|
1221 | $ratio=max($ratioW, $ratioH); |
---|
1222 | $datas['distanceTreshold']=pow($datas['distanceTreshold']*$ratio,2); |
---|
1223 | |
---|
1224 | $groups=array(); |
---|
1225 | |
---|
1226 | /* |
---|
1227 | * build groups |
---|
1228 | */ |
---|
1229 | while($row=pwg_db_fetch_assoc($result)) |
---|
1230 | { |
---|
1231 | $row['imageName'] =GPCCore::getUserLanguageDesc($row['imageName']); |
---|
1232 | $row['imageTnFile']=dirname($row['path']).'/'.$conf['dir_thumbnail'].'/'.$conf['prefix_thumbnail'].get_filename_wo_extension(basename($row['path'])).'.'.$row['tn_ext']; |
---|
1233 | if(!$this->checkInGroup($row, $groups, $datas['distanceTreshold'])) |
---|
1234 | { |
---|
1235 | $groups[]=array($row); |
---|
1236 | } |
---|
1237 | } |
---|
1238 | |
---|
1239 | /* |
---|
1240 | * for each group, calculate coordinates for a unique representative |
---|
1241 | * point |
---|
1242 | */ |
---|
1243 | foreach($groups as $keyGroup => $group) |
---|
1244 | { |
---|
1245 | $coords=array( |
---|
1246 | 'nbImgTxt' => '', |
---|
1247 | 'nbImg' => 0, |
---|
1248 | 'lat' => 0, // 'lat' rather than 'latitude' |
---|
1249 | 'lng' => 0, // 'lng' rather than 'longitude' |
---|
1250 | 'imgTn' => array(), |
---|
1251 | 'imgCatsNames' => array(), |
---|
1252 | 'imgName' => array(), |
---|
1253 | 'imgCatsUrl' => array(), |
---|
1254 | ); |
---|
1255 | |
---|
1256 | foreach($group as $point) |
---|
1257 | { |
---|
1258 | $tmpCatsUrl=array(); |
---|
1259 | $tmpCatsId=explode(';', $point['imageCatsId']); |
---|
1260 | $tmpCatsNames=explode(';', $point['imageCatsNames']); |
---|
1261 | $tmpCatsPLinks=explode(';', $point['imageCatsPLink']); |
---|
1262 | |
---|
1263 | foreach($tmpCatsId as $key => $id) |
---|
1264 | { |
---|
1265 | $tmpCatsUrl[]=make_picture_url( |
---|
1266 | array( |
---|
1267 | 'image_id' => $point['imageId'], |
---|
1268 | 'category' => array( |
---|
1269 | 'id' => $id, |
---|
1270 | 'name' => GPCCore::getUserLanguageDesc($tmpCatsNames[$key]), |
---|
1271 | 'permalink' => (substr($tmpCatsPLinks[$key],0,1)=='*')?'':$tmpCatsPLinks[$key], |
---|
1272 | ) |
---|
1273 | ) |
---|
1274 | ); |
---|
1275 | } |
---|
1276 | |
---|
1277 | if(count($tmpCatsId)<=1) $tmpCatsNames=''; |
---|
1278 | |
---|
1279 | $coords['nbImg']++; |
---|
1280 | |
---|
1281 | $coords['lat']+=$point['latitude']; |
---|
1282 | $coords['lng']+=$point['longitude']; |
---|
1283 | |
---|
1284 | $coords['imgTn'][]=$this->replaceImgRoot($point['imageTnFile']); |
---|
1285 | $coords['imgCatsNames'][]=$tmpCatsNames; |
---|
1286 | $coords['imgName'][]=GPCCore::getUserLanguageDesc($point['imageName']); |
---|
1287 | $coords['imgCatsUrl'][]=$tmpCatsUrl; |
---|
1288 | } |
---|
1289 | $coords['lat']=$coords['lat']/count($group); |
---|
1290 | $coords['lng']=$coords['lng']/count($group); |
---|
1291 | $coords['uId']=md5($coords['lat'].$coords['lng']); |
---|
1292 | |
---|
1293 | if($coords['nbImg']==1) |
---|
1294 | { |
---|
1295 | $coords['nbImgTxt']=l10n('gmaps_1_picture'); |
---|
1296 | } |
---|
1297 | else |
---|
1298 | { |
---|
1299 | $coords['nbImgTxt']=sprintf(l10n('gmaps_nb_pictures'), $coords['nbImg']); |
---|
1300 | } |
---|
1301 | |
---|
1302 | $returned['markers'][]=$coords; |
---|
1303 | $returned['datas']['nbPhotos']+=$coords['nbImg']; |
---|
1304 | } |
---|
1305 | } |
---|
1306 | |
---|
1307 | if($returned['datas']['nbPhotos']>1) |
---|
1308 | { |
---|
1309 | $returned['datas']['nbPhotos']=sprintf(l10n('gmaps_nb_pictures'), $returned['datas']['nbPhotos']); |
---|
1310 | } |
---|
1311 | elseif($returned['datas']['nbPhotos']==1) |
---|
1312 | { |
---|
1313 | $returned['datas']['nbPhotos']=l10n('gmaps_1_picture'); |
---|
1314 | } |
---|
1315 | else |
---|
1316 | { |
---|
1317 | $returned['datas']['nbPhotos']=l10n('gmaps_0_picture'); |
---|
1318 | } |
---|
1319 | |
---|
1320 | return(json_encode($returned)); |
---|
1321 | } //ajax_gmaps_public_mapsGetMarkers |
---|
1322 | |
---|
1323 | /** |
---|
1324 | * check if a point is inside an existing group, and add it |
---|
1325 | * @param Array $point : the point |
---|
1326 | * @param Array &$groups : the groups |
---|
1327 | * @param Float $maxDist : maximum distance to be inside group |
---|
1328 | * @return Bool : true if added in a group, otherwise false |
---|
1329 | */ |
---|
1330 | private function checkInGroup($point, &$groups, $maxDist) |
---|
1331 | { |
---|
1332 | foreach($groups as $key=>$group) |
---|
1333 | { |
---|
1334 | $dist=pow($point['latitude']-$group[0]['latitude'],2) + pow($point['longitude']-$group[0]['longitude'],2); |
---|
1335 | |
---|
1336 | if($dist<=$maxDist) |
---|
1337 | { |
---|
1338 | $groups[$key][]=$point; |
---|
1339 | return(true); |
---|
1340 | } |
---|
1341 | } |
---|
1342 | return(false); |
---|
1343 | } |
---|
1344 | |
---|
1345 | /** |
---|
1346 | * replace the root directroy for image |
---|
1347 | * => './galleries/' becomes "G" |
---|
1348 | * => './upload/' becomes "U" |
---|
1349 | * => other case : no chnages |
---|
1350 | * |
---|
1351 | * @param String $value : path |
---|
1352 | * @returned String : |
---|
1353 | */ |
---|
1354 | private function replaceImgRoot($value) |
---|
1355 | { |
---|
1356 | if(preg_match('/^\.\/galleries\//i', $value)>0) |
---|
1357 | { |
---|
1358 | return("G".substr($value,12)); |
---|
1359 | } |
---|
1360 | elseif(preg_match('/^\.\/upload\//i', $value)>0) |
---|
1361 | { |
---|
1362 | return("U".substr($value,9)); |
---|
1363 | } |
---|
1364 | return($value); |
---|
1365 | } |
---|
1366 | |
---|
1367 | } //class |
---|
1368 | |
---|
1369 | |
---|
1370 | $returned=new GMaps_Ajax($prefixeTable, __FILE__); |
---|
1371 | ?> |
---|