1<?php 2/* 3** Zabbix 4** Copyright (C) 2001-2021 Zabbix SIA 5** 6** This program is free software; you can redistribute it and/or modify 7** it under the terms of the GNU General Public License as published by 8** the Free Software Foundation; either version 2 of the License, or 9** (at your option) any later version. 10** 11** This program is distributed in the hope that it will be useful, 12** but WITHOUT ANY WARRANTY; without even the implied warranty of 13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14** GNU General Public License for more details. 15** 16** You should have received a copy of the GNU General Public License 17** along with this program; if not, write to the Free Software 18** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19**/ 20 21 22/** 23 * @var CView $this 24 */ 25 26$form = (new CForm()) 27 ->cleanItems() 28 ->setId('maintenance_period_form') 29 ->addVar('action', 'popup.maintenance.period') 30 ->addVar('refresh', 1) 31 ->addVar('update', $data['update']) 32 ->addVar('index', $data['index']); 33 34$form_list = (new CFormList()); 35 36if (array_key_exists('timeperiodid', $data)) { 37 $form->addVar('timeperiodid', $data['timeperiodid']); 38} 39 40$days_weekly = []; 41$days_monthly = []; 42 43foreach ([1, 4, 6, 2, 5, 7, 3] as $day) { 44 $value = 1 << ($day - 1); 45 $days_weekly[] = [ 46 'name' => getDayOfWeekCaption($day), 47 'value' => $value, 48 'checked' => ($data['timeperiod_type'] == TIMEPERIOD_TYPE_WEEKLY && (bool) ($value & $data['dayofweek'])) 49 ]; 50 $days_monthly[] = [ 51 'name' => getDayOfWeekCaption($day), 52 'value' => $value, 53 'checked' => ($data['timeperiod_type'] == TIMEPERIOD_TYPE_MONTHLY && (bool) ($value & $data['dayofweek'])) 54 ]; 55} 56 57$months = []; 58 59foreach ([1, 5, 9, 2, 6, 10, 3, 7, 11, 4, 8, 12] as $month) { 60 $value = 1 << ($month - 1); 61 $months[] = [ 62 'name' => getMonthCaption($month), 63 'value' => $value, 64 'checked' => ($data['timeperiod_type'] == TIMEPERIOD_TYPE_MONTHLY && (bool) ($value & $data['month'])) 65 ]; 66} 67 68$form_list 69 ->addRow((new CLabel(_('Period type'), 'label-timeperiod-type')), 70 (new CSelect('timeperiod_type')) 71 ->setId('timeperiod_type') 72 ->setFocusableElementId('label-timeperiod-type') 73 ->setValue($data['timeperiod_type']) 74 ->addOptions(CSelect::createOptionsFromArray([ 75 TIMEPERIOD_TYPE_ONETIME => _('One time only'), 76 TIMEPERIOD_TYPE_DAILY => _('Daily'), 77 TIMEPERIOD_TYPE_WEEKLY => _('Weekly'), 78 TIMEPERIOD_TYPE_MONTHLY => _('Monthly') 79 ])) 80 ->setAttribute('autofocus', 'autofocus') 81 ) 82 ->addRow((new CLabel(_('Every day(s)'), 'every_day'))->setAsteriskMark(), 83 (new CNumericBox('every', ($data['timeperiod_type'] == TIMEPERIOD_TYPE_DAILY) ? $data['every'] : 1, 3)) 84 ->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH) 85 ->setId('every_day') 86 ->setAriaRequired(), 87 'row_timeperiod_every_day' 88 ) 89 ->addRow((new CLabel(_('Every week(s)'), 'every_week'))->setAsteriskMark(), 90 (new CNumericBox('every', ($data['timeperiod_type'] == TIMEPERIOD_TYPE_WEEKLY) ? $data['every'] : 1, 2)) 91 ->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH) 92 ->setId('every_week') 93 ->setAriaRequired(), 94 'row_timeperiod_every_week' 95 ) 96 ->addRow((new CLabel(_('Day of week'), 'days'))->setAsteriskMark(), 97 (new CCheckBoxList('days')) 98 ->addClass(ZBX_STYLE_COLUMNS) 99 ->addClass(ZBX_STYLE_COLUMNS_3) 100 ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 101 ->setOptions($days_weekly), 102 'row_timeperiod_dayofweek' 103 ) 104 ->addRow((new CLabel(_('Month'), 'months'))->setAsteriskMark(), 105 (new CCheckBoxList('months')) 106 ->addClass(ZBX_STYLE_COLUMNS) 107 ->addClass(ZBX_STYLE_COLUMNS_3) 108 ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 109 ->setOptions($months), 110 'row_timeperiod_months' 111 ) 112 ->addRow(new CLabel(_('Date'), 'month_date_type'), 113 (new CRadioButtonList('month_date_type', (int) $data['month_date_type'])) 114 ->addValue(_('Day of month'), 0) 115 ->addValue(_('Day of week'), 1) 116 ->setModern(true), 117 'row_timeperiod_date' 118 ) 119 ->addRow((new CLabel(_('Day of week'), 'label-every-dow'))->setAsteriskMark(), 120 (new CSelect('every')) 121 ->setValue($data['every']) 122 ->setFocusableElementId('label-every-dow') 123 ->addOptions(CSelect::createOptionsFromArray([ 124 1 => _('first'), 125 2 => _x('second', 'adjective'), 126 3 => _('third'), 127 4 => _('fourth'), 128 5 => _x('last', 'week of month') 129 ])) 130 ->setId('every_dow'), 131 'row_timeperiod_week' 132 ) 133 ->addRow('', 134 (new CCheckBoxList('monthly_days')) 135 ->addClass(ZBX_STYLE_COLUMNS) 136 ->addClass(ZBX_STYLE_COLUMNS_3) 137 ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 138 ->setOptions($days_monthly), 139 'row_timeperiod_week_days' 140 ) 141 ->addRow((new CLabel(_('Day of month'), 'day'))->setAsteriskMark(), 142 (new CNumericBox('day', ($data['month_date_type'] == 0) ? $data['day'] : 1, 2)) 143 ->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH) 144 ->setAriaRequired(), 145 'row_timeperiod_day' 146 ) 147 ->addRow((new CLabel(_('Date'), 'start_date'))->setAsteriskMark(), 148 (new CDateSelector('start_date', $data['start_date'])) 149 ->setDateFormat(ZBX_DATE_TIME) 150 ->setPlaceholder(_('YYYY-MM-DD hh:mm')) 151 ->setAriaRequired(), 152 'row_timepreiod_start_date' 153 ) 154 ->addRow(new CLabel(_('At (hour:minute)'), 'hour'), 155 (new CDiv([ 156 (new CNumericBox('hour', $data['hour'], 2))->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH), 157 ' : ', 158 (new CNumericBox('minute', $data['minute'], 2))->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH) 159 ]))->addClass(ZBX_STYLE_FORM_FIELDS_INLINE), 160 'row_timeperiod_period_at_hours_minutes' 161 ) 162 ->addRow((new CLabel(_('Maintenance period length'), 'period_days'))->setAsteriskMark(), 163 (new CDiv([ 164 (new CNumericBox('period_days', $data['period_days'], 3))->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH), 165 new CLabel(_('Days'), 'period_days'), 166 (new CSelect('period_hours')) 167 ->setFocusableElementId('label-period-hours') 168 ->setValue($data['period_hours']) 169 ->addOptions(CSelect::createOptionsFromArray(range(0, 23))), 170 new CLabel(_('Hours'), 'label-period-hours'), 171 (new CSelect('period_minutes')) 172 ->setFocusableElementId('label-period-minutes') 173 ->setValue($data['period_minutes']) 174 ->addOptions(CSelect::createOptionsFromArray(range(0, 59))), 175 new CLabel(_('Minutes'), 'label-period-minutes') 176 ]))->addClass(ZBX_STYLE_FORM_FIELDS_INLINE), 177 'row_timeperiod_period_length' 178 ); 179 180$form 181 ->addItem($form_list) 182 ->addItem((new CInput('submit', 'submit'))->addStyle('display: none;')); 183 184$output = [ 185 'header' => $data['title'], 186 'body' => (new CDiv([$data['errors'], $form]))->toString(), 187 'buttons' => [ 188 [ 189 'title' => $data['update'] ? _('Apply') : _('Add'), 190 'class' => 'dialogue-widget-save', 191 'keepOpen' => true, 192 'isSubmit' => true, 193 'action' => 'return submitMaintenancePeriod(overlay);' 194 ] 195 ], 196 'params' => $data['params'], 197 'script_inline' => $this->readJsFile('popup.maintenance.period.js.php') 198]; 199 200if ($data['user']['debug_mode'] == GROUP_DEBUG_MODE_ENABLED) { 201 CProfiler::getInstance()->stop(); 202 $output['debug'] = CProfiler::getInstance()->make()->toString(); 203} 204 205echo json_encode($output); 206