#!/usr/bin/perl # use CGI; $query = new CGI; #Unique script ID: bac5-ec3 $stringpassed=$ENV{'QUERY_STRING'}; $stringpassed=~s/\+/ /g; $data="/home/sites/www.koegelmeats.com/recipeinfo/data.txt"; $tempdata="/home/sites/www.koegelmeats.com/recipeinfo/temp.txt"; $thisurl="http://www.koegelmeats.com/recipes/recipes.cgi"; $openinghtml="/home/sites/www.koegelmeats.com/web/recipes/template.shtml"; $adminpassword="hotdog"; $forwardingURL="http://www.koegelmeats.com/recipes"; $counterfile="/home/sites/www.koegelmeats.com/recipeinfo/counter.txt"; $timestampupdate="Yes"; $maximumpage=25; $maximum=250; $minimumcharacters=1; @variablenames = $query->param; foreach $variable (@variablenames){ $value=$query->param($variable); $tempapprove{$variable}="$value";} #STEP D================================ #You should not need to modify this section at all #D1. Check to see if opening html file is on server if (-e "$openinghtml"){ #D2. If so, open it and write opening and closing text to different strings #to be used throughout the script $problem="Can't open template file. Make sure you are referencing the file and not just a directory."; open(OPENING, "$openinghtml") || &security; @wholefile=; close(OPENING); $fulltemplate=join("\n",@wholefile); ($templatestart,$templateend)=split(/\+\+\+/,$fulltemplate);} else{ #D3. If template file not found, use this for now $templatestart="$templatetitle"; $templateend="";} $delimiter="\\|"; #D4. Get words entered by user $words=$query->param('words'); #D5. Checks to see if anything attached to URL if (length($stringpassed)>1){ ($words,$sf1)=split(/&&/,$stringpassed);} #D6. Get Password Entered by User $checkpassword=$query->param('checkpassword'); #D7. Figure out what action user wants to take. $actiontotake=$query->param('actiontotake'); $linenumberpass=$query->param('linenumberpass'); #D8. If user wants to delete record, and has already #verified password, then go to the makechange subroutine if ($actiontotake eq "Delete Record"){ $recordaction="Deleted"; &makechange; exit;} #D9. If user wants to edit record, and has already #verified password, then go to the makechange subroutine if ($actiontotake eq "Edit Record"){ $recordaction="Edited"; &makechange; exit;} #D10. If user wants to edit record, to go subroutine to verify if ($actiontotake eq "Edit"){ &edit; exit;} #D11. If user wants to delete record, to go subroutine to verify if ($actiontotake eq "Delete"){ &delete; exit;} #D12. If user wants to add record, go to add subroutine if ($actiontotake eq "Add"){ &addrecord; exit;} #D13. If user wants to add record to temporary file if ($actiontotake eq "Addtemp"){ &addtemp; exit;} #D14. If owner wants to evaluate records in temp file if ($actiontotake eq "Scrolltemp"){ &scrolltemp; exit;} #D15. If user wants to update temp file if ($actiontotake eq "Updatetemp"){ &updatetemp; exit;} #STEP E================================ #E2. Remove quotation marks from words entered by user $words=~s/\"//g; #E3. Remove word AND from search words since all #searches are and searches $words=~s/ and / /g; $words=~s/ AND / /g; #E4 Check to make sure that user has searched for the number of characters #you specified at C3. if (length($words)<$minimumcharacters && !$actiontotake){ $problem="Unable to execute your search. You need to search for at least 1 characters. Please press back on your browser to continue."; &security;} #E5. Get field user wants to search if (!$sf1){ $sf1=$query->param('sf1');} #E6. Get number of records already displayed $startitem=$query->param('startitem'); #E7. Figure the last record to display on this page $enditem=$startitem+$maximumpage; #STEP F================================ #Do not modify this section #F1. Get length of words entered by user $checklength=length($words); #F2. Checks to see if length is shorter than your minimum if ($checklength<$minimum && !$actiontotake){ $problem="You must enter at least $minimum characters. Please press BACK on your browser and fix this problem."; &security;} #F3. Lowercase search words to make matches easier $words2=$words; $words=lc($words); #F4. Split words entered by user into seven variables ($one1, $two2, $three3, $four4, $five5, $six6, $seven7)=split(/ /, $words); #STEP G================================ #Do not modify this section #G1. Open datafile and write contents to an array, if can't open report the problem at the security subroutine $problem="You do not have a file to search on my server. Please ADD test records before trying to search your test data file."; open (FILE, "$data") || &security; @all=; close (FILE); #G2. The line below is required, do not modify print "Content-type: text/html\n\n"; #G3. Display HTML Header print "$templatestart\n"; #G4. Show words user searched for #print "You Searched For: $words2

