[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.40, Thu Mar 24 03:15:06 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::URL;  use URI::URL;
9  use HTTP::Request::Common;  use HTTP::Request::Common;
10    use POSIX;
11    
12  sub show_page {  sub new
13      my($cgi,$html,$no_home) = @_;  {
14      my $i;      my($class) = @_;
15    
16      #      my $self = {};
     # Find the HTML header  
     #  
17    
18        return bless $self, $class;
19    }
20    
21    sub compute_html_header
22    {
23        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
24        my($additional_insert,$user) = @_;
25      my $html_hdr_file = "./Html/html.hdr";      my $html_hdr_file = "./Html/html.hdr";
26      if (! -f $html_hdr_file)      if (! -f $html_hdr_file)
27      {      {
28          $html_hdr_file = "$FIG_Config::fig/CGI/Html/html.hdr";          $html_hdr_file = "$FIG_Config::fig/CGI/Html/html.hdr";
29      }      }
30        my @html_hdr = &FIG::file_read($html_hdr_file);
31        push( @html_hdr, "<br><a href=\"index.cgi?user=$user\">FIG search</a>\n" );
32    
33        if (@html_hdr)
34        {
35            my $insert_stuff;
36            my @ver = &FIG::file_head("$FIG_Config::fig_disk/CURRENT_RELEASE", 1);
37            my $ver = $ver[0];
38            chomp $ver;
39            if ($ver =~ /^cvs\.(\d+)$/)
40            {
41                my $d = asctime(localtime($1));
42                chomp($d);
43                $ver .=  " ($d)";
44            }
45            my $host = &FIG::get_local_hostname();
46            $insert_stuff = "SEED version <b>$ver</b> on $host";
47            if ($additional_insert)
48            {
49                $insert_stuff .= "<br>" . $additional_insert;
50            }
51    
52            for $_ (@html_hdr)
53            {
54                s,(href|img\s+src)="/FIG/,\1="$FIG_Config::cgi_base,g;
55                if ($_ eq "<!-- HEADER_INSERT -->\n")
56                {
57                    $_ = $insert_stuff;
58                }
59            }
60        }
61    
62        return @html_hdr;
63    }
64    
65    sub show_page {
66        #warn "SHOWPAGE: cgi=", Dumper(@_);
67        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
68        my($cgi,$html,$no_home, $alt_header, $css, $javasrc) = @_;
69        my $i;
70    
71    
72        # ARGUMENTS:
73        #     $cgi is the CGI method
74        #     $html is an array with all the html in it. It is just joined by "\n" (and not <br> or <p>
75        #     $no_home eliminates ONLY the bottom FIG search link in a page
76        #     $alt_header is a reference to an array for an alternate header banner that you can replace the standard one with
77        #     $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
78        #               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
79        #               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
80        #     $javasrc is a reference to an array of URLs to javascripts to be included (e.g. "/FIG/Html/css/styleswitcher.js")
81        #
82        # Find the HTML header
83        #
84    
85      my $html_tail_file = "./Html/html.tail";      my $html_tail_file = "./Html/html.tail";
86      if (! -f $html_tail_file)      if (! -f $html_tail_file)
# Line 27  Line 88 
88          $html_tail_file = "$FIG_Config::fig/CGI/Html/html.tail";          $html_tail_file = "$FIG_Config::fig/CGI/Html/html.tail";
89      }      }
90    
91        my $user = $cgi->param('user') || "";
92        my @html_hdr;
93        if ($alt_header && ref($alt_header) eq "ARRAY")
94        {
95           @html_hdr = @$alt_header;
96        }
97        else
98        {
99            @html_hdr = compute_html_header(undef,$user);
100        }
101    
102    
103      print $cgi->header;      print $cgi->header;
104    
# Line 145  Line 217 
217      #      #
218      #  <BODY> goes after last head line      #  <BODY> goes after last head line
219      #      #
220        #  RAE:
221        #  Added the javascript for the buttons immediately after body.
222        #  Note if no buttons are added we still (at the moment) add the script,
223        #  but it only adds a little text (495 characters) to the html and noone will notice!
224    
225      if ( $body_line < 0 )      if ( $body_line < 0 )
226      {      {
227            my $js=&javascript;
228          $body_line = $last_head_line + 1;          $body_line = $last_head_line + 1;
229          splice( @$html, $body_line, 0, "<BODY>\n" );          splice( @$html, $body_line, 0, "<BODY>\n$js\n" );
230      }      }
231    
232      #      #
233      #  Seed page header (if it exists) goes after <BODY>      #  Seed page header (if it exists) goes after <BODY>
234      #      #
235    
236      if ( -f $html_hdr_file )      if (@html_hdr)
237      {      {
238          splice( @$html, $body_line + 1, 0, `cat $html_hdr_file` );          splice( @$html, $body_line + 1, 0, @html_hdr );
239      }      }
240    
241      #      #
# Line 171  Line 248 
248          splice( @$html, $body_line, 0, "</HEAD>\n" );          splice( @$html, $body_line, 0, "</HEAD>\n" );
249      }      }
250    
251        # RAE:
252        # Add css here
253        # Note that at the moment I define these two sheets here. I think this should
254        # be moved out, but I want to try it and see what happens.  css has the format:
255        #
256        # <link rel='stylesheet' title='default' href='/css/default.css' type='text/css'>
257    
258        # convert the default key to the right case. and eliminate dups
259        foreach my $k (keys %$css) {if (lc($k) eq "default") {$css->{'Default'}=$css->{$k}}}
260    
261        if (!$css || !$css->{'Default'})
262        {
263           $css->{'Default'}="/FIG/Html/css/default.css";
264        }
265        if (!$css->{"Sans Serif"})
266        {
267           $css->{'Sans Serif'}="/FIG/Html/css/sanserif.css";
268        }
269        my $csstext = "<link rel='stylesheet' title='default' href='".$css->{'Default'}."' type='text/css'>\n";
270        $csstext   .= "<link rel='alternate stylesheet' title='Sans Serif' href='".$css->{'Sans Serif'}."' type='text/css'>\n";
271    
272        foreach my $k (keys %$css)
273        {
274           next if (lc($k) eq "default" || lc($k) eq "sans serif");
275           $csstext .= "<link rel='alternate stylesheet' title='$k' href='".$css->{$k}."' type='text/css'>\n";
276        }
277    
278    
279        # RAE: also added support for external javascripts here.
280        # we are cluttering the HTML code with all the javascripts when they could easily be in external files
281        # this solution allows us to source other files
282    
283        # $javasrc must be a ref to an array with urls (absolute or relative) to the javascripts
284        if ($javasrc && ref($javasrc) eq "ARRAY") {
285         foreach my $script (@$javasrc) {
286          $csstext .= "<script src=\"$script\" type=\"text/javascript\"></script>\n";
287         }
288        }
289    
290    
291    
292        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.
293    
294      #      #
295      #  <BASE ...> goes before </HEAD>      #  <BASE ...> goes before </HEAD>
296      #      #
# Line 183  Line 303 
303          #  only, or every update?), I provide an alternative derivation          #  only, or every update?), I provide an alternative derivation
304          #  from $cgi_url. -- GJO          #  from $cgi_url. -- GJO
305          #          #
306            # BASE href needs to be absolute. RDO.
307          my $base_url = $FIG_Config::cgi_base;          #
308          if ( ! $base_url )                      # if cgi_base was not defined          #
309          {          $base_url = &FIG::cgi_url;
310              $base_url = $FIG_Config::cgi_url;   # get the full cgi url  #       my $base_url = $FIG_Config::cgi_base;
311              $base_url =~ s~^http://[^/]*~~;     # remove protocol and host  #       if ( ! $base_url )                      # if cgi_base was not defined
312              $base_url =~ m~/$~ || $base_url =~ s~$~/~; # check trailing slash  #       {
313          }  #           $base_url = $FIG_Config::cgi_url;   # get the full cgi url
314    #           $base_url =~ s~^http://[^/]*~~;     # remove protocol and host
315    #           $base_url =~ m~/$~ || $base_url =~ s~$~/~; # check trailing slash
316    #       }
317    
318          $base_line = $head_end_line;          $base_line = $head_end_line;
319          splice( @$html, $base_line, 0, "<BASE href=\"$base_url\">\n" );          splice( @$html, $base_line, 0, "<BASE href=\"$base_url/\">\n" );
320      }      }
321    
322      #      #
# Line 228  Line 351 
351      }      }
352    
353      #      #
354        # See if we have a site-specific tail (for disclaimers, etc).
355        #
356    
357        my $site_tail = "$FIG_Config::fig_disk/config/site_tail.html";
358        my $site_fh;
359        if (open($site_fh, "<$site_tail"))
360        {
361            push(@tail, <$site_fh>);
362            close($site_fh);
363        }
364    
365        #
366      #  Figure out where to insert The SEED tail.  Before </body>,      #  Figure out where to insert The SEED tail.  Before </body>,
367      #  or before </html>, or at end of page.      #  or before </html>, or at end of page.
368      #      #
# Line 255  Line 390 
390          splice( @$html, $i, 0, @tags );          splice( @$html, $i, 0, @tags );
391      }      }
392    
393        # RAE the chomp will return any new lines at the ends of elements in the array,
394        # and then we can join  with a "\n". This is because somethings put newlines in,
395        # and others don't. This should make nicer looking html
396        #
397        # chomp(@$html);
398        # print join "\n", @$html;
399        #
400        # Apparently the above still breaks things. This is the correct code:
401    
402      print @$html;      print @$html;
403  }  }
404    
405  sub make_table {  sub make_table {
406      my($col_hdrs,$tab,$title,$instr) = @_;      my($col_hdrs,$tab,$title, %options ) = @_;
407      my(@tab);      my(@tab);
408    
409      push( @tab, "\n<table border>\n",      my $border = defined $options{border} ? "border=\"$options{border}\"" : "border";
410        push( @tab, "\n<table $border>\n",
411                  "\t<caption><b>$title</b></caption>\n",                  "\t<caption><b>$title</b></caption>\n",
412                  "\t<tr>\n\t\t<th>"                  "\t<tr>\n\t\t"
413                . join( "</th>\n\t\t<th>", @$col_hdrs )                . join( "\n", map { &expand($_, "th") } @$col_hdrs )
414                . "</th>\n\t</tr>\n"                . "\n\t</tr>\n"
415          );          );
416      my($i,$nowrap);      my($i);
   
     for ($i=0; ($i < @$instr) && ($instr->[$i] !~ /nowrap/); $i++) {}  
     $nowrap = ($i == @$instr) ? "" : " nowrap";  
417    
418      my $row;      my $row;
419      foreach $row (@$tab)      foreach $row (@$tab)
420      {      {
421          push( @tab, "\t<tr>\n"          push( @tab, "\t<tr>\n"
422                    . join( "\n", map { &expand($_,$nowrap) } @$row )                    . join( "\n", map { &expand($_) } @$row )
423                    . "\n\t</tr>\n"                    . "\n\t</tr>\n"
424              );              );
425      }      }
# Line 286  Line 428 
428  }  }
429    
430  sub expand {  sub expand {
431      my($x,$nowrap) = @_;      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
432        my( $x, $tag ) = @_;
433    
434        $tag = "td" unless $tag;
435        my $endtag = $tag;
436    
437      if ($x =~ /^\@([^:]+)\:([^:]+)\:(.*)$/)      # RAE modified this so that you can pass in a reference to an array where
438        # the first element is the data to display and the second element is optional
439        # things like colspan and align. Note that in this case you need to include the td
440        # use something like ["some data to appear", "td colspan=4 bgcolor=gray"]
441    
442        if ( ref($x) eq "ARRAY" ) { ($x, $tag) = @$x; if ($tag =~ /td/) { $endtag = "td" } }
443    
444        if ( $x =~ /^\@([^:]+)\:(.*)$/ )
445      {      {
446          return "\t\t<td$nowrap $1=\"$2\">$3</td>";          return "\t\t<$tag $1>$2</$endtag>";
447      }      }
448      else      else
449      {      {
450          return "\t\t<td$nowrap>$x</td>";          return "\t\t<$tag>$x</$endtag>";
451      }      }
452  }  }
453    
454    sub set_ec_links {
455        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
456        my($cgi,$x) = @_;
457        my($before,$match,$after);
458    
459        if ($x =~ /^(.*)(EC \d+\.\d+\.\d+\.\d+)(.*)/s)
460        {
461            $before = $1;
462            $match = $2;
463            $after = $3;
464            return &set_ec_links($cgi,$before) . &HTML::ec_link($match) . &set_ec_links($cgi,$after);
465        }
466        return $x;
467    }
468    
469  sub ec_link {  sub ec_link {
470        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
471      my($role) = @_;      my($role) = @_;
472    
473      if ($role =~ /(\d+\.\d+\.\d+\.\d+)/)      if ($role =~ /(\d+\.\d+\.\d+\.\d+)/)
# Line 312  Line 481 
481  }  }
482    
483  sub role_link {  sub role_link {
484        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
485      my($cgi,$role) = @_;      my($cgi,$role) = @_;
486    
487      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 492 
492      return "<a href=$link>$role</a>";      return "<a href=$link>$role</a>";
493  }  }
494    
495    #
496    # Local means to eliminate the fig|org.peg from the
497    # text of the link.
498    #
499  sub fid_link {  sub fid_link {
500        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
501      my($cgi,$fid,$local,$just_url) = @_;      my($cgi,$fid,$local,$just_url) = @_;
502      my($n);      my($n);
503    
# Line 347  Line 522 
522          my $user = $cgi->param('user');          my $user = $cgi->param('user');
523          if (! $user) { $user = "" }          if (! $user) { $user = "" }
524          my $trans = $cgi->param('translate') ? "&translate=1" : "";          my $trans = $cgi->param('translate') ? "&translate=1" : "";
525          my $link = $cgi->url() . "?prot=$fid&user=$user$trans";          my $sprout = $cgi->param('SPROUT') ? "&SPROUT=1" : "";
526          $link =~ s/[a-z_A-Z]+\.cgi\?/protein.cgi?/;          my $link = &FIG::cgi_url . "/protein.cgi?prot=$fid&user=$user$trans$sprout";
527            $link =~ s/[a-z_A-Z0-9]+\.cgi\?/protein.cgi?/;
528            #
529            # Elimin the p2p part if we're in that subdir. Ugh.
530            #
531            $link =~ s,p2p/protein.cgi,protein.cgi,;
532    
533          if ($just_url)          if ($just_url)
534          {          {
535              return $link;              return $link;
# Line 362  Line 543 
543  }  }
544    
545  sub family_link {  sub family_link {
546        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
547      my($family,$user) = @_;      my($family,$user) = @_;
548    
549      return $family;      return $family;
# Line 370  Line 552 
552  use URI::Escape;  use URI::Escape;
553    
554  sub get_html {  sub get_html {
555        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
556      my( $url, $type, $kv_pairs) = @_;      my( $url, $type, $kv_pairs) = @_;
557      my( $encoded, $ua, $args, @args, $out, @output, $x );      my( $encoded, $ua, $args, @args, $out, @output, $x );
558    
559      $ua = new LWP::UserAgent;      $ua = new LWP::UserAgent;
560      $ua->timeout( 900 );      $ua->timeout( 900 );
   
561      if ($type =~/post/i)      if ($type =~/post/i)
562      {      {
563          $args = [];          $args = [];
# Line 435  Line 617 
617  }  }
618    
619  sub trim_output {  sub trim_output {
620        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
621      my($out) = @_;      my($out) = @_;
622      my $i;      my $i;
623    
# Line 472  Line 655 
655  }  }
656    
657  sub set_prot_links {  sub set_prot_links {
658        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
659      my($cgi,$x) = @_;      my($cgi,$x) = @_;
660      my($before,$match,$after);      my($before,$match,$after);
661    
662      if ($x =~ /^(.*)(fig\|\d+\.\d+\.peg\.\d+)(.*)$/)      if ($x =~ /^(.*)(fig\|\d+\.\d+\.peg\.\d+)(.*)/s)
663        {
664            $before = $1;
665            $match = $2;
666            $after = $3;
667            return &set_prot_links($cgi,$before) . &HTML::fid_link($cgi,$match) . &set_prot_links($cgi,$after);
668        }
669        elsif ($x =~ /^(.*)\b([NXYZA]P_[0-9\.]+)\b(.*)/s)
670        {
671            $before = $1;
672            $match = $2;
673            $after = $3;
674            return &set_prot_links($cgi,$before) . &HTML::refseq_link($cgi,$match) . &set_prot_links($cgi,$after);
675        }
676        elsif ($x =~ /^(.*)(gi\|\d+)(.*)/s)
677        {
678            $before = $1;
679            $match = $2;
680            $after = $3;
681            return &set_prot_links($cgi,$before) . &HTML::gi_link($cgi,$match) . &set_prot_links($cgi,$after);
682        }
683        elsif ($x =~  /^(.*)(uni\|[A-Z0-9]{6})(.*)/s)
684      {      {
685          $before = $1;          $before = $1;
686          $match = $2;          $match = $2;
687          $after = $3;          $after = $3;
688          return &set_prot_links($cgi,$before) . &HTML::fid_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);
689      }      }
690      elsif ($x =~ /^(.*)(gi\|\d+)(.*)$/)      elsif ($x =~ /^(.*)(sp\|[A-Z0-9]{6})(.*)/s)
691      {      {
692          $before = $1;          $before = $1;
693          $match = $2;          $match = $2;
694          $after = $3;          $after = $3;
695          return &set_prot_links($cgi,$before) . &HTML::gi_link($cgi,$match) . &set_prot_links($cgi,$after) . "\n";          return &set_prot_links($cgi,$before) . &HTML::sp_link($cgi,$match) . &set_prot_links($cgi,$after);
696      }      }
697      elsif ($x =~ /^(.*)(sp\|[A-Z0-9]{6})(.*)$/)      elsif ($x =~ /^(.*)(pirnr\|NF\d+)(.*)/s)
698      {      {
699          $before = $1;          $before = $1;
700          $match = $2;          $match = $2;
701          $after = $3;          $after = $3;
702          return &set_prot_links($cgi,$before) . &HTML::sp_link($cgi,$match) . &set_prot_links($cgi,$after) . "\n";          return &set_prot_links($cgi,$before) . &HTML::pir_link($cgi,$match) . &set_prot_links($cgi,$after);
703      }      }
704      elsif ($x =~ /^(.*)(pirnr\|NF\d+)(.*)$/)      elsif ($x =~ /^(.*)(kegg\|[a-z]{2,4}:[a-zA-Z_0-9]+)(.*)/s)
705      {      {
706          $before = $1;          $before = $1;
707          $match = $2;          $match = $2;
708          $after = $3;          $after = $3;
709          return &set_prot_links($cgi,$before) . &HTML::pir_link($cgi,$match) . &set_prot_links($cgi,$after) . "\n";          return &set_prot_links($cgi,$before) . &HTML::kegg_link($cgi,$match) . &set_prot_links($cgi,$after);
710      }      }
711      return $x;      return $x;
712  }  }
713    
714    sub refseq_link {
715        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
716        my($cgi,$id) = @_;
717    
718        if ($id =~ /^[NXYZA]P_/)
719        {
720            return "<a href=http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=protein&cmd=search&term=$id>$id</a>";
721        }
722    }
723    
724  sub gi_link {  sub gi_link {
725        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
726      my($cgi,$gi) = @_;      my($cgi,$gi) = @_;
727    
728      if ($gi =~ /^gi\|(\d+)$/)      if ($gi =~ /^gi\|(\d+)$/)
# Line 516  Line 732 
732      return $gi;      return $gi;
733  }  }
734    
735    sub uni_link {
736        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
737        my($cgi,$uni) = @_;
738    
739        if ($uni =~ /^uni\|(\S+)$/)
740        {
741            return "<a href=http://www.pir.uniprot.org/cgi-bin/upEntry?id=$1>$uni</a>";
742        }
743        return $uni;
744    }
745    
746  sub sp_link {  sub sp_link {
747        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
748      my($cgi,$sp) = @_;      my($cgi,$sp) = @_;
749    
750      if ($sp =~ /^sp\|(\S+)$/)      if ($sp =~ /^sp\|(\S+)$/)
# Line 527  Line 755 
755  }  }
756    
757  sub pir_link {  sub pir_link {
758        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
759      my($cgi,$pir) = @_;      my($cgi,$pir) = @_;
760    
761      if ($pir =~ /^pirnr\|(NF\d+)$/)      if ($pir =~ /^pirnr\|(NF\d+)$/)
# Line 536  Line 765 
765      return $pir;      return $pir;
766  }  }
767    
768    sub kegg_link {
769        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
770        my($cgi,$kegg) = @_;
771    
772        if ($kegg =~ /^kegg\|([^:]+):(\S+)$/)
773        {
774            return "<a href=http://www.genome.ad.jp/dbget-bin/www_bget?$1+$2>$kegg</a>";
775        }
776        return $kegg;
777    }
778    
779    sub set_map_links {
780        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
781        my($cgi,$x) = @_;
782        my($before,$match,$after);
783    
784        my $org = ($cgi->param('org') || $cgi->param('genome') || "");
785    
786        if ($x =~ /^(.*)(MAP\d+)(.*)/s)
787        {
788            $before = $1;
789            $match = $2;
790            $after = $3;
791            return &set_map_links($cgi,$before) . &map_link($cgi,$match,$org) . &set_map_links($cgi,$after);
792        }
793        return $x;
794    }
795    
796    sub map_link {
797        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
798        my($cgi,$map,$org) = @_;
799    
800        $user = $cgi->param('user');
801        $user = $user ? $user : "";
802        $org = $org ? $org : "";
803        my $url = "$FIG_Config::cgi_url/show_kegg_map.cgi?user=$user&map=$map&org=$org";
804        my $link = "<a href=\"$url\">$map</a>";
805        return $link;
806    }
807    
808    sub javascript {
809        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
810            #### MODIFIED BY RAE TO ADD JAVA SUPPORT FOR CHECK ALL/UNCHECK ALL
811            # This routine takes three arguments, $html, $form, and $button
812            # $html is the ref to the array with the html in it
813            # $form is the name of the form. This must be added whenever start_form is called
814            # by including a -name entry. This is only used for the javascript
815            # $button is the name of the button that should be checked/unchecked.
816            #
817            # At the moment this add's four buttons:
818            # Check all, check's all
819            # Check first half will check the first 50% of the entries
820            # Check second half will check the second 50% of the entries
821            # Uncheck all will remove the checks.
822    
823            # Note that the other change is I added a -name=>'fig_checked' to the start_form
824            # field. The name is needed for the java script.
825            #
826    
827              $java_script=<<EOF;
828      <SCRIPT LANGUAGE="JavaScript">
829      <!-- Begin
830      function checkAll(field)
831      {
832       for (i = 0; i < field.length; i++)
833       field[i].checked = true ;
834      }
835    
836      function checkFirst(field)
837      {
838       for (i = 0; i < field.length/2; i++)
839       field[i].checked = true;
840      }
841    
842      function checkSecond(field)
843      {
844       for (i=Math.round(field.length/2); i < field.length; i++)
845       field[i].checked = true ;
846      }
847    
848      function uncheckAll(field)
849      {
850       for (i = 0; i < field.length; i++)
851       field[i].checked = false ;
852      }
853      //  End -->
854      </script>
855    EOF
856            return $java_script;
857    }
858    
859    sub java_buttons {
860        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
861      ## ADDED BY RAE
862      # Provides code to include check all/first half/second half/none for javascrspt
863      # this takes two variables - the form name provided in start_form with the
864      # -name => field and the checkbox name
865      my ($form, $button)=@_;
866    
867      $java_script="<input type=\"button\" name=\"CheckAll\" value=\"Check All\"\nonClick=\"checkAll(document.$form.$button)\">\n";
868      $java_script.="<input type=\"button\" name=\"CheckFirst\" value=\"Check First Half\"\nonClick=\"checkFirst(document.$form.$button)\">\n";
869      $java_script.="<input type=\"button\" name=\"CheckSecond\" value=\"Check Second Half\"\nonClick=\"checkSecond(document.$form.$button)\">\n";
870      $java_script.="<input type=\"button\" name=\"UnCheckAll\" value=\"Uncheck All\"\nonClick=\"uncheckAll(document.$form.$button)\">\n";
871    
872      return $java_script;
873    }
874    
875    sub sub_link {
876        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
877        my($cgi,$sub) = @_;
878        my($sub_link);
879    
880        my $user = $cgi->param('user');
881        if ($user)
882        {
883            $sub_link = "<a href=./subsys.cgi?ssa_name=$sub&request=show_ssa&user=$user>$sub</a>";
884        }
885        else
886        {
887            $sub_link = $sub;
888        }
889        return $sub_link;
890    }
891    
892  1  1

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3