source: extensions/GMaps/gmaps_ajax.php @ 27153

Last change on this file since 27153 was 16011, checked in by grum, 12 years ago

feature:2638- compatibility with Piwigo 2.4

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