Welcome to mirror list, hosted at ThFree Co, Russian Federation.

popup.maintenance.period.php « views « app « ui - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 00ed746266233f100a5d17c2dd1fa090df633cd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
/*
** Zabbix
** Copyright (C) 2001-2022 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/


/**
 * @var CView $this
 */

$form = (new CForm())
	->cleanItems()
	->setId('maintenance_period_form')
	->addVar('action', 'popup.maintenance.period')
	->addVar('refresh', 1)
	->addVar('update', $data['update'])
	->addVar('index', $data['index']);

$form_list = (new CFormList());

if (array_key_exists('timeperiodid', $data)) {
	$form->addVar('timeperiodid', $data['timeperiodid']);
}

$days_weekly = [];
$days_monthly = [];

foreach (range(1, 7) as $day) {
	$value = 1 << ($day - 1);
	$days_weekly[] = [
		'label' => getDayOfWeekCaption($day),
		'value' => $value,
		'checked' => $data['timeperiod_type'] == TIMEPERIOD_TYPE_WEEKLY && ($value & $data['dayofweek'])
	];
	$days_monthly[] = [
		'label' => getDayOfWeekCaption($day),
		'value' => $value,
		'checked' => $data['timeperiod_type'] == TIMEPERIOD_TYPE_MONTHLY && ($value & $data['dayofweek'])
	];
}

$months = [];

foreach (range(1, 12) as $month) {
	$value = 1 << ($month - 1);
	$months[] = [
		'label' => getMonthCaption($month),
		'value' => $value,
		'checked' => $data['timeperiod_type'] == TIMEPERIOD_TYPE_MONTHLY && ($value & $data['month'])
	];
}

$form_list
	->addRow((new CLabel(_('Period type'), 'label-timeperiod-type')),
		(new CSelect('timeperiod_type'))
			->setId('timeperiod_type')
			->setFocusableElementId('label-timeperiod-type')
			->setValue($data['timeperiod_type'])
			->addOptions(CSelect::createOptionsFromArray([
				TIMEPERIOD_TYPE_ONETIME	=> _('One time only'),
				TIMEPERIOD_TYPE_DAILY	=> _('Daily'),
				TIMEPERIOD_TYPE_WEEKLY	=> _('Weekly'),
				TIMEPERIOD_TYPE_MONTHLY	=> _('Monthly')
			]))
			->setAttribute('autofocus', 'autofocus')
	)
	->addRow((new CLabel(_('Every day(s)'), 'every_day'))->setAsteriskMark(),
		(new CNumericBox('every', ($data['timeperiod_type'] == TIMEPERIOD_TYPE_DAILY) ? $data['every'] : 1, 3))
			->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH)
			->setId('every_day')
			->setAriaRequired(),
		'row_timeperiod_every_day'
	)
	->addRow((new CLabel(_('Every week(s)'), 'every_week'))->setAsteriskMark(),
		(new CNumericBox('every', ($data['timeperiod_type'] == TIMEPERIOD_TYPE_WEEKLY) ? $data['every'] : 1, 2))
			->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH)
			->setId('every_week')
			->setAriaRequired(),
		'row_timeperiod_every_week'
	)
	->addRow((new CLabel(_('Day of week'), 'days'))->setAsteriskMark(),
		(new CCheckBoxList('days'))
			->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
			->setOptions($days_weekly)
			->setVertical(true)
			->setColumns(3),
		'row_timeperiod_dayofweek'
	)
	->addRow((new CLabel(_('Month'), 'months'))->setAsteriskMark(),
		(new CCheckBoxList('months'))
			->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
			->setOptions($months)
			->setVertical(true)
			->setColumns(3),
		'row_timeperiod_months'
	)
	->addRow(new CLabel(_('Date'), 'month_date_type'),
		(new CRadioButtonList('month_date_type', (int) $data['month_date_type']))
			->addValue(_('Day of month'), 0)
			->addValue(_('Day of week'), 1)
			->setModern(true),
		'row_timeperiod_date'
	)
	->addRow((new CLabel(_('Day of week'), 'label-every-dow'))->setAsteriskMark(),
		(new CSelect('every'))
			->setValue($data['every'])
			->setFocusableElementId('label-every-dow')
			->addOptions(CSelect::createOptionsFromArray([
				1 => _('first'),
				2 => _x('second', 'adjective'),
				3 => _('third'),
				4 => _('fourth'),
				5 => _x('last', 'week of month')
			]))
			->setId('every_dow'),
		'row_timeperiod_week'
	)
	->addRow('',
		(new CCheckBoxList('monthly_days'))
			->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
			->setOptions($days_monthly)
			->setVertical(true)
			->setColumns(3),
		'row_timeperiod_week_days'
	)
	->addRow((new CLabel(_('Day of month'), 'day'))->setAsteriskMark(),
		(new CNumericBox('day', ($data['month_date_type'] == 0) ? $data['day'] : 1, 2))
			->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH)
			->setAriaRequired(),
		'row_timeperiod_day'
	)
	->addRow((new CLabel(_('Date'), 'start_date'))->setAsteriskMark(),
		(new CDateSelector('start_date', $data['start_date']))
			->setDateFormat(ZBX_DATE_TIME)
			->setPlaceholder(_('YYYY-MM-DD hh:mm'))
			->setAriaRequired(),
		'row_timepreiod_start_date'
	)
	->addRow(new CLabel(_('At (hour:minute)'), 'hour'),
		(new CDiv([
			(new CNumericBox('hour', $data['hour'], 2))->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH),
			' : ',
			(new CNumericBox('minute', $data['minute'], 2))->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH)
		]))->addClass(ZBX_STYLE_FORM_FIELDS_INLINE),
		'row_timeperiod_period_at_hours_minutes'
	)
	->addRow((new CLabel(_('Maintenance period length'), 'period_days'))->setAsteriskMark(),
		(new CDiv([
			(new CNumericBox('period_days', $data['period_days'], 3))->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH),
			new CLabel(_('Days'), 'period_days'),
			(new CSelect('period_hours'))
				->setFocusableElementId('label-period-hours')
				->setValue($data['period_hours'])
				->addOptions(CSelect::createOptionsFromArray(range(0, 23))),
			new CLabel(_('Hours'), 'label-period-hours'),
			(new CSelect('period_minutes'))
				->setFocusableElementId('label-period-minutes')
				->setValue($data['period_minutes'])
				->addOptions(CSelect::createOptionsFromArray(range(0, 59))),
			new CLabel(_('Minutes'), 'label-period-minutes')
		]))->addClass(ZBX_STYLE_FORM_FIELDS_INLINE),
		'row_timeperiod_period_length'
	);

$form
	->addItem($form_list)
	->addItem((new CInput('submit', 'submit'))->addStyle('display: none;'));

$output = [
	'header' => $data['title'],
	'body' => (new CDiv([$data['errors'], $form]))->toString(),
	'buttons' => [
		[
			'title' => $data['update'] ? _('Apply') : _('Add'),
			'class' => 'dialogue-widget-save',
			'keepOpen' => true,
			'isSubmit' => true,
			'action' => 'return submitMaintenancePeriod(overlay);'
		]
	],
	'params' => $data['params'],
	'script_inline' => $this->readJsFile('popup.maintenance.period.js.php')
];

if ($data['user']['debug_mode'] == GROUP_DEBUG_MODE_ENABLED) {
	CProfiler::getInstance()->stop();
	$output['debug'] = CProfiler::getInstance()->make()->toString();
}

echo json_encode($output);