[% USE HTML %]
[% PROCESS _header.tt %]
[% UNLESS nomap %]

<script type="text/javascript">
<!--

  function MyHash()
  {
      this.length = 0;
      for (var i = 0; i < arguments.length; i += 2) {
          if (typeof(arguments[i + 1]) != 'undefined') {
              this[arguments[i]] = arguments[i + 1];
              this.length++;
          }
      }
  }

  function html_entity_decode(str) {
    var ta=document.createElement("textarea");
    ta.innerHTML=str.replace('<',"&lt;").replace('>',"&gt;");
    return ta.value;
  }


  var details = new Array(
  [% FOR a = image_map %]
  new MyHash('start', "[% a.start_human %]", 'end', "[% a.end_human %]", 'state', "[% a.state %]", 'duration',  "[% a.duration %]", 'plugin_output', "[% HTML.escape(a.plugin_output) | replace("'", "\\'") %]", 'real_plugin_output', "[% HTML.escape(a.real_plugin_output) | replace("'", "\\'") %]")[% UNLESS loop.last %],[% END %]

  [% END %]
  );

  var tmp;
  function showDetail(nr) {
    tmp = details[nr];
    document.getElementById('popup').style.visibility='visible';
    document.getElementById('detail_state').innerHTML         = details[nr].state;
    document.getElementById('detail_start').innerHTML         = details[nr].start;
    document.getElementById('detail_end').innerHTML           = details[nr].end;
    document.getElementById('detail_duration').innerHTML      = details[nr].duration;
    if(details[nr].plugin_output != details[nr].real_plugin_output) {
      [% IF escape_html_tags %]
        document.getElementById('detail_plugin_output').innerHTML = details[nr].plugin_output + "<br><i>original output was:<\/i><br>" + details[nr].real_plugin_output;
      [% ELSE %]
        document.getElementById('detail_plugin_output').innerHTML = html_entity_decode(details[nr].plugin_output) + "<br><i>original output was:<\/i><br>" + html_entity_decode(details[nr].real_plugin_output);
      [% END %]
    } else {
      [% IF escape_html_tags %]
        document.getElementById('detail_plugin_output').innerHTML = details[nr].plugin_output;
      [% ELSE %]
        document.getElementById('detail_plugin_output').innerHTML = html_entity_decode(details[nr].plugin_output);
      [% END %]
    }
  }

  function hideDetail() {
    document.getElementById('popup').style.visibility='hidden';
  }
-->
</script>
<div id="popup" class="image_hover">
  <table class="popupBorder" border=1>
    <tr>
      <td>
        <table class="popupText">
          <tr>
            <th colspan=2 id="detail_state"></th>
          </tr>
          <tr>
            <td>Start:</td>
            <td id="detail_start"></td>
          </tr>
          <tr>
            <td>End:</td>
            <td id="detail_end"></td>
          </tr>
          <tr>
            <td>Duration:</td>
            <td id="detail_duration"></td>
          </tr>
          <tr>
            <td>State Info:</td>
            <td id="detail_plugin_output"></td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</div>
