Gossamer Forum
Home : Products : Gossamer Links : Discussions :

recommend_it script for user table

Quote Reply
recommend_it script for user table
hello
I want to use Pugdog's reccomend_it script to count mail from visitors to users.
I modified the neccesary tables & fields, but I get an Internal Server Error.
There is something wrong in the syntax code.

Who can check this & correct it.

The code is:
-----------------------------------------------------------------------------------------------------

#!/usr/local/bin/perl
# ==================================================================
# Links SQL - enhanced directory management system
#
# Website : http://gossamer-threads.com/
# Support : http://gossamer-threads.com/scripts/support/
# Revision : $Id: add.cgi,v 1.20 2000/12/22 23:24:13 alex Exp $
#
# Copyright (c) 2000 Gossamer Threads Inc. All Rights Reserved.
# Redistribution in part or in whole strictly prohibited. Please
# see LICENSE file for full details.
# ==================================================================

# Load required modules.
# -------------------------------------------------------------------
use strict;
use lib '/home/ridesworld/www/cgi-bin/links/admin';
use Links qw/$DB $IN $USER $CFG/;
use Links::SiteHTML;
use Links::Authenticate;
use GT::Mail;

# -------------------------------------------------------------------

my $SCRIPT_NAME = $CFG->{db_cgi_url} . "/usermail.cgi";

my $SITE_NAME = 'Ericho';

my $SITE_URL = 'http://www.yourhost.com';

my $MAXNUM = 1;

my $count_recs = 1;

&main();

sub main {
# -------------------------------------------------------------------
my ($user, $contactname, $contactemail, $user_db, $rec);

# Get the Links ID number from the input.
$user = $IN->param('Username');
$contactname = $IN->param('Contact_Name');
$contactemail = $IN->param('Contact_Email');

## check to see if an ID was submitted and that it was numeric
if (!(defined $user) or !($user =~ /^\d+$/)) {
print $IN->header();
print Links::SiteHTML::display('sendlinkowner', { error => Links::language('SEND_RECIEPIENT', $user) });
return;
}

## Check to see if the ID/Link record exists

$user_db = $DB->table('Users');

$rec = $user_db->get ($user);

if (! $rec) {
print $IN->header();
print Links::SiteHTML::display('sendlinkowner', { error => Links::language('SEND_SENDER', $user) });
return;
}

## add the following constant/variables to the $rec
$rec->{'SCRIPT_NAME'} = $SCRIPT_NAME;
$rec->{'SITE_NAME'} = $SITE_NAME;
$rec->{'SITE_URL'} = $SITE_URL;

$rec->{'MAXNUM'} = $MAXNUM;


# -------------------------------------------------------------------

if ( $ENV{'REQUEST_METHOD'} ne "POST") {

$rec->{'email_list'} = &create_input_block;

print $IN->header();
print Links::SiteHTML::display('sendlinkowner', $rec);
return;
}
else { ## the form was POSTed and we need to process the form data.

## make sure that values were passed in.
if (!$IN->param('recipname_1') or !$IN->param('recipemail_1')) {
$rec->{'email_list'} = &create_input_block;
$rec->{'send_name'} = $IN->param('send_name');
$rec->{'send_email'} = $IN->param('send_email');
print $IN->header();
print Links::SiteHTML::display('sendlinkowner', { error => Links::language('SEND_RECIEPIENT') });
return;
}
if (!$IN->param('send_name') or !$IN->param('send_email')) {
$rec->{'email_list'} = &create_input_block; ### used to place the variable sized list in the template
$rec->{'send_name'} = $IN->param('send_name');
$rec->{'send_email'} = $IN->param('send_email');
print $IN->header();
print Links::SiteHTML::display('sendlinkowner', { error => Links::language('SEND_SENDER') });
return;
}

my $results = &go_mail_go ($rec); ### send $rec to the sub. $IN is a global. Returns list of people successfully sent.

## at this point, the message has been sent.
## update the count in the links database if you are tracking the # of recommendations.
if ($count_recs) {
$db_user->update ({
UserMail => \"UserMail + 1"
},
{
Username => $user
}
);
}

print $IN->header();
print Links::SiteHTML::display('send_success', {%$rec, recip_list => $results, from_name => $IN->param('send_name')});
return;
}
print $IN->header();
print Links::SiteHTML::display('sendlinkowner', { error => Links::language('REC_SOMEHOW') });
return;
}


