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

Author: Lars Michelsen <[email protected]>
Date:   Thu Jun 17 18:03:35 2010 +0200

#313 Fetching services of a host in WUI addmodify dialog works again

---

 share/frontend/wui/ajax_handler.php |   62 ++++++++++++++--------------------
 1 files changed, 26 insertions(+), 36 deletions(-)

diff --git a/share/frontend/wui/ajax_handler.php 
b/share/frontend/wui/ajax_handler.php
index 858f9c9..0455f03 100644
--- a/share/frontend/wui/ajax_handler.php
+++ b/share/frontend/wui/ajax_handler.php
@@ -54,8 +54,10 @@ if(!isset($_GET['action'])) {
 switch($_GET['action']) {
        /*
         * Get all objects in defined BACKEND if the defined TYPE
+        * Get all services in the defined BACKEND of the defined HOST
         */
        case 'getObjects':
+       case 'getServices':
                // These values are submited by WUI requests:
                // $_GET['backend_id'], $_GET['type']
                
@@ -64,10 +66,14 @@ switch($_GET['action']) {
                
                // Do some validations
                if(!isset($_GET['backend_id']) || $_GET['backend_id'] == '')
-                       new GlobalMessage('ERROR', 
$CORE->getLang()->getText('mustValueNotSet', 'ATTRIBUTE~backend_id'));
-               if(!isset($_GET['type']) || $_GET['type'] == '') {
-                       new GlobalMessage('ERROR', 
$CORE->getLang()->getText('mustValueNotSet', 'ATTRIBUTE~type'));
-               }
+                       new GlobalMessage('ERROR', 
$CORE->getLang()->getText('mustValueNotSet1', 'ATTRIBUTE~backend_id'));
+
+               if($_GET['action'] === 'getObjects' && (!isset($_GET['type']) 
|| $_GET['type'] == ''))
+                       new GlobalMessage('ERROR', 
$CORE->getLang()->getText('mustValueNotSet1', 'ATTRIBUTE~type'));
+
+               // Special validation for getServices
+               if($_GET['action'] === 'getServices' && 
(!isset($_GET['host_name']) || $_GET['host_name'] == ''))
+                       new GlobalMessage('ERROR', 
$CORE->getLang()->getText('mustValueNotSet1', 'ATTRIBUTE~host_name'));
 
                try {
                        
if(!method_exists($BACKEND->getBackend($_GET['backend_id']),'getObjects')) {
@@ -81,46 +87,30 @@ switch($_GET['action']) {
 
                // Input looks OK, handle the request...
                
-               $aRet = Array(Array('name' => ''));
+               $name1 = ($_GET['action'] === 'getServices' ? 
$_GET['host_name'] : '');
+               $type =  ($_GET['action'] === 'getObjects'  ? $_GET['type']     
 : 'service');
+               
+               // Initialize an empty list
+               if($_GET['action'] === 'getObjects')
+                       $aRet = Array(Array('name' => ''));
+               else
+                       $aRet = Array(Array('host_name' => '', 
'service_description' => ''));
+               
                // Read all objects of the requested type from the backend
                try {
-                       
foreach($BACKEND->getBackend($_GET['backend_id'])->getObjects($_GET['type'],'','')
 AS $arr) {
-                               $aRet[] = Array('name' => $arr['name1']);
+                       $objs = 
$BACKEND->getBackend($_GET['backend_id'])->getObjects($type, $name1, '');
+                       foreach($objs AS $obj) {
+                               if($_GET['action'] === 'getObjects')
+                                       $aRet[] = Array('name' => 
$obj['name1']);
+                               else
+                                       $aRet[] = Array('host_name'           
=> $obj['name1'],
+                                                       'service_description' 
=> $obj['name2']);
                        }
                } catch(BackendConnectionProblem $e) {}
                
                echo json_encode($aRet);
        break;
        /*
-        * Get all services in the defined BACKEND of the defined HOST
-        */
-       case 'getServices':
-               // These values are submited by WUI requests:
-               // $_GET['backend_id'], $_GET['host_name']
-               
-               // Initialize the backend
-               $BACKEND = new CoreBackendMgmt($CORE);
-               
-               // Do some validations
-               if(!isset($_GET['backend_id']) || $_GET['backend_id'] == '') {
-                       new GlobalMessage('ERROR', 
$CORE->getLang()->getText('mustValueNotSet', 'ATTRIBUTE~ackend_id'));
-               } elseif(!isset($_GET['host_name']) || $_GET['host_name'] == 
'') {
-                       new GlobalMessage('ERROR', 
$CORE->getLang()->getText('mustValueNotSet', 'ATTRIBUTE~host_name'));
-               } 
elseif(!method_exists($BACKEND->BACKENDS[$_GET['backend_id']],'getObjects')) {
-                       new GlobalMessage('ERROR', 
$CORE->getLang()->getText('methodNotSupportedByBackend', 'METHOD~getObjects'));
-               } else {
-                       // Input looks OK, handle the request...
-                       
-                       $aRet = Array();
-                       // Read all services of the given host
-                       
foreach($BACKEND->BACKENDS[$_GET['backend_id']]->getObjects('service',$_GET['host_name'],'')
 AS $arr) {
-                               $aRet[] = Array('host_name' => $arr['name1'], 
'service_description' => $arr['name2']);
-                       }
-                       
-                       echo json_encode($aRet);
-               }
-       break;
-       /*
         * Gets values for the backend options of a defined backend. Needed when
         * editing existing backends
         */


------------------------------------------------------------------------------
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