Files
@ f43d1a4680a9
Branch filter:
Location: hot67beta/administrator/components/com_massmail/admin.massmail.php
f43d1a4680a9
4.3 KiB
text/x-php
menubar 0 to 10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | <?php
/**
* @version $Id: admin.massmail.php 10381 2008-06-01 03:35:53Z pasamio $
* @package Joomla
* @subpackage Massmail
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
/*
* Make sure the user is authorized to view this page
*/
$user = & JFactory::getUser();
if (!$user->authorize( 'com_massmail', 'manage' )) {
$mainframe->redirect( 'index.php', JText::_('ALERTNOTAUTH') );
}
require_once( JApplicationHelper::getPath( 'admin_html' ) );
switch ($task)
{
case 'send':
sendMail();
break;
case 'cancel':
$mainframe->redirect( 'index.php' );
break;
default:
messageForm( $option );
break;
}
function messageForm( $option )
{
$acl =& JFactory::getACL();
$gtree = array(
JHTML::_('select.option', 0, '- '. JText::_( 'All User Groups' ) .' -' )
);
// get list of groups
$lists = array();
$gtree = array_merge( $gtree, $acl->get_group_children_tree( null, 'users', false ) );
$lists['gid'] = JHTML::_('select.genericlist', $gtree, 'mm_group', 'size="10"', 'value', 'text', 0 );
HTML_massmail::messageForm( $lists, $option );
}
function sendMail()
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
$db =& JFactory::getDBO();
$user =& JFactory::getUser();
$acl =& JFactory::getACL();
$mode = JRequest::getVar( 'mm_mode', 0, 'post', 'int' );
$subject = JRequest::getVar( 'mm_subject', '', 'post', 'string' );
$gou = JRequest::getVar( 'mm_group', '0', 'post', 'int' );
$recurse = JRequest::getVar( 'mm_recurse', 'NO_RECURSE', 'post', 'word' );
$bcc = JRequest::getVar( 'mm_bcc', 0, 'post', 'int' );
// pulls message inoformation either in text or html format
if ( $mode ) {
$message_body = JRequest::getVar( 'mm_message', '', 'post', 'string', JREQUEST_ALLOWRAW );
} else {
// automatically removes html formatting
$message_body = JRequest::getVar( 'mm_message', '', 'post', 'string' );
}
// Check for a message body and subject
if (!$message_body || !$subject) {
$mainframe->redirect( 'index.php?option=com_massmail', JText::_( 'Please fill in the form correctly' ) );
}
// get users in the group out of the acl
$to = $acl->get_group_objects( $gou, 'ARO', $recurse );
JArrayHelper::toInteger($to['users']);
// Get sending email address
/*
$query = 'SELECT email'
. ' FROM #__users'
. ' WHERE id = '.(int) $user->get('id')
;
$db->setQuery( $query );
$user->set( 'email', $db->loadResult() );
*/
// Get all users email and group except for senders
$query = 'SELECT email'
. ' FROM #__users'
. ' WHERE id != '.(int) $user->get('id')
. ( $gou !== 0 ? ' AND id IN (' . implode( ',', $to['users'] ) . ')' : '' )
;
$db->setQuery( $query );
$rows = $db->loadObjectList();
// Check to see if there are any users in this group before we continue
if ( ! count($rows) ) {
$msg = JText::_('No users could be found in this group.');
$mainframe->redirect( 'index.php?option=com_massmail', $msg );
}
$mailer =& JFactory::getMailer();
$params =& JComponentHelper::getParams( 'com_massmail' );
// Build e-mail message format
$mailer->setSender(array($mainframe->getCfg('mailfrom'), $mainframe->getCfg('fromname')));
$mailer->setSubject($params->get('mailSubjectPrefix') . stripslashes( $subject));
$mailer->setBody($message_body . $params->get('mailBodySuffix'));
$mailer->IsHTML($mode);
// Add recipients
if ( $bcc ) {
foreach ($rows as $row) {
$mailer->addBCC($row->email);
}
$mailer->addRecipient($mainframe->getCfg('mailfrom'));
}else {
foreach ($rows as $row) {
$mailer->addRecipient($row->email);
}
}
// Send the Mail
$rs = $mailer->Send();
// Check for an error
if ( JError::isError($rs) ) {
$msg = $rs->getError();
} else {
$msg = $rs ? JText::sprintf( 'E-mail sent to', count( $rows ) ) : JText::_('The mail could not be sent');
}
// Redirect with the message
$mainframe->redirect( 'index.php?option=com_massmail', $msg );
}
|