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

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 Ace::Browser::GrameneSubs;
use GrameneSubs;
use CGI 2.42 qw/:standard :html3 escape *table *blockquote/;

use constant CLASS   => 'Reference';
#use constant EXAMPLE => 'Chen-D-1997-95';

# 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 (".a({-href=>"/perl/pub_search?acedb=$obj"},'View in Literature Database').')' : 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->Source) {
    print TR(
	   th({-class=>'datatitle'},'Source'),
	   td({-class=>'databody'},$obj->Source)
	   );
  }
  if ($obj->Volume) {
    print TR(
	   th({-class=>'datatitle'},'Volume'),
	   td({-class=>'databody'},$obj->Volume)
	   );
  }
  if ($obj->Pages) {
    print TR(
	   th({-class=>'datatitle'},'Pages'),
	   td({-class=>'databody'},$obj->Pages)
	   );
  }
  if ($obj->Year) {
    print TR(
	   th({-class=>'datatitle'},'Year'),
	   td({-class=>'databody'},$obj->Year)
	   );
  }
  if ($obj->Title) {
    print TR(
	   th({-class=>'datatitle'},'Title'),
	   td({-class=>'databody'},$obj->Title)
	   );
  }
  if ($obj->Author) {
    print TR(
	   th({-class=>'datatitle'},'Author'),
	   td({-class=>'databody'},ObjectLink($obj->Author))
	   );
  }
  if ($obj->Publisher) {
    print TR(
	   th({-class=>'datatitle'},'Publisher'),
	   td({-class=>'databody'},ObjectLink($obj->Publisher))
	   );
  }
  if ($obj->Keyword) {
    print TR(
	   th({-class=>'datatitle'},'Keyword'),
	   td({-class=>'databody'},ObjectLink($obj->Keyword))
	   );
  }
  print end_table;

  my $sum = $obj->Summary;
  if ( $sum ) {
    print br,br;
    if ( Toggle('sum','Summary on reference') ) {
      print $sum;
    }
  }

  my $abstr = $obj->Abstract;
  if ( $abstr ) {
    print br,br;
    if ( Toggle('abstr','View Abstract',undef,1) ) {
      print p($abstr);
    }
  }

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


