To Antonimo
Antonimo wrote:
Quote:
What I'd like to know is, is there an easy way to automatically send a message to the user when the account is activated?
I am going to have to look into this one as I don't know the answer but I agree that it would be very useful
I think I have an idea of where this needs to go. I'm just stuck on one little
if ... then statement. Let me tell you where I'm going and see if you can help me get there. Here's what I've got so far. First I added another couple of message text strings to the language file
language\en-GB\en-GB.com_user.ini:
Code:
SEND_MSG_ADMIN_ACTIVATE=Hello, %s,\n\nthe account with username %s has had been activated.
SEND_MSG_ACTIVATED=Hello, %s,\n\nYour account with username %s has been activated.
Then I went into the
function activate() and added a call to the email function (somewhere around line 339):
Code:
UserController::_sendMail($user, $password);
So far so good. My last step is to modify the
function _sendMail(&$user, $password) (which starts around line 469) with some
if ... then statements that test whether the user is already activated. If activated, send the user an email that says, "User, your account is activated" and send the admins an email that says, "user's acount is activated" but I'm struggling with how to test for that. I can change:
Code:
function _sendMail(&$user, $password)
{
global $mainframe;
$db =& JFactory::getDBO();
$name = $user->get('name');
$email = $user->get('email');
$username = $user->get('username');
$usersConfig = &JComponentHelper::getParams( 'com_users' );
$sitename = $mainframe->getCfg( 'sitename' );
$useractivation = $usersConfig->get( 'useractivation' );
$mailfrom = $mainframe->getCfg( 'mailfrom' );
$fromname = $mainframe->getCfg( 'fromname' );
$siteURL = JURI::base();
$subject = sprintf ( JText::_( 'Account details for' ), $name, $sitename);
$subject = html_entity_decode($subject, ENT_QUOTES);
if ( $useractivation == 1 ){
$message = sprintf ( JText::_( 'SEND_MSG_ACTIVATE' ), $name, $sitename);
} else {
$message = sprintf ( JText::_( 'SEND_MSG' ), $name, $sitename, $siteURL);
}
$message = html_entity_decode($message, ENT_QUOTES);
//get all super administrator
$query = 'SELECT name, email, sendEmail' .
' FROM #__users' .
' WHERE LOWER( usertype ) = "super administrator"';
$db->setQuery( $query );
$rows = $db->loadObjectList();
// Send email to user
if ( ! $mailfrom || ! $fromname ) {
$fromname = $rows[0]->name;
$mailfrom = $rows[0]->email;
}
JUtility::sendMail($mailfrom, $fromname, $email, $subject, $message);
// Send notification to all administrators
$subject2 = sprintf ( JText::_( 'Account details for' ), $name, $sitename);
$subject2 = html_entity_decode($subject2, ENT_QUOTES);
// get superadministrators id
foreach ( $rows as $row )
{
if ($row->sendEmail)
{
$message2 = sprintf ( JText::_( 'SEND_MSG_ADMIN' ), $row->name, $siteURL."index.php?option=com_user&task=activate&activation=".$user->get('activation'), $name, $email, $username);
$message2 = html_entity_decode($message2, ENT_QUOTES);
JUtility::sendMail($mailfrom, $fromname, $row->email, $subject2, $message2);
}
}
}
to:
Code:
function _sendMail(&$user, $password)
{
global $mainframe;
$db =& JFactory::getDBO();
$name = $user->get('name');
$email = $user->get('email');
$username = $user->get('username');
$usersConfig = &JComponentHelper::getParams( 'com_users' );
$sitename = $mainframe->getCfg( 'sitename' );
$useractivation = $usersConfig->get( 'useractivation' );
$mailfrom = $mainframe->getCfg( 'mailfrom' );
$fromname = $mainframe->getCfg( 'fromname' );
$siteURL = JURI::base();
$subject = sprintf ( JText::_( 'Account details for' ), $name, $sitename);
$subject = html_entity_decode($subject, ENT_QUOTES);
if (<INSERT MY TEST STATEMENT HERE>){
if ( $useractivation == 1 ){
$message = sprintf ( JText::_( 'SEND_MSG_ACTIVATE' ), $name, $sitename);
} else {
$message = sprintf ( JText::_( 'SEND_MSG' ), $name, $sitename, $siteURL);
}
} else {
$message = sprintf ( JText::_( 'SEND_MSG_ACTIVATED' ), $name, $username, $sitename);
}
}
$message = html_entity_decode($message, ENT_QUOTES);
//get all super administrator
$query = 'SELECT name, email, sendEmail' .
' FROM #__users' .
' WHERE LOWER( usertype ) = "super administrator"';
$db->setQuery( $query );
$rows = $db->loadObjectList();
// Send email to user
if ( ! $mailfrom || ! $fromname ) {
$fromname = $rows[0]->name;
$mailfrom = $rows[0]->email;
}
JUtility::sendMail($mailfrom, $fromname, $email, $subject, $message);
// Send notification to all administrators
$subject2 = sprintf ( JText::_( 'Account details for' ), $name, $sitename);
$subject2 = html_entity_decode($subject2, ENT_QUOTES);
// get superadministrators id
foreach ( $rows as $row )
{
if (<INSERT MY TEST STATEMENT HERE>){
if ($row->sendEmail)
{
$message2 = sprintf ( JText::_( 'SEND_MSG_ADMIN' ), $row->name, $siteURL."index.php?option=com_user&task=activate&activation=".$user->get('activation'), $name, $email, $username);
$message2 = html_entity_decode($message2, ENT_QUOTES);
JUtility::sendMail($mailfrom, $fromname, $row->email, $subject2, $message2);
}
} else {
if ($row->sendEmail)
{
$message2 = sprintf ( JText::_( 'SEND_MSG_ADMIN_ACTIVATE' ), $row->name, $name);
$message2 = html_entity_decode($message2, ENT_QUOTES);
JUtility::sendMail($mailfrom, $fromname, $row->email, $subject2, $message2);
}
}
}
}
but I'm struggling to figure out what to put in place of
<INSERT MY TEST STATEMENT HERE>. Am I on the right track? Do you have any suggestions of how to achieve this end? I'm guessing it's simple but I just don't know enough about joomla to get this right. Your assistance is great appreacited! Thanks again!