require_once dirname(__FILE__).'/include/config.inc.php';
require_once dirname(__FILE__).'/include/hosts.inc.php';
require_once dirname(__FILE__).'/include/forms.inc.php';
$page['title'] = _('Configuration of applications');
$page['file'] = 'applications.php';
$page['scripts'] = ['multiselect.js'];
require_once dirname(__FILE__).'/include/page_header.php';
'applications' => [T_ZBX_INT, O_OPT, P_SYS, DB_ID, null],
'hostid' => [T_ZBX_INT, O_OPT, P_SYS, DB_ID.NOT_ZERO, 'isset({form}) && !isset({applicationid})'],
'applicationid' => [T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({form}) && {form} == "update"'],
'appname' => [T_ZBX_STR, O_OPT, null, NOT_EMPTY, 'isset({add}) || isset({update})', _('Name')],
'action' => [T_ZBX_STR, O_OPT, P_SYS|P_ACT,
IN('"application.massdelete","application.massdisable","application.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, null, 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_groups' => [T_ZBX_INT, O_OPT, null, DB_ID, null],
'filter_hostids' => [T_ZBX_INT, O_OPT, null, DB_ID, 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 (isset($_REQUEST['applicationid'])) {
$dbApplication = API::Application()->get([
'output' => ['name', 'hostid'],
'applicationids' => [$_REQUEST['applicationid']],
elseif (getRequest('hostid') && !isWritableHostTemplates([getRequest('hostid')])) {
$sort_field = getRequest('sort', CProfile::get('web.'.$page['file'].'.sort', 'name'));
$sort_order = getRequest('sortorder', CProfile::get('web.'.$page['file'].'.sortorder', ZBX_SORT_UP));
CProfile::update('web.'.$page['file'].'.sort', $sort_field, PROFILE_TYPE_STR);
CProfile::update('web.'.$page['file'].'.sortorder', $sort_order, PROFILE_TYPE_STR);
if (hasRequest('filter_set')) {
CProfile::updateArray('web.applications.filter_groups', getRequest('filter_groups', []), PROFILE_TYPE_ID);
CProfile::updateArray('web.applications.filter_hostids', getRequest('filter_hostids', []), PROFILE_TYPE_ID);
elseif (hasRequest('filter_rst')) {