Gossamer Forum
Home : Products : DBMan : Customization :

Email notificaion on modify_success

Quote Reply
Email notificaion on modify_success
Hi.

I need a sub routine that sends email when specific fields are amended. I already have a general send mail on modify_success but I need to trigger specfic emails when values are amended in particular fields. They also need to be or statements as mutipl fields may be amended.

I guess it's:-
If field was "frog" and is now "toad"
then email message
or if field was "tree" and is now "flower"
then email message
or if field was "cabbage" and is now "lemon"
then email message
else
carry on with modify_success

any clues anyone please?


Quote Reply
Re: Email notificaion on modify_success In reply to
The only reference i know of that is somewhat related to what you are wanting to do is:

Subject Getting the modified field to print in email...
vampy 8-Feb-01 08:48 AM
Thread reference: http://gossamer-threads.com/p/126334

perhaps this will give you ideas, although I'm not sure if a solution was found.



Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: Email notificaion on modify_success In reply to
I did look at that and it does hint, sadly my Perl skills are not that good to get it going :(

Quote Reply
Re: Email notificaion on modify_success In reply to
Hi! I only got it working like that:
(Place the codes in db.cgi sub modify_record after the line:

if ($auth_user_field >= 0 and (!$per_admin or !$in{$db_cols[$auth_user_field]})) {
$in{$db_cols[$auth_user_field]} = $data[$auth_user_field];
}" )

if ($rec{'field_name'} eq 'whatever_you_want') {
open (MAIL, "$mailprog") or &cgierr("unable to open mail program");
print MAIL "To: $data[$email_field_number]\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: Your Record at $html_title has been modified.\n\n";
print MAIL "Your record at $html_title was modified.\n\n";
print MAIL "Note that this mail informs you that your record has been modified.\n\n";
print MAIL "It has been modified to: $rec{'field_name'}.\n\n";
print MAIL "Your name\n";

print MAIL "\n\n";
close MAIL;
}

the only problem with this is that it cannot compare values stored in textera fields. I don't know why. It can compare values of single line text or digits.

Julian
Quote Reply
Re: Email notificaion on modify_success In reply to
It should be able to.

How are you trying to compare them?

Installations:http://www.wiredon.net/gt/
Favicon:http://www.wiredon.net/favicon/

Quote Reply
Re: Email notificaion on modify_success In reply to
using eq. For some reason, when i do that, no matter if I change the textera field or not, it still mails me. I hope this can help you find out what went wrong with my reasoning. I know that comparing strings should be done using eq and not ==.

Julian
Quote Reply
Re: Email notificaion on modify_success In reply to
Try....

if ($rec{'field_name'} =~ /whatever you want/gi) {

Installations:http://www.wiredon.net/gt/
Favicon:http://www.wiredon.net/favicon/

Quote Reply
Re: Email notificaion on modify_success In reply to
Thanks. I'll try it and let you know. It's getting late over at my side. As i mentioned several times before, I learn soemthing new everyday. :)

Julian
Quote Reply
Re: Email notificaion on modify_success In reply to
Thanks for the info :)
I'm not too sure what you are doing a compare on in your eq statement. I want an email tif the value gets changed. Can you give me any further advice please?


Quote Reply
Re: Email notificaion on modify_success In reply to
if ($rec{'email'} ne $in{'email'}) {
#open mail program here
}

Basically, what the above does is it compares the value of the inputed email field with that found in the .db file for that particular record. If it's equal nothing will happen. If not, it will send n email out to the user.

Try it. I think it should work.

Julian
Quote Reply
Re: Email notificaion on modify_success In reply to
Thanks...... Did you have this in the db.cgi modify_section?
I think I have a bit of everything now! I have the problem now that it prints everything based on this code:
if ($per_mod) {
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: The record at $html_title has been modified by a Member\n\n";
print MAIL "The record at $html_title was modified by $in{'UserID'}.\n\n";
foreach $column (@db_cols) {
if ($rec{$column} eq $in{$column}) {
print MAIL "$column: $rec{$column}\n";
} else {
print MAIL "$column: $rec{$column} changed to $in{$column}\n";
}
}
print MAIL "\n\n";
close MAIL;
}

Quote Reply
Re: Email notificaion on modify_success In reply to
Yup! What do you mean by it print everything. You mean you don't want certain fields to be printed?

Julian
Quote Reply
Re: Email notificaion on modify_success In reply to
No that code I posted printed all fields regardless of whether a field value had changed. I have since used your code and it printed out just the changed field that has the comparison, so many thanks for that. :) BUT......

