Gossamer Forum
Home : Products : Links 2.0 : Customization :

Optionally Email Link Owner When Manually Adding

Quote Reply
Optionally Email Link Owner When Manually Adding
I add a lot of links to my directory manually from the admin panel and I noticed when you manually add a link to the database, no email gets sent to the link owner's email address informing them that their resource was added.

What I was wanting was to add another Yes/No option box which, if the option is set to "yes," will email a message contained in a TXT file letting the owner know that their link was added to the directory. If the option is set to "no," then no email is sent.

Is their a mod for this already?
If not, could somebody help me out with this?

Best Wishes,
Eric J. Griffin


http://www.ActiveWebmaster.com - Webmaster Resources Cool
Quote Reply
Re: Optionally Email Link Owner When Manually Adding In reply to
A start point would be to add this to the form in add.html:

Send email to webmaster?:
<select name="mail"><option>Yes<option>No</select>

Then in add.cgi replace:

# Send the admin an email message notifying of new addition.
&send_email;

With:

# Send the admin an email message notifying of new addition.
if ($in{'mail'} eq "Yes"){
&send_email;
}



You'll also need to change this line:

print VAL &join_encode(%in);

Cause at the moment it would add this mail field to the db.

Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: Optionally Email Link Owner When Manually Adding In reply to
Dear Glennu

I think you misunderstood the question of ActiveWebmaster. He wants to send the link owner (and not the administrator) an email when he manually adds a link through the admin panel.

Now, a quick solution would be,



1) in admin_html.pl go to sub html_add_form and add something like

Code:
my $radio_html;

if ($html_object eq "Link") {$radio_html = qq~
Email link owner: <input type="radio" name="emailowner" value="yes" checked>Yes
<input type="radio" name="emailowner" value="no">No~;}
else
{$radio_html = ""};

before &html_print_headers();

At the end of the same sub add

Code:
$radio_html
just before
Code:
<INPUT TYPE="SUBMIT" NAME ...

2) do the same thing in sub html_add_failure



3) create a sub html_add_email, which can be basically a copy of sub html_validate_email except that you should replace
Code:
my $msg = &load_template ('email-add.txt', \%link);
by something like
Code:
my $msg = &load_template ('email-add-admin.txt', \%link);
Also change the subject of the email to be sent accordingly.



4) create a file called 'email-add-admin.txt' in your templates directory (even if you don't use templates), with the text of your choice (modelled after 'email-add.txt').



5) in db.pl go to sub add_record and add
Code:
if ($in{'emailowner'} eq 'yes'){&html_add_email (%in);}
just before
Code:
&html_add_success;

This should do the job (it works fine for me).

Ivan,
Iyengar Yoga Resources
http://www.iyengar-yoga.com/
Quote Reply
Re: Optionally Email Link Owner When Manually Adding In reply to
I'm having a problem with the info you gave me. When I manually add a link it adds the link, but doesn't send the email message and I get this error message:

CGI ERROR
==========================================
Error Message : fatal error: Undefined subroutine &main::html_add_email called at /usr/home/activewebmaster.com/cgi-bin/links/admin/db.pl line 55.

Script Location : admin.cgi
Perl Version : 5.006

###############################################

This is the part of db.pl it is talking about:

sub add_record {
# --------------------------------------------------------
# Adds a record to the database. First, validate_record is called
# to make sure the record is ok to add. If it is, then the record is
# encoded and added to the database and the user is sent to
# html_add_success, otherwise the user is sent to html_add_failure with
# an error message explaining why. The counter file is also updated to the
# next number.

my ($output, $status, $counter);

# First we validate the record to make sure the addition is ok.
$status = &validate_record (%in);

# We keep checking for the next available key, or until we've tried 50 times
# after which we give up.
while ($status eq "duplicate key error" and $db_key_track) {
return "duplicate key error" if ($counter++ > 50);
$in{$db_key}++;
$status = &validate_record (%in);
}
if ($status eq "ok") {
open (DB, ">>$db_file_name") or &cgierr("error in add_record. unable to open database: $db_file_name.\nReason: $!");
if ($db_use_flock) {
flock(DB, 2) or &cgierr("unable to get exclusive lock on $db_file_name.\nReason: $!");
}
print DB &join_encode(%in);
close DB; # automatically removes file lock
if ($db_key_track) {
open (ID, ">$db_id_file_name") or &cgierr("error in get_defaults. unable to open id file: $db_id_file_name.\nReason: $!");
if ($db_use_flock) {
flock(ID, 2) or &cgierr("unable to get exclusive lock on $db_id_file_name.\nReason: $!");
}
print ID $in{$db_key}; # update counter.
close ID; # automatically removes file lock
if ($in{'emailowner'} eq 'yes'){&html_add_email (%in);} <----------------######## This is what I was told to manually add.
}
&html_add_success;
}
else {
&html_add_failure($status);
}
}

################################


What could be the problem?

Thanks,
Eric J. Griffin

http://www.ActiveWebmaster.com - Webmaster Resources Cool
Quote Reply
Re: Optionally Email Link Owner When Manually Adding In reply to
Dear Eric

as far as I can see, the problem lies in step three of my instructions (which probably wasn't very clear). The message you get when you try to run the script tells you that the subroutine html_add_email is not defined.

Here we go: in admin_html.pl find
Code:
##########################################################
## Email Messages ##
##########################################################
Just under it you have to add
Code:
sub html_add_email {
# --------------------------------------------------------
# All the link information is stored in %link.
my (%link) = @_;

# Set the to, from, subject and message to send.
my $to = $link{'Contact Email'};
my $from = $db_admin_email;
my $subject = "Your Website";
my $msg = &load_template ('email-add-admin.txt', \%link);

# Then mail it away!
require "$db_lib_path/Mailer.pm";
my $mailer = new Mailer ( { smtp => $db_smtp_server,
sendmail => $db_mail_path,
from => $from,
subject => $subject,
to => $to,
msg => $msg,
log => $db_mailer_log
} ) or
&cgierr("Unable to init mailer! Reason: $Mailer::error");
$mailer->send or &cgierr ("Unable to send addition message. Reason: $Mailer::error");
}
This should do the job. Make sure you have a template file called email-add-admin.txt stored in your templates directory (even if you don't normally use templates).


Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: Optionally Email Link Owner When Manually Adding In reply to
 
Beacuse od the same problem i add my links through form on my homepage and then just validate them ... then link owner get message ...

bye



Gregor