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

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

Packing js files +using GPC 3.3.0 categorySelector

  • Property svn:executable set to *
File size: 13.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
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    GPCCore::addHeaderCSS('iconSelector', 'plugins/GrumPluginClasses/css/iconSelector_'.$template->get_themeconf('name').'.css');
219    GPCCore::addHeaderCSS('categorySelector', 'plugins/GrumPluginClasses/css/categorySelector_'.$template->get_themeconf('name').'.css');
220
221    $template->set_filename('body_page',
222                dirname($this->getFileLocation()).'/admin/gmaps_category_maps.tpl');
223
224    $mapTabsheet = new GPCTabSheet('mapTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itab2');
225    $mapTabsheet->add('assoc',
226                          l10n('gmaps_map_assoc'),
227                          '', false, "am.displayTab('assoc');");
228    $mapTabsheet->add('integration',
229                          l10n('gmaps_map_integration'),
230                          '', true, "am.displayTab('integration');");
231    $mapTabsheet->assign();
232
233
234    $datas=Array(
235      'urlRequest' => $this->getAdminLink('ajax'),
236      'cats' => $this->makeCategoryList(),
237      'maps' => $this->makeMapsList(),
238      'icons' => $this->makeIconsList(),
239      'markers' => $this->makeMarkersList(),
240      'kmlFiles'  => $this->makeKmlFilesList()
241    );
242    $template->assign('datas', $datas);
243
244    $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page');
245  }
246
247
248  /**
249   * display the kml file management page
250   *
251   */
252  protected function displayKmlFiles()
253  {
254    global $template;
255
256    $template->set_filename('body_page',
257                dirname($this->getFileLocation()).'/admin/gmaps_kmlfiles.tpl');
258
259    $datas=Array(
260      'urlRequest' => $this->getAdminLink('ajax'),
261    );
262    $template->assign('datas', $datas);
263
264    $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page');
265  }
266
267
268
269  /**
270   * display the search page
271   *
272   */
273  protected function displaySearch()
274  {
275    global $template;
276
277    $template->set_filename('body_page',
278                dirname($this->getFileLocation()).'/admin/gmaps_search.tpl');
279
280    $template->assign('gmaps_search_page', GPCRequestBuilder::displaySearchPage($this->getPluginName()));
281
282    $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page');
283  }
284
285
286  /**
287   * display the help page
288   *
289   */
290  protected function displayHelp()
291  {
292    global $template;
293
294    /*$template->set_filename('body_page',
295                dirname($this->getFileLocation()).'/admin/plugin_admin_maps.tpl');
296
297
298    $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page');*/
299  }
300
301
302
303  /**
304   * display a warning page if AMD is not installed
305   *
306   */
307  protected function displayAmdWarning()
308  {
309    global $template;
310
311    $template->set_filename('body_page',
312                dirname($this->getFileLocation()).'/admin/gmaps_amd_warning.tpl');
313
314    switch(GMaps_root::checkAMDActivated())
315    {
316      case 'none':
317      case 'inactive':
318        $template->assign('gmaps_amd_warning_inactive', sprintf(l10n('gmaps_amd_warning_inactive'), GMAPS_AMD_NEEDED));
319        break;
320      case 'basic':
321        $template->assign('gmaps_amd_warning_basic', l10n('gmaps_amd_warning_basic'));
322        break;
323    }
324    $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page');
325  }
326
327
328
329  /**
330   * build an ordered category list
331   * returns an array, each item is an array like :
332   *  'id'     => the category Id
333   *  'name'   => the category name
334   *  'rank'   => the category rank (global)
335   *  'level'  => the category level
336   *
337   * @return Array : the list
338   */
339  protected function makeCategoryList()
340  {
341    $returned=array(
342      array(
343        'id'     => 0,
344        'name'   => l10n('gmaps_applyForAllTheGallery'),
345        'rank'   => '0000',
346        'level'  => 0,
347        'status' => 'public',
348        'childs'  => false
349      )
350    );
351
352    $sql="SELECT DISTINCT pct.id, pct.name, pct.global_rank AS rank
353          FROM ".CATEGORIES_TABLE." pct
354            JOIN (
355              SELECT DISTINCT pgat.cat_id AS catId FROM ".GROUP_ACCESS_TABLE." pgat
356              UNION DISTINCT
357              SELECT DISTINCT puat.cat_id AS catId FROM ".USER_ACCESS_TABLE." puat
358                 ) pat
359            ON (pat.catId = pct.id AND pct.status = 'private') OR (pct.status = 'public')
360          ORDER BY global_rank;";
361    $result=pwg_query($sql);
362    if($result)
363    {
364      while($row=pwg_db_fetch_assoc($result))
365      {
366        $row['level']=1+substr_count($row['rank'], '.');
367
368        /* rank is in formated without leading zero, giving bad order
369         *  1
370         *  1.10
371         *  1.11
372         *  1.2
373         *  1.3
374         *  ....
375         *
376         *  this loop cp,vert all sub rank in four 0 format, allowing to order
377         *  categories easily
378         *  0001
379         *  0001.0010
380         *  0001.0011
381         *  0001.0002
382         *  0001.0003
383         */
384        $row['rank']=explode('.', $row['rank']);
385        foreach($row['rank'] as $key=>$rank)
386        {
387          $row['rank'][$key]=str_pad($rank, 4, '0', STR_PAD_LEFT);
388        }
389        $row['rank']=implode('.', $row['rank']);
390
391        $returned[]=$row;
392      }
393    }
394
395    usort($returned, array(&$this, 'compareCat'));
396
397    return($returned);
398  }
399
400  /**
401   * used for sort comparison
402   * defined as public, but don't use it directly
403   *
404   * this function compare two categorie with their rank value
405   */
406  public function compareCat($catA, $catB)
407  {
408    if($catA['rank'] == $catB['rank'])
409    {
410      return(0);
411    }
412    return( ($catA['rank'] < $catB['rank'])?-1:1 );
413  }
414
415
416  /**
417   * build a maps list
418   * @return Array : an array, ready to use in the template
419   */
420  private function makeMapsList()
421  {
422    $returned=array(
423      'IC' => array(),
424      'IP' => array(),
425      'MP' => array()
426    );
427
428    $sql="SELECT id, name, displayType
429          FROM ".$this->tables['maps']."
430          ORDER BY displayType, name";
431    $result = pwg_query($sql);
432    if($result)
433    {
434      while($row = pwg_db_fetch_assoc($result))
435      {
436        $returned[$row['displayType']][]=array(
437          'id' => $row['id'],
438          'name' => $row['name']
439        );
440      }
441    }
442
443    return($returned);
444  } //makeMapsList
445
446
447  /**
448   * build THE ICON LIST
449   * @return Array : an array, ready to use in the template
450   */
451  private function makeIconsList()
452  {
453    $returned=array();
454
455    $directory=scandir(GMAPS_PATH.'img/');
456    foreach($directory as $file)
457    {
458      $ext=(pathinfo($file, PATHINFO_EXTENSION));
459      if(preg_match('/^i.*(?:jpg|jpeg|png|gif)$/i', $file))
460      {
461        $returned[]=array(
462          'file' => $file
463        );
464      }
465    }
466
467    return($returned);
468  } //makeIconsList
469
470
471  /**
472   * build the markers list
473   * @return Array : an array, ready to use in the template
474   */
475  private function makeMarkersList()
476  {
477    $returned=array();
478
479    $directory=scandir(GMAPS_PATH.'img/');
480    foreach($directory as $file)
481    {
482      $ext=(pathinfo($file, PATHINFO_EXTENSION));
483      if(preg_match('/^mS(\d\d)_(\d\d)\.png$/i', $file))
484      {
485        $returned[]=array(
486          'file' => $file
487        );
488      }
489    }
490
491    return($returned);
492  } //makeIconsList
493
494  /**
495   * build the kml files list
496   * @return Array : an array, ready to use in the template
497   */
498  private function makeKmlFilesList()
499  {
500    $returned=array();
501
502    $sql="SELECT id, name
503          FROM ".$this->tables['kmlfiles']."
504          ORDER BY name, id";
505    $result = pwg_query($sql);
506    if($result)
507    {
508      while($row = pwg_db_fetch_assoc($result))
509      {
510        $returned[]=$row;
511      }
512    }
513
514    return($returned);
515  } //makeCategoriesTree
516
517} //class
518
519
520?>
Note: See TracBrowser for help on using the repository browser.