#!/usr/local/bin/perl #package and module declaration use DBI; use CGI; #use strict; require 'commonFuncs.pkg'; require 'IniReader.pkg'; %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}); print $c->header; my($id,$CheckBoxes,$Type,$colspan,$ProductTypes,$SubType,%TestTypes,%Tests,$numRequested); foreach $name ($c->param) {$in{$name} = $c->param($name);} #end foreach $sql = "SELECT ID FROM tblProd2 ORDER BY ID"; $query = $db->prepare($sql); $query->execute; while(($id) = $query->fetchrow_array) { if($in{$id} == $id) { $requestedProds .= ",$id"; } } $query->finish; if($requestedProds eq '') { $query = $db->prepare($sql); $query->execute; while(($id) = $query->fetchrow_array) { $requestedProds .= ",$id"; } $query->finish; } $requestedProds=substr($requestedProds,1); @temp = split(',',$requestedProds); $numRequested = $#temp; $numRequested++; $CheckBoxes = CreateBoxes(); $ProductTypes = CreateTypes(); $ProductSubTypes = CreateSubTypes(); %TestTypes = PopTestTypes(); $Descriptions = MakeDescriptionList(); %Tests = MakePropertiesDetail(); print ReadTemplate("$IniVars{site}{tmpBase}/_physical.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 $HTML =~ s/\%tt_(\w+)/$TestTypes{$1}/g; #replace %tt_ with TestType variables $HTML =~ s/\%t_(\w+)/$Tests{$1}/g; #replace %t_ with Tests variables return $HTML; } #end ReadTemplate sub CreateBoxes() { my($sql,$query,$reVal); $sql = "SELECT ID FROM tblProd2 ORDER BY ID"; $query = $db->prepare($sql); $query->execute; while(($id) = $query->fetchrow_array) { if($in{$id} eq $id) { $CheckBoxes .= ReadTemplate("$IniVars{site}{tmpBase}/_physical_checkboxes_box.htmlf"); } } $query->finish; if($CheckBoxes eq '') { $query = $db->prepare($sql); $query->execute; while(($id) = $query->fetchrow_array) { $CheckBoxes .= ReadTemplate("$IniVars{site}{tmpBase}/_physical_checkboxes_box.htmlf"); } $query->finish; } $retVal = ReadTemplate("$IniVars{site}{tmpBase}/_physical_checkboxes.htmlf"); return $retVal } sub CreateTypes() { my($sql,$query,$query2,$retVal); $sql = "SELECT ID,Type FROM tblProd2Types ORDER BY ID"; $query = $db->prepare($sql); $query->execute; while(($id,$Type) = $query->fetchrow_array) { $sql = "SELECT COUNT(ID) FROM tblProd2 WHERE ID in ($requestedProds) AND Type = $id"; $query2 = $db->prepare($sql); $query2->execute; ($colspan) = $query2->fetchrow_array; $query2->finish; if($colspan > 0) {$retVal .= ReadTemplate("$IniVars{site}{tmpBase}/_physical_types.html");} } $query->finish; return $retVal; } sub CreateSubTypes() { my($sql,$query,$query2,$retVal,$id2); $sql = "SELECT ID FROM tblProd2Types ORDER BY ID"; $query = $db->prepare($sql); $query->execute; while(($id,$Type) = $query->fetchrow_array) { $sql = "SELECT ID,Subtype FROM tblProd2SubTypes WHERE Type = $id ORDER BY ID"; $query2 = $db->prepare($sql); $query2->execute; while(($id2,$Type) = $query2->fetchrow_array) { $sql = "SELECT COUNT(ID) FROM tblProd2 WHERE Subtype = $id2 AND ID IN($requestedProds)"; $query3 = $db->prepare($sql); $query3->execute; ($colspan) = $query3->fetchrow_array; $query3->finish; if($colspan > 0) {$retVal .= ReadTemplate("$IniVars{site}{tmpBase}/_physical_types.html");} } $query2->finish; } $query->finish; return $retVal; } sub PopTestTypes() { my($sql,$query,$query2,%retVal,$id2,@tests,@testNames,$list); $sql = "SELECT ID FROM tblProd2Types ORDER BY ID"; $query = $db->prepare($sql); $query->execute; @tests = ('Mechanical','Thermal','Electrical','Miscellaneous','AgencyApprovals'); @testNames = ('Mechanical','Thermal','Electrical','Miscellaneous','Agency Approvals'); while(($id,$Type) = $query->fetchrow_array) { $sql = "SELECT ID,Subtype FROM tblProd2SubTypes WHERE Type = $id ORDER BY ID"; $query2 = $db->prepare($sql); $query2->execute; while(($id2,$Type) = $query2->fetchrow_array) { $sql = "SELECT Product FROM tblProd2 WHERE Subtype = $id2 AND ID IN($requestedProds) ORDER BY ID"; $query3 = $db->prepare($sql); $query3->execute; while(($Type) = $query3->fetchrow_array) { $list .= ReadTemplate("$IniVars{site}{tmpBase}/_physical_names_name.htmlf"); } $query3->finish; } $query2->finish; } $query->finish; for($i=0;$i<=$#tests;$i++) { $retVal{$tests[$i]} = "$testNames[$i]\n" . $list; } return %retVal; } sub MakeDescriptionList() { my($sql,$query,$query2,$retVal,$id2); $sql = "SELECT ID FROM tblProd2Types ORDER BY ID"; $query = $db->prepare($sql); $query->execute; $colspan=1; while(($id,$Type) = $query->fetchrow_array) { $sql = "SELECT ID,Subtype FROM tblProd2SubTypes WHERE Type = $id ORDER BY ID"; $query2 = $db->prepare($sql); $query2->execute; while(($id2,$Type) = $query2->fetchrow_array) { $sql = "SELECT Description FROM tblProd2 WHERE Subtype = $id2 AND ID IN($requestedProds) ORDER BY ID"; $query3 = $db->prepare($sql); $query3->execute; while(($Type) = $query3->fetchrow_array) { $retVal .= ReadTemplate("$IniVars{site}{tmpBase}/_physical_types.html"); } $query3->finish; } $query2->finish; } $query->finish; return $retVal; } sub MakePropertiesDetail() { my($sql,$query,%retVal,$i,$j,@rowNames,$temp,$id,$value,$lightcode,$darkcode,$font); $lightcode = "#CCCCCC"; $darkcode = "#EEEEEE"; $font = ""; @rowNames = (' ','SpecificGravity','TensilStrength','TensilElongation', 'TensilElasticity','FlexuralStrength','FlexuralElasticity', 'CompressiveStrength','IzodImpact','RockwellHardness', 'LinearThermal','UseTemp','HeatDeflection','MeltingPoint', 'SofteningTemperature','DielectricStrength','DielctricConstant', 'DielectricConstant2','DisipationFactor','VolumeRestivity', 'WaterAbsorbtion','WaterSaturation','Flamability','Friction', 'Color','FDA','NSF','ThreeA','USP'); $sql = "SELECT PropID, Value FROM tblProd2_2_Prop2 WHERE ProdID In ($requestedProds) ORDER BY PropID,ProdID"; $query = $db->prepare($sql); $query->execute; for($i=1;$i<=$#rowNames;$i++) { $temp = ""; for($j=0;$j<$numRequested;$j++) { ($id,$value) = $query->fetchrow_array; if($j%2 == 1) {$temp .= "$font $value\n";} else {$temp .= "$font $value\n";} } $retVal{$rowNames[$i]} = $temp; } return %retVal; }