#!/usr/bin/perl
use DBI;
##################################################################
# Configuration
require "/home/admin/domains/places.co.za/connectdb";
#$header_file = "/home/httpd/html/actstravel/template/global.html";
$header_file = "/home/admin/domains/actstravel.com/public_html/template/global2.html";
#$cgi_url = "http://172.2.201.7/cgi-bin/gameinfo";
$cgi_url = "http://www.actstravel.com/cgi-bin/gameinfo";
#$server = "172.2.201.7";
$server = "www.places.co.za";
#$photodir = "/home/httpd/html/actstravel/photos";
$photodir = "/home/admin/domains/actstravel.com/public_html/photos";
##################################################################
if ($ENV{'QUERY_STRING'} eq "")
{
read(STDIN, $temp, $ENV{'CONTENT_LENGTH'});
}
else
{
$temp = $ENV{'QUERY_STRING'};
}
@pairs=split(/&/,$temp);
foreach $item(@pairs) {
($key,$content)=split (/=/,$item,2);
$content=~tr/+/ /;
$content=~ s/%(..)/pack("c",hex($1))/ge;
$fields{$key}=$content;
}
$fields{'comment'}=~s/\cM//g;
$fields{'comment'}=~s/\n\n/
/g;
$fields{'comment'}=~s/\n/
/g;
##### without plusses in
# Ex. "Cape Town"
$city_full = $fields{'lookup'};
$city_full =~ tr/+/ /;
##### Without plusses and escaped
# Example "Betty\'s Bay"
$city_stripped =~ tr/+/ /;
$city_stripped = &stripstring ($fields{'lookup'});
##### With plusses not escaped
# Example "Betty's Bay"
$city_plus = $fields{'lookup'};
$city_plus =~ tr/ /+/;
###########################################################################
print "Content-type: text/html\n\n";
open (HEADERF, $header_file);
while (defined($line=))
{
if ($line =~ m/Results/g)
{
$r = pos($line);
print substr($line,0,$r - 7);
$ch_finish = 0;
#### Check what should be done
&mainsub;
####
print substr($line,$r,length($line));
}
else
{
print $line;
}
}
exit;
################################################################################
# Subs #########################################################################
################################################################################
sub mainsub
{
############################################
# Read data out of Database
&connectdb_places;
############################################
# Prepare the statement for execution
$sth = $dbh->prepare( "SELECT id,name,descrip,lookup,province
FROM actstravel WHERE lookup = '$fields{'lookup'}'");
if ( !defined $sth ) { die "Cannot prepare statement: $DBI::errstr\n";}
###############################################
# Execute the statement at the database level
$sth->execute;
$rows = $sth->rows();
$arrlisted = 0;
$listed = 0;
#########################
if ($rows < 1)
{
$sth->finish;
$dbh->disconnect;
print "No listings was found";
}
else
{
&get_full;
} ### End check if there is url's or not for the current town
}
####################################################################################
sub get_full
{
###### 10 Results per page operations
#
if ($fields{'whr'} eq "")
{
$whres = 1;
}
else
{
$whres = $fields{'whr'};
}
#
#############
$fincheck = 0;
print <
$fields{'lookup'} Accommodation, $fields{'lookup'} Exclusive Lodges
| $rows Game
Reserves and Lodges were found in the $fields{'lookup'} area |
End_of_records
while ( @row = $sth->fetchrow() )
{
if ($listed < $whres && $listed >= $whres - 1)
{
$itemnum = $listed + 1;
$photo = "s_" . "$row[0]" . ".jpg";
$exists = (-e "$photodir/$photo");
if ($exists > 0)
{
print <
![$row[1]](http://www.actstravel.com/photos/$photo) |
$row[1]
$row[2] |
End_of_park
}
else
{
print <
 |
$row[1]
$row[2] |
End_of_nophotos
}
}
}
$listed++;
} ### End of loop through db
##################################################
# Release the statement handle resources
$sth->finish;
$dbh->disconnect;
#####
##############################
# Bottom of page result links (10 results per page operations
print "
";
print "";
$critname =~ tr/ /+/;
if (($whres) != 10)
{
$prev10 = $whres - 10;
print " << Previous 10 | ";
}
if (($whres) < $rows)
{
$next10 = $whres + 10;
print " Next 10 >> | ";
}
print "Pages : ";
$pgs = $rows / 10;
$misccount = 0;
while ($misccount <= $pgs)
{
$misccount++;
$whatpage = $misccount * 10;
print "$misccount ";
}
print "";
print "
";
#}
####################################################################################################
####################################################################################################
sub stripstring
{
my($fstring) = @_;
$rpllist = chr(39);
$replcmnt = chr(92) . chr(39);
$fstring =~ s/$rpllist/$replcmnt/g;
return ($fstring);
}