#!/usr/bin/perl # ============================================================================================================= # # Module name: Shopping Cart session creator # Version: 3.1.1 # Purpose: Set cookie with session ID used for tracking shopping cart # Last change: 2002-08-09 Sean Hayes # ============================================================================================================= # # (c) Copyright 2000-2002 - Metal Software, Inc. All Rights Reserved. UNAUTHORIZED USE PROHIBITED! # http://www.metalsoftware.com/ infoweb@metalsoftware.com # ============================================================================================================= # # All users of this software agree to the following: # - Not to sell, distribute, lease or otherwise transfer ownership of the source code or derivatives of it. # - To provide Metal Software, Inc. with any updates, derivative works or rewriting made to the source code. # - The copyright on the delivered source code remains bound to Metal Software, Inc. # - To hold any person or company whom is given access the source code to the above terms. # - To include at the bottom of Web pages using the software the statement: # "Listing search logic developed by MetalSoftware.com" # ============================================================================================================= # # This license is not limited by the terms above and is subject to change without notice. # For questions contact: Metal Software, Inc., 410 West Nine Mile Road, Suite 2424, Pensacola, FL 32534 # ============================================================================================================= # # Change log: # Sean Hayes 2002-08-09: Added DEVelopment environment status # ============================================================================================================= # # To Do: # # $DEVcartPageTemplate done 09-15-2002 # ============================================================================================================= # # Load Modules use CGI; use DBI; use CGI::Carp qw(fatalsToBrowser); use Number::Format qw(:subs); my $HttpHost = $ENV{"HTTP_HOST"}; my $RequestUri = $ENV{"REQUEST_URI"}; my $CompleteUrl = 'http://' . $HttpHost . $RequestUri; my $domainName = getDomainName($HttpHost); # Load Configuration require '/usr/v/virtual/_halpin-br-1.0/config/global.conf.cgi'; require $configDir . '/database.conf.cgi'; require $configDir . '/' . $domainName . '.conf.cgi'; # Load Libraries require $libDir . '/search-lib-3.1.1.cgi'; # Global variables $ScriptName = $frontendDir .'/cart-session-3.1.1.cgi'; # Required for debugging $cgi = new CGI; my($cookiename) = 'cart'; my($expiretime) = '1h'; # (d=day,h=hr,M=month) my($cookiepath) = '/'; my($trakdomain) = '.downing-frye-realty.com'; my($cookiename2) = 'lastsearch'; my($expiretime2) = '1h'; # (d=day,h=hr,M=month) my($cookiepath2) = '/'; my($trakdomain2) = '.downing-frye-realty.com'; my($TodaysDate) = `date +%Y-%m-%d`; $TodaysDate =~ s#\s##igs; my($epochSeconds) = `date +%s`; $epochSeconds =~ s#\s##igs; my($TimeStamp) = `date +%Y%m%d%H%M%S`; my($UniqueNumber) = $ENV{'REMOTE_ADDR'}; my($referer) = $ENV{'HTTP_REFERER'}; $UniqueNumber =~ s#\.##igs; $UniqueNumber = $TimeStamp . $UniqueNumber . $$; $UniqueNumber =~ s#\s##igs; my($trackid) = $cgi->cookie(-name=>"$cookiename"); my($resetCookie) = $cgi->param('c'); my($ViewIt) = $cgi->param('view'); my($savesearch) = $cgi->param('saves'); my($frontsearch) = $cgi->param('front'); my($SRpage) = $cgi->param('srpage'); my($cartIt) = join(" ",$cgi->param('mls')); my($unCartIt) = join(" ",$cgi->param('umls')); my ($cookie,@items,$i,$item,@unitems,$u,$uitem,$section,$sec,$atype,$btype,$adec,$bdec); # ########################################################################################### if (defined $trackid) # cookie is set { $lastsearchCart = getSearchInCart($trackid,'SearchResult'); $lastsearchCart = makeLinkOutUrlsPercent($lastsearchCart); $frontsearchCart = getSearchInCart($trackid,'SearchFront'); $frontsearchCart = makeLinkOutUrlsPercent($frontsearchCart); if ($resetCookie eq '1') # delete cookie { $cookie = $cgi->cookie(-name=>"$cookiename", -value=>'0', -expires=>'-1d', -path=>"$cookiepath", -domain=>"$trakdomain"); print $cgi->header(-cookie=>$cookie); # ## print "

