[Bio] / FigKernelPackages / HTML.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/HTML.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6, Sun Mar 21 02:20:55 2004 UTC revision 1.45, Tue Jun 28 23:02:07 2005 UTC
# Line 1  Line 1 
1  package HTML;  package HTML;
2    
3    use FIG;
4  use Carp;  use Carp;
5  use Data::Dumper;  use Data::Dumper;
6  use LWP::UserAgent;  use LWP::UserAgent;
7  use LWP::Simple;  use LWP::Simple;
8    use URI::Escape;  # uri_escape()
9  use URI::URL;  use URI::URL;
10  use HTTP::Request::Common;  use HTTP::Request::Common;
11    use POSIX;
12    
13    sub new
14    {
15        my($class) = @_;
16    
17        my $self = {};
18    
19        return bless $self, $class;
20    }
21    
22    sub compute_html_header
23    {
24        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
25        my($additional_insert, $user, %options ) = @_;
26    
27        my $header_name = $options{header_name} ? $options{header_name} : "html.hdr";
28        my $tail_name = $options{tail_name} ? $options{tail_name} : "html.tail";
29    
30        my $html_hdr_file = "./Html/$header_name";
31        if (! -f $html_hdr_file)
32        {
33            $html_hdr_file = "$FIG_Config::fig/CGI/Html/$header_name";
34        }
35        my @html_hdr = &FIG::file_read($html_hdr_file);
36    
37        $options{no_fig_search} or push( @html_hdr, "<br><a href=\"index.cgi?user=$user\">FIG search</a>\n" );
38    
39        if (@html_hdr)
40        {
41            my $insert_stuff;
42    
43            if (not $options{no_release_info})
44            {
45                my @ver = &FIG::file_head("$FIG_Config::fig_disk/CURRENT_RELEASE", 1);
46                my $ver = $ver[0];
47                chomp $ver;
48                if ($ver =~ /^cvs\.(\d+)$/)
49                {
50                    my $d = asctime(localtime($1));
51                    chomp($d);
52                    $ver .=  " ($d)";
53                }
54                my $host = &FIG::get_local_hostname();
55                $insert_stuff = "SEED version <b>$ver</b> on $host";
56            }
57    
58            if ($additional_insert)
59            {
60                $insert_stuff .= "<br>" . $additional_insert;
61            }
62    
63            for $_ (@html_hdr)
64            {
65                s,(href|img\s+src)="/FIG/,\1="$FIG_Config::cgi_base,g;
66                if ($_ eq "<!-- HEADER_INSERT -->\n")
67                {
68                    $_ = $insert_stuff;
69                }
70            }
71        }
72    
73        return @html_hdr;
74    }
75    
76  sub show_page {  sub show_page {
77      my($cgi,$html,$no_home) = @_;      #warn "SHOWPAGE: cgi=", Dumper(@_);
78        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
79        my($cgi,$html,$no_home, $alt_header, $css, $javasrc) = @_;
80      my $i;      my $i;
81    
82        # ARGUMENTS:
83        #     $cgi is the CGI method
84        #     $html is an array with all the html in it. It is just joined by "\n" (and not <br> or <p>
85        #     $no_home eliminates ONLY the bottom FIG search link in a page
86        #     $alt_header is a reference to an array for an alternate header banner that you can replace the standard one with
87        #     $css is a reference to a hash. The key is the name of the CSS sheet and the value is the URL of that sheet. Note the usual rules about relative css urls
88        #               the sheet named "Default" is considered to be the default style sheet, and if this is not set it points at $FIG_Config::HTML/css/default.css
89        #               the sheet named "Sans Serif" is considered to the the first alternate, and if this is not set it points at $FIG_Config::HTML/css/sanserif.css
90        #     $javasrc is a reference to an array of URLs to javascripts to be included (e.g. "/FIG/Html/css/styleswitcher.js")
91      #      #
92      # Find the HTML header      # Find the HTML header
93      #      #
94    
95      my $html_hdr_file = "./Html/html.hdr";      my $html_tail_file = "./Html/$tail_name";
96      if (! -f $html_hdr_file)      if (! -f $html_tail_file)
97      {      {
98          $html_hdr_file = "$FIG_Config::fig/CGI/Html/html.hdr";          $html_tail_file = "$FIG_Config::fig/CGI/Html/$tail_name";
99      }      }
100    
101      my $html_tail_file = "./Html/html.tail";      my $user = $cgi->param('user') || "";
102      if (! -f $html_tail_file)      my @html_hdr;
103        if ($alt_header && ref($alt_header) eq "ARRAY")
104        {
105           @html_hdr = @$alt_header;
106        }
107        else
108      {      {
109          $html_tail_file = "$FIG_Config::fig/CGI/Html/html.tail";          @html_hdr = compute_html_header(undef,$user);
110      }      }
111    
112    
# Line 145  Line 227 
227      #      #
228      #  <BODY> goes after last head line      #  <BODY> goes after last head line
229      #      #
230        #  RAE:
231        #  Added the javascript for the buttons immediately after body.
232        #  Note if no buttons are added we still (at the moment) add the script,
233        #  but it only adds a little text (495 characters) to the html and noone will notice!
234    
235      if ( $body_line < 0 )      if ( $body_line < 0 )
236      {      {
237            my $js=&javascript;
238          $body_line = $last_head_line + 1;          $body_line = $last_head_line + 1;
239          splice( @$html, $body_line, 0, "<BODY>\n" );          splice( @$html, $body_line, 0, "<BODY>\n$js\n" );
240      }      }
241    
242      #      #
243      #  Seed page header (if it exists) goes after <BODY>      #  Seed page header (if it exists) goes after <BODY>
244      #      #
245    
246      if ( -f $html_hdr_file )      if (@html_hdr)
247      {      {
248          splice( @$html, $body_line + 1, 0, `cat $html_hdr_file` );          splice( @$html, $body_line + 1, 0, @html_hdr );
249      }      }
250    
251      #      #
# Line 171  Line 258 
258          splice( @$html, $body_line, 0, "</HEAD>\n" );          splice( @$html, $body_line, 0, "</HEAD>\n" );
259      }      }
260    
261        # RAE:
262        # Add css here
263        # Note that at the moment I define these two sheets here. I think this should
264        # be moved out, but I want to try it and see what happens.  css has the format:
265        #
266        # <link rel='stylesheet' title='default' href='/css/default.css' type='text/css'>
267    
268        # convert the default key to the right case. and eliminate dups
269        foreach my $k (keys %$css) {if (lc($k) eq "default") {$css->{'Default'}=$css->{$k}}}
270    
271        if (!$css || !$css->{'Default'})
272        {
273           $css->{'Default'}="/FIG/Html/css/default.css";
274        }
275        if (!$css->{"Sans Serif"})
276        {
277           $css->{'Sans Serif'}="/FIG/Html/css/sanserif.css";
278        }
279        my $csstext = "<link rel='stylesheet' title='default' href='".$css->{'Default'}."' type='text/css'>\n";
280        $csstext   .= "<link rel='alternate stylesheet' title='Sans Serif' href='".$css->{'Sans Serif'}."' type='text/css'>\n";
281    
282        foreach my $k (keys %$css)
283        {
284           next if (lc($k) eq "default" || lc($k) eq "sans serif");
285           $csstext .= "<link rel='alternate stylesheet' title='$k' href='".$css->{$k}."' type='text/css'>\n";
286        }
287    
288    
289        # RAE: also added support for external javascripts here.
290        # we are cluttering the HTML code with all the javascripts when they could easily be in external files
291        # this solution allows us to source other files
292    
293        # $javasrc must be a ref to an array with urls (absolute or relative) to the javascripts
294        if ($javasrc && ref($javasrc) eq "ARRAY") {
295         foreach my $script (@$javasrc) {
296          $csstext .= "<script src=\"$script\" type=\"text/javascript\"></script>\n";
297         }
298        }
299    
300    
301    
302        splice( @$html, $head_end_line, 1, "$csstext</HEAD>\n" );  # note here I am replacing the </head> line. Could be bad...? But it doesn't increment everything else.
303    
304      #      #
305      #  <BASE ...> goes before </HEAD>      #  <BASE ...> goes before </HEAD>
306      #      #
# Line 183  Line 313 
313          #  only, or every update?), I provide an alternative derivation          #  only, or every update?), I provide an alternative derivation
314          #  from $cgi_url. -- GJO          #  from $cgi_url. -- GJO
315          #          #
316            # BASE href needs to be absolute. RDO.
317          my $base_url = $FIG_Config::cgi_base;          #
318          if ( ! $base_url )                      # if cgi_base was not defined          #
319          {          $base_url = &FIG::cgi_url;
320              $base_url = $FIG_Config::cgi_url;   # get the full cgi url  #       my $base_url = $FIG_Config::cgi_base;
321              $base_url =~ s~^http://[^/]*~~;     # remove protocol and host  #       if ( ! $base_url )                      # if cgi_base was not defined
322              $base_url =~ m~/$~ || $base_url =~ s~$~/~; # check trailing slash  #       {
323          }  #           $base_url = $FIG_Config::cgi_url;   # get the full cgi url
324    #           $base_url =~ s~^http://[^/]*~~;     # remove protocol and host
325    #           $base_url =~ m~/$~ || $base_url =~ s~$~/~; # check trailing slash
326    #       }
327    
328          $base_line = $head_end_line;          $base_line = $head_end_line;
329          splice( @$html, $base_line, 0, "<BASE href=\"$base_url\">\n" );          splice( @$html, $base_line, 0, "<BASE href=\"$base_url/\">\n" );
330      }      }
331    
332      #      #
# Line 228  Line 361 
361      }      }
362    
363      #      #
364        # See if we have a site-specific tail (for disclaimers, etc).
365        #
366    
367        my $site_tail = "$FIG_Config::fig_disk/config/site_tail.html";
368        my $site_fh;
369        if (open($site_fh, "<$site_tail"))
370        {
371            push(@tail, <$site_fh>);
372            close($site_fh);
373        }
374    
375        #
376      #  Figure out where to insert The SEED tail.  Before </body>,      #  Figure out where to insert The SEED tail.  Before </body>,
377      #  or before </html>, or at end of page.      #  or before </html>, or at end of page.
378      #      #
# Line 255  Line 400 
400          splice( @$html, $i, 0, @tags );          splice( @$html, $i, 0, @tags );
401      }      }
402    
403      print @$html;      # RAE the chomp will return any new lines at the ends of elements in the array,
404        # and then we can join  with a "\n". This is because somethings put newlines in,
405        # and others don't. This should make nicer looking html
406        #
407        # chomp(@$html);
408        # print join "\n", @$html;
409        #
410        # Apparently the above still breaks things. This is the correct code:
411    
412        foreach $_ (@$html)
413        {
414            print $_;
415        }
416  }  }
417    
418  sub make_table {  sub make_table {
419      my($col_hdrs,$tab,$title,$instr) = @_;      my($col_hdrs,$tab,$title, %options ) = @_;
420      my(@tab);      my(@tab);
421    
422      push( @tab, "\n<table border>\n",      my $border = defined $options{border} ? "border=\"$options{border}\"" : "border";
423        push( @tab, "\n<table $border>\n",
424                  "\t<caption><b>$title</b></caption>\n",                  "\t<caption><b>$title</b></caption>\n",
425                  "\t<tr>\n\t\t<th>"                  "\t<tr>\n\t\t"
426                . join( "</th>\n\t\t<th>", @$col_hdrs )                . join( "\n", map { &expand($_, "th") } @$col_hdrs )
427                . "</th>\n\t</tr>\n"                . "\n\t</tr>\n"
428          );          );
429      my($i,$nowrap);      my($i);
   
     for ($i=0; ($i < @$instr) && ($instr->[$i] !~ /nowrap/); $i++) {}  
     $nowrap = ($i == @$instr) ? "" : " nowrap";  
430    
431      my $row;      my $row;
432      foreach $row (@$tab)      foreach $row (@$tab)
433      {      {
434          push( @tab, "\t<tr>\n"          push( @tab, "\t<tr>\n"
435                    . join( "\n", map { &expand($_,$nowrap) } @$row )                    . join( "\n", map { &expand($_) } @$row )
436                    . "\n\t</tr>\n"                    . "\n\t</tr>\n"
437              );              );
438      }      }
# Line 286  Line 441 
441  }  }
442    
443  sub expand {  sub expand {
444      my($x,$nowrap) = @_;      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
445        my( $x, $tag ) = @_;
446    
447        $tag = "td" unless $tag;
448        my $endtag = $tag;
449    
450        # RAE modified this so that you can pass in a reference to an array where
451        # the first element is the data to display and the second element is optional
452        # things like colspan and align. Note that in this case you need to include the td
453        # use something like ["some data to appear", "td colspan=4 bgcolor=gray"]
454    
455      if ($x =~ /^\@([^:]+)\:([^:]+)\:(.*)$/)      if ( ref($x) eq "ARRAY" ) { ($x, $tag) = @$x; if ($tag =~ /td/) { $endtag = "td" } }
456    
457        if ( $x =~ /^\@([^:]+)\:(.*)$/ )
458      {      {
459          return "\t\t<td$nowrap $1=\"$2\">$3</td>";          return "\t\t<$tag $1>$2</$endtag>";
460      }      }
461      else      else
462      {      {
463          return "\t\t<td$nowrap>$x</td>";          return "\t\t<$tag>$x</$endtag>";
464        }
465    }
466    
467    sub set_ec_links {
468        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
469        my($cgi,$x) = @_;
470        my($before,$match,$after);
471    
472        if ($x =~ /^(.*)(EC \d+\.\d+\.\d+\.\d+)(.*)/s)
473        {
474            $before = $1;
475            $match = $2;
476            $after = $3;
477            return &set_ec_links($cgi,$before) . &HTML::ec_link($match) . &set_ec_links($cgi,$after);
478      }      }
479        return $x;
480  }  }
481    
482  sub ec_link {  sub ec_link {
483        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
484      my($role) = @_;      my($role) = @_;
485    
486      if ($role =~ /(\d+\.\d+\.\d+\.\d+)/)      if ($role =~ /(\d+\.\d+\.\d+\.\d+)/)
# Line 312  Line 494 
494  }  }
495    
496  sub role_link {  sub role_link {
497        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
498      my($cgi,$role) = @_;      my($cgi,$role) = @_;
499    
500      my $roleR = ($role =~ /^(\d+\.\d+\.\d+\.\d+)\s+-\s+/) ? $1 : $role;      my $roleR = ($role =~ /^(\d+\.\d+\.\d+\.\d+)\s+-\s+/) ? $1 : $role;
# Line 322  Line 505 
505      return "<a href=$link>$role</a>";      return "<a href=$link>$role</a>";
506  }  }
507    
508    #
509    # Local means to eliminate the fig|org.peg from the
510    # text of the link.
511    #
512  sub fid_link {  sub fid_link {
513        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
514      my($cgi,$fid,$local,$just_url) = @_;      my($cgi,$fid,$local,$just_url) = @_;
515      my($n);      my($n);
516    
# Line 347  Line 535 
535          my $user = $cgi->param('user');          my $user = $cgi->param('user');
536          if (! $user) { $user = "" }          if (! $user) { $user = "" }
537          my $trans = $cgi->param('translate') ? "&translate=1" : "";          my $trans = $cgi->param('translate') ? "&translate=1" : "";
538          my $link = $cgi->url() . "?prot=$fid&user=$user$trans";          my $sprout = $cgi->param('SPROUT') ? "&SPROUT=1" : "";
539          $link =~ s/[a-z_A-Z]+\.cgi\?/protein.cgi?/;          my $link = &FIG::cgi_url . "/protein.cgi?prot=$fid&user=$user$trans$sprout";
540            $link =~ s/[a-z_A-Z0-9]+\.cgi\?/protein.cgi?/;
541            #
542            # Elimin the p2p part if we're in that subdir. Ugh.
543            #
544            $link =~ s,p2p/protein.cgi,protein.cgi,;
545    
546          if ($just_url)          if ($just_url)
547          {          {
548              return $link;              return $link;
# Line 362  Line 556 
556  }  }
557    
558  sub family_link {  sub family_link {
559        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
560      my($family,$user) = @_;      my($family,$user) = @_;
561    
562      return $family;      return $family;
563  }  }
564    
 use URI::Escape;  
565    
566  sub get_html {  sub get_html {
567        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
568      my( $url, $type, $kv_pairs) = @_;      my( $url, $type, $kv_pairs) = @_;
569      my( $encoded, $ua, $args, @args, $out, @output, $x );      my( $encoded, $ua, $args, @args, $out, @output, $x );
570    
571      $ua = new LWP::UserAgent;      $ua = new LWP::UserAgent;
572      $ua->timeout( 900 );      $ua->timeout( 900 );
   
573      if ($type =~/post/i)      if ($type =~/post/i)
574      {      {
575          $args = [];          $args = [];
# Line 435  Line 629 
629  }  }
630    
631  sub trim_output {  sub trim_output {
632        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
633      my($out) = @_;      my($out) = @_;
634      my $i;      my $i;
635    
# Line 472  Line 667 
667  }  }
668    
669  sub set_prot_links {  sub set_prot_links {
670        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
671      my($cgi,$x) = @_;      my($cgi,$x) = @_;
672      my($before,$match,$after);      my($before,$match,$after);
673    
674      if ($x =~ /^(.*)(fig\|\d+\.\d+\.peg\.\d+)(.*)$/)      if ($x =~ /^(.*)(fig\|\d+\.\d+\.peg\.\d+)(.*)/s)
675        {
676            $before = $1;
677            $match = $2;
678            $after = $3;
679            return &set_prot_links($cgi,$before) . &HTML::fid_link($cgi,$match) . &set_prot_links($cgi,$after);
680        }
681        elsif ($x =~ /^(.*)\b([NXYZA]P_[0-9\.]+)\b(.*)/s)
682      {      {
683          $before = $1;          $before = $1;
684          $match = $2;          $match = $2;
685          $after = $3;          $after = $3;
686          return &set_prot_links($cgi,$before) . &HTML::fid_link($cgi,$match) . &set_prot_links($cgi,$after) . "\n";          return &set_prot_links($cgi,$before) . &HTML::refseq_link($cgi,$match) . &set_prot_links($cgi,$after);
687      }      }
688      elsif ($x =~ /^(.*)(gi\|\d+)(.*)$/)      elsif ($x =~ /^(.*)(gi\|\d+)(.*)/s)
689      {      {
690          $before = $1;          $before = $1;
691          $match = $2;          $match = $2;
692          $after = $3;          $after = $3;
693          return &set_prot_links($cgi,$before) . &HTML::gi_link($cgi,$match) . &set_prot_links($cgi,$after) . "\n";          return &set_prot_links($cgi,$before) . &HTML::gi_link($cgi,$match) . &set_prot_links($cgi,$after);
694      }      }
695      elsif ($x =~ /^(.*)(sp\|[A-Z0-9]{6})(.*)$/)      elsif ($x =~ /^(.*)(tigr\|[0-9a-zA-Z]+)(.*)/s)
696      {      {
697          $before = $1;          $before = $1;
698          $match = $2;          $match = $2;
699          $after = $3;          $after = $3;
700          return &set_prot_links($cgi,$before) . &HTML::sp_link($cgi,$match) . &set_prot_links($cgi,$after) . "\n";          return &set_prot_links($cgi,$before) . &HTML::tigr_link($cgi,$match) . &set_prot_links($cgi,$after);
701      }      }
702      elsif ($x =~ /^(.*)(pirnr\|NF\d+)(.*)$/)      elsif ($x =~  /^(.*)(uni\|[A-Z0-9]{6})(.*)/s)
703      {      {
704          $before = $1;          $before = $1;
705          $match = $2;          $match = $2;
706          $after = $3;          $after = $3;
707          return &set_prot_links($cgi,$before) . &HTML::pir_link($cgi,$match) . &set_prot_links($cgi,$after) . "\n";          return &set_prot_links($cgi,$before) . &HTML::uni_link($cgi,$match) . &set_prot_links($cgi,$after);
708        }
709        elsif ($x =~ /^(.*)(sp\|[A-Z0-9]{6})(.*)/s)
710        {
711            $before = $1;
712            $match = $2;
713            $after = $3;
714            return &set_prot_links($cgi,$before) . &HTML::sp_link($cgi,$match) . &set_prot_links($cgi,$after);
715        }
716        elsif ($x =~ /^(.*)(pirnr\|NF\d+)(.*)/s)
717        {
718            $before = $1;
719            $match = $2;
720            $after = $3;
721            return &set_prot_links($cgi,$before) . &HTML::pir_link($cgi,$match) . &set_prot_links($cgi,$after);
722        }
723        elsif ($x =~ /^(.*)(kegg\|[a-z]{2,4}:[a-zA-Z_0-9]+)(.*)/s)
724        {
725            $before = $1;
726            $match = $2;
727            $after = $3;
728            return &set_prot_links($cgi,$before) . &HTML::kegg_link($cgi,$match) . &set_prot_links($cgi,$after);
729      }      }
730      return $x;      return $x;
731  }  }
732    
733    sub refseq_link {
734        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
735        my($cgi,$id) = @_;
736    
737        if ($id =~ /^[NXYZA]P_/)
738        {
739            return "<a href=http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=protein&cmd=search&term=$id>$id</a>";
740        }
741    }
742    
743  sub gi_link {  sub gi_link {
744        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
745      my($cgi,$gi) = @_;      my($cgi,$gi) = @_;
746    
747      if ($gi =~ /^gi\|(\d+)$/)      if ($gi =~ /^gi\|(\d+)$/)
# Line 516  Line 751 
751      return $gi;      return $gi;
752  }  }
753    
754    sub tigr_link {
755        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
756        my($cgi,$tigr) = @_;
757    
758        if ($tigr =~ /^tigr\|([0-9a-zA-Z]+)$/)
759        {
760            return "<a href=\"http://pathema.tigr.org/tigr-scripts/CMR/GenePage.cgi?locus=$1\">$tigr</a>";
761        }
762        return $tigr;
763    }
764    
765    sub uni_link {
766        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
767        my($cgi,$uni) = @_;
768    
769        if ($uni =~ /^uni\|(\S+)$/)
770        {
771            return "<a href=http://www.pir.uniprot.org/cgi-bin/upEntry?id=$1>$uni</a>";
772        }
773        return $uni;
774    }
775    
776  sub sp_link {  sub sp_link {
777        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
778      my($cgi,$sp) = @_;      my($cgi,$sp) = @_;
779    
780      if ($sp =~ /^sp\|(\S+)$/)      if ($sp =~ /^sp\|(\S+)$/)
# Line 527  Line 785 
785  }  }
786    
787  sub pir_link {  sub pir_link {
788        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
789      my($cgi,$pir) = @_;      my($cgi,$pir) = @_;
790    
791      if ($pir =~ /^pirnr\|(NF\d+)$/)      if ($pir =~ /^pirnr\|(NF\d+)$/)
# Line 536  Line 795 
795      return $pir;      return $pir;
796  }  }
797    
798    sub kegg_link {
799        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
800        my($cgi,$kegg) = @_;
801    
802        if ($kegg =~ /^kegg\|([^:]+):(\S+)$/)
803        {
804            return "<a href=http://www.genome.ad.jp/dbget-bin/www_bget?$1+$2>$kegg</a>";
805        }
806        return $kegg;
807    }
808    
809    sub set_map_links {
810        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
811        my($cgi,$x) = @_;
812        my($before,$match,$after);
813    
814        my $org = ($cgi->param('org') || $cgi->param('genome') || "");
815    
816        if ($x =~ /^(.*)(MAP\d+)(.*)/s)
817        {
818            $before = $1;
819            $match = $2;
820            $after = $3;
821            return &set_map_links($cgi,$before) . &map_link($cgi,$match,$org) . &set_map_links($cgi,$after);
822        }
823        return $x;
824    }
825    
826    sub map_link {
827        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
828        my($cgi,$map,$org) = @_;
829    
830        $user = $cgi->param('user');
831        $user = $user ? $user : "";
832        $org = $org ? $org : "";
833        my $url = "$FIG_Config::cgi_url/show_kegg_map.cgi?user=$user&map=$map&org=$org";
834        my $link = "<a href=\"$url\">$map</a>";
835        return $link;
836    }
837    
838    sub javascript {
839        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
840            #### MODIFIED BY RAE TO ADD JAVA SUPPORT FOR CHECK ALL/UNCHECK ALL
841            # This routine takes three arguments, $html, $form, and $button
842            # $html is the ref to the array with the html in it
843            # $form is the name of the form. This must be added whenever start_form is called
844            # by including a -name entry. This is only used for the javascript
845            # $button is the name of the button that should be checked/unchecked.
846            #
847            # At the moment this add's four buttons:
848            # Check all, check's all
849            # Check first half will check the first 50% of the entries
850            # Check second half will check the second 50% of the entries
851            # Uncheck all will remove the checks.
852    
853            # Note that the other change is I added a -name=>'fig_checked' to the start_form
854            # field. The name is needed for the java script.
855            #
856    
857              $java_script=<<EOF;
858      <SCRIPT LANGUAGE="JavaScript">
859      <!-- Begin
860      function checkAll(field)
861      {
862       for (i = 0; i < field.length; i++)
863       field[i].checked = true ;
864      }
865    
866      function checkFirst(field)
867      {
868       for (i = 0; i < field.length/2; i++)
869       field[i].checked = true;
870      }
871    
872      function checkSecond(field)
873      {
874       for (i=Math.round(field.length/2); i < field.length; i++)
875       field[i].checked = true ;
876      }
877    
878      function uncheckAll(field)
879      {
880       for (i = 0; i < field.length; i++)
881       field[i].checked = false ;
882      }
883      //  End -->
884      </script>
885    EOF
886            return $java_script;
887    }
888    
889    sub java_buttons {
890        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
891      ## ADDED BY RAE
892      # Provides code to include check all/first half/second half/none for javascrspt
893      # this takes two variables - the form name provided in start_form with the
894      # -name => field and the checkbox name
895      my ($form, $button)=@_;
896    
897      $java_script="<input type=\"button\" name=\"CheckAll\" value=\"Check All\"\nonClick=\"checkAll(document.$form.$button)\">\n";
898      $java_script.="<input type=\"button\" name=\"CheckFirst\" value=\"Check First Half\"\nonClick=\"checkFirst(document.$form.$button)\">\n";
899      $java_script.="<input type=\"button\" name=\"CheckSecond\" value=\"Check Second Half\"\nonClick=\"checkSecond(document.$form.$button)\">\n";
900      $java_script.="<input type=\"button\" name=\"UnCheckAll\" value=\"Uncheck All\"\nonClick=\"uncheckAll(document.$form.$button)\">\n";
901    
902      return $java_script;
903    }
904    
905    sub sub_link {
906        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
907        my($cgi,$sub) = @_;
908        my($sub_link);
909    
910        my $user = $cgi->param('user');
911        if ($user)
912        {
913            my $esc_sub = uri_escape( $sub );
914            $sub_link = "<a href=./subsys.cgi?ssa_name=$esc_sub&request=show_ssa&user=$user>$sub</a>";
915        }
916        else
917        {
918            $sub_link = $sub;
919        }
920        return $sub_link;
921    }
922    
923  1  1

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.45

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3