}
$prefixRow = $prefixRes->fetchRow();
$ndoPrefix = $prefixRow['db_prefix'];
require_once $centreon_path . "GPL_LIB/Smarty/libs/Smarty.class.php";
$path = $centreon_path . "www/widgets/servicegroup-monitoring/src/";
$template = new Smarty();
$template = initSmartyTplForPopup($path, $template, "./", $centreon_path);
$centreon = $_SESSION['centreon'];
$widgetId = $_REQUEST['widgetId'];
$page = $_REQUEST['page'];
$dbb = new CentreonDB("ndo");
$widgetObj = new CentreonWidget($centreon, $db);
$sgMonObj = new ServicegroupMonitoring($dbb);
$preferences = $widgetObj->getWidgetPreferences($widgetId);
$pearDB = $db;
$aclObj = new CentreonACL($centreon->user->user_id, $centreon->user->admin);
$res = $db->query("SELECT `key`, `value` FROM `options` WHERE `key` LIKE 'color%'");
$hostStateColors = array(0 => "#19EE11", 1 => "#F91E05", 2 => "#82CFD8", 4 => "#2AD1D4");
$serviceStateColors = array(0 => "#13EB3A", 1 => "#F8C706", 2 => "#F91D05", 3 => "#DCDADA", 4 => "#2AD1D4");
while ($row = $res->fetchRow()) {
    if ($row['key'] == "color_up") {
        $hostStateColors[0] = $row['value'];
    } elseif ($row['key'] == "color_down") {
        $hostStateColors[1] = $row['value'];
    } elseif ($row['key'] == "color_unreachable") {
        $hostStateColors[2] = $row['value'];
    } elseif ($row['key'] == "color_pending") {
        $hostStateColors[4] = $row['value'];
    } elseif ($row['key'] == "color_ok") {
        $serviceStateColors[0] = $row['value'];
    } elseif ($row['key'] == "color_warning") {
예제 #2
0
    $gmapObj = new centreonGmapBroker($pearDB, $pearDBC);
    $gmapObj->init();
}
/*
 * Analyse User Profile
 */
$session = htmlentities($_GET["session_id"], ENT_QUOTES);
$DBRESULT = $gmapObj->_db->query("SELECT user_id FROM session WHERE session_id = '{$session}'");
$data = $DBRESULT->fetchRow();
$user_id = $data["user_id"];
unset($data);
/*
 * Access Control List
 */
$admin = 0;
$aclObj = new CentreonACL($user_id);
if ($aclObj->admin == 0) {
    // Get Group List
    $accessGroup = $aclObj->getAccessGroups();
    $groupList = "";
    foreach ($accessGroup as $key => $value) {
        if ($groupList != '') {
            $groupList .= ", ";
        }
        $groupList .= "'" . $key . "'";
    }
    $hostGroupList = $aclObj->getHostGroupsString();
} else {
    $admin = 1;
}
/*
 /**
  * Magic method for get/set/add/del relations
  *
  * @param string $name
  * @param array $arg
  * @throws CentreonClapiException
  */
 public function __call($name, $arg)
 {
     $name = strtolower($name);
     if (!isset($arg[0])) {
         throw new CentreonClapiException(self::MISSINGPARAMETER);
     }
     $args = explode($this->delim, $arg[0]);
     $cgIds = $this->object->getIdByParameter($this->object->getUniqueLabelField(), array($args[0]));
     if (!count($cgIds)) {
         throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $args[0]);
     }
     $cgId = $cgIds[0];
     if (preg_match("/^(get|set|add|del)contact\$/", $name, $matches)) {
         $relobj = new Centreon_Object_Relation_Contact_Group_Contact();
         $obj = new Centreon_Object_Contact();
         if ($matches[1] == "get") {
             $tab = $relobj->getTargetIdFromSourceId($relobj->getSecondKey(), $relobj->getFirstKey(), $cgIds);
             echo "id" . $this->delim . "name" . "\n";
             foreach ($tab as $value) {
                 $tmp = $obj->getParameters($value, array($obj->getUniqueLabelField()));
                 echo $value . $this->delim . $tmp[$obj->getUniqueLabelField()] . "\n";
             }
         } else {
             if (!isset($args[1])) {
                 throw new CentreonClapiException(self::MISSINGPARAMETER);
             }
             $relation = $args[1];
             $relations = explode("|", $relation);
             $relationTable = array();
             foreach ($relations as $rel) {
                 $tab = $obj->getIdByParameter($obj->getUniqueLabelField(), array($rel));
                 if (!count($tab)) {
                     throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $rel);
                 }
                 $relationTable[] = $tab[0];
             }
             if ($matches[1] == "set") {
                 $relobj->delete($cgId);
             }
             $existingRelationIds = $relobj->getTargetIdFromSourceId($relobj->getSecondKey(), $relobj->getFirstKey(), array($cgId));
             foreach ($relationTable as $relationId) {
                 if ($matches[1] == "del") {
                     $relobj->delete($cgId, $relationId);
                 } elseif ($matches[1] == "set" || $matches[1] == "add") {
                     if (!in_array($relationId, $existingRelationIds)) {
                         $relobj->insert($cgId, $relationId);
                     }
                 }
             }
             $acl = new CentreonACL();
             $acl->reload(true);
         }
     } else {
         throw new CentreonClapiException(self::UNKNOWN_METHOD);
     }
 }
