MODIFYING THE ALERT RECORD SAVED PLUGIN - Jun 17th, 2022


There's are a set of very handy free plugins that user Djulia created.

"Alert Record Saved" which sends an email to the admin each time a record is saved, modified or erased.
http://www.thecmsbcookbook/downloads/emailonapproved.zip

"Alert Admin Login" which sends an email to the admin each time a user logs in.
http://www.thecmsbcookbook/downloads/alertrecordsaved.zip

I needed to modify the "Alert Record Saved" plugin for an art exhibition submission application so that it was only
triggered when a new record was created in particular section (not when the record was updated or erased) and the email
was sent to the user that created the record instead of the admin.

Here's how.
:
First I surrounded the active code with an if statement that executed the code only if the tablename was equal to my
target table and the new record flag was equal to 1


if($tableName == 'my_trigger_field' && ($isNewRecord == 1) ){

$emailTemplate = "alert-record-saved.mel.php";
$emailHeaders = emailTemplate_load(array(
'template' => $emailTemplate,
'template' => saved_sendAlertMessage_pluginDir() . "/$emailTemplate",
'subject' => '[CMSB :: Alert New Record Is Saved]',
'from' => $SETTINGS['adminEmail'],
'to' => $SETTINGS['adminEmail'],
'placeholders' => array(
'username' => $CURRENT_USER['username'],
'email' => $CURRENT_USER['email'],
'tableName' => $tableName,
'isNewRecord' => $isNewRecord,
'recordNum' => intval(@$_REQUEST['num']),
'title' => htmlspecialchars(@$_REQUEST['title']),
'oldTitle' => htmlspecialchars($oldRecord['title']),
),
'disabled' => false,
'logging' => false,
));
$mailErrors = sendMessage($emailHeaders);
if ($mailErrors) { die("Mail Error: $mailErrors"); }
}

}

And then, since I did not want to send an alert when a record was erased, I commented out the entire "send email on
erase" code block like this:




To make the email a bit more user friendly, I changed

'subject' => '[CMSB :: Alert New Record Is Saved]',

to

'subject' => 'Your submission has been received',

and to direct the email alert to the current user, I changed

'to' => $SETTINGS['adminEmail'],

to

'to' => $CURRENT_USER['email'],


In the placeholder array (the values passed to the email template) I added a few placeholders that were more relevant to
my application. (as an example, 'projectTitle' is a new placeholder I want to be available in the email template and
@$_REQUEST['project_title'] is the field in my table where I want the value to come from.)


'projectTitle' => htmlspecialchars(@$_REQUEST['project_title']),
'ship' => htmlspecialchars(@$_REQUEST['i_am_planning_to_ship_my_artwork']),
'firstName' => $CURRENT_USER['first_name'],
'lastName' => $CURRENT_USER['last_name'],

_____________________________________________________

In the email template I changed the body to include a masthead image, included the user's first and last name and a link
to a simple viewer so that they could view their submission:

<body>
<img src="http://www.mysite.com/images/masthead.jpg" width="489" height="88" alt="Masthead" />
<br /> <br />
Hi <?php echo htmlspecialchars($PLACEHOLDERS['firstName']) ?>,
<br /> <br />

Your submission to <?php echo htmlspecialchars($PLACEHOLDERS['projectTitle']) ?> was received successfully.
<br /> <br />

<a href="http://www.mysite.com/exhibition_submission_viewer.php?num=<?php echo intval($PLACEHOLDERS['recordNum'])
?>">CLICK/TAP HERE TO VIEW / PRINT YOUR SUBMISSION INFORMATION</a>
<br /> <br />
<?php if($PLACEHOLDERS['ship'] == 1):?>You've indicated that you'll be shipping your work to this exhibition.Please
insure that it will arrive by the shipping deadline.<?php endif?>
<br /> <br />

If you have any questions, please <a href="http://www.nawafl.com/contact.php">CONTACT US</a>
<br /> <br />
Thanks,
The Exhibitions Committee
<br /> <br />
</body>




The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service