A member of this forum helped me create an extension that sends notifications to one of several different email addresses when an entry is created (instead of the default behavior of always sending to the same address). The problem with the extension is that it is sending notifications whenever an entry is modified in any way, and it should only send when a new entry is created. I’m including the code here, and I would be grateful if anyone could help me figure out how to make this change.
<?php
class Notify_volunteer
{
var $settings = array();
var $name = 'Notify volunteer';
var $version = '1.0.0';
var $description = 'Notify volunteer of entries made for their region';
var $settings_exist = 'n';
var $docs_url = '';
function Notify_volunteer($settings='')
{
$this->settings = $settings;
}
function notify($entry_id, $data, $ping_message)
{
global $DB;
$message = "";
$sql = "SELECT exp_weblog_data.*, exp_category_posts.*, exp_categories.* FROM exp_weblog_data
LEFT JOIN exp_category_posts ON exp_category_posts.entry_id = exp_weblog_data.entry_id
LEFT JOIN exp_categories ON exp_categories.cat_id = exp_category_posts.cat_id
WHERE exp_weblog_data.weblog_id = 4 AND exp_weblog_data.entry_id = $entry_id";
$query = $DB->query($sql);
//Add this code
// echo "<pre>";
// print_r($query);
//New code ends here
if ($query->num_rows == 1)
{
if ( ! class_exists('EEmail'))
{
require PATH_CORE.'core.email'.EXT;
}
$email = new EEmail;
$email->initialize();
$email->wordwrap = false;
$email->mailtype = 'html';
$email->from('[email protected]', 'Waiting child notification');
$email->to($query->row['cat_url_title']."@theshepherdscrook.org");
$email->reply_to('[email protected]');
$email->subject('A new child has been entered');
$message .= "A new child has been entered for ".$query->row['cat_name']."
";
$message .= "<strong>Entry title: </strong>".$data['title']."
";
$message .= "<strong>Child ID: </strong>TSC_".$query->row['entry_id']."
";
$message .= "To view the full details, log in to <a href="http://theshepherdscrook.org/core/index.php">http://theshepherdscrook.org/core/index.php</a>
";
$email->message($message);
$email->Send();
}
}
function activate_extension()
{
global $DB;
$DB->query($DB->insert_string('exp_extensions',
array(
'extension_id' => '',
'class' => 'Notify_volunteer',
'method' => "notify",
'hook' => "submit_new_entry_end",
'settings' => "",
'priority' => 10,
'version' => $this->version,
'enabled' => "y"
)
)
);
}
function update_extension($current='')
{
global $DB;
if ($current == '' OR $current == $this->version)
{
return FALSE;
}
$DB->query("UPDATE exp_extensions
SET version = '".$DB->escape_str($this->version)."'
WHERE class = '".get_class($this)."'");
}
function disable_extension()
{
global $DB;
$DB->query("DELETE FROM exp_extensions WHERE class = '".$DB->escape_str(get_class($this))."'");
}
}
?>