Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
32 | */ |
33 | class CRM_Mailing_Form_ForwardMailing extends CRM_Core_Form { | |
7e8c8317 | 34 | |
00be9182 | 35 | public function preProcess() { |
6a488035 TO |
36 | $job_id = CRM_Utils_Request::retrieve('jid', 'Positive', |
37 | $this, NULL | |
38 | ); | |
39 | $queue_id = CRM_Utils_Request::retrieve('qid', 'Positive', | |
40 | $this, NULL | |
41 | ); | |
42 | $hash = CRM_Utils_Request::retrieve('h', 'String', | |
43 | $this, NULL | |
44 | ); | |
45 | ||
46 | $q = CRM_Mailing_Event_BAO_Queue::verify($job_id, $queue_id, $hash); | |
47 | ||
48 | if ($q == NULL) { | |
49 | ||
25606795 | 50 | // ERROR. |
6a488035 TO |
51 | CRM_Core_Error::fatal(ts('Invalid form parameters.')); |
52 | CRM_Core_Error::statusBounce(ts('Invalid form parameters.')); | |
53 | } | |
54 | $mailing = &$q->getMailing(); | |
55 | ||
56 | if ($hash) { | |
57 | $emailId = CRM_Core_DAO::getfieldValue('CRM_Mailing_Event_DAO_Queue', $hash, 'email_id', 'hash'); | |
58 | $this->_fromEmail = $fromEmail = CRM_Core_DAO::getfieldValue('CRM_Core_DAO_Email', $emailId, 'email'); | |
59 | $this->assign('fromEmail', $fromEmail); | |
60 | } | |
61 | ||
25606795 SB |
62 | // Show the subject instead of the name here, since it's being |
63 | // displayed to external contacts/users. | |
6a488035 | 64 | |
be2fb01f | 65 | CRM_Utils_System::setTitle(ts('Forward Mailing: %1', [1 => $mailing->subject])); |
6a488035 TO |
66 | |
67 | $this->set('queue_id', $queue_id); | |
68 | $this->set('job_id', $job_id); | |
69 | $this->set('hash', $hash); | |
70 | } | |
71 | ||
72 | /** | |
fe482240 | 73 | * Build the form object. |
6a488035 TO |
74 | */ |
75 | public function buildQuickForm() { | |
76 | for ($i = 0; $i < 5; $i++) { | |
be2fb01f | 77 | $this->add('text', "email_$i", ts('Email %1', [1 => $i + 1])); |
6a488035 TO |
78 | $this->addRule("email_$i", ts('Email is not valid.'), 'email'); |
79 | } | |
80 | ||
81 | //insert message Text by selecting "Select Template option" | |
be2fb01f | 82 | $this->add('textarea', 'forward_comment', ts('Comment'), ['cols' => '80', 'rows' => '8']); |
5d51a2f9 | 83 | $this->add('wysiwyg', 'html_comment', |
6a488035 | 84 | ts('HTML Message'), |
be2fb01f | 85 | ['cols' => '80', 'rows' => '8'] |
6a488035 TO |
86 | ); |
87 | ||
be2fb01f CW |
88 | $this->addButtons([ |
89 | [ | |
353ffa53 TO |
90 | 'type' => 'next', |
91 | 'name' => ts('Forward'), | |
92 | 'isDefault' => TRUE, | |
be2fb01f CW |
93 | ], |
94 | [ | |
353ffa53 TO |
95 | 'type' => 'cancel', |
96 | 'name' => ts('Cancel'), | |
be2fb01f CW |
97 | ], |
98 | ]); | |
6a488035 TO |
99 | } |
100 | ||
101 | /** | |
102 | * Form submission of new/edit contact is processed. | |
6a488035 TO |
103 | */ |
104 | public function postProcess() { | |
353ffa53 TO |
105 | $queue_id = $this->get('queue_id'); |
106 | $job_id = $this->get('job_id'); | |
107 | $hash = $this->get('hash'); | |
6a488035 TO |
108 | $timeStamp = date('YmdHis'); |
109 | ||
353ffa53 | 110 | $formValues = $this->controller->exportValues($this->_name); |
be2fb01f | 111 | $params = []; |
6a488035 | 112 | $params['body_text'] = $formValues['forward_comment']; |
353ffa53 | 113 | $html_comment = $formValues['html_comment']; |
6a488035 TO |
114 | $params['body_html'] = str_replace('%7B', '{', str_replace('%7D', '}', $html_comment)); |
115 | ||
be2fb01f | 116 | $emails = []; |
6a488035 TO |
117 | for ($i = 0; $i < 5; $i++) { |
118 | $email = $this->controller->exportValue($this->_name, "email_$i"); | |
119 | if (!empty($email)) { | |
120 | $emails[] = $email; | |
121 | } | |
122 | } | |
123 | ||
124 | $forwarded = NULL; | |
125 | foreach ($emails as $email) { | |
be2fb01f | 126 | $params = [ |
6a488035 TO |
127 | 'version' => 3, |
128 | 'job_id' => $job_id, | |
129 | 'event_queue_id' => $queue_id, | |
130 | 'hash' => $hash, | |
131 | 'email' => $email, | |
132 | 'time_stamp' => $timeStamp, | |
133 | 'fromEmail' => $this->_fromEmail, | |
134 | 'params' => $params, | |
be2fb01f | 135 | ]; |
6a488035 TO |
136 | $result = civicrm_api('Mailing', 'event_forward', $params); |
137 | if (!civicrm_error($result)) { | |
138 | $forwarded++; | |
139 | } | |
140 | } | |
141 | ||
be2fb01f | 142 | $status = ts('Mailing is not forwarded to the given email address.', [ |
7e8c8317 SL |
143 | 'count' => count($emails), |
144 | 'plural' => 'Mailing is not forwarded to the given email addresses.', | |
145 | ]); | |
6a488035 | 146 | if ($forwarded) { |
be2fb01f | 147 | $status = ts('Mailing is forwarded successfully to %count email address.', [ |
7e8c8317 SL |
148 | 'count' => $forwarded, |
149 | 'plural' => 'Mailing is forwarded successfully to %count email addresses.', | |
150 | ]); | |
6a488035 TO |
151 | } |
152 | ||
153 | CRM_Utils_System::setUFMessage($status); | |
154 | ||
155 | // always redirect to front page of url | |
156 | $session = CRM_Core_Session::singleton(); | |
157 | $config = CRM_Core_Config::singleton(); | |
158 | $session->pushUserContext($config->userFrameworkBaseURL); | |
159 | } | |
96025800 | 160 | |
6a488035 | 161 | } |