<?php declare(strict_types = 0);
class CReport extends CApiService {
public const ACCESS_RULES = [
'min_user_type' => USER_TYPE_ZABBIX_ADMIN
'min_user_type' => USER_TYPE_ZABBIX_ADMIN,
'action' => CRoleHelper::ACTIONS_MANAGE_SCHEDULED_REPORTS
'min_user_type' => USER_TYPE_ZABBIX_ADMIN,
'action' => CRoleHelper::ACTIONS_MANAGE_SCHEDULED_REPORTS
'min_user_type' => USER_TYPE_ZABBIX_ADMIN,
'action' => CRoleHelper::ACTIONS_MANAGE_SCHEDULED_REPORTS
protected $tableName = 'report';
protected $tableAlias = 'r';
protected $sortColumns = ['reportid', 'name', 'status'];
private $output_fields = ['reportid', 'userid', 'name', 'description', 'status', 'dashboardid', 'period', 'cycle',
'weekdays', 'start_time', 'active_since', 'active_till', 'state', 'lastsent', 'info', 'subject', 'message'
private $user_output_fields = ['userid', 'access_userid', 'exclude'];
private $usrgrp_output_fields = ['usrgrpid', 'access_userid'];
public function get(array $options = []) {
$api_input_rules = ['type' => API_OBJECT, 'fields' => [
'reportids' => ['type' => API_IDS, 'flags' => API_ALLOW_NULL | API_NORMALIZE, 'default' => null],
'expired' => ['type' => API_BOOLEAN, 'flags' => API_ALLOW_NULL, 'default' => null],
'filter' => ['type' => API_FILTER, 'flags' => API_ALLOW_NULL, 'default' => null, 'fields' => ['reportid', 'userid', 'name', 'dashboardid', 'status', 'state']],
'search' => ['type' => API_FILTER, 'flags' => API_ALLOW_NULL, 'default' => null, 'fields' => ['name']],
'searchByAny' => ['type' => API_BOOLEAN, 'default' => false],
'startSearch' => ['type' => API_FLAG, 'default' => false],
'excludeSearch' => ['type' => API_FLAG, 'default' => false],
'searchWildcardsEnabled' => ['type' => API_BOOLEAN, 'default' => false],
'output' => ['type' => API_OUTPUT, 'in' => implode(',', $this->output_fields), 'default' => API_OUTPUT_EXTEND],
'countOutput' => ['type' => API_FLAG, 'default' => false],
'selectUsers' => ['type' => API_OUTPUT, 'flags' => API_ALLOW_NULL, 'in' => implode(',', $this->user_output_fields), 'default' => null],
'selectUserGroups' => ['type' => API_OUTPUT, 'flags' => API_ALLOW_NULL, 'in' => implode(',', $this->usrgrp_output_fields), 'default' => null],
'sortfield' => ['type' => API_STRINGS_UTF8, 'flags' => API_NORMALIZE, 'in' => implode(',', $this->sortColumns), 'uniq' => true, 'default' => []],
'sortorder' => ['type' => API_SORTORDER, 'default' => []],
'limit' => ['type' => API_INT32, 'flags' => API_ALLOW_NULL, 'in' => '1:'.ZBX_MAX_INT32, 'default' => null],
'preservekeys' => ['type' => API_BOOLEAN, 'default' => false]
if (!CApiInputValidator::validate($api_input_rules, $options, '/', $error)) {
self::exception(ZBX_API_ERROR_PARAMETERS, $error);
$sql_parts = $this->createSelectQueryParts($this->tableName(), $this->tableAlias(), $options);
if ($options['expired'] !== null) {
$sql_parts['where'][] = $options['expired']
? '(r.active_till>0 AND r.active_till<'.time().')'
: '(r.active_till=0 OR r.active_till>='.time().')';