# Get language
$locale = $oreon->user->get_lang();
putenv("LANG={$locale}");
setlocale(LC_ALL, $locale);
bindtextdomain("messages", $syslog_mod_path . "locale/");
bind_textdomain_codeset("messages", "UTF-8");
textdomain("messages");
/*
 * Get ACL
 */
$pearDB = new CentreonDB();
$pearDBndo = new CentreonDB("ndo");
$sid = session_id($_GET["sid"]);
$contact_id = check_session($sid, $pearDB);
$is_admin = isUserAdmin($sid);
$access = new CentreonACL($contact_id, $is_admin);
$aclHostString = $access->getHostsString("ID", $pearDBndo);
/*
 * Get selected option in lists
 */
if (isset($_GET['collector_id']) && $_GET['collector_id'] != "") {
    $collector_id = $_GET['collector_id'];
} else {
    $collector_id = "";
}
if (isset($_GET['Ffacility']) && $_GET['Ffacility'] != "" && $_GET['Ffacility'] != "undefined") {
    $Ffacility_selected = $_GET['Ffacility'];
} else {
    $Ffacility_selected = "";
}
if (isset($_GET['Fseverity']) && $_GET['Fseverity'] != "" && $_GET['Fseverity'] != "undefined") {
 /**
  * Magic method for get/set/add/del relations
  *
  * @param string $name
  * @param array $arg
  * @throws CentreonClapiException
  */
 public function __call($name, $arg)
 {
     $name = strtolower($name);
     if (!isset($arg[0])) {
         throw new CentreonClapiException(self::MISSINGPARAMETER);
     }
     $args = explode($this->delim, $arg[0]);
     $sgIds = $this->object->getIdByParameter($this->object->getUniqueLabelField(), array($args[0]));
     if (!count($sgIds)) {
         throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $args[0]);
     }
     $sgId = $sgIds[0];
     if (preg_match("/^(get|add|del|set)(service|hostgroupservice)\$/", $name, $matches)) {
         if ($matches[2] == "service") {
             $relobj = new Centreon_Object_Relation_Service_Group_Service();
             $obj = new Centreon_Object_Relation_Host_Service();
             $existingRelationIds = $relobj->getHostIdServiceIdFromServicegroupId($sgId);
             $hstring = "host_id";
         } else {
             $relobj = new Centreon_Object_Relation_Service_Group_Host_Group_Service();
             $obj = new Centreon_Object_Relation_Host_Group_Service();
             $existingRelationIds = $relobj->getHostGroupIdServiceIdFromServicegroupId($sgId);
             $hstring = "hostgroup_id";
         }
         if ($matches[1] == "get") {
             if ($matches[2] == "service") {
                 echo "host id" . $this->delim . "host name" . $this->delim . "service id" . $this->delim . "service description\n";
             } elseif ($matches[2] == "hostgroupservice") {
                 echo "hostgroup id" . $this->delim . "hostgroup name" . $this->delim . "service id" . $this->delim . "service description\n";
             }
             foreach ($existingRelationIds as $val) {
                 if ($matches[2] == "service") {
                     $elements = $obj->getMergedParameters(array('host_name', 'host_id'), array('service_description', 'service_id'), -1, 0, "host_name,service_description", "ASC", array("service_id" => $val['service_id'], "host_id" => $val['host_id']), "AND");
                     if (isset($elements[0])) {
                         echo $elements[0]['host_id'] . $this->delim . $elements[0]['host_name'] . $this->delim . $elements[0]['service_id'] . $this->delim . $elements[0]['service_description'] . "\n";
                     }
                 } else {
                     $elements = $obj->getMergedParameters(array('hg_name', 'hg_id'), array('service_description', 'service_id'), -1, 0, "hg_name,service_description", "ASC", array("service_id" => $val['service_id'], "hg_id" => $val['hostgroup_id']), "AND");
                     if (isset($elements[0])) {
                         echo $elements[0]['hg_id'] . $this->delim . $elements[0]['hg_name'] . $this->delim . $elements[0]['service_id'] . $this->delim . $elements[0]['service_description'] . "\n";
                     }
                 }
             }
         } else {
             if (!isset($args[1])) {
                 throw new CentreonClapiException(self::MISSINGPARAMETER);
             }
             $relation = $args[1];
             $relations = explode("|", $relation);
             $relationTable = array();
             $i = 0;
             foreach ($relations as $rel) {
                 $tmp = explode(",", $rel);
                 if (count($tmp) < 2) {
                     throw new CentreonClapiException(self::MISSINGPARAMETER);
                 }
                 if ($matches[2] == "service") {
                     $elements = $obj->getMergedParameters(array('host_id'), array('service_id'), -1, 0, null, null, array("host_name" => $tmp[0], "service_description" => $tmp[1]), "AND");
                     if (!count($elements)) {
                         throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $tmp[0] . "/" . $tmp[1]);
                     }
                     $relationTable[$i]['host_id'] = $elements[0]['host_id'];
                     $relationTable[$i]['service_id'] = $elements[0]['service_id'];
                 } elseif ($matches[2] == "hostgroupservice") {
                     $elements = $obj->getMergedParameters(array('hg_id'), array('service_id'), -1, 0, null, null, array("hg_name" => $tmp[0], "service_description" => $tmp[1]), "AND");
                     if (!count($elements)) {
                         throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $tmp[0] . "/" . $tmp[1]);
                     }
                     $relationTable[$i]['hostgroup_id'] = $elements[0]['hg_id'];
                     $relationTable[$i]['service_id'] = $elements[0]['service_id'];
                 }
                 $i++;
             }
             if ($matches[1] == "set") {
                 foreach ($existingRelationIds as $key => $existrel) {
                     $relobj->delete($sgId, $existrel[$hstring], $existrel['service_id']);
                     unset($existingRelationIds[$key]);
                 }
             }
             foreach ($relationTable as $relation) {
                 if ($matches[1] == "del") {
                     $relobj->delete($sgId, $relation[$hstring], $relation['service_id']);
                 } elseif ($matches[1] == "add" || $matches[1] == "set") {
                     $insert = true;
                     foreach ($existingRelationIds as $existrel) {
                         if ($existrel[$hstring] == $relation[$hstring] && $existrel['service_id'] == $relation['service_id']) {
                             $insert = false;
                             break;
                         }
                     }
                     if ($insert == true) {
                         $relobj->insert($sgId, $relation[$hstring], $relation['service_id']);
                     }
                 }
             }
             $acl = new CentreonACL();
             $acl->reload(true);
         }
     } else {
         throw new CentreonClapiException(self::UNKNOWN_METHOD);
     }
 }
