<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: http://svn.centreon.com/trunk/centreon/www/include/monitoring/status/Services/xml/broker/serviceXML.php $
 * SVN : $Id: serviceXML.php 11683 2011-02-14 16:10:44Z jmathis $
 *
 */

	/**
	 * Require configuration.
	 */
	include_once "@CENTREON_ETC@/centreon.conf.php";

	/**
	 * Require Sepecific XML / Ajax Class
	 */
	include_once $centreon_path . "www/class/centreonXMLBGRequest.class.php";

	/**
	 * Require commonu Files.
	 */
	include_once $centreon_path . "www/include/monitoring/status/Common/common-Func.php";
	include_once $centreon_path . "www/include/common/common-Func.php";

	/**
	 * Create XML Request Objects
	 */
	$obj = new CentreonXMLBGRequest($_GET["sid"], 1, 1, 0, 1);
	CentreonSession::start();

	if (isset($obj->session_id) && CentreonSession::checkSession($obj->session_id, $obj->DB)) {
		;
	} else {
		print "Bad Session ID";
		exit();
	}

	/**
	 * Set Default Poller
	 */
	$obj->getDefaultFilters();

	/** **************************************************
	 * Check Arguments From GET tab
	 */
	$o 			= $obj->checkArgument("o", $_GET, "h");
	$p 			= $obj->checkArgument("p", $_GET, "2");
	$nc 		= $obj->checkArgument("nc", $_GET, "0");
	$num 		= $obj->checkArgument("num", $_GET, 0);
	$limit 		= $obj->checkArgument("limit", $_GET, 20);
	$instance 	= $obj->checkArgument("instance", $_GET, $obj->defaultPoller);
	$search 	= $obj->checkArgument("search", $_GET, "");
	$search_host	= $obj->checkArgument("search_host", $_GET, "");
	$sort_type 	= $obj->checkArgument("sort_type", $_GET, "host_name");
	$order 		= $obj->checkArgument("order", $_GET, "ASC");
	$dateFormat = $obj->checkArgument("date_time_format_status", $_GET, "d/m/Y H:i:s");

	/** **************************************************
	 * Backup poller selection
	 */
	$obj->setInstanceHistory($instance);

	/**
	 * Graphs Tables
	 */
	$graphs = array();

	/** **************************************************
	 * Get Service status
	 */

	$instance_filter = "";
	if ($instance != -1) {
		$instance_filter = " AND h.instance_id = ".$instance." ";
	}

	$searchHost = "";
	if ($search_host) {
		$searchHost .= " AND h.name LIKE '%$search_host%' ";
	}

	$searchService = "";
	if ($search) {
		$searchService .= " AND s.description LIKE '%$search%' ";
	}

	$tabOrder = array();
	$tabOrder["host_name"] 			= " ORDER BY h.name ". $order.", s.description ";
	$tabOrder["service_description"]= " ORDER BY s.description ". $order.", h.name";
	$tabOrder["current_state"] 		= " ORDER BY s.state ". $order.", h.name, s.description";
	$tabOrder["last_state_change"] 	= " ORDER BY s.last_state_change ". $order.", h.name, s.description";
	$tabOrder["last_hard_state_change"] = " ORDER by s.last_hard_state_change ". $order.", h.name, s.description";
	$tabOrder["last_check"] 		= " ORDER BY s.last_check ". $order.", h.name, s.description";
	$tabOrder["current_attempt"] 	= " ORDER BY s.check_attempt ". $order.", h.name, s.description";
	$tabOrder["output"] 			= " ORDER BY s.output ". $order.", h.name, s.description";
	$tabOrder["default"] 			= " ORDER BY s.next_check ". $order.", h.name, s.description" ;

	$request = "SELECT SQL_CALC_FOUND_ROWS h.name, h.host_id, s.description, s.service_id, s.notes, s.notes_url, s.action_url, s.max_check_attempts,
				s.icon_image, s.display_name, s.process_perfdata, s.state, s.output as plugin_output,
				s.state_type, s.check_attempt as current_attempt, s.last_update as status_update_time, s.last_state_change,
				s.last_hard_state_change, s.last_check, s.next_check,
				s.notify, s.acknowledged, s.passive_checks, s.active_checks, s.event_handler_enabled, s.flapping,
				s.scheduled_downtime_depth, s.flap_detection, h.state as host_state, h.acknowledged AS h_acknowledged, h.scheduled_downtime_depth AS h_scheduled_downtime_depth,
				h.icon_image AS h_icon_images, h.display_name AS h_display_name, h.action_url AS h_action_url, h.notes_url AS h_notes_url, h.notes AS h_notes, h.address,
				h.passive_checks AS h_passive_checks, h.active_checks AS h_active_checks ";
	$request .= " FROM hosts h, services s ";
	if (!$obj->is_admin) {
		$request .= ", centreon_acl ";
	}
	$request .= " WHERE h.host_id = s.host_id
				  AND s.service_id IS NOT NULL
				  AND s.service_id != 0
				  AND h.enabled = 1
				  AND s.enabled = 1
				  AND h.name NOT LIKE '_Module_%' ";
	if ($searchHost) {
		$request .= $searchHost;
	}
	if ($searchService) {
		$request .= $searchService;
	}
	$request .= $instance_filter;

	/**
	 * ACL activation
	 */
	if (!$obj->is_admin) {
		$request .= " AND h.host_id = centreon_acl.host_id AND s.service_id = centreon_acl.service_id AND AND group_id IN (".$obj->grouplistStr.") ";
	}

	(isset($tabOrder[$sort_type])) ? $request .= $tabOrder[$sort_type] : $request .= $tabOrder["default"];
	$request .= " LIMIT ".($num * $limit).",".$limit;

	/** ***************************************************
	 * Get Pagination Rows
	 */<commit_msg>Bug #3287 Error in serviceScheduleXML.php<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: http://svn.centreon.com/trunk/centreon/www/include/monitoring/status/Services/xml/broker/serviceXML.php $
 * SVN : $Id: serviceXML.php 11683 2011-02-14 16:10:44Z jmathis $
 *
 */

	/**
	 * Require configuration.
	 */
	include_once "@CENTREON_ETC@/centreon.conf.php";

	/**
	 * Require Sepecific XML / Ajax Class
	 */
	include_once $centreon_path . "www/class/centreonXMLBGRequest.class.php";

	/**
	 * Require commonu Files.
	 */
	include_once $centreon_path . "www/include/monitoring/status/Common/common-Func.php";
	include_once $centreon_path . "www/include/common/common-Func.php";

	/**
	 * Create XML Request Objects
	 */
	$obj = new CentreonXMLBGRequest($_GET["sid"], 1, 1, 0, 1);
	CentreonSession::start();

	if (isset($obj->session_id) && CentreonSession::checkSession($obj->session_id, $obj->DB)) {
		;
	} else {
		print "Bad Session ID";
		exit();
	}

	/**
	 * Set Default Poller
	 */
	$obj->getDefaultFilters();

	/** **************************************************
	 * Check Arguments From GET tab
	 */
	$o 			= $obj->checkArgument("o", $_GET, "h");
	$p 			= $obj->checkArgument("p", $_GET, "2");
	$nc 		= $obj->checkArgument("nc", $_GET, "0");
	$num 		= $obj->checkArgument("num", $_GET, 0);
	$limit 		= $obj->checkArgument("limit", $_GET, 20);
	$instance 	= $obj->checkArgument("instance", $_GET, $obj->defaultPoller);
	$search 	= $obj->checkArgument("search", $_GET, "");
	$search_host	= $obj->checkArgument("search_host", $_GET, "");
	$sort_type 	= $obj->checkArgument("sort_type", $_GET, "host_name");
	$order 		= $obj->checkArgument("order", $_GET, "ASC");
	$dateFormat = $obj->checkArgument("date_time_format_status", $_GET, "d/m/Y H:i:s");

	/** **************************************************
	 * Backup poller selection
	 */
	$obj->setInstanceHistory($instance);

	/**
	 * Graphs Tables
	 */
	$graphs = array();

	/** **************************************************
	 * Get Service status
	 */

	$instance_filter = "";
	if ($instance != -1) {
		$instance_filter = " AND h.instance_id = ".$instance." ";
	}

	$searchHost = "";
	if ($search_host) {
		$searchHost .= " AND h.name LIKE '%$search_host%' ";
	}

	$searchService = "";
	if ($search) {
		$searchService .= " AND s.description LIKE '%$search%' ";
	}

	$tabOrder = array();
	$tabOrder["host_name"] 			= " ORDER BY h.name ". $order.", s.description ";
	$tabOrder["service_description"]= " ORDER BY s.description ". $order.", h.name";
	$tabOrder["current_state"] 		= " ORDER BY s.state ". $order.", h.name, s.description";
	$tabOrder["last_state_change"] 	= " ORDER BY s.last_state_change ". $order.", h.name, s.description";
	$tabOrder["last_hard_state_change"] = " ORDER by s.last_hard_state_change ". $order.", h.name, s.description";
	$tabOrder["last_check"] 		= " ORDER BY s.last_check ". $order.", h.name, s.description";
	$tabOrder["current_attempt"] 	= " ORDER BY s.check_attempt ". $order.", h.name, s.description";
	$tabOrder["output"] 			= " ORDER BY s.output ". $order.", h.name, s.description";
	$tabOrder["default"] 			= " ORDER BY s.next_check ". $order.", h.name, s.description" ;

	$request = "SELECT SQL_CALC_FOUND_ROWS h.name, h.host_id, s.description, s.service_id, s.notes, s.notes_url, s.action_url, s.max_check_attempts,
				s.icon_image, s.display_name, s.process_perfdata, s.state, s.output as plugin_output,
				s.state_type, s.check_attempt as current_attempt, s.last_update as status_update_time, s.last_state_change,
				s.last_hard_state_change, s.last_check, s.next_check,
				s.notify, s.acknowledged, s.passive_checks, s.active_checks, s.event_handler_enabled, s.flapping,
				s.scheduled_downtime_depth, s.flap_detection, h.state as host_state, h.acknowledged AS h_acknowledged, h.scheduled_downtime_depth AS h_scheduled_downtime_depth,
				h.icon_image AS h_icon_images, h.display_name AS h_display_name, h.action_url AS h_action_url, h.notes_url AS h_notes_url, h.notes AS h_notes, h.address,
				h.passive_checks AS h_passive_checks, h.active_checks AS h_active_checks ";
	$request .= " FROM hosts h, services s ";
	if (!$obj->is_admin) {
		$request .= ", centreon_acl ";
	}
	$request .= " WHERE h.host_id = s.host_id
				  AND s.service_id IS NOT NULL
				  AND s.service_id != 0
				  AND h.enabled = 1
				  AND s.enabled = 1
				  AND h.name NOT LIKE '_Module_%' ";
	if ($searchHost) {
		$request .= $searchHost;
	}
	if ($searchService) {
		$request .= $searchService;
	}
	$request .= $instance_filter;

	/**
	 * ACL activation
	 */
	if (!$obj->is_admin) {
		$request .= " AND h.host_id = centreon_acl.host_id AND s.service_id = centreon_acl.service_id AND group_id IN (".$obj->grouplistStr.") ";
	}

	(isset($tabOrder[$sort_type])) ? $request .= $tabOrder[$sort_type] : $request .= $tabOrder["default"];
	$request .= " LIMIT ".($num * $limit).",".$limit;

	/** ***************************************************
	 * Get Pagination Rows
	 */
{'fraction_non_alphanumeric': 0.16942521817634668, 'fraction_numerical': 0.006770990069214565, 'mean_word_length': 4.114659484417084, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 10, 'xml': 2}, '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': '7063139', 'n_tokens_mistral': 4653, 'n_tokens_neox': 4257, 'n_words': 1211}