Gossamer Forum
Home : Products : DBMan : Customization :

Validate Mod: 2 problems

Quote Reply
Validate Mod: 2 problems
Hello again. After a few days of frustrating Internet problems with my ISP and the new "Verizon" company, I've run into yet another problem with DBMan, although easily solved I suspect. Okay, here it goes:

I've set up the validate mod so that when the sub html_add_success runs, it sends an email to the administrator telling him that someone has added their stuff to the database. However, the email is never received and therefore probably never sent. Here's the code:

In default.cfg:

# Full path to sendmail on your system
$mailprog = "/var/qmail/bin/qmail-inject";
# Fieldname that contains the email address of the user
$db_email_field = 'Email';
# Your email address
$admin_email = 'WBK73G\@webknights.hypermart.net';


Note: I have tried taking the \ out of the $admin_email variable but to no avail.

In html.pl:

sub html_add_success {
# --------------------------------------------------------
# The page that is returned upon a successful addition to
# the database. You should use &get_record and &html_record
# to verify that the record was inserted properly and to make
# updating easier.

%rec=&get_record($in{$db_key});

open (MAIL, "$mailprog") or &cgierr("unable to open mail program");
print MAIL "To: $admin_email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: New Staff Entry! - WebKnights Virtual Airlines\n\n";
print MAIL "$db_userid has added his/her self to the database. Here is his/her information:\n\n";
foreach $column (@db_cols) {
print MAIL "$column: $rec{$column}\n";
}
print MAIL "\n\n";
close MAIL;

&html_print_headers;
print qq|
<html>
<head>
<title>$html_title: New Member Added</title>

...

</body>
</html>
|;
}


My second problem is that when I am logged in as the admin, and I click the validate link in the footer, I get the search failed page with the error "<>No search terms specified." or something to that effect. I'm not sure what code I should post, if any, to help determine the problem. So, if you need code, just tell me what to post and I'll get it to you. That is, if my ISP and Verizon allow me to. Smile

Thanks everyone,

Michael DeLong
Quote Reply
Re: Validate Mod: 2 problems In reply to

# Full path to sendmail on your system
$mailprog = "|/var/qmail/bin/qmail-inject";
# Fieldname that contains the email address of the user
$db_email_field = 'Email';
# Your email address
$admin_email = 'WBK73G@webknights.hypermart.net';


You must have the | character at the beginning of the path to sendmail. And, if you use single quotes, you do not use the \ in front of the @. Either of these are correct:

$admin_email = 'WBK73G@webknights.hypermart.net';

or

$admin_email = "WBK73G\@webknights.hypermart.net";

Regarding your other problem, do you have


# Name of your validation field
$db_validated_field = 'Validated';


in your .cfg file?

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Validate Mod: 2 problems In reply to
1. The | worked. Thanks.
2. About $admin_email, thanks - I just learned something.
3. db_validated_field wasn't there, like you thought, but I sure would have bet it was once because I remember adding it. Anyway...it works now.
4. There's one more problem I've run into:
in roster.cgi (db.cgi), the scirpt sends an email to the person to which the record belongs when it gets validated. This is how it's supposed to be. But, in the message it says something like this:
Dear ('First Name'),

blah blah blah.

When it should say:

Dear Joe,
blah blah blah.

Here's the code:

# Here's where you create your canned validate message. You can use the $rec{'fieldname'} variables
# just like in sub html_record to include the values of any fields that you'd like to.
# As you define your message, use carriage returns for a newline
$email_message = qq|
Dear $rec('First Name'),

It's with my greatest pleasure ....


Any ideas?

Thanks,



Michael DeLong
Quote Reply
Re: Validate Mod: 2 problems In reply to
Dear $rec{'First Name'},

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Validate Mod: 2 problems In reply to
Ah ha! Makes sense - sillly me. Hard to tell the difference between the curly bracket and parenthesis.

Thanks,



Michael DeLong
Quote Reply
Re: Validate Mod: 2 problems In reply to
It is hard to tell the difference sometimes, depending on the font you use for your text editor. I often have a hard time telling the difference in the Perl books I have.

