#!/usr/local/bin/perl use FileHandle; use CGI; #BEGIN #{ # use CGI::Carp qw(carpout); # open (ERROR, "> cgierror.log") || die "cant open cgierror.log\n"; # carpout(*ERROR); #} # Uncomment if debugging. #$debug = "Y"; open (LOG, "> newsletter.log") || die "cant open newsletter.log\n" if ($debug eq "Y"); autoflush LOG 1 if ($debug eq "Y"); $system = `uname -n`; chomp($system); if ($system =~ /^(pitboss|vp)/) { require '/cgi-bin/lib/cgilib.pl'; require '/cgi-bin/lib/login_lib.pl'; } else { require '/html/u/generic/cgilib.pl'; require '/html/u/generic/login_lib.pl'; } $form = new CGI; $subdir = $form->param('subdir'); @sysinfo = get_system_info(); if ($sysinfo[7] =~ /vegasinsider/) { $this_arena = 2; $this_arena_letter = "V"; $other_arena_letter = "S"; $prog_dir = "/cgi-bin/guest/contests/newsletter"; $site_name = $site_name2 = "VegasInsider.com"; $domain = "vegasinsider.com"; $privacy = "http://www.vegasinsider.com/privacy.html"; $html_dir = "/vhtml/u/newsletters"; $nl_prog_dir = "cgi-bin/newsletter"; } else { $this_arena = 1; $this_arena_letter = "S"; $other_arena_letter = "V"; $prog_dir = "/html/u/newsletters"; $site_name = "SportsLine.com"; $site_name2 = "CBS SportsLine"; $domain = "sportsline.com"; $privacy = "http://www.sportsline.com/u/userservices/privacy.htm"; require '/html/u/rewards/club_lib.pl'; $html_dir = "/html/u/newsletters"; $nl_prog_dir = "u/newsletters"; } if ($subdir) { $thanks_page = "/u/newsletters/$subdir/thankyou.html"; $confirm_page = "/u/newsletters/$subdir/confirm.html"; $exclude_conf_page = "/u/newsletters/$subdir/exclude_conf.html"; $mainfile1 = "/u/newsletters/$subdir/maint_top.html"; $mainfile2 = "/u/newsletters/$subdir/maint_bottom.html"; $nlfile = "$html_dir/$subdir/nlbox.html"; $splash_top = "/u/newsletters/$subdir/splash_top.html"; $splash_bottom = "/u/newsletters/$subdir/splash_bottom.html"; $login_page = "/u/newsletters/$subdir/login.html"; $error_page = "/u/newsletters/$subdir/error.html"; } else { $thanks_page = "/u/newsletters/thankyou.html"; $confirm_page = "/u/newsletters/confirm.html"; $exclude_conf_page = "/u/newsletters/exclude_conf.html"; $mainfile1 = "/u/newsletters/maint_top.html"; $mainfile2 = "/u/newsletters/maint_bottom.html"; $nlfile = "$html_dir/nlbox.html"; $splash_top = "/u/newsletters/splash_top.html"; $splash_bottom = "/u/newsletters/splash_bottom.html"; $login_page = "/u/newsletters/login.html"; $error_page = "/u/newsletters/error.html"; } # This config file contains the newsletter IDs and event codes of any newsletters that we are # giving points for subscribing to. if ($this_arena == 1) { open(CFG, "$html_dir/newsletter_pts.cfg"); while () { next if (/^\#/); # skip commented lines chomp; my ($id, $ev) = split(/\|/); $events{$id} = $ev; } } print LOG "CGI parms:\n" if ($debug eq "Y"); foreach $in ($form->param()) { print LOG "name = $in, value = " . $form->param($in) . "\n" if ($debug eq "Y"); if ($in =~ /^nlname/) { $id = $in; $id =~ s/nlname//; $nlnames{$id} = $form->param($in); print LOG "nlnames{$id} = $nlnames{$id}\n" if ($debug eq "Y"); } elsif ($in =~ /^nlfreq/) { $id = $in; $id =~ s/nlfreq//; $frequencies{$id} = $form->param($in); print LOG "frequencies{$id} = $frequencies{$id}\n" if ($debug eq "Y"); } else { ${$in} = $form->param($in); } # These personalization fields may or may not be in the HTML form. If any of them are, check to see if a value # was filled into the form for that field. If not, exit with an error. if ($in =~ /^(firstname|lastname|addr[12]|city|state|zip|country|phone|sac?_misc_char[123]|sac?_misc_number[123]|sac?_misc_date[123]|session_id|gender|fax|company|title|salary)$/ && !$form->param($in)) { &printError("We are missing some fields to complete your subscription. Please use your \"BACK\" button to finish filling out the form."); } print LOG "$in = ${$in}\n" if ($debug eq "Y"); } $esc_email = escape_bad_chars($email); # Optional params. Escape 'em so they don't mess with the worker function. $firstname = &escape_bad_chars($firstname) if ($firstname); $lastname = &escape_bad_chars($lastname) if ($lastname); $addr1 = &escape_bad_chars($addr1) if ($addr1); $addr2 = &escape_bad_chars($addr2) if ($addr2); $city = &escape_bad_chars($city) if ($city); $state = &escape_bad_chars($state) if ($state); $zip = &escape_bad_chars($zip) if ($zip); $country = &escape_bad_chars($country) if ($country); $phone = &escape_bad_chars($phone) if ($phone); $sa_misc_char1 = &escape_bad_chars($sa_misc_char1) if ($sa_misc_char1); $sa_misc_char2 = &escape_bad_chars($sa_misc_char2) if ($sa_misc_char2); $sa_misc_char3 = &escape_bad_chars($sa_misc_char3) if ($sa_misc_char3); $sa_misc_number1 = &escape_bad_chars($sa_misc_number1) if ($sa_misc_number1); $sa_misc_number2 = &escape_bad_chars($sa_misc_number2) if ($sa_misc_number2); $sa_misc_number3 = &escape_bad_chars($sa_misc_number3) if ($sa_misc_number3); $sa_misc_date1 = &escape_bad_chars($sa_misc_date1) if ($sa_misc_date1); $sa_misc_date2 = &escape_bad_chars($sa_misc_date2) if ($sa_misc_date2); $sa_misc_date3 = &escape_bad_chars($sa_misc_date3) if ($sa_misc_date3); $session_id = &escape_bad_chars($session_id) if ($session_id); $gender = &escape_bad_chars($gender) if ($gender); $fax = &escape_bad_chars($fax) if ($fax); $company = &escape_bad_chars($company) if ($company); $title = &escape_bad_chars($title) if ($title); $salary = &escape_bad_chars($salary) if ($salary); $sac_misc_char1 = &escape_bad_chars($sac_misc_char1) if ($sac_misc_char1); $sac_misc_char2 = &escape_bad_chars($sac_misc_char2) if ($sac_misc_char2); $sac_misc_char3 = &escape_bad_chars($sac_misc_char3) if ($sac_misc_char3); $sac_misc_number1 = &escape_bad_chars($sac_misc_number1) if ($sac_misc_number1); $sac_misc_number2 = &escape_bad_chars($sac_misc_number2) if ($sac_misc_number2); $sac_misc_number3 = &escape_bad_chars($sac_misc_number3) if ($sac_misc_number3); $sac_misc_date1 = &escape_bad_chars($sac_misc_date1) if ($sac_misc_date1); $sac_misc_date2 = &escape_bad_chars($sac_misc_date2) if ($sac_misc_date2); $sac_misc_date3 = &escape_bad_chars($sac_misc_date3) if ($sac_misc_date3); $date = `date`; print LOG "$date\n" if ($debug eq "Y"); #### # Staging or Production Database? #### $system=`uname -n`; chop $system; if ($system ne "stage1") { $system = "www"; } local $returnurl; $email =~ tr/A-Z/a-z/; local $email2 = $email; if ($action eq "show_login") { $msg = ""; print $form->header; &process_http_file($login_page, \&print_line, 0); exit; } if (!$referer) { if ($ENV{HTTP_REFERER}) { $referer = $ENV{HTTP_REFERER}; } else { $referer = "http://$sysinfo[7]"; } } $returnurl = $referer; #$SearchType = $ENV{PATH_INFO}; local $mode; local $nextaction; $action=$a; print LOG "email=$email, action is $action,a=$a\n" if ($debug eq "Y"); # If an e-mail address was provided on the form, we're in one of the maintenance pages. if ($email) { # The cancel_remove param will be set if the has previously been on the exclude list, tried to # subscribe to one or more newsletters, got the confirmation page asking if they want to be # removed from the exclude list, and hit "Cancel" (meaning don't remove me from the excludes). # In this case we just throw them back to the splash page. if ($cancel_remove) { $mode = "splash"; &ShowNewsletters; } # If action = "login", this means they just came through the login screen where they typed in their # e-mail address because they already have newsletter subscriptions. elsif ($action eq "login" || !$action) { $email = trim_ws($email); if ($email !~ /^([\w\-\.\+]+)\@([\w\-]+)\.([\w\-\.]+)$/) { &printNotFoundMsg; #&printError("The email address you entered is not valid."); } # Call worker to see if this email is in the sess_addr table. $ret = `$prog_dir/newsletters -c "$email"`; chomp($ret); @fields = split(":,:", $ret); $sa_email = $fields[2]; if ($fields[0] ne "0") { &printError("We are currently updating our database. Please try again a little later."); } if ($sa_email eq "0") { &printNotFoundMsg; exit(); } $nextaction = "doupdates"; &ShowNewsletters; } # New subscription. elsif ($action eq "subscribe") { $ect = 0; # If they came in on the splash page, check to see if they have existing subscriptions. $ret = `$prog_dir/newsletters -c "$email"`; chomp($ret); @fields = split(":,:", $ret); $ect = $fields[2]; if ($fields[0] ne "0") { &printError("We are currently updating our database. Please try again a little later."); } # If they have existing subscriptions, note this fact in the mode value. If we # don't do this, they will be unsubbed from anything they were subscribed to before. # This would be Bad. $mode = ($ect > 0 ? "subscribe_existing" : "subscribe"); &DoUpdates; } elsif ($action eq "doupdates") { $mode = "update"; print LOG "calling sub DoUpdates\n" if ($debug eq "Y"); &DoUpdates; } elsif ($action eq "remove" ) { print LOG "Calling spam_me_not\n" if ($debug eq "Y"); &spam_me_not; } # The "subconf" action is a result of hitting "OK" on the page that says, "You're in # the exclude list, click OK to get off and subscribe to these newsletters." elsif ($action eq "subconf" ) { print LOG "subscribe - confirmed remove from exclude list\n" if ($debug eq "Y"); $mode = "subscribe_remove"; &DoUpdates; } else # this one will execute after they fill in their address on the login screen { print LOG "action=$action" if ($debug eq "Y"); $nextaction = "doupdates"; &ShowNewsletters; } } else # no e-mail address, so put up the splash page { $mode = "splash"; &ShowNewsletters; } $date = `date`; print LOG "ended at $date\n" if ($debug eq "Y"); exit 0; ###################################################################### sub ShowNewsletters ###################################################################### { print LOG "======= sub ShowNewsletters; mode=$mode\n" if ($debug eq "Y"); # Print the list of currently active newsletters, and for each, check if this email address is subscribed. # Don't want to check the e-mail address if this is the splash page, since there is no e-mail # address on that page. if ($mode ne "splash") { $hiddenemail = $email; $email = trim_ws($email); if ($email !~ /^([\w\-\.]+)\@([\w\-]+)\.([\w\-\.]+)$/) { &printError("The email address you entered is not valid."); } if (length($email) > 64) { &printError("A valid email address field may not exceed 64 characters in length."); } } my $text; local $dispemail=$email; # Decide which newsletter worker call to use based on whether we're on the splash or the # maintenance page. if ($mode ne "splash") { if ($subdir) { print LOG "calling newsletters -l $this_arena_letter $email $subdir\n" if ($debug eq "Y"); # Call worker to get list of data to display. @retlines = `$prog_dir/newsletters -l $this_arena_letter "$email" $subdir`; } else { print LOG "calling newsletters -l $this_arena_letter $email\n" if ($debug eq "Y"); @retlines = `$prog_dir/newsletters -l $this_arena_letter "$email"`; } } else { $mainfile1 = $splash_top; $mainfile2 = $splash_bottom; # The splash page has different HTML files. if ($subdir) { print LOG "calling newsletters -l $this_arena_letter \"\" $subdir\n" if ($debug eq "Y"); @retlines = `$prog_dir/newsletters -l $this_arena_letter "" $subdir`; } else { print LOG "calling newsletters -l $this_arena_letter\n" if ($debug eq "Y"); @retlines = `$prog_dir/newsletters -l $this_arena_letter`; } } print LOG "@retlines\n" if ($debug eq "Y"); @test_fields = split(":,:", $retlines[0]); if ($test_fields[0] ne "0") { &printError("We are currently updating our database. Please try again a little later."); } my $selected = ""; my $version = ""; my $html = "CHECKED"; $text = ""; # mainfile1 contains the top of the newsletter page -- everything up to the point where the # newsletter listing begins. print "Content-type: text/html\n\n" if (!$notfound); &process_http_file($mainfile1, \&print_line, 0); # Loop through worker results, creating arrays of all the fields. for ($i = 0; $i <= $#retlines; $i++) { chomp($retlines[$i]); print LOG "worker returned: $retlines[$i]\n" if ($debug eq "Y"); ($status, $sc_id, $sc_name, $format, $epub, $image, $description, $version, $disp_order, $freq, $subscribed) = split(":,:", $retlines[$i]); print LOG "sc_id=$sc_id, version is $version\n" if ($debug eq "Y"); # If the query returned a subscribed status of 1 for this newsletter, check the main newsletter box. if ($subscribed == 1) { $selected = "CHECKED"; } else { $selected = ""; } # print the newsletter entry. &process_nl($sc_id,$sc_name,$html,$text,$selected,$format,$epub,$image,$description,$version,$freq); if ($selected) { $nlchoices .= "," if ($nlchoices); $nlchoices .= "$sc_id=$version"; } $image=""; $description=""; } # mainfile2 is the bottom of the newsletters page -- the stuff after the newsletter listing. &process_http_file($mainfile2, \&print_line, 0); } ################################################################################## sub DoUpdates ################################################################################## # # Process the user's subscription/unsubscription choices. Save their previous # selections so that a confirmation email can be sent informing the user # of the changes. # ################################################################################## { my %old_choices=(); my $was_inexcludelist="n"; @ret = `/html/u/rewards/contests/register/get_email -all "$email"`; $max_mod = ""; foreach $r (@ret) { print LOG "r = $r" if ($debug); chomp($r); ($status, $ccode, $login_id) = split(":,:", $r); print LOG "found login: $login_id\n" if ($debug); $ret = `/html/u/rewards/contests/register/get_info "$login_id"`; @mi_fields = split(":,:", $ret); $mdate = $mi_fields[14]; $mdate = substr($mdate, 6, 4) . substr($mdate, 0, 2) . substr($mdate, 3, 2); if ($mdate > $max_mod) { $max_mod = $mdate; $max_login = $login_id; } } $login_id = $max_login; $mi_id = ""; if ($login_id) { $ret = `/html/u/rewards/register/globe/get_globe $login_id`; ($status, $mi_id, $junk, $junk2) = split(":,:", $ret); } print LOG "sub DoUpdates, mode=$mode, email=$email, mi_id=$mi_id, email22=$email22, referer=$referer, returnurl=$returnurl\n" if ($debug eq "Y"); if (defined($email22)) { $email22 =~ tr/A-Z/a-z/; if ($email22 eq $email) { print LOG "email22 is equal to email\n" if ($debug eq "Y"); } else { &printError("The email address and the confirming email that you entered do not match."); } } $email = trim_ws($email); if ($email !~ /^([\w\-\.]+)\@([\w\-]+)\.([\w\-\.]+)$/) { &printError("The email address you entered is not valid."); } # Check if this email is in the exclude list. print LOG "checking exclude_list for email = $email\n" if ($debug eq "Y"); local $exclude_list; $ret = `$prog_dir/newsletters -x "$email"`; chomp($ret); ($exc_status, $junk, $exc_arena) = split(":,:", $ret); $was_inexcludelist = "Y" if ($exc_status eq "0"); print LOG "was_inexcludelist=$was_inexcludelist\n" if ($debug eq "Y"); if ($mode ne "subscribe_remove") { if ($was_inexcludelist eq 'Y' && ($exc_arena == $this_arena || $exc_arena == 0)) { $exclude_list = 'Y'; # If they're in the exclude list, save all their newsletter ID and version choices as hidden # input fields on the confirmation page. foreach $item ($form->param()) { next if ($item !~ /^nlid/); if ($form->param($item)) { $id = $item; $id =~ s/nlid//; $nlchoices .= "\n"; $v = "ver$id"; $vval = $form->param($v); $nlvers .= "\n"; $n = "nlname$id"; $nln = $nlnames{$id}; $nlnames .= "\n"; $f = "nlfreq$id"; $fr = $frequencies{$id}; $freqs .= "\n"; } } print LOG "exclude_list= $exclude_list\n" if ($debug eq "Y"); # Display confirmation page if they're on the exclude list. $message = "Thank you for your request. Our records show that you have previously asked not to receive any email communication from $site_name. In order for us to fulfill your subscription request, please confirm that you do want to receive email from $site_name. $site_name takes your privacy seriously. To learn more about $site_name's use of personal information, please read our Privacy Statement."; print "Content-type: text/html\n\n"; &process_http_file($confirm_page, \&print_line, 0); exit; } } else { # If they were in the exclude list for this arena, delete them. if ($was_inexcludelist && $exc_arena == $this_arena) { $ret = `$prog_dir/newsletters -d "$email"`; chomp($ret); @fields = split(":,:", $ret); if ($fields[0] ne "0") { &printError("We are currently updating our database. Please try again a little later."); } } # If they were in "both" exclude lists (SPLN and Vegas), update their record so they're # only on the Vegas exclude list. elsif ($was_inexcludelist && $exc_arena == 0) { $ret = `$html_dir/newsletters -ux "$email" $other_arena_letter`; chomp($ret); @fields = split(":,:", $ret); if ($fields[0] ne "0" && $fields[0] ne "-1") { &printError("We are currently updating our database. Please try again a little later."); } } } # Find the person's previous subscriptions. Store in hash old_choices. # Old subscription choices are passed in from the maintenance form. if ($mode eq "update" || $mode eq "subscribe_existing") { print LOG "mode is $mode, saving prev subs\n" if ($debug eq "Y"); # The form param old_nlchoices contains the IDs and versions of all newsletters the person # was previously subscribed to, in the form "nlid1=v1,nlid2=v2,..." # Example: "58=H,52=T,51=H" @oc = split(",", $old_nlchoices); # split on comma foreach $n (@oc) { ($nid, $v) = split("=", $n); # each value is an x=y pair $old_choices{$nid} = $nlnames{$nid}; } } else { print LOG "mode is subscribe, not saving prev subs\n" if ($debug eq "Y"); } my %currchoices; print "Content-type: text/html\n\n"; # Find all newsletter IDs they're subscribing to. # Subscribe them, and populate hash currchoices with the appropriate info. foreach $param ($form->param()) { print LOG "Looking for subs, param=$param, ${$param}\n" if ($debug eq "Y"); next if ($param !~ /^nlid/); $id = $param; $id =~ s/^nlid//; local $version; print LOG "-----> id is $id\n" if ($debug eq "Y"); my $verchoice = "ver" . $id; print LOG "verchoice=$verchoice\n" if ($debug eq "Y"); print LOG "looking for version, param is $param\n" if ($debug eq "Y"); $version = $form->param($verchoice); # get corresponding version print LOG "setting version to $version\n" if ($debug eq "Y"); print LOG "calling sub subscribe with id=$id\n" if ($debug eq "Y"); &subscribe($id); $currchoices{$id} = $nlnames{$id}; print LOG "currchoices{$id} = $currchoices{$id}\n" if ($debug eq "Y"); } # Unsubscribes if ($mode eq "update") { # For each newsletter in the old_choices hash, if it's not in currchoices, unsubscribe. while (($scid,$scname) = each %old_choices) { print LOG "Looking for unsubs, scid=$scid, scname=$scname\n" if ($debug eq "Y"); unless (exists $currchoices{$scid}) { &unsubscribe($scid); $unsubs{$scid} = $scname; } } } my $text; local $webtext; my $changecount = 0; my $subcount = 0; my $unsubcount = 0; my $frequency; if ($this_arena == 1) { # For giving Rewards points for subscribing. Get session ID and SportsLine cookies, and get the # email address for this person's user ID from the database. If the database email address and the # one they entered for this script do not match, they will not receive points. $sess_id = $form->cookie('SessionID'); %spl = $form->cookie('SportsLine'); $info = `$sysinfo[2]/get_info $spl{'userid'}`; @mid = split(":,:", $info); $db_email = $mid[4]; } print LOG "determining changes...\n" if ($debug eq "Y"); if ($subdir && -e "$html_dir/$subdir/letter.txt") { open(LETTER, "$html_dir/$subdir/letter.txt"); while ($line = ) { $text .= $line; } close(LETTER); $has_letter_file = 1; } $sub_text = ""; while (($scid,$scname) = each %currchoices) { print LOG "$scid=$scname\n" if ($debug eq "Y"); # If this new choice is not in the old_choices hash, include it in the mail. if (!exists($old_choices{$scid})) { if ($subcount == 0 && !$has_letter_file) { $text = "Dear $site_name Subscriber:\n\nThank you for subscribing! You are subscribed as $email. This confirms your subscription to the following Newsletter(s):\n\n"; } elsif ($subcount == 0 && $has_letter_file) { $sub_text = "This confirms your subscription to the following newsletter(s):\n\n"; } $subcount++; $frequency = $frequencies{$scid}; $frequency = "occasionally" if (!$frequency); $pname = $scname; $pname .= " Newsletter" if ($pname !~ / Newsletter/); if (!$has_letter_file) { $text = $text . "$pname will be sent to your mailbox $frequency\n"; } else { $sub_text .= " $pname will be sent to your mailbox $frequency\n"; } $webtext = $webtext . " You subscribed to the $pname\n"; $changecount++; # If this newsletter was in the config file of newsletters to give points for, and if # we have valid cookie info for this person, give points. if ($this_arena == 1 && $sess_id && $spl{'userid'} && $spl{'club'} eq "yes" && $events{$scid} && $email eq $db_email) { &give_points($sess_id, $events{$scid}); } } } if ($has_letter_file) { $text =~ s/X_SUBNEWS_X/$sub_text/; } if ($mode eq "update") { while (($scid,$scname) = each %unsubs) { if ($unsubcount ==0) { if ($subcount == 0 && !$has_letter_file) { $text = "Dear $site_name Subscriber:\n" } if (!$has_letter_file) { $text = $text . "\nThis confirms that you cancelled your subscription to the following Newsletter(s) sent to $email:\n"; } else { $unsub_text = "This confirms that you cancelled your subscription to the following\nnewsletter(s) sent to $email:\n\n"; } } $pname = $scname; $pname .= " Newsletter" if ($pname !~ / Newsletter/); if (!$has_letter_file) { $text = $text . " $pname\n"; } else { $unsub_text .= " $pname\n"; } $webtext = $webtext . " You unsubscribed from the $pname\n"; $changecount++; $unsubcount++; } } if ($has_letter_file) { $text =~ s/X_UNSUBNEWS_X/$unsub_text/; $text =~ s/X_EMAIL_X/$email2/g; } if ($changecount != 0) { print LOG "sending a confirmation email to $email2\n" if ($debug eq "Y"); $text = $text . "\n\nIf our information is incorrect or you wish to add/delete subscriptions or change your E-mail address, go to:\nhttp://$sysinfo[7]/$nl_prog_dir/newsletter.cgi?email=" . $email2 . "&subdir=$subdir\nWe appreciate your interest in $site_name and look forward to providing you with the best the Internet and the world of sports have to offer.\nBest regards,\n\n$site_name\n" if (!$has_letter_file); open (SENDMAIL, "| /usr/lib/sendmail -t -n"); if (!$has_letter_file) { print SENDMAIL < To:$email2 Subject: $site_name2 Newsletters $text End_of_Mail } else { print SENDMAIL "$text"; } close SENDMAIL; } $webtext =~ s/\n/
/g; $webtext = "No changes were made.
\n" if (($changecount == 0) && ($formatchanges == 0)); $msg = $webtext; print LOG "printing thanks page\n" if ($debug eq "Y"); &process_http_file($thanks_page, \&print_line, 0); } ################################################################################## sub unsubscribe ################################################################################## { my $nlid = shift(@_); print LOG "$prog_dir/newsletters -u $esc_email $nlid\n" if ($debug eq "Y"); $return = `$prog_dir/newsletters -u $esc_email $nlid`; print LOG "return from newsletters program is $return\n" if ($debug eq "Y"); chomp($return); @fields = split(":,:", $return); &printError("There was an error unsubscribing you from the newsletter. Please try again a little later.") if ($fields[0] ne "0"); } ################################################################################## sub subscribe ################################################################################## { my $nlid = @_; print LOG "===================== sub subscribe, email = $esc_email,id=$id,version=$version\n" if ($debug eq "Y"); if ($version ne 'txt' && $version ne 'Y' && $version ne "T") { $version = 'H'; } print LOG "$prog_dir/newsletters -s $esc_email $id $version \"$mi_id\" \"$firstname\" \"$lastname\" \"$addr1\" \"$addr2\" \"$city\" \"$state\" \"$zip\" \"$country\" \"$phone\" \"$sa_misc_char1\" \"$sa_misc_char2\" \"$sa_misc_char3\" \"$sa_misc_number1\" \"$sa_misc_number2\" \"$sa_misc_number3\" \"$sa_misc_date1\" \"$sa_misc_date2\" \"$sa_misc_date3\" \"$session_id\" \"$gender\" \"$fax\" \"$company\" \"$title\" \"$salary\" \"$sac_misc_char1\" \"$sac_misc_char2\" \"$sac_misc_char3\" \"$sac_misc_number1\" \"$sac_misc_number2\" \"$sac_misc_number3\" \"$sac_misc_date1\" \"$sac_misc_date2\" \"$sac_misc_date3\"" if ($debug eq "Y"); $return = `$prog_dir/newsletters -s $esc_email $id $version "$mi_id" "$firstname" "$lastname" "$addr1" "$addr2" "$city" "$state" "$zip" "$country" "$phone" "$sa_misc_char1" "$sa_misc_char2" "$sa_misc_char3" "$sa_misc_number1" "$sa_misc_number2" "$sa_misc_number3" "$sa_misc_date1" "$sa_misc_date2" "$sa_misc_date3" "$session_id" "$gender" "$fax" "$company" "$title" "$salary" "$sac_misc_char1" "$sac_misc_char2" "$sac_misc_char3" "$sac_misc_number1" "$sac_misc_number2" "$sac_misc_number3" "$sac_misc_date1" "$sac_misc_date2" "$sac_misc_date3"`; chomp($return); @fields = split(":,:", $return); if ($fields[0] ne "0") { &printError("There was an error subscribing you to the newsletter. Pleas try again a little later."); } else {print LOG "return from newsletters:\n$return\n" if ($debug eq "Y");} print LOG "==================================\n\n" if ($debug eq "Y"); } ################################################################################## sub printError ################################################################################## { $msg = shift(@_); print "Content-type: text/html\n\n"; &process_http_file($error_page, \&print_line, 0); exit; } ################################################################################## sub process_nl ################################################################################## { # Read the template file for the given newsletter, and substitute # the variables. ($sc_id, $sc_name, $html, $text, $selected, $format, $epub, $image, $description, $version, $freq) = @_; $nl_name = "nlname$sc_id"; $nl_freq = "nlfreq$sc_id"; print LOG "writing NL $sc_id, version = $version, epub = $epub to $nlfile\n" if ($debug eq "Y"); $image = "http://$sysinfo[13]$image" if ($image && $image !~ /^http/); open (NL, $nlfile) or die "Cannot open $nlfile"; while ($input_line = ) { $input_line =~ s/X_NLID_X/$sc_id/g; $input_line =~ s/X_SCNAME_X/$sc_name/g; $input_line =~ s/X_NLNAME_X/$nl_name/; $input_line =~ s/X_NLFREQ_X/$nl_freq/; $input_line =~ s/X_NLFREQVAL_X/$freq/; ## Don't draw a html radio button if the newsletter is text only, and select the text one if ($input_line =~ /X_HTMLCHECKED_X/) { if ($format eq "TEXT") { $text = "CHECKED"; $input_line =~ s/radio/hidden/; next; } elsif ($format eq "HTML") { $input_line =~ s/radio/hidden/; $input_line =~ s/>HTMLHTML OnlyTextText Only/; } else { $input_line =~ s/X_IMAGE_X/$sc_name/; } if ($description) { $input_line =~ s/X_DESC_X/$description/; } else { $input_line =~ s/X_DESC_X//; } print $input_line; } close(NL); } sub print_line { my $printcntl = 'n'; my $line = $_[0]; if($line=~/\$_/) { $printcntl = 'y' if ($line =~ /errmessage/); while($line=~m/\$_/g) { $var = pos $line; pos $line = $var + 1; $line=~m/[^0-9_A-Za-z]/g; $end_word = pos $line; $word = substr $line, $var, ($end_word-$var-1) ; $line=~s/\$_$word/${$word}/; pos $line = $var-1; } } $printcntl = 'n' if ($printcntl == 'y'); print $line . "\n"; } sub trim_ws { my $var = shift @_; $var =~ s/\s+/ /g; $var =~ s/^\s//; $var =~ s/\s$//; return $var; } sub printNotFoundMsg { print LOG "sub printNotFoundMsg, login=$login_page\n" if ($debug eq "Y"); print "Content-type: text/html\n\n"; $msg = "Sorry, there are no subscriptions matching the following address: $email.

