<?php
class CControllerPopupMedia extends CController {
protected function init() {
$this->disableCsrfValidation();
}
protected function checkInput() {
$fields = [
'dstfrm' => 'required|string',
'media' => 'int32',
'mediatypeid' => 'db media_type.mediatypeid',
'sendto' => 'string',
'sendto_emails' => 'array',
'period' => 'time_periods',
'active' => 'in '.implode(',', [MEDIA_STATUS_ACTIVE, MEDIA_STATUS_DISABLED]),
'severity' => '',
'add' => 'in 1'
];
$ret = $this->validateInput($fields);
if (!$ret) {
$this->setResponse(
(new CControllerResponseData(['main_block' => json_encode([
'error' => [
'messages' => array_column(get_and_clear_messages(), 'message')
]
])]))->disableView()
);
}
return $ret;
}
protected function checkPermissions() {
if (CWebUser::getType() < USER_TYPE_ZABBIX_ADMIN
|| (CWebUser::isGuest() && CWebUser::getType() < USER_TYPE_SUPER_ADMIN)) {
return false;
}
return true;
}
protected function doAction() {
$page_options = [
'dstfrm' => $this->getInput('dstfrm'),
'media' => $this->getInput('media', -1),
'sendto' => $this->getInput('sendto', ''),
'mediatypeid' => $this->getInput('mediatypeid', 0),
'active' => $this->getInput('active', MEDIA_STATUS_ACTIVE),
'period' => $this->getInput('period', ZBX_DEFAULT_INTERVAL),
'sendto_emails' => array_values($this->getInput('sendto_emails', ['']))
];
if ($this->hasInput('add')) {
$output = [];
if ($page_options['mediatypeid'] == 0) {
error(_s('Incorrect value for field "%1$s": %2$s.', 'mediatypeid', _('cannot be empty')));
}
$db_mediatypes = API::MediaType()->get([
'output' => ['type'],
'mediatypeids' => $page_options['mediatypeid']
]);
$type = $db_mediatypes ? $db_mediatypes[0]['type'] : 0;
if ($db_mediatypes) {
if ($type == MEDIA_TYPE_EMAIL) {