##################################################################
## this was from the BNB script.... seems to work.
##################################################################
sub valid_address
{
my $testmail = @_;
if ($testmail =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ ||
$testmail !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/)
{
return 0;
}
else
{
return 1;
}
}

sub go_mail_go {
# -------------------------------------------------------------------

my ($rec) = @_;
my $msg = $IN->param('message');
$msg =~ s/\r//g;

## Create the message object instance, check to see mail paths exist - once - and set up for the send loop.
require GT::Mail;
if (!$CFG->{db_smtp_server} and !$CFG->{db_mail_path}) {
print $IN->header();
print Links::SiteHTML::display('sendlinkowner', { error => Links::language('SMTP_ERROR') });
exit; ## mod_perl safe in current perl.
};
$GT::Mail::error ||= ''; # Silence -w

my $recip_list = '';

for (my $i = 1; $i < $MAXNUM + 1; $i++) {

my $recipname = "recipname_$i";
my $recipemail = "recipemail_$i";

if ($IN->param($recipemail) eq "")
{
next;
}

$recip_list .= "<BR>" . $IN->param($recipemail);

my %TAGS = (
to_email => $IN->param($recipemail),
to_name => $IN->param($recipname),
from_email => $IN->param('send_email'),
from_name => $IN->param('send_name'),
subject => "Mail from $SITE_NAME visitor to you",
message => $msg ## $IN->param('message') was verified and validated at first
);

## my $formatted_message = Links::SiteHTML::display('email_send.txt', {%TAGS, %$rec});
my $formatted_message = Links::load_template ('email_send.txt', {%TAGS, %$rec});

GT::Mail->send (
smtp => $CFG->{db_smtp_server},
sendmail => $CFG->{db_mail_path},
to => $IN->param($recipemail),
from => $IN->param('send_email'),
subject => "Web Page Recommendation on POSTCARDS.COM",
reply => $IN->param('send_email'),
msg => $formatted_message,
debug => $Links::DEBUG
) or Links::fatal ("Unable to send mail: $GT::Mail::error");
}


return $recip_list; ## allows post-success handling

} ## end subroutine go_mail_go

sub create_input_block {
my $email_list ='';
my ($rname, $remail);

my $input = $IN->get_hash;

#print $IN->header;
#foreach my $key (keys %$input) {
# print "The Key is --", $key, " The Value is -- ", $input->{$key},"<BR>";
#}

for (my $i = 1; $i < $MAXNUM + 1; $i++) {
my $recipname = "recipname_$i";
my $recipemail = "recipemail_$i";

#print "recipname is : ", $input->{$recipname},"<BR>";
#print "recipemail is : ", $input->{$recipemail},"<BR>";

#($input->{$recipname}) ? $rname = $input->{$recipname} : $rname = '';
#($input->{$recipemail}) ? $remail = $input->{$recipemail} : $remail = '';

#print "My value for $recipname is name: ", $rname, "and for $recipemail is ", $remail, "<BR>";
#print "My value for $recipname is name: ", $input->{$recipname}, "and for $recipemail is ", $input->{$recipemail}, "<BR>";

$email_list .= qq|
<INPUT TYPE="hidden" NAME="recipname_2" VALUE="$input->{$recipname}" SIZE="15"></SPAN></TD>\n
<INPUT TYPE="hidden" NAME="recipemail_2" VALUE="$input->{$recipemail}" SIZE="15"></SPAN></TD>\n
|;
}

#foreach my $key (keys %$input) {
# print "The Key is --", $key, " The Value is -- ", $input->{$key},"<BR>";
#}

return $email_list
}



Quote Reply
Re: recommend_it script for user table In reply to
for starts:

Global symbol "$db_user" requires explicit package name at line 109.

should probably be $user_db

Your error.log is the _best_ place to go.

Barring that, running: perl -c will usually find the syntax errors.

FWIW... 500 internal errors in Links are 90% bad headers.




PUGDOG®
PUGDOG® Enterprises, Inc.
FAQ: http://pugdog.com/FAQ


Quote Reply
Re: recommend_it script for user table In reply to
OK I try this too, but I don't get errors, but it can't stil load the template with the userwhen I open it like:
usermail.cgi?Username=testuser

here is my code:
-----------------------------------------------------------