예제 #6
0
 /**
  * Magic method
  *
  * @param string $name
  * @param array $args
  * @return void
  * @throws CentreonClapiException
  */
 public function __call($name, $arg)
 {
     $name = strtolower($name);
     if (!isset($arg[0])) {
         throw new CentreonClapiException(self::MISSINGPARAMETER);
     }
     $args = explode($this->delim, $arg[0]);
     $hostIds = $this->object->getIdByParameter($this->object->getUniqueLabelField(), array($args[0]));
     if (!count($hostIds)) {
         throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $args[0]);
     }
     $hostId = $hostIds[0];
     if (preg_match("/^(get|set|add|del)([a-zA-Z_]+)/", $name, $matches)) {
         switch ($matches[2]) {
             case "contact":
                 $class = "Centreon_Object_Contact";
                 $relclass = "Centreon_Object_Relation_Contact_Host";
                 break;
             case "contactgroup":
                 $class = "Centreon_Object_Contact_Group";
                 $relclass = "Centreon_Object_Relation_Contact_Group_Host";
                 break;
             case "hostgroup":
                 $class = "Centreon_Object_Host_Group";
                 $relclass = "Centreon_Object_Relation_Host_Group_Host";
                 break;
             case "template":
                 $class = "Centreon_Object_Host";
                 $relclass = "Centreon_Object_Relation_Host_Template_Host";
                 break;
             case "parent":
                 $class = "Centreon_Object_Host";
                 $relclass = "Centreon_Object_Relation_Host_Parent_Host";
                 break;
             case "hostcategory":
                 $class = "Centreon_Object_Host_Category";
                 $relclass = "Centreon_Object_Relation_Host_Category_Host";
                 break;
             default:
                 throw new CentreonClapiException(self::UNKNOWN_METHOD);
                 break;
         }
         if (class_exists($relclass) && class_exists($class)) {
             $relobj = new $relclass();
             $obj = new $class();
             if ($matches[1] == "get") {
                 $tab = $relobj->getTargetIdFromSourceId($relobj->getFirstKey(), $relobj->getSecondKey(), $hostId);
                 echo "id" . $this->delim . "name" . "\n";
                 foreach ($tab as $value) {
                     $tmp = $obj->getParameters($value, array($obj->getUniqueLabelField()));
                     echo $value . $this->delim . $tmp[$obj->getUniqueLabelField()] . "\n";
                 }
             } else {
                 if (!isset($args[1])) {
                     throw new CentreonClapiException(self::MISSINGPARAMETER);
                 }
                 if ($matches[2] == "contact") {
                     $args[1] = str_replace(" ", "_", $args[1]);
                 }
                 $relation = $args[1];
                 $relations = explode("|", $relation);
                 $relationTable = array();
                 foreach ($relations as $rel) {
                     $tab = $obj->getIdByParameter($obj->getUniqueLabelField(), array($rel));
                     if (!count($tab)) {
                         throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $rel);
                     }
                     $relationTable[] = $tab[0];
                 }
                 if ($matches[1] == "set") {
                     $relobj->delete(null, $hostId);
                 }
                 $existingRelationIds = $relobj->getTargetIdFromSourceId($relobj->getFirstKey(), $relobj->getSecondKey(), $hostId);
                 foreach ($relationTable as $relationId) {
                     if ($matches[1] == "del") {
                         $relobj->delete($relationId, $hostId);
                     } elseif ($matches[1] == "set" || $matches[1] == "add") {
                         if (!in_array($relationId, $existingRelationIds)) {
                             $relobj->insert($relationId, $hostId);
                         }
                     }
                 }
                 if ($matches[2] == "hostgroup") {
                     $aclObj = new CentreonACL();
                     $aclObj->reload(true);
                 }
             }
         } else {
             throw new CentreonClapiException(self::UNKNOWN_METHOD);
         }
     } else {
         throw new CentreonClapiException(self::UNKNOWN_METHOD);
     }
 }
 /**
  * Magic method for get/set/add/del relations
  *
  * @param string $name
  * @param array $arg
  */
 public function __call($name, $arg)
 {
     $name = strtolower($name);
     if (!isset($arg[0])) {
         throw new CentreonClapiException(self::MISSINGPARAMETER);
     }
     $args = explode($this->delim, $arg[0]);
     $hcIds = $this->object->getIdByParameter($this->object->getUniqueLabelField(), array($args[0]));
     if (!count($hcIds)) {
         throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $args[0]);
     }
     $categoryId = $hcIds[0];
     if (preg_match("/^(get|add|del)(service|servicetemplate)\$/", $name, $matches)) {
         $obj = new Centreon_Object_Service();
         $relobj = new Centreon_Object_Relation_Service_Category_Service();
         $hostServiceRel = new Centreon_Object_Relation_Host_Service();
         if ($matches[1] == "get") {
             $tab = $relobj->getTargetIdFromSourceId($relobj->getSecondKey(), $relobj->getFirstKey(), $hcIds);
             if ($matches[2] == "servicetemplate") {
                 echo "template id" . $this->delim . "service template description\n";
             } elseif ($matches[2] == "service") {
                 echo "host id" . $this->delim . "host name" . $this->delim . "service id" . $this->delim . "service description\n";
             }
             foreach ($tab as $value) {
                 $p = $obj->getParameters($value, array('service_description', 'service_register'));
                 if ($p['service_register'] == 1 && $matches[2] == "service") {
                     $elements = $hostServiceRel->getMergedParameters(array('host_name', 'host_id'), array('service_description'), -1, 0, "host_name,service_description", "ASC", array("service_id" => $value), "AND");
                     if (isset($elements[0])) {
                         echo $elements[0]['host_id'] . $this->delim . $elements[0]['host_name'] . $this->delim . $value . $this->delim . $elements[0]['service_description'] . "\n";
                     }
                 } elseif ($p['service_register'] == 0 && $matches[2] == "servicetemplate") {
                     echo $value . $this->delim . $p['service_description'] . "\n";
                 }
             }
         } else {
             if (!isset($args[1])) {
                 throw new CentreonClapiException(self::MISSINGPARAMETER);
             }
             $relation = $args[1];
             $relations = explode("|", $relation);
             $relationTable = array();
             foreach ($relations as $rel) {
                 if ($matches[2] == "service") {
                     $tmp = explode(",", $rel);
                     if (count($tmp) < 2) {
                         throw new CentreonClapiException(self::MISSINGPARAMETER);
                     }
                     $elements = $hostServiceRel->getMergedParameters(array('host_id'), array('service_id'), -1, 0, null, null, array("host_name" => $tmp[0], "service_description" => $tmp[1]), "AND");
                     if (!count($elements)) {
                         throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $tmp[0] . "/" . $tmp[1]);
                     }
                     $relationTable[] = $elements[0]['service_id'];
                 } elseif ($matches[2] == "servicetemplate") {
                     $tab = $obj->getList("service_id", -1, 0, null, null, array('service_description' => $rel, 'service_register' => 0), "AND");
                     if (!count($tab)) {
                         throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $rel);
                     }
                     $relationTable[] = $tab[0]['service_id'];
                 }
             }
             $existingRelationIds = $relobj->getTargetIdFromSourceId($relobj->getSecondKey(), $relobj->getFirstKey(), array($categoryId));
             foreach ($relationTable as $relationId) {
                 if ($matches[1] == "del") {
                     $relobj->delete($categoryId, $relationId);
                 } elseif ($matches[1] == "add") {
                     if (!in_array($relationId, $existingRelationIds)) {
                         $relobj->insert($categoryId, $relationId);
                     }
                 }
             }
             $acl = new CentreonACL();
             $acl->reload(true);
         }
     } else {
         throw new CentreonClapiException(self::UNKNOWN_METHOD);
     }
 }
