Exemplo n.º 1
0
function shedule2str($timeperiod)
{
    $timeperiod['hour'] = floor($timeperiod['start_time'] / SEC_PER_HOUR);
    $timeperiod['minute'] = floor(($timeperiod['start_time'] - $timeperiod['hour'] * SEC_PER_HOUR) / SEC_PER_MIN);
    if ($timeperiod['hour'] < 10) {
        $timeperiod['hour'] = '0' . $timeperiod['hour'];
    }
    if ($timeperiod['minute'] < 10) {
        $timeperiod['minute'] = '0' . $timeperiod['minute'];
    }
    if ($timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_ONETIME) {
        $str = zbx_date2str(DATE_TIME_FORMAT, $timeperiod['start_date']);
    } elseif ($timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_DAILY) {
        $str = _n('At %1$s:%2$s on every day', 'At %1$s:%2$s on every %3$s days', $timeperiod['hour'], $timeperiod['minute'], $timeperiod['every']);
    } elseif ($timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_WEEKLY) {
        $days = '';
        $dayofweek = zbx_num2bitstr($timeperiod['dayofweek'], true);
        $length = strlen($dayofweek);
        for ($i = 0; $i < $length; $i++) {
            if ($dayofweek[$i] == 1) {
                if (!zbx_empty($days)) {
                    $days .= ', ';
                }
                $days .= getDayOfWeekCaption($i + 1);
            }
        }
        $str = _n('At %1$s:%2$s on every %3$s of every week', 'At %1$s:%2$s on every %3$s of every %4$s weeks', $timeperiod['hour'], $timeperiod['minute'], $days, $timeperiod['every']);
    } elseif ($timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_MONTHLY) {
        $months = '';
        $month = zbx_num2bitstr($timeperiod['month'], true);
        $length = strlen($month);
        for ($i = 0; $i < $length; $i++) {
            if ($month[$i] == 1) {
                if (!zbx_empty($months)) {
                    $months .= ', ';
                }
                $months .= getMonthCaption($i + 1);
            }
        }
        if ($timeperiod['dayofweek'] > 0) {
            $days = '';
            $dayofweek = zbx_num2bitstr($timeperiod['dayofweek'], true);
            $length = strlen($dayofweek);
            for ($i = 0; $i < $length; $i++) {
                if ($dayofweek[$i] == 1) {
                    if (!zbx_empty($days)) {
                        $days .= ', ';
                    }
                    $days .= getDayOfWeekCaption($i + 1);
                }
            }
            $every = '';
            switch ($timeperiod['every']) {
                case 1:
                    $every = _('First');
                    break;
                case 2:
                    $every = _('Second');
                    break;
                case 3:
                    $every = _('Third');
                    break;
                case 4:
                    $every = _('Fourth');
                    break;
                case 5:
                    $every = _('Last');
                    break;
            }
            $str = _s('At %1$s:%2$s on %3$s %4$s of every %5$s', $timeperiod['hour'], $timeperiod['minute'], $every, $days, $months);
        } else {
            $str = _s('At %1$s:%2$s on day %3$s of every %4$s', $timeperiod['hour'], $timeperiod['minute'], $timeperiod['day'], $months);
        }
    }
    return $str;
}
Exemplo n.º 2
0
function dowHrMinToStr($value, $display24Hours = false)
{
    $dow = $value - $value % SEC_PER_DAY;
    $hr = $value - $dow;
    $hr -= $hr % SEC_PER_HOUR;
    $min = $value - $dow - $hr;
    $min -= $min % SEC_PER_MIN;
    $dow /= SEC_PER_DAY;
    $hr /= SEC_PER_HOUR;
    $min /= SEC_PER_MIN;
    if ($display24Hours && $hr == 0 && $min == 0) {
        $dow--;
        $hr = 24;
    }
    return sprintf('%s %02d:%02d', getDayOfWeekCaption($dow), $hr, $min);
}
Exemplo n.º 3
0
function shedule2str($timeperiod)
{
    $timeperiod['hour'] = floor($timeperiod['start_time'] / 3600);
    $timeperiod['minute'] = floor(($timeperiod['start_time'] - $timeperiod['hour'] * 3600) / 60);
    if ($timeperiod['hour'] < 10) {
        $timeperiod['hour'] = '0' . $timeperiod['hour'];
    }
    if ($timeperiod['minute'] < 10) {
        $timeperiod['minute'] = '0' . $timeperiod['minute'];
    }
    $str = S_AT . SPACE . $timeperiod['hour'] . ':' . $timeperiod['minute'] . SPACE . S_ON_SMALL . SPACE;
    if ($timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_ONETIME) {
        $str = S_AT . SPACE . date('H', $timeperiod['start_date']) . ':' . date('i', $timeperiod['start_date']) . SPACE . S_ON_SMALL . SPACE . zbx_date2str(S_MAINTENANCES_SCHEDULE_DATE_FORMAT, $timeperiod['start_date']);
    } else {
        if ($timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_DAILY) {
            $str .= S_EVERY_SMALL . SPACE . ($timeperiod['every'] > 1 ? $timeperiod['every'] . SPACE . S_DAYS_SMALL : S_DAY_SMALL);
        } else {
            if ($timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_WEEKLY) {
                $days = '';
                $dayofweek = zbx_num2bitstr($timeperiod['dayofweek'], true);
                $length = zbx_strlen($dayofweek);
                for ($i = 0; $i < $length; $i++) {
                    if ($dayofweek[$i] == 1) {
                        if (!zbx_empty($days)) {
                            $days .= ', ';
                        }
                        $days .= getDayOfWeekCaption($i + 1);
                    }
                }
                $str .= S_EVERY_SMALL . SPACE . $days . SPACE . S_OF_EVERY_SMALL . SPACE . ($timeperiod['every'] > 1 ? $timeperiod['every'] . SPACE . S_WEEKS_SMALL : S_WEEK_SMALL);
            } else {
                if ($timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_MONTHLY) {
                    $months = '';
                    $month = zbx_num2bitstr($timeperiod['month'], true);
                    $length = zbx_strlen($month);
                    for ($i = 0; $i < $length; $i++) {
                        if ($month[$i] == 1) {
                            if (!zbx_empty($months)) {
                                $months .= ', ';
                            }
                            $months .= getMonthCaption($i + 1);
                        }
                    }
                    if ($timeperiod['dayofweek'] > 0) {
                        $days = '';
                        $dayofweek = zbx_num2bitstr($timeperiod['dayofweek'], true);
                        $length = zbx_strlen($dayofweek);
                        for ($i = 0; $i < $length; $i++) {
                            if ($dayofweek[$i] == 1) {
                                if (!zbx_empty($days)) {
                                    $days .= ', ';
                                }
                                $days .= getDayOfWeekCaption($i + 1);
                            }
                        }
                        $every = '';
                        switch ($timeperiod['every']) {
                            case 1:
                                $every = S_FIRST;
                                break;
                            case 2:
                                $every = S_SECOND;
                                break;
                            case 3:
                                $every = S_THIRD;
                                break;
                            case 4:
                                $every = S_FOURTH;
                                break;
                            case 5:
                                $every = S_LAST;
                                break;
                        }
                        $str .= $every . SPACE . $days . SPACE . S_OF_EVERY_SMALL . SPACE . $months;
                    } else {
                        $str .= S_DAY_SMALL . SPACE . $timeperiod['day'] . SPACE . S_OF_EVERY_SMALL . SPACE . $months;
                    }
                }
            }
        }
    }
    return $str;
}
    }
    $servicesForm->addVar('new_service_time[to]', $serviceTimeTo);
    // create calendar table
    $timeCalendarTable = new CTable();
    $noteTextBox = new CTextBox('new_service_time[note]', '', ZBX_TEXTBOX_STANDARD_SIZE);
    $noteTextBox->setAttribute('placeholder', _('short description'));
    $timeCalendarTable->addRow(array(_('Note'), $noteTextBox));
    $timeCalendarTable->addRow(array(_('From'), createDateSelector('new_service_time_from', $fromDate, 'new_service_time_to')));
    $timeCalendarTable->addRow(array(_('Till'), createDateSelector('new_service_time_to', $toDate, 'new_service_time_from')));
    $serviceTimeTable->addRow($timeCalendarTable);
} else {
    $weekFromComboBox = new CComboBox('new_service_time[from_week]', isset($_REQUEST['new_service_time']['from_week']) ? $_REQUEST['new_service_time']['from_week'] : 0);
    $weekToComboBox = new CComboBox('new_service_time[to_week]', isset($_REQUEST['new_service_time']['from_week']) ? $_REQUEST['new_service_time']['to_week'] : 0);
    for ($dow = 0; $dow < 7; $dow++) {
        $weekFromComboBox->addItem($dow, getDayOfWeekCaption($dow));
        $weekToComboBox->addItem($dow, getDayOfWeekCaption($dow));
    }
    $timeFromHourTextBox = new CTextBox('new_service_time[from_hour]', isset($_REQUEST['new_service_time']['from_hour']) ? $_REQUEST['new_service_time']['from_hour'] : '', 2, false, 2);
    $timeFromHourTextBox->setAttribute('placeholder', _('hh'));
    $timeFromMinuteTextBox = new CTextBox('new_service_time[from_minute]', isset($_REQUEST['new_service_time']['from_minute']) ? $_REQUEST['new_service_time']['from_minute'] : '', 2, false, 2);
    $timeFromMinuteTextBox->setAttribute('placeholder', _('mm'));
    $timeToHourTextBox = new CTextBox('new_service_time[to_hour]', isset($_REQUEST['new_service_time']['to_hour']) ? $_REQUEST['new_service_time']['to_hour'] : '', 2, false, 2);
    $timeToHourTextBox->setAttribute('placeholder', _('hh'));
    $timeToMinuteTextBox = new CTextBox('new_service_time[to_minute]', isset($_REQUEST['new_service_time']['to_minute']) ? $_REQUEST['new_service_time']['to_minute'] : '', 2, false, 2);
    $timeToMinuteTextBox->setAttribute('placeholder', _('mm'));
    $serviceTimeTable->addRow(array(_('From'), $weekFromComboBox, new CCol(array(_('Time'), SPACE, $timeFromHourTextBox, ' : ', $timeFromMinuteTextBox))));
    $serviceTimeTable->addRow(array(_('Till'), $weekToComboBox, new CCol(array(_('Time'), SPACE, $timeToHourTextBox, ' : ', $timeToMinuteTextBox))));
    $servicesForm->addVar('new_service_time[note]', '');
}
$timeTypeComboBox = new CComboBox('new_service_time[type]', $this->data['new_service_time']['type'], 'javascript: document.forms[0].action += \'?form=1\'; submit();');
$timeTypeComboBox->addItem(SERVICE_TIME_TYPE_UPTIME, _('Uptime'));
function shedule2str($timeperiod)
{
    $timeperiod['hour'] = floor($timeperiod['start_time'] / SEC_PER_HOUR);
    $timeperiod['minute'] = floor(($timeperiod['start_time'] - $timeperiod['hour'] * SEC_PER_HOUR) / SEC_PER_MIN);
    if ($timeperiod['hour'] < 10) {
        $timeperiod['hour'] = '0' . $timeperiod['hour'];
    }
    if ($timeperiod['minute'] < 10) {
        $timeperiod['minute'] = '0' . $timeperiod['minute'];
    }
    $str = _('At') . SPACE . $timeperiod['hour'] . ':' . $timeperiod['minute'] . SPACE . _('on') . SPACE;
    if ($timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_ONETIME) {
        $str = _('At') . SPACE . date('H', $timeperiod['start_date']) . ':' . date('i', $timeperiod['start_date']) . SPACE . _('on') . SPACE . zbx_date2str(_('d M Y'), $timeperiod['start_date']);
    } elseif ($timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_DAILY) {
        $str .= _('every') . SPACE . ($timeperiod['every'] > 1 ? $timeperiod['every'] . SPACE . _('days') : _('day'));
    } elseif ($timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_WEEKLY) {
        $days = '';
        $dayofweek = zbx_num2bitstr($timeperiod['dayofweek'], true);
        $length = zbx_strlen($dayofweek);
        for ($i = 0; $i < $length; $i++) {
            if ($dayofweek[$i] == 1) {
                if (!zbx_empty($days)) {
                    $days .= ', ';
                }
                $days .= getDayOfWeekCaption($i + 1);
            }
        }
        $str .= _('every') . SPACE . $days . SPACE . _('of every') . SPACE . ($timeperiod['every'] > 1 ? $timeperiod['every'] . SPACE . _('weeks') : _('week'));
    } elseif ($timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_MONTHLY) {
        $months = '';
        $month = zbx_num2bitstr($timeperiod['month'], true);
        $length = zbx_strlen($month);
        for ($i = 0; $i < $length; $i++) {
            if ($month[$i] == 1) {
                if (!zbx_empty($months)) {
                    $months .= ', ';
                }
                $months .= getMonthCaption($i + 1);
            }
        }
        if ($timeperiod['dayofweek'] > 0) {
            $days = '';
            $dayofweek = zbx_num2bitstr($timeperiod['dayofweek'], true);
            $length = zbx_strlen($dayofweek);
            for ($i = 0; $i < $length; $i++) {
                if ($dayofweek[$i] == 1) {
                    if (!zbx_empty($days)) {
                        $days .= ', ';
                    }
                    $days .= getDayOfWeekCaption($i + 1);
                }
            }
            $every = '';
            switch ($timeperiod['every']) {
                case 1:
                    $every = _('First');
                    break;
                case 2:
                    $every = _('Second');
                    break;
                case 3:
                    $every = _('Third');
                    break;
                case 4:
                    $every = _('Fourth');
                    break;
                case 5:
                    $every = _('Last');
                    break;
            }
            $str .= $every . SPACE . $days . SPACE . _('of every') . SPACE . $months;
        } else {
            $str .= _('day') . SPACE . $timeperiod['day'] . SPACE . _('of every') . SPACE . $months;
        }
    }
    return $str;
}