\n"; #STEP H================================ #H1. Read each line of the data file, compare with search words foreach $line (@all){ $line=~s/\n//g; $loopsaround++; $checkleng=length($line); if ($checkleng<2){next}; $linetemp1=lc($line); ($First_Name,$Last_Name,$City,$State,$Name_of_Recipe,$Ingredients,$Directions,$Unix_Timestamp,$Date_Time_Added,$Autoincrement,$Reserved1,$Reserved2,$Reserved3,$Reserved4,$Reserved5,$Reserved6,$Reserved7,$Reserved8,$Reserved9,$Reserved10,$skipthisfield)=split (/$delimiter/,$linetemp1); #H2. This section specifies the fields to sort results by #See help databases for patches to allow various kinds of sorts $line="$Name_of_Recipe$Date_Time_Added$delimiter$loopsaround$delimiter$line"; #H3. This line removes stray leading spaces before sorting your results $line=~s/^ +//; #H4. If the variable sf1 is deleted from search page, then #search all of the fields in the database if ($sf1 eq ""){ $wholestring=" $First_Name $Last_Name $City $State $Name_of_Recipe $Ingredients $Directions $Date_Time_Added $Autoincrement"; #H5. Pull out those marked to edit if ($line=~/markedtoedit/ && $actiontotake eq "markedtoedit"){ $line=~s/markedtoedit//g; push (@keepers2,$line);} $line=~s/markedtoedit//g; if ($wholestring =~/\b$one1/ && $wholestring =~/\b$two2/ && $wholestring =~/\b$three3/ && $wholestring =~/\b$four4/ && $wholestring =~/\b$five5/ && $wholestring=~/\b$six6/ && $wholestring =~/\b$seven7/){ push (@keepers,$line);}} #H7. If the variable sf1 is named First_Name, then do this search if ($sf1 eq "First_Name" && $First_Name =~/\b$one1/ && $First_Name =~/\b$two2/ && $First_Name =~/\b$three3/ && $First_Name =~/\b$four4/ && $First_Name =~/\b$five5/ && $First_Name =~/\b$six6/ && $First_Name =~/\b$seven7/){ push (@keepers,$line);} #H7. If the variable sf1 is named Last_Name, then do this search if ($sf1 eq "Last_Name" && $Last_Name =~/\b$one1/ && $Last_Name =~/\b$two2/ && $Last_Name =~/\b$three3/ && $Last_Name =~/\b$four4/ && $Last_Name =~/\b$five5/ && $Last_Name =~/\b$six6/ && $Last_Name =~/\b$seven7/){ push (@keepers,$line);} #H7. If the variable sf1 is named City, then do this search if ($sf1 eq "City" && $City =~/\b$one1/ && $City =~/\b$two2/ && $City =~/\b$three3/ && $City =~/\b$four4/ && $City =~/\b$five5/ && $City =~/\b$six6/ && $City =~/\b$seven7/){ push (@keepers,$line);} #H7. If the variable sf1 is named State, then do this search if ($sf1 eq "State" && $State =~/\b$one1/ && $State =~/\b$two2/ && $State =~/\b$three3/ && $State =~/\b$four4/ && $State =~/\b$five5/ && $State =~/\b$six6/ && $State =~/\b$seven7/){ push (@keepers,$line);} #H7. If the variable sf1 is named Name_of_Recipe, then do this search if ($sf1 eq "Name_of_Recipe" && $Name_of_Recipe =~/\b$one1/ && $Name_of_Recipe =~/\b$two2/ && $Name_of_Recipe =~/\b$three3/ && $Name_of_Recipe =~/\b$four4/ && $Name_of_Recipe =~/\b$five5/ && $Name_of_Recipe =~/\b$six6/ && $Name_of_Recipe =~/\b$seven7/){ push (@keepers,$line);} #H7. If the variable sf1 is named Ingredients, then do this search if ($sf1 eq "Ingredients" && $Ingredients =~/\b$one1/ && $Ingredients =~/\b$two2/ && $Ingredients =~/\b$three3/ && $Ingredients =~/\b$four4/ && $Ingredients =~/\b$five5/ && $Ingredients =~/\b$six6/ && $Ingredients =~/\b$seven7/){ push (@keepers,$line);} #H7. If the variable sf1 is named Directions, then do this search if ($sf1 eq "Directions" && $Directions =~/\b$one1/ && $Directions =~/\b$two2/ && $Directions =~/\b$three3/ && $Directions =~/\b$four4/ && $Directions =~/\b$five5/ && $Directions =~/\b$six6/ && $Directions =~/\b$seven7/){ push (@keepers,$line);} #H7. If the variable sf1 is named Date_Time_Added, then do this search if ($sf1 eq "Date_Time_Added" && $Date_Time_Added =~/\b$one1/ && $Date_Time_Added =~/\b$two2/ && $Date_Time_Added =~/\b$three3/ && $Date_Time_Added =~/\b$four4/ && $Date_Time_Added =~/\b$five5/ && $Date_Time_Added =~/\b$six6/ && $Date_Time_Added =~/\b$seven7/){ push (@keepers,$line);} #H7. If the variable sf1 is named Autoincrement, then do this search if ($sf1 eq "Autoincrement" && $Autoincrement =~/\b$one1/ && $Autoincrement =~/\b$two2/ && $Autoincrement =~/\b$three3/ && $Autoincrement =~/\b$four4/ && $Autoincrement =~/\b$five5/ && $Autoincrement =~/\b$six6/ && $Autoincrement =~/\b$seven7/){ push (@keepers,$line);} #H8. If the variable sf1 is named All Below, then do this if ($sf1 eq "All Fields"){ $wholestring= "$Autoincrement $Date_Time_Added $Directions $Ingredients $Name_of_Recipe $State $City $Last_Name $First_Name "; if ($wholestring =~/\b$one1/ && $wholestring =~/\b$two2/ && $wholestring =~/\b$three3/ && $wholestring =~/\b$four4/ && $wholestring =~/\b$five5/ && $wholestring=~/\b$six6/ && $wholestring =~/\b$seven7/){ push (@keepers,$line);}} } #STEP J================================ if ($actiontotake eq "markedtoedit"){ @keepers=@keepers2;} #J1. Sort matches stored in array. @keepers=sort(@keepers); #J2. Get and display number of matches found $length1=@keepers; #J3. If the number of matches is less than enditem, adjust if ($length1<$enditem){ $enditem=$length1; $displaystat="Y";} #J4. The first field about to display $disstart=$startitem+1; #J5. Show user total number of matches found #if ($length1){ #print "$length1 Matches Found (displaying $disstart to $enditem)

