Gossamer Forum
Home : Products : DBMan : Customization :

email to admin when delete file from database

Quote Reply
email to admin when delete file from database
http://www.cpphsa.org/cgi-bin/dbman/db.cgi

All other files are there too. Only test data is there. All passwords are out-of-box at this point. author/author is deleted in passwords, however.

Unix System.

Problem: Although the email addon works for add and modify files. the email to admin and moderator and sender does not include the data to see what file is being deleted. I had added the same info in add, modify, and delete in testing and the add/modify worked fine. So I deleted the variables from the delete to see what would work to at least get an id to see in the email message what file was deleted.

Below is a copy of the existing section in the html.pl file. This is the out-of-box html.pl file with email addon. The out-of-box email add on did not work so I modify it a bit. Here is the section of variables that were there in testing.

print MAIL "ID: $rec{'ID'} \n\n";
print MAIL "Category: $rec{'Category'} \n\n";
print MAIL "Type: $rec{'Type'} \n\n";
print MAIL "Class Year: $rec{'ClassYr'} \n\n";
print MAIL "Event Name: $rec{'EventName'} \n\n";
print MAIL "RSVP: $rec{'RSVP'} \n\n";
print MAIL "Location: $rec{'Location'} \n\n";
print MAIL "Cost: $rec{'Cost'} \n\n";
print MAIL "Contact: $rec{'Contact'} \n\n";
print MAIL "Event Description: $rec{'EventDesc'} \n\n";
print MAIL "Website Url: $rec{'URL'} \n\n";
print MAIL "Need Volunteers: $rec{'Volunteer'} \n\n";
print MAIL "Must Pre-Register: $rec{'Register'} \n\n";
print MAIL "Submit Email: $rec{'SubmitEmail'} \n\n";
print MAIL "Submit Date: $rec{'Date'} \n\n";
print MAIL "Submit Name: $rec{'YourName'} \n\n";
print MAIL "Reunion Committee Members: $rec{'Committee'} \n\n";


Question: need delete module to send email to admin, moderator, and submitter with at least an id of file that is being deleted.

Below is the file modules in the html.pl file.

##########################################################
## Deleting ##
##########################################################

sub html_delete_search {
# --------------------------------------------------------
# The page is displayed when a user wants to delete records. First
# the user has to search the database to pick which records to delete.
# That's handled by this form.

&html_print_headers;
print qq|
<html>
<head>
<title>$html_title: Search the Database for Deletion.</title>
</head>

<body bgcolor="#DDDDDD">
<form action="$db_script_url" method="GET">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<center>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 align=center valign=top>
<tr><td colspan=2 bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Search the Database for Deletion</b>
</td></tr>
<tr><td>
<p><center><$font_title><b>
Search the Database for Deletion
</b></font></center><br>
<$font>
<P>Search the database for the records you wish to delete or
<A HREF="$db_script_link_url&delete_form=1&$db_key=*">list all</a>:</p>
|; &html_record_form(); print qq|
|; &html_search_options; print qq|</p>
</font></p>
<p><center> <INPUT TYPE="SUBMIT" NAME="delete_form" VALUE="Search"> <INPUT TYPE="RESET" VALUE="Reset Form"></center></p>
|; &html_footer; print qq|
</td></tr>
</table>
</center>
</form>
</body>
</html>
|;
}

