> ------------------------------------------------------------------------------ See main.inc.php for release information GMaps_AIP : classe to manage plugin admin pages --------------------------------------------------------------------------- */ include_once('gmaps_root.class.inc.php'); include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTables.class.inc.php'); include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTabSheet.class.inc.php'); include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCRequestBuilder.class.inc.php'); include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); class GMaps_AIP extends GMaps_root { protected $tabsheet; protected $amdState; public function __construct($prefixeTable, $filelocation) { parent::__construct($prefixeTable, $filelocation); $this->loadConfig(); $this->configForTemplate(); $this->amdState=GMaps_root::checkAMDActivated(); $this->initRequest(); $this->initEvents(); $this->tabsheet = new tabsheet(); if($this->amdState!='advanced') { $this->tabsheet->add('amd_warning', l10n('gmaps_warning'), $this->getAdminLink()."-amd_warning"); } $this->tabsheet->add('maps', l10n('gmaps_maps'), $this->getAdminLink()."-maps"); $this->tabsheet->add('category_maps', l10n('gmaps_associate_category_maps'), $this->getAdminLink()."-category_maps"); $this->tabsheet->add('kml_files', l10n('gmaps_kml_files_management'), $this->getAdminLink()."-kml_files"); $this->tabsheet->add('search', l10n('gmaps_search'), $this->getAdminLink()."-search"); $this->tabsheet->add('config', l10n('gmaps_config'), $this->getAdminLink()."-config"); /* $this->tabsheet->add('help', l10n('gmaps_help'), $this->getAdminLink()."-help"); */ } public function __destruct() { unset($this->tabsheet); parent::__destruct(); } /** * initialize events call for the plugin */ public function initEvents() { global $template; parent::initEvents(); if($_GET['tab']=='search') { // load request builder JS only on the search page GPCRequestBuilder::loadJSandCSS(); } } /** * display the administration page */ public function manage() { global $template; $this->cleanCache(); $this->initRequest(); $template->set_filename('plugin_admin_content', dirname(__FILE__)."/admin/gmaps_admin.tpl"); GPCCore::setTemplateToken(); switch($_GET['tab']) { case 'amd_warning': $this->displayAmdWarning(); break; case 'maps': $this->displayMaps(); break; case 'category_maps': $this->displayCategoryMaps(); break; case 'kml_files': $this->displayKmlFiles(); break; case 'search': $this->displaySearch(); break; case 'config': $this->displayConfig(); break; case 'help': $this->displayHelp(); break; } $this->tabsheet->select($_GET['tab']); $this->tabsheet->assign(); $selected_tab=$this->tabsheet->get_selected(); $template->assign($this->tabsheet->get_titlename(), "[".$selected_tab['caption']."]"); $template_plugin["GMAPS_VERSION"] = "".$this->getPluginName()." ".l10n('gmaps_release').GMAPS_VERSION; $template_plugin["GMAPS_PAGE"] = $_GET['tab']; $template_plugin["GMAPS_TITLE"] = ""; $template->assign('plugin', $template_plugin); if($_REQUEST['errcode']!='') { $template->assign('errcode', l10n('gmaps_error_code_'.$_REQUEST['errcode'])); } $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); } /** * if empty, initialize the $_REQUEST var * * if not empty, check validity for the request values * */ private function initRequest() { //initialise $REQUEST values if not defined if(!isset($_REQUEST['errcode'])) $_REQUEST['errcode']=''; if(!isset($_GET['tab'])) { if($this->amdState!='advanced' ) { $_GET['tab']="amd_warning"; } else { $_GET['tab']="maps"; } } if(!($_GET['tab']!="maps" or $_GET['tab']!="category_maps" or $_GET['tab']!="amd_warning" or $_GET['tab']!="kml_files" or $_GET['tab']!="search" //$_GET['tab']!="help" )) $_GET['tab']="maps"; if($_GET['tab']=="amd_warning" and $this->amdState=='advanced') $_GET['tab']="maps"; } /** * display de maps page * */ protected function displayMaps() { global $template; $template->set_filename('body_page', dirname($this->getFileLocation()).'/admin/gmaps_maps.tpl'); $mapTabsheet = new GPCTabSheet('mapTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itab2'); $mapTabsheet->add('general', l10n('gmaps_properties_general'), '', true, "udm.displayTab('general');"); $mapTabsheet->add('dimensions', l10n('gmaps_dimensions'), '', false, "udm.displayTab('dimensions');"); $mapTabsheet->add('mapType', l10n('gmaps_properties_mapType'), '', false, "udm.displayTab('mapType');"); $mapTabsheet->add('zoomLevel', l10n('gmaps_properties_zoomLevel'), '', false, "udm.displayTab('zoomLevel');"); $mapTabsheet->assign(); $datas=Array( 'urlRequest' => $this->getAdminLink('ajax') ); $template->assign('datas', $datas); $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page'); } /** * display the category_maps page * */ protected function displayCategoryMaps() { global $template; GPCCore::addUI('categorySelector'); GPCCore::addHeaderCSS('iconSelector', 'plugins/GrumPluginClasses/css/iconSelector_'.$template->get_themeconf('name').'.css'); $template->set_filename('body_page', dirname($this->getFileLocation()).'/admin/gmaps_category_maps.tpl'); $mapTabsheet = new GPCTabSheet('mapTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itab2'); $mapTabsheet->add('assoc', l10n('gmaps_map_assoc'), '', false, "am.displayTab('assoc');"); $mapTabsheet->add('integration', l10n('gmaps_map_integration'), '', true, "am.displayTab('integration');"); $mapTabsheet->assign(); $datas=Array( 'urlRequest' => $this->getAdminLink('ajax'), 'cats' => $this->makeCategoryList(), 'maps' => $this->makeMapsList(), 'icons' => $this->makeIconsList(), 'markers' => $this->makeMarkersList(), 'kmlFiles' => $this->makeKmlFilesList() ); $template->assign('datas', $datas); $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page'); } /** * display the kml file management page * */ protected function displayKmlFiles() { global $template; $template->set_filename('body_page', dirname($this->getFileLocation()).'/admin/gmaps_kmlfiles.tpl'); $datas=Array( 'urlRequest' => $this->getAdminLink('ajax'), ); $template->assign('datas', $datas); $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page'); } /** * display the search page * */ protected function displaySearch() { global $template; $template->set_filename('body_page', dirname($this->getFileLocation()).'/admin/gmaps_search.tpl'); $template->assign('gmaps_search_page', GPCRequestBuilder::displaySearchPage($this->getPluginName())); $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page'); } /** * display the help page * */ protected function displayHelp() { global $template; /*$template->set_filename('body_page', dirname($this->getFileLocation()).'/admin/plugin_admin_maps.tpl'); $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page');*/ } /** * display a warning page if AMD is not installed * */ protected function displayAmdWarning() { global $template; $template->set_filename('body_page', dirname($this->getFileLocation()).'/admin/gmaps_amd_warning.tpl'); switch(GMaps_root::checkAMDActivated()) { case 'none': case 'inactive': $template->assign('gmaps_amd_warning', sprintf(l10n('gmaps_amd_warning_inactive'), GMAPS_AMD_NEEDED)); break; case 'basic': $template->assign('gmaps_amd_warning', l10n('gmaps_amd_warning_basic')); break; } $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page'); } /** * display the config page * */ protected function displayConfig() { global $template; $this->updateConfig(); $this->configForTemplate(); $template->set_filename('body_page', dirname($this->getFileLocation()).'/admin/gmaps_config.tpl'); $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page'); } /** * update config values */ protected function updateConfig() { global $infos; if(!isset($_POST) or count($_POST)==0) return(false); if(isset($_POST['fBDPopupAutomaticSize']) and $_POST['fBDPopupAutomaticSize']>=0.5 and $_POST['fBDPopupAutomaticSize']<=0.95) { $this->config['popupAutomaticSize']=$_POST['fBDPopupAutomaticSize']; } else { return(false); } if($this->saveConfig()) { $this->displayResult(l10n('gmaps_config_saved'), true); return(true); } return(false); } /** * build an ordered category list * returns an array, each item is an array like : * 'id' => the category Id * 'name' => the category name * 'rank' => the category rank (global) * 'level' => the category level * * @return Array : the list */ protected function makeCategoryList() { $returned=array( array( 'id' => 0, 'name' => l10n('gmaps_applyForAllTheGallery'), 'rank' => '0000', 'level' => 0, 'status' => 'public', 'childs' => false ) ); $sql="SELECT DISTINCT pct.id, pct.name, pct.global_rank AS rank FROM ".CATEGORIES_TABLE." pct JOIN ( SELECT DISTINCT pgat.cat_id AS catId FROM ".GROUP_ACCESS_TABLE." pgat UNION DISTINCT SELECT DISTINCT puat.cat_id AS catId FROM ".USER_ACCESS_TABLE." puat ) pat ON (pat.catId = pct.id AND pct.status = 'private') OR (pct.status = 'public') ORDER BY global_rank;"; $result=pwg_query($sql); if($result) { while($row=pwg_db_fetch_assoc($result)) { $row['level']=1+substr_count($row['rank'], '.'); $returned[]=$row; } } usort($returned, array(&$this, 'compareCat')); return($returned); } /** * used for sort comparison * defined as public, but don't use it directly * * this function compare two categorie with their rank value */ public function compareCat($catA, $catB) { return(strnatcmp($catA['rank'], $catB['rank'])); } /** * build a maps list * @return Array : an array, ready to use in the template */ private function makeMapsList() { $returned=array( 'IC' => array(), 'IP' => array(), 'MP' => array() ); $sql="SELECT id, name, displayType FROM ".$this->tables['maps']." ORDER BY displayType, name"; $result = pwg_query($sql); if($result) { while($row = pwg_db_fetch_assoc($result)) { $returned[$row['displayType']][]=array( 'id' => $row['id'], 'name' => $row['name'] ); } } return($returned); } //makeMapsList /** * build THE ICON LIST * @return Array : an array, ready to use in the template */ private function makeIconsList() { $returned=array(); $directory=scandir(GMAPS_PATH.'img/'); foreach($directory as $file) { $ext=(pathinfo($file, PATHINFO_EXTENSION)); if(preg_match('/^i.*(?:jpg|jpeg|png|gif)$/i', $file)) { $returned[]=array( 'file' => $file ); } } return($returned); } //makeIconsList /** * build the markers list * @return Array : an array, ready to use in the template */ private function makeMarkersList() { $returned=array(); $directory=scandir(GMAPS_PATH.'img/'); foreach($directory as $file) { $ext=(pathinfo($file, PATHINFO_EXTENSION)); if(preg_match('/^mS(\d\d)_(\d\d)\.png$/i', $file)) { $returned[]=array( 'file' => $file ); } } return($returned); } //makeIconsList /** * build the kml files list * @return Array : an array, ready to use in the template */ private function makeKmlFilesList() { $returned=array(); $sql="SELECT id, name FROM ".$this->tables['kmlfiles']." ORDER BY name, id"; $result = pwg_query($sql); if($result) { while($row = pwg_db_fetch_assoc($result)) { $returned[]=$row; } } return($returned); } //makeCategoriesTree } //class ?>