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

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

Admin interface + Gallery integration finished

  • Property svn:executable set to *
File size: 10.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    $this->loadConfig();
30    $this->configForTemplate();
31
32    $this->amdState=GMaps_root::checkAMDActivated();
33
34    $this->initRequest();
35    $this->initEvents();
36
37    $this->tabsheet = new tabsheet();
38
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/*
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    add_event_handler('loc_end_page_header', array(&$this->css, 'applyCSS'));
77    GPCCss::applyGpcCss();
78
79    parent::initEvents();
80  }
81
82  /**
83   * display the administration page
84   */
85  public function manage()
86  {
87    global $template;
88
89    $this->initRequest();
90
91    $template->set_filename('plugin_admin_content', dirname(__FILE__)."/admin/gmaps_admin.tpl");
92
93    switch($_REQUEST['fGMaps_tabsheet'])
94    {
95      case 'amd_warning':
96        $this->displayAmdWarning();
97        break;
98      case 'maps':
99        $this->displayMaps();
100        break;
101      case 'category_maps':
102        $this->displayCategoryMaps();
103        break;
104      case 'kml_files':
105        $this->displayKmlFiles();
106        break;
107      case 'search':
108        $this->displaySearch();
109        break;
110      case 'help':
111        $this->displayHelp();
112        break;
113    }
114
115    $this->tabsheet->select($_REQUEST['fGMaps_tabsheet']);
116    $this->tabsheet->assign();
117    $selected_tab=$this->tabsheet->get_selected();
118    $template->assign($this->tabsheet->get_titlename(), "[".$selected_tab['caption']."]");
119
120    $template_plugin["GMAPS_VERSION"] = "<i>".$this->getPluginName()."</i> ".l10n('gmaps_release').GMAPS_VERSION;
121    $template_plugin["GMAPS_PAGE"] = $_REQUEST['fGMaps_tabsheet'];
122    $template_plugin["GMAPS_TITLE"] = "";
123
124    $template->assign('plugin', $template_plugin);
125    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
126
127  }
128
129
130
131
132  /**
133   * if empty, initialize the $_REQUEST var
134   *
135   * if not empty, check validity for the request values
136   *
137   */
138  private function initRequest()
139  {
140    //initialise $REQUEST values if not defined
141
142    if(!isset($_REQUEST['fGMaps_tabsheet']))
143    {
144      $_REQUEST['fGMaps_tabsheet']="maps";
145    }
146
147    if(!($_REQUEST['fGMaps_tabsheet']!="maps" or
148         $_REQUEST['fGMaps_tabsheet']!="category_maps" or
149         $_REQUEST['fGMaps_tabsheet']!="amd_warning"
150         //$_REQUEST['fGMaps_tabsheet']!="kml_files" or
151         //$_REQUEST['fGMaps_tabsheet']!="search" or
152         //$_REQUEST['fGMaps_tabsheet']!="help"
153         )) $_REQUEST['fGMaps_tabsheet']="maps";
154
155    if($_REQUEST['fGMaps_tabsheet']=="amd_warning" and $this->amdState=='advanced') $_REQUEST['fGMaps_tabsheet']="maps";
156  }
157
158
159
160
161
162  /**
163   * display de maps page
164   *
165   */
166  protected function displayMaps()
167  {
168    global $template;
169
170    $template->set_filename('body_page',
171                dirname($this->getFileLocation()).'/admin/gmaps_maps.tpl');
172
173    $mapTabsheet = new GPCTabSheet('mapTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itab2');
174    $mapTabsheet->add('general',
175                          l10n('gmaps_properties_general'),
176                          '', true, "udm.displayTab('general');");
177    $mapTabsheet->add('dimensions',
178                          l10n('gmaps_dimensions'),
179                          '', false, "udm.displayTab('dimensions');");
180    $mapTabsheet->add('mapType',
181                          l10n('gmaps_properties_mapType'),
182                          '', false, "udm.displayTab('mapType');");
183    $mapTabsheet->add('zoomLevel',
184                          l10n('gmaps_properties_zoomLevel'),
185                          '', false, "udm.displayTab('zoomLevel');");
186    $mapTabsheet->assign();
187
188
189    $datas=Array(
190      'urlRequest' => $this->getAdminLink('ajax')
191    );
192    $template->assign('datas', $datas);
193
194    $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page');
195  }
196
197
198  /**
199   * display the category_maps page
200   *
201   */
202  protected function displayCategoryMaps()
203  {
204    global $template;
205
206    $template->set_filename('body_page',
207                dirname($this->getFileLocation()).'/admin/gmaps_category_maps.tpl');
208
209    $mapTabsheet = new GPCTabSheet('mapTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itab2');
210    $mapTabsheet->add('assoc',
211                          l10n('gmaps_map_assoc'),
212                          '', false, "am.displayTab('assoc');");
213    $mapTabsheet->add('integration',
214                          l10n('gmaps_map_integration'),
215                          '', true, "am.displayTab('integration');");
216    $mapTabsheet->assign();
217
218
219    $datas=Array(
220      'urlRequest' => $this->getAdminLink('ajax'),
221      'cats' => $this->makeCategoriesTree(),
222      'maps' => $this->makeMapsList(),
223      'icons' => $this->makeIconsList(),
224    );
225    $template->assign('datas', $datas);
226
227    $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page');
228  }
229
230
231  /**
232   * display the kml file management page
233   *
234   */
235  protected function displayKmlFiles()
236  {
237    global $template;
238
239    /*$template->set_filename('body_page',
240                dirname($this->getFileLocation()).'/admin/plugin_admin_maps.tpl');
241
242
243    $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page');*/
244  }
245
246
247
248  /**
249   * display the search page
250   *
251   */
252  protected function displaySearch()
253  {
254    global $template;
255
256    /*$template->set_filename('body_page',
257                dirname($this->getFileLocation()).'/admin/plugin_admin_maps.tpl');
258
259
260    $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page');*/
261  }
262
263
264  /**
265   * display the help page
266   *
267   */
268  protected function displayHelp()
269  {
270    global $template;
271
272    /*$template->set_filename('body_page',
273                dirname($this->getFileLocation()).'/admin/plugin_admin_maps.tpl');
274
275
276    $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page');*/
277  }
278
279
280
281  /**
282   * display a warning page if AMD is not installed
283   *
284   */
285  protected function displayAmdWarning()
286  {
287    global $template;
288
289    $template->set_filename('body_page',
290                dirname($this->getFileLocation()).'/admin/gmaps_amd_warning.tpl');
291
292    switch(GMaps_root::checkAMDActivated())
293    {
294      case 'none':
295      case 'inactive':
296        $template->assign('gmaps_amd_warning_inactive', sprintf(l10n('gmaps_amd_warning_inactive'), GMAPS_AMD_NEEDED));
297        break;
298      case 'basic':
299        $template->assign('gmaps_amd_warning_basic', l10n('gmaps_amd_warning_basic'));
300        break;
301    }
302    $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page');
303  }
304
305
306  /**
307   * build the categories tree
308   * @return Array : an array, ready to use in the template
309   */
310  private function makeCategoriesTree()
311  {
312    $returned=array(
313      array(
314        'id' => 0,
315        'name' => '-- '.l10n('gmaps_applyForAllTheGallery').' --'
316      )
317    );
318
319    $sql="SELECT id, name, global_rank
320          FROM ".CATEGORIES_TABLE."
321          ORDER BY global_rank";
322    $result = pwg_query($sql);
323    if($result)
324    {
325      while ($row = pwg_db_fetch_assoc($result))
326      {
327        $returned[]=array(
328          'id' => $row['id'],
329          'name' => str_repeat('&nbsp;&nbsp;', substr_count($row['global_rank'], '.')).$row['name']
330        );
331      }
332    }
333
334    return($returned);
335  } //makeCategoriesTree
336
337
338  /**
339   * build a maps list
340   * @return Array : an array, ready to use in the template
341   */
342  private function makeMapsList()
343  {
344    $returned=array(
345      'IC' => array(),
346      'IP' => array(),
347      'MP' => array()
348    );
349
350    $sql="SELECT id, name, displayType
351          FROM ".$this->tables['maps']."
352          ORDER BY displayType, name";
353    $result = pwg_query($sql);
354    if($result)
355    {
356      while($row = pwg_db_fetch_assoc($result))
357      {
358        $returned[$row['displayType']][]=array(
359          'id' => $row['id'],
360          'name' => $row['name']
361        );
362      }
363    }
364
365    return($returned);
366  } //makeCategoriesTree
367
368
369  /**
370   * build THE ICON LIST
371   * @return Array : an array, ready to use in the template
372   */
373  private function makeIconsList()
374  {
375    $returned=array();
376
377    $directory=scandir(GMAPS_PATH.'img/');
378    foreach($directory as $file)
379    {
380      $ext=(pathinfo($file, PATHINFO_EXTENSION));
381      if(preg_match('/^i.*(?:jpg|jpeg|png|gif)$/i', $file))
382      {
383        $returned[]=array(
384          'type' => (strtolower(substr($file,0,1))=='i')?'img':'other',
385          'file' => $file
386        );
387      }
388    }
389
390    return($returned);
391  } //makeCategoriesTree
392
393
394} //class
395
396
397?>
Note: See TracBrowser for help on using the repository browser.