#!D:\Perl\bin\perl.exe -w use CGI qw(:standard); use CGI::Cookie; |
# custom content for each M-Business Anywhere user. # # This is your basic Movie News front page. It looks up # the user's preferences for movies he likes, and # provides links to, different movie reviews if they # fit into his list of categories. If this is the user's # first time here, it provides him with some default # categories. # |
# The basic strategy is this: We look for a cookie called # moviereviewID. # # If it exists, we take the value of that # cookie (the user's ID) and look it up in a database. # That database contains a list of the user's preferred # channels. # |
# If we don't find a cookie, we just give them some # default content. # # PLEASE NOTE: This is a script running under ActivePerl # on Win2k. Please change the first line to reflect # whatever system you're running Perl under. Please read # the legal message at the bottom. # |
# Prints out some standard HTTP headers. |
print header(-'Cache-Control'=>'private'); |
# Gets all the cookies and puts them into a hash. |
%cookies = fetch CGI::Cookie; |
if ($cookies{'moviereviewID'} ) { |
# If a cookie exists, we get its value (which is the # user's ID number) |
$myID = $cookies{'moviereviewID'} -> value; |
dbmopen(%prefs,"movieuserprefs",0644) ||
die "Can't open movieuserprefs! $!"; |
# We look up the user's preferences based on his ID # in the database. # # The record itself is a big string of values # separated by ~:~ characters. # The "split" function breaks up that string and # places the resulting values into the variable # "propername" and the array "prefs" |
($propername, @prefs) = split(/~:~/, $prefs{$myID}); |
dbmclose(%prefs); |
} else { |
# We make prefs an array of default values if the # user's cookie does not exist. |
@prefs = (1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0); |
# Flag indicates we're using default values. |
$default = 1; |
} |
# Now we print out the beginning of the Web page. |
print <<END_of_Start; |
<HTML> <HEAD> <TITLE>Movie reviews</title> <META NAME="HandheldFriendly" content="True"> </head> <body> <Center><h2>The movie review channel!</h2></center> |
END_of_Start |
print "<p>Welcome, $propername </p>" unless $default; print "<p>Here are a list of movies you might be interested in...</p>\n <ul>\n"; |
dbmopen(%movies,"moviereviews",0644) || die "Can't open moviereviews! $!"; |
# We iterate over movie ID within the moviereviews # database. |
foreach $filmnumber (keys (%movies)) { |
# Again, breaking up a string into the variable # "filmname" and the "genres" array using a split # command. |
($filmname, @genres) = split(/~:~/, $movies{$filmnumber}); |
$match = 0; for ($i =0; $i < 11; $i++) { if ($genres[$i] && $prefs[$i]) { $match = 1; # We've found a match! last; # Break out of the loop. # no need to keep looking. } } |
# If this film has a match, include a link to it. |
if ($match) { print "<li><A href=\"reviews/${filmnumber}.html\">$filmname</a>\n"; } |
} |
dbmclose(%movies); |
print "</ul>\n<p>Tune in next time for more movie reviews!<p>\n"; |
if ($default) { # Informative message telling them to personalize # their content print "<center>Want personalized content? Of course you do!\n"; print "<br><a href=\"/cgi-bin/movies/editprefsform.pl\ ">Edit your preferences</a></center>\n"; |
} else { |
# They've already personalized, so we can be a little # more understated here. print "<a href=\"/cgi-bin/movies/editprefsform.pl\ ">Edit preferences</a>\n"; } |
print "</body>\n</html>\n"; |
# And now, the important legal message... # # Copyright (c) 2007, iAnywhere Solutions, Inc., # all rights reserved. # # IANYWHERE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT # THE SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR # PURPOSE, OR NON-INFRINGEMENT. IANYWHERE SHALL NOT BE # LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT # OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR # ITS DERIVATIVES. |
Send feedback about this page using email. | Copyright © 2008, iAnywhere Solutions, Inc. |