1 <?php
defined('SYSPATH') OR die('No direct access allowed.');
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
14 class recurring_downtime_Controller
extends Authenticated_Controller
{
17 * Setup/Edit schedules
19 public function index($id=false)
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
;
37 $data[$field] = $_REQUEST[$field];
42 $recurring_downtime_error = 'Missing required fields: ' . implode(', ', $missing);
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->template
->js
[] = 'application/media/js/jquery.datePicker.js';
61 $this->template
->js
[] = 'application/media/js/jquery.timePicker.js';
62 $this->template
->js
[] = $this->add_path('reports/js/common.js');
63 $this->template
->js
[] = $this->add_path('recurring_downtime/js/recurring_downtime.js');
65 $this->template
->js
[] = 'application/media/js/lib.set.js';
66 $this->template
->js
[] = 'application/media/js/jquery.filterable.js';
68 $this->template
->css
[] = $this->add_path('reports/css/datePicker.css');
69 $this->template
->css
[] = 'application/media/css/jquery.filterable.css';
71 $date_format = cal
::get_calendar_format(true);
73 $schedule_id = arr
::search($_REQUEST, 'schedule_id', $id);
75 if (isset($recurring_downtime_error)) {
76 $this->template
->content
->error
= $recurring_downtime_error;
79 $this->template
->toolbar
= new Toolbar_Controller('Recurring scheduled downtimes');
81 $this->template
->toolbar
->button('<span class="icon-menu menu-schedulereports"></span>' . _('Schedules'), array('href' => url
::base(true) . 'listview?q=[recurring_downtimes]%20all'));
84 $schedule_info = array(
85 'start_time' => 12 * 3600,
86 'end_time' => 14 * 3600,
87 'duration' => 2 * 3600,
92 $schedule_info = array_merge($schedule_info, $_POST);
93 $schedule_info = new RecurringDowntime_Model($schedule_info, '', false);
95 else if ($schedule_id) {
96 $set = RecurringDowntimePool_Model
::get_by_query('[recurring_downtimes] id = ' . $schedule_id);
97 $schedule_info = $set->it(array('id', 'downtime_type', 'objects', 'start_time', 'end_time', 'duration', 'fixed', 'weekdays', 'months', 'comment'))->current();
99 $schedule_info = new RecurringDowntime_Model($schedule_info, '', false);
103 $this->js_strings
.= "var _report_data = " . json_encode(array('objects' => $schedule_info->get_objects(), 'downtime_type' => $schedule_info->get_downtime_type())) . "\n";
105 $this->js_strings
.= reports
::js_strings();
107 $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";
108 $this->js_strings
.= "var _form_err_empty_fields = '"._("Please Enter valid values in all required fields (marked by *) ")."';\n";
109 $this->js_strings
.= "var _form_err_bad_timeformat = '"._("Please Enter a valid %s value (hh:mm[:ss])")."';\n";
110 $this->js_strings
.= "var _schedule_error = '"._("An error occurred when trying to delete this schedule")."';\n";
112 $this->js_strings
.= "var _schedule_delete_ok = '"._("OK")."';\n";
113 $this->js_strings
.= "var _schedule_delete_success = '"._("The schedule was successfully removed")."';\n";
115 $this->js_strings
.= "var _form_field_start_time = '"._("Start Time")."';\n";
116 $this->js_strings
.= "var _form_field_end_time = '"._("End Time")."';\n";
117 $this->js_strings
.= "var _form_field_duration = '"._("duration")."';\n";
120 $template->day_names
= date
::day_names();
121 $template->day_index
= array(1, 2, 3, 4, 5, 6, 0);
122 $template->month_names
= date
::month_names();
124 $template->schedule_id
= $schedule_id;
125 $template->schedule_info
= $schedule_info;
127 $this->template
->inline_js
= $this->inline_js
;
128 $this->template
->js_strings
= $this->js_strings
;
136 function insert_downtimes()
138 $this->auto_render
= false;
139 $objects = $this->input
->post('objects', false);
140 $object_type = $this->input
->post('object_type', false);
141 $start_time = $this->input
->post('start_time', false);
142 $end_time = $this->input
->post('end_time', false);
143 $fixed = $this->input
->post('fixed', false);
144 $duration = $this->input
->post('duration', false);
145 $comment = $this->input
->post('comment', false);
147 if (ScheduleDate_Model
::insert_downtimes($objects, $object_type, $start_time, $end_time, $fixed, $duration, $comment) !== false) {
148 return json
::ok("Downtime successfully scheduled");
150 return json
::fail("Failed to schedule downtime");
157 public function delete()
159 $this->auto_render
=false;
160 $schedule_id = $this->input
->post('schedule_id', false);
163 return json
::fail('Error: no schedule id provided');
166 if (ScheduleDate_Model
::delete_schedule($schedule_id) !== false) {
167 return json
::ok("Schedule deleted");
169 return json
::fail("Not authorized to delete schedule or it doesn't exist.");