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

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

Fix bugs on install process ; add street view control management

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