#!/usr/bin/perl
# -*- Mode: perl -*-
# file: homoeology

use lib '/usr/local/gramene/lib/perl/';
use strict;
use vars qw($DB);
use Ace 1.51;
use Ace::Browser::AceSubs qw(:DEFAULT Toggle);
use GrameneSubs;
use CGI 2.42 qw/:standard :html3 escape *table *blockquote/;

use constant CLASS   => 'Homoeology';
#use constant EXAMPLE => 'Centro-1';

# open the database
$DB = OpenDatabase() || AceError("Couldn't open database.");

my ($obj_name, $obj);
$obj_name = param('name');
$obj = get_obj($obj_name) if $obj_name;

PrintTop($obj,CLASS,$obj ? CLASS . ": $obj" : CLASS . " Search");
PrintWarning($obj_name,CLASS) if $obj_name && !$obj;
print_report($obj) if $obj;
PrintBottom();

sub get_obj {
  my $name = shift;
  my ($obj) = $DB->fetch(-class =>CLASS,
			 -name  => $name);
  return $obj;
}

sub print_report {
  my $obj = shift;

  print start_table({-border=>1});
  if ($obj->Map) {
    my $map = $obj->Map;
    my $left = $obj->Map(2)->get('Left',1);
    my $right = $obj->Map(2)->get('Right',1);
    print TR(
	   th({-class=>'datatitle'},'Rice Map'),
 	   td({-class=>'databody'},ObjectLink($obj->Map)," from $left to $right cM")
	   );
  }
  if ($obj->Contains) {
    print TR(
	   th({-class=>'datatitle'},'Positive Contains'),
 	   td({-class=>'databody'},map {ObjectLink($_)} $obj->Contains)
	   );
  }
  if ($obj->Homoeologous_segment) {
    print TR(
	   th({-class=>'datatitle'},'Homoeology Segment'),
 	   td({-class=>'databody'},ObjectLink($obj->Homoeologous_segment))
	   );
  }
  if ($obj->Colour) {
    print TR(
	   th({-class=>'datatitle'},'Colour'),
 	   td({-class=>'databody'},$obj->Colour)
	   );
  }
  if ($obj->Taxon) {
    print TR(
	   th({-class=>'datatitle'},'Taxa'),
 	   td({-class=>'databody'},map {ObjectLink($_)} $obj->Taxon)
	   );
  }
  if ($obj->Reference) {
    print TR(
	   th({-class=>'datatitle'},'Reference'),
 	   td({-class=>'databody'},map {ObjectLink($_)} $obj->Reference)
	   );
  }
  if ($obj->Remarks) {
    print TR(
	   td({-class=>'datatitle',-colspan=>2},$obj->Remarks)
	   );
  }
  print end_table;

  my $remark = $obj->Remarks;
  if ( $remark ) {
    print br,br;
    if ( Toggle('remark','Remarks on homoeology',undef,1) ) {
      print $remark;
    }  
  }

  my $info = $obj->Help->Info;
  if ( $info ) {
    print br,br;
    if ( Toggle('help','Help on homoeology',undef,1) ) {
      print pre($info->right);
    }
  }
}