Deleted $cookiename cookie!

"; unLogSession($trackid); unLogCart($trackid); unLogSearch($trackid); } elsif ($cartIt ne '') # put properties in a cart { if ($SRpage eq 'yes') # redirect back to search results page if post orig. from { @items = split(/ /,$cartIt); for ($i = 0; $i <= $#items; $i++) { $item = $items[$i]; $section = $cgi->param("$item"); # print "

ADDED MLS #: $item

"; logCart($trackid,$item,$section); } if($referer ne '') { print "Location: $referer\n\n"; } else { print "Content-type: text/html\n\n"; print qq| Back to search...


... Saving to basket ...

|; } } # end if else { print "Content-type: text/html\n\n"; $numberInCart = checkNumberInCart($trackid); $numberInCart = $numberInCart + 1; # correction for addition printHeader($cartPageTemplate); print "

ADDED MLS number(s): "; @items = split(/ /,$cartIt); for ($i = 0; $i <= $#items; $i++) { $item = $items[$i]; $section = $cgi->param("$item"); print "$item "; logCart($trackid,$item,$section); } print "

"; printTableHeaderRow(); getCartRows($trackid); printFooter($cartPageTemplate); } # end else } elsif ($unCartIt ne '') # remove properties from cart { print "Content-type: text/html\n\n"; print qq| |; $numberInCart = checkNumberInCart($trackid); $numberInCart = $numberInCart - 1; # correction for removal printHeader($cartPageTemplate); print "

REMOVED MLS Number(s): "; @unitems = split(/ /,$unCartIt); for ($u = 0; $u <= $#unitems; $u++) { $uitem = $unitems[$u]; # ## print "$uitem "; unLogCartItems($trackid,$uitem); } print "

"; printTableHeaderRow(); getCartRows($trackid); printFooter($cartPageTemplate); } elsif ($ViewIt ne '') # show cart { print "Content-type: text/html\n\n"; $numberInCart = checkNumberInCart($trackid); printHeader($cartPageTemplate); printTableHeaderRow(); getCartRows($trackid); printFooter($cartPageTemplate); } else { print "Content-type: text/html\n\n"; # ## print "

Cookie IS set!

"; if ($savesearch ne '') { $adec = urlDecode($savesearch); $atype = 'SearchResult'; logSearch($trackid,$adec,$atype); # print "Saved search: $adec\n"; } if ($referer ne '') # !~ /property/ && $frontsearch !~ /property/ && $frontsearch !~ /search-result/ && $frontsearch ne '' && $frontsearch !~ /session/ && $frontsearch !~ /halpin/ { $bdec = urlDecode($frontsearch); $btype = 'SearchFront'; logSearch($trackid,$bdec,$btype); # print "Saved search: $bdec
\n$referer
\n"; } # else # { # print "No save: $bdec\n"; # } } } else # no cookie is set, setting... { $cookie = $cgi->cookie(-name=>"$cookiename", -value=>"$UniqueNumber", -expires=>"+$expiretime", -path=>"$cookiepath", -domain=>"$trakdomain"); print $cgi->header(-cookie=>$cookie); # ## # print "Content-type: text/html\n\n"; if ($cartIt) { $url_d = 'http://www.downing-frye-realty.com/www.larryhalpin.com/property/1/area/BrokerRecip/' . $cartIt . '.html'; } else { $url_d = 'http://www.larryhalpin.com/'; } print qq| On To cart...


Cart temporarily inactive, directing to property page in 5 seconds.

DEBUG: Setting $cookiename cookie: _id: $UniqueNumber
_name: $cookiename
_expire: $expiretime
_path: $cookiepath
_domain: $trakdomain

