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

Last change on this file since 7548 was 7308, checked in by grum, 13 years ago

fix bug and implement new features
bug:1926, bug:1927, bug:1929, bug:1930, bug:1931, bug:1939, bug:1946

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