Send Email on delete row(s)

dimoss

Well-Known Member
Hi

I wonder if it's possible somehow to send email using the email list plugin when a user deletes one or more rows from a list and keep track of what deleted through placeholders.

Thanks!
 
I would do it with a list php plugin (I don't now at the moment how to get the "Do you really want to delete..." confirmation, but I'm sure this is possible, too).
Fetch the ids, mail the row content and delete rows
or just set a row status "deleted" and pre-filter on the status, so you have a "trash" with deleted rows.

I've done this with an update column plugin (without confirmation and mail).
 
Hi Troester

I think it's better to fetch the ids than change the row status to Deleted which is relatively easy with an Update plugin.
The problem is what is the code to mail the row content and is it possible to use placeholders.
Thanks!
 
No, there isn't that ability in the email plugin. As Troester said, you'd have to roll your own code, using the php-events plugin.

I don't think you'd be able to use placeholders. So if you tell me how where your email addresses come from, I'll help you write the code you'll need. So are they just simple text in a field on the main table, or are they joined from another table (like, using the user element)?

-- hugh
 
Hi Hugh

I use a php plugin with a code that insert the user who deletes, which rows deletes and from which list into the fabrik log table. The problem is how to send the info to the email address of the user who did the delete action as well as the row data. The email address can be fetched from the users table as there is a user element on the list

Thanks
 
In the php plugin code you can get the user's email and the row data with e.g.
Code:
$app =&JFactory::getApplication();
$ids = $app->input->get( 'ids', array(), 'method', 'array' );
$user = JFactory::getUser();
$usermail =  $user->get('email');
 
foreach ($ids AS $rid) {
    $row = $model->getRow($rid);
var_dump($row);echo '<br/><br/>';
}
var_dump($usermail);exit;
 
Hi Hugh

The code I use into the list php - event plugin is:

PHP:
$log = FabTable::getInstance('log', 'FabrikTable');
$log->message_type = 'List name';
$rowids = implode(", ", JRequest::getVar('ids', array()));
$user = JFactory::getUser();
$listid = JRequest::getVar('listid');
$label = $model->getTable()->label;
$log->message = $user->get('name') . ' deleted row(s) ' . $rowids;
$log->store();

I use this onDeleteRows and insert row id and list id on the fabrik log table.

Thanks
 
To mail add something like
Code:
$app = JFactory::getApplication();
$MailFrom    = $app->getCfg('mailfrom'); //Joomla mail infos
$FromName    = $app->getCfg('fromname');
$SiteName    = $app->getCfg('sitename');
$MailTo= $user->get('email');
...
$res = JUtility::sendMail( $MailFrom, $FromName, $MailTo, $subject, $message, true);
 
Hi Troester

I tried with the code you gave me, but I get blank page when trying to delete.
Thanks!
 
Ok, sorry, this was J!2.5 code. Try
$mailer = JFactory::getMailer();
$config = JFactory::getConfig();
$sender = array(
$config->get( 'config.mailfrom' ),
$config->get( 'config.fromname' ) );

$mailer->setSender($sender);
$user = JFactory::getUser();
$recipient= $user->email;
$mailer->addRecipient($recipient);
$body = "Your body string\nin double quotes if you want to parse the \nnewlines etc";
$mailer->setSubject('Your subject string');
$mailer->setBody($body);
$send = $mailer->Send();
See http://docs.joomla.org/Sending_email_from_extensions
 
Hi Troester

Thanks for the code. Customizing the code a little bit I get the email working!

Code:
$mailer = JFactory::getMailer();
$config = JFactory::getConfig();
$sender = array(
$config->get( 'config.mailfrom' ),
$config->get( 'config.fromname' ) );
$mailer->setSender($sender);
$user = JFactory::getUser();
$recipient= $user->email;
$mailer->addRecipient($recipient);
$date = JFactory::getDate();
$rowids = implode(", ", JRequest::getVar('ids', array()));
$body = $log->message = $user->get('name') . ' deleted row(s) ' . $rowids . ' on ' . $date . ' GMT from xxxx list';
$mailer->setSubject('Deletion');
$mailer->setBody($body);
$send = $mailer->Send();

Now the problem is that as I cannot use placeholders, I don't know how to get selected data of the record putting them in the email body.

Any ideas??

Thanks!
 
Yes, see #6
Your data will be in $row->table___element

BTW: JRequest::getVar is deprecated, you should use
$app =&JFactory::getApplication();
$ids = $app->input->get( 'ids', array(), 'method', 'array' );
 
Hi

I changed:
Code:
$rowids = implode(", ", JRequest::getVar('ids', array()));

with:
Code:
$app =&JFactory::getApplication();
$rowids = $app->input->get( 'ids', array(), 'method', 'array' );

but now I don't get the ids in the email body...
 
You have still to implode
$rowids = implode(", ", $app->input->get( 'ids', array(), 'method', 'array' ));
 
You have still to implode
$rowids = implode(", ", $app->input->get( 'ids', array(), 'method', 'array' ));

Hi Troester

Yes, you are correct. I had forgotten to put the implode!
You wrote in a previous post that my table data can be in $row->table___element
However I don't know how to implement this..:(
 
Troester had already mentioned it, so BEFORE you implode the ids. you do:

PHP:
foreach ($ids as $rid)
{
    $row = $model->getRow($rid);
    var_dump($row);echo '<br/><br/>';
   // data in $row->table___element;
}
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top