#!/usr/local/bin/perl #package and module declaration use DBI; use CGI; #use strict; require 'errorChecks.pkg'; 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}); foreach $name ($c->param) {$in{$name} = $c->param($name);} #end foreach $sql = "SELECT Common FROM tblTradeNames ORDER BY ID"; $query = $db->prepare($sql); $query->execute; while(($Nytef) = $query->fetchrow_array) {$prods .= " \n";} print $c->header; if($in{'Submit'} eq 'Submit') { $errString = EditChecks(); if($errString eq '') { $email = ReadTemplate("$IniVars{site}{tmpBase}/_email.txt"); CommonFuncs::SendEmail($in{email},$IniVars{special}{email},'Web Request',$email,0); $message = "Your email has been sent."; } #end if else {$errString = "$errString\n";} } #end if print ReadTemplate("$IniVars{site}{tmpBase}/_mailForm.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 EditChecks() ######################################################################################### # Function: EditChecks # # # # Purpose: This function checks the fields entered against criteria specified in the # # EditChecks table. It's basically a wrapper for the ErrorChecks package # # # # Parameters: # # $table = the table whose data is to be checked # # # # Returns: The list of error messages or a null string for success # # # ######################################################################################### { my($retval); unless(ErrorChecks::CheckLength($in{'firstname'},1,0)) {$retval .= "You must enter a first name.
\n";} unless(ErrorChecks::CheckLength($in{'lastname'},1,0)) {$retval .= "You must enter a last name.
\n";} unless(ErrorChecks::CheckLength($in{'coname'},1,0)) {$retval .= "You must enter a company name.
\n";} unless(ErrorChecks::CheckLength($in{'address'},1,0)) {$retval .= "You must enter a street adress.
\n";} unless(ErrorChecks::CheckLength($in{'city'},1,0)) {$retval .= "You must enter a city.
\n";} unless(ErrorChecks::CheckLength($in{'state'},1,0)) {$retval .= "You must enter a state.
\n";} unless(ErrorChecks::CheckLength($in{'zip'},1,0)) {$retval .= "You must enter a zip code.
\n";} unless(ErrorChecks::CheckLength($in{'country'},1,0)) {$retval .= "You must enter a country.
\n";} unless(ErrorChecks::CheckLength($in{'phone'},4,0)) {$retval .= "You must enter a phone number.
\n";} unless(ErrorChecks::CheckEmailAddress($in{'email'})) {$retval .= "You must enter an email address.
\n";} unless(ErrorChecks::CheckLength($in{'material'},1,0)) {$retval .= "You must enter a material.
\n";} return $retval }