<commit_before><?php
/*
 * Copyright 2005-2011 MERETHIS
 * Centreon is developped by : <NAME> and <NAME> under
 * GPL Licence 2.0.
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation ; either version 2 of the License.
 *
 * 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, see <http://www.gnu.org/licenses>.
 *
 * Linking this program statically or dynamically with other modules is making a
 * combined work based on this program. Thus, the terms and conditions of the GNU
 * General Public License cover the whole combination.
 *
 * As a special exception, the copyright holders of this program give MERETHIS
 * permission to link this program with independent modules to produce an executable,
 * regardless of the license terms of these independent modules, and to copy and
 * distribute the resulting executable under terms of MERETHIS choice, provided that
 * MERETHIS also meet, for each linked independent module, the terms  and conditions
 * of the license of that module. An independent module is a module which is not
 * derived from this program. If you modify this program, you may extend this
 * exception to your version of the program, but you are not obliged to do so. If you
 * do not wish to do so, delete this exception statement from your version.
 *
 * For more information : <EMAIL>
 *
 * SVN : $URL$
 * SVN : $Id$
 *
 */

	if (!isset($oreon)) {
		exit();
	}

	include_once $centreon_path."www/class/centreonGMT.class.php";

	include("./include/common/autoNumLimit.php");

	if (isset($_POST["search_service"]))
	  	$search_service = $_POST["search_service"];
	else if (isset($_GET["search_service"]))
	  	$search_service = $_GET["search_service"];
	else
	  	$search_service = NULL;

	if (isset($_POST["search_host"]))
		$host_name = $_POST["search_host"];
	else if (isset($_GET["search_host"]))
		$host_name = $_GET["search_host"];
	else
		$host_name = NULL;

	if (isset($_POST["search_output"]))
		$search_output = $_POST["search_output"];
	else if (isset($_GET["search_output"]))
		$search_output = $_GET["search_output"];
	else
		$search_output = NULL;

	if (isset($_POST["view_all"]))
		$view_all = 1;
	else if (isset($_GET["view_all"]) && !isset($_POST["SearchB"]))
		$view_all = 1;
	else
		$view_all = 0;

	if (isset($_POST["view_downtime_cycle"]))
		$view_downtime_cycle = 1;
	else if (isset($_GET["view_downtime_cycle"]) && !isset($_POST["SearchB"]))
		$view_downtime_cycle = 1;
	else
		$view_downtime_cycle = 0;

	if (isset($_POST["search_author"]))
		$search_author = $_POST["search_author"];
	else if (isset($_GET["search_author"]) && !isset($_POST["SearchB"]))
		$search_author = $_GET["search_author"];
	else
		$search_author = NULL;
	
	/*
	 * Init GMT class
	 */
	$centreonGMT = new CentreonGMT($pearDB);
	$centreonGMT->getMyGMTFromSession(session_id(), $pearDB);

	include_once("./class/centreonDB.class.php");

	if ($oreon->broker->getBroker() == "ndo") {
		$pearDBndo = new CentreonDB("ndo");
		$ndo_base_prefix = getNDOPrefix();
	} else {
	    $pearDBndo = new CentreonDB("centstorage");
	}

	/*
	 * Smarty template Init
	 */
	$tpl = new Smarty();
	$tpl = initSmartyTpl($path, $tpl, "template/");

	/*
	 * Pear library
	 */
	require_once "HTML/QuickForm.php";
	require_once 'HTML/QuickForm/advmultiselect.php';
	require_once 'HTML/QuickForm/Renderer/ArraySmarty.php';

	$form = new HTML_QuickForm('select_form', 'GET', "?p=".$p);

	$tab_downtime_svc = array();

	/*
	 * Service Downtimes
	 */
	if ($view_all == 1) {
		$downtimeTable = "downtimehistory";
		if ($oreon->broker->getBroker() == "ndo") {
		    $extrafields = ", UNIX_TIMESTAMP(dtm.actual_end_time) as actual_end_time, was_cancelled ";
		} else {
		    $extrafields = ", actual_end_time, cancelled as was_cancelled ";
		}
	} else {
		$downtimeTable = "scheduleddowntime";
		$extrafields = "";
	}
	if ($oreon->broker->getBroker() == "ndo") {
		if ($is_admin) {
			$request =	"SELECT SQL_CALC_FOUND_ROWS DISTINCT dtm.internal_downtime_id, unix_timestamp(dtm.entry_time), dtm.duration, dtm.author_name, dtm.comment_data, dtm.is_fixed, unix_timestamp(dtm.scheduled_start_time) AS scheduled_start_time, unix_timestamp(dtm.scheduled_end_time) AS scheduled_end_time, obj.name1 host_name, obj.name2 service_description, was_started " . $extrafields .
					"FROM ".$ndo_base_prefix.$downtimeTable." dtm, ".$ndo_base_prefix."objects obj " .
					"WHERE obj.name1 IS NOT NULL " .
					"AND obj.name2 IS NOT NULL " .
					"AND obj.object_id = dtm.object_id ";
			$request .= (isset($search_service) && $search_service != "" ? "AND obj.name2 LIKE '%$search_service%' " : "") .
					(isset($host_name) && $host_name != "" ? "AND obj.name1 LIKE '%$host_name%' " : "") .
					(isset($search_output) && $search_output != "" ? "AND dtm.comment_data LIKE '%$search_output%' " : "") .
					(isset($search_author) && $search_author != "" ? " AND dtm.author_name LIKE '%$search_author%'" : "") .
					(isset($view_downtime_cycle) && $view_downtime_cycle == 0 ? " AND dtm.comment_data NOT LIKE '%Downtime cycle%' " : "") .	
					(isset($view_all) && $view_all == 0 ? "AND dtm.scheduled_end_time > '".date("Y-m-d G:i:s", time())."' " : "") .
					"ORDER BY dtm.actual_start_time DESC " .
					"LIMIT ".$num * $limit.", ".$limit;
		} else {
			$request =	"SELECT SQL_CALC_FOUND_ROWS DISTINCT dtm.internal_downtime_id, unix_timestamp(dtm.entry_time), dtm.duration, dtm.author_name, dtm.comment_data, dtm.is_fixed, unix_timestamp(dtm.scheduled_start_time) AS scheduled_start_time, unix_timestamp(dtm.scheduled_end_time) AS scheduled_end_time, obj.name1 host_name, obj.name2 service_description, was_started " . $extrafields .
					"FROM ".$ndo_base_prefix.$downtimeTable." dtm, ".$ndo_base_prefix."objects obj, centreon_acl " .
					"WHERE obj.name1 IS NOT NULL " .
					"AND obj.name2 IS NOT NULL " .
					"AND obj.object_id = dtm.object_id " .
					"AND obj.name1 = centreon_acl.host_name ";
			$request .= (isset($search_service) && $search_service != "" ? "AND obj.name2 LIKE '%$search_service%' " : "") .
					(isset($host_name) && $host_name != "" ? "AND obj.name1 LIKE '%$host_name%' " : "") .
					(isset($search_output) && $search_output != "" ? "AND dtm.comment_data LIKE '%$search_output%' " : "") .
					(isset($search_author) && $search_author != "" ? " AND dtm.author_name LIKE '%$search_author%'" : "") .
					(isset($view_downtime_cycle) && $view_downtime_cycle == 0 ? " AND dtm.comment_data NOT LIKE '%Downtime cycle%' " : "") .
					"AND obj.name2 = centreon_acl.service_description " .
					"AND centreon_acl.group_id IN (".$oreon->user->access->getAccessGroupsString().") " .
					(isset($view_all) && $view_all == 0 ? "AND dtm.scheduled_end_time > '".date("Y-m-d G:i:s", time())."' " : "") .
					"ORDER BY dtm.actual_start_time DESC " .
					"LIMIT ".$num * $limit.", ".$limit;
		}
		$DBRESULT_NDO = $pearDBndo->query($request);
		$rows = $pearDBndo->numberRows();
		for ($i = 0; $data = $DBRESULT_NDO->fetchRow(); $i++) {
			$tab_downtime_svc[$i] = $data;
			$tab_downtime_svc[$i]["comment_data"] = trim($data['comment_data']);
			$tab_downtime_svc[$i]["scheduled_start_time"] = $centreonGMT->getDate("m/d/Y H:i" , $tab_downtime_svc[$i]["scheduled_start_time"])." ";
			$tab_downtime_svc[$i]["scheduled_end_time"] = $centreonGMT->getDate("m/d/Y H:i" , $tab_downtime_svc[$i]["scheduled_end_time"])." ";
			$tab_downtime_svc[$i]["host_name_link"] = urlencode($tab_downtime_svc[$i]["host_name"]);
		}
		unset($data);
	} else {
        $request =  "SELECT SQL_CALC_FOUND_ROWS d.internal_id as internal_downtime_id,
                    d.entry_time, duration, d.author as author_name, d.comment_data,
                    d.fixed as is_fixed, d.start_time as scheduled_start_time, d.end_time as scheduled_end_time,
                    d.started as was_started, h.name as host_name, s.description as service_description " . $extrafields .
                    "FROM downtimes d, services s, hosts h " .
                    "WHERE d.host_id  = h.host_id " .
                    "AND d.service_id = s.service_id " .
                    "AND s.enabled = 1 ";
        if (!$view_all) {
            $request .= " AND d.cancelled = 0 ";
        }
        if (!$is_admin) {
            $request .= " AND EXISTS(SELECT 1 FROM centreon_acl WHERE s.host_id = centreon_acl.host_id AND s.service_id = centreon_acl.service_id AND group_id IN (" . $oreon->user->access->getAccessGroupsString() . ")) ";
        }
        $request .= (isset($search_service) && $search_service != "" ? "AND s.description LIKE '%$search_service%' " : "") .
                    (isset($host_name) && $host_name != "" ? "AND h.name LIKE '%$host_name%' " : "") .
                    (isset($search_output) && $search_output != "" ? "AND d.comment_data LIKE '%$search_output%' " : "") .
                    (isset($view_all) && $view_all == 0 ? "AND d.end_time > '".time()."' " : "") .
                    (isset($view_downtime_cycle) && $view_downtime_cycle == 0 ? " AND d.comment_data NOT LIKE '%Downtime cycle%' " : "") .
                    (isset($search_author) && $search_author != "" ? " AND d.author LIKE '%$search_author%'" : "") .
                    "ORDER BY d.start_time DESC " .
                    "LIMIT ".$num * $limit.", ".$limit;
		$DBRESULT_NDO = $pearDBndo->query($request);
		$rows = $pearDBndo->numberRows();
		for ($i = 0; $data = $DBRESULT_NDO->fetchRow(); $i++) {
			$tab_downtime_svc[$i] = $data;
            $tab_downtime_svc[$i]['comment_data'] = htmlentities(trim($data['comment_data']));
			$tab_downtime_svc[$i]['host_name'] = htmlentities($data['host_name']);
			$tab_downtime_svc[$i]['service_description'] = htmlentities($data['service_description']);
			$tab_downtime_svc[$i]["scheduled_start_time"] = $centreonGMT->getDate("m/d/Y H:i" , $tab_downtime_svc[$i]["scheduled_start_time"])." ";
			$tab_downtime_svc[$i]["scheduled_end_time"] = $centreonGMT->getDate("m/d/Y H:i" , $tab_downtime_svc[$i]["scheduled_end_time"])." ";<commit_msg>Fix #5943<commit_after><?php
/*
 * Copyright 2005-2011 MERETHIS
 * Centreon is developped by : <NAME> and <NAME> under
 * GPL Licence 2.0.
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation ; either version 2 of the License.
 *
 * 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, see <http://www.gnu.org/licenses>.
 *
 * Linking this program statically or dynamically with other modules is making a
 * combined work based on this program. Thus, the terms and conditions of the GNU
 * General Public License cover the whole combination.
 *
 * As a special exception, the copyright holders of this program give MERETHIS
 * permission to link this program with independent modules to produce an executable,
 * regardless of the license terms of these independent modules, and to copy and
 * distribute the resulting executable under terms of MERETHIS choice, provided that
 * MERETHIS also meet, for each linked independent module, the terms  and conditions
 * of the license of that module. An independent module is a module which is not
 * derived from this program. If you modify this program, you may extend this
 * exception to your version of the program, but you are not obliged to do so. If you
 * do not wish to do so, delete this exception statement from your version.
 *
 * For more information : <EMAIL>
 *
 * SVN : $URL$
 * SVN : $Id$
 *
 */

	if (!isset($oreon)) {
		exit();
	}

	include_once $centreon_path."www/class/centreonGMT.class.php";

	include("./include/common/autoNumLimit.php");

	if (isset($_POST["search_service"]))
	  	$search_service = $_POST["search_service"];
	else if (isset($_GET["search_service"]))
	  	$search_service = $_GET["search_service"];
	else
	  	$search_service = NULL;

	if (isset($_POST["search_host"]))
		$host_name = $_POST["search_host"];
	else if (isset($_GET["search_host"]))
		$host_name = $_GET["search_host"];
	else
		$host_name = NULL;

	if (isset($_POST["search_output"]))
		$search_output = $_POST["search_output"];
	else if (isset($_GET["search_output"]))
		$search_output = $_GET["search_output"];
	else
		$search_output = NULL;

	if (isset($_POST["view_all"]))
		$view_all = 1;
	else if (isset($_GET["view_all"]) && !isset($_POST["SearchB"]))
		$view_all = 1;
	else
		$view_all = 0;

	if (isset($_POST["view_downtime_cycle"]))
		$view_downtime_cycle = 1;
	else if (isset($_GET["view_downtime_cycle"]) && !isset($_POST["SearchB"]))
		$view_downtime_cycle = 1;
	else
		$view_downtime_cycle = 0;

	if (isset($_POST["search_author"]))
		$search_author = $_POST["search_author"];
	else if (isset($_GET["search_author"]) && !isset($_POST["SearchB"]))
		$search_author = $_GET["search_author"];
	else
		$search_author = NULL;
	
	/*
	 * Init GMT class
	 */
	$centreonGMT = new CentreonGMT($pearDB);
	$centreonGMT->getMyGMTFromSession(session_id(), $pearDB);

	include_once("./class/centreonDB.class.php");

	if ($oreon->broker->getBroker() == "ndo") {
		$pearDBndo = new CentreonDB("ndo");
		$ndo_base_prefix = getNDOPrefix();
	} else {
	    $pearDBndo = new CentreonDB("centstorage");
	}

	/*
	 * Smarty template Init
	 */
	$tpl = new Smarty();
	$tpl = initSmartyTpl($path, $tpl, "template/");

	/*
	 * Pear library
	 */
	require_once "HTML/QuickForm.php";
	require_once 'HTML/QuickForm/advmultiselect.php';
	require_once 'HTML/QuickForm/Renderer/ArraySmarty.php';

	$form = new HTML_QuickForm('select_form', 'GET', "?p=".$p);

	$tab_downtime_svc = array();

	/*
	 * Service Downtimes
	 */
	if ($view_all == 1) {
		$downtimeTable = "downtimehistory";
		if ($oreon->broker->getBroker() == "ndo") {
		    $extrafields = ", UNIX_TIMESTAMP(dtm.actual_end_time) as actual_end_time, was_cancelled ";
		} else {
		    $extrafields = ", actual_end_time, cancelled as was_cancelled ";
		}
	} else {
		$downtimeTable = "scheduleddowntime";
		$extrafields = "";
	}
	if ($oreon->broker->getBroker() == "ndo") {
		if ($is_admin) {
			$request =	"SELECT SQL_CALC_FOUND_ROWS DISTINCT dtm.internal_downtime_id, unix_timestamp(dtm.entry_time), dtm.duration, dtm.author_name, dtm.comment_data, dtm.is_fixed, unix_timestamp(dtm.scheduled_start_time) AS scheduled_start_time, unix_timestamp(dtm.scheduled_end_time) AS scheduled_end_time, obj.name1 host_name, obj.name2 service_description, was_started " . $extrafields .
					"FROM ".$ndo_base_prefix.$downtimeTable." dtm, ".$ndo_base_prefix."objects obj " .
					"WHERE obj.name1 IS NOT NULL " .
					"AND obj.name2 IS NOT NULL " .
					"AND obj.object_id = dtm.object_id ";
			$request .= (isset($search_service) && $search_service != "" ? "AND obj.name2 LIKE '%$search_service%' " : "") .
					(isset($host_name) && $host_name != "" ? "AND obj.name1 LIKE '%$host_name%' " : "") .
					(isset($search_output) && $search_output != "" ? "AND dtm.comment_data LIKE '%$search_output%' " : "") .
					(isset($search_author) && $search_author != "" ? " AND dtm.author_name LIKE '%$search_author%'" : "") .
					(isset($view_downtime_cycle) && $view_downtime_cycle == 0 ? " AND dtm.comment_data NOT LIKE '%Downtime cycle%' " : "") .	
					(isset($view_all) && $view_all == 0 ? "AND dtm.scheduled_end_time > '".date("Y-m-d G:i:s", time())."' " : "") .
					"ORDER BY dtm.actual_start_time DESC " .
					"LIMIT ".$num * $limit.", ".$limit;
		} else {
			$request =	"SELECT SQL_CALC_FOUND_ROWS DISTINCT dtm.internal_downtime_id, unix_timestamp(dtm.entry_time), dtm.duration, dtm.author_name, dtm.comment_data, dtm.is_fixed, unix_timestamp(dtm.scheduled_start_time) AS scheduled_start_time, unix_timestamp(dtm.scheduled_end_time) AS scheduled_end_time, obj.name1 host_name, obj.name2 service_description, was_started " . $extrafields .
					"FROM ".$ndo_base_prefix.$downtimeTable." dtm, ".$ndo_base_prefix."objects obj, centreon_acl " .
					"WHERE obj.name1 IS NOT NULL " .
					"AND obj.name2 IS NOT NULL " .
					"AND obj.object_id = dtm.object_id " .
					"AND obj.name1 = centreon_acl.host_name ";
			$request .= (isset($search_service) && $search_service != "" ? "AND obj.name2 LIKE '%$search_service%' " : "") .
					(isset($host_name) && $host_name != "" ? "AND obj.name1 LIKE '%$host_name%' " : "") .
					(isset($search_output) && $search_output != "" ? "AND dtm.comment_data LIKE '%$search_output%' " : "") .
					(isset($search_author) && $search_author != "" ? " AND dtm.author_name LIKE '%$search_author%'" : "") .
					(isset($view_downtime_cycle) && $view_downtime_cycle == 0 ? " AND dtm.comment_data NOT LIKE '%Downtime cycle%' " : "") .
					"AND obj.name2 = centreon_acl.service_description " .
					"AND centreon_acl.group_id IN (".$oreon->user->access->getAccessGroupsString().") " .
					(isset($view_all) && $view_all == 0 ? "AND dtm.scheduled_end_time > '".date("Y-m-d G:i:s", time())."' " : "") .
					"ORDER BY dtm.actual_start_time DESC " .
					"LIMIT ".$num * $limit.", ".$limit;
		}
		$DBRESULT_NDO = $pearDBndo->query($request);
		$rows = $pearDBndo->numberRows();
		for ($i = 0; $data = $DBRESULT_NDO->fetchRow(); $i++) {
			$tab_downtime_svc[$i] = $data;
			$tab_downtime_svc[$i]["comment_data"] = trim($data['comment_data']);
			$tab_downtime_svc[$i]["scheduled_start_time"] = $centreonGMT->getDate("m/d/Y H:i" , $tab_downtime_svc[$i]["scheduled_start_time"])." ";
			$tab_downtime_svc[$i]["scheduled_end_time"] = $centreonGMT->getDate("m/d/Y H:i" , $tab_downtime_svc[$i]["scheduled_end_time"])." ";
			$tab_downtime_svc[$i]["host_name_link"] = urlencode($tab_downtime_svc[$i]["host_name"]);
		}
		unset($data);
	} else {
        $request =  "SELECT SQL_CALC_FOUND_ROWS d.internal_id as internal_downtime_id,
                    d.entry_time, duration, d.author as author_name, d.comment_data,
                    d.fixed as is_fixed, d.start_time as scheduled_start_time, d.end_time as scheduled_end_time,
                    d.started as was_started, h.name as host_name, s.description as service_description " . $extrafields .
                    "FROM downtimes d, services s, hosts h " .
                    "WHERE d.host_id = s.host_id AND
                        d.service_id = s.service_id AND
                        s.host_id = h.host_id ";
        if (!$view_all) {
            $request .= " AND d.cancelled = 0 ";
        }
        if (!$is_admin) {
            $request .= " AND EXISTS(SELECT 1 FROM centreon_acl WHERE s.host_id = centreon_acl.host_id AND s.service_id = centreon_acl.service_id AND group_id IN (" . $oreon->user->access->getAccessGroupsString() . ")) ";
        }
        $request .= (isset($search_service) && $search_service != "" ? "AND s.description LIKE '%$search_service%' " : "") .
                    (isset($host_name) && $host_name != "" ? "AND h.name LIKE '%$host_name%' " : "") .
                    (isset($search_output) && $search_output != "" ? "AND d.comment_data LIKE '%$search_output%' " : "") .
                    (isset($view_all) && $view_all == 0 ? "AND d.end_time > '".time()."' " : "") .
                    (isset($view_downtime_cycle) && $view_downtime_cycle == 0 ? " AND d.comment_data NOT LIKE '%Downtime cycle%' " : "") .
                    (isset($search_author) && $search_author != "" ? " AND d.author LIKE '%$search_author%'" : "") .
                    "ORDER BY d.start_time DESC " .
                    "LIMIT ".$num * $limit.", ".$limit;
		$DBRESULT_NDO = $pearDBndo->query($request);
		$rows = $pearDBndo->numberRows();
		for ($i = 0; $data = $DBRESULT_NDO->fetchRow(); $i++) {
			$tab_downtime_svc[$i] = $data;
            $tab_downtime_svc[$i]['comment_data'] = htmlentities(trim($data['comment_data']));
			$tab_downtime_svc[$i]['host_name'] = htmlentities($data['host_name']);
			$tab_downtime_svc[$i]['service_description'] = htmlentities($data['service_description']);
			$tab_downtime_svc[$i]["scheduled_start_time"] = $centreonGMT->getDate("m/d/Y H:i" , $tab_downtime_svc[$i]["scheduled_start_time"])." ";
			$tab_downtime_svc[$i]["scheduled_end_time"] = $centreonGMT->getDate("m/d/Y H:i" , $tab_downtime_svc[$i]["scheduled_end_time"])." ";
{'fraction_non_alphanumeric': 0.16045983673863692, 'fraction_numerical': 0.004298893880113993, 'mean_word_length': 3.8328664799253036, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '677837', 'n_tokens_mistral': 7788, 'n_tokens_neox': 7082, 'n_words': 1573}