require_once $centreon_open_tickets_path . 'providers/' . $provider_name . '/' . $provider_name . 'Provider.class.php';
$classname = $provider_name . 'Provider';
$centreon_provider = new $classname($rule, $centreon_path, $centreon_open_tickets_path, $get_information['rule_id'], $get_information['form'], $get_information['provider_id']);
$centreon_provider->setWidgetId($get_information['form']['widgetId']);
// We get Host or Service
require_once $centreon_path . 'www/class/centreonDuration.class.php';
$selected_values = explode(',', $get_information['form']['selection']);
$db_storage = new centreonDBManager('centstorage');
$selected = $rule->loadSelection($db_storage, $get_information['form']['cmd'], $get_information['form']['selection']);
try {
    $contact_infos = get_contact_information();
    $resultat['result'] = $centreon_provider->submitTicket($db_storage, $contact_infos, $selected['host_selected'], $selected['service_selected']);
    if ($resultat['result']['ticket_is_ok'] == 1) {
        require_once $centreon_path . 'www/class/centreonExternalCommand.class.php';
        $oreon = $_SESSION['centreon'];
        $external_cmd = new CentreonExternalCommand($oreon);
        foreach ($selected['host_selected'] as $value) {
            $command = "CHANGE_CUSTOM_HOST_VAR;%s;%s;%s";
            $external_cmd->set_process_command(sprintf($command, $value['name'], $centreon_provider->getMacroTicketId(), $resultat['result']['ticket_id']), $value['instance_id']);
            if ($centreon_provider->doAck()) {
                $command = "ACKNOWLEDGE_HOST_PROBLEM;%s;%s;%s;%s;%s;%s;%";
                $external_cmd->set_process_command(sprintf($command, $value['name'], 2, 0, 1, $contact_infos['alias'], 'open ticket: ' . $resultat['result']['ticket_id']), $value['instance_id']);
            }
        }
        foreach ($selected['service_selected'] as $value) {
            $command = "CHANGE_CUSTOM_SVC_VAR;%s;%s;%s;%s";
            $external_cmd->set_process_command(sprintf($command, $value['host_name'], $value['description'], $centreon_provider->getMacroTicketId(), $resultat['result']['ticket_id']), $value['instance_id']);
            if ($centreon_provider->doAck()) {
                $command = "ACKNOWLEDGE_SVC_PROBLEM;%s;%s;%s;%s;%s;%s;%s";
                $external_cmd->set_process_command(sprintf($command, $value['host_name'], $value['description'], 2, 0, 1, $contact_infos['alias'], 'open ticket: ' . $resultat['result']['ticket_id']), $value['instance_id']);
            }
$DBRESULT = $db_storage->query($query);
while ($row = $DBRESULT->fetchRow()) {
    if (isset($hosts_done[$row['host_name'] . ';' . $row['description']])) {
        continue;
    }
    $problems[] = $row;
    $tickets[$row['ticket_value']] = array('status' => 0, 'msg_error' => null);
    $hosts_done[$row['host_name'] . ';' . $row['description']] = 1;
}
try {
    $centreon_provider->closeTicket($tickets);
    #fwrite($fp, print_r($problems, true) . "===\n");
    #fwrite($fp, print_r($tickets, true) . "===\n");
    require_once $centreon_path . 'www/class/centreonExternalCommand.class.php';
    $oreon = $_SESSION['centreon'];
    $external_cmd = new CentreonExternalCommand($oreon);
    $removed_tickets = array();
    $error_msg = array();
    foreach ($problems as $row) {
        # an error in ticket close
        if (isset($tickets[$row['ticket_value']]) && $tickets[$row['ticket_value']]['status'] == -1) {
            $error_msg[] = $tickets[$row['ticket_value']]['msg_error'];
            continue;
        }
        # ticket is really closed
        if ($tickets[$row['ticket_value']]['status'] == 2 && !isset($removed_tickets[$row['ticket_value']])) {
            $removed_tickets[$row['ticket_value']] = 1;
        }
        if (is_null($row['description']) || $row['description'] == '') {
            $command = "CHANGE_CUSTOM_HOST_VAR;%s;%s;%s";
            $external_cmd->set_process_command(sprintf($command, $row['host_name'], $centreon_provider->getMacroTicketId(), ''), $row['instance_id']);