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

Last change on this file since 7139 was 7139, checked in by grum, 14 years ago

add marker style management + minor bugs fixed

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