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

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

feature:2638- compatibility with Piwigo 2.4

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