Merge branch 'ent-11682-no-se-configuran-las-listas-de-dias-especiales' into 'develop'
Ent 11682 No se configuran las listas de dias especiales See merge request artica/pandorafms!6220
This commit is contained in:
commit
bfd505a538
|
@ -262,7 +262,7 @@ $data[1] = '';
|
|||
$table_conditions->data[] = $data;
|
||||
|
||||
$data[0] = __('Use special days list');
|
||||
$data[1] = (isset($alert['special_day']) && $alert['special_day'] == 1) ? __('Yes') : __('No');
|
||||
$data[1] = (isset($template['special_day']) && (int) $template['special_day'] !== 0) ? __('Yes') : __('No');
|
||||
$table_conditions->data[] = $data;
|
||||
|
||||
$data[0] = __('Time threshold');
|
||||
|
|
|
@ -78,6 +78,17 @@ class SpecialDay extends Entity
|
|||
// Update.
|
||||
$updates = $this->fields;
|
||||
|
||||
$exist_special_days = $this->specialDays(
|
||||
[ '`talert_special_days`.*' ],
|
||||
['date_match' => $updates['date']]
|
||||
);
|
||||
|
||||
if (count($exist_special_days) > 0) {
|
||||
throw new \Exception(
|
||||
__('Already exist special day in this day.'),
|
||||
);
|
||||
}
|
||||
|
||||
$rs = \db_process_sql_update(
|
||||
$this->table,
|
||||
$updates,
|
||||
|
@ -94,6 +105,17 @@ class SpecialDay extends Entity
|
|||
// Creation.
|
||||
$inserts = $this->fields;
|
||||
|
||||
$exist_special_days = $this->specialDays(
|
||||
[ '`talert_special_days`.*' ],
|
||||
['date_match' => $inserts['date']]
|
||||
);
|
||||
|
||||
if (count($exist_special_days) > 0) {
|
||||
throw new \Exception(
|
||||
__('Already exist special day in this day.'),
|
||||
);
|
||||
}
|
||||
|
||||
// Clean null fields.
|
||||
foreach ($inserts as $k => $v) {
|
||||
if ($v === null) {
|
||||
|
|
|
@ -331,7 +331,7 @@ for ($month = 1; $month <= 12; $month++) {
|
|||
}
|
||||
}
|
||||
|
||||
if ($week == 0 || $week == 6) {
|
||||
if ($week == 0 || $week == 6 || isset($specialDays[$display_year][$display_month][$day]) === true) {
|
||||
$cal_table->cellstyle[$cal_line][$week] = 'color: red;';
|
||||
}
|
||||
|
||||
|
@ -341,7 +341,7 @@ for ($month = 1; $month <= 12; $month++) {
|
|||
$cal_table->cellstyle[$cal_line][$week] .= 'font-size: 18px;';
|
||||
$cal_table->data[$cal_line][$week] = $day.' ';
|
||||
|
||||
if ($is_management_allowed === true) {
|
||||
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(
|
||||
|
|
|
@ -108,6 +108,7 @@ $inputs[] = [
|
|||
'returnAllGroup' => $display_all_group,
|
||||
'name' => 'id_group',
|
||||
'selected' => $specialDay->id_group(),
|
||||
'required' => true,
|
||||
],
|
||||
];
|
||||
|
||||
|
|
|
@ -535,20 +535,22 @@ sub pandora_evaluate_alert ($$$$$$$;$$$$) {
|
|||
|
||||
# Get current time
|
||||
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time());
|
||||
|
||||
|
||||
my @weeks = ( 'none', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday', 'holiday');
|
||||
my $special_day;
|
||||
|
||||
# Check weekday
|
||||
if ($alert->{'special_day'}) {
|
||||
logger ($pa_config, "Checking special days '" . $alert->{'name'} . "'.", 10);
|
||||
my $date = sprintf("%4d%02d%02d", $year + 1900, $mon + 1, $mday);
|
||||
# '0001' means every year.
|
||||
my $date_every_year = sprintf("0001%02d%02d", $mon + 1, $mday);
|
||||
my $special_day = get_db_value ($dbh, 'SELECT day_code FROM talert_special_days WHERE (date = ? OR date = ?) AND (id_group = 0 OR id_group = ?) AND (id_calendar = ?) ORDER BY date DESC', $date, $date_every_year, $alert->{'id_group'}, $alert->{'special_day'});
|
||||
$special_day = get_db_value ($dbh, 'SELECT day_code FROM talert_special_days WHERE (date = ? OR date = ?) AND (id_group = 0 OR id_group = ?) AND (id_calendar = ?) ORDER BY date DESC', $date, $date_every_year, $alert->{'id_group'}, $alert->{'special_day'});
|
||||
|
||||
if (!defined($special_day)) {
|
||||
$special_day = 0;
|
||||
}
|
||||
|
||||
my @weeks = ( 'none', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday', 'holiday');
|
||||
if ($special_day != 0) {
|
||||
logger ($pa_config, $date . " is a special day for " . $alert->{'name'} . ". (as a " . $weeks[$special_day] . ")", 10);
|
||||
return $status if (!defined($alert->{$weeks[$special_day]}) || $alert->{$weeks[$special_day]} == 0);
|
||||
|
@ -565,6 +567,9 @@ sub pandora_evaluate_alert ($$$$$$$;$$$$) {
|
|||
my $schedule;
|
||||
if (defined($alert->{'schedule'}) && $alert->{'schedule'} ne '') {
|
||||
$schedule = PandoraFMS::Tools::p_decode_json($pa_config, $alert->{'schedule'});
|
||||
if ($special_day != 0) {
|
||||
return $status if (!defined($schedule->{$weeks[$special_day]}));
|
||||
}
|
||||
}
|
||||
|
||||
if (defined($schedule)) {
|
||||
|
@ -577,11 +582,18 @@ sub pandora_evaluate_alert ($$$$$$$;$$$$) {
|
|||
|
||||
my $time = sprintf ("%.2d:%.2d:%.2d", $hour, $min, $sec);
|
||||
|
||||
my $schedule_day;
|
||||
if ($special_day != 0 && defined($schedule->{$weeks[$special_day]})) {
|
||||
$schedule_day = $weeks[$special_day];
|
||||
} else {
|
||||
$schedule_day = $DayNames[$wday];
|
||||
}
|
||||
|
||||
#
|
||||
# Check time slots
|
||||
#
|
||||
my $inSlot = 0;
|
||||
foreach my $timeBlock (@{$schedule->{$DayNames[$wday]}}) {
|
||||
foreach my $timeBlock (@{$schedule->{$schedule_day}}) {
|
||||
if ($timeBlock->{'start'} eq $timeBlock->{'end'}) {
|
||||
# All day.
|
||||
$inSlot = 1;
|
||||
|
|
Loading…
Reference in New Issue