#!/usr/bin/perl -w # # Written by Hendra use CGI qw/:standard/; $bug = 0; $home = 'default.html'; $src = 'products.list'; $pdfdir = "/usr3/farchemical/pdfs"; print header; $body = &MakeBody("$src"); &makepage("$body"); sub MakeBody { my ($i) = @_; my ( $o, $t, %cat, %name, %cas, $ln, %sort, %found, $search, $k, ); my $pon = qq(); my $son = qq(); my $mon = qq(); my $won = qq(); my $emp = qq(); $search = param('search'); $search =~ s/^\s+//; $search =~ s/\s+$//; if (open (SRC, "$i")) { while () { chomp; s/\"//g; # ($cnum, $cnam, $casn) = split(/\t/); # $cat{"$ln"} = $cnum; # $name{"$ln"} = $cnam; # $cas{"$ln"} = $casn; $ln ++; $found{$ln} = 1 if /$search/ && $search; @q = split(/\t/); $cat{"$ln"} = $q[0]; $name{"$ln"} = $q[1]; $cas{"$ln"} = $q[2]; if ($s = param('sortf')) { $s--; $sort{$ln} = $q[$s]; } else { $sort{$ln} = $ln; } } close SRC; } else { $t = "Unsuccessful on opening $i"; } foreach $k (sort {$sort{$a} cmp $sort{$b} || $sort{$a} <=> $sort{$b}} keys %cat) { $pdfs = ''; $filea = "M-" . $cat{$k} . ".pdf"; $fileb = "S-" . $cat{$k} . ".pdf"; $filec = "P-" . $cat{$k} . ".pdf"; $filed = "W-" . $cat{$k} . ".pdf"; if (-e "$pdfdir/$filea") { $pdfs .= ""; } else { $pdfs .= ""; } if (-e "$pdfdir/$fileb") { $pdfs .= ""; } else { $pdfs .= ""; } if (-e "$pdfdir/$filec") { $pdfs .= ""; } else { $pdfs .= ""; } # if (-e "$pdfdir/$filed") { # $pdfs .= ""; # } else { # $pdfs .= ""; # } $pdfs .= "
$mon$emp$son$emp$pon$emp$won$emp  $cat{$k}
"; if ($search) { $t .= qq($pdfs$name{$k}$cas{$k}\n) if $found{$k}; } else { $t .= qq($pdfs$name{$k}$cas{$k}\n); } } $o = qq(
Many FAR Chemical, Inc. products are presented in the following table. Please call for current value pricing and availability or send us a request by email to info\@far-chemical.com. Should you not find your compound in our listing, contact us and we’ll see if we can make it for you!
PDF Legend:
$mon: MSDS
$son: Spec Sheet
$pon: Profile
); # '); $o .= qq($t
Catalog Number Chemical Name CAS Number
); $o; } sub makepage { my ($l, $t, $o) = @_; $o = ''; $out = "-- this page is empty --" unless $out; if (open (HTML, "$home")) { while () { s/\<\/head\>/$thisstyle\<\/head\>/i; if (s/\<\!--\#include\s+file=\"([^\"]+)\"\s*--\>//) { if ("$1" =~ /body.html/) { $o .= $l; $skip = 1; } elsif (open (INC, "$1")) { while ($t = ) { $o .= $t; } $skip = 1; } } elsif (s/\<\!--\#include\s+virtual=\"\/([^\"]+)\"\s*--\>//) { if (open (INC, "../$1")) { while ($t = ) { $o .= $t; } $skip = 1; } } $o .= "$_" unless $skip; $skip = 0; } $o =~ s/\<\!\-\-\s*TITLE OF PAGE\s*\-\-\>/

$top

/; print "$o"; } else { print qq(

$out ); } if ($bug) { print qq(


Bugs:
$rep
$header
$list
$footer
); } }