Changeset 5744

Show
Ignore:
Timestamp:
07/18/08 12:07:11 (5 months ago)
Author:
shotamchay
Message:

fulfills task #80 and request #71, has yet to be tested

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/centreon/www/include/configuration/configObject/host/DB-Func.php

    r5736 r5744  
    582582        } 
    583583         
     584        /* 
     585         *      this function cleans all the services that were linked to the removed host template   
     586         */ 
     587        function deleteHostServiceMultiTemplate($hID, $scndHID){ 
     588                global $pearDB, $path, $oreon; 
     589         
     590                $DBRESULT3 =& $pearDB->query("SELECT service_service_id " . 
     591                                                                "FROM `service` svc, `host_service_relation` hsr " . 
     592                                                                "WHERE svc.service_id = hsr.service_service_id " . 
     593                                                                "AND svc.service_register = '0' " . 
     594                                                                "AND hsr.host_host_id = '" . $scndHID . "'"); 
     595                if (PEAR::isError($DBRESULT3)) 
     596                        print "DB Error : ".$DBRESULT3->getDebugInfo()."<br />"; 
     597                while ($svcID =& $DBRESULT3->fetchRow()) { 
     598                        $rq2 = "DELETE hsr, svc FROM `host_service_relation` hsr, `service` svc " . 
     599                                "WHERE hsr.service_service_id = svc.service_id " . 
     600                                "AND svc.service_template_model_stm_id = '".$svcID['service_service_id']."' " . 
     601                                "AND hsr.host_host_id = '".$hID."'"; 
     602                        $DBRESULT4 =& $pearDB->query($rq2); 
     603                        if (PEAR::isError($DBRESULT4)) 
     604                                print "DB Error : ".$DBRESULT4->getDebugInfo()."<br />"; 
     605                } 
     606                 
     607                $rq = "SELECT host_tpl_id " . 
     608                                "FROM host_template_relation " . 
     609                                "WHERE host_host_id = '".$scndHID."' " . 
     610                                "ORDER BY `order`"; 
     611                                 
     612                $DBRESULT =& $pearDB->query($rq);                
     613                if (PEAR::isError($DBRESULT)) 
     614                        print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; 
     615                while ($result =& $DBRESULT->fetchRow()) { 
     616                        $DBRESULT2 =& $pearDB->query("SELECT service_service_id " . 
     617                                                                        "FROM `service` svc, `host_service_relation` hsr " . 
     618                                                                        "WHERE svc.service_id = hsr.service_service_id " . 
     619                                                                        "AND svc.service_register = '0' " . 
     620                                                                        "AND hsr.host_host_id = '" . $result["host_tpl_id"] . "'"); 
     621                        if (PEAR::isError($DBRESULT2)) 
     622                                print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 
     623                        while ($svcID =& $DBRESULT2->fetchRow()) { 
     624                                $rq2 = "DELETE hsr, svc FROM `host_service_relation` hsr, `service` svc " . 
     625                                                "WHERE hsr.service_service_id = svc.service_id " . 
     626                                                "AND svc.service_template_model_stm_id = '".$svcID['service_service_id']."' " . 
     627                                                "AND hsr.host_host_id = '".$hID."'"; 
     628                                $DBRESULT4 =& $pearDB->query($rq2); 
     629                                if (PEAR::isError($DBRESULT4)) 
     630                                        print "DB Error : ".$DBRESULT4->getDebugInfo()."<br />"; 
     631                        } 
     632                        deleteHostServiceMultiTemplate($hID, $result["host_tpl_id"]); 
     633                }        
     634        } 
     635         
    584636        function updateHost($host_id = null, $from_MC = false)  { 
    585637                if (!$host_id) return; 
     
    695747                 *  Update multiple templates             
    696748                 */ 
    697                 if (isset($_POST['nbOfSelect'])) {                       
     749                if (isset($_POST['nbOfSelect'])) { 
    698750                        $already_stored = array(); 
     751                         
     752                         
     753                        $oldTp = array(); 
     754                        $newTp = array();                        
     755                        $DBRESULT =& $pearDB->query("SELECT `host_tpl_id` FROM `host_template_relation` WHERE `host_host_id`='".$host_id."'"); 
     756                        if (PEAR::isError($DBRESULT)) 
     757                                print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; 
     758                        while ($hst =& $DBRESULT->fetchRow()) 
     759                                $oldTp[$hst["host_tpl_id"]] = $hst["host_tpl_id"];                       
     760                        for ($i=0;$i <= $_POST['nbOfSelect']; $i++) 
     761                        { 
     762                                $tpSelect = "tpSelect_" . $i; 
     763                                $newTp[$_POST[$tpSelect]] = 1; 
     764                        } 
     765                        foreach ($oldTp as $val) 
     766                        { 
     767                                /* 
     768                                 * if not set, then that means a template was removed 
     769                                 * we will have to remove the services that were linked to that host template as well   
     770                                 */ 
     771                                if (!isset($newTp[$val])) { 
     772                                        deleteHostServiceMultiTemplate($host_id, $val); 
     773                                } 
     774                        } 
     775                         
    699776                        $DBRESULT =& $pearDB->query("DELETE FROM `host_template_relation` WHERE `host_host_id`='".$host_id."'"); 
    700                                  
     777                        if (PEAR::isError($DBRESULT)) 
     778                                print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; 
    701779                        for ($i=0, $j = 1;$i <= $_POST['nbOfSelect']; $i++) 
    702780                        {