3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Mailing_Form_ForwardMailing
extends CRM_Core_Form
{
19 public function preProcess() {
20 $job_id = CRM_Utils_Request
::retrieve('jid', 'Positive',
23 $queue_id = CRM_Utils_Request
::retrieve('qid', 'Positive',
26 $hash = CRM_Utils_Request
::retrieve('h', 'String',
30 $q = CRM_Mailing_Event_BAO_Queue
::verify($job_id, $queue_id, $hash);
35 throw new CRM_Core_Exception(ts('Invalid form parameters.'));
36 CRM_Core_Error
::statusBounce(ts('Invalid form parameters.'));
38 $mailing = &$q->getMailing();
41 $emailId = CRM_Core_DAO
::getfieldValue('CRM_Mailing_Event_DAO_Queue', $hash, 'email_id', 'hash');
42 $this->_fromEmail
= $fromEmail = CRM_Core_DAO
::getfieldValue('CRM_Core_DAO_Email', $emailId, 'email');
43 $this->assign('fromEmail', $fromEmail);
46 // Show the subject instead of the name here, since it's being
47 // displayed to external contacts/users.
49 CRM_Utils_System
::setTitle(ts('Forward Mailing: %1', [1 => $mailing->subject
]));
51 $this->set('queue_id', $queue_id);
52 $this->set('job_id', $job_id);
53 $this->set('hash', $hash);
57 * Build the form object.
59 public function buildQuickForm() {
60 for ($i = 0; $i < 5; $i++
) {
61 $this->add('text', "email_$i", ts('Email %1', [1 => $i +
1]));
62 $this->addRule("email_$i", ts('Email is not valid.'), 'email');
65 //insert message Text by selecting "Select Template option"
66 $this->add('textarea', 'forward_comment', ts('Comment'), ['cols' => '80', 'rows' => '8']);
67 $this->add('wysiwyg', 'html_comment',
69 ['cols' => '80', 'rows' => '8']
75 'name' => ts('Forward'),
80 'name' => ts('Cancel'),
86 * Form submission of new/edit contact is processed.
88 public function postProcess() {
89 $queue_id = $this->get('queue_id');
90 $job_id = $this->get('job_id');
91 $hash = $this->get('hash');
92 $timeStamp = date('YmdHis');
94 $formValues = $this->controller
->exportValues($this->_name
);
96 $params['body_text'] = $formValues['forward_comment'];
97 $html_comment = $formValues['html_comment'];
98 $params['body_html'] = str_replace('%7B', '{', str_replace('%7D', '}', $html_comment));
101 for ($i = 0; $i < 5; $i++
) {
102 $email = $this->controller
->exportValue($this->_name
, "email_$i");
103 if (!empty($email)) {
109 foreach ($emails as $email) {
113 'event_queue_id' => $queue_id,
116 'time_stamp' => $timeStamp,
117 'fromEmail' => $this->_fromEmail
,
120 $result = civicrm_api('Mailing', 'event_forward', $params);
121 if (!civicrm_error($result)) {
126 $status = ts('Mailing is not forwarded to the given email address.', [
127 'count' => count($emails),
128 'plural' => 'Mailing is not forwarded to the given email addresses.',
131 $status = ts('Mailing is forwarded successfully to %count email address.', [
132 'count' => $forwarded,
133 'plural' => 'Mailing is forwarded successfully to %count email addresses.',
137 CRM_Utils_System
::setUFMessage($status);
139 // always redirect to front page of url
140 $session = CRM_Core_Session
::singleton();
141 $config = CRM_Core_Config
::singleton();
142 $session->pushUserContext($config->userFrameworkBaseURL
);