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