Merge pull request #5248 from solgenomics/topic/batch_update_trials
[sgn.git] / cgi-bin / tools / networkbrowser / ajax_image_request.pl
blob737a142a8bda270389497ce01a7df085b71c3894
2 use strict;
3 use warnings;
4 use CatalystX::GlobalContext '$c';
6 use File::Temp;
7 use File::Spec;
8 use CXGN::Scrap::AjaxPage;
9 use CXGN::Sunshine::Browser;
10 use CXGN::Sunshine::Node;
11 use CXGN::Tools::WebImageCache;
12 use CatalystX::GlobalContext '$c';
14 my $ajax_page = CXGN::Scrap::AjaxPage->new("Sunshine", "Lukas");
16 my $dbh = $c->dbc->dbh;
18 my ($name, $type, $level, $force, $hide_relationships, $hilite) = $ajax_page->get_arguments("name", "type", "level", "force", "hide", "hilite");
20 my $temp_dir = File::Spec->catfile(
21 $c->config->{"tempfiles_subdir"},
22 "sunshine");
23 my $image_url = "";
25 my $b = CXGN::Sunshine::Browser->new($dbh);
27 if ($level) {
28 $b->set_level_depth($level);
31 my @hide_relationships = split /\s+/, $hide_relationships;
32 $b->set_hide_relationships(@hide_relationships);
33 $b->set_hilited_nodes($hilite);
34 $b->set_ref_node_name($name);
35 $b->set_ref_node_type($type);
36 $b->build_graph();
38 my $ref_node = $b->get_node("$name");
39 if (!$ref_node) {
40 print "Content-Type: text/xml\n\n<ajax><error>The node selected is not defined</error></ajax>";
41 exit();
44 if ($b->set_reference_node($ref_node)) {
45 #$page->message_page("The node ".$ref_node->get_name()." does not exist in the graph. Sorry!");
48 $b->layout();
51 my $mapname = "clickmap".time(); # create some unique string so that it reloads on Safari
52 my $cache = CXGN::Tools::WebImageCache->new();
53 $cache->set_key($name."-".$type."-".$level."-".(join ":", @hide_relationships));
54 $cache->set_expiration_time(86400); # seconds, this would be a day.
55 $cache->set_map_name($mapname); # what's in the <map name='map_name' tag.o
56 $cache->set_temp_dir($temp_dir);
57 $cache->set_basedir($c->config->{"basepath"});
58 $force = 1; # always force because the map name has to be unique (no caching is possible... unfortunately)
59 if (! $cache->is_valid() || $force) {
60 # generate the image and associated image map.
62 my $systime = time();
63 my $img_data = $b->render_string();
64 my $img_map_data = $b->get_image_map($mapname);
65 $cache->set_image_data($img_data);
66 $cache->set_image_map_data($img_map_data);
69 my $contents = "Content-Type: text/xml\n\n<ajax>".$cache->get_image_html()."</ajax>\n";
71 $ajax_page->header();
73 print $contents;
75 $ajax_page->footer();