function remove_tickets()
{
    global $cmd, $widgetId, $rule, $preferences, $centreon, $centreon_path, $centreon_bg;
    $path = $centreon_path . "www/widgets/open-tickets/src/";
    $provider_infos = $rule->getAliasAndProviderId($preferences['rule']);
    $template = new Smarty();
    $template = initSmartyTplForPopup($path . 'templates/', $template, "./", $centreon_path);
    $template->assign('title', _('Close Tickets'));
    $template->assign('selection', $_REQUEST['selection']);
    $template->assign('provider_id', $provider_infos['provider_id']);
    $template->assign('rule_id', $preferences['rule']);
    $template->display('removetickets.ihtml');
}
    exit;
}
$db = new CentreonDB();
if (CentreonSession::checkSession(session_id(), $db) == 0) {
    exit;
}
$prefixRes = $db->query("SELECT db_prefix FROM cfg_ndo2db WHERE activate = '1' LIMIT 1");
if (!$prefixRes->numRows()) {
    exit;
}
$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'];
 protected function doSubmit($db_storage, $contact, $host_problems, $service_problems, $extra_ticket_arguments = array())
 {
     $result = array('ticket_id' => null, 'ticket_error_message' => null, 'ticket_is_ok' => 0, 'ticket_time' => time());
     $tpl = new Smarty();
     $tpl = initSmartyTplForPopup($this->_centreon_open_tickets_path, $tpl, 'providers/Abstract/templates', $this->_centreon_path);
     $tpl->assign("centreon_open_tickets_path", $this->_centreon_open_tickets_path);
     $tpl->assign('user', $contact);
     $tpl->assign('host_selected', $host_problems);
     $tpl->assign('service_selected', $service_problems);
     $this->assignSubmittedValues($tpl);
     $ticket_arguments = $extra_ticket_arguments;
     if (isset($this->rule_data['clones']['mappingTicket'])) {
         foreach ($this->rule_data['clones']['mappingTicket'] as $value) {
             $tpl->assign('string', $value['Value']);
             $result_str = $tpl->fetch('eval.ihtml');
             if ($result_str == '') {
                 $result_str = null;
             }
             $ticket_arguments[$this->_internal_arg_name[$value['Arg']]] = $result_str;
             // Old version of GLPI use 'recipient' depiste groupassign
             if ($value['Arg'] == self::ARG_GROUP_ASSIGN) {
                 $ticket_arguments['recipient'] = $result_str;
             }
         }
     }
     $code = $this->createTicketGlpi($ticket_arguments);
     if ($code == -1) {
         $result['ticket_error_message'] = $this->rpc_error;
         return $result;
     }
     $this->saveHistory($db_storage, $result, array('contact' => $contact, 'host_problems' => $host_problems, 'service_problems' => $service_problems, 'ticket_value' => $this->glpi_call_response['response']['id'], 'subject' => $ticket_arguments[self::ARG_TITLE], 'data_type' => self::DATA_TYPE_JSON, 'data' => json_encode($ticket_arguments)));
     return $result;
 }
 protected function doSubmit($db_storage, $contact, $host_problems, $service_problems)
 {
     $result = array('ticket_id' => null, 'ticket_error_message' => null, 'ticket_is_ok' => 0, 'ticket_time' => time());
     $tpl = new Smarty();
     $tpl = initSmartyTplForPopup($this->_centreon_open_tickets_path, $tpl, 'providers/Abstract/templates', $this->_centreon_path);
     $tpl->assign("centreon_open_tickets_path", $this->_centreon_open_tickets_path);
     $tpl->assign('user', $contact);
     $tpl->assign('host_selected', $host_problems);
     $tpl->assign('service_selected', $service_problems);
     $this->assignSubmittedValues($tpl);
     $ticket_arguments = array();
     if (isset($this->rule_data['clones']['mappingTicket'])) {
         foreach ($this->rule_data['clones']['mappingTicket'] as $value) {
             $tpl->assign('string', $value['Value']);
             $result_str = $tpl->fetch('eval.ihtml');
             if ($result_str == '') {
                 $result_str = null;
             }
             foreach ($this->_internal_arguments as $arg) {
                 if ($arg['id'] == $value['Arg']) {
                     $ticket_arguments[$arg['soap']] = $result_str;
                     break;
                 }
             }
         }
     }
     $code = $this->createTicketBmcItsm($ticket_arguments);
     if ($code == -1) {
         $result['ticket_error_message'] = $this->ws_error;
         return $result;
     }
     $this->saveHistory($db_storage, $result, array('contact' => $contact, 'host_problems' => $host_problems, 'service_problems' => $service_problems, 'ticket_value' => $this->_ticket_number, 'subject' => $ticket_arguments['Description'], 'data_type' => self::DATA_TYPE_JSON, 'data' => json_encode(array('arguments' => $ticket_arguments))));
     return $result;
 }
        $grouplist = $access->getAccessGroups();
        $grouplistStr = $access->getAccessGroupsString();
    }
    $widgetObj = new CentreonWidget($centreon, $db_centreon);
    $preferences = $widgetObj->getWidgetPreferences($widgetId);
    $autoRefresh = 0;
    if (isset($preferences['refresh_interval'])) {
        $autoRefresh = $preferences['refresh_interval'];
    }
} catch (Exception $e) {
    echo $e->getMessage() . "<br/>";
    exit;
}
/* Start Smarty Init */
$template = new Smarty();
$template = initSmartyTplForPopup(getcwd() . "/src/", $template, "./", $centreon_path);
$data = array();
$data_service = array();
$data_check = array();
$inc = 0;
/* Query 1 */
$query1 = "SELECT DISTINCT T1.name, T2.host_id " . "FROM hosts T1, hosts_hostgroups T2 " . ($centreon->user->admin == 0 ? ", centreon_acl acl" : "") . "WHERE T1.host_id = T2.host_id " . "AND T1.enabled = 1 " . "AND T2.hostgroup_id = " . $preferences['host_group'] . ($centreon->user->admin == 0 ? " AND T1.host_id = acl.host_id AND T2.host_id = acl.host_id AND acl.group_id IN (" . ($grouplistStr != "" ? $grouplistStr : 0) . ")" : "");
/* Query 2 */
$query2 = "SELECT distinct T1.description " . "FROM services T1 " . ($centreon->user->admin == 0 ? ", centreon_acl acl" : "") . "WHERE T1.enabled = 1 " . ($centreon->user->admin == 0 ? " AND T1.service_id = acl.service_id AND acl.group_id IN (" . ($grouplistStr != "" ? $grouplistStr : 0) . " AND (" : " AND (");
foreach (explode(",", $preferences['service']) as $elem) {
    if (!$inc) {
        $query2 .= "T1.description LIKE '{$elem}'";
    } else {
        $query2 .= " OR T1.description like '{$elem}'";
    }
    $inc++;
 protected function doSubmit($db_storage, $contact, $host_problems, $service_problems)
 {
     $result = array('ticket_id' => null, 'ticket_error_message' => null, 'ticket_is_ok' => 0, 'ticket_time' => time());
     $tpl = new Smarty();
     $tpl = initSmartyTplForPopup($this->_centreon_open_tickets_path, $tpl, 'providers/Abstract/templates', $this->_centreon_path);
     $tpl->assign("centreon_open_tickets_path", $this->_centreon_open_tickets_path);
     $tpl->assign('user', $contact);
     $tpl->assign('host_selected', $host_problems);
     $tpl->assign('service_selected', $service_problems);
     $this->assignSubmittedValues($tpl);
     $ticket_arguments = array();
     if (isset($this->rule_data['clones']['mappingTicket'])) {
         foreach ($this->rule_data['clones']['mappingTicket'] as $value) {
             $tpl->assign('string', $value['Value']);
             $result_str = $tpl->fetch('eval.ihtml');
             if ($result_str == '') {
                 $result_str = null;
             }
             $ticket_arguments[$this->_internal_arg_name[$value['Arg']]] = $result_str;
         }
     }
     $ticket_dynamic_fields = array();
     if (isset($this->rule_data['clones']['mappingTicketDynamicField'])) {
         foreach ($this->rule_data['clones']['mappingTicketDynamicField'] as $value) {
             if ($value['Name'] == '' || $value['Value'] == '') {
                 continue;
             }
             $array_tmp = array();
             $tpl->assign('string', $value['Name']);
             $array_tmp = array('Name' => $tpl->fetch('eval.ihtml'));
             $tpl->assign('string', $value['Value']);
             $array_tmp['Value'] = $tpl->fetch('eval.ihtml');
             $ticket_dynamic_fields[] = $array_tmp;
         }
     }
     $code = $this->createTicketOtrs($ticket_arguments, $ticket_dynamic_fields);
     if ($code == -1) {
         $result['ticket_error_message'] = $this->ws_error;
         return $result;
     }
     $this->saveHistory($db_storage, $result, array('contact' => $contact, 'host_problems' => $host_problems, 'service_problems' => $service_problems, 'ticket_value' => $this->_otrs_call_response['TicketNumber'], 'subject' => $ticket_arguments['Subject'], 'data_type' => self::DATA_TYPE_JSON, 'data' => json_encode(array('arguments' => $ticket_arguments, 'dynamic_fields' => $ticket_dynamic_fields))));
     return $result;
 }
    for (; $top <= $num_page && $total >= 0; $top++) {
        $top_display[] = $top;
        $total--;
    }
    sort($top_display, SORT_NUMERIC);
    if ($top > $rows / $pagination + 1) {
        $arrow_last_display = 0;
    }
    $tpl->assign("bottom_display", $bottom_display);
    $tpl->assign("top_display", $top_display);
    $tpl->assign("arrow_first_display", $arrow_first_display);
    $tpl->assign("arrow_last_display", $arrow_last_display);
}
$resultat = array("code" => 0, "msg" => 'ok', "data" => null, "pagination" => null);
//$fp = fopen('/tmp/debug.txt', 'a+');
//fwrite($fp, print_r($get_information, true));
$_SESSION['OT_form_logs'] = $get_information['form'];
try {
    $tickets = $ticket_log->getLog($get_information['form'], $centreon_bg, $get_information['pagination'], $get_information['current_page']);
    //fwrite($fp, print_r($tickets, true));
    $tpl = new Smarty();
    $tpl = initSmartyTplForPopup($centreon_open_tickets_path, $tpl, 'views/logs/templates', $centreon_path);
    $tpl->assign("tickets", $tickets['tickets']);
    $resultat['data'] = $tpl->fetch('data.ihtml');
    // Get Pagination
    set_pagination($tpl, $get_information['pagination'], $get_information['current_page'], $tickets['rows']);
    $resultat['pagination'] = $tpl->fetch('pagination.ihtml');
} catch (Exception $e) {
    $resultat['code'] = 1;
    $resultat['msg'] = $e->getMessage();
}
require_once $centreon_path . 'www/class/centreonService.class.php';
require_once $centreon_path . 'www/class/centreonMedia.class.php';
require_once $centreon_path . 'www/class/centreonCriticality.class.php';
require_once $centreon_path . "GPL_LIB/Smarty/libs/Smarty.class.php";
require_once $centreon_path . 'www/modules/centreon-open-tickets/class/rule.php';
session_start();
if (!isset($_SESSION['centreon']) || !isset($_REQUEST['widgetId']) || !isset($_REQUEST['page'])) {
    exit;
}
$db = new CentreonDB();
if (CentreonSession::checkSession(session_id(), $db) == 0) {
    exit;
}
// Init Smarty
$template = new Smarty();
$template = initSmartyTplForPopup($centreon_path . "www/widgets/open-tickets/src/templates/", $template, "./", $centreon_path);
/* Init Objects */
$criticality = new CentreonCriticality($db);
$media = new CentreonMedia($db);
$rule = new Centreon_OpenTickets_Rule($db);
$centreon = $_SESSION['centreon'];
$widgetId = $_REQUEST['widgetId'];
$page = $_REQUEST['page'];
$dbb = new CentreonDB("centstorage");
$widgetObj = new CentreonWidget($centreon, $db);
$preferences = $widgetObj->getWidgetPreferences($widgetId);
if (!isset($preferences['rule'])) {
    exit;
}
$macro_tickets = $rule->getMacroNames($preferences['rule'], $widgetId);
// Set Colors Table
 public function getUrl($ticket_id, $data)
 {
     $tpl = new Smarty();
     $tpl = initSmartyTplForPopup($this->_centreon_open_tickets_path, $tpl, 'providers/Abstract/templates', $this->_centreon_path);
     foreach ($data as $label => $value) {
         $tpl->assign($label, $value);
     }
     foreach ($this->rule_data as $label => $value) {
         $tpl->assign($label, $value);
     }
     $tpl->assign('ticket_id', $ticket_id);
     $tpl->assign('string', $this->rule_data['url']);
     return $tpl->fetch('eval.ihtml');
 }
 protected function doSubmit($db_storage, $contact, $host_problems, $service_problems)
 {
     $result = array('ticket_id' => null, 'ticket_error_message' => null, 'ticket_is_ok' => 0, 'ticket_time' => time());
     try {
         $query = "INSERT INTO mod_open_tickets\n  (`timestamp`, `user`) VALUES ('" . $result['ticket_time'] . "', '" . $db_storage->escape($contact['name']) . "')";
         $db_storage->query($query);
         $result['ticket_id'] = $db_storage->lastinsertId('mod_open_tickets');
     } catch (Exception $e) {
         $result['ticket_error_message'] = $e->getMessage();
         return $result;
     }
     $tpl = new Smarty();
     $tpl = initSmartyTplForPopup($this->_centreon_open_tickets_path, $tpl, 'providers/Abstract/templates', $this->_centreon_path);
     $tpl->assign("centreon_open_tickets_path", $this->_centreon_open_tickets_path);
     $tpl->assign('user', $contact);
     $tpl->assign('host_selected', $host_problems);
     $tpl->assign('service_selected', $service_problems);
     $tpl->assign('ticket_id', $result['ticket_id']);
     $this->assignSubmittedValues($tpl);
     // We send the mail
     $tpl->assign('string', $this->rule_data['from']);
     $from = $tpl->fetch('eval.ihtml');
     $headers = "From: " . $from;
     if (isset($this->rule_data['clones']['headerMail'])) {
         foreach ($this->rule_data['clones']['headerMail'] as $values) {
             $headers .= "\r\n" . $values['Name'] . ':' . $values['Value'];
         }
     }
     $tpl->assign('string', $this->rule_data['subject']);
     $subject = $tpl->fetch('eval.ihtml');
     mail($this->rule_data['to'], $subject, $this->body, $headers);
     $this->saveHistory($db_storage, $result, array('no_create_ticket_id' => true, 'contact' => $contact, 'host_problems' => $host_problems, 'service_problems' => $service_problems, 'subject' => $subject, 'data_type' => self::DATA_TYPE_JSON, 'data' => json_encode(array('body' => $this->body, 'from' => $from, 'headers' => $headers, 'to' => $this->rule_data['to']))));
     return $result;
 }