#!/usr/local/bin/perl #package and module declaration use DBI; use CGI; #use strict; require 'commonFuncs.pkg'; require 'IniReader.pkg'; sub MakeHeader(); sub MakeMenu(); sub BuildChart($); my($c,$chart,$db,%IniVars,$header,$menu,$message,$sql,$nytefNames); %IniVars = IniFile::ReadIni("Nytef.ini"); $c = new CGI; $db = DBI->connect("DBI:mysql:database=$IniVars{database}{db};host=$IniVars{database}{host}", $IniVars{database}{user}, $IniVars{database}{pass}); foreach $name ($c->param) {$in{$name} = $c->param($name);} #end foreach #make sure that the letter parameter is acceptable, defaulting to A for all letters that are out of bounds if(ord($in{Letter}) > 64 && ord($in{Letter}) < 91) {} elsif(ord($in{Letter}) > 97 && ord($in{Letter}) < 122) {$in{Letter} = chr(ord($in{Letter}) - 32);} else {$in{Letter} = 'A';} $menu = MakeMenu(); $nytefNames = MakeNytef(); $header = MakeHeader(); $chart = BuildChart($in{Letter}); if($in{Letter} lt 'N') { $chartlink = 'chartsa-m.pdf'; $chartlets = 'A-M'; } else { $chartlink = 'chartsn-z.pdf'; $chartlets = 'N-Z'; } print $c->header; print ReadTemplate("$IniVars{site}{tmpBase}/_compare.html"); sub ReadTemplate($) ######################################################################################### # Function: ReadTemplate # # # # Purpose: This function reads in an HTML template file and returns the HTML with the # # value of the variable put in where the variable name is # # # # Parameters: # # $file = the file to read # # @_ = the variables and values from the template in the order of varName value # # # # Returns: The html code from the template with the variables replaed by the value of # # the variable # # # ######################################################################################### { local(*FILE); # filehandle my($file); # file path my($HTML); # HTML data $file = $_[0] || die "Template : No template file specified\n"; open(FILE, "<$file") || die "Template : Couldn't open $file : $!\n"; while () {$HTML .= $_;} close(FILE); $HTML =~ s/(\$\w+)/{$1}/eeg; #replace standard variables $HTML =~ s/\%d_(\w+)/$IniVars{database}{$1}/g; #replace %d_ with database variables $HTML =~ s/\%s_(\w+)/$IniVars{site}{$1}/g; #replace %s_ with site variables $HTML =~ s/\%i_(\w+)/$in{$1}/g; #replace %i_ with in variables return $HTML; } #end ReadTemplate sub MakeMenu() { my($i,$retval); for($i=65;$i<91;$i++) { if($i == ord($in{Letter})) {$retval .= chr($i) . " | ";} else {$retval .= "" . chr($i) . " | ";} } $retval = substr($retval,0,(length($retval)-2)); return $retval; } sub MakeHeader() { my($common,$resin,$row2,$row3,$retval,$query); $row2 = " \n Common Name\n"; $row3 = " \n Common Resin Tradename\n"; $sql = "SELECT Common,Resin FROM tblTradeNames ORDER BY ID"; $query = $db->prepare($sql); $query->execute; while (($common,$resin) = $query->fetchrow_array) { if($common eq '') {$row2 .= "  \n";} else {$row2 .= " $common\n";} if($resin eq '') {$row3 .= "  \n";} else {$row3 .= " $resin\n";} } $query->finish; $row2 .= " \n"; $row3 .= " \n"; $retval = $row2. $row3; return $retval; } sub BuildChart($) { my($letter) = @_; my($chemical,$conc,$count,$form,$grade,$id,$sql,$query,$query2,$retval,$i); $i = 1; $sql = "SELECT ChemID,Name,Form,Conc FROM tblChemicals WHERE Name LIKE '$letter\%' ORDER BY Name"; $query = $db->prepare($sql); $query->execute; while(($id,$chemical,$form,$conc) = $query->fetchrow_array) { if($i%10 == 0) {$retval .= $nytefNames;} $retval .= " \n"; if ($chemical eq '') {$retval .= "  \n";} else {$retval .= " $chemical\n";} if ($form eq '') {$retval .= "  \n";} else {$retval .= " $form\n";} if ($conc eq '') {$retval .= "  \n";} else {$retval .= " $conc\n";} $sql = "SELECT Grade FROM tblChem2Trade WHERE ChemID = $id ORDER BY TradeID"; $query2 = $db->prepare($sql); $query2->execute; $count = 0; while(($grade) = $query2->fetchrow_array) { if ($grade eq '') {$grade = "\ ";} if($count%2) {$retval .= " $grade\n";} else {$retval .= " $grade\n";} $count ++; } $query2->finish; $retval .= " \n"; $i++; } $query->finish; return $retval; } sub MakeNytef() { my($Nytef,$sql,$row1,$retval,$query); $row1 = " \n Nytef Product Family Tradename\n"; $sql = "SELECT Nytef FROM tblTradeNames ORDER BY ID"; $query = $db->prepare($sql); $query->execute; while (($Nytef) = $query->fetchrow_array) { if($Nytef eq '') {$row1 .= "  \n";} else {$row1 .= " $Nytef\n";} } $query->finish; $row1 .= " \n"; return $row1; }