#!/usr/bin/perl -w use My_Ver_1_01::NewsLetter_Tracking_Const; use Data::Dumper; use DBI; use Crypt::Tea_promoonly; require "/big/www/docs/perl_subs/parsform.pl"; &parse_form; #QUERY_STRING format,standard,ID=sdfdsf&WEBURL=sdfdsf&abc=xyz,we only support ID and WEBURL now, capts letter sensitive,both TEA encrypted no define V4_NEWSLETTER_DB_HOST; no define V4_NEWSLETTER_DB_NAME; no define V4_NEWSLETTER_DB_USER; no define V4_NEWSLETTER_DB_PASSWORD; no define SECRET_KEY; if(0){ print "Content-type:text/html\r\n\r\n"; print ''; print ''; print 'Hello Word - First CGI Program'; print ''; print ''; #print Dumper(%ENV); print Dumper(%FORM); print ''; print ''; die; } if (1) { if($FORM{WEBURL}){ my $key = SECRET_KEY; setupTea($key); my $htmlfilename=&decrypt(&hex2text($FORM{WEBURL})); my $filename = $ENV{'DOCUMENT_ROOT'} . '/newsletter/' . $htmlfilename; if (-e $filename) { my $length = -s $filename; print "Content-type: text/html\r\n\r\n"; # print "Content-length: $length \n\n"; binmode STDOUT; open (FH,'<', $filename) || die "Could not open $filename: $!"; my $buffer = ""; while (read(FH, $buffer, 10240)) { print $buffer; } close FH; if($FORM{ID}){ my $key = SECRET_KEY; setupTea($key); my $nl_id=&decrypt(&hex2text($FORM{ID})); if ($nl_id>0){ my $sql="select NewsLetter_ID from newsletteremail where ID=$nl_id"; my $newsletter_id=selectonerow($sql); $sql = " select Recipient_ID from newsletteremail where ID=$nl_id "; my $recipient_id=selectonerow($sql); $sql = "select master_id from mpe_v2.useremails where user_id=$recipient_id and authorized=1"; my $master_id=selectonerow($sql); $sql = "select group_concat(user_id) from mpe_v2.useremails where master_id=$master_id and authorized=1"; my $recipient_ids = selectonerow($sql); ## Connect to database my $dbh = DBI->connect("DBI:mysql:" . V4_NEWSLETTER_DB_NAME . ";" . V4_NEWSLETTER_DB_HOST, V4_NEWSLETTER_DB_USER, V4_NEWSLETTER_DB_PASSWORD) or die "Unable to connect to DB $DBI::errstr)\n"; my $updatesql = "update newsletteremail set EmailReadDate=date_add(now(),interval 3 hour),EmailReadBySubscriber=EmailReadBySubscriber+1 where NewsLetter_ID='$newsletter_id' and Recipient_ID IN ( $recipient_id)"; # print $updatesql . "\n";die; my $sth = $dbh->prepare($updatesql) or die "Couldn't prepare $updatesql at " . __FILE__ . ":" . __LINE__ . "\n"; $sth->execute() or die "Couldn't execute $updatesql at " . __FILE__ . ":" . __LINE__ . "\n"; if ( $sth->rows == 0) { die "No record updated: $updatesql at " . __FILE__ . ":" . __LINE__ . "\n"; } if ( $sth->rows > 0 ) { #should be good } } } } else {die "$filename can not be found\n"} } sub selectonerow { my ($select_sql) = @_; my $ret; #printf("$select_sql\n");die; my $dbha = DBI->connect("DBI:mysql:" . V4_NEWSLETTER_DB_NAME . ";" . V4_NEWSLETTER_DB_HOST, V4_NEWSLETTER_DB_USER, V4_NEWSLETTER_DB_PASSWORD) or die "Unable to connect to DB ($DBI::errstr)\n"; my $select_sql_sth = $dbha->prepare($select_sql) or dbfail("Could not prepare statement", $select_sql); $select_sql_sth->execute or dbfail("Could not execute statement", $select_sql); if (my @result = $select_sql_sth->fetchrow) { $ret = $result[0]; } $select_sql_sth->finish(); $dbha->disconnect(); return $ret; } sub dbfail { my $msg = $_[0]; my $sql = $_[1]; my $errMsg = sprintf "WARNING: [%s] DB Error in script %s. SQL [%s]. Error [%s]\n", $ENV{'REMOTE_ADDR'}, $0, $sql, $DBI::errstr; warn "$errMsg"; # $error = 1; # $errorStr = "Database Error"; } }