#!/usr/local/bin/perl ######## # tvlisting.cgi - get the user's zip code and then pass user over to tv land ######## use CGI; require '/html/u/generic/login_lib.pl'; require '/html/u/generic/cgilib.pl'; #### # get form parameters, if any #### $form = new CGI; foreach $value (@params = $form->param()) { ${$value} = $form->param($value); } #### # if not called from form, then get zip and do redirect if possible #### if (!$sub_action) { $zip = GetZipFromCookie(); if ($zip) { RedirectTV($zip); } #### # if no zip, put up form #### else { DisplayZipForm(); } } #### # else, we are processing form #### else { $zip = GetZipFromForm(); if ($zip) { RedirectTV($zip); } else { $errmsg = "Please enter a 5 digit USA zip
or 6 character Canadian postal code."; DisplayZipForm(); } } exit; #### # get zip from cookie #### sub GetZipFromCookie { my $cookiezip = ""; #### # if tvlistings has been set, we don't need zip for user #### $cookie = $form->cookie('TVListings'); if ($cookie) { $cookiezip = 'TVLIST'; } #### # else try sportsline userid #### else { %cookie = $form->cookie('SportsLine'); if ($cookie{'userid'}) { $user_info_return = &get_user_info($cookie{'userid'}); @user_info = split ':,:', $user_info_return; #### # make sure we got results with a good zip #### if ($user_info[0] eq '0') { #### # starts with 5 digits #### if ($user_info[11] =~ /^\d{5}/) { $cookiezip = substr($user_info[11],0,5); } #### # else look for canada (without spaces) #### else { $user_info[11] =~ s/ //g; if ($user_info[11] =~ /^[A-Z]\d[A-Z]\d[A-Z]\d$/i and $user_info[11] =~ /^[^ZWDFIOQU].[^DFIOQU].[^DFIOQU].$/i) { $cookiezip = $user_info[11]; } } } } } return $cookiezip; } #### # get zip from form #### sub GetZipFromForm { my $formzip = ''; if ($USR_ZIP =~ /^\d{5}$/ or ($USR_ZIP =~ /^[A-Z]\d[A-Z]\d[A-Z]\d$/i and $USR_ZIP =~ /^[^ZWDFIOQU].[^DFIOQU].[^DFIOQU].$/i)) { $formzip = $USR_ZIP; } return $formzip; } #### # display form #### sub DisplayZipForm { print $form->header(); process_http_file("/signup/partners/tvlisting.htm",\&print_line,0); } #### # redirect #### sub RedirectTV { my $zip = shift; #### # send user's zip code, unless there is already 1 set by the tv guys #### my $tag = ($zip eq 'TVLIST') ? "" : "&zipcode=$zip&ziptype=new"; ###print $form->redirect("http://stage1.sportsline.com/signup/partners/tvtest.htm?partner_id=cbs$tag"); print $form->redirect("http://tvlistings.sportsline.com/?partner_id=cbs$tag"); }