# # Copyright (c) 2003-2006 University of Chicago and Fellowship # for Interpretations of Genomes. All Rights Reserved. # # This file is part of the SEED Toolkit. # # The SEED Toolkit is free software. You can redistribute # it and/or modify it under the terms of the SEED Toolkit # Public License. # # You should have received a copy of the SEED Toolkit Public License # along with this program; if not write to the University of Chicago # at info@ci.uchicago.edu or the Fellowship for Interpretation of # Genomes at veronika@thefig.info or download a copy from # http://www.theseed.org/LICENSE.TXT. # use HtmlPageParser; use HTML; use strict; use CGI; use Tracer; use TemplateObject; use SFXlate; use FIG; my $cgi = new CGI; ETracing($cgi); my $ssa = $cgi->param('ssa'); my $diagram_id = $cgi->param("diagram"); my $fig = ($cgi->param('SPROUT') ? SFXlate->new() : FIG->new()); if (!$ssa) { &error("No subsystem name provided.\n"); } if (!$diagram_id) { &error("No diagram id provided.\n"); } my $sub = $fig->get_subsystem($ssa); $sub or &error("Subsystem $ssa not found.\n"); if ($cgi->param("image")) { Trace("Image parameter specified.") if T(2); show_image($sub, $diagram_id); exit; } Trace("Creating template.") if T(3); my $to = TemplateObject->new($cgi, php => 'SubsysDiagram'); my $name = $sub->get_name; $name =~ s/_/ /g; my($dname, $dlink, $img_link) = $sub->get_diagram($diagram_id); # # See if we have a html page. # my $diagram_html_file = $sub->get_diagram_html_file($diagram_id); my($map, $map_name, $usemap); if ($diagram_html_file) { # # Parse the HTML to extract the map and map name. # my $parser = HtmlPageParser->new(); $parser->parse_file($diagram_html_file); $map_name = $parser->{map_names}->[0]; $map = $parser->{map}->{$map_name}; } # # If we have an image map, put an onload handler onto the body tag. # my $onload; if ($map) { $onload = qq(onload="onBodyLoad()"); } if ($to->raw()) { $to->add(undef => "Subsystem Diagram"); } else { Trace("Load handler is \"$onload\".") if T(3); $to->add(onload => $onload); } if ($map) { my $js_url = "Html/css/coloring.js"; $to->append(results => qq()); $to->append(results => &get_coloring_js($map_name, "map_div")); } $to->titles({fig_object => $fig, table_style => 'plain', fig_disk => "$FIG_Config::fig_disk/"}); $to->append(results => $cgi->h1("$name: Diagram $dname")); if ($map) { my $style = "position:relative; left:0px; top:0px;"; $to->append(results => qq(
)); $to->append(results => $map); $usemap = qq(usemap="#$map_name"); } $to->append(results => qq()); if ($map) { $to->append(results => "
"); } $to->append(results => ""); print "CONTENT-TYPE: text/html\n\n"; print $to->finish(); exit; sub show_image { my($sub, $diagram_id) = @_; Trace("Opening diagram image.") if T(3); my($type, $fh) = $sub->open_diagram_image($diagram_id); Trace("Image type for $diagram_id is $type.") if T(3); $type or exit(0); binmode STDOUT; print $cgi->header($type); my $buf; while (read($fh, $buf, 4096)) { print $buf; } close($fh); exit(0); } sub error { my($err) = @_; my $html = []; push(@$html, $cgi->title("Error")); push(@$html, $cgi->h1("Page error")); push(@$html, $cgi->p($err)); &HTML::show_page($cgi, $html, 1); exit; } sub get_coloring_js { my($mapname, $divname) = @_; my $txt = <<'END'; END $txt =~ s/%map%/$mapname/gm; $txt =~ s/%div%/$divname/gm; $txt =~ s,%trans_png%,Html/diagram_overlay.png,gm; return $txt; }