[%# EDIT #%]
[% IF block == 'edit' %]
  [%
    deprecated = 1;
    required_fields = [
        { 'language'                     => [ 'Language',                   'language',        'en'                  ,'', 1    ] },
        { 'affected_sla_objects'         => [ '',                           'affected_sla_objects', ''                         ] },
        { 'host'                         => [ 'Host',                       'hosts',           ''                              ] },
        { 'service'                      => [ 'Service',                    'services',        ''                              ] },
        { 'timeperiod'                   => [ 'Timeperiod',                 'rptimeperiod',    'last12months'                  ] },
        { 'breakdown'                    => [ 'Breakdown by',               'breakdowns',      'months'                        ] },
        { 'rpttimeperiod'                => [ 'Report Timeperiod',          'rpttimeperiod',   ''                              ] },
        { 'sla'                          => [ 'SLA %',                      'int',             '98'                  ,'', 1    ] },
        { 'graph_min_sla'                => [ 'Graph SLA %',                'int',             '90'                  ,'', 1    ] },
        { 'decimals'                     => [ 'Decimal Points',             'int',             '2'                   ,'', 1    ] },
        { 'servicenameformat'            => [ 'Servicename Format',         'serviceformat', 'description'                     ] },
        { 'dateformat'                   => [ 'Dateformat',                 'dateformat', ''                                   ] },
        { 'datetimeformat'               => [ 'Datetimeformat',             'datetimeformat', ''                               ] },
        { 'assumeinitialstates'          => [ 'Assume Initial States',      'yes_no',          'yes'                           ] },
        { 'initialassumedservicestate'   => [ 'Initial Assumed State',      'svc_initialassumedstate',          '0'            ] },
        { 'includesoftstates'            => [ 'Include Soft States',        'yes_no',          'no'                            ] },
        { 'unavailable'                  => [ 'Unavailable States',         'svc_unavailable', ['critical', 'unknown'], '', 1  ] },
        { 'overview_max_level'           => [ 'Overview SLA %',             'int_box',         '-1' ,'hide object from overview table if sla is above or equal threshold', 0, 100 ] },
        { 'details_max_level'            => [ 'Details SLA %',              'int_box',         '100' ,'hide details if sla is above or equal threshold', 1, 100 ] },
        { 'mail_max_level'               => [ 'Mail SLA %',                 'int_box',         '-1', 'cancel mail if no object breaks this sla', 0, 100] },
        { 'max_worst_pages'              => [ 'Worst Outages',              'int_box',          '1'          ,'max. # pages', 1, 1 ] },
        { 'max_outages_pages'            => [ 'Latest Outages',             'int_box',         '-1'          ,'max. # pages', 1, 1 ] },
        { 'max_pnp_sources'              => [ 'Maximum Graph Sources',      'int_box',          '1'          ,'max. # graph images', 1, 1 ] },
        { 'attach_json'                  => [ 'Attach Json',                'yes_no',           'no', 'attach json raw data'  ] },
    ];
  %]
[% END %]

[%# MAIL LAYOUT #%]
[% PROCESS 'reports/comp/mail.tt' %]

[%# PREPARE REPORT #%]
[% PROCESS 'reports/comp/sla_prepare.tt' %]

[%# REPORT LAYOUT #%]
[% IF block == 'render' %]
  [% PROCESS 'reports/comp/sla_render_settings.tt' %]
  [%
    title        = loc('SLA Report')
    subtitle     = r.name
    coverdetails = [ loc('Report Timeperiod:'), get_report_timeperiod(start, end, reportDateFormat) ];
    IF param.host;    coverdetails.push(loc('Host:'),    param.host);    END;
    IF param.service; coverdetails.push(loc('Service:'), param.service); END;
  %]

  [% WRAPPER 'reports/comp/report.tt' %]
    [% WRAPPER 'reports/comp/page_cover.tt' %][% END %]
    [% PROCESS 'reports/comp/backend_error_page.tt' %]

    [% IF total_services > 1 %]
      [% WRAPPER 'reports/comp/page_standard.tt' pagetitle=loc("SLA Overview Graph") %]
        [% PROCESS 'reports/comp/sla_total_graph.tt' type='service' %]
      [% END %]
    [% END %]

    [% FOREACH hst = avail_data.services.keys.sort %]
      [% FOREACH svc = avail_data.services.$hst.keys.sort %]
        [% available = get_availability_percents(hst, svc) %]
        [% p = available.total.percent;
           IF p == -1; p = 100; END;
           IF param.exists('mail_max_level') && param.mail_max_level != -1 && p < param.mail_max_level; param.mail_max_level_count = param.mail_max_level_count + 1; END;
           IF total_services > 1 && param.details_max_level != -1 && p >= param.details_max_level; NEXT;
          END %]
        [% pagetitle                    = loc("Service: %s on %s", _svc(hst, svc), _hst(hst)) %]

        [% WRAPPER 'reports/comp/page_standard.tt'  %]
          [% PROCESS 'reports/comp/sla_graph_page.tt' %]
        [% END %]
        [% PROCESS 'reports/comp/pnp_multiple_graph_page.tt' %]
        [% PROCESS 'reports/comp/sla_outages.tt' %]
      [% END %]
    [% END %]

  [% END %][%# report wrapper #%]
[% END %][%# render block #%]
