histogram: Make histograms crash less
[ninja.git] / application / controllers / recurring_downtime.php
blob0de7194362100d80044d0e79e100b1f7572678fc
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
2 /**
3 * Controller to handle Recurring Downtime Schedules
4 * Requires authentication
6 * op5, and the op5 logo are trademarks, servicemarks, registered servicemarks
7 * or registered trademarks of op5 AB.
8 * All other trademarks, servicemarks, registered trademarks, and registered
9 * servicemarks mentioned herein may be the property of their respective owner(s).
10 * The information contained herein is provided AS IS with NO WARRANTY OF ANY
11 * KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY, AND FITNESS FOR A
12 * PARTICULAR PURPOSE.
14 class recurring_downtime_Controller extends Authenticated_Controller {
16 /**
17 * Setup/Edit schedules
19 public function index($id=false)
21 if (!empty($_POST)) {
22 $data = false;
23 $missing = array();
24 foreach (ScheduleDate_Model::$valid_fields as $field) {
25 if (!isset($_REQUEST[$field])) {
26 if ($field === 'fixed') {
27 $data[$field] = false;
29 else if ($field === 'author') {
30 $data[$field] = Auth::instance()->get_user()->username;
32 else {
33 $missing[] = $field;
36 else {
37 $data[$field] = $_REQUEST[$field];
41 if ($missing) {
42 $recurring_downtime_error = 'Missing required fields: ' . implode(', ', $missing);
43 } else {
44 $id = arr::search($_REQUEST, 'schedule_id');
46 $sd = new ScheduleDate_Model();
47 if ($sd->edit_schedule($data, $id))
48 return url::redirect(url::base(true) . 'listview?q=[recurring_downtimes]%20all');
49 $recurring_downtime_error = 'Failed to save changed schedule';
53 $this->template->disable_refresh = true;
55 $this->template->title = _('Monitoring » Scheduled downtime » Recurring downtime');
57 $this->template->content = $this->add_view('recurring_downtime/setup');
58 $template = $this->template->content;
60 $this->xtra_js[] = 'application/media/js/jquery.datePicker.js';
61 $this->xtra_js[] = 'application/media/js/jquery.timePicker.js';
62 $this->xtra_js[] = $this->add_path('reports/js/common.js');
63 $this->xtra_js[] = $this->add_path('recurring_downtime/js/recurring_downtime.js');
65 $this->xtra_css[] = $this->add_path('reports/css/datePicker.css');
67 $date_format = cal::get_calendar_format(true);
69 $schedule_id = arr::search($_REQUEST, 'schedule_id', $id);
71 if (isset($recurring_downtime_error)) {
72 $this->template->content->error = $recurring_downtime_error;
75 $this->template->toolbar = new Toolbar_Controller('Recurring scheduled downtimes');
77 $this->template->toolbar->button('<span class="icon-menu menu-schedulereports"></span>' . _('Schedules'), array('href' => url::base(true) . 'listview?q=[recurring_downtimes]%20all'));
79 $data = false;
80 $schedule_info = array(
81 'start_time' => 12 * 3600,
82 'end_time' => 14 * 3600,
83 'duration' => 2 * 3600,
84 'fixed' => true,
85 'comment' => '',
87 if (!empty($_POST)) {
88 $schedule_info = array_merge($schedule_info, $_POST);
89 $schedule_info = new RecurringDowntime_Model($schedule_info, '', false);
91 else if ($schedule_id) {
92 $set = RecurringDowntimePool_Model::get_by_query('[recurring_downtimes] id = ' . $schedule_id);
93 $schedule_info = $set->it(array('id', 'downtime_type', 'objects', 'start_time', 'end_time', 'duration', 'fixed', 'weekdays', 'months', 'comment'))->current();
94 } else {
95 $schedule_info = new RecurringDowntime_Model($schedule_info, '', false);
98 if ($schedule_id) {
99 $this->js_strings .= "var _report_data = " . json_encode(array('objects' => $schedule_info->get_objects(), 'downtime_type' => $schedule_info->get_downtime_type())) . "\n";
101 $this->js_strings .= reports::js_strings();
103 $this->js_strings .= "var _reports_err_str_noobjects = '".sprintf(_("Please select objects by moving them from %s the left selectbox to the right selectbox"), '<br />')."';\n";
104 $this->js_strings .= "var _form_err_empty_fields = '"._("Please Enter valid values in all required fields (marked by *) ")."';\n";
105 $this->js_strings .= "var _form_err_bad_timeformat = '"._("Please Enter a valid %s value (hh:mm)")."';\n";
106 $this->js_strings .= "var _schedule_error = '"._("An error occurred when trying to delete this schedule")."';\n";
108 $this->js_strings .= "var _schedule_delete_ok = '"._("OK")."';\n";
109 $this->js_strings .= "var _schedule_delete_success = '"._("The schedule was successfully removed")."';\n";
111 $this->js_strings .= "var _form_field_time = '"._("time")."';\n";
112 $this->js_strings .= "var _form_field_duration = '"._("duration")."';\n";
115 $template->day_names = date::day_names();
116 $template->day_index = array(1, 2, 3, 4, 5, 6, 0);
117 $template->month_names = date::month_names();
119 $template->schedule_id = $schedule_id;
120 $template->schedule_info = $schedule_info;
122 $this->template->inline_js = $this->inline_js;
123 $this->template->js_strings = $this->js_strings;
127 * Delete a schedule
129 public function delete()
131 $this->auto_render=false;
132 $schedule_id = $this->input->post('schedule_id', false);
134 if (!$schedule_id) {
135 return json::fail('Error: no schedule id provided');
138 if (ScheduleDate_Model::delete_schedule($schedule_id) !== false) {
139 return json::ok("Schedule deleted");
140 } else {
141 return json::fail("Not authorized to delete schedule or it doesn't exist.");