package GUI::Thresholds;
#<copyright>
# ----------------------------------------------------------
# Sun Proprietary/Confidential Code
# Copyright 2001, Sun Microsystems, Inc. All rights reserved.
# ----------------------------------------------------------
#</copyright>

#  $Id: Thresholds.pm,v 1.11 2002/09/19 15:44:00 ccadieux Exp $

use Thresholds;

sub th {
  my($q) = @_;
  print "\n<body bgcolor=$main'BGCOLOR><center>";
  $h = Html->header2("report.general.thresholds" );
  my $L = Labels->read("GUI::Thresholds");

  $o =<<EOF;
<form  method=get>
 <input type=hidden name=GO value=th>
<center>
$h
<table border=2 cellspacing=2 width=90% bgcolor=white><tr><td>
<table border=0 cellspacing=2 width=100% bgcolor=#F0F0F0>
<tr><td colspan=6 bgcolor=#666699><b><font color=white>$L->{thresholds}</td>
<tr bgcolor=$main'LIGHT>
   <th>$L->{name}</th>
   <td colspan=2><b>&nbsp;$L->{freq}</td>
   <td><b>&nbsp;$L->{quiet}</td>
   <th>$L->{type}</th>
   <th>$L->{desc}</th>
EOF


  ($data, $th) = Thresholds->init();

  open(O, System->get_home() ."/System/SW_Thresholds");
  my $last;
  while ($l = <O>) {
    chop($l);
    next if ($l =~ /^ *$/ or substr($l,0,1) eq "#");
    next if (substr($l,0,1) eq "'");
    @a = split(/ *[\.\=\,] */, $l);
    $freq = $a[3];
    $repeat = $a[4];
    $type = ($a[5] eq "W")? "Warning":"Error";
    $unit = ($a[3] =~ /m$/) ? "ins":"ours";
    $unit2 = ($repeat =~ /m$/) ? "ins":"ours";
    if ($a[0] ne $last) {
       $last = $a[0];
       $o .= "<tr><td colspan=6 bgcolor=white><b>$last</td>";
    }
    $o .= "<tr>
         <td>$a[0].$a[1]</td>
         <td><center>$a[2]</td>
         <td>/ $a[3]$unit</td>
         <td>$repeat$unit2</td>
         <td><center>$type</td>
         <td>&nbsp;$a[6]</td>
         ";
    $p = $data->{$a[0]}{$a[1]};
    $xx = 0;
    foreach $k (keys %$p) {
      $v  = $p->{$k};
      $xx++;
      $d1 = Util->get_date($v->[0]*60);
      if ($v->[1] == 0) {
        $text = $L->expand(last => $d1);
      } else {
        $text = $L->expand(receiced => $v->[1], $d1);
      }
      $o .= "<tr><td bgcolor=white align=right><font color=navy><b>$k:</td>
              <td colspan=5 bgcolor=white><font color=navy>$text</td>";
    }
    $o .= "<tr><td></td>" if ($xx);
  }
  $o .= "</table></table>";
  print $o;
}

1;
