#!/usr/bin/perl -w
#!"C:/Program Files/Perl/bin/perl.exe" -w
# If you want to run this script on Windows, copy the above line to the *first* line and 
#  be sure that the path points to the location of the Perl interpreter!
# On Unix, the current first line should be OK on most systems. On some systems you have to change the path.
#  After you have uploaded this script in ASCII mode, change permissions to chmod 755.
#
# ANET.at HomepageSearchEngine Helper Application "passurl.cgi"
# Written by Robert Allerstorfer. Last updated on 2002 06 08
#
# This Perl CGI script can be used to redirect the result links to a custom application, eg., a shopping cart script,
#  which makes use of a ID that has been dynamically generated before the search started.
#  Assuming this script is located in the "/cgi-bin/hse" web directory (along with the HomepageSearchEngine application),
#  you must set the following in section (8.7) of the "hse.ini" file:
#
#	results_href = /cgi-bin/hse/passurl.cgi?url=URL
#
#  Additionally, you must deliver the ID to HomepageSearchEngine as the "append" delivery parameter's value. See chapter
#  6.12 (Options to call the search engine) of the ReadMe.txt for details.
#
# The URL to the page (URL), the name of the found page (PAGE) and the appended "append" value (APPEND) will be extracted. 
#  These strings can then be used to be delivered to your own application, specified by its URL ($app_url).

use strict;

######### Configuration section ################################################################################################
#                                                                                                                              #

# $app_url: Specify your application's URL. The strings URL, PAGE and APPEND will be resolved to the corresponding values.
my $app_url = "/cgi-bin/cart/shopwa.pl/page=PAGE/sid=APPEND";

#                                                                                                                              #
######### don't change anything below this line!!! #############################################################################


BEGIN {	$| = 1 }
my ($url, $append) = split(/%3Fappend%3D/, (split(/=/, $ENV{QUERY_STRING}))[1]);
my ($page) = $url =~ /.*\/([^\/]+$)/;

$app_url =~ s/URL/$url/;
$app_url =~ s/APPEND/$append/;
$app_url =~ s/PAGE/$page/;

unless ($ENV{QUERY_STRING} =~ /debug;/) {
	print "Location: $app_url\n\n";
} else {
	print "Content-Type: text/html\n\n<pre>";
	print "\nURL\t'$url'";
	print "\nPAGE\t'$page'";
	print "\nAPPEND\t'$append'";
	print "\napp_url\t'$app_url'";
}

exit(0);