\n"; #} else { #print "Your search found zero records, please try again.

\n";} #STEP K================================ #K1. Do some HTML formatting before showing results #K3 Open table for results $totalmatches=@keepers; if ($totalmatches>0){ $darkcolor="#EEEEEE"; print "
Recipe: $Name_of_Recipe
From the Kitchen of: $First_Name $Last_Name
Ingredients: $Ingredients
Directions: $Directions

Many thanks to $First_Name of $City, $State, for submitting this recipe! \n";} #K4. Keep track of results processed on this page foreach $line (@keepers){ #K5. Delete stray hard returns $line=~s/\n//g; #K6. Keep track of records displayed $countline1++; #K7. Decide whether or not this record goes on this page if ($countline1>$startitem && $countline1<=$enditem){ #K8. Open each line of sorted array for displaying ($sortfield,$loopsaround,$First_Name,$Last_Name,$City,$State,$Name_of_Recipe,$Ingredients,$Directions,$Unix_Timestamp,$Date_Time_Added,$Autoincrement,$Reserved1,$Reserved2,$Reserved3,$Reserved4,$Reserved5,$Reserved6,$Reserved7,$Reserved8,$Reserved9,$Reserved10,$skipthisfield)=split (/$delimiter/,$line); #STEP L================================ #L1. If total displayed equals maximum you set, then exit if ($countline1 == $maximum && $maximum){ $problem2="Your search was terminated at $maximum records, please be more specific in your search"; last;} #L2. If script just got to last match then exit program if ($length1 == $countline1){ last;} #L3. If script is at the end of a page then show NEXT button if ($countline1 == $enditem && $displaystat ne "Y" && $maximum>$countline1){ $stopit="Y"; last; } }} #L4. Display NEXT MATCHES button if ($stopit eq "Y"){ print "

\n"; #L5. Pass hidden variables so script will know how to display next page print " \n"; print " \n"; print " \n"; print " \n"; print "
\n"; } #L6. Show problems print "

$problem2\n"; #L8. If opening.htm was found, show its closing html codes srand(); $checkval=int(rand(30)); if ($checkval==3){ print "\n";} print "$templateend\n"; exit; #STEP M================================ sub security{ #M1. This is the subroutine that reports all problems print "Content-type: text/html\n\n"; print "$templatestart\n"; print "

Data Error

\n"; print "Please correct the following error:

