Example #1
0
function get_timeperiod_form()
{
    $tblPeriod = new CTable(null, 'formElementTable');
    // init new_timeperiod variable
    $new_timeperiod = getRequest('new_timeperiod', array());
    $new = is_array($new_timeperiod);
    if (is_array($new_timeperiod)) {
        if (isset($new_timeperiod['id'])) {
            $tblPeriod->addItem(new CVar('new_timeperiod[id]', $new_timeperiod['id']));
        }
        if (isset($new_timeperiod['timeperiodid'])) {
            $tblPeriod->addItem(new CVar('new_timeperiod[timeperiodid]', $new_timeperiod['timeperiodid']));
        }
    }
    if (!is_array($new_timeperiod)) {
        $new_timeperiod = array();
        $new_timeperiod['timeperiod_type'] = TIMEPERIOD_TYPE_ONETIME;
    }
    if (!isset($new_timeperiod['every'])) {
        $new_timeperiod['every'] = 1;
    }
    if (!isset($new_timeperiod['day'])) {
        $new_timeperiod['day'] = 1;
    }
    if (!isset($new_timeperiod['hour'])) {
        $new_timeperiod['hour'] = 12;
    }
    if (!isset($new_timeperiod['minute'])) {
        $new_timeperiod['minute'] = 0;
    }
    if (!isset($new_timeperiod['start_date'])) {
        $new_timeperiod['start_date'] = 0;
    }
    if (!isset($new_timeperiod['period_days'])) {
        $new_timeperiod['period_days'] = 0;
    }
    if (!isset($new_timeperiod['period_hours'])) {
        $new_timeperiod['period_hours'] = 1;
    }
    if (!isset($new_timeperiod['period_minutes'])) {
        $new_timeperiod['period_minutes'] = 0;
    }
    if (!isset($new_timeperiod['month_date_type'])) {
        $new_timeperiod['month_date_type'] = !(bool) $new_timeperiod['day'];
    }
    // start time
    if (isset($new_timeperiod['start_time'])) {
        $new_timeperiod['hour'] = floor($new_timeperiod['start_time'] / SEC_PER_HOUR);
        $new_timeperiod['minute'] = floor(($new_timeperiod['start_time'] - $new_timeperiod['hour'] * SEC_PER_HOUR) / SEC_PER_MIN);
    }
    // period
    if (isset($new_timeperiod['period'])) {
        $new_timeperiod['period_days'] = floor($new_timeperiod['period'] / SEC_PER_DAY);
        $new_timeperiod['period_hours'] = floor(($new_timeperiod['period'] - $new_timeperiod['period_days'] * SEC_PER_DAY) / SEC_PER_HOUR);
        $new_timeperiod['period_minutes'] = floor(($new_timeperiod['period'] - $new_timeperiod['period_days'] * SEC_PER_DAY - $new_timeperiod['period_hours'] * SEC_PER_HOUR) / SEC_PER_MIN);
    }
    // daysofweek
    $dayofweek = '';
    $dayofweek .= !isset($new_timeperiod['dayofweek_mo']) ? '0' : '1';
    $dayofweek .= !isset($new_timeperiod['dayofweek_tu']) ? '0' : '1';
    $dayofweek .= !isset($new_timeperiod['dayofweek_we']) ? '0' : '1';
    $dayofweek .= !isset($new_timeperiod['dayofweek_th']) ? '0' : '1';
    $dayofweek .= !isset($new_timeperiod['dayofweek_fr']) ? '0' : '1';
    $dayofweek .= !isset($new_timeperiod['dayofweek_sa']) ? '0' : '1';
    $dayofweek .= !isset($new_timeperiod['dayofweek_su']) ? '0' : '1';
    if (isset($new_timeperiod['dayofweek'])) {
        $dayofweek = zbx_num2bitstr($new_timeperiod['dayofweek'], true);
    }
    $new_timeperiod['dayofweek_mo'] = $dayofweek[0];
    $new_timeperiod['dayofweek_tu'] = $dayofweek[1];
    $new_timeperiod['dayofweek_we'] = $dayofweek[2];
    $new_timeperiod['dayofweek_th'] = $dayofweek[3];
    $new_timeperiod['dayofweek_fr'] = $dayofweek[4];
    $new_timeperiod['dayofweek_sa'] = $dayofweek[5];
    $new_timeperiod['dayofweek_su'] = $dayofweek[6];
    // months
    $month = '';
    $month .= !isset($new_timeperiod['month_jan']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_feb']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_mar']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_apr']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_may']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_jun']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_jul']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_aug']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_sep']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_oct']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_nov']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_dec']) ? '0' : '1';
    if (isset($new_timeperiod['month'])) {
        $month = zbx_num2bitstr($new_timeperiod['month'], true);
    }
    $new_timeperiod['month_jan'] = $month[0];
    $new_timeperiod['month_feb'] = $month[1];
    $new_timeperiod['month_mar'] = $month[2];
    $new_timeperiod['month_apr'] = $month[3];
    $new_timeperiod['month_may'] = $month[4];
    $new_timeperiod['month_jun'] = $month[5];
    $new_timeperiod['month_jul'] = $month[6];
    $new_timeperiod['month_aug'] = $month[7];
    $new_timeperiod['month_sep'] = $month[8];
    $new_timeperiod['month_oct'] = $month[9];
    $new_timeperiod['month_nov'] = $month[10];
    $new_timeperiod['month_dec'] = $month[11];
    $bit_dayofweek = strrev($dayofweek);
    $bit_month = strrev($month);
    $cmbType = new CComboBox('new_timeperiod[timeperiod_type]', $new_timeperiod['timeperiod_type'], 'submit()');
    $cmbType->addItem(TIMEPERIOD_TYPE_ONETIME, _('One time only'));
    $cmbType->addItem(TIMEPERIOD_TYPE_DAILY, _('Daily'));
    $cmbType->addItem(TIMEPERIOD_TYPE_WEEKLY, _('Weekly'));
    $cmbType->addItem(TIMEPERIOD_TYPE_MONTHLY, _('Monthly'));
    $tblPeriod->addRow(array(_('Period type'), $cmbType));
    if ($new_timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_DAILY) {
        $tblPeriod->addItem(new CVar('new_timeperiod[dayofweek]', bindec($bit_dayofweek)));
        $tblPeriod->addItem(new CVar('new_timeperiod[month]', bindec($bit_month)));
        $tblPeriod->addItem(new CVar('new_timeperiod[day]', $new_timeperiod['day']));
        $tblPeriod->addItem(new CVar('new_timeperiod[start_date]', $new_timeperiod['start_date']));
        $tblPeriod->addItem(new CVar('new_timeperiod[month_date_type]', $new_timeperiod['month_date_type']));
        $tblPeriod->addRow(array(_('Every day(s)'), new CNumericBox('new_timeperiod[every]', $new_timeperiod['every'], 3)));
    } elseif ($new_timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_WEEKLY) {
        $tblPeriod->addItem(new CVar('new_timeperiod[month]', bindec($bit_month)));
        $tblPeriod->addItem(new CVar('new_timeperiod[day]', $new_timeperiod['day']));
        $tblPeriod->addItem(new CVar('new_timeperiod[start_date]', $new_timeperiod['start_date']));
        $tblPeriod->addItem(new CVar('new_timeperiod[month_date_type]', $new_timeperiod['month_date_type']));
        $tblPeriod->addRow(array(_('Every week(s)'), new CNumericBox('new_timeperiod[every]', $new_timeperiod['every'], 2)));
        $tabDays = new CTable();
        $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_mo]', $dayofweek[0], null, 1), _('Monday')));
        $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_tu]', $dayofweek[1], null, 1), _('Tuesday')));
        $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_we]', $dayofweek[2], null, 1), _('Wednesday')));
        $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_th]', $dayofweek[3], null, 1), _('Thursday')));
        $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_fr]', $dayofweek[4], null, 1), _('Friday')));
        $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_sa]', $dayofweek[5], null, 1), _('Saturday')));
        $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_su]', $dayofweek[6], null, 1), _('Sunday')));
        $tblPeriod->addRow(array(_('Day of week'), $tabDays));
    } elseif ($new_timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_MONTHLY) {
        $tblPeriod->addItem(new CVar('new_timeperiod[start_date]', $new_timeperiod['start_date']));
        $tabMonths = new CTable();
        $tabMonths->addRow(array(new CCheckBox('new_timeperiod[month_jan]', $month[0], null, 1), _('January'), SPACE, SPACE, new CCheckBox('new_timeperiod[month_jul]', $month[6], null, 1), _('July')));
        $tabMonths->addRow(array(new CCheckBox('new_timeperiod[month_feb]', $month[1], null, 1), _('February'), SPACE, SPACE, new CCheckBox('new_timeperiod[month_aug]', $month[7], null, 1), _('August')));
        $tabMonths->addRow(array(new CCheckBox('new_timeperiod[month_mar]', $month[2], null, 1), _('March'), SPACE, SPACE, new CCheckBox('new_timeperiod[month_sep]', $month[8], null, 1), _('September')));
        $tabMonths->addRow(array(new CCheckBox('new_timeperiod[month_apr]', $month[3], null, 1), _('April'), SPACE, SPACE, new CCheckBox('new_timeperiod[month_oct]', $month[9], null, 1), _('October')));
        $tabMonths->addRow(array(new CCheckBox('new_timeperiod[month_may]', $month[4], null, 1), _('May'), SPACE, SPACE, new CCheckBox('new_timeperiod[month_nov]', $month[10], null, 1), _('November')));
        $tabMonths->addRow(array(new CCheckBox('new_timeperiod[month_jun]', $month[5], null, 1), _('June'), SPACE, SPACE, new CCheckBox('new_timeperiod[month_dec]', $month[11], null, 1), _('December')));
        $tblPeriod->addRow(array(_('Month'), $tabMonths));
        $tblPeriod->addRow(array(_('Date'), array(new CRadioButton('new_timeperiod[month_date_type]', '0', null, null, !$new_timeperiod['month_date_type'], 'submit()'), _('Day'), SPACE, new CRadioButton('new_timeperiod[month_date_type]', '1', null, null, $new_timeperiod['month_date_type'], 'submit()'), _('Day of week'))));
        if ($new_timeperiod['month_date_type'] > 0) {
            $tblPeriod->addItem(new CVar('new_timeperiod[day]', $new_timeperiod['day']));
            $cmbCount = new CComboBox('new_timeperiod[every]', $new_timeperiod['every']);
            $cmbCount->addItem(1, _('First'));
            $cmbCount->addItem(2, _('Second'));
            $cmbCount->addItem(3, _('Third'));
            $cmbCount->addItem(4, _('Fourth'));
            $cmbCount->addItem(5, _('Last'));
            $td = new CCol($cmbCount);
            $td->setColSpan(2);
            $tabDays = new CTable();
            $tabDays->addRow($td);
            $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_mo]', $dayofweek[0], null, 1), _('Monday')));
            $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_tu]', $dayofweek[1], null, 1), _('Tuesday')));
            $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_we]', $dayofweek[2], null, 1), _('Wednesday')));
            $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_th]', $dayofweek[3], null, 1), _('Thursday')));
            $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_fr]', $dayofweek[4], null, 1), _('Friday')));
            $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_sa]', $dayofweek[5], null, 1), _('Saturday')));
            $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_su]', $dayofweek[6], null, 1), _('Sunday')));
            $tblPeriod->addRow(array(_('Day of week'), $tabDays));
        } else {
            $tblPeriod->addItem(new CVar('new_timeperiod[dayofweek]', bindec($bit_dayofweek)));
            $tblPeriod->addRow(array(_('Day of month'), new CNumericBox('new_timeperiod[day]', $new_timeperiod['day'], 2)));
        }
    } else {
        $tblPeriod->addItem(new CVar('new_timeperiod[every]', $new_timeperiod['every'], 'new_timeperiod_every_tmp'));
        $tblPeriod->addItem(new CVar('new_timeperiod[month]', bindec($bit_month), 'new_timeperiod_month_tmp'));
        $tblPeriod->addItem(new CVar('new_timeperiod[day]', $new_timeperiod['day'], 'new_timeperiod_day_tmp'));
        $tblPeriod->addItem(new CVar('new_timeperiod[hour]', $new_timeperiod['hour'], 'new_timeperiod_hour_tmp'));
        $tblPeriod->addItem(new CVar('new_timeperiod[minute]', $new_timeperiod['minute'], 'new_timeperiod_minute_tmp'));
        $tblPeriod->addItem(new CVar('new_timeperiod[start_date]', $new_timeperiod['start_date']));
        $tblPeriod->addItem(new CVar('new_timeperiod[month_date_type]', $new_timeperiod['month_date_type']));
        $tblPeriod->addItem(new CVar('new_timeperiod[dayofweek]', bindec($bit_dayofweek)));
        if (isset($_REQUEST['add_timeperiod'])) {
            $date = array('y' => getRequest('new_timeperiod_start_date_year'), 'm' => getRequest('new_timeperiod_start_date_month'), 'd' => getRequest('new_timeperiod_start_date_day'), 'h' => getRequest('new_timeperiod_start_date_hour'), 'i' => getRequest('new_timeperiod_start_date_minute'));
        } else {
            $date = zbxDateToTime($new_timeperiod['start_date'] ? $new_timeperiod['start_date'] : date(TIMESTAMP_FORMAT_ZERO_TIME, time()));
        }
        $tblPeriod->addRow(array(_('Date'), createDateSelector('new_timeperiod_start_date', $date)));
    }
    if ($new_timeperiod['timeperiod_type'] != TIMEPERIOD_TYPE_ONETIME) {
        $tblPeriod->addRow(array(_('At (hour:minute)'), array(new CNumericBox('new_timeperiod[hour]', $new_timeperiod['hour'], 2), ':', new CNumericBox('new_timeperiod[minute]', $new_timeperiod['minute'], 2))));
    }
    $perHours = new CComboBox('new_timeperiod[period_hours]', $new_timeperiod['period_hours'], null, range(0, 23));
    $perMinutes = new CComboBox('new_timeperiod[period_minutes]', $new_timeperiod['period_minutes'], null, range(0, 59));
    $tblPeriod->addRow(array(_('Maintenance period length'), array(new CNumericBox('new_timeperiod[period_days]', $new_timeperiod['period_days'], 3), _('Days') . SPACE . SPACE, $perHours, _('Hours') . SPACE . SPACE, $perMinutes, _('Minutes'))));
    return $tblPeriod;
}
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;
}
Example #3
0
function get_timeperiod_form()
{
    $tblPeriod = new CTableInfo();
    /* init new_timeperiod variable */
    $new_timeperiod = get_request('new_timeperiod', array());
    if (is_array($new_timeperiod) && isset($new_timeperiod['id'])) {
        $tblPeriod->addItem(new Cvar('new_timeperiod[id]', $new_timeperiod['id']));
    }
    if (!is_array($new_timeperiod)) {
        $new_timeperiod = array();
        $new_timeperiod['timeperiod_type'] = TIMEPERIOD_TYPE_ONETIME;
    }
    if (!isset($new_timeperiod['every'])) {
        $new_timeperiod['every'] = 1;
    }
    if (!isset($new_timeperiod['day'])) {
        $new_timeperiod['day'] = 1;
    }
    if (!isset($new_timeperiod['hour'])) {
        $new_timeperiod['hour'] = 12;
    }
    if (!isset($new_timeperiod['minute'])) {
        $new_timeperiod['minute'] = 0;
    }
    if (!isset($new_timeperiod['date'])) {
        $new_timeperiod['date'] = 0;
    }
    if (!isset($new_timeperiod['period_days'])) {
        $new_timeperiod['period_days'] = 0;
    }
    if (!isset($new_timeperiod['period_hours'])) {
        $new_timeperiod['period_hours'] = 1;
    }
    if (!isset($new_timeperiod['month_date_type'])) {
        $new_timeperiod['month_date_type'] = !(bool) $new_timeperiod['day'];
    }
    // START TIME
    if (isset($new_timeperiod['start_time'])) {
        $new_timeperiod['hour'] = floor($new_timeperiod['start_time'] / 3600);
        $new_timeperiod['minute'] = floor(($new_timeperiod['start_time'] - $new_timeperiod['hour'] * 3600) / 60);
    }
    //--
    // PERIOD
    if (isset($new_timeperiod['period'])) {
        $new_timeperiod['period_days'] = floor($new_timeperiod['period'] / 86400);
        $new_timeperiod['period_hours'] = floor(($new_timeperiod['period'] - $new_timeperiod['period_days'] * 86400) / 3600);
    }
    //--
    // DAYSOFWEEK
    $dayofweek = '';
    $dayofweek .= !isset($new_timeperiod['dayofweek_mo']) ? '0' : '1';
    $dayofweek .= !isset($new_timeperiod['dayofweek_tu']) ? '0' : '1';
    $dayofweek .= !isset($new_timeperiod['dayofweek_we']) ? '0' : '1';
    $dayofweek .= !isset($new_timeperiod['dayofweek_th']) ? '0' : '1';
    $dayofweek .= !isset($new_timeperiod['dayofweek_fr']) ? '0' : '1';
    $dayofweek .= !isset($new_timeperiod['dayofweek_sa']) ? '0' : '1';
    $dayofweek .= !isset($new_timeperiod['dayofweek_su']) ? '0' : '1';
    if (isset($new_timeperiod['dayofweek'])) {
        $dayofweek = zbx_num2bitstr($new_timeperiod['dayofweek'], true);
    }
    $new_timeperiod['dayofweek_mo'] = $dayofweek[0];
    $new_timeperiod['dayofweek_tu'] = $dayofweek[1];
    $new_timeperiod['dayofweek_we'] = $dayofweek[2];
    $new_timeperiod['dayofweek_th'] = $dayofweek[3];
    $new_timeperiod['dayofweek_fr'] = $dayofweek[4];
    $new_timeperiod['dayofweek_sa'] = $dayofweek[5];
    $new_timeperiod['dayofweek_su'] = $dayofweek[6];
    //--
    // MONTHS
    $month = '';
    $month .= !isset($new_timeperiod['month_jan']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_feb']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_mar']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_apr']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_may']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_jun']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_jul']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_aug']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_sep']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_oct']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_nov']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_dec']) ? '0' : '1';
    if (isset($new_timeperiod['month'])) {
        $month = zbx_num2bitstr($new_timeperiod['month'], true);
    }
    $new_timeperiod['month_jan'] = $month[0];
    $new_timeperiod['month_feb'] = $month[1];
    $new_timeperiod['month_mar'] = $month[2];
    $new_timeperiod['month_apr'] = $month[3];
    $new_timeperiod['month_may'] = $month[4];
    $new_timeperiod['month_jun'] = $month[5];
    $new_timeperiod['month_jul'] = $month[6];
    $new_timeperiod['month_aug'] = $month[7];
    $new_timeperiod['month_sep'] = $month[8];
    $new_timeperiod['month_oct'] = $month[9];
    $new_timeperiod['month_nov'] = $month[10];
    $new_timeperiod['month_dec'] = $month[11];
    //--
    $bit_dayofweek = zbx_str_revert($dayofweek);
    $bit_month = zbx_str_revert($month);
    $cmbType = new CComboBox('new_timeperiod[timeperiod_type]', $new_timeperiod['timeperiod_type'], 'submit()');
    $cmbType->addItem(TIMEPERIOD_TYPE_ONETIME, S_ONE_TIME_ONLY);
    $cmbType->addItem(TIMEPERIOD_TYPE_DAILY, S_DAILY);
    $cmbType->addItem(TIMEPERIOD_TYPE_WEEKLY, S_WEEKLY);
    $cmbType->addItem(TIMEPERIOD_TYPE_MONTHLY, S_MONTHLY);
    $tblPeriod->addRow(array(S_PERIOD_TYPE, $cmbType));
    if ($new_timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_DAILY) {
        $tblPeriod->addItem(new Cvar('new_timeperiod[dayofweek]', bindec($bit_dayofweek)));
        $tblPeriod->addItem(new Cvar('new_timeperiod[month]', bindec($bit_month)));
        $tblPeriod->addItem(new Cvar('new_timeperiod[day]', $new_timeperiod['day']));
        $tblPeriod->addItem(new Cvar('new_timeperiod[date]', $new_timeperiod['date']));
        $tblPeriod->addItem(new Cvar('new_timeperiod[month_date_type]', $new_timeperiod['month_date_type']));
        $tblPeriod->addRow(array(S_EVERY_DAY_S, new CNumericBox('new_timeperiod[every]', $new_timeperiod['every'], 3)));
    } else {
        if ($new_timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_WEEKLY) {
            $tblPeriod->addItem(new Cvar('new_timeperiod[month]', bindec($bit_month)));
            $tblPeriod->addItem(new Cvar('new_timeperiod[day]', $new_timeperiod['day']));
            $tblPeriod->addItem(new Cvar('new_timeperiod[date]', $new_timeperiod['date']));
            $tblPeriod->addItem(new Cvar('new_timeperiod[month_date_type]', $new_timeperiod['month_date_type']));
            $tblPeriod->addRow(array(S_EVERY_WEEK_S, new CNumericBox('new_timeperiod[every]', $new_timeperiod['every'], 2)));
            $tabDays = new CTable();
            $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_mo]', $dayofweek[0], null, 1), S_MONDAY));
            $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_tu]', $dayofweek[1], null, 1), S_TUESDAY));
            $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_we]', $dayofweek[2], null, 1), S_WEDNESDAY));
            $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_th]', $dayofweek[3], null, 1), S_THURSDAY));
            $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_fr]', $dayofweek[4], null, 1), S_FRIDAY));
            $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_sa]', $dayofweek[5], null, 1), S_SATURDAY));
            $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_su]', $dayofweek[6], null, 1), S_SUNDAY));
            $tblPeriod->addRow(array(S_DAY_OF_WEEK, $tabDays));
        } else {
            if ($new_timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_MONTHLY) {
                $tblPeriod->addItem(new Cvar('new_timeperiod[date]', $new_timeperiod['date']));
                $tabMonths = new CTable();
                $tabMonths->addRow(array(new CCheckBox('new_timeperiod[month_jan]', $month[0], null, 1), S_JANUARY, SPACE, SPACE, new CCheckBox('new_timeperiod[month_jul]', $month[6], null, 1), S_JULY));
                $tabMonths->addRow(array(new CCheckBox('new_timeperiod[month_feb]', $month[1], null, 1), S_FEBRUARY, SPACE, SPACE, new CCheckBox('new_timeperiod[month_aug]', $month[7], null, 1), S_AUGUST));
                $tabMonths->addRow(array(new CCheckBox('new_timeperiod[month_mar]', $month[2], null, 1), S_MARCH, SPACE, SPACE, new CCheckBox('new_timeperiod[month_sep]', $month[8], null, 1), S_SEPTEMBER));
                $tabMonths->addRow(array(new CCheckBox('new_timeperiod[month_apr]', $month[3], null, 1), S_APRIL, SPACE, SPACE, new CCheckBox('new_timeperiod[month_oct]', $month[9], null, 1), S_OCTOBER));
                $tabMonths->addRow(array(new CCheckBox('new_timeperiod[month_may]', $month[4], null, 1), S_MAY, SPACE, SPACE, new CCheckBox('new_timeperiod[month_nov]', $month[10], null, 1), S_NOVEMBER));
                $tabMonths->addRow(array(new CCheckBox('new_timeperiod[month_jun]', $month[5], null, 1), S_JUNE, SPACE, SPACE, new CCheckBox('new_timeperiod[month_dec]', $month[11], null, 1), S_DECEMBER));
                $tblPeriod->addRow(array(S_MONTH, $tabMonths));
                $radioDaily = new CTag('input');
                $radioDaily->addOption('type', 'radio');
                $radioDaily->addOption('name', 'new_timeperiod[month_date_type]');
                $radioDaily->addOption('value', '0');
                $radioDaily->addOption('onclick', 'submit()');
                $radioDaily2 = new CTag('input');
                $radioDaily2->addOption('type', 'radio');
                $radioDaily2->addOption('name', 'new_timeperiod[month_date_type]');
                $radioDaily2->addOption('value', '1');
                $radioDaily2->addOption('onclick', 'submit()');
                if ($new_timeperiod['month_date_type']) {
                    $radioDaily2->addOption('checked', 'checked');
                } else {
                    $radioDaily->addOption('checked', 'checked');
                }
                $tblPeriod->addRow(array(S_DATE, array($radioDaily, S_DAY, SPACE, SPACE, $radioDaily2, S_DAY_OF_WEEK)));
                if ($new_timeperiod['month_date_type'] > 0) {
                    $tblPeriod->addItem(new Cvar('new_timeperiod[day]', $new_timeperiod['day']));
                    $cmbCount = new CComboBox('new_timeperiod[every]', $new_timeperiod['every']);
                    $cmbCount->addItem(1, S_FIRST);
                    $cmbCount->addItem(2, S_SECOND);
                    $cmbCount->addItem(3, S_THIRD);
                    $cmbCount->addItem(4, S_FOURTH);
                    $cmbCount->addItem(5, S_LAST);
                    $td = new CCol($cmbCount);
                    $td->setColSpan(2);
                    $tabDays = new CTable();
                    $tabDays->addRow($td);
                    $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_mo]', $dayofweek[0], null, 1), S_MONDAY));
                    $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_tu]', $dayofweek[1], null, 1), S_TUESDAY));
                    $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_we]', $dayofweek[2], null, 1), S_WEDNESDAY));
                    $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_th]', $dayofweek[3], null, 1), S_THURSDAY));
                    $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_fr]', $dayofweek[4], null, 1), S_FRIDAY));
                    $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_sa]', $dayofweek[5], null, 1), S_SATURDAY));
                    $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_su]', $dayofweek[6], null, 1), S_SUNDAY));
                    $tblPeriod->addRow(array(S_DAY_OF_WEEK, $tabDays));
                } else {
                    $tblPeriod->addItem(new Cvar('new_timeperiod[dayofweek]', bindec($bit_dayofweek)));
                    $tblPeriod->addRow(array(S_DAY_OF_MONTH, new CNumericBox('new_timeperiod[day]', $new_timeperiod['day'], 2)));
                }
            } else {
                $tblPeriod->addItem(new Cvar('new_timeperiod[every]', $new_timeperiod['every']));
                $tblPeriod->addItem(new Cvar('new_timeperiod[dayofweek]', bindec($bit_dayofweek)));
                $tblPeriod->addItem(new Cvar('new_timeperiod[month]', bindec($bit_month)));
                $tblPeriod->addItem(new Cvar('new_timeperiod[day]', $new_timeperiod['day']));
                $tblPeriod->addItem(new Cvar('new_timeperiod[hour]', $new_timeperiod['hour']));
                $tblPeriod->addItem(new Cvar('new_timeperiod[minute]', $new_timeperiod['minute']));
                $tblPeriod->addItem(new Cvar('new_timeperiod[month_date_type]', $new_timeperiod['month_date_type']));
                /***********************************************************/
                $tblPeriod->addItem(new Cvar('new_timeperiod[date]', $new_timeperiod['date']));
                $clndr_icon = new CImg('images/general/bar/cal.gif', 'calendar', 16, 12, 'pointer');
                $clndr_icon->addAction('onclick', 'javascript: ' . 'var pos = getPosition(this); ' . 'pos.top+=10; ' . 'pos.left+=16; ' . "CLNDR['new_timeperiod_date'].clndr.clndrshow(pos.top,pos.left);");
                $filtertimetab = new CTable(null, 'calendar');
                $filtertimetab->addOption('width', '10%');
                $filtertimetab->SetCellPadding(0);
                $filtertimetab->SetCellSpacing(0);
                $filtertimetab->addRow(array(new CNumericBox('new_timeperiod_day', $new_timeperiod['date'] > 0 ? date('d', $new_timeperiod['date']) : '', 2), '/', new CNumericBox('new_timeperiod_month', $new_timeperiod['date'] > 0 ? date('m', $new_timeperiod['date']) : '', 2), '/', new CNumericBox('new_timeperiod_year', $new_timeperiod['date'] > 0 ? date('Y', $new_timeperiod['date']) : '', 4), SPACE, new CNumericBox('new_timeperiod_hour', $new_timeperiod['date'] > 0 ? date('H', $new_timeperiod['date']) : '', 2), ':', new CNumericBox('new_timeperiod_minute', $new_timeperiod['date'] > 0 ? date('i', $new_timeperiod['date']) : '', 2), $clndr_icon));
                zbx_add_post_js('create_calendar(null,' . '["new_timeperiod_day","new_timeperiod_month","new_timeperiod_year","new_timeperiod_hour","new_timeperiod_minute"],' . '"new_timeperiod_date",' . '"new_timeperiod[date]");');
                $clndr_icon->addAction('onclick', 'javascript: ' . 'var pos = getPosition(this); ' . 'pos.top+=10; ' . 'pos.left+=16; ' . "CLNDR['mntc_active_till'].clndr.clndrshow(pos.top,pos.left);");
                $tblPeriod->addRow(array(S_DATE, $filtertimetab));
                zbx_add_post_js('if("undefined" != typeof(CLNDR["new_timeperiod_date"]))' . ' addListener($("hat_new_timeperiod_icon"),' . '"click",' . 'CLNDR["new_timeperiod_date"].clndr.clndrhide.bindAsEventListener(CLNDR["new_timeperiod_date"].clndr));');
                //-------
            }
        }
    }
    if ($new_timeperiod['timeperiod_type'] != TIMEPERIOD_TYPE_ONETIME) {
        $tabTime = new CTable(null, 'calendar');
        $tabTime->addRow(array(new CNumericBox('new_timeperiod[hour]', $new_timeperiod['hour'], 2), ':', new CNumericBox('new_timeperiod[minute]', $new_timeperiod['minute'], 2)));
        $tblPeriod->addRow(array(S_AT . SPACE . '(' . S_HOUR . ':' . S_MINUTE . ')', $tabTime));
    }
    $perHours = new CComboBox('new_timeperiod[period_hours]', $new_timeperiod['period_hours']);
    for ($i = 0; $i < 25; $i++) {
        $perHours->addItem($i, $i . SPACE);
    }
    $tblPeriod->addRow(array(S_MAINTENANCE_PERIOD_LENGTH, array(new CNumericBox('new_timeperiod[period_days]', $new_timeperiod['period_days'], 3), S_DAYS . SPACE . SPACE, $perHours, SPACE . S_HOURS)));
    //			$tabPeriod = new CTable();
    //			$tabPeriod->addRow(S_DAYS)
    //			$tblPeriod->addRow(array(S_AT.SPACE.'('.S_HOUR.':'.S_MINUTE.')', $tabTime));
    $td = new CCol(array(new CButton('add_timeperiod', S_SAVE), SPACE, new CButton('cancel_new_timeperiod', S_CANCEL)));
    $td->addOption('colspan', '3');
    $td->addOption('style', 'text-align: right;');
    $tblPeriod->SetFooter($td);
    return $tblPeriod;
}
Example #4
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 = 'At ' . $timeperiod['hour'] . ':' . $timeperiod['minute'] . ' on ';
    if ($timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_ONETIME) {
        $str = 'At ' . date('H', $timeperiod['date']) . ':' . date('i', $timeperiod['date']) . ' on ' . date(S_DATE_FORMAT_YMD, $timeperiod['date']);
    } else {
        if ($timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_DAILY) {
            $str .= 'every ' . ($timeperiod['every'] > 1 ? $timeperiod['every'] . ' days' : 'day');
        } else {
            if ($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 .= get_str_dayofweek($i + 1);
                    }
                }
                $str .= 'every ' . $days . ' of every ' . ($timeperiod['every'] > 1 ? $timeperiod['every'] . ' weeks' : 'week');
            } else {
                if ($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 .= get_str_month($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 .= get_str_dayofweek($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 . ' of every ' . $months;
                    } else {
                        $str .= 'day ' . $timeperiod['day'] . ' of every ' . $months;
                    }
                }
            }
        }
    }
    return $str;
}
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;
}
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;
}
function get_timeperiod_form()
{
    $tblPeriod = new CTableInfo();
    // init new_timeperiod variable
    $new_timeperiod = get_request('new_timeperiod', array());
    $new = is_array($new_timeperiod);
    if (is_array($new_timeperiod)) {
        if (isset($new_timeperiod['id'])) {
            $tblPeriod->addItem(new CVar('new_timeperiod[id]', $new_timeperiod['id']));
        }
        if (isset($new_timeperiod['timeperiodid'])) {
            $tblPeriod->addItem(new CVar('new_timeperiod[timeperiodid]', $new_timeperiod['timeperiodid']));
        }
    }
    if (!is_array($new_timeperiod)) {
        $new_timeperiod = array();
        $new_timeperiod['timeperiod_type'] = TIMEPERIOD_TYPE_ONETIME;
    }
    if (!isset($new_timeperiod['every'])) {
        $new_timeperiod['every'] = 1;
    }
    if (!isset($new_timeperiod['day'])) {
        $new_timeperiod['day'] = 1;
    }
    if (!isset($new_timeperiod['hour'])) {
        $new_timeperiod['hour'] = 12;
    }
    if (!isset($new_timeperiod['minute'])) {
        $new_timeperiod['minute'] = 0;
    }
    if (!isset($new_timeperiod['start_date'])) {
        $new_timeperiod['start_date'] = 0;
    }
    if (!isset($new_timeperiod['period_days'])) {
        $new_timeperiod['period_days'] = 0;
    }
    if (!isset($new_timeperiod['period_hours'])) {
        $new_timeperiod['period_hours'] = 1;
    }
    if (!isset($new_timeperiod['period_minutes'])) {
        $new_timeperiod['period_minutes'] = 0;
    }
    if (!isset($new_timeperiod['month_date_type'])) {
        $new_timeperiod['month_date_type'] = !(bool) $new_timeperiod['day'];
    }
    // start time
    if (isset($new_timeperiod['start_time'])) {
        $new_timeperiod['hour'] = floor($new_timeperiod['start_time'] / SEC_PER_HOUR);
        $new_timeperiod['minute'] = floor(($new_timeperiod['start_time'] - $new_timeperiod['hour'] * SEC_PER_HOUR) / SEC_PER_MIN);
    }
    // period
    if (isset($new_timeperiod['period'])) {
        $new_timeperiod['period_days'] = floor($new_timeperiod['period'] / SEC_PER_DAY);
        $new_timeperiod['period_hours'] = floor(($new_timeperiod['period'] - $new_timeperiod['period_days'] * SEC_PER_DAY) / SEC_PER_HOUR);
        $new_timeperiod['period_minutes'] = floor(($new_timeperiod['period'] - $new_timeperiod['period_days'] * SEC_PER_DAY - $new_timeperiod['period_hours'] * SEC_PER_HOUR) / SEC_PER_MIN);
    }
    // daysofweek
    $dayofweek = '';
    $dayofweek .= !isset($new_timeperiod['dayofweek_mo']) ? '0' : '1';
    $dayofweek .= !isset($new_timeperiod['dayofweek_tu']) ? '0' : '1';
    $dayofweek .= !isset($new_timeperiod['dayofweek_we']) ? '0' : '1';
    $dayofweek .= !isset($new_timeperiod['dayofweek_th']) ? '0' : '1';
    $dayofweek .= !isset($new_timeperiod['dayofweek_fr']) ? '0' : '1';
    $dayofweek .= !isset($new_timeperiod['dayofweek_sa']) ? '0' : '1';
    $dayofweek .= !isset($new_timeperiod['dayofweek_su']) ? '0' : '1';
    if (isset($new_timeperiod['dayofweek'])) {
        $dayofweek = zbx_num2bitstr($new_timeperiod['dayofweek'], true);
    }
    $new_timeperiod['dayofweek_mo'] = $dayofweek[0];
    $new_timeperiod['dayofweek_tu'] = $dayofweek[1];
    $new_timeperiod['dayofweek_we'] = $dayofweek[2];
    $new_timeperiod['dayofweek_th'] = $dayofweek[3];
    $new_timeperiod['dayofweek_fr'] = $dayofweek[4];
    $new_timeperiod['dayofweek_sa'] = $dayofweek[5];
    $new_timeperiod['dayofweek_su'] = $dayofweek[6];
    // months
    $month = '';
    $month .= !isset($new_timeperiod['month_jan']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_feb']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_mar']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_apr']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_may']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_jun']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_jul']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_aug']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_sep']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_oct']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_nov']) ? '0' : '1';
    $month .= !isset($new_timeperiod['month_dec']) ? '0' : '1';
    if (isset($new_timeperiod['month'])) {
        $month = zbx_num2bitstr($new_timeperiod['month'], true);
    }
    $new_timeperiod['month_jan'] = $month[0];
    $new_timeperiod['month_feb'] = $month[1];
    $new_timeperiod['month_mar'] = $month[2];
    $new_timeperiod['month_apr'] = $month[3];
    $new_timeperiod['month_may'] = $month[4];
    $new_timeperiod['month_jun'] = $month[5];
    $new_timeperiod['month_jul'] = $month[6];
    $new_timeperiod['month_aug'] = $month[7];
    $new_timeperiod['month_sep'] = $month[8];
    $new_timeperiod['month_oct'] = $month[9];
    $new_timeperiod['month_nov'] = $month[10];
    $new_timeperiod['month_dec'] = $month[11];
    $bit_dayofweek = zbx_str_revert($dayofweek);
    $bit_month = zbx_str_revert($month);
    $cmbType = new CComboBox('new_timeperiod[timeperiod_type]', $new_timeperiod['timeperiod_type'], 'submit()');
    $cmbType->addItem(TIMEPERIOD_TYPE_ONETIME, _('One time only'));
    $cmbType->addItem(TIMEPERIOD_TYPE_DAILY, _('Daily'));
    $cmbType->addItem(TIMEPERIOD_TYPE_WEEKLY, _('Weekly'));
    $cmbType->addItem(TIMEPERIOD_TYPE_MONTHLY, _('Monthly'));
    $tblPeriod->addRow(array(_('Period type'), $cmbType));
    if ($new_timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_DAILY) {
        $tblPeriod->addItem(new CVar('new_timeperiod[dayofweek]', bindec($bit_dayofweek)));
        $tblPeriod->addItem(new CVar('new_timeperiod[month]', bindec($bit_month)));
        $tblPeriod->addItem(new CVar('new_timeperiod[day]', $new_timeperiod['day']));
        $tblPeriod->addItem(new CVar('new_timeperiod[start_date]', $new_timeperiod['start_date']));
        $tblPeriod->addItem(new CVar('new_timeperiod[month_date_type]', $new_timeperiod['month_date_type']));
        $tblPeriod->addRow(array(_('Every day(s)'), new CNumericBox('new_timeperiod[every]', $new_timeperiod['every'], 3)));
    } elseif ($new_timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_WEEKLY) {
        $tblPeriod->addItem(new CVar('new_timeperiod[month]', bindec($bit_month)));
        $tblPeriod->addItem(new CVar('new_timeperiod[day]', $new_timeperiod['day']));
        $tblPeriod->addItem(new CVar('new_timeperiod[start_date]', $new_timeperiod['start_date']));
        $tblPeriod->addItem(new CVar('new_timeperiod[month_date_type]', $new_timeperiod['month_date_type']));
        $tblPeriod->addRow(array(_('Every week(s)'), new CNumericBox('new_timeperiod[every]', $new_timeperiod['every'], 2)));
        $tabDays = new CTable();
        $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_mo]', $dayofweek[0], null, 1), _('Monday')));
        $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_tu]', $dayofweek[1], null, 1), _('Tuesday')));
        $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_we]', $dayofweek[2], null, 1), _('Wednesday')));
        $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_th]', $dayofweek[3], null, 1), _('Thursday')));
        $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_fr]', $dayofweek[4], null, 1), _('Friday')));
        $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_sa]', $dayofweek[5], null, 1), _('Saturday')));
        $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_su]', $dayofweek[6], null, 1), _('Sunday')));
        $tblPeriod->addRow(array(_('Day of week'), $tabDays));
    } elseif ($new_timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_MONTHLY) {
        $tblPeriod->addItem(new CVar('new_timeperiod[start_date]', $new_timeperiod['start_date']));
        $tabMonths = new CTable();
        $tabMonths->addRow(array(new CCheckBox('new_timeperiod[month_jan]', $month[0], null, 1), _('January'), SPACE, SPACE, new CCheckBox('new_timeperiod[month_jul]', $month[6], null, 1), _('July')));
        $tabMonths->addRow(array(new CCheckBox('new_timeperiod[month_feb]', $month[1], null, 1), _('February'), SPACE, SPACE, new CCheckBox('new_timeperiod[month_aug]', $month[7], null, 1), _('August')));
        $tabMonths->addRow(array(new CCheckBox('new_timeperiod[month_mar]', $month[2], null, 1), _('March'), SPACE, SPACE, new CCheckBox('new_timeperiod[month_sep]', $month[8], null, 1), _('September')));
        $tabMonths->addRow(array(new CCheckBox('new_timeperiod[month_apr]', $month[3], null, 1), _('April'), SPACE, SPACE, new CCheckBox('new_timeperiod[month_oct]', $month[9], null, 1), _('October')));
        $tabMonths->addRow(array(new CCheckBox('new_timeperiod[month_may]', $month[4], null, 1), _('May'), SPACE, SPACE, new CCheckBox('new_timeperiod[month_nov]', $month[10], null, 1), _('November')));
        $tabMonths->addRow(array(new CCheckBox('new_timeperiod[month_jun]', $month[5], null, 1), _('June'), SPACE, SPACE, new CCheckBox('new_timeperiod[month_dec]', $month[11], null, 1), _('December')));
        $tblPeriod->addRow(array(_('Month'), $tabMonths));
        $radioDaily = new CTag('input');
        $radioDaily->setAttribute('type', 'radio');
        $radioDaily->setAttribute('name', 'new_timeperiod[month_date_type]');
        $radioDaily->setAttribute('value', '0');
        $radioDaily->setAttribute('onclick', 'submit()');
        $radioDaily2 = new CTag('input');
        $radioDaily2->setAttribute('type', 'radio');
        $radioDaily2->setAttribute('name', 'new_timeperiod[month_date_type]');
        $radioDaily2->setAttribute('value', '1');
        $radioDaily2->setAttribute('onclick', 'submit()');
        if ($new_timeperiod['month_date_type']) {
            $radioDaily2->setAttribute('checked', 'checked');
        } else {
            $radioDaily->setAttribute('checked', 'checked');
        }
        $tblPeriod->addRow(array(_('Date'), array($radioDaily, _('Day'), SPACE, SPACE, $radioDaily2, _('Day of week'))));
        if ($new_timeperiod['month_date_type'] > 0) {
            $tblPeriod->addItem(new CVar('new_timeperiod[day]', $new_timeperiod['day']));
            $cmbCount = new CComboBox('new_timeperiod[every]', $new_timeperiod['every']);
            $cmbCount->addItem(1, _('First'));
            $cmbCount->addItem(2, _('Second'));
            $cmbCount->addItem(3, _('Third'));
            $cmbCount->addItem(4, _('Fourth'));
            $cmbCount->addItem(5, _('Last'));
            $td = new CCol($cmbCount);
            $td->setColSpan(2);
            $tabDays = new CTable();
            $tabDays->addRow($td);
            $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_mo]', $dayofweek[0], null, 1), _('Monday')));
            $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_tu]', $dayofweek[1], null, 1), _('Tuesday')));
            $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_we]', $dayofweek[2], null, 1), _('Wednesday')));
            $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_th]', $dayofweek[3], null, 1), _('Thursday')));
            $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_fr]', $dayofweek[4], null, 1), _('Friday')));
            $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_sa]', $dayofweek[5], null, 1), _('Saturday')));
            $tabDays->addRow(array(new CCheckBox('new_timeperiod[dayofweek_su]', $dayofweek[6], null, 1), _('Sunday')));
            $tblPeriod->addRow(array(_('Day of week'), $tabDays));
        } else {
            $tblPeriod->addItem(new CVar('new_timeperiod[dayofweek]', bindec($bit_dayofweek)));
            $tblPeriod->addRow(array(_('Day of month'), new CNumericBox('new_timeperiod[day]', $new_timeperiod['day'], 2)));
        }
    } else {
        $tblPeriod->addItem(new CVar('new_timeperiod[every]', $new_timeperiod['every'], 'new_timeperiod_every_tmp'));
        $tblPeriod->addItem(new CVar('new_timeperiod[month]', bindec($bit_month), 'new_timeperiod_month_tmp'));
        $tblPeriod->addItem(new CVar('new_timeperiod[day]', $new_timeperiod['day'], 'new_timeperiod_day_tmp'));
        $tblPeriod->addItem(new CVar('new_timeperiod[hour]', $new_timeperiod['hour'], 'new_timeperiod_hour_tmp'));
        $tblPeriod->addItem(new CVar('new_timeperiod[minute]', $new_timeperiod['minute'], 'new_timeperiod_minute_tmp'));
        $tblPeriod->addItem(new CVar('new_timeperiod[start_date]', $new_timeperiod['start_date']));
        $tblPeriod->addItem(new CVar('new_timeperiod[month_date_type]', $new_timeperiod['month_date_type']));
        $tblPeriod->addItem(new CVar('new_timeperiod[dayofweek]', bindec($bit_dayofweek)));
        $clndr_icon = new CImg('images/general/bar/cal.gif', 'calendar', 16, 12, 'pointer');
        $clndr_icon->addAction('onclick', 'javascript: var pos = getPosition(this); pos.top += 10; pos.left += 16; CLNDR["new_timeperiod_date"].clndr.clndrshow(pos.top, pos.left);');
        $filtertimetab = new CTable(null, 'calendar');
        $filtertimetab->setAttribute('width', '10%');
        $filtertimetab->setCellPadding(0);
        $filtertimetab->setCellSpacing(0);
        $startDate = zbxDateToTime($new_timeperiod['start_date']);
        if (isset($_REQUEST['add_timeperiod'])) {
            $newTimePeriodYear = get_request('new_timeperiod_year');
            $newTimePeriodMonth = get_request('new_timeperiod_month');
            $newTimePeriodDay = get_request('new_timeperiod_day');
            $newTimePeriodHours = get_request('new_timeperiod_hour');
            $newTimePeriodMinutes = get_request('new_timeperiod_minute');
        } elseif ($startDate > 0) {
            $newTimePeriodYear = date('Y', $startDate);
            $newTimePeriodMonth = date('m', $startDate);
            $newTimePeriodDay = date('d', $startDate);
            $newTimePeriodHours = date('H', $startDate);
            $newTimePeriodMinutes = date('i', $startDate);
        } else {
            $newTimePeriodYear = '';
            $newTimePeriodMonth = '';
            $newTimePeriodDay = '';
            $newTimePeriodHours = '';
            $newTimePeriodMinutes = '';
        }
        $filtertimetab->addRow(array(new CNumericBox('new_timeperiod_day', $newTimePeriodDay, 2), '/', new CNumericBox('new_timeperiod_month', $newTimePeriodMonth, 2), '/', new CNumericBox('new_timeperiod_year', $newTimePeriodYear, 4), SPACE, new CNumericBox('new_timeperiod_hour', $newTimePeriodHours, 2), ':', new CNumericBox('new_timeperiod_minute', $newTimePeriodMinutes, 2), $clndr_icon));
        zbx_add_post_js('create_calendar(null, ["new_timeperiod_day", "new_timeperiod_month", "new_timeperiod_year", "new_timeperiod_hour", "new_timeperiod_minute"], "new_timeperiod_date", "new_timeperiod_start_date");');
        $tblPeriod->addRow(array(_('Date'), $filtertimetab));
    }
    if ($new_timeperiod['timeperiod_type'] != TIMEPERIOD_TYPE_ONETIME) {
        $tabTime = new CTable(null, 'calendar');
        $tabTime->addRow(array(new CNumericBox('new_timeperiod[hour]', $new_timeperiod['hour'], 2), ':', new CNumericBox('new_timeperiod[minute]', $new_timeperiod['minute'], 2)));
        $tblPeriod->addRow(array(_('At (hour:minute)'), $tabTime));
    }
    $perHours = new CComboBox('new_timeperiod[period_hours]', $new_timeperiod['period_hours']);
    for ($i = 0; $i < 24; $i++) {
        $perHours->addItem($i, $i);
    }
    $perMinutes = new CComboBox('new_timeperiod[period_minutes]', $new_timeperiod['period_minutes']);
    for ($i = 0; $i < 60; $i++) {
        $perMinutes->addItem($i, $i);
    }
    $tblPeriod->addRow(array(_('Maintenance period length'), array(new CNumericBox('new_timeperiod[period_days]', $new_timeperiod['period_days'], 3), _('Days') . SPACE . SPACE, $perHours, SPACE . _('Hours'), $perMinutes, SPACE . _('Minutes'))));
    $td = new CCol(array(new CSubmit('add_timeperiod', $new ? _('Save') : _('Add')), SPACE, new CSubmit('cancel_new_timeperiod', _('Cancel'))));
    $td->setAttribute('colspan', '3');
    $td->setAttribute('style', 'text-align: right;');
    $tblPeriod->setFooter($td);
    return $tblPeriod;
}