Module: nagvis
Branch: master
Commit: b778adf8da10aca3661621b411e010040b75dc9d
URL:    
http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis;a=commit;h=b778adf8da10aca3661621b411e010040b75dc9d

Author: Lars Michelsen <[email protected]>
Date:   Mon Jun 14 20:32:19 2010 +0200

Added new module to render a multisite snapin which shows the permitted maps of 
a user

---

 share/server/core/ajax_handler.php                 |    1 +
 share/server/core/classes/CoreModMultisite.php     |  149 ++++++++++++++++++++
 share/server/core/classes/GlobalIndexPage.php      |    2 +-
 .../userfiles/templates/default.multisiteMaps.html |   10 ++
 4 files changed, 161 insertions(+), 1 deletions(-)

diff --git a/share/server/core/ajax_handler.php 
b/share/server/core/ajax_handler.php
index 16a4b5b..8dc682d 100644
--- a/share/server/core/ajax_handler.php
+++ b/share/server/core/ajax_handler.php
@@ -100,6 +100,7 @@ try {
        $MHANDLER->regModule('MainCfg');
        $MHANDLER->regModule('ManageShapes');
        $MHANDLER->regModule('ManageBackgrounds');
+       $MHANDLER->regModule('Multisite');
 
        // Load the module
        $MODULE = $MHANDLER->loadModule($UHANDLER->get('mod'));
diff --git a/share/server/core/classes/CoreModMultisite.php 
b/share/server/core/classes/CoreModMultisite.php
new file mode 100644
index 0000000..7c55c44
--- /dev/null
+++ b/share/server/core/classes/CoreModMultisite.php
@@ -0,0 +1,149 @@
+<?php
+/*******************************************************************************
+ *
+ * CoreModMultisite.php - Core multisite  module to handle ajax requests
+ *
+ * Copyright (c) 2004-2010 NagVis Project (Contact: [email protected])
+ *
+ * License:
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ 
******************************************************************************/
+
+/**
+ * @author Lars Michelsen <[email protected]>
+ */
+class CoreModMultisite extends CoreModule {
+       private $BACKEND = null;
+       
+       public function __construct(GlobalCore $CORE) {
+               $this->CORE = $CORE;
+               
+               $this->aActions = Array(
+                       'getMaps' => REQUIRES_AUTHORISATION,
+               );
+       }
+       
+       public function handleAction() {
+               $sReturn = '';
+               
+               if(!$this->offersAction($this->sAction))
+                       return '';
+               
+               $this->BACKEND = new CoreBackendMgmt($this->CORE);
+               
+               switch($this->sAction) {
+                       case 'getMaps':
+                               // Initialize template system
+                               $TMPL = New CoreTemplateSystem($this->CORE);
+                               $TMPLSYS = $TMPL->getTmplSys();
+                               
+                               $aData = Array(
+                                       'htmlBase'  => 
$this->CORE->getMainCfg()->getValue('paths', 'htmlbase'),
+                                       'maps'      => $this->getMaps(),
+                               );
+                               
+                               // Build page based on the template file and 
the data array
+                               $sReturn = 
$TMPLSYS->get($TMPL->getTmplFile('default', 'multisiteMaps'), $aData);
+                       break;
+               }
+               
+               return $sReturn;
+       }
+
+       /**
+        * Returns the NagVis maps available to the user as HTML formated string
+        *
+        * @return      String  HTML code
+        * @author      Lars Michelsen <[email protected]>
+        */
+       private function getMaps() {
+               $aObjs = Array();
+               foreach($this->CORE->getAvailableMaps() AS $object_id => 
$mapName) {
+                       if(!$this->AUTHORISATION->isPermitted('Map', 'view', 
$mapName))
+                               continue;
+                       
+                       $map = Array();
+                       $map['type'] = 'map';
+                       
+                       $MAPCFG = new NagVisMapCfg($this->CORE, $mapName);
+                       
+                       try {
+                               $MAPCFG->readMapConfig();
+                       } catch(MapCfgInvalid $e) {
+                               $map['configError'] = true;
+                               $map['configErrorMsg'] = $e->getMessage();
+                       }
+                       
+                       if($MAPCFG->getValue('global',0 , 'show_in_lists') != 1)
+                               continue;
+                       
+                       $MAP = new NagVisMap($this->CORE, $MAPCFG, 
$this->BACKEND, GET_STATE, !IS_VIEW);
+                       
+                       // Apply default configuration to object
+                       $objConf = $MAPCFG->getTypeDefaults('global');
+                       $objConf['type'] = 'map';
+                       $objConf['map_name'] = $MAPCFG->getName();
+                       $objConf['object_id'] = $object_id;
+                       // Enable the hover menu in all cases - maybe make it 
configurable
+                       $objConf['hover_menu'] = 1;
+                       $objConf['hover_childs_show'] = 1;
+                       $objConf['hover_template'] = 'default';
+                       unset($objConf['alias']);
+                       
+                       $MAP->MAPOBJ->setConfiguration($objConf);
+                       
+                       if(isset($map['configError'])) {
+                               $map['overview_class']  = 'error';
+                               $map['overview_url']    = 
'javascript:alert(\''.$map['configErrorMsg'].'\');';
+                               $map['summary_output']  = 
$this->CORE->getLang()->getText('Map Configuration Error: 
'.$map['configErrorMsg']);
+                               
+                               $MAP->MAPOBJ->clearMembers();
+                               $MAP->MAPOBJ->setSummaryState('ERROR');
+                               $MAP->MAPOBJ->fetchIcon();
+                       } elseif($MAP->MAPOBJ->checkMaintenance(0)) {
+                               $MAP->MAPOBJ->fetchIcon();
+                               
+                               $map['overview_url']    = 
$this->CORE->getMainCfg()->getValue('paths', 
'htmlbase').'/index.php?mod=Map&act=view&show='.$mapName;
+                               $map['overview_class']  = '';
+                               $map['summary_output']  = 
$MAP->MAPOBJ->getSummaryOutput();
+                       } else {
+                               $map['overview_class']  = 'disabled';
+                               $map['overview_url']    = 
'javascript:alert(\''.$this->CORE->getLang()->getText('mapInMaintenance').'\');';
+                               $map['summary_output']  = 
$this->CORE->getLang()->getText('mapInMaintenance');
+                               
+                               $MAP->MAPOBJ->clearMembers();
+                               $MAP->MAPOBJ->setSummaryState('UNKNOWN');
+                               $MAP->MAPOBJ->fetchIcon();
+                       }
+                       
+                       $MAP->MAPOBJ->queueState(GET_STATE, 
GET_SINGLE_MEMBER_STATES);
+                       $aObjs[] = Array($MAP->MAPOBJ, $map);
+               }
+               
+               $this->BACKEND->execute();
+                       
+               $aMaps = Array();
+               foreach($aObjs AS $aObj) {
+                       $aObj[0]->applyState();
+                       $aObj[0]->fetchIcon();
+                       
+                       $aMaps[] = $aObj[0]->getObjectInformation();
+               }
+               
+               return $aMaps;
+       }
+}
+?>
diff --git a/share/server/core/classes/GlobalIndexPage.php 
b/share/server/core/classes/GlobalIndexPage.php
index d403472..acb7e2a 100644
--- a/share/server/core/classes/GlobalIndexPage.php
+++ b/share/server/core/classes/GlobalIndexPage.php
@@ -49,7 +49,7 @@ class GlobalIndexPage {
        }
        
        /**
-        * Parses the automaps for the overview page
+        * Parses the maps and automaps for the overview page
         *
         * @return      String  Json Code
         * @author      Lars Michelsen <[email protected]>
diff --git a/share/userfiles/templates/default.multisiteMaps.html 
b/share/userfiles/templates/default.multisiteMaps.html
new file mode 100644
index 0000000..076d209
--- /dev/null
+++ b/share/userfiles/templates/default.multisiteMaps.html
@@ -0,0 +1,10 @@
+<table class="allhosts">
+<tbody>
+       {foreach $maps map}
+  <tr><td>
+  <div class="statebullet state2">&nbsp;</div>
+  <a href="{$htmlBase}/index.php?mod=Map&act=view&show={$map.name}" 
class="link" target="main">{$map.alias}</a>
+  </td></tr>
+       {/foreach}
+</tbody>
+</table>


------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to