Send mail from a form for users belonging to the level of access recorded in a form field.

MILORD65

Member
Hello,

I have a form that contains elements corresponding to various fields including a viewlevel element that allows to see the recording to users in the specified level of access in this element viewlevel.
In this form, I also have an email plugin that allows to alert users for a new recording.
Problem: I want the email to be sent only to users corresponding to the access level selected in the viewlevel element, and thus that the recipients or groups depend on a viewlevel field.
I think it is possible with PHP but I do not know how.
Can anyone help me?
Thank you in advance.

Jean Pierre.
 
Try something like this in the "Email to (eval)":

Code:
$myViewLevel = '{yourtable___yourviewlevel}';
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery->select('rules')->from('#__viewlevels')->where('title = ' . $myDb->quote($myViewLevel));
$myDb->setQuery($myQuery);
//var_dump((string)$myQuery);exit;
$myRules = $myDb->loadResult();
//var_dump($myRules);exit;
$myEmails = '';
if (!empty($myRules)) {
  $myRules = json_decode($myRules);
  $myEmails = (array) $this->getUsersInGroups($myRules, 'email');
  $myEmails = implode(',', $myEmails);
}
return $myEmails;

Replace yourtable___yourviewlevel with the full element name of your element.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top