source: extensions/GMaps/gmaps_aip.class.inc.php @ 9568

Last change on this file since 9568 was 7616, checked in by grum, 13 years ago

fix bug:2004 - Cache table becomes very huge
fix bug:2005 - Category map is not displayed when a [gmaps] map is inserted in category description

  • Property svn:executable set to *
File size: 14.3 KB
Line 
1<?php
2/* -----------------------------------------------------------------------------
3  Plugin     : GMaps
4  Author     : Grum
5    email    : grum@piwigo.org
6    website  : http://photos.grum.fr
7
8    << May the Little SpaceFrog be with you ! >>
9  ------------------------------------------------------------------------------
10  See main.inc.php for release information
11
12  GMaps_AIP : classe to manage plugin admin pages
13
14  --------------------------------------------------------------------------- */
15
16include_once('gmaps_root.class.inc.php');
17include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTables.class.inc.php');
18include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTabSheet.class.inc.php');
19include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCRequestBuilder.class.inc.php');
20include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
21
22class GMaps_AIP extends GMaps_root
23{
24  protected $tabsheet;
25  protected $amdState;
26
27  public function __construct($prefixeTable, $filelocation)
28  {
29    parent::__construct($prefixeTable, $filelocation);
30
31    $this->loadConfig();
32    $this->configForTemplate();
33
34    $this->amdState=GMaps_root::checkAMDActivated();
35
36    $this->initRequest();
37    $this->initEvents();
38
39    $this->tabsheet = new tabsheet();
40
41    if($this->amdState!='advanced')
42    {
43      $this->tabsheet->add('amd_warning',
44                            l10n('gmaps_warning'),
45                            $this->getAdminLink()."&amp;fGMaps_tabsheet=amd_warning");
46    }
47    $this->tabsheet->add('maps',
48                          l10n('gmaps_maps'),
49                          $this->getAdminLink()."&amp;fGMaps_tabsheet=maps");
50    $this->tabsheet->add('category_maps',
51                          l10n('gmaps_associate_category_maps'),
52                          $this->getAdminLink()."&amp;fGMaps_tabsheet=category_maps");
53    $this->tabsheet->add('kml_files',
54                          l10n('gmaps_kml_files_management'),
55                          $this->getAdminLink()."&amp;fGMaps_tabsheet=kml_files");
56    $this->tabsheet->add('search',
57                          l10n('gmaps_search'),
58                          $this->getAdminLink()."&amp;fGMaps_tabsheet=search");
59    $this->tabsheet->add('config',
60                          l10n('gmaps_config'),
61                          $this->getAdminLink()."&amp;fGMaps_tabsheet=config");
62
63/*    $this->tabsheet->add('help',
64                          l10n('gmaps_help'),
65                          $this->getAdminLink()."&amp;fGMaps_tabsheet=help");
66*/
67  }
68
69  public function __destruct()
70  {
71    unset($this->tabsheet);
72    parent::__destruct();
73  }
74
75  /**
76   * initialize events call for the plugin
77   */
78  public function initEvents()
79  {
80    parent::initEvents();
81
82    if($_REQUEST['fGMaps_tabsheet']=='search')
83    {
84      // load request builder JS only on the search page
85      GPCRequestBuilder::loadJSandCSS();
86    }
87    add_event_handler('loc_end_page_header', array(&$this->css, 'applyCSS'));
88    GPCCss::applyGpcCss();
89  }
90
91  /**
92   * display the administration page
93   */
94  public function manage()
95  {
96    global $template;
97
98    $this->cleanCache();
99    $this->initRequest();
100
101    $template->set_filename('plugin_admin_content', dirname(__FILE__)."/admin/gmaps_admin.tpl");
102
103    switch($_REQUEST['fGMaps_tabsheet'])
104    {
105      case 'amd_warning':
106        $this->displayAmdWarning();
107        break;
108      case 'maps':
109        $this->displayMaps();
110        break;
111      case 'category_maps':
112        $this->displayCategoryMaps();
113        break;
114      case 'kml_files':
115        $this->displayKmlFiles();
116        break;
117      case 'search':
118        $this->displaySearch();
119        break;
120      case 'config':
121        $this->displayConfig();
122        break;
123      case 'help':
124        $this->displayHelp();
125        break;
126    }
127
128    $this->tabsheet->select($_REQUEST['fGMaps_tabsheet']);
129    $this->tabsheet->assign();
130    $selected_tab=$this->tabsheet->get_selected();
131    $template->assign($this->tabsheet->get_titlename(), "[".$selected_tab['caption']."]");
132
133    $template_plugin["GMAPS_VERSION"] = "<i>".$this->getPluginName()."</i> ".l10n('gmaps_release').GMAPS_VERSION;
134    $template_plugin["GMAPS_PAGE"] = $_REQUEST['fGMaps_tabsheet'];
135    $template_plugin["GMAPS_TITLE"] = "";
136
137    $template->assign('plugin', $template_plugin);
138
139    if($_REQUEST['errcode']!='')
140    {
141      $template->assign('errcode', l10n('gmaps_error_code_'.$_REQUEST['errcode']));
142    }
143
144    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
145
146  }
147
148
149
150
151  /**
152   * if empty, initialize the $_REQUEST var
153   *
154   * if not empty, check validity for the request values
155   *
156   */
157  private function initRequest()
158  {
159    //initialise $REQUEST values if not defined
160
161    if(!isset($_REQUEST['errcode'])) $_REQUEST['errcode']='';
162
163    if(!isset($_REQUEST['fGMaps_tabsheet']))
164    {
165      if($this->amdState!='advanced' )
166      {
167        $_REQUEST['fGMaps_tabsheet']="amd_warning";
168      }
169      else
170      {
171        $_REQUEST['fGMaps_tabsheet']="maps";
172      }
173    }
174
175    if(!($_REQUEST['fGMaps_tabsheet']!="maps" or
176         $_REQUEST['fGMaps_tabsheet']!="category_maps" or
177         $_REQUEST['fGMaps_tabsheet']!="amd_warning" or
178         $_REQUEST['fGMaps_tabsheet']!="kml_files" or
179         $_REQUEST['fGMaps_tabsheet']!="search"
180         //$_REQUEST['fGMaps_tabsheet']!="help"
181         )) $_REQUEST['fGMaps_tabsheet']="maps";
182
183    if($_REQUEST['fGMaps_tabsheet']=="amd_warning" and $this->amdState=='advanced') $_REQUEST['fGMaps_tabsheet']="maps";
184  }
185
186
187
188
189
190  /**
191   * display de maps page
192   *
193   */
194  protected function displayMaps()
195  {
196    global $template;
197
198    $template->set_filename('body_page',
199                dirname($this->getFileLocation()).'/admin/gmaps_maps.tpl');
200
201    $mapTabsheet = new GPCTabSheet('mapTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itab2');
202    $mapTabsheet->add('general',
203                          l10n('gmaps_properties_general'),
204                          '', true, "udm.displayTab('general');");
205    $mapTabsheet->add('dimensions',
206                          l10n('gmaps_dimensions'),
207                          '', false, "udm.displayTab('dimensions');");
208    $mapTabsheet->add('mapType',
209                          l10n('gmaps_properties_mapType'),
210                          '', false, "udm.displayTab('mapType');");
211    $mapTabsheet->add('zoomLevel',
212                          l10n('gmaps_properties_zoomLevel'),
213                          '', false, "udm.displayTab('zoomLevel');");
214    $mapTabsheet->assign();
215
216
217    $datas=Array(
218      'urlRequest' => $this->getAdminLink('ajax')
219    );
220    $template->assign('datas', $datas);
221
222    $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page');
223  }
224
225
226  /**
227   * display the category_maps page
228   *
229   */
230  protected function displayCategoryMaps()
231  {
232    global $template;
233
234    GPCCore::addHeaderCSS('iconSelector', 'plugins/GrumPluginClasses/css/iconSelector_'.$template->get_themeconf('name').'.css');
235    GPCCore::addHeaderCSS('categorySelector', 'plugins/GrumPluginClasses/css/categorySelector_'.$template->get_themeconf('name').'.css');
236
237    $template->set_filename('body_page',
238                dirname($this->getFileLocation()).'/admin/gmaps_category_maps.tpl');
239
240    $mapTabsheet = new GPCTabSheet('mapTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itab2');
241    $mapTabsheet->add('assoc',
242                          l10n('gmaps_map_assoc'),
243                          '', false, "am.displayTab('assoc');");
244    $mapTabsheet->add('integration',
245                          l10n('gmaps_map_integration'),
246                          '', true, "am.displayTab('integration');");
247    $mapTabsheet->assign();
248
249
250    $datas=Array(
251      'urlRequest' => $this->getAdminLink('ajax'),
252      'cats' => $this->makeCategoryList(),
253      'maps' => $this->makeMapsList(),
254      'icons' => $this->makeIconsList(),
255      'markers' => $this->makeMarkersList(),
256      'kmlFiles'  => $this->makeKmlFilesList()
257    );
258    $template->assign('datas', $datas);
259
260    $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page');
261  }
262
263
264  /**
265   * display the kml file management page
266   *
267   */
268  protected function displayKmlFiles()
269  {
270    global $template;
271
272    $template->set_filename('body_page',
273                dirname($this->getFileLocation()).'/admin/gmaps_kmlfiles.tpl');
274
275    $datas=Array(
276      'urlRequest' => $this->getAdminLink('ajax'),
277    );
278    $template->assign('datas', $datas);
279
280    $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page');
281  }
282
283
284
285  /**
286   * display the search page
287   *
288   */
289  protected function displaySearch()
290  {
291    global $template;
292
293    $template->set_filename('body_page',
294                dirname($this->getFileLocation()).'/admin/gmaps_search.tpl');
295
296    $template->assign('gmaps_search_page', GPCRequestBuilder::displaySearchPage($this->getPluginName()));
297
298    $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page');
299  }
300
301
302  /**
303   * display the help page
304   *
305   */
306  protected function displayHelp()
307  {
308    global $template;
309
310    /*$template->set_filename('body_page',
311                dirname($this->getFileLocation()).'/admin/plugin_admin_maps.tpl');
312
313
314    $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page');*/
315  }
316
317
318
319  /**
320   * display a warning page if AMD is not installed
321   *
322   */
323  protected function displayAmdWarning()
324  {
325    global $template;
326
327    $template->set_filename('body_page',
328                dirname($this->getFileLocation()).'/admin/gmaps_amd_warning.tpl');
329
330    switch(GMaps_root::checkAMDActivated())
331    {
332      case 'none':
333      case 'inactive':
334        $template->assign('gmaps_amd_warning', sprintf(l10n('gmaps_amd_warning_inactive'), GMAPS_AMD_NEEDED));
335        break;
336      case 'basic':
337        $template->assign('gmaps_amd_warning', l10n('gmaps_amd_warning_basic'));
338        break;
339    }
340    $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page');
341  }
342
343
344
345
346
347  /**
348   * display the config page
349   *
350   */
351  protected function displayConfig()
352  {
353    global $template;
354
355    $this->updateConfig();
356    $this->configForTemplate();
357
358    $template->set_filename('body_page',
359                dirname($this->getFileLocation()).'/admin/gmaps_config.tpl');
360
361    $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page');
362  }
363
364  /**
365   * update config values
366   */
367  protected function updateConfig()
368  {
369    global $infos;
370
371    if(!isset($_POST) or count($_POST)==0) return(false);
372
373
374    if(isset($_POST['fBDPopupAutomaticSize']) and $_POST['fBDPopupAutomaticSize']>=0.5 and $_POST['fBDPopupAutomaticSize']<=0.95)
375    {
376      $this->config['popupAutomaticSize']=$_POST['fBDPopupAutomaticSize'];
377    }
378    else
379    {
380      return(false);
381    }
382
383    if($this->saveConfig())
384    {
385      $this->displayResult(l10n('gmaps_config_saved'), true);
386      return(true);
387    }
388    return(false);
389  }
390
391
392
393
394
395
396
397  /**
398   * build an ordered category list
399   * returns an array, each item is an array like :
400   *  'id'     => the category Id
401   *  'name'   => the category name
402   *  'rank'   => the category rank (global)
403   *  'level'  => the category level
404   *
405   * @return Array : the list
406   */
407  protected function makeCategoryList()
408  {
409    $returned=array(
410      array(
411        'id'     => 0,
412        'name'   => l10n('gmaps_applyForAllTheGallery'),
413        'rank'   => '0000',
414        'level'  => 0,
415        'status' => 'public',
416        'childs'  => false
417      )
418    );
419
420    $sql="SELECT DISTINCT pct.id, pct.name, pct.global_rank AS rank
421          FROM ".CATEGORIES_TABLE." pct
422            JOIN (
423              SELECT DISTINCT pgat.cat_id AS catId FROM ".GROUP_ACCESS_TABLE." pgat
424              UNION DISTINCT
425              SELECT DISTINCT puat.cat_id AS catId FROM ".USER_ACCESS_TABLE." puat
426                 ) pat
427            ON (pat.catId = pct.id AND pct.status = 'private') OR (pct.status = 'public')
428          ORDER BY global_rank;";
429    $result=pwg_query($sql);
430    if($result)
431    {
432      while($row=pwg_db_fetch_assoc($result))
433      {
434        $row['level']=1+substr_count($row['rank'], '.');
435        $returned[]=$row;
436      }
437    }
438
439    usort($returned, array(&$this, 'compareCat'));
440
441    return($returned);
442  }
443
444  /**
445   * used for sort comparison
446   * defined as public, but don't use it directly
447   *
448   * this function compare two categorie with their rank value
449   */
450  public function compareCat($catA, $catB)
451  {
452    return(strnatcmp($catA['rank'], $catB['rank']));
453  }
454
455
456  /**
457   * build a maps list
458   * @return Array : an array, ready to use in the template
459   */
460  private function makeMapsList()
461  {
462    $returned=array(
463      'IC' => array(),
464      'IP' => array(),
465      'MP' => array()
466    );
467
468    $sql="SELECT id, name, displayType
469          FROM ".$this->tables['maps']."
470          ORDER BY displayType, name";
471    $result = pwg_query($sql);
472    if($result)
473    {
474      while($row = pwg_db_fetch_assoc($result))
475      {
476        $returned[$row['displayType']][]=array(
477          'id' => $row['id'],
478          'name' => $row['name']
479        );
480      }
481    }
482
483    return($returned);
484  } //makeMapsList
485
486
487  /**
488   * build THE ICON LIST
489   * @return Array : an array, ready to use in the template
490   */
491  private function makeIconsList()
492  {
493    $returned=array();
494
495    $directory=scandir(GMAPS_PATH.'img/');
496    foreach($directory as $file)
497    {
498      $ext=(pathinfo($file, PATHINFO_EXTENSION));
499      if(preg_match('/^i.*(?:jpg|jpeg|png|gif)$/i', $file))
500      {
501        $returned[]=array(
502          'file' => $file
503        );
504      }
505    }
506
507    return($returned);
508  } //makeIconsList
509
510
511  /**
512   * build the markers list
513   * @return Array : an array, ready to use in the template
514   */
515  private function makeMarkersList()
516  {
517    $returned=array();
518
519    $directory=scandir(GMAPS_PATH.'img/');
520    foreach($directory as $file)
521    {
522      $ext=(pathinfo($file, PATHINFO_EXTENSION));
523      if(preg_match('/^mS(\d\d)_(\d\d)\.png$/i', $file))
524      {
525        $returned[]=array(
526          'file' => $file
527        );
528      }
529    }
530
531    return($returned);
532  } //makeIconsList
533
534  /**
535   * build the kml files list
536   * @return Array : an array, ready to use in the template
537   */
538  private function makeKmlFilesList()
539  {
540    $returned=array();
541
542    $sql="SELECT id, name
543          FROM ".$this->tables['kmlfiles']."
544          ORDER BY name, id";
545    $result = pwg_query($sql);
546    if($result)
547    {
548      while($row = pwg_db_fetch_assoc($result))
549      {
550        $returned[]=$row;
551      }
552    }
553
554    return($returned);
555  } //makeCategoriesTree
556
557} //class
558
559
560?>
Note: See TracBrowser for help on using the repository browser.