#!/usr/bin/perl $| = 1; $hitCount = 0; $database = "/u1/www/transportuniverse/db2/search.txt"; $logfile = "/u1/www/transportuniverse/db1/searchlog.dat"; @table_fields = ("PICTURE","YEAR","MAKE","MODEL","CITY","STATE","MILEAGE","PRICE","AD_ID"); print "Content-type: text/html\n\n"; print qq~ Universal Search: Total Transportation Index v1
 
Search Transport Universe
Any Vehicle Ever Made Is
At Your Fingertips!
 
 
CLASSIFIEDS AUCTIONS DEALERS WANTED JOBS B2B

                             

UNIVERSAL SEARCH RESULTS
~; ############################################################## # Parse from the web form ############################################################## read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @cgiPairs = split(/&/,$buffer); foreach $cgiPair (@cgiPairs) { ($name,$value) = split(/=/,$cgiPair); $value =~ s/\+/ /g; $value =~ s/%(..)/pack("c",hex($1))/ge; $form{$name} .= "\0" if (defined($form{$name})); $form{$name} .= "$value"; } $ebaysearch = $form{'fyear'} . " " . $form{'fmake'} . " " . $form{'fmodel'}; # trimp whitespace from beginning and end $ebaysearch =~ s/^\s//; $ebaysearch =~ s/\s+$//; # replace whitespace with - $ebaysearch =~ s/\s/-/g; $ebayseearchUrl = "http://www.qksrv.net/click-1950362-5463217?loc=http%3A//motors.search.ebay.com/" . $ebaysearch . "_Passenger-Vehicles"; ################################################ # SORT THE DATABASE AND PUT RESULTS IN @database_rows ################################################ #$sortit = $form{'sortby'}; if ($form{'sortit'} eq "") { $sortit = 1; } else { $sortit = $form{'sortit'}; } $start_display = $form{'startdisplay'}; $display_end = $form{'displayend'}; # First pick out the field, and move it to the beginning of the line open(FILE, "$database"); flock(FILE, $LOCK_EX); $count=0; @row1 =; close (FILE); while (@row1[$count] ne "") { $row = @row1[$count]; @row = split (/\|/, $row); $sortable_field = $row[$sortit]; unshift (@row, $sortable_field); $new_row = join ("\|", @row); push (@new_rows, $new_row); $count++ } # Next, sort the lines of the database if ($form{'order'} eq "alpha") { @sorted_rows = sort (@new_rows); } else { @sorted_rows = reverse sort (@new_rows); } #now put the field back where it belongs @database_rows = (); foreach $sorted_row (@sorted_rows) { @row = split (/\|/, $sorted_row); $sorted_field = shift (@row); $old_but_sorted_row = join ("\|", @row); push (@database_rows, $old_but_sorted_row); } #######Used to check the sorting # open FILE, ">/u1/www/transportuniverse/db2/sorted.txt"; # print FILE (@database_rows); # close FILE; ################################# # END OF SORT DATABASE ################################# $form{'searchtext'} = $form{'fyear'} . " " . $form{'fmake'} . " " . $form{'fmodel'} . " " . $form{'fstate'}; $form{'searchtype'} = "all"; if ($form{'searchtext'} eq "") { $form{'searchtext'} = $searchtext; } @searchText = split(/\x20/,$form{'searchtext'}); foreach $test (@searchText) { if ($test =~ /\S{2,}/) {push (@searchKey, $test);} } ######################################## # add eBay search #print "

searchtext: " . $form{'searchtext'} . "

"; # print "

ebaysearch: " . $ebaysearch . "

"; print "

"; print "Search on eBay

"; ######################################## if (! @searchKey) {print " Please Enter One Or More Keywords.
\n";} else { print "
Select a column to sort these results in alpha-numeric order.
Uncheck the sort box to sort the results in reverse order
"; print"\n"; print " method=post action=\"\/cgi-transportuniverse\/supersearch.cgi\">\n"; print "\n"; print "\n"; print "
YEARVEHICLELOCATIONMILESPRICE
\n"; $count=1; foreach $inLine (@database_rows) { $line=$inLine; if ( $form{'field'} ne "") { @fields = split (/\|/, $inLine); $inLine=$fields[$form{'field'}]; } if ($form{'searchtype'} eq "any") {$foundFlag = "N";} else {$foundFlag = "Y";} foreach $test (@searchKey) { if ($inLine =~ /$test/i) { if ($form{'searchtype'} eq "any") { $foundFlag = "Y"; last; } } else { if ($form{'searchtype'} eq "all") { $foundFlag = "N"; last; } } #end of foreach inLine of @database_rows } # end ForEach Test if ($foundFlag eq "Y") { @fields = split(/\|/,$line); $hitCount++; $odd_row_color = '#DFDFDF'; if ($i % 2 == 1) { $bg = $odd_row_color; } else { $bg = '#ffffff'; } $i++; $ii++; $camera = " "; $piciconpath = ""; if ($fields[0] eq "Y") { $camera = $piciconpath; } else { $camera = " "; } $adid = $fields[6]; if ($adid =~ m/asp/) { $link = "$fields[2]"; $yearlink = "$fields[1]"; } elsif ($adid =~ m/\_/) { $link = "$fields[2]"; $yearlink = "$fields[1]"; } else { $link = "$fields[2]"; $yearlink = "$fields[1]"; } print"\n"; print"
$camera $yearlink $link$fields[3]$fields[4]\$$fields[5]
\n"; } $count++; } # end While InLine close(LINK); print "

Your search returned $hitCount entries.

\n"; } $nowtime = localtime(time); open THEFILE, ">>$logfile"; print THEFILE "$form{'searchtext'}\|$hitCount\|$nowtime\n"; close THEFILE; print qq~

START A NEW SEARCH

UNIVERSAL VEHICLE SEARCH
YEAR MAKE MODEL STATE
 
Fill in one or more of the above fields and click GO to search >>>  
Leave a field blank to see all of those listings...

OR

~; ############################################################## # Display the footer ############################################################## ############################################## # Print The Page Footer # print <<"EOF";


Copyright 1999-2001 Transport Universe Inc. All Rights Reserved.
 Use of this Web site constitutes acceptance of the TRANSPORT UNIVERSE User Agreement

EOF ;