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

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

Connect the plugin to the RBuilder component + fixe some small bugs

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