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

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

use constant CLASS   => 'Display';
use constant EXAMPLE => '1MW99';

# 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;
PrintPrompt(CLASS, EXAMPLE);
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;
  my $article = $obj->Map_study->Cited_in->Title 
    if defined $obj->Map_study->Cited_in;

  print hr,h2({-class=>'heading'},'Interesting Information');

  print start_table({-border=>1});

  PrintObj($obj);
  if ($obj->Title) {
    print TR(
	   th({-class=>'datatitle'},'Title'),
	   td({-class=>'databody'},$obj->Title)
	   );
  }
  if ($obj->Map_units) {
    print TR(
	   th({-class=>'datatitle'},'Map_units'),
	   td({-class=>'databody'},$obj->Map_units)
	   );
  }
  if ($obj->View) {
    print TR(
	   th({-class=>'datatitle'},'View'),
	   td({-class=>'databody'},ObjectLink($obj->View))
	   );
  }
  print end_table;

  my $remark = $obj->Remarks;
  if ( $remark ) {
    print br,br;
    if ( Toggle('remark','Remarks on display') ) {
      print $remark;
    }  
  }
  
  my $info = $obj->Help->Info if defined $obj->Help;
  if ( $info ) {
    print br,br;
    if ( Toggle('help','Help on display') ) {
      print pre($info->right);
    }
  }
}