[% END %]
<table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
    <td align="left" valign="top" width="33%">
      [% PROCESS _infobox.tt %]
      <table border="1" cellpadding="0" cellspacing="0" class='linkBox'>
        <tr>
          <td class='linkBox'>
            [% IF service %]
            <a href="trends.cgi?host=[% host | uri %]&amp;t1=[% start %]&amp;t2=[% end %]&amp;includesoftstates=[% includesoftstates %]&amp;assumestateretention=[% assumestateretention %]&amp;assumeinitialstates=[% assumeinitialstates %]&amp;assumestatesduringnotrunning=[% assumestatesduringnotrunning %]&amp;initialassumedservicestate=[% initialassumedservicestate %]&amp;backtrack=[% backtrack %]&amp;rpttimeperiod=[% rpttimeperiod %][% IF nomap %]&amp;nomap=[% nomap %][% END %]">View Trends For This Host</a><br>
            <a href="avail.cgi?host=[% host | uri %]&amp;service=[% service | uri %]&amp;t1=[% start %]&amp;t2=[% end %]&amp;assumestateretention=[% assumestateretention %]&amp;includesoftstates=[% includesoftstates %]&amp;assumeinitialstates=[% assumeinitialstates %]&amp;assumestatesduringnotrunning=[% assumestatesduringnotrunning %]&amp;initialassumedservicestate=[% initialassumedservicestate %]&amp;backtrack=[% backtrack %]&amp;rpttimeperiod=[% rpttimeperiod %]&amp;show_log_entries">View Availability Report For This Service</a><br>
            [% IF use_feature_histogram %]<a href="histogram.cgi?host=[% host | uri %]&amp;service=[% service | uri %]&amp;t1=[% start %]&amp;t2=[% end %]&amp;assumestateretention=[% assumestateretention %]">View Alert Histogram For This Service</a><br>[% END %]
            <a href="history.cgi?host=[% host | uri %]&amp;service=[% service | uri %]">View Alert History For This Service</a><br>
            <a href="notifications.cgi?host=[% host | uri %]&amp;service=[% service | uri %]">View Notifications For This Service</a><br>
            [% ELSE %]
            <a href='avail.cgi?host=[% host | uri %]&amp;t1=[% start %]&amp;t2=[% end %]&amp;includesoftstates=[% includesoftstates %]&amp;assumestateretention=[% assumestateretention %]&amp;assumeinitialstates=[% assumeinitialstates %]&amp;assumestatesduringnotrunning=[% assumestatesduringnotrunning %]&amp;initialassumedhoststate=[% initialassumedhoststate %]&amp;backtrack=[% backtrack %]&amp;show_log_entries&amp;rpttimeperiod=[% rpttimeperiod %]'>View Availability Report For This Host</a><br>
            <a href='status.cgi?host=[% host | uri %]'>View Status Detail For This Host</a><br>
            <a href='history.cgi?host=[% host | uri %]'>View Alert History For This Host</a><br>
            <a href='notifications.cgi?host=[% host | uri %]'>View Notifications For This Host</a><br>
            [% END %]
          </td>
        </tr>
      </table>
    </td>
    <td align="center" valign="top" width="33%">
      <div align="center" class='dataTitle'>
        [% IF service %]
        Service '[% service %]' On Host '[% host %]'
        [% ELSE %]
        Host '[% host %]'
        [% END %]
      </div><br>
      <img src='[% url_prefix %]thruk/themes/[% theme %]/images/trends.gif' width="20" height="20" border="0" alt='[% IF service %]Service[% ELSE %]Host[% END %] State Trends' title='[% IF service %]Service[% ELSE %]Host[% END %] State Trends'><br clear="all">
      <div align="center" class='reportRange'>
        [% format_date(start, datetime_format) %] to [% format_date(end, datetime_format) %]
      </div>
      <div align="center" class='reportDuration'>
        Duration: [% SET dur = end - start %][% duration(dur) %]
      </div>
    </td>
    <td align="right" valign="bottom" width="33%">
      <form method="get" action="trends.cgi">
        <input type='hidden' name='t1' value='[% start %]'>
        <input type='hidden' name='t2' value='[% end %]'>
        <input type='hidden' name='host' value='[% host %]'>
        [% IF service %]<input type='hidden' name='service' value='[% service %]'>[% END %]
        <input type='hidden' name='assumeinitialstates' value='[% assumeinitialstates %]'>
        <input type='hidden' name='assumestateretention' value='[% assumestateretention %]'>
        <input type='hidden' name='assumestatesduringnotrunning' value='[% assumestatesduringnotrunning %]'>
        <input type='hidden' name='includesoftstates' value='[% includesoftstates %]'>
        <input type='hidden' name='rpttimeperiod' value='[% rpttimeperiod %]'>
        [% IF nomap %]<input type='hidden' name='nomap' value='[% nomap %]'>[% END %]
        <table border="0" class='optBox'>
          <tr>
            [% IF service %]
              <td class='optBoxItem' valign="top" align="left">First assumed service state:</td>
            [% ELSE %]
              <td class='optBoxItem' valign="top" align="left">First assumed host state:</td>
            [% END %]
            <td class='optBoxItem' valign="top" align="left">Backtracked archives:</td>
          </tr>
          <tr>
            <td class='optBoxItem' valign="top" align="left">
              [% IF service %]
              <input type='hidden' name='initialassumedhoststate' value='[% initialassumedhoststate %]'>
              <select name='initialassumedservicestate'>
                <option value="0"[% IF  initialassumedservicestate ==  0 %] selected[% END %]>Unspecified</option>
                <option value="-1"[% IF initialassumedservicestate == -1 %] selected[% END %]>Current State</option>
                <option value="6"[% IF  initialassumedservicestate ==  6 %] selected[% END %]>Service Ok</option>
                <option value="8"[% IF  initialassumedservicestate ==  8 %] selected[% END %]>Service Warning</option>
                <option value="7"[% IF  initialassumedservicestate ==  7 %] selected[% END %]>Service Unknown</option>
                <option value="9"[% IF  initialassumedservicestate ==  9 %] selected[% END %]>Service Critical</option>
              </select>
              [% ELSE %]
              <input type='hidden' name='initialassumedservicestate' value='[% initialassumedservicestate %]'>
              <select name='initialassumedhoststate'>
                <option value="0"[% IF  initialassumedhoststate ==  0 %] selected[% END %]>Unspecified</option>
                <option value="-1"[% IF initialassumedhoststate == -1 %] selected[% END %]>Current State</option>
                <option value="3"[% IF  initialassumedhoststate ==  3 %] selected[% END %]>Host Up</option>
                <option value="4"[% IF  initialassumedhoststate ==  4 %] selected[% END %]>Host Down</option>
                <option value="5"[% IF  initialassumedhoststate ==  5 %] selected[% END %]>Host Unreachable</option>
              </select>
              [% END %]
            </td>
            <td class='optBoxItem' valign="top" align="left">
              <input type='text' name='backtrack' size='2' maxlength='2' value='[% backtrack %]'>
            </td>
          </tr>
          <tr>
            <td class='optBoxItem' valign="top" align="left">Report period:</td>
            <td class='optBoxItem' valign="top" align="left">Zoom factor:</td>
          </tr>
          <tr>
            <td class='optBoxItem' valign="top" align="left">
              <select name='timeperiod'>
                <option value="current"[% IF      timeperiod == 'current'      %] selected[% END %]>[ Current time range ]</option>
                <option value="today"[% IF        timeperiod == 'today'        %] selected[% END %]>Today</option>
                <option value="last24hours"[% IF  timeperiod == 'last24hours'  %] selected[% END %]>Last 24 Hours</option>
                <option value="yesterday"[% IF    timeperiod == 'yesterday'    %] selected[% END %]>Yesterday</option>
                <option value="thisweek"[% IF     timeperiod == 'thisweek'     %] selected[% END %]>This Week</option>
                <option value="last7days"[% IF    timeperiod == 'last7days'    %] selected[% END %]>Last 7 Days</option>
                <option value="lastweek"[% IF     timeperiod == 'lastweek'     %] selected[% END %]>Last Week</option>
                <option value="thismonth"[% IF    timeperiod == 'thismonth'    %] selected[% END %]>This Month</option>
                <option value="last31days"[% IF   timeperiod == 'last31days'   %] selected[% END %]>Last 31 Days</option>
                <option value="lastmonth"[% IF    timeperiod == 'lastmonth'    %] selected[% END %]>Last Month</option>
                <option value="last12months"[% IF timeperiod == 'last12months' %] selected[% END %]>Last 12 Months</option>
                <option value="thisyear"[% IF     timeperiod == 'thisyear'     %] selected[% END %]>This Year</option>
                <option value="lastyear"[% IF     timeperiod == 'lastyear'     %] selected[% END %]>Last Year</option>
              </select>
            </td>
            <td class='optBoxItem' valign="top" align="left">
              <select name='zoom'>
                <option value="[% zoom %]" selected>[% zoom %]</option>
                <option value="+2">+2</option>
                <option value="+3">+3</option>
                <option value="+4">+4</option>
                <option value="-2">-2</option>
                <option value="-3">-3</option>
                <option value="-4">-4</option>
              </select>
            </td>
          </tr>
          <tr>
            <td class='optBoxItem' valign="top" align="left"></td>
            <td class='optBoxItem' valign="top" align="left">
              <input type='submit' value='Update'>
            </td>
          </tr>
          <tr>
            <td></td>
            <td align="right" valign="bottom"></td>
          </tr>
        </table>
      </form>
      [% PROCESS _help.tt topic = "trends" %]
    </td>
  </tr>
