pandorafms/pandora_console/views/calendar/special_days.php

539 lines
18 KiB
PHP
Raw Normal View History

2021-11-02 17:49:45 +01:00
<?php
/**
* Calendar: Calendar list page.
*
* @category View
* @package Pandora FMS
* @subpackage Alert
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
2023-06-08 12:42:10 +02:00
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
2021-11-02 17:49:45 +01:00
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
2023-06-08 11:53:13 +02:00
* Copyright (c) 2005-2023 Pandora FMS
2023-06-08 13:19:01 +02:00
* Please see https://pandorafms.com/community/ for full contribution list
2021-11-02 17:49:45 +01:00
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation for version 2.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ============================================================================
*/
2021-11-03 10:59:00 +01:00
global $config;
\ui_require_css_file('wizard');
\enterprise_include_once('meta/include/functions_alerts_meta.php');
if (\is_metaconsole() === true) {
\alerts_meta_print_header($tabs);
} else {
// Header.
2023-03-07 15:59:36 +01:00
ui_print_standard_header(
__('Alerts'),
'images/gm_alerts.png',
false,
'alert_special_days',
true,
2023-03-07 15:59:36 +01:00
$tabs,
[
[
'link' => '',
2023-03-21 17:02:03 +01:00
'label' => __('Alerts'),
],
[
'link' => '',
2023-03-07 15:59:36 +01:00
'label' => __('Special days'),
],
]
);
}
$is_management_allowed = \is_management_allowed();
if ($is_management_allowed === false) {
if (\is_metaconsole() === false) {
$url_link = '<a target="_blank" href="'.ui_get_meta_url($url).'">';
$url_link .= __('metaconsole');
$url_link .= '</a>';
} else {
$url_link = __('any node');
}
\ui_print_warning_message(
__(
'This node is configured with centralized mode. All alert calendar information is read only. Go to %s to manage it.',
$url_link
)
);
}
2021-11-02 17:49:45 +01:00
if (empty($message) === false) {
echo $message;
}
$inputs = [];
// Name.
$inputs[] = [
'label' => __('iCalendar(.ics) file'),
'arguments' => [
'name' => 'ical_file',
'type' => 'file',
'columns' => 25,
'rows' => 10,
2021-11-03 17:30:54 +01:00
'options' => ['required' => 1],
2021-11-02 17:49:45 +01:00
],
2023-03-07 15:59:36 +01:00
'class' => 'flex flex_column',
2021-11-02 17:49:45 +01:00
];
$days = [];
$days['monday'] = __('Monday');
$days['tuesday'] = __('Tuesday');
$days['wednesday'] = __('Wednesday');
$days['thursday'] = __('Thursday');
$days['friday'] = __('Friday');
$days['saturday'] = __('Saturday');
$days['sunday'] = __('Sunday');
// Same day of the week.
$inputs[] = [
'label' => __('Same day of the week'),
'arguments' => [
'name' => 'day_code',
'type' => 'select',
'fields' => $days,
],
2023-03-07 15:59:36 +01:00
'class' => 'mrgn_right_20px',
2021-11-02 17:49:45 +01:00
];
// Group.
$inputs[] = [
'label' => __('Group'),
'arguments' => [
'type' => 'select_groups',
'returnAllGroup' => true,
'name' => 'id_group',
],
2023-03-07 15:59:36 +01:00
'class' => 'mrgn_right_20px',
2021-11-02 17:49:45 +01:00
];
// Group.
$inputs[] = [
'label' => __('Overwrite').ui_print_help_tip(
__('Check this box, if you want to overwrite existing same days.'),
true
),
'arguments' => [
'type' => 'checkbox',
'name' => 'overwrite',
'id' => 'overwrite',
'disabled_hidden' => true,
],
2023-03-07 15:59:36 +01:00
'class' => 'flex flex_column',
2021-11-02 17:49:45 +01:00
];
// Submit.
$inputs[] = [
'arguments' => [
'name' => 'button',
'label' => __('Upload'),
'type' => 'submit',
2023-03-07 15:59:36 +01:00
'attributes' => [
'icon' => 'wand',
'class' => 'mini',
],
2021-11-02 17:49:45 +01:00
],
];
if ($is_management_allowed === true) {
// Print form.
2023-03-07 15:59:36 +01:00
$form_upload = HTML::printForm(
[
'form' => [
'action' => $url.'&op=upload_ical&id='.$id_calendar,
'method' => 'POST',
'id' => 'icalendar-special-days',
'enctype' => 'multipart/form-data',
2023-03-07 15:59:36 +01:00
'class' => 'calendar-upload-form',
],
'inputs' => $inputs,
2021-11-02 17:49:45 +01:00
],
2023-03-07 15:59:36 +01:00
true
);
ui_toggle(
$form_upload,
'<span class="subsection_header_title">'.__('Upload').'</span>',
__('Upload'),
'upload',
true,
false,
'',
'white-box-content no_border',
'filter-datatable-main box-flat white_table_graph fixed_filter_bar '
);
}
2021-11-02 17:49:45 +01:00
$this_year = date('Y');
$this_month = date('m');
$filter = [];
if (!is_user_admin($config['id_user'])) {
$filter['id_group'] = array_keys(users_get_groups(false, 'LM'));
}
2021-11-03 17:30:54 +01:00
$url = $url.'&id_calendar='.$id_calendar;
2021-11-02 17:49:45 +01:00
// Show display range.
$html = "<table cellpadding='4' cellspacing='4' width='100%' margin-bottom: 10px;'><tr><td>".__('Display range: ');
if ($display_range) {
$html .= '<a href="'.$url.'">['.__('Default').']</a>&nbsp;&nbsp;';
if ($display_range > 1970) {
$html .= '<a href="'.$url.'&display_range=';
$html .= ($display_range - 1);
$html .= '">&lt;&lt;&nbsp;</a>';
}
$html .= '<a href="'.$url.'&display_range='.$display_range.'" class="bolder">['.$display_range.']</a>';
$html .= '<a href="'.$url.'&display_range=';
$html .= ($display_range + 1);
$html .= '">&nbsp;&gt;&gt;</a>';
} else {
$html .= '<a href="'.$url.'" class="bolder">['.__('Default').']</a>&nbsp;&nbsp;';
$html .= '<a href="'.$url.'&display_range=';
$html .= ($this_year - 1);
$html .= '">&lt;&lt;&nbsp;</a>';
$html .= '<a href="'.$url.'&display_range=';
$html .= $this_year;
$html .= '">[';
$html .= $this_year;
$html .= ']</a>';
$html .= '<a href="'.$url.'&display_range=';
$html .= ($this_year + 1);
$html .= '">&nbsp;&gt;&gt;</a>';
}
$html .= '</td></tr>';
echo $html;
// Show calendar.
for ($month = 1; $month <= 12; $month++) {
if ($display_range) {
$display_month = $month;
$display_year = $display_range;
} else {
$display_month = ($this_month + $month - 1);
$display_year = $this_year;
}
if ($display_month > 12) {
$display_month -= 12;
$display_year++;
}
$cal_table = new stdClass();
$cal_table->width = '100%';
2023-03-07 15:59:36 +01:00
$cal_table->class = 'databox data special-days-thead';
2021-11-02 17:49:45 +01:00
$cal_table->data = [];
$cal_table->head = [];
$cal_table->head[0] = __('Sun');
$cal_table->head[1] = __('Mon');
$cal_table->head[2] = __('Tue');
$cal_table->head[3] = __('Wed');
$cal_table->head[4] = __('Thu');
$cal_table->head[5] = __('Fri');
$cal_table->head[6] = __('Sat');
$cal_table->cellstyle = [];
$cal_table->size = [];
$cal_table->size[0] = '14%';
$cal_table->size[1] = '14%';
$cal_table->size[2] = '14%';
$cal_table->size[3] = '14%';
$cal_table->size[4] = '14%';
$cal_table->size[5] = '14%';
$cal_table->size[6] = '14%';
$cal_table->align = [];
$cal_table->border = '1';
2023-03-07 15:59:36 +01:00
$cal_table->titlestyle = 'text-align:center;';
2021-11-02 17:49:45 +01:00
switch ($display_month) {
case 1:
$cal_table->title = __('January');
break;
case 2:
$cal_table->title = __('February');
break;
case 3:
$cal_table->title = __('March');
break;
case 4:
$cal_table->title = __('April');
break;
case 5:
$cal_table->title = __('May');
break;
case 6:
$cal_table->title = __('June');
break;
case 7:
$cal_table->title = __('July');
break;
case 8:
$cal_table->title = __('August');
break;
case 9:
$cal_table->title = __('September');
break;
case 10:
$cal_table->title = __('October');
break;
case 11:
$cal_table->title = __('November');
break;
case 12:
$cal_table->title = __('December');
break;
default:
// Not possible.
break;
}
$cal_table->title .= ' / '.$display_year;
$last_day = date('j', mktime(0, 0, 0, ($display_month + 1), 0, $display_year));
$cal_line = 0;
for ($day = 1; $day < ($last_day + 1); $day++) {
$week = date('w', mktime(0, 0, 0, $display_month, $day, $display_year));
if ($cal_line == 0 && $week != 0 && $day == 1) {
for ($i = 0; $i < $week; $i++) {
$cal_table->cellstyle[$cal_line][$i] = 'font-size: 18px;';
$cal_table->data[$cal_line][$i] = '-';
}
}
2023-08-08 18:04:30 +02:00
if ($week == 0 || $week == 6 || isset($specialDays[$display_year][$display_month][$day]) === true) {
2021-11-02 17:49:45 +01:00
$cal_table->cellstyle[$cal_line][$week] = 'color: red;';
}
$date = sprintf('%04d-%02d-%02d', $display_year, $display_month, $day);
$date_wildcard = sprintf('0001-%02d-%02d', $display_month, $day);
$cal_table->cellstyle[$cal_line][$week] .= 'font-size: 18px;';
$cal_table->data[$cal_line][$week] = $day.'&nbsp;';
2023-08-08 18:04:30 +02:00
if ($is_management_allowed === true && isset($specialDays[$display_year][$display_month][$day]) === false) {
$cal_table->data[$cal_line][$week] .= '<a href="'.$url.'&op=edit&date='.$date.'" title=';
$cal_table->data[$cal_line][$week] .= __('Create');
$cal_table->data[$cal_line][$week] .= '>'.html_print_image(
'images/add_mc.png',
true,
['class' => 'invert_filter']
).'</a>';
}
2021-11-02 17:49:45 +01:00
2021-11-03 10:59:00 +01:00
if (empty($specialDays) === false && isset($specialDays[$display_year][$display_month][$day]) === true) {
2021-11-02 17:49:45 +01:00
$cal_table->data[$cal_line][$week] .= '<br>';
2021-11-03 10:59:00 +01:00
foreach ($specialDays[$display_year][$display_month][$day] as $special_day) {
2021-11-02 17:49:45 +01:00
// Only show description if is filled.
$cal_table->data[$cal_line][$week] .= '<div class="note-special-day">';
$cal_table->data[$cal_line][$week] .= '<div>';
$cal_table->data[$cal_line][$week] .= ui_print_group_icon(
$special_day['id_group'],
true
);
if (empty($special_day['description']) === false) {
$cal_table->data[$cal_line][$week] .= ui_print_help_tip($special_day['description'], true);
}
if ($special_day['date'] == $date_wildcard) {
$cal_table->data[$cal_line][$week] .= '(';
$cal_table->data[$cal_line][$week] .= ui_print_help_tip(
'This is valid every year. However, this will be ignored if indivisual setting for the same group is available.',
true
);
$cal_table->data[$cal_line][$week] .= ') ';
}
$cal_table->data[$cal_line][$week] .= __('As ');
2021-11-03 10:59:00 +01:00
switch ($special_day['day_code']) {
case '1':
2021-11-02 17:49:45 +01:00
$cal_table->data[$cal_line][$week] .= __('Monday');
break;
2021-11-03 10:59:00 +01:00
case '2':
2021-11-02 17:49:45 +01:00
$cal_table->data[$cal_line][$week] .= __('Tuesday');
break;
2021-11-03 10:59:00 +01:00
case '3':
2021-11-02 17:49:45 +01:00
$cal_table->data[$cal_line][$week] .= __('Wednesday');
break;
2021-11-03 10:59:00 +01:00
case '4':
2021-11-02 17:49:45 +01:00
$cal_table->data[$cal_line][$week] .= __('Thursday');
break;
2021-11-03 10:59:00 +01:00
case '5':
2021-11-02 17:49:45 +01:00
$cal_table->data[$cal_line][$week] .= __('Friday');
break;
2021-11-03 10:59:00 +01:00
case '6':
2021-11-02 17:49:45 +01:00
$cal_table->data[$cal_line][$week] .= __('Saturday');
break;
2021-11-03 10:59:00 +01:00
case '7':
2021-11-02 17:49:45 +01:00
$cal_table->data[$cal_line][$week] .= __('Sunday');
break;
2021-11-03 10:59:00 +01:00
case '8':
$cal_table->data[$cal_line][$week] .= __('Holidays');
break;
2021-11-02 17:49:45 +01:00
default:
// Not possible.
break;
}
$cal_table->data[$cal_line][$week] .= '</div>';
$cal_table->data[$cal_line][$week] .= '<div>';
2021-11-03 10:59:00 +01:00
if ($special_day['id_group'] || (users_can_manage_group_all('LM') === true && $special_day['id_group'] == 0)) {
2021-11-02 17:49:45 +01:00
$script_delete = '';
$dateformat = date_create($special_day['date']);
$options_zoom = htmlspecialchars(
json_encode(
[
'date' => $special_day['date'],
'id_group' => $special_day['id_group'],
2021-11-03 10:59:00 +01:00
'day_code' => $special_day['day_code'],
2021-11-04 09:55:37 +01:00
'id_calendar' => $special_day['id_calendar'],
2021-11-02 17:49:45 +01:00
'btn_ok_text' => __('Create'),
'btn_cancel_text' => __('Cancel'),
'title' => date_format($dateformat, 'd M Y'),
'url' => ui_get_full_url('ajax.php', false, false, false),
2021-11-03 10:59:00 +01:00
'page' => $ajax_url,
2021-11-02 17:49:45 +01:00
'loading' => __('Loading, this operation might take several minutes...'),
]
),
ENT_QUOTES,
'UTF-8'
);
$onclick_zoom = 'load_templates_alerts_special_days('.$options_zoom.')';
$cal_table->data[$cal_line][$week] .= '<a href="#" onclick="'.$onclick_zoom.'"';
$cal_table->data[$cal_line][$week] .= 'title="';
$cal_table->data[$cal_line][$week] .= __('Show templates');
$cal_table->data[$cal_line][$week] .= '">';
$cal_table->data[$cal_line][$week] .= html_print_image(
'images/zoom.png',
true,
2023-07-06 17:22:49 +02:00
['class' => 'invert_filter special_days']
2021-11-02 17:49:45 +01:00
).'</a>';
if ($is_management_allowed === true) {
$cal_table->data[$cal_line][$week] .= '<a href="'.$url.'&op=edit&id='.$special_day['id'].'" title=';
$cal_table->data[$cal_line][$week] .= __('Edit');
$cal_table->data[$cal_line][$week] .= '>'.html_print_image(
2023-03-10 12:40:21 +01:00
'images/edit.svg',
true,
2023-07-06 17:22:49 +02:00
['class' => 'invert_filter main_menu_icon']
).'</a> &nbsp;';
$url_delete = $url.'&op=delete&id='.$special_day['id'];
$script_delete = 'if (!confirm(\''.__('Are you sure?').'\')) return false;';
$cal_table->data[$cal_line][$week] .= '<a href="'.$url_delete.'"';
$cal_table->data[$cal_line][$week] .= ' onClick="'.$script_delete.'"';
$cal_table->data[$cal_line][$week] .= 'title="';
$cal_table->data[$cal_line][$week] .= __('Remove');
$cal_table->data[$cal_line][$week] .= '">';
$cal_table->data[$cal_line][$week] .= html_print_image(
2023-03-10 12:40:21 +01:00
'images/delete.svg',
true,
2023-07-06 17:22:49 +02:00
['class' => 'invert_filter main_menu_icon']
).'</a>';
}
2021-11-02 17:49:45 +01:00
}
$cal_table->data[$cal_line][$week] .= '</div>';
$cal_table->data[$cal_line][$week] .= '</div>';
}
}
if ($week == 6) {
$cal_line++;
}
}
for ($padding = ($week + 1); $padding <= 6; $padding++) {
$cal_table->cellstyle[$cal_line][$padding] = 'font-size: 18px;';
$cal_table->data[$cal_line][$padding] = '-';
}
html_print_table($cal_table);
}
if ((bool) check_acl($config['id_user'], 0, 'LM') === true) {
2023-03-07 15:59:36 +01:00
$form_create = HTML::printForm(
2021-11-02 17:49:45 +01:00
[
'form' => [
'action' => $url.'&op=edit',
'method' => 'POST',
],
'inputs' => [
[
'arguments' => [
'name' => 'button',
'label' => __('Create'),
'type' => 'submit',
2023-03-07 15:59:36 +01:00
'attributes' => ['icon' => 'wand'],
2021-11-02 17:49:45 +01:00
],
],
],
2023-03-07 15:59:36 +01:00
],
true
2021-11-02 17:49:45 +01:00
);
2023-03-07 15:59:36 +01:00
html_print_action_buttons($form_create);
2021-11-02 17:49:45 +01:00
}
echo '<div id="modal-alert-templates" class="invisible"></div>';
2021-11-03 10:59:00 +01:00
ui_require_javascript_file('pandora_alerts');
2021-11-03 10:59:00 +01:00
?>
<script type="text/javascript">
$(document).ready (function () {
2021-11-03 17:30:54 +01:00
$("#submit-button").click (function (e) {
2021-11-03 10:59:00 +01:00
e.preventDefault();
load_templates_alerts_special_days({
date: '',
id_group: $("#id_group").val(),
day_code: $("#day_code").val(),
2021-11-04 09:55:37 +01:00
id_calendar: '<?php echo $id_calendar; ?>',
2021-11-03 10:59:00 +01:00
btn_ok_text: '<?php echo __('Create'); ?>',
btn_cancel_text: '<?php echo __('Cancel'); ?>',
title: '<?php echo __('Load calendar'); ?>',
url: '<?php echo ui_get_full_url('ajax.php', false, false, false); ?>',
page: "godmode/alerts/alert_special_days",
loading: '<?php echo __('Loading, this operation might take several minutes...'); ?>',
name_form: 'icalendar-special-days'
});
});
});
</script>