$problem
\n"; print "$templateend\n"; exit; } #STEP N================================ sub edit{ #N1. Open data file and read it $problem="Can't open data file to read from it at edit subroutine"; open (FILE,"$data") || &security; @all=; close (FILE); #N2. Read each line of the data file foreach $line (@all){ $line=~s/\n//g; ($copyFirst_Name,$copyLast_Name,$copyCity,$copyState,$copyName_of_Recipe,$copyIngredients,$copyDirections,$copyUnix_Timestamp,$copyDate_Time_Added,$copyAutoincrement,$copyReserved1,$copyReserved2,$copyReserved3,$copyReserved4,$copyReserved5,$copyReserved6,$copyReserved7,$copyReserved8,$copyReserved9,$copyReserved10,$skipthisfield)=split (/$delimiter/,$line); $keepcount++; #N3. Find the line user wants to modify if ($keepcount==$linenumberpass){ $linetokeep=$line; $linetokeep=~s/markedtoedit//g; last; } } #N4. Check password sent via hidden field if ($adminpassword ne $checkpassword){ $problem="Your password does not match the master password and appears to have been changed since logging onto this record."; &security;} #N6. Split matching line into its respective variables ($First_Name,$Last_Name,$City,$State,$Name_of_Recipe,$Ingredients,$Directions,$Unix_Timestamp,$Date_Time_Added,$Autoincrement,$Reserved1,$Reserved2,$Reserved3,$Reserved4,$Reserved5,$Reserved6,$Reserved7,$Reserved8,$Reserved9,$Reserved10,$skipthisfield)=split (/$delimiter/,$linetokeep); #Required Header, do not delete print "Content-type: text/html\n\n"; #N8. If can't find opening html, display default header print "$templatestart\n"; print "

Edit this Record

\n"; print "

\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; $Ingredients=~s/
/\n/g; $Ingredients=~s/
/\n/g; print "\n"; $Directions=~s/
/\n/g; $Directions=~s/
/\n/g; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; #N10. Pass values to next screen print "
First Name:
Last Name:
City:
State:
Name of Recipe:
Ingredients:
Directions:
Unix Timestamp:
Date Time Added:
Autoincrement:
Reserved1:
Reserved2:
Reserved3:
Reserved4:
Reserved5:
Reserved6:
Reserved7:
Reserved8:
Reserved9:
Reserved10:
\n"; print "\n"; print "\n"; print "

\n"; print "$templateend\n"; exit; } #STEP O================================ sub delete{ #O1. Open data file and read it $problem="Can't open data file to read from it at delete subroutine"; open (FILE,"$data") || &security; @all=; close (FILE); #O2. Read each line of the file foreach $line (@all){ $line=~s/\n//g; ($copyFirst_Name,$copyLast_Name,$copyCity,$copyState,$copyName_of_Recipe,$copyIngredients,$copyDirections,$copyUnix_Timestamp,$copyDate_Time_Added,$copyAutoincrement,$copyReserved1,$copyReserved2,$copyReserved3,$copyReserved4,$copyReserved5,$copyReserved6,$copyReserved7,$copyReserved8,$copyReserved9,$copyReserved10,$skipthisfield)=split (/$delimiter/,$line); $keepcount++; #O3. Find line to delete if ($keepcount==$linenumberpass){ $linetokeep=$line; $linetokeep=~s/markedtoedit//g; last; } } ($First_Name,$Last_Name,$City,$State,$Name_of_Recipe,$Ingredients,$Directions,$Unix_Timestamp,$Date_Time_Added,$Autoincrement,$Reserved1,$Reserved2,$Reserved3,$Reserved4,$Reserved5,$Reserved6,$Reserved7,$Reserved8,$Reserved9,$Reserved10,$skipthisfield)=split (/$delimiter/,$linetokeep); #O4. Check password sent via hidden field if ($adminpassword ne $checkpassword){ $problem="Your password does not match the master password."; &security;} #O6. Requred Header, do not delete print "Content-type: text/html\n\n"; print "$templatestart\n"; print "

Delete this Record?

\n"; ($First_Name,$Last_Name,$City,$State,$Name_of_Recipe,$Ingredients,$Directions,$Unix_Timestamp,$Date_Time_Added,$Autoincrement,$Reserved1,$Reserved2,$Reserved3,$Reserved4,$Reserved5,$Reserved6,$Reserved7,$Reserved8,$Reserved9,$Reserved10,$skipthisfield)=split (/$delimiter/,$linetokeep); #O7. Show validation HTML print "

\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
First_Name: $First_Name
Last_Name: $Last_Name
City: $City
State: $State
Name_of_Recipe: $Name_of_Recipe
Ingredients: $Ingredients
Directions: $Directions
Unix_Timestamp: $Unix_Timestamp
Date_Time_Added: $Date_Time_Added
Autoincrement: $Autoincrement
Reserved1: $Reserved1
Reserved2: $Reserved2
Reserved3: $Reserved3
Reserved4: $Reserved4
Reserved5: $Reserved5
Reserved6: $Reserved6
Reserved7: $Reserved7
Reserved8: $Reserved8
Reserved9: $Reserved9
Reserved10: $Reserved10

\n"; print "\n"; print "\n"; print "