Glad I could help. Smile

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Validate Mod: 2 problems In reply to
Okay, one more problem! Frown

After I have validated a record, it can then be returned in a view or list all, the member who owns that record gets an email saying "welcome aboard" and that's that. That's for new members. But when a returning member comes back to the roster and changes some of his info (like say, his email address has changed), the record is no long valid and must be revalidated. Okay, so I go and revalidate it. But when I do, it re-sends the welcome message it would normally send to a new member. How can I get it so that it sends a different email saying "Okay, you've changed your info and I agree that the new stuff is okay", or even no email at all? It would be something like this:

if ($this-is-the-first-time eq "yes") {print **print the new member mail**}
else if {$this-is-the-first-time eq "no" and $this-is-the-second-time eq "yes") {print **print the returning member email**}

I know that is totally unreal of what the code might be, but it just might make it easier to understand what I'm trying to do.

Michael DeLong
Quote Reply
Re: Validate Mod: 2 problems In reply to
First, you'd have to come up with some way to tell whether the record was a new one or a modified one. I'm not sure what that would be.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Validate Mod: 2 problems In reply to
Could you do it using cookies?

Michael DeLong
Quote Reply
Re: Validate Mod: 2 problems In reply to
I don't know. I know nothing at all about cookies.

The only thing I can think of would be to have another field added to your database. Call it "Modified." It would be automatically set to either "No" or nothing at all when a record is added and set to "Yes" when a record is modified.

Go ahead and add the field to your database first. You'll need to add it to your .cfg file and to every record that is currently in your database. Also, you'll need to add a hidden field to sub html_record_form.

Once you have the field in place, we can work on how to use it.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Validate Mod: 2 problems In reply to
Okay, here are the last three definitions in the .cfg file:

'Password' => [17, 'alpha', 10, 10, 1, '', ''],
'Validated' => [18, 'alpha', 0, 3, 1, 'No', 'Yes|No'],
'Modified' => [19, 'alpha', 0, 3, 1, 'No', 'Yes|No']
);

What next?

Thanks,


Michael DeLong
Quote Reply
Re: Validate Mod: 2 problems In reply to
In sub modify_record, after

(!$per_admin) and ($in{$db_validated_field} = "No");

add

(!$per_admin) and ($in{Modified} = "Yes");[/blue]

Add the line and then modify a couple of records and check to be sure that the field value is being changed.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Validate Mod: 2 problems In reply to
Okay, I added that line into the roster.cgi but now when they modify their record, it isn't listed in the validate page and thus is automatically accepted. Was this expected?

Michael DeLong
Quote Reply
Re: Validate Mod: 2 problems In reply to
Okay, I spoke before I should have. That problem was with my record (and since I'm admin, funny things can happen). But when I became a normal user, everything worked fine, except I'm still getting the newbie email.

Michael DeLong
Quote Reply
Re: Validate Mod: 2 problems In reply to
That's because we haven't changed the code yet to send out different emails.

Make the following change in sub validate_records:

Code:

elsif ($validate_list{$data[$db_key_pos]}) {
$validate_list{$data[$db_key_pos]} = 0;
%rec = &array_to_hash(0,@data);
open (MAIL, "$mailprog") or &cgierr("unable to open mail program");
print MAIL "To: $rec{$db_email_field}\n";
print MAIL "From: $admin_email\n";

# you can change the subject line to whatever you want
print MAIL "Subject: $html_title: Record validated\n\n";
print MAIL "-" x 75 . "\n\n";

if ($rec{'Modified'} eq "Yes") {
$email_message = qq|
message for modified records
|;
}
else {

$email_message = qq|
newbie message
|;
}

print MAIL $email_message;
close (MAIL); $rec{$db_validated_field} = "Yes";
$output .= &join_encode(%rec);
}
JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Validate Mod: 2 problems In reply to
It works like a charm! I've got a few more questions that I'll post in a new thread for convience.

Thanks JPD!

Michael DeLong