[% PROCESS _header.tt css="thruk/plugins/reports/reports.css" js="thruk/plugins/reports/reports.js" %]
[% PROCESS _message.tt %]
[% USE date %]

<table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
    <td align="left" valign="top" width="33%">
      [% PROCESS _infobox.tt %]
    </td>
    <td align="center" valign="top" width="33%">
      <br><br>
      <div align="center" class='dataTitle'>
        Reporting
      </div>
    </td>
    <td align="right" valign="bottom" width="33%">
      [% PROCESS _help.tt topic = "reports" %]
    </td>
  </tr>
</table>

[% running = 0 %]
<div style="margin-left: 10px; display: table;">
<div style="text-align: right; margin-bottom: 3px;"><a href="reports.cgi?action=edit&amp;report=new" class="report_button report_save_button" style="width: 160px;">create new report</a></div>
<div id="reports_table">
<table border="1" class='status' id="statusTable" style="max-width: 1000px;">
  <tr>
    <th class="status" nowrap width="200">Name</th>
    <th class="status" nowrap>Description</th>
    <th class="status" nowrap width="40">Public</th>
    <th class="status" nowrap width="40">Mail</th>
    <th class="status" nowrap width="100">Schedule</th>
    <th class="status" nowrap width="150">Last Time Run</th>
    <th class="status" nowrap width="150">Duration</th>
    <th class="status" nowrap width="25">&nbsp;</th>
    <th class="status" nowrap width="25">&nbsp;</th>
    <th class="status" nowrap width="25">&nbsp;</th>
  </tr>
  [% FOREACH r = reports %]
  [% SET rowclass = 'statusOdd'  IF loop.even %]
  [% SET rowclass = 'statusEven' IF loop.odd %]
  <tr[% IF loop.first %] class="firstrow"[% END %]>
    <td class="status [% rowclass %]" align="left">[% r.name %]</td>
    <td class="status [% rowclass %]" align="left">[% IF r.desc.length > 50 %]<span title="[% r.desc %]">[% r.desc.substr(0,50) %]...</span>[% ELSE %][% r.desc %][% END %]</td>
    <td class="status [% rowclass %]">[% IF r.is_public %]yes[% ELSE %]no[% END %]</td>
    <td class="status [% rowclass %]">[% IF ( r.to || r.cc ) && r.send_types.size > 0 %]yes[% ELSE %]no[% END %]</td>
    <td class="status [% rowclass %]" nowrap>[% IF r.send_types.size == 0 %]never[% ELSE %][% FOREACH st = r.send_types %][% format_cronentry(c, st) %]<br>[% END %][% END %]</td>
    <td class="status [% rowclass %]">
      [% IF r.var.start_time %][% date_format(c, r.var.start_time) %][% ELSE %]never[% END %]
    </td>
    <td class="status [% rowclass %]">
      [% IF r.failed %]
        <span class="clickable" style="color: red;" [% info_popup_event_type %]="return overlib('[% escape_quotes(r.error) | nl2br %]',CAPTION,'report error',WIDTH,700,[% c.config.info_popup_options %]);">
        failed
        </span>
      [% ELSE %]
        [% IF r.var.start_time %]
          [% IF r.var.is_running > 0 %][% end_time = date.now %][% ELSE %][% end_time = r.var.end_time %][% END %]
          [% duration(end_time - r.var.start_time) %]
        [% END %]
      [% END %]
    </td>
    <td class="status [% rowclass %]">
      [% IF r.var.is_running != 0 %]
        [% running = running + 1 %]
        <a href="#" class="is_running"><img src='[% url_prefix %]thruk/themes/[% theme %]/images/waiting.gif' border="0" alt='Report is currently beeing refreshed' title='Report is currently beeing refreshed' width=16 height=16></a>
      [% ELSE %]
        <a href="reports.cgi?report=[% r.nr %]&amp;action=update"><img src='[% url_prefix %]thruk/themes/[% theme %]/images/arrow_refresh.png' border="0" alt='Refresh Report' title='Refresh Report' width=16 height=16></a>
      [% END %]
    </td>
    <td class="status [% rowclass %]">
      [% IF ! r.readonly %]
        <a href="reports.cgi?report=[% r.nr %]&amp;action=edit"><img src='[% url_prefix %]thruk/themes/[% theme %]/images/edit.png' border="0" alt='Change Report' title='Change Report' width=16 height=16></a>
      [% END %]
    </td>
    <td class="status [% rowclass %]">
      [% IF r.var.file_exists && r.var.is_running == 0 %]
      [% icon = 'page_white_acrobat.png' %]
      [% IF    r.var.ctype == 'application/x-msexcel' %][% icon = 'page_white_excel.png' %]
      [% ELSIF r.var.ctype == 'text/html'             %][% icon = 'page_world.png' %]
      [% ELSIF r.var.ctype == 'image/png'             %][% icon = 'page_white_picture.png' %]
      [% ELSIF r.var.ctype != '' %][% icon = 'page_white_text.png' %]
      [% END %]
      <a href="reports.cgi?report=[% r.nr %]&amp;refresh=0"><img src='[% url_prefix %]thruk/themes/[% theme %]/images/[% icon %]' border="0" alt='View Report' title='View Report' width=16 height=16></a>
      [% END %]
    </td>
  </tr>
  [% END %]
  [% IF reports.size == 0 %]
  <tr class="firstrow">
    <td class="status statusOdd" align="center" colspan="10">no reports defined yet</td>
  </tr>
  [% END %]
</table>
</div>
</div>

<script type="text/javascript">
<!--
  init_report_tool_buttons();
  [% IF running > 0 %]
  var update_reports_status_int = window.setInterval("update_reports_status()", 1000);
  [%+ END +%]
-->
</script>