\n"; #If opening.htm was not found, show default closing html codes print "$templateend\n"; exit; } #STEP P================================ sub makechange{ #P1. For each variable, translate it, remove any delimiters that #user may have accidentally included, replace hard returns with #HTML line breaks, and delete all carriage returns $delimiter="\|"; #Go to get variable subroutine and make sure add preferences apply if ($recordaction eq "Edited"){ &getvariables;} #P2. This step either replaces or empties the existing line if ($recordaction eq "Deleted"){ $replacementline="";} else{ $replacementline="$First_Name$delimiter$Last_Name$delimiter$City$delimiter$State$delimiter$Name_of_Recipe$delimiter$Ingredients$delimiter$Directions$delimiter$Unix_Timestamp$delimiter$Date_Time_Added$delimiter$Autoincrement$delimiter$Reserved1$delimiter$Reserved2$delimiter$Reserved3$delimiter$Reserved4$delimiter$Reserved5$delimiter$Reserved6$delimiter$Reserved7$delimiter$Reserved8$delimiter$Reserved9$delimiter$Reserved10";} $problem="Can't open data file to read from it"; open (FILE,"$data") || &security; @all=; close (FILE); $linenumberpass--; $all[$linenumberpass]=$replacementline; $problem="Can't open temporary file. You need to chmod 777 the directory your data file is in. See the help files under Permissions for Class B Scripts."; #P6. Write the entire changed file to a temporary file open (FILE2,">$data.tmp") || &security; foreach $line (@all){ $line=~s/\n//g; print FILE2 "$line\n";} close(FILE2); #P7. Rename the temp file to your master data file $problem="Can't rename file after making change"; rename("$data.tmp", "$data") || &security; print "Content-type: text/html\n\n"; #P8. If can't find opening html, display default header print "$templatestart\n"; print "Your record has been $recordaction. Please click here to continue.\n"; close (FILE); #If opening.htm was not found, show default closing html codes print "$templateend\n"; exit; } #STEP Q================================ #This subroutine adds records to your database sub addrecord{ $delimiter="\|"; #Q1. Check password if ($adminpassword ne $checkpassword && $adminpassword){ $problem="The password you entered does not match your administration password. Please press BACK on your browser to fix this problem."; &security;} &getvariables; $replacementline="$First_Name$delimiter$Last_Name$delimiter$City$delimiter$State$delimiter$Name_of_Recipe$delimiter$Ingredients$delimiter$Directions$delimiter$Unix_Timestamp$delimiter$Date_Time_Added$delimiter$Autoincrement$delimiter$Reserved1$delimiter$Reserved2$delimiter$Reserved3$delimiter$Reserved4$delimiter$Reserved5$delimiter$Reserved6$delimiter$Reserved7$delimiter$Reserved8$delimiter$Reserved9$delimiter$Reserved10"; #Q3. Write the new record to the bottom of the data file $problem="Can't write to the data file. Please verify its location and change its permissions to 777."; open (FILE2,">>$data") || &security; print FILE2 "$replacementline\n"; close(FILE2); print "Content-type: text/html\n\n"; #Q4. If can't find opening html, display default header print "$templatestart\n"; print "Your record has been added. Please click here to continue.\n"; #If opening.htm was not found, show default closing html codes print "$templateend\n"; exit; } #STEP R================================ sub getvariables{ #R1. This step checks your variables before adding/editing them $First_Name=$query->param('First_Name'); $Last_Name=$query->param('Last_Name'); $City=$query->param('City'); $State=$query->param('State'); $Name_of_Recipe=$query->param('Name_of_Recipe'); $Ingredients=$query->param('Ingredients'); $Directions=$query->param('Directions'); $Unix_Timestamp=$query->param('Unix_Timestamp'); $Date_Time_Added=$query->param('Date_Time_Added'); $Autoincrement=$query->param('Autoincrement'); $Reserved1=$query->param('Reserved1'); $Reserved2=$query->param('Reserved2'); $Reserved3=$query->param('Reserved3'); $Reserved4=$query->param('Reserved4'); $Reserved5=$query->param('Reserved5'); $Reserved6=$query->param('Reserved6'); $Reserved7=$query->param('Reserved7'); $Reserved8=$query->param('Reserved8'); $Reserved9=$query->param('Reserved9'); $Reserved10=$query->param('Reserved10'); #R3. Replace hard returns with
, cut carriage returns $First_Name=~s/\n/
/g; $First_Name=~s/\r//g; if ($First_Name eq "Select"){ $First_Name="";} #R3. Replace hard returns with
, cut carriage returns $Last_Name=~s/\n/
/g; $Last_Name=~s/\r//g; if ($Last_Name eq "Select"){ $Last_Name="";} #R3. Replace hard returns with
, cut carriage returns $City=~s/\n/
/g; $City=~s/\r//g; if ($City eq "Select"){ $City="";} #R3. Replace hard returns with
, cut carriage returns $State=~s/\n/
/g; $State=~s/\r//g; if ($State eq "Select"){ $State="";} #R3. Replace hard returns with
, cut carriage returns $Name_of_Recipe=~s/\n/
/g; $Name_of_Recipe=~s/\r//g; if ($Name_of_Recipe eq "Select"){ $Name_of_Recipe="";} #R3. Replace hard returns with
, cut carriage returns $Ingredients=~s/\n/
/g; $Ingredients=~s/\r//g; if ($Ingredients eq "Select"){ $Ingredients="";} #R3. Replace hard returns with
, cut carriage returns $Directions=~s/\n/
/g; $Directions=~s/\r//g; if ($Directions eq "Select"){ $Directions="";} #R3. Replace hard returns with
, cut carriage returns $Unix_Timestamp=~s/\n/
/g; $Unix_Timestamp=~s/\r//g; if ($Unix_Timestamp eq "Select"){ $Unix_Timestamp="";} #R3. Replace hard returns with
, cut carriage returns $Date_Time_Added=~s/\n/
/g; $Date_Time_Added=~s/\r//g; if ($Date_Time_Added eq "Select"){ $Date_Time_Added="";} #R3. Replace hard returns with
, cut carriage returns $Autoincrement=~s/\n/
/g; $Autoincrement=~s/\r//g; if ($Autoincrement eq "Select"){ $Autoincrement="";} #R3. Replace hard returns with
, cut carriage returns $Reserved1=~s/\n/
/g; $Reserved1=~s/\r//g; if ($Reserved1 eq "Select"){ $Reserved1="";} #R3. Replace hard returns with
, cut carriage returns $Reserved2=~s/\n/
/g; $Reserved2=~s/\r//g; if ($Reserved2 eq "Select"){ $Reserved2="";} #R3. Replace hard returns with
, cut carriage returns $Reserved3=~s/\n/
/g; $Reserved3=~s/\r//g; if ($Reserved3 eq "Select"){ $Reserved3="";} #R3. Replace hard returns with
, cut carriage returns $Reserved4=~s/\n/
/g; $Reserved4=~s/\r//g; if ($Reserved4 eq "Select"){ $Reserved4="";} #R3. Replace hard returns with
, cut carriage returns $Reserved5=~s/\n/
/g; $Reserved5=~s/\r//g; if ($Reserved5 eq "Select"){ $Reserved5="";} #R3. Replace hard returns with
, cut carriage returns $Reserved6=~s/\n/
/g; $Reserved6=~s/\r//g; if ($Reserved6 eq "Select"){ $Reserved6="";} #R3. Replace hard returns with
, cut carriage returns $Reserved7=~s/\n/
/g; $Reserved7=~s/\r//g; if ($Reserved7 eq "Select"){ $Reserved7="";} #R3. Replace hard returns with
, cut carriage returns $Reserved8=~s/\n/
/g; $Reserved8=~s/\r//g; if ($Reserved8 eq "Select"){ $Reserved8="";} #R3. Replace hard returns with
, cut carriage returns $Reserved9=~s/\n/
/g; $Reserved9=~s/\r//g; if ($Reserved9 eq "Select"){ $Reserved9="";} #R3. Replace hard returns with
, cut carriage returns $Reserved10=~s/\n/
/g; $Reserved10=~s/\r//g; if ($Reserved10 eq "Select"){ $Reserved10="";} #R4. You have marked First_Name as a field that must contain at least 1 #non-blank characters before allowing the field to be added. You can change the #requirement below, or comment out all 6 lines below step to skip validation $First_Namecheck=$First_Name; $First_Namecheck=~s/ +/ /g; $First_Namecheck=length($First_Namecheck); if ($First_Namecheck<1){ $problem="Please press back on your browser and provide more information for the First_Name field."; &security;} #R4. You have marked Last_Name as a field that must contain at least 1 #non-blank characters before allowing the field to be added. You can change the #requirement below, or comment out all 6 lines below step to skip validation $Last_Namecheck=$Last_Name; $Last_Namecheck=~s/ +/ /g; $Last_Namecheck=length($Last_Namecheck); if ($Last_Namecheck<1){ $problem="Please press back on your browser and provide more information for the Last_Name field."; &security;} #R4. You have marked City as a field that must contain at least 1 #non-blank characters before allowing the field to be added. You can change the #requirement below, or comment out all 6 lines below step to skip validation $Citycheck=$City; $Citycheck=~s/ +/ /g; $Citycheck=length($Citycheck); if ($Citycheck<1){ $problem="Please press back on your browser and provide more information for the City field."; &security;} #R4. You have marked State as a field that must contain at least 1 #non-blank characters before allowing the field to be added. You can change the #requirement below, or comment out all 6 lines below step to skip validation $Statecheck=$State; $Statecheck=~s/ +/ /g; $Statecheck=length($Statecheck); if ($Statecheck<1){ $problem="Please press back on your browser and provide more information for the State field."; &security;} #R4. You have marked Name_of_Recipe as a field that must contain at least 1 #non-blank characters before allowing the field to be added. You can change the #requirement below, or comment out all 6 lines below step to skip validation $Name_of_Recipecheck=$Name_of_Recipe; $Name_of_Recipecheck=~s/ +/ /g; $Name_of_Recipecheck=length($Name_of_Recipecheck); if ($Name_of_Recipecheck<1){ $problem="Please press back on your browser and provide more information for the Name_of_Recipe field."; &security;} #R4. You have marked Ingredients as a field that must contain at least 1 #non-blank characters before allowing the field to be added. You can change the #requirement below, or comment out all 6 lines below step to skip validation $Ingredientscheck=$Ingredients; $Ingredientscheck=~s/ +/ /g; $Ingredientscheck=length($Ingredientscheck); if ($Ingredientscheck<1){ $problem="Please press back on your browser and provide more information for the Ingredients field."; &security;} #R4. You have marked Directions as a field that must contain at least 1 #non-blank characters before allowing the field to be added. You can change the #requirement below, or comment out all 6 lines below step to skip validation $Directionscheck=$Directions; $Directionscheck=~s/ +/ /g; $Directionscheck=length($Directionscheck); if ($Directionscheck<1){ $problem="Please press back on your browser and provide more information for the Directions field."; &security;} if ((!$Unix_Timestamp) || ($timestampupdate=~/yes/i && $actiontotake eq "Edit Record")){ #Formatting for Unix Timestamp $Unix_Timestamp=time; if (length($Unix_Timestamp)==9){ $Unix_Timestamp="0$Unix_Timestamp";}} if ($actiontotake!~/edit/i || !$Date_Time_Added){ #Formatting for Unix Date and Time Added Stamp ($secstamp,$minstamp,$hourstamp,$mdaystamp,$monthstamp,$yearstamp,$wdaystamp,$dayofyearstamp,$isdst1stamp) = localtime(time); $monthstamp++; $yearstamp=1900+$yearstamp; if (length($monthstamp)==1){ $monthstamp="0$monthstamp";} if (length($mdaystamp)==1){ $mdaystamp="0$mdaystamp";} if (length($minstamp)==1){ $minstamp="0$minstamp";} if (length($hourstamp)==1){ $hourstamp="0$hourstamp";} if (length($secstamp)==1){ $secstamp="0$secstamp";} $Date_Time_Added="$yearstamp/$monthstamp/$mdaystamp $hourstamp:$minstamp:$secstamp";} if ($actiontotake!~/edit/i || !$Autoincrement){ $count=0; $problem="Unable to open or create the counter file at $counterfile, please check the path to the file."; open (COUNTER, "$counterfile") || open (COUNTER, ">>$counterfile") || &security; $count=; close(COUNTER); if ($count=~ /\n$/) { chop($count); } $count++; $problem="Unable to write to counter file at $counterfile. Please check the path to the file and make sure that it is chmod 766 or 777."; open (COUNTER,">$counterfile") || &error; print COUNTER "$count"; close (COUNTER); #Make all numbers six digit for proper sorting if (length($count)==1){ $Autoincrement="00000$count";} if (length($count)==2){ $Autoincrement="0000$count";} if (length($count)==3){ $Autoincrement="000$count";} if (length($count)==4){ $Autoincrement="00$count";} if (length($count)==5){ $Autoincrement="0$count";} } } #STEP S================================ sub addtemp{ #S1. This subroutine adds records to your temporary file for approval $delimiter="\|"; #S2. Check variable sent &getvariables; #S3. Randomize in preparation for random generator srand(); #S4. Get IP address of person posting record $ipstamp=$ENV{'REMOTE_ADDR'}; #S5. Generate a large random number to serve as key $randnumb=int(rand(9999999)); $replacementline="$ipstamp&&temp$randnumb(\+\+)$First_Name$delimiter$Last_Name$delimiter$City$delimiter$State$delimiter$Name_of_Recipe$delimiter$Ingredients$delimiter$Directions$delimiter$Unix_Timestamp$delimiter$Date_Time_Added$delimiter$Autoincrement$delimiter$Reserved1$delimiter$Reserved2$delimiter$Reserved3$delimiter$Reserved4$delimiter$Reserved5$delimiter$Reserved6$delimiter$Reserved7$delimiter$Reserved8$delimiter$Reserved9$delimiter$Reserved10"; #S6. Write the temp record to the bottom of the $problem="Can't write to the data file. Please verify its location and change its permissions to 777."; open (FILE2,">>$tempdata") || &security; print FILE2 "$replacementline\n"; close(FILE2); print "Content-type: text/html\n\n"; print "$templatestart\n"; #S7. Acknowledge that record has been posted print "Your record has been sent for evaluation. Please click here to continue.\n"; print "$templateend\n"; exit; } #STEP T================================ sub scrolltemp{ #T1. This step is your interface with the temp file #T2. Check password if ($adminpassword ne $checkpassword && $adminpassword){ $problem="The password you entered does not match your administration password. Please press BACK on your browser to fix this problem."; &security;} #T3. Check to make sure that the data file can be opened. $problem="Unable to open your temporary data file. It either contains no records, or the path to it is incorrect."; open (FILE, "$tempdata") || &security; @all=; close (FILE); print "Content-type: text/html\n\n"; #T4. Start showing contents of data file print "$templatestart\n"; print "