Please re-enter your email address or click here if you are a new subscriber."; $email = ""; &process_http_file($login_page, \&print_line, 0); exit; } sub spam_me_not { my $exclude_list_email; $rowcount = 0; print LOG "calling $prog_dir/newsletters -x $esc_email\n" if ($debug eq "Y"); # Find if they're already in the exclude list. $ret = `$prog_dir/newsletters -x $esc_email`; chomp($ret); print LOG "returns: $ret\n" if ($debug eq "Y"); ($exc_status, $junk, $exc_arena) = split(":,:", $ret); $exists = ($exc_status eq "0" ? 1 : 0); # If exc_arena is 0, they're on all exclude lists, 1 is SportsLine, 2 is Vegas. # So if they're on all exclude lists or the SportsLine one, we don't need to do anything. if ($exists && ($exc_arena == 0 || $exc_arena == $this_arena)) { print LOG "sub spam_me_not, but $email was already in the exclude_list ( rowcount=$rowcount )\n" if ($debug eq "Y"); } elsif (!$exists) # They're not in there at all, so put 'em on the one for this arena. { print LOG "calling $prog_dir/newsletters -ax $esc_email $this_arena_letter\n" if ($debug eq "Y"); $ret = `$prog_dir/newsletters -ax $esc_email $this_arena_letter`; chomp($ret); print LOG "returns: $ret\n" if ($debug eq "Y"); @fields = split(":,:", $ret); if ($fields[0] ne "0") { &printError("We are currently updating our database. Please try again a little later."); } } elsif ($exists && $exc_arena != $this_arena) # They're in there but not under this arena, so update the record and set to 0 (all). { print LOG "calling $prog_dir/newsletters -ux $esc_email B\n" if ($debug eq "Y"); $ret = `$prog_dir/newsletters -ux $esc_email B`; chomp($ret); @fields = split(":,:", $ret); print LOG "returns: $ret\n" if ($debug eq "Y"); if ($fields[0] ne "0") { &printError("We are currently updating our database. Please try again a little later."); } } # Now unsubscribe user to all Newsletters. $ret = `$prog_dir/newsletters -u $esc_email $this_arena_letter`; chomp($ret); @fields = split(":,:", $ret); if ($fields[0] ne "0") { &printError("We are currently updating our database. Please try again a little later."); } print "Content-type: text/html\n\n"; &process_http_file($exclude_conf_page, \&print_line, 0); }