#!/usr/local/bin/perl
# ==================================================================
# Links SQL - enhanced directory management system
#
# Website : http://gossamer-threads.com/
# Support : http://gossamer-threads.com/scripts/support/
# Revision : $Id: add.cgi,v 1.20 2000/12/22 23:24:13 alex Exp $
#
# Copyright (c) 2000 Gossamer Threads Inc. All Rights Reserved.
# Redistribution in part or in whole strictly prohibited. Please
# see LICENSE file for full details.
# ==================================================================

# Load required modules.
# -------------------------------------------------------------------
use strict;
use lib '/home/ridesworld/www/cgi-bin/links/admin';
use Links qw/$IN $DB $CFG/;
use Links::SiteHTML;
use Links::Authenticate;
use GT::Mail;

# -------------------------------------------------------------------

my $SCRIPT_NAME = $CFG->{db_cgi_url} . "/usermail.cgi";

my $SITE_NAME = 'Ridesworld.com';

my $SITE_URL = 'http://www.ridesworld.com';

my $MAXNUM = 9;

my $count_recs = 1;

&main();

sub main {
# -------------------------------------------------------------------
my ($username, $user_db, $rec);

# Get the Links ID number from the input.
$username = $IN->param('Username');

## check to see if an ID was submitted and that it was numeric
if (!(defined $username) or !($username =~ /^\d+$/)) {
print $IN->header();
print Links::SiteHTML::display('error', { error => Links::language('REC_RECIEPIENT', $username) });
return;
}

## Check to see if the ID/Link record exists

$user_db = $DB->table('Users');

$rec = $user_db->get ($username);

if (! $rec) {
print $IN->header();
print Links::SiteHTML::display('error', { error => Links::language('REC_SENDER', $username) });
return;
}

## add the following constant/variables to the $rec
$rec->{'SCRIPT_NAME'} = $SCRIPT_NAME;
$rec->{'SITE_NAME'} = $SITE_NAME;
$rec->{'SITE_URL'} = $SITE_URL;

$rec->{'MAXNUM'} = $MAXNUM;


# -------------------------------------------------------------------

if ( $ENV{'REQUEST_METHOD'} ne "POST") {

$rec->{'email_list'} = &create_input_block;

print $IN->header();
print Links::SiteHTML::display('usermail', $rec);
return;
}
else { ## the form was POSTed and we need to process the form data.

## make sure that values were passed in.
if (!$IN->param('recipname_1') or !$IN->param('recipemail_1')) {
$rec->{'email_list'} = &create_input_block;
$rec->{'send_name'} = $IN->param('send_name');
$rec->{'send_email'} = $IN->param('send_email');
print $IN->header();
print Links::SiteHTML::display('usermail', { error => Links::language('REC_RECIEPIENT') });
return;
}
if (!$IN->param('send_name') or !$IN->param('send_email')) {
$rec->{'email_list'} = &create_input_block; ### used to place the variable sized list in the template
$rec->{'send_name'} = $IN->param('send_name');
$rec->{'send_email'} = $IN->param('send_email');
print $IN->header();
print Links::SiteHTML::display('usermail', { error => Links::language('REC_SENDER') });
return;
}

my $results = &go_mail_go ($rec); ### send $rec to the sub. $IN is a global. Returns list of people successfully sent.

## at this point, the message has been sent.
## update the count in the links database if you are tracking the # of recommendations.
if ($count_recs) {
$user_db->update ({
UserMail => \"UserMail + 1"
},
{
Username => $username
}
);
}

print $IN->header();
print Links::SiteHTML::display('usermail_success', {%$rec, recip_list => $results, from_name => $IN->param('send_name')});
return;
}
print $IN->header();
print Links::SiteHTML::display('usermail', { error => Links::language('REC_SOMEHOW') });
return;
}


##################################################################
## this was from the BNB script.... seems to work.
##################################################################
sub valid_address
{
my $testmail = @_;
if ($testmail =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ ||
$testmail !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/)
{
return 0;
}
else
{
return 1;
}
}

