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_header
= $this->add_view('js_header');
62 $this->xtra_js
[] = 'application/media/js/jquery.datePicker.js';
63 $this->xtra_js
[] = 'application/media/js/jquery.timePicker.js';
64 $this->xtra_js
[] = $this->add_path('reports/js/common.js');
65 $this->xtra_js
[] = $this->add_path('recurring_downtime/js/recurring_downtime.js');
67 $this->template
->js_header
->js
= $this->xtra_js
;
69 $this->template
->css_header
= $this->add_view('css_header');
70 $this->xtra_css
[] = $this->add_path('reports/css/datePicker.css');
71 $this->template
->css_header
->css
= $this->xtra_css
;
73 $date_format = cal
::get_calendar_format(true);
75 $schedule_id = arr
::search($_REQUEST, 'schedule_id', $id);
77 if (isset($recurring_downtime_error)) {
78 $this->template
->content
->error
= $recurring_downtime_error;
81 $this->template
->toolbar
= new Toolbar_Controller('Recurring scheduled downtimes');
83 $this->template
->toolbar
->button('<span class="icon-menu menu-schedulereports"></span>' . _('Schedules'), array('href' => url
::base(true) . 'listview?q=[recurring_downtimes]%20all'));
86 $schedule_info = array(
87 'start_time' => 12 * 3600,
88 'end_time' => 14 * 3600,
89 'duration' => 2 * 3600,
94 $schedule_info = array_merge($schedule_info, $_POST);
95 $schedule_info = new RecurringDowntime_Model($schedule_info, '', false);
97 else if ($schedule_id) {
98 $set = RecurringDowntimePool_Model
::get_by_query('[recurring_downtimes] id = ' . $schedule_id);
99 $schedule_info = $set->it(array('id', 'downtime_type', 'objects', 'start_time', 'end_time', 'duration', 'fixed', 'weekdays', 'months', 'comment'))->current();
101 $schedule_info = new RecurringDowntime_Model($schedule_info, '', false);
105 $this->js_strings
.= "var _report_data = " . json_encode(array('objects' => $schedule_info->get_objects(), 'downtime_type' => $schedule_info->get_downtime_type())) . "\n";
107 $this->js_strings
.= reports
::js_strings();
109 $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";
110 $this->js_strings
.= "var _form_err_empty_fields = '"._("Please Enter valid values in all required fields (marked by *) ")."';\n";
111 $this->js_strings
.= "var _form_err_bad_timeformat = '"._("Please Enter a valid %s value (hh:mm)")."';\n";
112 $this->js_strings
.= "var _schedule_error = '"._("An error occurred when trying to delete this schedule")."';\n";
114 $this->js_strings
.= "var _schedule_delete_ok = '"._("OK")."';\n";
115 $this->js_strings
.= "var _schedule_delete_success = '"._("The schedule was successfully removed")."';\n";
117 $this->js_strings
.= "var _form_field_time = '"._("time")."';\n";
118 $this->js_strings
.= "var _form_field_duration = '"._("duration")."';\n";
121 $template->day_names
= date
::day_names();
122 $template->day_index
= array(1, 2, 3, 4, 5, 6, 0);
123 $template->month_names
= date
::month_names();
125 $template->schedule_id
= $schedule_id;
126 $template->schedule_info
= $schedule_info;
128 $this->template
->inline_js
= $this->inline_js
;
129 $this->template
->js_strings
= $this->js_strings
;
135 public function delete()
137 $this->auto_render
=false;
138 $schedule_id = $this->input
->post('schedule_id', false);
141 return json
::fail('Error: no schedule id provided');
144 if (ScheduleDate_Model
::delete_schedule($schedule_id) !== false) {
145 return json
::ok("Schedule deleted");
147 return json
::fail("Not authorized to delete schedule or it doesn't exist.");