sub html_delete_form {
# --------------------------------------------------------
# The user has searched the database for deletion and must now
# pick which records to delete from the records returned. This page
# should produce a checkbox with name=ID value=delete for each record.
# We have to do a little work to convert the array @hits that contains
# the search results to a hash for printing.

my ($status, @hits) = &query("mod");
my ($numhits) = ($#hits+1) / ($#db_cols+1);
my ($maxhits); $in{'mh'} ? ($maxhits = $in{'mh'}) : ($maxhits = $db_max_hits);
my (%tmp);

&html_print_headers;
print qq|
<html>
<head>
<title>$html_title: Delete Record(s).</title>
</head>

<body bgcolor="#DDDDDD">
<form action="$db_script_url" METHOD="POST">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">

<blockquote>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 valign=top>
<tr><td colspan=2 bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Delete Record(s)</b>
</td></tr>
</table>
<p><$font>
Check which records you wish to delete and then press "Delete Records":<br>
Your search returned <b>$db_total_hits</b> matches.</font>
|;
if ($db_next_hits) {
print "<br><$font>Pages: $db_next_hits</font>";
}
# Go through each hit and convert the array to hash and send to
# html_record for printing. Also add a checkbox with name=key and value=delete.

if ($status ne "ok") { # There was an error searching!
print qq|<P><FONT COLOR="RED" SIZE=4>Error: $status</FONT></P>|;
}
else {
print "<P>";
for (0 .. $numhits - 1) {
%tmp = &array_to_hash($_, @hits);
print qq|<TABLE BORDER=0><TR><TD><INPUT TYPE=CHECKBOX NAME="$tmp{$db_key}" VALUE="delete"></TD><TD>|;
&html_record (%tmp);
print qq|</TD></TR></TABLE>\n|;
}
if ($db_next_hits) {
print "<br><$font>Pages: $db_next_hits</font>";
}
}
print qq|
<p>
<table border=0 bgcolor="#DDDDDD" cellpadding=5 cellspacing=3 width=500 valign=top>
<tr><td>
<p><center><INPUT TYPE="SUBMIT" name="delete_records" VALUE="Delete Checked Record(s)"> <INPUT TYPE="RESET" VALUE="Reset Form"></center></p>
|; &html_footer; print qq|
</td></tr>
</table>
</blockquote>
</body>
</html>
|;
}

sub html_delete_success {
# --------------------------------------------------------
# This page let's the user know that the records were successfully
# deleted.

########
# To send mail to the administrator after a record is deleted
########

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

open (MAIL, "$mailprog") || &cgierr("Can't start mail program");
print MAIL "To: $admin_email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: $html_title Deleted Record\n\n";
print MAIL "The following new record has been deleted from the database:.\n\n";

close (MAIL);


#########
# To send mail to the modator after a record is deleted
#########

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

open (MAIL, "$mailprog") || &cgierr("Can't start mail program");
print MAIL "To: $mod_email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: $html_title Deleted Record\n\n";
print MAIL "The following new record has been deleted from the database:.\n\n";

close (MAIL);

#########
# To send mail to the submitter after a record is deleted
#########

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

open (MAIL, "$mailprog") || &cgierr("Can't start mail program");

########
# Be sure to change the name of the field below to match your email
# field name
########

print MAIL "To: $rec{'SubmitEmail'}\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: Welcome to $html_title\n\n";

#######
# Be sure to write your welcome message. You may use the $rec{'FieldName'}
# variables to include values from the record if you wish.
#######

print MAIL "Your Reunion Database Information has been deleted.\n\n";

close (MAIL);

my $message = shift;

&html_print_headers;
print qq|
<html>
<head>
<title>$html_title: Record(s) Deleted.</title>
</head>

<body bgcolor="#DDDDDD">
<center>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 align=center valign=top>
<tr><td colspan=2 bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Record(s) Deleted.</b>
</td></tr>
<tr><td>
<p><center><$font_title><b>
Record(s) Deleted
</b></font></center><br>
<$font>
The following records were deleted from the database: '$message'.
</font></p>
|; &html_footer; print qq|
</td></tr>
</table>
</center>
</body>
</html>
|;
}

sub html_delete_failure {
# --------------------------------------------------------
# This page let's the user know that some/all of the records were
# not deleted (because they were not found in the database).
# $errstr contains a list of records not deleted.

my ($errstr) = $_[0];

&html_print_headers;
print qq|
<html>
<head>
<title>$html_title: Error: Record(s) Not Deleted.</title>
</head>

<body bgcolor="#DDDDDD">
<center>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 align=center valign=top>
<tr><td colspan=2 bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Error: Record(s) Not Deleted</b>
</td></tr>
<tr><td>
<p><center><$font_title><b>
Error: <font color=red>Record(s) Not Deleted</font>
</b></font></center><br>
<$font>
The records with the following keys were not found in the database: <FONT COLOR="red">'$errstr'</FONT>.
</font></p>
|; &html_footer; print qq|
</td></tr>
</table>
</center>
</body>
</html>
|;
}
Quote Reply
Re: [ameigh] email to admin when delete file from database In reply to
This information adapted from the DbMan Forum in another thread.......

If you haven't already done so, add the following to your .cfg file:
Note: I could only seem to get one email out to either the admin or owner fo the record and
not both.

Note: This can replace the Administrator email address if you want the confirmation
sent to the submitter/owner of the record. Change the "TO" to print MAIL "To: $data[$auth_email_field]\n"; instead of print MAIL "To: $admin_email\n";

# the email address of the one who owns the record. Set to -1 if not used.
$auth_email_field = 4;


--------------------------------------------------------------------------------
Code
--------------------------------------------------------------------------------

# Full path to sendmail on your system
$mailprog = "|/usr/lib/sendmail -t -oeq"; # Your email address
$admin_email = 'you@yourserver.com'; # This is the field position in the database used for storing
# Administrator email address
$admin_email = 'admin@wherever.com';

--------------------------------------------------------------------------------
Code
--------------------------------------------------------------------------------

$delete_list{$data[$db_key_pos]} ? # if this id is one we want to delete
($delete_list{$data[$db_key_pos]} = 0) : # then mark it deleted and don't print it to the new
database. ($output .= $line . "\n"); # otherwise print it.

--------------------------------------------------------------------------------


to


--------------------------------------------------------------------------------
Code
--------------------------------------------------------------------------------
################
# Sends email message to administrator when record is deleted
################

if ($delete_list{$data[$db_key_pos]}) {
$delete_list{$data[$db_key_pos]} = 0; # then mark it deleted and don't print it to the new database.

open (MAIL, "$mailprog") or &cgierr("Can't start mail program");
print MAIL "To: $admin_email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: $html_title Confirmation of Deleted Record\n\n";
print MAIL "-" x 75 . "\n\n";
print MAIL "Your record at $html_title, which had the following information:\n";
print MAIL "\n has been deleted from the database.\n\n";

for ($i=0;$i<=$#db_cols ;++$i) {
print MAIL "$db_cols[$i]: $data[$i]\n"; }

close MAIL; }

else { $output .= $line . "\n"; # otherwise print it.
}

##############
# End of email to administrator upon deletion of record.
##############



else { $output .= $line . "\n"; # otherwise print it.
}

##############
# End of email to administator upon deletion of record.
##############Sly
Quote Reply
Re: [ameigh] email to admin when delete file from database In reply to
The routine for sending the email needs to be placed in db.cgi, sub delete_records not in delete_success of your html.pl file.

Unoffical DBMan FAQ
http://redundantcartridge.com/dbman/