sub go_mail_go {
# -------------------------------------------------------------------

my ($rec) = @_;
my $msg = $IN->param('message');
$msg =~ s/\r//g;

## Create the message object instance, check to see mail paths exist - once - and set up for the send loop.
require GT::Mail;
if (!$CFG->{db_smtp_server} and !$CFG->{db_mail_path}) {
print $IN->header();
print Links::SiteHTML::display('usermail', { error => Links::language('SMTP_ERROR') });
exit; ## mod_perl safe in current perl.
};
$GT::Mail::error ||= ''; # Silence -w

my $recip_list = '';

for (my $i = 1; $i < $MAXNUM + 1; $i++) {

my $recipname = "recipname_$i";
my $recipemail = "recipemail_$i";

if ($IN->param($recipemail) eq "")
{
next;
}

$recip_list .= "<BR>" . $IN->param($recipemail);

my %TAGS = (
to_email => $IN->param($recipemail),
to_name => $IN->param($recipname),
from_email => $IN->param('send_email'),
from_name => $IN->param('send_name'),
subject => "Web Page Recommendation on $SITE_NAME",
message => $msg ## $IN->param('message') was verified and validated at first
);

## my $formatted_message = Links::SiteHTML::display('usermail_recc.txt', {%TAGS, %$rec});
my $formatted_message = Links::load_template ('usermail_recc.txt', {%TAGS, %$rec});

GT::Mail->send (
smtp => $CFG->{db_smtp_server},
sendmail => $CFG->{db_mail_path},
to => $IN->param($recipemail),
from => $IN->param('send_email'),
subject => "Web Page Recommendation on POSTCARDS.COM",
reply => $IN->param('send_email'),
msg => $formatted_message,
debug => $Links::DEBUG
) or Links::fatal ("Unable to send mail: $GT::Mail::error");
}


return $recip_list; ## allows post-success handling

} ## end subroutine go_mail_go

sub create_input_block {
my $email_list ='';
my ($rname, $remail);

my $input = $IN->get_hash;

#print $IN->header;
#foreach my $key (keys %$input) {
# print "The Key is --", $key, " The Value is -- ", $input->{$key},"<BR>";
#}

for (my $i = 1; $i < $MAXNUM + 1; $i++) {
my $recipname = "recipname_$i";
my $recipemail = "recipemail_$i";

#print "recipname is : ", $input->{$recipname},"<BR>";
#print "recipemail is : ", $input->{$recipemail},"<BR>";

#($input->{$recipname}) ? $rname = $input->{$recipname} : $rname = '';
#($input->{$recipemail}) ? $remail = $input->{$recipemail} : $remail = '';

#print "My value for $recipname is name: ", $rname, "and for $recipemail is ", $remail, "<BR>";
#print "My value for $recipname is name: ", $input->{$recipname}, "and for $recipemail is ", $input->{$recipemail}, "<BR>";

$email_list .= qq|
<TR>\n
<TD CLASS="dateline" WIDTH="60" HEIGHT="50" ALIGN="left" VALIGN="middle" NOWRAP><SPAN CLASS="form"> Friend $i</SPAN></TD>\n
<TD CLASS="dateline" WIDTH="140" HEIGHT="50" ALIGN="left" VALIGN="middle" NOWRAP><SPAN CLASS="form"> <INPUT CLASS="form" TYPE="text" NAME="recipname_$i" VALUE="$input->{$recipname}" SIZE="15"></SPAN></TD>\n
<TD CLASS="dateline" WIDTH="140" HEIGHT="50" ALIGN="left" VALIGN="middle" NOWRAP><SPAN CLASS="form"> <INPUT CLASS="form" TYPE="text" NAME="recipemail_$i" VALUE="$input->{$recipemail}" SIZE="15"></SPAN></TD>\n
</TR>\n
|;
}

#foreach my $key (keys %$input) {
# print "The Key is --", $key, " The Value is -- ", $input->{$key},"<BR>";
#}

return $email_list
}

Quote Reply
Re: recommend_it script for user table In reply to
Do a :

# Get the Links ID number from the input.
$username = $IN->param('Username');
print $IN->header();
print "The username is $username";

and see what you get. Start tracing the program out. I can't run it, because my database doesn't look like yours.

PUGDOG®
PUGDOG® Enterprises, Inc.
FAQ: http://pugdog.com/FAQ


Quote Reply
Re: recommend_it script for user table In reply to
Ok that works, but I get an error template again.
It can't load the usermail.html template
what to do next???

By the way:
when I enter usermail.cgi?Username=testuser
the logout appears in the template...

Quote Reply
Re: recommend_it script for user table In reply to
make sure usermail.html exists.

If it can't find the template, it can't load it.

PUGDOG®
PUGDOG® Enterprises, Inc.
FAQ: http://pugdog.com/FAQ


Quote Reply
Re: recommend_it script for user table In reply to
I am sure uesermail.html exists in my default template directory