Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | class CRM_Mailing_Form_ForwardMailing extends CRM_Core_Form { | |
7e8c8317 | 18 | |
00be9182 | 19 | public function preProcess() { |
6a488035 TO |
20 | $job_id = CRM_Utils_Request::retrieve('jid', 'Positive', |
21 | $this, NULL | |
22 | ); | |
23 | $queue_id = CRM_Utils_Request::retrieve('qid', 'Positive', | |
24 | $this, NULL | |
25 | ); | |
26 | $hash = CRM_Utils_Request::retrieve('h', 'String', | |
27 | $this, NULL | |
28 | ); | |
29 | ||
30 | $q = CRM_Mailing_Event_BAO_Queue::verify($job_id, $queue_id, $hash); | |
31 | ||
32 | if ($q == NULL) { | |
33 | ||
25606795 | 34 | // ERROR. |
2a7b8221 | 35 | throw new CRM_Core_Exception(ts('Invalid form parameters.')); |
6a488035 TO |
36 | CRM_Core_Error::statusBounce(ts('Invalid form parameters.')); |
37 | } | |
38 | $mailing = &$q->getMailing(); | |
39 | ||
40 | if ($hash) { | |
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); | |
44 | } | |
45 | ||
25606795 SB |
46 | // Show the subject instead of the name here, since it's being |
47 | // displayed to external contacts/users. | |
6a488035 | 48 | |
be2fb01f | 49 | CRM_Utils_System::setTitle(ts('Forward Mailing: %1', [1 => $mailing->subject])); |
6a488035 TO |
50 | |
51 | $this->set('queue_id', $queue_id); | |
52 | $this->set('job_id', $job_id); | |
53 | $this->set('hash', $hash); | |
54 | } | |
55 | ||
56 | /** | |
fe482240 | 57 | * Build the form object. |
6a488035 TO |
58 | */ |
59 | public function buildQuickForm() { | |
60 | for ($i = 0; $i < 5; $i++) { | |
be2fb01f | 61 | $this->add('text', "email_$i", ts('Email %1', [1 => $i + 1])); |
6a488035 TO |
62 | $this->addRule("email_$i", ts('Email is not valid.'), 'email'); |
63 | } | |
64 | ||
65 | //insert message Text by selecting "Select Template option" | |
be2fb01f | 66 | $this->add('textarea', 'forward_comment', ts('Comment'), ['cols' => '80', 'rows' => '8']); |
5d51a2f9 | 67 | $this->add('wysiwyg', 'html_comment', |
6a488035 | 68 | ts('HTML Message'), |
be2fb01f | 69 | ['cols' => '80', 'rows' => '8'] |
6a488035 TO |
70 | ); |
71 | ||
be2fb01f CW |
72 | $this->addButtons([ |
73 | [ | |
353ffa53 TO |
74 | 'type' => 'next', |
75 | 'name' => ts('Forward'), | |
76 | 'isDefault' => TRUE, | |
be2fb01f | 77 | ], |
be2fb01f | 78 | ]); |
6a488035 TO |
79 | } |
80 | ||
81 | /** | |
82 | * Form submission of new/edit contact is processed. | |
6a488035 TO |
83 | */ |
84 | public function postProcess() { | |
353ffa53 TO |
85 | $queue_id = $this->get('queue_id'); |
86 | $job_id = $this->get('job_id'); | |
87 | $hash = $this->get('hash'); | |
6a488035 TO |
88 | $timeStamp = date('YmdHis'); |
89 | ||
353ffa53 | 90 | $formValues = $this->controller->exportValues($this->_name); |
be2fb01f | 91 | $params = []; |
6a488035 | 92 | $params['body_text'] = $formValues['forward_comment']; |
353ffa53 | 93 | $html_comment = $formValues['html_comment']; |
6a488035 TO |
94 | $params['body_html'] = str_replace('%7B', '{', str_replace('%7D', '}', $html_comment)); |
95 | ||
be2fb01f | 96 | $emails = []; |
6a488035 TO |
97 | for ($i = 0; $i < 5; $i++) { |
98 | $email = $this->controller->exportValue($this->_name, "email_$i"); | |
99 | if (!empty($email)) { | |
100 | $emails[] = $email; | |
101 | } | |
102 | } | |
103 | ||
104 | $forwarded = NULL; | |
105 | foreach ($emails as $email) { | |
be2fb01f | 106 | $params = [ |
6a488035 TO |
107 | 'version' => 3, |
108 | 'job_id' => $job_id, | |
109 | 'event_queue_id' => $queue_id, | |
110 | 'hash' => $hash, | |
111 | 'email' => $email, | |
112 | 'time_stamp' => $timeStamp, | |
113 | 'fromEmail' => $this->_fromEmail, | |
114 | 'params' => $params, | |
be2fb01f | 115 | ]; |
6a488035 TO |
116 | $result = civicrm_api('Mailing', 'event_forward', $params); |
117 | if (!civicrm_error($result)) { | |
118 | $forwarded++; | |
119 | } | |
120 | } | |
121 | ||
be2fb01f | 122 | $status = ts('Mailing is not forwarded to the given email address.', [ |
7e8c8317 SL |
123 | 'count' => count($emails), |
124 | 'plural' => 'Mailing is not forwarded to the given email addresses.', | |
125 | ]); | |
6a488035 | 126 | if ($forwarded) { |
be2fb01f | 127 | $status = ts('Mailing is forwarded successfully to %count email address.', [ |
7e8c8317 SL |
128 | 'count' => $forwarded, |
129 | 'plural' => 'Mailing is forwarded successfully to %count email addresses.', | |
130 | ]); | |
6a488035 TO |
131 | } |
132 | ||
133 | CRM_Utils_System::setUFMessage($status); | |
134 | ||
135 | // always redirect to front page of url | |
136 | $session = CRM_Core_Session::singleton(); | |
137 | $config = CRM_Core_Config::singleton(); | |
138 | $session->pushUserContext($config->userFrameworkBaseURL); | |
139 | } | |
96025800 | 140 | |
6a488035 | 141 | } |