$form->addItem(array(SPACE . S_HOST . SPACE, $cmbHosts)); $numrows = new CSpan(null, 'info'); $numrows->addOption('name', 'numrows'); $header = get_table_header(array(S_APPLICATIONS_BIG, new CSpan(SPACE . SPACE . '|' . SPACE . SPACE, 'divider'), S_FOUND . ': ', $numrows)); show_table_header($header, $form); /* TABLE */ $form = new CForm(); $form->setName('applications'); $table = new CTableInfo(); $table->setHeader(array(array(new CCheckBox('all_applications', NULL, "CheckAll('" . $form->GetName() . "','all_applications');"), SPACE, make_sorting_link(S_APPLICATION, 'a.name')), S_SHOW)); $db_applications = DBselect('SELECT a.* ' . ' FROM applications a' . ' WHERE a.hostid=' . $_REQUEST['hostid'] . order_by('a.name')); while ($db_app = DBfetch($db_applications)) { if ($db_app['templateid'] == 0) { $name = new CLink($db_app['name'], 'hosts.php?form=update&applicationid=' . $db_app['applicationid'] . url_param('config'), 'action'); } else { $template_host = get_realhost_by_applicationid($db_app['templateid']); $name = array(new CLink($template_host['host'], 'hosts.php?hostid=' . $template_host['hostid'] . url_param('config'), 'action'), ':', $db_app['name']); } $items = get_items_by_applicationid($db_app['applicationid']); $rows = 0; while (DBfetch($items)) { $rows++; } $table->addRow(array(array(new CCheckBox('applications[' . $db_app['applicationid'] . ']', NULL, NULL, $db_app['applicationid']), SPACE, $name), array(new CLink(S_ITEMS, 'items.php?hostid=' . $db_app['hostid'], 'action'), SPACE . '(' . $rows . ')'))); $row_count++; } $table->setFooter(new CCol(array(new CButtonQMessage('activate', S_ACTIVATE_ITEMS, S_ACTIVATE_ITEMS_FROM_SELECTED_APPLICATIONS_Q), SPACE, new CButtonQMessage('disable', S_DISABLE_ITEMS, S_DISABLE_ITEMS_FROM_SELECTED_APPLICATIONS_Q), SPACE, new CButtonQMessage('delete', S_DELETE_SELECTED, S_DELETE_SELECTED_APPLICATIONS_Q)))); $form->addItem($table); $form->show(); } } else {
function get_realhost_by_applicationid($applicationid) { $application = get_application_by_applicationid($applicationid); if ($application["templateid"] > 0) { return get_realhost_by_applicationid($application["templateid"]); } return get_host_by_applicationid($applicationid); }
// get application $sortfield = getPageSortField('name'); $sortorder = getPageSortOrder(); $options = array('output' => API_OUTPUT_SHORTEN, 'editable' => 1, 'sortfield' => $sortfield, 'limit' => $config['search_limit'] + 1); if ($data['pageFilter']->hostid > 0) { $options['hostids'] = $data['pageFilter']->hostid; } elseif ($data['pageFilter']->groupid > 0) { $options['groupids'] = $data['pageFilter']->groupid; } $data['applications'] = API::Application()->get($options); // get applications $options = array('applicationids' => zbx_objectValues($data['applications'], 'applicationid'), 'output' => API_OUTPUT_EXTEND, 'selectItems' => API_OUTPUT_REFER, 'expandData' => 1); $data['applications'] = API::Application()->get($options); order_result($data['applications'], $sortfield, $sortorder); // fill applications with templated hosts foreach ($data['applications'] as $id => $application) { if (!empty($application['templateid'])) { $data['applications'][$id]['template_host'] = get_realhost_by_applicationid($application['templateid']); } } } else { $data['applications'] = array(); } // get paging $data['paging'] = getPagingLine($data['applications']); // render view $applicationView = new CView('configuration.application.list', $data); $applicationView->render(); $applicationView->show(); } require_once dirname(__FILE__) . '/include/page_footer.php';