\n"; $checktemp=@all; if (!$checktemp){ print "Your temporary file contains no records for you to evaluate at this time. Please click here to continue.

\n"; print "$templateend\n"; exit;} print "KEY
A=Add to Database
D=Delete from Temp File
E=Add to Database but Mark for Editing
H=Hold in Temp File for Decision Later

\n"; print "\n"; print "\n"; foreach $line (@all){ $line=~s/\n//g; $checkleng=length($line); if ($checkleng<2){next}; ($indexvalues,$stringvalues)=split(/\(\+\+\)/,$line); ($ipaddress,$uniqueapproval)=split(/&&/,$indexvalues); ($First_Name,$Last_Name,$City,$State,$Name_of_Recipe,$Ingredients,$Directions,$Unix_Timestamp,$Date_Time_Added,$Autoincrement,$Reserved1,$Reserved2,$Reserved3,$Reserved4,$Reserved5,$Reserved6,$Reserved7,$Reserved8,$Reserved9,$Reserved10,$skipthisfield)=split (/$delimiter/,$stringvalues); print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; $keeptrack2++; if ($keeptrack2>10){ last}; } print "
ADEHFieldContents
IP Address:$ipaddress
    First Name:$First_Name
    Last Name:$Last_Name
    City:$City
    State:$State
    Name of Recipe:$Name_of_Recipe
    Ingredients:$Ingredients
    Directions:$Directions
    Unix Timestamp:$Unix_Timestamp
    Date Time Added:$Date_Time_Added
    Autoincrement:$Autoincrement
    Reserved1:$Reserved1
    Reserved2:$Reserved2
    Reserved3:$Reserved3
    Reserved4:$Reserved4
    Reserved5:$Reserved5
    Reserved6:$Reserved6
    Reserved7:$Reserved7
    Reserved8:$Reserved8
    Reserved9:$Reserved9
    Reserved10:$Reserved10
