alert template schedule pandora_enterprise#3943
This commit is contained in:
parent
2e5f778703
commit
392a9223e8
|
@ -284,6 +284,7 @@ function update_template($step)
|
||||||
|
|
||||||
$result = alerts_update_alert_template($id, $values);
|
$result = alerts_update_alert_template($id, $values);
|
||||||
} else if ($step == 2) {
|
} else if ($step == 2) {
|
||||||
|
// TODO: Days.
|
||||||
$monday = (bool) get_parameter('monday');
|
$monday = (bool) get_parameter('monday');
|
||||||
$tuesday = (bool) get_parameter('tuesday');
|
$tuesday = (bool) get_parameter('tuesday');
|
||||||
$wednesday = (bool) get_parameter('wednesday');
|
$wednesday = (bool) get_parameter('wednesday');
|
||||||
|
@ -291,11 +292,14 @@ function update_template($step)
|
||||||
$friday = (bool) get_parameter('friday');
|
$friday = (bool) get_parameter('friday');
|
||||||
$saturday = (bool) get_parameter('saturday');
|
$saturday = (bool) get_parameter('saturday');
|
||||||
$sunday = (bool) get_parameter('sunday');
|
$sunday = (bool) get_parameter('sunday');
|
||||||
$special_day = (int) get_parameter('special_day');
|
|
||||||
$time_from = (string) get_parameter('time_from');
|
$time_from = (string) get_parameter('time_from');
|
||||||
$time_from = date('H:i:00', strtotime($time_from));
|
$time_from = date('H:i:00', strtotime($time_from));
|
||||||
$time_to = (string) get_parameter('time_to');
|
$time_to = (string) get_parameter('time_to');
|
||||||
$time_to = date('H:i:00', strtotime($time_to));
|
$time_to = date('H:i:00', strtotime($time_to));
|
||||||
|
|
||||||
|
$schedule = get_parameter('schedule');
|
||||||
|
|
||||||
|
$special_day = (int) get_parameter('special_day');
|
||||||
$threshold = (int) get_parameter('threshold');
|
$threshold = (int) get_parameter('threshold');
|
||||||
$max_alerts = (int) get_parameter('max_alerts');
|
$max_alerts = (int) get_parameter('max_alerts');
|
||||||
$min_alerts = (int) get_parameter('min_alerts');
|
$min_alerts = (int) get_parameter('min_alerts');
|
||||||
|
@ -312,14 +316,24 @@ function update_template($step)
|
||||||
$default_action = null;
|
$default_action = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hd($schedule);
|
||||||
|
|
||||||
$values = [
|
$values = [
|
||||||
'monday' => $monday,
|
// 'monday' => $monday,
|
||||||
'tuesday' => $tuesday,
|
// 'tuesday' => $tuesday,
|
||||||
'wednesday' => $wednesday,
|
// 'wednesday' => $wednesday,
|
||||||
'thursday' => $thursday,
|
// 'thursday' => $thursday,
|
||||||
'friday' => $friday,
|
// 'friday' => $friday,
|
||||||
'saturday' => $saturday,
|
// 'saturday' => $saturday,
|
||||||
'sunday' => $sunday,
|
// 'sunday' => $sunday,
|
||||||
|
// 'time_from' => $time_from,
|
||||||
|
// 'time_to' => $time_to,
|
||||||
|
'schedule' => json_encode(
|
||||||
|
json_decode(
|
||||||
|
io_safe_output($schedule),
|
||||||
|
true
|
||||||
|
)
|
||||||
|
),
|
||||||
'special_day' => $special_day,
|
'special_day' => $special_day,
|
||||||
'time_threshold' => $threshold,
|
'time_threshold' => $threshold,
|
||||||
'id_alert_action' => $default_action,
|
'id_alert_action' => $default_action,
|
||||||
|
@ -334,20 +348,6 @@ function update_template($step)
|
||||||
'disable_event' => $disable_event,
|
'disable_event' => $disable_event,
|
||||||
];
|
];
|
||||||
|
|
||||||
// Different datetimes format for oracle
|
|
||||||
switch ($config['dbtype']) {
|
|
||||||
case 'mysql':
|
|
||||||
case 'postgresql':
|
|
||||||
$values['time_from'] = $time_from;
|
|
||||||
$values['time_to'] = $time_to;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'oracle':
|
|
||||||
$values['time_from'] = "#to_date('".$time_from."','hh24:mi:ss')";
|
|
||||||
$values['time_to'] = "#to_date('".$time_to."','hh24:mi:ss')";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = alerts_update_alert_template($id, $values);
|
$result = alerts_update_alert_template($id, $values);
|
||||||
} else if ($step == 3) {
|
} else if ($step == 3) {
|
||||||
$recovery_notify = (bool) get_parameter('recovery_notify');
|
$recovery_notify = (bool) get_parameter('recovery_notify');
|
||||||
|
@ -412,6 +412,7 @@ $type = '';
|
||||||
$value = '';
|
$value = '';
|
||||||
$max = '';
|
$max = '';
|
||||||
$min = '';
|
$min = '';
|
||||||
|
// TODO: Remove.
|
||||||
$time_from = '12:00:00';
|
$time_from = '12:00:00';
|
||||||
$time_to = '12:00:00';
|
$time_to = '12:00:00';
|
||||||
$monday = true;
|
$monday = true;
|
||||||
|
@ -421,6 +422,8 @@ $thursday = true;
|
||||||
$friday = true;
|
$friday = true;
|
||||||
$saturday = true;
|
$saturday = true;
|
||||||
$sunday = true;
|
$sunday = true;
|
||||||
|
|
||||||
|
$schedule = null;
|
||||||
$special_day = 0;
|
$special_day = 0;
|
||||||
$default_action = 0;
|
$default_action = 0;
|
||||||
$fields = [];
|
$fields = [];
|
||||||
|
@ -555,6 +558,8 @@ if ($id && ! $create_template) {
|
||||||
$max = $template['max_value'];
|
$max = $template['max_value'];
|
||||||
$min = $template['min_value'];
|
$min = $template['min_value'];
|
||||||
$matches = $template['matches_value'];
|
$matches = $template['matches_value'];
|
||||||
|
|
||||||
|
// TODO: Remove.
|
||||||
$time_from = $template['time_from'];
|
$time_from = $template['time_from'];
|
||||||
$time_to = $template['time_to'];
|
$time_to = $template['time_to'];
|
||||||
$monday = (bool) $template['monday'];
|
$monday = (bool) $template['monday'];
|
||||||
|
@ -564,6 +569,8 @@ if ($id && ! $create_template) {
|
||||||
$friday = (bool) $template['friday'];
|
$friday = (bool) $template['friday'];
|
||||||
$saturday = (bool) $template['saturday'];
|
$saturday = (bool) $template['saturday'];
|
||||||
$sunday = (bool) $template['sunday'];
|
$sunday = (bool) $template['sunday'];
|
||||||
|
|
||||||
|
$schedule = $template['schedule'];
|
||||||
$special_day = (int) $template['special_day'];
|
$special_day = (int) $template['special_day'];
|
||||||
$max_alerts = $template['max_alerts'];
|
$max_alerts = $template['max_alerts'];
|
||||||
$min_alerts = $template['min_alerts'];
|
$min_alerts = $template['min_alerts'];
|
||||||
|
@ -613,70 +620,7 @@ if ($step == 2) {
|
||||||
$show_matches = false;
|
$show_matches = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Firing conditions and events.
|
$table->data[0][0] = __('Use special days list');
|
||||||
$table->colspan = [];
|
|
||||||
$table->data[0][0] = __('Days of week');
|
|
||||||
$table->data[0][1] = __('Mon');
|
|
||||||
$table->data[0][1] .= html_print_checkbox(
|
|
||||||
'monday',
|
|
||||||
1,
|
|
||||||
$monday,
|
|
||||||
true,
|
|
||||||
(!$is_management_allowed | $disabled)
|
|
||||||
);
|
|
||||||
$table->data[0][1] .= __('Tue');
|
|
||||||
$table->data[0][1] .= html_print_checkbox(
|
|
||||||
'tuesday',
|
|
||||||
1,
|
|
||||||
$tuesday,
|
|
||||||
true,
|
|
||||||
(!$is_management_allowed | $disabled)
|
|
||||||
);
|
|
||||||
$table->data[0][1] .= __('Wed');
|
|
||||||
$table->data[0][1] .= html_print_checkbox(
|
|
||||||
'wednesday',
|
|
||||||
1,
|
|
||||||
$wednesday,
|
|
||||||
true,
|
|
||||||
(!$is_management_allowed | $disabled)
|
|
||||||
);
|
|
||||||
$table->data[0][1] .= __('Thu');
|
|
||||||
$table->data[0][1] .= html_print_checkbox(
|
|
||||||
'thursday',
|
|
||||||
1,
|
|
||||||
$thursday,
|
|
||||||
true,
|
|
||||||
(!$is_management_allowed | $disabled)
|
|
||||||
);
|
|
||||||
$table->data[0][1] .= __('Fri');
|
|
||||||
$table->data[0][1] .= html_print_checkbox(
|
|
||||||
'friday',
|
|
||||||
1,
|
|
||||||
$friday,
|
|
||||||
true,
|
|
||||||
(!$is_management_allowed | $disabled)
|
|
||||||
);
|
|
||||||
$table->data[0][1] .= __('Sat');
|
|
||||||
$table->data[0][1] .= html_print_checkbox(
|
|
||||||
'saturday',
|
|
||||||
1,
|
|
||||||
$saturday,
|
|
||||||
true,
|
|
||||||
(!$is_management_allowed | $disabled)
|
|
||||||
);
|
|
||||||
$table->data[0][1] .= __('Sun');
|
|
||||||
$table->data[0][1] .= html_print_checkbox(
|
|
||||||
'sunday',
|
|
||||||
1,
|
|
||||||
$sunday,
|
|
||||||
true,
|
|
||||||
(!$is_management_allowed | $disabled)
|
|
||||||
);
|
|
||||||
|
|
||||||
$table->colspan[0][1] = 3;
|
|
||||||
$table->data[0][1] = '<div id="calendar"></div>';
|
|
||||||
|
|
||||||
$table->data[1][0] = __('Use special days list');
|
|
||||||
$data_special_days = Calendar::calendars(
|
$data_special_days = Calendar::calendars(
|
||||||
// Fields.
|
// Fields.
|
||||||
[ '`talert_calendar`.*' ],
|
[ '`talert_calendar`.*' ],
|
||||||
|
@ -696,7 +640,7 @@ if ($step == 2) {
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
$table->data[1][1] = html_print_select(
|
$table->data[0][1] = html_print_select(
|
||||||
$data_special_days,
|
$data_special_days,
|
||||||
'special_day',
|
'special_day',
|
||||||
$special_day,
|
$special_day,
|
||||||
|
@ -710,46 +654,12 @@ if ($step == 2) {
|
||||||
(!$is_management_allowed | $disabled)
|
(!$is_management_allowed | $disabled)
|
||||||
);
|
);
|
||||||
|
|
||||||
$table->data[2][0] = __('Time from');
|
// Firing conditions and events.
|
||||||
$table->data[2][1] = html_print_input_text(
|
$table->colspan = [];
|
||||||
'time_from',
|
$table->data[1][0] = __('Schedule');
|
||||||
$time_from,
|
$table->colspan[1][1] = 3;
|
||||||
'',
|
$table->data[1][1] = '<div id="calendar_map"></div>';
|
||||||
7,
|
$table->data[1][1] .= html_print_input_hidden('schedule', $schedule, true);
|
||||||
8,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
false,
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
(!$is_management_allowed | $disabled)
|
|
||||||
);
|
|
||||||
$table->data[2][2] = __('Time to');
|
|
||||||
$table->data[2][3] = html_print_input_text(
|
|
||||||
'time_to',
|
|
||||||
$time_to,
|
|
||||||
'',
|
|
||||||
7,
|
|
||||||
8,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
false,
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
(!$is_management_allowed | $disabled)
|
|
||||||
);
|
|
||||||
|
|
||||||
$table->colspan['threshold'][1] = 3;
|
$table->colspan['threshold'][1] = 3;
|
||||||
$table->data['threshold'][0] = __('Time threshold');
|
$table->data['threshold'][0] = __('Time threshold');
|
||||||
|
@ -958,6 +868,8 @@ if ($step == 2) {
|
||||||
);
|
);
|
||||||
$table->colspan['example'][1] = 4;
|
$table->colspan['example'][1] = 4;
|
||||||
} else if ($step == 3) {
|
} else if ($step == 3) {
|
||||||
|
hd($_POST);
|
||||||
|
|
||||||
$table->style[0] = 'font-weight: bold; vertical-align: middle';
|
$table->style[0] = 'font-weight: bold; vertical-align: middle';
|
||||||
$table->style[1] = 'font-weight: bold; vertical-align: top';
|
$table->style[1] = 'font-weight: bold; vertical-align: top';
|
||||||
$table->style[2] = 'font-weight: bold; vertical-align: top';
|
$table->style[2] = 'font-weight: bold; vertical-align: top';
|
||||||
|
@ -1548,7 +1460,11 @@ if ($step == 2) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var calendarEl = document.getElementById('calendar');
|
//time_from, time_to, monday, tuesday, wednesday, thursday, friday, saturday, sunday
|
||||||
|
var eventsBBDD = $("#hidden-schedule").val();
|
||||||
|
var events = loadEventBBDD(eventsBBDD);
|
||||||
|
|
||||||
|
var calendarEl = document.getElementById('calendar_map');
|
||||||
var settings = {
|
var settings = {
|
||||||
timeFormat: '<?php echo TIME_FORMAT_JS; ?>',
|
timeFormat: '<?php echo TIME_FORMAT_JS; ?>',
|
||||||
timeOnlyTitle: '<?php echo __('Choose time'); ?>',
|
timeOnlyTitle: '<?php echo __('Choose time'); ?>',
|
||||||
|
@ -1561,7 +1477,7 @@ if ($step == 2) {
|
||||||
url: '<?php echo ui_get_full_url('ajax.php', false, false, false); ?>'
|
url: '<?php echo ui_get_full_url('ajax.php', false, false, false); ?>'
|
||||||
}
|
}
|
||||||
|
|
||||||
var calendar = fullCalendarPandora(calendarEl, settings);
|
var calendar = fullCalendarPandora(calendarEl, settings, events);
|
||||||
calendar.render();
|
calendar.render();
|
||||||
<?php
|
<?php
|
||||||
} else if ($step == 3) {
|
} else if ($step == 3) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* globals $, FullCalendar, uniqId, confirmDialog*/
|
/* globals $, FullCalendar, uniqId, confirmDialog*/
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
function fullCalendarPandora(calendarEl, settings) {
|
function fullCalendarPandora(calendarEl, settings, initialEvents) {
|
||||||
var calendar = new FullCalendar.Calendar(calendarEl, {
|
var calendar = new FullCalendar.Calendar(calendarEl, {
|
||||||
height: 625,
|
height: 625,
|
||||||
headerToolbar: {
|
headerToolbar: {
|
||||||
|
@ -36,7 +36,7 @@ function fullCalendarPandora(calendarEl, settings) {
|
||||||
eventColor: "#82b92e",
|
eventColor: "#82b92e",
|
||||||
editable: true,
|
editable: true,
|
||||||
dayMaxEvents: false,
|
dayMaxEvents: false,
|
||||||
events: [],
|
events: initialEvents,
|
||||||
select: function(info) {
|
select: function(info) {
|
||||||
var nextDay = info.start.getDay() === 6 ? 0 : info.start.getDay() + 1;
|
var nextDay = info.start.getDay() === 6 ? 0 : info.start.getDay() + 1;
|
||||||
if (
|
if (
|
||||||
|
@ -46,6 +46,7 @@ function fullCalendarPandora(calendarEl, settings) {
|
||||||
recalculate_events(calendar, {}, info.start, info.end, true);
|
recalculate_events(calendar, {}, info.start, info.end, true);
|
||||||
}
|
}
|
||||||
calendar.unselect();
|
calendar.unselect();
|
||||||
|
save_data_input(calendar);
|
||||||
},
|
},
|
||||||
selectAllow: function(info) {
|
selectAllow: function(info) {
|
||||||
var nextDay = info.start.getDay() === 6 ? 0 : info.start.getDay() + 1;
|
var nextDay = info.start.getDay() === 6 ? 0 : info.start.getDay() + 1;
|
||||||
|
@ -85,10 +86,11 @@ function fullCalendarPandora(calendarEl, settings) {
|
||||||
info.event.end,
|
info.event.end,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
save_data_input(calendar);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
eventDragStop: function(info) {
|
eventDragStop: function(info) {
|
||||||
var trashEl = $("#calendar");
|
var trashEl = $("#calendar_map");
|
||||||
var ofs = trashEl.offset();
|
var ofs = trashEl.offset();
|
||||||
|
|
||||||
var x1 = ofs.left;
|
var x1 = ofs.left;
|
||||||
|
@ -104,6 +106,7 @@ function fullCalendarPandora(calendarEl, settings) {
|
||||||
) {
|
) {
|
||||||
// Remove event.
|
// Remove event.
|
||||||
info.event.remove();
|
info.event.remove();
|
||||||
|
save_data_input(calendar);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
eventResize: function(info) {
|
eventResize: function(info) {
|
||||||
|
@ -121,6 +124,7 @@ function fullCalendarPandora(calendarEl, settings) {
|
||||||
info.event.end,
|
info.event.end,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
save_data_input(calendar);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
eventClick: function(info) {
|
eventClick: function(info) {
|
||||||
|
@ -234,6 +238,7 @@ function fullCalendarPandora(calendarEl, settings) {
|
||||||
// Remove event.
|
// Remove event.
|
||||||
info.event.remove();
|
info.event.remove();
|
||||||
}
|
}
|
||||||
|
save_data_input(calendar);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -309,3 +314,112 @@ function recalculate_events(calendar, newEvent, from, to, create) {
|
||||||
newEvent.setDates(from, to);
|
newEvent.setDates(from, to);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function save_data_input(calendar) {
|
||||||
|
var allEvents = calendar.getEvents();
|
||||||
|
var data = {};
|
||||||
|
var day_names = [
|
||||||
|
"sunday",
|
||||||
|
"monday",
|
||||||
|
"tuesday",
|
||||||
|
"wednesday",
|
||||||
|
"thursday",
|
||||||
|
"friday",
|
||||||
|
"saturday"
|
||||||
|
];
|
||||||
|
allEvents.forEach(function(event) {
|
||||||
|
var obj = {
|
||||||
|
start: time_format(event.start),
|
||||||
|
end: time_format(event.end)
|
||||||
|
};
|
||||||
|
if (data[day_names[event.start.getDay()]] == undefined) {
|
||||||
|
data[day_names[event.start.getDay()]] = [];
|
||||||
|
}
|
||||||
|
data[day_names[event.start.getDay()]].push(obj);
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#hidden-schedule").val(JSON.stringify(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
function loadEventBBDD(events) {
|
||||||
|
console.log(events);
|
||||||
|
if (events === null || events === "") {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
var current_day = new Date();
|
||||||
|
|
||||||
|
var day_names = [
|
||||||
|
"monday",
|
||||||
|
"tuesday",
|
||||||
|
"wednesday",
|
||||||
|
"thursday",
|
||||||
|
"friday",
|
||||||
|
"saturday",
|
||||||
|
"sunday",
|
||||||
|
"sun"
|
||||||
|
];
|
||||||
|
|
||||||
|
var keys_days_names = {
|
||||||
|
monday: 0,
|
||||||
|
tuesday: 1,
|
||||||
|
wednesday: 2,
|
||||||
|
thursday: 3,
|
||||||
|
friday: 4,
|
||||||
|
saturday: 5,
|
||||||
|
sunday: 6,
|
||||||
|
sun: 7
|
||||||
|
};
|
||||||
|
|
||||||
|
var dates = [];
|
||||||
|
day_names.forEach(function(element, i) {
|
||||||
|
dates[element] = getDays(current_day, i);
|
||||||
|
});
|
||||||
|
|
||||||
|
var result = [];
|
||||||
|
Object.entries(JSON.parse(events)).forEach(function(element) {
|
||||||
|
var day_string = element[0];
|
||||||
|
var events_day = element[1];
|
||||||
|
events_day.forEach(function(event) {
|
||||||
|
if (event != null) {
|
||||||
|
var time_from = event.start.split(":");
|
||||||
|
var time_to = event.end.split(":");
|
||||||
|
var end = dates[day_string].setHours(
|
||||||
|
time_to[0],
|
||||||
|
time_to[1],
|
||||||
|
time_to[2],
|
||||||
|
0
|
||||||
|
);
|
||||||
|
if (event.end === "00:00:00") {
|
||||||
|
end = dates[day_names[keys_days_names[day_string] + 1]].setHours(
|
||||||
|
time_to[0],
|
||||||
|
time_to[1],
|
||||||
|
time_to[2],
|
||||||
|
0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
result.push({
|
||||||
|
title: "",
|
||||||
|
start: dates[day_string].setHours(
|
||||||
|
time_from[0],
|
||||||
|
time_from[1],
|
||||||
|
time_from[2],
|
||||||
|
0
|
||||||
|
),
|
||||||
|
end: end,
|
||||||
|
id: uniqId()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDays(d, i) {
|
||||||
|
d = new Date(d);
|
||||||
|
var day = d.getDay(),
|
||||||
|
diff = d.getDate() - day + i + (day == 0 ? -6 : 1);
|
||||||
|
return new Date(d.setDate(diff));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue