Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Pulling Email Address -> Links v1.11

Quote Reply
Pulling Email Address -> Links v1.11
I have hacked the tables and scripts to only have the email address stored in the Users table. I have deleted the Contact Email field in the Links and Validate tables. I have tried to use a variety of codes to pull the email address from the Users table in the sub validate_records routine in the admin.cgi script.

Here are the codes I am currently using:

Code:

# Connect to Users table and obtain Email Address for UserID
$userid = $links{$id}{'UserID'};
$db2 = new Links::DBSQL $LINKS{admin_root_path} . "/defs/Users.def";
$rec = $db2->get_record ($userid, 'HASH');
$email = $rec->{'Email'};


I have replaced Contact Email with $email and added $email as a variable to pass to the email subroutines in the Admin_HTML.pm module.

And, of course, I keep getting the bad email address error message and no email is sent to the user.

I have experimented this for the past two days with no progress. I am using similar codes in the add.cgi and modify.cgi script and the codes work fine (email is sent to the admin from the email address pulled from the Users table)...I know it is more complicated with the validation function. I have also tried putting the above codes in the email subroutines in the Admin_HTML.pm file and also in the sub html_validate_form. When I put the codes in the validate form subroutine, the email address is pulled into the email-del.txt file.

If you have any suggestions for fixing the codes I've posted, I would greatly appreciate it.

Thanks in advance.

Regards,

Eliot

Quote Reply
Re: Pulling Email Address -> Links v1.11 In reply to
Yeah......

Let me see if I can figure this one out again.

All this stuff is hard coded, some in odd places. (hopefully this is one of the 'upgrades' in the next release, and why it's taking so long).

This is a pretty major hack. Are you not planning to upgrade to the 2.0?? <G>

There is no way this is going to a portable modification.

With the current speculation on the new authentication routines, what information is going to be stored in the users table is open.

If there is going to be a good/full users table, then all that needs to be stored in the "link" is an "owner".

The problem is that the "contact" information for the public link, may not be the owner information. For instance, many sites have an "admin" type person that handles the accounts, and placements (or a sales or pr person) and the "contact" name goes to Info, Support, Feedback or some other address.

Everyone has done different things with their sites. Not all 'links' contain the same sort of information, or serve the same purpose.

For _ultimate_ flexibility, there should be a User table, with all the auth data, and the 'user' owns the link. In the link, some sites may want to list the contact info. This may or may not be different from the 'owner.'. The program should be smart enough to check the 'contact' information slot, and if there is no email address there, then use the 'owner' information.

The admin routines (or modify routines) could do the 'fill-in' for you if the user checks the box "make contact info same as admin". Some sites may not want contact information displayed, or used in the listings. A global "turn off contact information" can be used in the Links.pm file, or for sites with an "optional" contact information a check box to "not display" contact information with the link.

I'm actually thinking about this, since I'm working on a newsletter mod. Because of the changing nature of Links with the next release, this will be an external mod, that I hope can be turned into a "plug-in" when the release comes out.




http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: Pulling Email Address -> Links v1.11 In reply to
In the admin.cgi you'll see several blocks of code:

Code:
# Delete records.
foreach $id (@delete_list) {
$result = $val->delete_record ($id);
$result or ($error{$id} = "<li>$id (Couldn't delete: $Links::DBSQL::error)");
next if ($in->param($id) eq 'delete');
if ($links{$id}{'Contact_Email'} !~ /^.+\@.+\..+$/) {
$error{$id} = "<li>$id (Record deleted, but couldn't send email due to bad email address)";
next;
}
&html_reject_email ($in, $db, \%{$links{$id}});
}
The search in the file is "couldn't send email due".

What this is doing, with some convoluted and obscure logic, is checking the $id{'Contact_Email'} field, to see if there is something that looks like a valid email address. If not, it prints the error.

Depending on how you are sending the notifications, you can simply erase the error message, so nothing gets printed, or you can test the variable that contains the email address (and pass it to the email template) in place of the default value: ie: $id{'Contact_Email'}

(it seems $id is hash of the new link records, and $links is the hash of the $id records. This is a bit of a change from the normal variables used, but works the same).

http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: Pulling Email Address -> Links v1.11 In reply to
Thanks for the replies, pugdog.

I most likely will not be upgrading to the next version of Links SQL until later this year. While Alex, I believe, mentioned that a "stable" release will be made shortly after the beta is released, I don't anticipate upgrading until there is a stable version out there.

In terms of my current problem...I understand the logic in terms of checking the format of the Contact Email field. However, the email notifications are not even sent out. I added the $email variable in the error message to see if it was even being pulled from the Users table, and it is not. No email notification is sent.

Anyway...if you happen to see something that could be a good fix to this problem, I would appreciate it. I'll keep plugging away at it.

See ya.

Regards,

Eliot Lee

Quote Reply
Re: Pulling Email Address -> Links v1.11 In reply to
I guess I'm not seeing the problem.

But, in order to get the email addresses out of the users table, you'd have to make a call to the users table, and load the results of that call into a hash variable (pointer to a hash).

Then, you'd use that returned result $user->{'Email'} to generate the proper values, and pass the test.

When adding a record, the only data available is the information in the $links hash of hashes. You need to use that value, to do a lookup on the $users table, and find the corresponding value, then pass _that_ value to the email template.

You could try to use a "join" construct, and do it all on one lookup, but I don't think it would work given the current construct of the code.

The best way would just be to do a get_record for the matching "user" value, then add that hash to the passed hash values. (or, assign $user->{email} to $links->{$id->{email}} or whatever).

Make sense?

In order to _use_ the values, you have to do an explicit lookup of the value in the user table. Then, pass that value to the email routines.

This is why I'm not sure why you did it the way you did, and why in another message, I said doing all the checks up front was a better way around the gestalt of the problem.

To do this right, would require a logic change to the code, where when a link was submitted with a valid userID. Then, when the "link" was going to be validated, (or presented in the Admin) a "join" was made with the users table, so that the missing data was inserted into the Admin edit screen. Then, when the records were sent to be validated, _all_ the link+user data was available, but only the link data was inserted into the Links table -- the rest was just discarded.

See what I'm getting to? The user management features need to be integrated on the front end, so that they are available through the program, otherwise you are going to have to make odd database calls at various points in the code (very messy) -- when the _logical_ place was up front, when the record was initially presented for approval.

If I've still not hit the problem, I really don't see it. What I see as the problem is you have no "Contact_Email" in the "link" and you need to get it from the "users" table, which is keyed to the link (or vice versa) by the UserID. Logically "join" the tables in the begining of the 'validate' routines, and you'll have those variables available in all the subsequent calls.

http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: Pulling Email Address -> Links v1.11 In reply to
Thanks, pugdog...I think you have provided some good suggestions to tackle the problem. And the "user management" is done at the front end...email addresses are checked for format when they create or modify an account via the user.cgi script. The only reason I have left the error checking codes in the sub validate_records is to see if the email address is being pulled from the Users table, which it is not. But hopefully with a little more tweaking, I will be able to get it to work...this is really the last obstacle before releasing my new site...well, one of the last obstacles...I still have to fine tune the review.cgi script and a some other small odds and ends...

Yet...this seems to be quite a stumbling block.

Thanks again. Smile I really appreciate it.

Regards,

Eliot Lee

Quote Reply
Re: Pulling Email Address -> Links v1.11 In reply to
Okay...I have made some progress....Here is what I did:

1) Added a field called EmailAddress in the Validation form that is filled in with the Email field value from the Users table with the following codes:

Code:

$USERDB = new Links::DBSQL $LINKS{admin_root_path} . "/defs/Users.def";
# Connect to Users table and obtain Email Address for UserID
# Added 08/14/00
# Written by Eliot Lee
$userid = $record->{'UserID'};
$user = $USERDB->get_record ($userid, 'HASH');
$email = $user->{'Email'};
$reason = &load_text_template ('email-del.txt', $record);
<$FONT><B>Email Address:</b> <INPUT TYPE="TEXT" NAME="EmailAddress" VALUE="$email" SIZE="40"></font></TD>


in the sub html_validate_form.

2) Then I edited the sub html_reject_email routine to look like the following:

Code:

sub html_reject_email {
# --------------------------------------------------------
# All the link information is stored in $link.
#
my ($in, $link) = @_;
my ($to, $from, $subject, $msg, $mailer, $key, $db, $email);

# The message subject is defined in the form.
$to = $in->param('EmailAddress');
$from = $LINKS{db_admin_email};
$subject = "$LINKS{build_site_title}: Your link has been rejected.";
$msg = $in->param("reason-${$link}{$key}");

# Mail it away!
require Links::Mailer;
$mailer = new Links::Mailer ( { smtp => $LINKS{db_smtp_server},
sendmail => $LINKS{db_mail_path},
from => $from,
subject => $subject,
to => $to,
msg => $msg
} ) or
die ("Unable to init mailer! Reason: $Links::Mailer::error");
$mailer->send or die ("Unable to send rejection message. Reason: $Links::Mailer::error");
}


I have restored the sub validate_records routine to its original state.

What happens is the following:

1) The EmailAddress field is filled with the correct email address based on the UserID field.

2) When I click on the Validate/Delete button, I get the following error message:

Code:

Unable to send rejection message: msg body not defined.


(Something like that...)

So, the rejection email is still not sent out.

Any other thoughts will be appreciated.

Thanks in advance.

Regards,

Eliot Lee

Quote Reply
Re: Pulling Email Address -> Links v1.11 In reply to
The error message is telling you the $msg variable is "Null" or empty.

Looking back, I see this:

$msg = $in->param("reason-${$link}{$key}");

I don't understand that construct... "param" is a function of the CGI.pm module that queries the CGI object, and gets a key/value pair. (It's in my copy too, and I wonder what obscure thing it's doing -- Alex?)

You can give it an argument -name or -value and _reassign_ the parameter, but I don't see why you'd want to do that here, since the idea is to find a value, and put that value into the $msg variable.

But even beyond that, $in is probably not a "CGI" object any more, and you might need to reference it as a standard reference:

$in->{$value}

Did you try just assigning something you know to the value for $msg ??

What about just giving $msg a test string "This is a rejection" and see if the error goes away. I have a feeling the Mailer.pm is seeing no value for the body, and refusing to send an empty message -- and looking at the $msg assignment I could see why :) <G> Why it would start doing that now, I don't know...

I _really_ don't understand that assignment statement, and I even have the CGI.pm book by Lincoln Stein here, and can't decipher it!!

If someone doesn't figure out the answer, I'll backtrack through the Mailer.pm again and see what is happening. Been in there a few times, and it's dark and scarey :(~


http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: Pulling Email Address -> Links v1.11 In reply to
Thanks for the continued support, pugdog...Wink

In Reply To:
Did you try just assigning something you know to the value for $msg ??
Yes...I used the following:

Code:

$msg = ('email-del.txt', $link);


Different error message...I received NOT a HASH value in the line where these codes are located.

Anyway...I appreciate your comments...I will continue to hack my way through this problem.

Yet if anyone has an idea about how to fix the message problem, let me know, please.

Thanks in advance.

Regards,

Eliot Lee

Quote Reply
Re: Pulling Email Address -> Links v1.11 In reply to
Eliot -- this is going to be a "Duh!"

$msg is a scaler -- that's all.

It's passed right through.

If you want to assign something like that to $msg, you need to do:

$msg = &load_template('email-del.txt', $link);

Or just

$msg = "This is the text of the message!";



http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: Pulling Email Address -> Links v1.11 In reply to
Thanks for the input, pugdog...

Actually, I was using similar codes as you posted. I posted the incorrect codes in my previous Reply.

Here is what I used:

Code:

$msg = &load_text_template ('email-mod.txt', $link);


Disregard the _text_...I have split up my templates into four different directories for easier management.

Anyway...I took your advice and simply added the following codes in the $msg config line:

Code:

$msg = qq|Link rejected|;


The message was sent...however, not an ideal solution since I would like to use the email-del.txt template file to send messages. Oh well...at least I solved the Email Address problem.

Now...I will have to work on the email-del.txt template file problem.

Thanks again for your helpful suggestions. I really appreciate you taking the time to help. Smile

Regards,

Eliot Lee

Quote Reply
Re: Pulling Email Address -> Links v1.11 In reply to
Eliot,

Is $link a reference to a hash, or a reference to a reference to a hash??

Without all the codes I can't tell, but you need to pass the &load_template routine ('template',HASH_REF) (I'm assuming you didn't change anything in it, but just cloned it a few times.)

Seems to me somewhere above $link was a hash of hash references, not a reference to a hash of data.

http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: Pulling Email Address -> Links v1.11 In reply to
Even when I add a record to the Links table using the default codes that comes with Links SQL in the Admin_HTML.pm, I get the HASH error. So, something seems to be buggy in Admin_HTML.pm.

Not a big deal...all I did was pass the variables from the record hash in the sub html_validate_form to the email subroutines and wrote out the message rather than using the templates and it works...a bit clumpsy, but it works.

Regards,

Eliot Lee