require_once dirname(__FILE__).'/include/config.inc.php';
require_once dirname(__FILE__).'/include/hosts.inc.php';
$page['title'] = _('Configuration of host groups');
$page['file'] = 'hostgroups.php';
require_once dirname(__FILE__).'/include/page_header.php';
'groups' => [T_ZBX_INT, O_OPT, P_SYS|P_ONLY_ARRAY, DB_ID, null],
'groupid' => [T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({form}) && {form} == "update"'],
'name' => [T_ZBX_STR, O_OPT, null, NOT_EMPTY, 'isset({add}) || isset({update})', _('Group name')],
'subgroups' => [T_ZBX_INT, O_OPT, null, IN([1]), null],
'action' => [T_ZBX_STR, O_OPT, P_SYS|P_ACT,
IN('"hostgroup.massdelete","hostgroup.massdisable","hostgroup.massenable"'),
'add' => [T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null],
'update' => [T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null],
'clone' => [T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null],
'delete' => [T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null],
'cancel' => [T_ZBX_STR, O_OPT, P_SYS, null, null],
'form' => [T_ZBX_STR, O_OPT, P_SYS, null, null],
'form_refresh' => [T_ZBX_INT, O_OPT, P_SYS, null, null],
'filter_set' => [T_ZBX_STR, O_OPT, P_SYS, null, null],
'filter_rst' => [T_ZBX_STR, O_OPT, P_SYS, null, null],
'filter_name' => [T_ZBX_STR, O_OPT, P_NO_TRIM, null, null],
'sort' => [T_ZBX_STR, O_OPT, P_SYS, IN('"name"'), null],
'sortorder' => [T_ZBX_STR, O_OPT, P_SYS, IN('"'.ZBX_SORT_DOWN.'","'.ZBX_SORT_UP.'"'), null]
if (hasRequest('form')) {
if (hasRequest('clone')) {
unset($_REQUEST['groupid']);
elseif (hasRequest('add') || hasRequest('update')) {
$groupId = getRequest('groupid');
$name = getRequest('name');
$messageSuccess = _('Group updated');
$messageFailed = _('Cannot update group');
'groupid' => getRequest('groupid'),
'name' => getRequest('name')
$oldGroups = API::HostGroup()->get([
'output' => ['name', 'flags'],
'selectHosts' => ['hostid'],
'selectTemplates' => ['templateid'],
$oldGroup = reset($oldGroups);