<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.4 |
+ | CiviCRM version 4.5 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013 |
+ | Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
* $Id$
*
*/
*
* @params array $params contains form values
*
+ * @param $testParams
+ *
* @return void
* @access public
*/
/**
* static wrapper for getting verp and urls
*
- * @param int $job_id ID of the Job associated with this message
- * @param int $event_queue_id ID of the EventQueue
- * @param string $hash Hash of the EventQueue
- * @param string $email Destination address
+ * @param int $job_id ID of the Job associated with this message
+ * @param int $event_queue_id ID of the EventQueue
+ * @param string $hash Hash of the EventQueue
+ * @param string $email Destination address
*
- * @return (reference) array array ref that hold array refs to the verp info and urls
+ * @return array (reference) array array ref that hold array refs to the verp info and urls
*/
static function getVerpAndUrls($job_id, $event_queue_id, $hash, $email) {
// create a skeleton object and set its properties that are required by getVerpAndUrlsAndHeaders()
/**
* get verp, urls and headers
*
- * @param int $job_id ID of the Job associated with this message
- * @param int $event_queue_id ID of the EventQueue
- * @param string $hash Hash of the EventQueue
- * @param string $email Destination address
+ * @param int $job_id ID of the Job associated with this message
+ * @param int $event_queue_id ID of the EventQueue
+ * @param string $hash Hash of the EventQueue
+ * @param string $email Destination address
*
- * @return (reference) array array ref that hold array refs to the verp info, urls, and headers
- * @access private
+ * @param bool $isForward
+ *
+ * @return array (reference) array array ref that hold array refs to the verp info, urls, and headers@access private
*/
private function getVerpAndUrlsAndHeaders($job_id, $event_queue_id, $hash, $email, $isForward = FALSE) {
$config = CRM_Core_Config::singleton();
/**
* Compose a message
*
- * @param int $job_id ID of the Job associated with this message
- * @param int $event_queue_id ID of the EventQueue
- * @param string $hash Hash of the EventQueue
- * @param string $contactId ID of the Contact
- * @param string $email Destination address
- * @param string $recipient To: of the recipient
- * @param boolean $test Is this mailing a test?
- * @param boolean $isForward Is this mailing compose for forward?
- * @param string $fromEmail email address of who is forwardinf it.
+ * @param int $job_id ID of the Job associated with this message
+ * @param int $event_queue_id ID of the EventQueue
+ * @param string $hash Hash of the EventQueue
+ * @param string $contactId ID of the Contact
+ * @param string $email Destination address
+ * @param string $recipient To: of the recipient
+ * @param boolean $test Is this mailing a test?
+ * @param $contactDetails
+ * @param $attachments
+ * @param boolean $isForward Is this mailing compose for forward?
+ * @param string $fromEmail email address of who is forwardinf it.
+ *
+ * @param null $replyToEmail
*
* @return object The mail object
* @access public
CRM_Utils_Hook::alterMailParams($mailParams, 'civimail');
// CRM-10699 support custom email headers
- if (CRM_Utils_Array::value('headers', $mailParams)) {
+ if (!empty($mailParams['headers'])) {
$headers = array_merge($headers, $mailParams['headers']);
}
//cycle through mailParams and set headers array
$result = $mailing->save();
- if (CRM_Utils_Array::value('mailing', $ids)) {
+ if (!empty($ids['mailing'])) {
CRM_Utils_Hook::post('edit', 'Mailing', $mailing->id, $mailing);
}
else {
*
* @params array $params Form values
*
+ * @param $params
+ * @param array $ids
+ *
* @return object $mailing The new mailing object
* @access public
* @static
'forward_replies' => FALSE,
'open_tracking' => TRUE,
'url_tracking' => TRUE,
- 'visibility' => 'User and User Admin Only',
+ 'visibility' => 'Public Pages',
'replyto_email' => $domain_email,
'header_id' => CRM_Mailing_PseudoConstant::defaultComponent('header_id', ''),
'footer_id' => CRM_Mailing_PseudoConstant::defaultComponent('footer_id', ''),
$transaction->rollback();
return $mailing;
}
+ // update mailings with hash values
+ CRM_Contact_BAO_Contact_Utils::generateChecksum($mailing->id, NULL, NULL, NULL, 'mailing', 16);
$groupTableName = CRM_Contact_BAO_Group::getTableName();
$mailingTableName = CRM_Mailing_BAO_Mailing::getTableName();
$mg = new CRM_Mailing_DAO_MailingGroup();
foreach (array('groups', 'mailings') as $entity) {
foreach (array('include', 'exclude', 'base') as $type) {
- if (isset($params[$entity]) &&
- CRM_Utils_Array::value($type, $params[$entity]) &&
+ if (isset($params[$entity]) && !empty($params[$entity][$type]) &&
is_array($params[$entity][$type])) {
foreach ($params[$entity][$type] as $entityId) {
$mg->reset();
return $mailing;
}
+ /**
+ * get hash value of the mailing
+ *
+ */
+ public static function getMailingHash($id) {
+ $hash = NULL;
+ if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'hash_mailing_url')) {
+ $hash = CRM_Core_DAO::getFieldValue('CRM_Mailing_BAO_Mailing', $id, 'hash', 'id');
+ }
+ return $hash;
+ }
+
/**
* Generate a report. Fetch event count information, mailing data, and job
* status.
*
- * @param int $id The mailing id to report
+ * @param int $id The mailing id to report
* @param boolean $skipDetails whether return all detailed report
*
+ * @param bool $isSMS
+ *
* @return array Associative array of reporting data
* @access public
* @static
$report['event_totals']['queue'] = self::getRecipientsCount($mailing_id, $mailing_id);
}
- if (CRM_Utils_Array::value('queue', $report['event_totals'])) {
+ if (!empty($report['event_totals']['queue'])) {
$report['event_totals']['delivered_rate'] = (100.0 * $report['event_totals']['delivered']) / $report['event_totals']['queue'];
$report['event_totals']['bounce_rate'] = (100.0 * $report['event_totals']['bounce']) / $report['event_totals']['queue'];
$report['event_totals']['unsubscribe_rate'] = (100.0 * $report['event_totals']['unsubscribe']) / $report['event_totals']['queue'];
) as $key) {
$url = 'mailing/detail';
$reportFilter = "reset=1&mailing_id_value={$mailing_id}";
- $searchFilter = "force=1&mailing_id={$mailing_id}";
+ $searchFilter = "force=1&mailing_id=%%mid%%";
switch ($key) {
case 'delivered':
$reportFilter .= "&delivery_status_value=successful";
if (array_key_exists(CRM_Core_Action::ADVANCED, $actionLinks)) {
$actionLinks[CRM_Core_Action::ADVANCED]['qs'] = $searchFilter;
}
- $report['event_totals']['actionlinks'][$key] = CRM_Core_Action::formLink($actionLinks, $action, array());
+ $report['event_totals']['actionlinks'][$key] = CRM_Core_Action::formLink(
+ $actionLinks,
+ $action,
+ array('mid' => $mailing_id),
+ ts('more'),
+ FALSE,
+ 'mailing.report.action',
+ 'Mailing',
+ $mailing_id
+ );
}
return $report;
/**
* Get the rows for a browse operation
*
- * @param int $offset The row number to start from
- * @param int $rowCount The nmber of rows to return
- * @param string $sort The sql string that describes the sort order
+ * @param int $offset The row number to start from
+ * @param int $rowCount The nmber of rows to return
+ * @param string $sort The sql string that describes the sort order
+ *
+ * @param null $additionalClause
+ * @param null $additionalParams
*
* @return array The rows
* @access public
*
* @param int $id
*
+ * @return string
* @static
* @access public
*/
*
* @param $form
*
- * @return None
+ * @return void
* @access public
*/
public static function commonCompose(&$form) {
//get the tokens.
$tokens = CRM_Core_SelectValues::contactTokens();
- //token selector for subject
- //CRM-5058
- $form->add('select', 'token3', ts('Insert Token'),
- $tokens, FALSE,
- array(
- 'size' => "5",
- 'multiple' => TRUE,
- 'onclick' => "return tokenReplText(this);",
- )
- );
$className = CRM_Utils_System::getClassName($form);
if ($className == 'CRM_Mailing_Form_Upload') {
$tokens = array_merge(CRM_Core_SelectValues::mailingTokens(), $tokens);
}
//sorted in ascending order tokens by ignoring word case
- natcasesort($tokens);
- $form->assign('tokens', json_encode($tokens));
-
- $form->add('select', 'token1', ts('Insert Tokens'),
- $tokens, FALSE,
- array(
- 'size' => "5",
- 'multiple' => TRUE,
- 'onclick' => "return tokenReplText(this);",
- )
- );
-
- $form->add('select', 'token2', ts('Insert Tokens'),
- $tokens, FALSE,
- array(
- 'size' => "5",
- 'multiple' => TRUE,
- 'onclick' => "return tokenReplHtml(this);",
- )
- );
-
+ $form->assign('tokens', CRM_Utils_Token::formatTokensForDisplay($tokens));
$form->_templates = CRM_Core_BAO_MessageTemplate::getMessageTemplates(FALSE);
if (!empty($form->_templates)) {
*
* @param $form
*
- * @return None
+ * @return void
* @access public
*/
public static function commonLetterCompose(&$form) {
$tokens = array_merge($form->listTokens(), $tokens);
}
- //sorted in ascending order tokens by ignoring word case
- natcasesort($tokens);
-
- $form->assign('tokens', json_encode($tokens));
-
- $form->add('select', 'token1', ts('Insert Tokens'),
- $tokens, FALSE,
- array(
- 'size' => "5",
- 'multiple' => TRUE,
- 'onchange' => "return tokenReplHtml(this);",
- )
- );
+ $form->assign('tokens', CRM_Utils_Token::formatTokensForDisplay($tokens));
$form->_templates = CRM_Core_BAO_MessageTemplate::getMessageTemplates(FALSE);
if (!empty($form->_templates)) {
*
* @param $form reference of this
*
- * @return $report array content/component.
- * @access public
+ * @param bool $isSMS
+ *
+ * @return array $report array content/component.@access public
*/
static function getMailingContent(&$report, &$form, $isSMS = FALSE) {
$htmlHeader = $textHeader = NULL;
}
}
- $text = CRM_Utils_Request::retrieve('text', 'Boolean', $form);
- if ($text) {
- echo "<pre>{$textHeader}</br>{$report['mailing']['body_text']}</br>{$textFooter}</pre>";
- CRM_Utils_System::civiExit();
- }
-
+ $mailingKey = $form->_mailing_id;
if (!$isSMS) {
- $html = CRM_Utils_Request::retrieve('html', 'Boolean', $form);
- if ($html) {
- $output = $htmlHeader . $report['mailing']['body_html'] . $htmlFooter ;
- echo str_replace( "\n", '<br />', $output );
- CRM_Utils_System::civiExit();
+ if ($hash = CRM_Mailing_BAO_Mailing::getMailingHash($mailingKey)) {
+ $mailingKey = $hash;
}
}
if (!empty($report['mailing']['body_text'])) {
- $url = CRM_Utils_System::url('civicrm/mailing/report', 'reset=1&text=1&mid=' . $form->_mailing_id);
- $popup = "javascript:popUp(\"$url\");";
- $form->assign('textViewURL', $popup);
+ $url = CRM_Utils_System::url('civicrm/mailing/view', 'reset=1&text=1&id=' . $mailingKey);
+ $form->assign('textViewURL', $url);
}
if (!$isSMS) {
if (!empty($report['mailing']['body_html'])) {
- $url = CRM_Utils_System::url('civicrm/mailing/report', 'reset=1&html=1&mid=' . $form->_mailing_id);
- $popup = "javascript:popUp(\"$url\");";
- $form->assign('htmlViewURL', $popup);
+ $url = CRM_Utils_System::url('civicrm/mailing/view', 'reset=1&id=' . $mailingKey);
+ $form->assign('htmlViewURL', $url);
}
}
//CRM-12814
if (!empty($mailings)) {
- $openCounts = CRM_Mailing_Event_BAO_Opened::getMailingTotalCount(array_keys($mailings));
- $clickCounts = CRM_Mailing_Event_BAO_TrackableURLOpen::getMailingTotalCount(array_keys($mailings));
+ $openCounts = CRM_Mailing_Event_BAO_Opened::getMailingContactCount(array_keys($mailings), $params['contact_id']);
+ $clickCounts = CRM_Mailing_Event_BAO_TrackableURLOpen::getMailingContactCount(array_keys($mailings), $params['contact_id']);
}
// format params and add links
"reset=1&cid={$values['creator_id']}");
//CRM-12814
- $contactMailings[$mailingId]['openstats'] = ts('Opens') . ': ' . $openCounts[$values['mailing_id']] .
- '<br />' . ts('Clicks') . ': ' . $clickCounts[$values['mailing_id']];
+ $contactMailings[$mailingId]['openstats'] = "Opens: ".
+ CRM_Utils_Array::value($values['mailing_id'], $openCounts, 0).
+ "<br />Clicks: ".
+ CRM_Utils_Array::value($values['mailing_id'], $clickCounts, 0);
$actionLinks = array(
CRM_Core_Action::VIEW => array(
'name' => ts('View'),
'url' => 'civicrm/mailing/view',
- 'qs' => "reset=1&id={$values['mailing_id']}",
+ 'qs' => "reset=1&id=%%mkey%%",
'title' => ts('View Mailing'),
- 'class' => 'crm-mailing-view',
+ 'class' => 'crm-popup',
),
CRM_Core_Action::BROWSE => array(
'name' => ts('Mailing Report'),
'url' => 'civicrm/mailing/report',
- 'qs' => "mid={$values['mailing_id']}&reset=1&cid={$params['contact_id']}&context=mailing",
+ 'qs' => "mid=%%mid%%&reset=1&cid=%%cid%%&context=mailing",
'title' => ts('View Mailing Report'),
)
);
- $contactMailings[$mailingId]['links'] = CRM_Core_Action::formLink($actionLinks);
+ $mailingKey = $values['mailing_id'];
+ if ($hash = CRM_Mailing_BAO_Mailing::getMailingHash($mailingKey)) {
+ $mailingKey = $hash;
+ }
+
+ $contactMailings[$mailingId]['links'] = CRM_Core_Action::formLink(
+ $actionLinks,
+ null,
+ array(
+ 'mid' => $values['mailing_id'],
+ 'cid' => $params['contact_id'],
+ 'mkey' => $mailingKey,
+ ),
+ ts('more'),
+ FALSE,
+ 'mailing.contact.action',
+ 'Mailing',
+ $values['mailing_id']
+ );
}
return $contactMailings;
return civicrm_api('MailingContact', 'getcount', $params);
}
}
-