[%# 1.0@bugzilla.org %]
[%# The contents of this file are subject to the Mozilla Public
  # License Version 1.1 (the "License"); you may not use this file
  # except in compliance with the License. You may obtain a copy of
  # the License at http://www.mozilla.org/MPL/
  #
  # Software distributed under the License is distributed on an "AS
  # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  # implied. See the License for the specific language governing
  # rights and limitations under the License.
  #
  # The Original Code is the Bugzilla Bug Tracking System.
  #
  # The Initial Developer of the Original Code is Netscape Communications
  # Corporation. Portions created by Netscape are
  # Copyright (C) 1998 Netscape Communications Corporation. All
  # Rights Reserved.
  #
  # Contributor(s): Gervase Markham <gerv@gerv.net>
  #%]
  
[%# INTERFACE:
  # report.col_field: string. Name of the field being plotted as columns.
  # report.row_field: string. Name of the field being plotted as rows.
  # report.tbl_field: string. Name of the field being plotted as tables.
  # report.tbl_names: array. List of values for the field being plotted as tables.
  # time: integer. Seconds since the epoch.
  # report.data: <depends on format>. Data to plot. 
  # report.format: string. Format of the individual reports.
  # report.width: integer. For image charts, height of the image.
  # report.height: integer. For image charts, width of the image.
  # switchbase: string. Base URL for format switching.
  # cumulate: boolean. For bar/line charts, whether to cumulate data sets.
  #%]

[% DEFAULT width = 600
           height = 350 
%]

[% IF report.min_width AND report.width < report.min_width %]
  [% width = report.min_width %]
[% END %]

[%# We ignore report.row_field for pie charts %]
[% IF report.format == "pie" %]
  [% report.row_field = "" %]
[% END %]

[% PROCESS "global/field-descs.none.tmpl" %]

[% tbl_field_disp = field_descs.$report.tbl_field || report.tbl_field %]
[% col_field_disp = field_descs.$report.col_field || report.col_field %]
[% row_field_disp = field_descs.$report.row_field || report.row_field %]

[% title = BLOCK %]
  Report: 
  [% IF report.tbl_field %]
    [% tbl_field_disp FILTER html %]
  [% END %]
  [% " / " IF report.tbl_field AND (report.col_field OR report.row_field) %]
  [% IF report.row_field %]
    [% row_field_disp FILTER html %]
  [% END %]
  [% " / " IF report.col_field AND report.row_field %]
  [% col_field_disp FILTER html %]
[% END %]

[% IF debug %]
  <p>[% query FILTER html %]</p>
[% END %]

<div align="center">
<h1>[% qname FILTER html %]</h1>
  [% FOREACH tbl = report.tbl_names %]    
    [% IF tbl == "-total-" %]
      [% tbl_disp = "Total" %]
    [% ELSE %]
      [% tbl_disp = tbl %]
    [% END %]

    [% IF report.format == "table" %]
      [% PROCESS "testopia/reports/report-table.html.tmpl" %]
    [% ELSE %]
      [% IF tbl %]
        <h2>[% tbl_disp FILTER html %]</h2>
      [% END %]
      
      [% imageurl = BLOCK %][% report.report_loc %]?[% report.imagebase %]&amp;format=
        [% report.format FILTER url_quote %]&amp;ctype=png&amp;report_action=plot&amp;
        [% IF report.tbl_field %]
          [% IF tbl != "-total-" %]
            [% report.tbl_field FILTER url_quote %]=[% tbl FILTER url_quote %]&amp;
          [% ELSE %]
            [% FOREACH tblname = report.tbl_names %]
              [% IF tblname != "-total-" %]
                [% report.tbl_field FILTER url_quote %]=[% tblname FILTER url_quote %]&amp;
              [% END %]
            [% END %]
          [% END %]
        [% END %]width=[% width %]&amp;height=[% height %]      
      [% END %]
      
      <img alt="Graphical report results" src="[% imageurl %]"
        width="[% width %]" height="[% height %]">
    [% END %]
    <br>
  [% END %]  

  <table>
    <tr>
      <td>
        [% formaturl = "$report.report_loc?$report.switchbase&width=$width&height=$height" _ 
                       "&report_action=data" %]
        <a href="[% formaturl %]&amp;ctype=csv&amp;format=table">Export as CSV</a> 
      </td>
    <tr>
  </table>
</div>
