header('Content-Type: text/xml');
    header('Pragma: no-cache');
    header('Expires: 0');
    header('Cache-Control: no-cache, must-revalidate');
    $buffer = new SyslogXML();
    $buffer->startElement("error");
    $buffer->writeElement("msg", _("Please select a collector."));
    $buffer->endElement();
    $buffer->output();
    exit;
}
/*
 * Build SQL request
 */
$pearDB = new syslogDB("centreon");
$pearDB_syslog = new SyslogDB("syslog", $collector_id);
$cfg_syslog = getSyslogOption($collector_id);
$sql_filter = array();
if (isset($_GET['program']) && $_GET['program'] != "" && $_GET['program'] != "undefined") {
    array_push($sql_filter, " (program = '" . htmlentities($_GET['program'], ENT_QUOTES) . "') ");
}
if (isset($_GET['hostgroup']) && $_GET['hostgroup'] != "" && $_GET['hostgroup'] != "undefined") {
    array_push($sql_filter, " (host IN (" . getSyslogHostFromHostgroups($_GET['hostgroup']) . ")) ");
} else {
    if (isset($_GET['host']) && $_GET['host'] != "" && $_GET['host'] != "undefined") {
        array_push($sql_filter, " (host IN (" . getSyslogHostFromCentreon($_GET['host']) . ")) ");
    } else {
        if ($is_admin) {
            array_push($sql_filter, " (host IN (" . getFullSyslogHostFromCentreon($collector_id, $aclHostString) . ")) ");
        } else {
            array_push($sql_filter, " (host IN (" . getAllSyslogHostFromCentreon($collector_id, $aclHostString) . ")) ");
 */
//ini_set("display_errors", "Off");
include "@CENTREON_ETC@centreon.conf.php";
require_once $centreon_path . "www/modules/centreon-syslog-frontend/include/common/header.php";
/*
 * Common functions
 */
require_once $syslog_mod_path . 'class/syslogDB.class.php';
require_once $syslog_mod_path . 'class/syslogXML.class.php';
require_once $syslog_mod_path . 'include/common/common-Func.php';
require_once $centreon_path . 'www/include/common/common-Func.php';
/*
 * Build PEAR DB object
 */
if (isset($_GET['collector']) && $_GET['collector'] != "") {
    $pearSyslogDB = new SyslogDB("syslog", $_GET['collector']);
} else {
    exit(1);
}
/*
 * Database retrieve information for Centreon-Syslog
 */
$cfg_syslog = getSyslogOption($_GET['collector']);
if (isset($_GET['type']) && $_GET['type'] != "") {
    $type = $_GET['type'];
}
/*
 * Get filters
 */
$sql_filter = array();
if (isset($_GET['program']) && $_GET['program'] != "") {
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";
/*
 * Database retrieve information for Centreon-Syslog
 */
$pearCentreonDB = new SyslogDB("centreon");
$collectorList = getCollectorList();
# QuickSearch form
include_once "./include/common/quickSearch.php";
# Set limit & num
$DBRESULT =& $pearCentreonDB->query("SELECT maxViewMonitoring FROM general_opt LIMIT 1");
if (PEAR::isError($DBRESULT)) {
    # For Centreon 2.1 compatibility
    $DBRESULT =& $pearCentreonDB->query("SELECT `value` FROM options WHERE `key`=\"maxViewMonitoring\" LIMIT 1");
    $row = $DBRESULT->fetchRow();
    $gopt = $row["value"];
    if (PEAR::isError($DBRESULT)) {
        print "Mysql Error : " . $DBRESULT->getMessage() . "\n";
    }
} else {
    $gopt = array_map("myDecode", $DBRESULT->fetchRow());
require_once $syslog_mod_path . "/include/common/common-Func.php";
require_once $syslog_mod_path . "class/syslogDB.class.php";
/*
 * Get host name and IP address
 */
$tab_host = explode(";", $_GET["hosts"]);
print_r($tab_host);
foreach ($tab_host as $host) {
    $hostAndIP = split("::", $host);
    if (isset($_GET['collector_id']) && $_GET['collector_id'] != "") {
        $collector_id = $_GET['collector_id'];
    }
    $hostname = $hostAndIP[0];
    $hostIP = $hostAndIP[1];
    $value = _("no IP");
    if (strcmp($hostIP, $value) == 0) {
        $hostIP = "0.0.0.0";
    }
    /*
     * Insert into Database informations
     */
    $pearCentreonDB = new SyslogDB("centreon");
    $DBRESULT =& $pearCentreonDB->query("SELECT `host_id` FROM `host` WHERE `host_address` = '" . $hostIP . "' OR `host_name` LIKE '%" . $hostname . "%' OR `host_alias` LIKE '%" . $hostname . "%'");
    $result = $DBRESULT->fetchRow();
    if ($DBRESULT->numRows() == 1) {
        $query = "INSERT INTO mod_syslog_hosts (id, collector_id, host_centreon_id, host_syslog_name, host_syslog_ipv4, state) VALUES ('', {$collector_id}, '" . $result["host_id"] . "', '" . $hostname . "', '" . $hostIP . "', '1');";
    } else {
        $query = "INSERT INTO mod_syslog_hosts (id, collector_id, host_centreon_id, host_syslog_name, host_syslog_ipv4, state) VALUES ('', {$collector_id}, NULL, '" . $hostname . "', '" . $hostIP . "', '2');";
    }
    $pearCentreonDB->query($query);
}