function delete_template_applications($hostid, $templateids = null, $unlink_mode = false) { zbx_value2array($templateids); $db_apps = get_applications_by_hostid($hostid); while ($db_app = DBfetch($db_apps)) { if ($db_app["templateid"] == 0) { continue; } if (!is_null($templateids)) { unset($skip); if ($tmp_app_data = get_application_by_applicationid($db_app["templateid"])) { if (!uint_in_array($tmp_app_data["hostid"], $templateids)) { $skip = true; break; } } if (isset($skip)) { continue; } } if ($unlink_mode) { if (DBexecute("update applications set templateid=0 where applicationid=" . $db_app["applicationid"])) { info(S_APPLICATION . SPACE . "'" . $db_app["name"] . "'" . SPACE . S_UNLINKED_SMALL); } } else { delete_application($db_app["applicationid"]); } } }
function get_resource_name($permission, $id) { $res = '-'; if ($permission == 'Graph') { if (isset($id) && $id != 0) { if ($graph = get_graph_by_graphid($id)) { $res = $graph['name']; } } else { if (!isset($id) || $id == 0) { $res = 'All graphs'; } } } else { if ($permission == 'Host') { if (isset($id) && $id != 0) { if ($host = get_host_by_hostid($id)) { $res = $host['host']; } } else { if (!isset($id) || $id == 0) { $res = 'All hosts'; } } } else { if ($permission == 'Screen') { if (isset($id) && $id != 0) { if ($screen = get_screen_by_screenid($id)) { $res = $screen['name']; } } else { if (!isset($id) || $id == 0) { $res = 'All screens'; } } } else { if ($permission == 'Item') { if (isset($id) && $id != 0) { if ($item = get_item_by_itemid($id)) { if ($host = get_host_by_hostid($item['hostid'])) { $res = $host['host'] . ':' . $item['description']; } } } else { if (!isset($id) || $id == 0) { $res = 'All items'; } } } else { if ($permission == 'User') { if (isset($id) && $id != 0) { if ($user = get_user_by_userid($id)) { $res = $user['alias']; } } else { if (!isset($id) || $id == 0) { $res = 'All users'; } } } else { if ($permission == 'Network map') { if (isset($id) && $id != 0) { if ($user = get_sysmap_by_sysmapid($id)) { $res = $user['name']; } } else { if (!isset($id) || $id == 0) { $res = 'All maps'; } } } else { if ($permission == 'Application') { if (isset($id) && $id > 0) { if ($app = get_application_by_applicationid($id)) { $res = $app['name']; } } else { if (!isset($id) || $id == 0) { $res = 'All applications'; } } } else { if ($permission == 'Service') { if (isset($id) && $id > 0) { if ($service = get_service_by_serviceid($id)) { $res = $service['name']; } } else { if (!isset($id) || $id == 0) { $res = 'All services'; } } } } } } } } } } if ($res == '-' && isset($id) && $id > 0) { $res = $id; } return $res; }
add_audit($auditAction, AUDIT_RESOURCE_APPLICATION, _('Application') . ' [' . $_REQUEST['appname'] . '] [' . $applicationId . ']'); unset($_REQUEST['form']); } $result = DBend($dbApplications); if ($result) { uncheckTableRows(getRequest('hostid')); } show_messages($result, $messageSuccess, $messageFailed); } elseif (isset($_REQUEST['clone']) && isset($_REQUEST['applicationid'])) { unset($_REQUEST['applicationid']); $_REQUEST['form'] = 'clone'; } elseif (isset($_REQUEST['delete'])) { if (isset($_REQUEST['applicationid'])) { $result = false; DBstart(); if ($app = get_application_by_applicationid($_REQUEST['applicationid'])) { $host = get_host_by_hostid($app['hostid']); $result = API::Application()->delete(array(getRequest('applicationid'))); } if ($result) { add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_APPLICATION, 'Application [' . $app['name'] . '] from host [' . $host['host'] . ']'); } unset($_REQUEST['form'], $_REQUEST['applicationid']); $result = DBend($result); if ($result) { uncheckTableRows(getRequest('hostid')); } show_messages($result, _('Application deleted'), _('Cannot delete application')); } } elseif (hasRequest('action') && getRequest('action') == 'application.massdelete' && hasRequest('applications')) { $result = true;
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); }