|; logSession($UniqueNumber,$ClientID,$TodaysDate,$TimeStamp,$epochSeconds); } $dbh->disconnect(); $sdbh->disconnect(); exit(); # ------------------------------------------------------------------------- # logSession() # ------------------------------------------------------------------------- sub logSession { my($UniqueNumber,$ClientID,$TodaysDate,$TimeStamp,$epochSeconds) = @_ ; my($ipAddress) = $ENV{'REMOTE_ADDR'}; my($Referer) = $ENV{'HTTP_REFERER'}; my $query = 'INSERT INTO sessionTrack (sessionTrackId,ipAddress,Referer,trackDate,timeStamp,epochSeconds) VALUES (?,?,?,?,?,?)'; my $sth = $sdbh->prepare("$query") or die "Unable to prepare query: $sdbh->errstr\n"; $sth->execute($UniqueNumber,$ipAddress,$Referer,$TodaysDate,$TimeStamp,$epochSeconds) or die "Unable to execute query: $sdbh->errstr, sth: $sth->errstr\n"; $sth->finish(); } # end sub logSession # ------------------------------------------------------------------------- # logCart() # ------------------------------------------------------------------------- sub logCart { my($UniqueNumber,$mlsNumber,$sec) = @_ ; my $query = 'REPLACE INTO sessionCart (sessionTrackId,mlsNumber,Section) VALUES (?,?,?)'; my $sth = $sdbh->prepare("$query") or die "Unable to prepare query: $sdbh->errstr\n"; $sth->execute($UniqueNumber,$mlsNumber,$sec) or die "Unable to execute query: $sdbh->errstr, sth: $sth->errstr\n"; $sth->finish(); } # end sub logCart # ------------------------------------------------------------------------- # logSearch($UniqueNumber,$search,$type) # ------------------------------------------------------------------------- sub logSearch { my($UniqueNumber,$search,$type) = @_ ; if ($search eq '') { $search = 'http://www.larryhalpin.com/'; } my $query = 'REPLACE INTO sessionSearch (sessionTrackId,lastSearch,Type) VALUES (?,?,?)'; my $sth = $sdbh->prepare("$query") or die "Unable to prepare query: $sdbh->errstr\n"; $sth->execute($UniqueNumber,$search,$type) or die "Unable to execute query: $sdbh->errstr, sth: $sth->errstr\n"; $sth->finish(); } # end sub logSearch # ------------------------------------------------------------------------- # unLogSession() # ------------------------------------------------------------------------- sub unLogSession { my($trackingId) = @_ ; my $query = 'DELETE FROM sessionTrack WHERE sessionTrackId = ?'; my $sth = $sdbh->prepare("$query") or die "Unable to prepare query: $sdbh->errstr\n"; $sth->execute($trackingId) or die "Unable to execute query: $sdbh->errstr, sth: $sth->errstr\n"; $sth->finish(); } # end sub unLogSession # ------------------------------------------------------------------------- # unLogCart() # ------------------------------------------------------------------------- sub unLogCart { my($trackingId) = @_ ; my $query = 'DELETE FROM sessionCart WHERE sessionTrackId = ?'; my $sth = $sdbh->prepare("$query") or die "Unable to prepare query: $sdbh->errstr\n"; $sth->execute($trackingId) or die "Unable to execute query: $sdbh->errstr, sth: $sth->errstr\n"; $sth->finish(); } # end sub unLogCart # ------------------------------------------------------------------------- # unLogSearch() # ------------------------------------------------------------------------- sub unLogSearch { my($trackingId) = @_ ; my $query = 'DELETE FROM sessionSearch WHERE sessionTrackId = ?'; my $sth = $sdbh->prepare("$query") or die "Unable to prepare query: $sdbh->errstr\n"; $sth->execute($trackingId) or die "Unable to execute query: $sdbh->errstr, sth: $sth->errstr\n"; $sth->finish(); } # end sub unLogSearch # ------------------------------------------------------------------------- # unLogCartItems($trackingId,$mlsNumber) # ------------------------------------------------------------------------- sub unLogCartItems { my($trackingId,$mlsNumber) = @_ ; my $query = 'DELETE FROM sessionCart WHERE sessionTrackId = ? AND mlsNumber = ?'; my $sth = $sdbh->prepare("$query") or die "Unable to prepare query: $sdbh->errstr\n"; $sth->execute($trackingId,,$mlsNumber) or die "Unable to execute query: $sdbh->errstr, sth: $sth->errstr\n"; $sth->finish(); } # end sub unLogCartItems # ------------------------------------------------------------------------- # getCartRows($trackid) currently supports BR only # ------------------------------------------------------------------------- sub getCartRows { my ($trackid) = @_; my $Query = "SELECT $brokerRecipTable.BedroomsNoof, $brokerRecipTable.BuildingDesign, $brokerRecipTable.DevelopmentName, $brokerRecipTable.FullBaths, $brokerRecipTable.HalfBaths, $brokerRecipTable.PriceList, $brokerRecipTable.Pool, $brokerRecipTable.AreaTotalunderRoofApprox, $brokerRecipTable.YearBuilt, $brokerRecipTable.MLNum, $brokerRecipTable.ListAgentName, $brokerRecipTable.AuxUrl, $brokerRecipTable.Section FROM $brokerRecipTable,sessionCart WHERE sessionCart.mlsNumber = $brokerRecipTable.MLNum AND sessionCart.sessionTrackId = ? ORDER BY PriceList $orderSQLcode"; my $sth = $dbh->prepare("$Query") or die "Unable to prepare query: $dbh->errstr\n"; $sth->execute($trackid) or die "Unable to execute query: $dbh->errstr\n"; my ($BedroomsNoof,$BuildingDesign,$DevelopmentName,$FullBaths,$HalfBaths,$PriceList,$Pool,$AreaTotalunderRoofApprox,$YearBuilt,$MLNum,$ListAgentName,$AuxUrl,$Section,$DevelopmentNameOut,$DevelopmentNameUrlOut,$ListAgentNameOut,$BuildingDesignOut,$BedroomsNoof,$YearBuiltDesc,$PriceFormat,%resultsHash,$lineOut,$listingUrl,$propTypeOut,$photoExist,$displayPhoto); $sth->bind_columns(undef, \$BedroomsNoof, \$BuildingDesign, \$DevelopmentName, \$FullBaths, \$HalfBaths, \$PriceList, \$Pool, \$AreaTotalunderRoofApprox, \$YearBuilt, \$MLNum, \$ListAgentName, \$AuxUrl, \$Section); while (my $ref = $sth->fetchrow_hashref()) { $numRows = $sth->rows; $DevelopmentNameOut = TitleCase($DevelopmentName); $DevelopmentNameUrlOut = removeSpacesReplaceDash($DevelopmentNameOut); $BuildingDesignOut = cleanUpBuildingDesign($BuildingDesign); $BedroomsNoof = removeAllButNumbers($BedroomsNoof); $YearBuiltDesc = "$BuildingDesignOut, $BedroomsNoof/$FullBaths/$HalfBaths"; $PriceFormat = FormatPrice($PriceList); if ($Section eq 'BrokerRec') { $ListAgentNameOut = 'Broker Reciprocity'; $propTypeOut = 'BrokerRecip'; } else { $ListAgentNameOut = TitleCase($ListAgentName); $propTypeOut = $propType; } $photoExist = getPropertyPhotoExist($MLNum,$propTypeOut); if ($photoExist > 0) { $displayPhoto = " "; } else { $displayPhoto = ""; } if ($PriceFormat =~ /\$/) { $PriceFormat = "$PriceFormat"; } elsif ($PriceFormat eq 'Call Agent') { $PriceFormat = "$PriceFormat"; } else { $PriceFormat = "\$$PriceFormat"; } $listingUrl = formatUrlString($listingPageRootUrl,$PriceList,$DevelopmentNameUrlOut,$propTypeOut,$MLNum,$AuxUrl); $lineOut = "$MLNum  $displayPhoto    $DevelopmentNameOut $YearBuiltDesc $PriceFormat  Remove \n"; # $lineOut = "$MLNum   $displayPhoto $DevelopmentNameOut $YearBuiltDesc $PriceFormat   Remove \n"; print "$lineOut\n"; } $sth->finish(); } # end sub getCartRows # ------------------------------------------------------------------------- # getDomainName - Strips the domain name from a host name # ------------------------------------------------------------------------- sub getDomainName { my($hostname) = @_; # Debug( "GetDomainName/begin: $hostname" ); # must be at least 2 dots while (($hostname =~ tr/././) > 1 ) { # Debug( "getDomainName: $hostname" ); $hostname =~ s/^[\w\-]+\.//; } return $hostname; } # end sub getDomainName