I then added a second routine for another field and a third and it now sends three emails regardless of what field is changed. So I put it back to just email comparison but it still sends an email if I change a field that is not compared. Here is the code I now have:

if ($auth_user_field >= 0 and (!$per_admin or !$in{$db_cols[$auth_user_field]})) {
$in{$db_cols[$auth_user_field]} = $data[$auth_user_field];
}

# Email support if email is changed
if ($rec{'Email address'} ne $in{'Email address'}) {
open (MAIL, "$mailprog") or &cgierr("unable to open mail program");
print MAIL "To: $admin_email\n";
print MAIL "From: Database Server\n";
print MAIL "Subject: Live Email Record Update at $html_title\n\n";
print MAIL "The record at $html_title was modified by $in{'First name'} $in{'Surname'} .\n\n";
print MAIL "It has been modified to: $in{'Email address'}\n\n";
print MAIL "Userid is: $in{'UserID'}\n\n";
print MAIL "Update was done at: " , scalar localtime(), ".\n";
print MAIL "\n\n";
close MAIL;
}
if ($rec{'Account number'} ne $in{'Account number'}) {
open (MAIL, "$mailprog") or &cgierr("unable to open mail program");
print MAIL "To: $admin_email\n";
print MAIL "From: Database Server\n";
print MAIL "Subject: Live User Bank Record Update at $html_title\n\n";
print MAIL "The record at $html_title was modified by $in{'First name'} $in{'Surname'} .\n\n";
print MAIL "Account Number has been modified to: $in{'Account number'}\n\n";
print MAIL "Sort Code has been modified to: $in{'Bank sortcode'}\n\n";
print MAIL "Account name has been modified to: $in{'Branch account name'}\n\n";
print MAIL "Userid is: $in{'UserID'}\n\n";
print MAIL "Update was done at: " , scalar localtime(), ".\n";
print MAIL "\n\n";
close MAIL;
}
if ($rec{'Home address'} ne $in{'Home address'}) {
open (MAIL, "$mailprog") or &cgierr("unable to open mail program");
print MAIL "To: $admin_email\n";
print MAIL "From: Parasol Database Server\n";
print MAIL "Subject: Live User Address Record Update at $html_title\n\n";
print MAIL "The record at $html_title was modified by $in{'First name'} $in{'Surname'} .\n\n";
print MAIL "Address has been modified to: $in{'Home address'}\n\n";
print MAIL "Post code has been modified to: $in{'Home postcode'}\n\n";
print MAIL "Userid is: $in{'UserID'}\n\n";
print MAIL "Update was done at: " , scalar localtime(), ".\n";
print MAIL "\n\n";
close MAIL;
}


$output .= &join_encode(%in);
$found = 1;
}
Quote Reply
Re: Email notificaion on modify_success In reply to
Sorry I was away for a while. You mentioned that it now sends an email regardless of whether the field is being compared, right? What exactly is the content of that email .Does it only contain the values of a particular field or does it print out all the values of all the fields?

If it's alright with you, could you possibly put a .txt version of your db.cgi on your server where I can access it and see if there are anything wrong with it.

Julian
Quote Reply
Re: Email notificaion on modify_success In reply to
Hi, no probs, thanks for the help :)
It prints the content of the specific fields that are defined in the email. This however is regardless of the field that is amended in the database. Say I amend title from miss to mrs, i get an email stating that the email, bank and address have changed (they haven't of course).



Quote Reply
Re: Email notificaion on modify_success In reply to
Do you still have the original codes within the subroutines? What i meant is the codes that came with DBMan? It doesn't make sense to me that is the original is no longer there, it still sends amn email out regardless of what was amended or what was not amended. If you still have them, delete them away. Just use the codes I gave you. It's defintely working on mine and it will only send out emails if certain fields are amended and will only print out those fields that were amended.

Julian