Avail feature updated
[ninja.git] / modules / reports / controllers / alert_history.php
blobae1199f02a3535efa85e121c709c1af1006def51
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
2 /**
3 * Alert History controller
4 * This is just a special case of the recent alert view in the summary controller
5 */
6 class Alert_history_Controller extends Summary_Controller
8 public $type = 'alert_history';
10 public function index($input = false)
12 if (isset($_SESSION['report_err_msg'])) {
13 $this->template->content = _("<h1>You're not authorized to see any hosts, so I can't show you a history of their alerts.</h1>\n<p>But then, you <i>were</i> allowed to log in, so I bet something is broken. Please contact <a href=\"mailto:support@op5.com\">support@op5.com</a> with any information you have.</p>");
14 unset($_SESSION['report_err_msg']);
16 else {
17 return url::redirect('alert_history/generate');
21 public function generate($input = false)
23 $this->setup_options_obj($input);
25 unset($this->options['page']);
26 $pagination = new CountlessPagination(array('items_per_page' => $this->options['summary_items'], 'extra_params' => $this->options->as_keyval_string()));
27 $this->options['page'] = $pagination->current_page;
29 $this->options['summary_type'] = Summary_options::RECENT_ALERTS;
30 $this->template->js[] = $this->add_path('alert_history/js/alert_history.js');
31 $real_output_format = $this->options['output_format'];
32 if ($this->options['output_format'] === 'pdf')
33 $this->options['output_format'] = 'html';
34 parent::generate();
35 if ($this->options['output_format'] !== 'csv') {
36 $this->template->content->report_options = $this->add_view('alert_history/options');
37 $this->template->title = _('Alert history');
38 $this->template->content->header->standard_header->skip_save = true;
39 $this->template->content->header->standard_header->title = _('Alert history');
40 $pagination->hide_next = false;
41 if(!$this->template->content->content->result || count($this->template->content->content->result) < $this->options['summary_items']) {
42 $pagination->hide_next = true;
44 $this->template->content->content->pagination = $pagination;
46 if ($real_output_format == 'pdf') {
47 return $this->generate_pdf();
51 /**
52 * End-point for XHR requests, that creates an event comment which will be
53 * displayed with the event itself in reports.
55 public function add_comment()
57 $this->auto_render = false;
58 $timestamp = $this->input->post('timestamp');
59 $event_type = $this->input->post('event_type');
60 $host_name = $this->input->post('host_name');
61 $service = $this->input->post('service_description');
62 $comment = $this->input->post('comment');
63 $username = Auth::instance()->get_user()->username;
65 if (Summary_Reports_Model::add_event_comment($timestamp, $event_type, $host_name, $service, $comment, $username))
66 echo '<div class="content">'.html::specialchars($comment).'</div><div class="author">/'.$username.'</div>';