Source
xxxxxxxxxx
632
632
}
633
633
}
634
634
else {
635
635
$error = _('a time unit is expected');
636
636
637
637
return false;
638
638
}
639
639
640
640
return true;
641
641
}
642
-
643
-
/**
644
-
* Validate "from" and "to" parameters for allowed time period.
645
-
*
646
-
* @param string from
647
-
* @param string to
648
-
*/
649
-
function validateTimeSelector($from, $to) {
650
-
$period_from = null;
651
-
$period_to = null;
652
-
$ts = [];
653
-
$ts['now'] = time();
654
-
$range_time_parser = new CRangeTimeParser();
655
-
656
-
if (($from !== '') && $range_time_parser->parse($from) == CParser::PARSE_SUCCESS) {
657
-
$period_from = $range_time_parser
658
-
->getDateTime(true)
659
-
->getTimestamp();
660
-
}
661
-
else {
662
-
error(_s('Incorrect value for field "%1$s": %2$s.', _s('From'), _('a date is expected')));
663
-
}
664
-
665
-
666
-
if (($to !== '') && $range_time_parser->parse($to) == CParser::PARSE_SUCCESS) {
667
-
$period_to = $range_time_parser
668
-
->getDateTime(true)
669
-
->getTimestamp();
670
-
}
671
-
else {
672
-
error(_s('Incorrect value for field "%1$s": %2$s.', _s('To'), _('a date is expected')));
673
-
}
674
-
675
-
if ($from !== '' && $to !== '' && $range_time_parser->parse($to) == CParser::PARSE_SUCCESS
676
-
&& $range_time_parser->parse($from) == CParser::PARSE_SUCCESS) {
677
-
foreach (['from' => $from, 'to' => $to] as $field => $value) {
678
-
$range_time_parser->parse($value);
679
-
680
-
$ts[$field] = $range_time_parser->getDateTime($field === 'from')->getTimestamp();
681
-
}
682
-
}
683
-
684
-
if ($from !== '' && $to !== '' && $range_time_parser->parse($to) == CParser::PARSE_SUCCESS
685
-
&& $range_time_parser->parse($from) == CParser::PARSE_SUCCESS) {
686
-
$period = $ts['to'] - $ts['from'] + 1;
687
-
$range_time_parser->parse('now-'.CSettingsHelper::get(CSettingsHelper::MAX_PERIOD));
688
-
$max_period = 1 + $ts['now'] - $range_time_parser->getDateTime(true)->getTimestamp();
689
-
690
-
if ($period_from !== null && $period_to !== null && $period_to < $period_from) {
691
-
error(_s('"%1$s" date must be less than "%2$s" date.', _('From'), _('To')));
692
-
}
693
-
elseif ($period < ZBX_MIN_PERIOD) {
694
-
error(_n('Minimum time period to display is %1$s minute.',
695
-
'Minimum time period to display is %1$s minutes.', (int)(ZBX_MIN_PERIOD / SEC_PER_MIN)
696
-
));
697
-
}
698
-
elseif ($period > $max_period) {
699
-
error(_n('Maximum time period to display is %1$s day.',
700
-
'Maximum time period to display is %1$s days.', (int)round($max_period / SEC_PER_DAY)
701
-
));
702
-
}
703
-
}
704
-
}