require_once $centreon_path . 'www/class/centreonDB.class.php';
require_once $centreon_path . 'www/class/centreonWidget.class.php';
session_start();
if (!isset($_SESSION['centreon']) || !isset($_REQUEST['widgetId'])) {
    print "DDD";
    exit;
}
$centreon = $_SESSION['centreon'];
$widgetId = $_REQUEST['widgetId'];
try {
    global $pearDB;
    $db = new CentreonDB();
    $db2 = new CentreonDB("centstorage");
    $pearDB = $db;
    if ($centreon->user->admin == 0) {
        $access = new CentreonACL($centreon->user->get_id());
        $grouplist = $access->getAccessGroups();
        $grouplistStr = $access->getAccessGroupsString();
    }
    $widgetObj = new CentreonWidget($centreon, $db);
    $preferences = $widgetObj->getWidgetPreferences($widgetId);
    $autoRefresh = 0;
    if (isset($preferences['refresh_interval'])) {
        $autoRefresh = $preferences['refresh_interval'];
    }
} catch (Exception $e) {
    echo $e->getMessage() . "<br/>";
    exit;
}
?>
<html>
예제 #9
0
        $labels .= "'" . trim($p) . "'";
    }
    $query2 = "SELECT sc_id FROM service_categories WHERE sc_name IN (" . $labels . ")";
    $RES = $db->query($query2);
    $idC = "";
    while ($d1 = $RES->fetchRow()) {
        if ($idC != '') {
            $idC .= ",";
        }
        $idC .= $d1['sc_id'];
    }
    $query .= " AND cv2.`value` IN ({$idC}) ";
}
if (!$centreon->user->admin) {
    $pearDB = $db;
    $aclObj = new CentreonACL($centreon->user->user_id, $centreon->user->admin);
    $groupList = $aclObj->getAccessGroupsString();
    $query .= " AND h.host_id = acl.host_id\n\tAND acl.service_id = s.service_id\n\tAND acl.group_id IN ({$groupList})";
}
if (isset($preferences['output_search']) && $preferences['output_search'] != "") {
    $tab = split(" ", $preferences['output_search']);
    $op = $tab[0];
    if (isset($tab[1])) {
        $search = $tab[1];
    }
    if ($op && isset($search) && $search != "") {
        $query = CentreonUtils::conditionBuilder($query, "s.output " . CentreonUtils::operandToMysqlFormat($op) . " '" . $dbb->escape($search) . "' ");
    }
}
if (isset($preferences['ticket_id_search']) && $preferences['ticket_id_search'] != "") {
    $query .= " AND (mop1.ticket_value LIKE '" . $dbb->escape($preferences['ticket_id_search']) . "' OR mop2.ticket_value LIKE '" . $dbb->escape($preferences['ticket_id_search']) . "') ";
$pearDBD = new CentreonDB("centstorage");
$sid = CentreonDB::escape($sid);
/* Check if session is initialised */
$res = $pearDB->query("SELECT s.user_id, c.contact_admin FROM session s, contact c WHERE s.user_id = c.contact_id AND s.session_id = '" . $sid . "'");
if (PEAR::isError($res)) {
    sendJson("Internal Server Error", 500);
}
$row = $res->fetchRow();
if (is_null($row)) {
    sendJson("Forbidden access", 403);
}
$isAdmin = $row['contact_admin'];
$userId = $row['user_id'];
/* Get ACL if user is not admin */
if (!$isAdmin) {
    $acl = new CentreonACL($userId, $isAdmin);
    $aclGroups = $acl->getAccessGroupsString();
}
/* Validate options */
if (false === isset($_GET['start']) || false === is_numeric($_GET['start']) || false === isset($_GET['end']) || false === is_numeric($_GET['end'])) {
    sendJson("Bad Request", 400);
}
$start = $_GET['start'];
$end = $_GET['end'];
$rows = 200;
if (isset($_GET['rows'])) {
    if (false === is_numeric($_GET['rows'])) {
        sendJson("Bad Request", 400);
    }
    $rows = $_GET['rows'];
}
예제 #11
0
 * Set language
 */
$locale = $oreon->user->get_lang();
putenv("LANG={$locale}");
setlocale(LC_ALL, $locale);
bindtextdomain("messages", $syslog_mod_path . "locale/");
bind_textdomain_codeset("messages", "UTF-8");
textdomain("messages");
/*
 * Get ACL
 */
$pearDB = new CentreonDB();
$pearDBndo = new CentreonDB("ndo");
$contact_id = check_session($sid, $pearDB);
$is_admin = isUserAdmin($sid);
$access = new CentreonACL($contact_id, $is_admin);
$aclHostString = $access->getHostsString("ID", $pearDBndo);
$aclHostGroups = $access->getHostGroups();
# Pagination
include "./include/common/autoNumLimit.php";
/*
 * Pear library
 */
require_once "HTML/QuickForm.php";
require_once 'HTML/QuickForm/advmultiselect.php';
require_once 'HTML/QuickForm/Renderer/ArraySmarty.php';
/*
 * PHP functions
 */
require_once $syslog_mod_path . "include/common/common-Func.php";
require_once "./include/common/common-Func.php";
 /**
  * Get Service States
  *
  * @param string $sgName
  * @param int $detailFlag
  * @param int $admin
  * @param CentreonACL $aclObj
  * @param array $preferences
  * @param bool $isNdo
  * @param string $ndoPrefix
  * @return string
  */
 public function getServiceStates($sgName, $detailFlag = false, $admin, $aclObj, $preferences, $isNdo = false, $ndoPrefix = "nagios_")
 {
     if ($isNdo == false) {
         $query = "SELECT DISTINCT h.host_id, s.state, h.name, s.service_id, s.description, ssg.servicegroup_id\n                      FROM `services_servicegroups` ssg, `services` s, `hosts` h, `servicegroups` sg ";
         if (!$admin) {
             $query .= ", centreon_acl acl ";
         }
         $query .= "WHERE h.host_id = s.host_id\n                       AND h.name NOT LIKE '_Module_%'\n                       AND s.enabled = 1\n                       AND s.host_id = ssg.host_id\n                       AND ssg.service_id = s.service_id\n                       AND ssg.servicegroup_id = sg.servicegroup_id\n                       AND sg.name = '" . $this->dbb->escape($sgName) . "' ";
         if (!$admin) {
             $query .= " AND h.host_id = acl.host_id\n                            AND acl.service_id = s.service_id ";
             $query .= " AND acl.group_id IN (" . $aclObj->getAccessGroupsString() . ") ";
         }
         $query .= " ORDER BY h.name ";
     } else {
         $query = "SELECT DISTINCT h.host_id, ss.current_state as state, h.display_name as name, \n                                      s.service_id, s.display_name as description, ssg.servicegroup_id\n                      FROM `{$ndoPrefix}servicegroup_members` ssg, `{$ndoPrefix}hosts` h, `{$ndoPrefix}services` s,\n                           `{$ndoPrefix}servicestatus` ss, `{$ndoPrefix}servicegroups` sg, `{$ndoPrefix}objects` o ";
         if (!$admin) {
             $query .= ", centreon_acl acl ";
         }
         $query .= "WHERE h.host_object_id = s.host_object_id\n                       AND s.service_object_id = ss.service_object_id\n                       AND h.display_name NOT LIKE '_Module_%'                       \n                       AND s.service_object_id = ssg.service_object_id\n                       AND ssg.servicegroup_id = sg.servicegroup_id\n                       AND sg.servicegroup_object_id = o.object_id\n                       AND s.config_type = 0\n                       AND o.name1 = '" . $this->dbb->escape($sgName) . "' ";
         if (!$admin) {
             $query .= " AND h.display_name = acl.host_name\n                            AND acl.service_description = s.display_name ";
             $query .= " AND acl.group_id IN (" . $aclObj->getAccessGroupsString() . ") ";
         }
         $query .= " ORDER BY h.display_name ";
     }
     $res = $this->dbb->query($query);
     $tab = array();
     $detailTab = array();
     while ($row = $res->fetchRow()) {
         if (!isset($tab[$row['state']])) {
             $tab[$row['state']] = 0;
         }
         if (!isset($detailTab[$row['host_id']])) {
             $detailTab[$row['host_id']] = array();
         }
         if (isset($detailTab[$row['name']]) && !isset($detailTab[$row['name']][$row['service_id']])) {
             $detailTab[$row['host_id']][$row['service_id']] = array();
         }
         foreach ($row as $key => $val) {
             $detailTab[$row['host_id']][$row['service_id']][$key] = $val;
         }
         $tab[$row['state']]++;
     }
     if ($detailFlag == true) {
         return $detailTab;
     }
     return $tab;
 }
$orderby = "name ASC";
if (isset($preferences['order_by']) && $preferences['order_by'] != "") {
    $orderby = $preferences['order_by'];
}
$start = time() - $preferences['log_period'];
$end = time();
$query = "SELECT SQL_CALC_FOUND_ROWS * FROM logs WHERE ctime > '{$start}' AND ctime <= '{$end}' {$msg_req}";
$query .= " ORDER BY ctime DESC, host_name ASC, log_id DESC, service_description ASC";
$query .= " LIMIT " . $page * $preferences['entries'] . "," . $preferences['entries'];
$res = $dbb->query($query);
$nbRows = $dbb->numberRows();
$data = array();
$outputLength = $preferences['output_length'] ? $preferences['output_length'] : 50;
if (!$centreon->user->admin) {
    $pearDB = $db;
    $aclObj = new CentreonACL($centreon->user->get_id(), $centreon->user->get_admin());
    $lca = array("LcaHost" => $aclObj->getHostServices($dbb, null, 1));
}
while ($row = $res->fetchRow()) {
    if (!$centreon->user->admin) {
        $continue = true;
        if (isset($row['host_id']) && isset($lca['LcaHost'][$row['host_id']])) {
            $continue = false;
        } elseif (isset($row['host_id']) && isset($row['service_description'])) {
            foreach ($lca['LcaHost'][$row['host_id']] as $key => $value) {
                if ($value == $row['service_description']) {
                    $continue = false;
                }
            }
        }
        if ($continue == true) {