</table>
[% UNLESS nomap %]
<map name='trendsmap' id="trendsmap">

  [% SET x = 0 %]
  [% FOR a = image_map %]
  <area shape='rect' coords='[% a.x1 %],[% a.y1 %],[% a.x2 %],[% a.y2 %]' href='trends.cgi?t1=[% a.t1 %]&amp;t2=[% a.t2 %]&amp;host=[% host | uri %][% IF service %]&amp;service=[% service | uri %][% END %]&amp;assumeinitialstates=[% assumeinitialstates %]&amp;initialassumedhoststate=[% initialassumedhoststate %]&amp;initialassumedservicestate=[% initialassumedservicestate %]&amp;assumestateretention=[% assumestateretention %]&amp;assumestatesduringnotrunning=[% assumestatesduringnotrunning %]&amp;includesoftstates=[% includesoftstates %]&amp;backtrack=[% backtrack %]&amp;zoom=[% zoom %]&amp;rpttimeperiod=[% rpttimeperiod %]' onmouseover='showDetail([% x %])' onmouseout='hideDetail()'>

  [% SET x = x+1 %]
  [% END %]
</map>
[% END %]
<br><br>
<div align="center">
  <img src='trends.cgi?createimage&amp;host=[% host | uri %][% IF service %]&amp;service=[% service | uri %][% END %]&amp;t1=[% start %]&amp;t2=[% end %]&amp;assumeinitialstates=[% assumeinitialstates %]&amp;assumestatesduringnotrunning=[% assumestatesduringnotrunning %]&amp;initialassumedhoststate=[% initialassumedhoststate %]&amp;initialassumedservicestate=[% initialassumedservicestate %]&amp;assumestateretention=[% assumestateretention %]&amp;includesoftstates=[% includesoftstates %]&amp;backtrack=[% backtrack %]&amp;zoom=[% zoom %]&amp;rpttimeperiod=[% rpttimeperiod %][% IF ! c.config.no_external_job_forks %]&amp;job_id=[% job_id %][% END %]' border="0" name='trendsimage' usemap='#trendsmap' width="[% image_width %]" height="[% image_height %]" alt="#########" id="trendsimage">
</div>

[% PROCESS _footer.tt %]