\n"; if ($keeptrack2>=10){ print "

\n";} else{ print "\n";} print "$templateend\n"; exit; } #STEP U================================ sub updatetemp{ #U1. This step makes changes from temp file #U2. Check password if ($adminpassword ne $checkpassword && $adminpassword){ $problem="The password you entered does not match your administration password. Please press BACK on your browser to fix this problem."; &security;} $problem="Unable to open your temporary data file. It either contains no records, or the path to it is incorrect."; open (FILE, "$tempdata") || &security; @all=; close (FILE); foreach $line (@all){ $line=~s/\n//g; $checkleng=length($line); if ($checkleng<2){next}; ($indexvalues,$stringvalues)=split(/\(\+\+\)/,$line); ($ipaddress,$uniqueapproval)=split(/&&/,$indexvalues); ($First_Name,$Last_Name,$City,$State,$Name_of_Recipe,$Ingredients,$Directions,$Unix_Timestamp,$Date_Time_Added,$Autoincrement,$Reserved1,$Reserved2,$Reserved3,$Reserved4,$Reserved5,$Reserved6,$Reserved7,$Reserved8,$Reserved9,$Reserved10,$skipthisfield)=split (/$delimiter/,$stringvalues); if ($tempapprove{$uniqueapproval} eq "A"){ push(@recordstoadd,$stringvalues);} elsif ($tempapprove{$uniqueapproval} eq "D"){ push(@recordstodelete,$stringvalues);} elsif ($tempapprove{$uniqueapproval} eq "E"){ push(@recordstoedit,$stringvalues);} else { push(@recordstohold,$line);} } $problem="Unable to open data file to add records. Check path to it and its permissions."; open (FILE, ">>$data") || &security; foreach $line (@recordstoadd){ $line=~s/\n//g; print FILE "$line\n";} close(FILE); $problem="Unable to open data file to records to edit. Check path to it and its permissions."; open (FILE, ">>$data") || &security; foreach $line (@recordstoedit){ $line=~s/\n//g; print FILE "markedtoedit$line\n";} close(FILE); $problem="Unable to open temporary file to refresh data. Check path to it and its permissions."; open (FILE, ">$tempdata") || &security; foreach $line (@recordstohold){ $line=~s/\n//g; print FILE "$line\n";} close(FILE); $checkhold=@recordstohold; if ($checkhold){ &scrolltemp;} print "Content-type: text/html\n\n"; print "$templatestart\n"; print "

Your actions have been taken. Please click here to continue.

\n"; print "$templateend\n"; exit; }