Skip to content

Commit

Permalink
Fixed issue #6559: Batch emails to selected boxes not batching but tr…
Browse files Browse the repository at this point in the history
…ying to send to everyone
  • Loading branch information
c-schmitz committed Oct 1, 2012
1 parent 625a3de commit 74ec1be
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions application/controllers/admin/tokens.php
Expand Up @@ -1226,13 +1226,26 @@ function updatetokenattributedescriptions($iSurveyId)
/**
* Handle email action
*/
function email($iSurveyId, $aTokenIds = null)
function email($iSurveyId, $tids = null)
{
/* Check permissions */
if (!hasSurveyPermission($iSurveyId, 'tokens', 'read'))
{
die("You do not have permission to view this page"); // TODO Replace
}
$aTokenIds=$tids;
if (empty($tids))
{
$aTokenIds = Yii::app()->request->getPost('tokenids', false);
}
if (!empty($aTokenIds))
{
$aTokenIds = explode('|', $aTokenIds);
$aTokenIds = array_filter($aTokenIds);
$aTokenIds = array_map('sanitize_int', $aTokenIds);
}
$aTokenIds=array_unique(array_filter((array) $aTokenIds));

// CHECK TO SEE IF A TOKEN TABLE EXISTS FOR THIS SURVEY
$bTokenExists = tableExists('{{tokens_' . $iSurveyId . '}}');
if (!$bTokenExists) //If no tokens table exists
Expand Down Expand Up @@ -1260,7 +1273,6 @@ function email($iSurveyId, $aTokenIds = null)
$aSurveyLangs = Survey::model()->findByPk($iSurveyId)->additionalLanguages;
$sBaseLanguage = Survey::model()->findByPk($iSurveyId)->language;
array_unshift($aSurveyLangs, $sBaseLanguage);
$aTokenIds = $this->_getTokenIds($aTokenIds, $iSurveyId);
$aTokenFields = getTokenFieldsAndNames($iSurveyId, true);
$iAttributes = 0;
$bHtml = (getEmailFormat($iSurveyId) == 'html');
Expand Down Expand Up @@ -1440,7 +1452,7 @@ function email($iSurveyId, $aTokenIds = null)
$slquery->date_invited = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig("timeadjust"));
$slquery->save();
}
$tokenoutput .= " {$emrow['firstname']} {$emrow['lastname']} ({$emrow['email']})<br />\n";
$tokenoutput .= "{$emrow['tid']}: {$emrow['firstname']} {$emrow['lastname']} ({$emrow['email']})<br />\n";
if (Yii::app()->getConfig("emailsmtpdebug") == 2)
{
$tokenoutput .= $maildebug;
Expand Down Expand Up @@ -2302,28 +2314,6 @@ function _handletokenform($iSurveyId, $subaction, $iTokenId="")
$this->_renderWrappedTemplate('token', array('tokenbar', 'tokenform'), $aData);
}

private function _getTokenIds($aTokenIds, $iSurveyId)
{
// CHECK TO SEE IF A TOKEN TABLE EXISTS FOR THIS SURVEY
$bTokenExists = tableExists('{{tokens_' . $iSurveyId . '}}');
if (!$bTokenExists) //If no tokens table exists
{
self::_newtokentable($iSurveyId);
}
if (empty($aTokenIds))
{
$aTokenIds = Yii::app()->request->getPost('tokenids', false);
}
if (!empty($aTokenIds))
{
$aTokenIds = explode('|', $aTokenIds);
$aTokenIds = array_filter($aTokenIds);
$aTokenIds = array_map('sanitize_int', $aTokenIds);
}

return array_unique(array_filter((array) $aTokenIds));
}

/**
* Show dialogs and create a new tokens table
*/
Expand Down

0 comments on commit 74ec1be

Please sign in to comment.