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

Last change on this file since 31844 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
RevLine 
[7054]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');
[7177]19include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCRequestBuilder.class.inc.php');
[7054]20include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
21
22class GMaps_AIP extends GMaps_root
23{
24  protected $tabsheet;
[7125]25  protected $amdState;
[7054]26
27  public function __construct($prefixeTable, $filelocation)
28  {
29    parent::__construct($prefixeTable, $filelocation);
[7139]30
[7054]31    $this->loadConfig();
32    $this->configForTemplate();
[7125]33
34    $this->amdState=GMaps_root::checkAMDActivated();
35
36    $this->initRequest();
[7054]37    $this->initEvents();
38
39    $this->tabsheet = new tabsheet();
[7125]40
41    if($this->amdState!='advanced')
42    {
43      $this->tabsheet->add('amd_warning',
44                            l10n('gmaps_warning'),
[15345]45                            $this->getAdminLink()."-amd_warning");
[7125]46    }
[7054]47    $this->tabsheet->add('maps',
48                          l10n('gmaps_maps'),
[15345]49                          $this->getAdminLink()."-maps");
[7054]50    $this->tabsheet->add('category_maps',
51                          l10n('gmaps_associate_category_maps'),
[15345]52                          $this->getAdminLink()."-category_maps");
[7125]53    $this->tabsheet->add('kml_files',
54                          l10n('gmaps_kml_files_management'),
[15345]55                          $this->getAdminLink()."-kml_files");
[7125]56    $this->tabsheet->add('search',
57                          l10n('gmaps_search'),
[15345]58                          $this->getAdminLink()."-search");
[7308]59    $this->tabsheet->add('config',
60                          l10n('gmaps_config'),
[15345]61                          $this->getAdminLink()."-config");
[7308]62
[7128]63/*    $this->tabsheet->add('help',
[7054]64                          l10n('gmaps_help'),
[15345]65                          $this->getAdminLink()."-help");
[7125]66*/
[7054]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  {
[16011]80    global $template;
81
[7128]82    parent::initEvents();
83
[15345]84    if($_GET['tab']=='search')
[7128]85    {
86      // load request builder JS only on the search page
87      GPCRequestBuilder::loadJSandCSS();
88    }
[7054]89  }
90
[16011]91
[7054]92  /**
93   * display the administration page
94   */
95  public function manage()
96  {
97    global $template;
98
[7616]99    $this->cleanCache();
[7054]100    $this->initRequest();
101
102    $template->set_filename('plugin_admin_content', dirname(__FILE__)."/admin/gmaps_admin.tpl");
[16011]103    GPCCore::setTemplateToken();
[7054]104
[15345]105    switch($_GET['tab'])
[7054]106    {
[7125]107      case 'amd_warning':
108        $this->displayAmdWarning();
109        break;
[7054]110      case 'maps':
111        $this->displayMaps();
112        break;
113      case 'category_maps':
114        $this->displayCategoryMaps();
115        break;
[7125]116      case 'kml_files':
117        $this->displayKmlFiles();
118        break;
119      case 'search':
120        $this->displaySearch();
121        break;
[7308]122      case 'config':
123        $this->displayConfig();
124        break;
[7054]125      case 'help':
126        $this->displayHelp();
127        break;
128    }
129
[15345]130    $this->tabsheet->select($_GET['tab']);
[7054]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;
[15345]136    $template_plugin["GMAPS_PAGE"] = $_GET['tab'];
[7054]137    $template_plugin["GMAPS_TITLE"] = "";
138
139    $template->assign('plugin', $template_plugin);
[7132]140
141    if($_REQUEST['errcode']!='')
142    {
143      $template->assign('errcode', l10n('gmaps_error_code_'.$_REQUEST['errcode']));
144    }
145
[7054]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
[7132]163    if(!isset($_REQUEST['errcode'])) $_REQUEST['errcode']='';
164
[15345]165    if(!isset($_GET['tab']))
[7054]166    {
[7177]167      if($this->amdState!='advanced' )
168      {
[15345]169        $_GET['tab']="amd_warning";
[7177]170      }
171      else
172      {
[15345]173        $_GET['tab']="maps";
[7177]174      }
[7054]175    }
176
[15345]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";
[7125]184
[15345]185    if($_GET['tab']=="amd_warning" and $this->amdState=='advanced') $_GET['tab']="maps";
[7054]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'),
[7125]206                          '', true, "udm.displayTab('general');");
[7054]207    $mapTabsheet->add('dimensions',
208                          l10n('gmaps_dimensions'),
[7125]209                          '', false, "udm.displayTab('dimensions');");
[7054]210    $mapTabsheet->add('mapType',
211                          l10n('gmaps_properties_mapType'),
[7125]212                          '', false, "udm.displayTab('mapType');");
[7054]213    $mapTabsheet->add('zoomLevel',
214                          l10n('gmaps_properties_zoomLevel'),
[7125]215                          '', false, "udm.displayTab('zoomLevel');");
[7054]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
[16011]236    GPCCore::addUI('categorySelector');
[7176]237    GPCCore::addHeaderCSS('iconSelector', 'plugins/GrumPluginClasses/css/iconSelector_'.$template->get_themeconf('name').'.css');
238
[7125]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'),
[7139]254      'cats' => $this->makeCategoryList(),
[7125]255      'maps' => $this->makeMapsList(),
256      'icons' => $this->makeIconsList(),
[7139]257      'markers' => $this->makeMarkersList(),
[7132]258      'kmlFiles'  => $this->makeKmlFilesList()
[7125]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
[7132]274    $template->set_filename('body_page',
275                dirname($this->getFileLocation()).'/admin/gmaps_kmlfiles.tpl');
[7054]276
[7132]277    $datas=Array(
278      'urlRequest' => $this->getAdminLink('ajax'),
279    );
280    $template->assign('datas', $datas);
[7054]281
[7132]282    $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page');
[7054]283  }
284
[7125]285
286
[7054]287  /**
[7125]288   * display the search page
289   *
290   */
291  protected function displaySearch()
292  {
293    global $template;
294
[7128]295    $template->set_filename('body_page',
296                dirname($this->getFileLocation()).'/admin/gmaps_search.tpl');
[7125]297
[7128]298    $template->assign('gmaps_search_page', GPCRequestBuilder::displaySearchPage($this->getPluginName()));
[7125]299
[7128]300    $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page');
[7125]301  }
302
303
304  /**
[7054]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
[7125]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':
[7177]336        $template->assign('gmaps_amd_warning', sprintf(l10n('gmaps_amd_warning_inactive'), GMAPS_AMD_NEEDED));
[7125]337        break;
338      case 'basic':
[7177]339        $template->assign('gmaps_amd_warning', l10n('gmaps_amd_warning_basic'));
[7125]340        break;
341    }
342    $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page');
343  }
344
345
[7139]346
[7308]347
348
[7125]349  /**
[7308]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  /**
[7139]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
[7125]408   */
[7139]409  protected function makeCategoryList()
[7125]410  {
411    $returned=array(
412      array(
[7139]413        'id'     => 0,
414        'name'   => l10n('gmaps_applyForAllTheGallery'),
415        'rank'   => '0000',
416        'level'  => 0,
417        'status' => 'public',
418        'childs'  => false
[7125]419      )
420    );
421
[7139]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);
[7125]432    if($result)
433    {
[7139]434      while($row=pwg_db_fetch_assoc($result))
[7125]435      {
[7139]436        $row['level']=1+substr_count($row['rank'], '.');
437        $returned[]=$row;
[7125]438      }
439    }
440
[7139]441    usort($returned, array(&$this, 'compareCat'));
442
[7125]443    return($returned);
[7139]444  }
[7125]445
[7139]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  {
[7308]454    return(strnatcmp($catA['rank'], $catB['rank']));
[7139]455  }
[7125]456
[7139]457
[7125]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);
[7132]486  } //makeMapsList
[7125]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);
[7132]510  } //makeIconsList
511
512
513  /**
[7139]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  /**
[7132]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);
[7125]557  } //makeCategoriesTree
558
[7054]559} //class
560
561
562?>
Note: See TracBrowser for help on using the repository browser.