commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / CRM / Mailing / Form / Settings.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2015
32 * $Id$
33 *
34 */
35
36 /**
37 * This file is used to build the form configuring mailing details
38 */
39 class CRM_Mailing_Form_Settings extends CRM_Core_Form {
40
41 /**
42 * Set variables up before form is built.
43 *
44 * @return void
45 */
46 public function preProcess() {
47 //when user come from search context.
48 $ssID = $this->get('ssID');
49 $this->assign('ssid', $ssID);
50 $this->_searchBasedMailing = CRM_Contact_Form_Search::isSearchContext($this->get('context'));
51 if (CRM_Contact_Form_Search::isSearchContext($this->get('context')) && !$ssID) {
52 $params = array();
53 $result = CRM_Core_BAO_PrevNextCache::getSelectedContacts();
54 $this->assign("value", $result);
55 }
56 }
57
58 /**
59 * Set default values for the form.
60 * the default values are retrieved from the database
61 *
62 *
63 * @return void
64 */
65 public function setDefaultValues() {
66 $mailingID = CRM_Utils_Request::retrieve('mid', 'Integer', $this, FALSE, NULL);
67 // CRM-14716 - Pick up mailingID from session since most of the time it's not in the URL
68 if (!$mailingID) {
69 $mailingID = $this->get('mailing_id');
70 }
71 $count = $this->get('count');
72 $this->assign('count', $count);
73 $defaults = array();
74
75 $componentFields = array(
76 'reply_id' => 'Reply',
77 'optout_id' => 'OptOut',
78 'unsubscribe_id' => 'Unsubscribe',
79 'resubscribe_id' => 'Resubscribe',
80 );
81
82 foreach ($componentFields as $componentVar => $componentType) {
83 $defaults[$componentVar] = CRM_Mailing_PseudoConstant::defaultComponent($componentType, '');
84 }
85
86 if ($mailingID) {
87 $dao = new CRM_Mailing_DAO_Mailing();
88 $dao->id = $mailingID;
89 $dao->find(TRUE);
90 // override_verp must be flipped, as in 3.2 we reverted
91 // its meaning to ‘should CiviMail manage replies?’ – i.e.,
92 // ‘should it *not* override Reply-To: with VERP-ed address?’
93 $dao->override_verp = !$dao->override_verp;
94 $dao->storeValues($dao, $defaults);
95 $defaults['visibility'] = $dao->visibility;
96 }
97
98 return $defaults;
99 }
100
101 /**
102 * Build the form object.
103 *
104 * @return void
105 */
106 public function buildQuickForm() {
107
108 $this->addElement('checkbox', 'override_verp', ts('Track Replies?'));
109
110 $defaults['override_verp'] = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
111 'track_civimail_replies', NULL, FALSE
112 );
113
114 $this->add('checkbox', 'forward_replies', ts('Forward Replies?'));
115 $defaults['forward_replies'] = FALSE;
116
117 $this->add('checkbox', 'url_tracking', ts('Track Click-throughs?'));
118 $defaults['url_tracking'] = TRUE;
119
120 $this->add('checkbox', 'open_tracking', ts('Track Opens?'));
121 $defaults['open_tracking'] = TRUE;
122
123 $this->add('checkbox', 'auto_responder', ts('Auto-respond to Replies?'));
124 $defaults['auto_responder'] = FALSE;
125
126 $this->add('select', 'visibility', ts('Mailing Visibility'), CRM_Core_SelectValues::groupVisibility(), TRUE);
127
128 $this->add('select', 'reply_id', ts('Auto-responder'),
129 CRM_Mailing_PseudoConstant::component('Reply'), TRUE
130 );
131
132 $this->add('select', 'unsubscribe_id', ts('Unsubscribe Message'),
133 CRM_Mailing_PseudoConstant::component('Unsubscribe'), TRUE
134 );
135
136 $this->add('select', 'resubscribe_id', ts('Resubscribe Message'),
137 CRM_Mailing_PseudoConstant::component('Resubscribe'), TRUE
138 );
139
140 $this->add('select', 'optout_id', ts('Opt-out Message'),
141 CRM_Mailing_PseudoConstant::component('OptOut'), TRUE
142 );
143
144 $buttons = array(
145 array(
146 'type' => 'back',
147 'name' => ts('Previous'),
148 ),
149 array(
150 'type' => 'next',
151 'name' => ts('Next'),
152 'spacing' => '&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;',
153 'isDefault' => TRUE,
154 ),
155 array(
156 'type' => 'submit',
157 'name' => ts('Save & Continue Later'),
158 ),
159 array(
160 'type' => 'cancel',
161 'name' => ts('Cancel'),
162 ),
163 );
164
165 $this->addButtons($buttons);
166
167 $this->setDefaults($defaults);
168 }
169
170 public function postProcess() {
171 $params = $ids = array();
172
173 $session = CRM_Core_Session::singleton();
174 $params['created_id'] = $session->get('userID');
175
176 $uploadParams = array('reply_id', 'unsubscribe_id', 'optout_id', 'resubscribe_id');
177 $uploadParamsBoolean = array('override_verp', 'forward_replies', 'url_tracking', 'open_tracking', 'auto_responder');
178
179 $qf_Settings_submit = $this->controller->exportValue($this->_name, '_qf_Settings_submit');
180
181 foreach ($uploadParams as $key) {
182 $params[$key] = $this->controller->exportvalue($this->_name, $key);
183 $this->set($key, $this->controller->exportvalue($this->_name, $key));
184 }
185
186 foreach ($uploadParamsBoolean as $key) {
187 if ($this->controller->exportvalue($this->_name, $key)) {
188 $params[$key] = TRUE;
189 }
190 else {
191 $params[$key] = FALSE;
192 }
193 $this->set($key, $this->controller->exportvalue($this->_name, $key));
194 }
195
196 $params['visibility'] = $this->controller->exportvalue($this->_name, 'visibility');
197
198 // override_verp must be flipped, as in 3.2 we reverted
199 // its meaning to ‘should CiviMail manage replies?’ – i.e.,
200 // ‘should it *not* override Reply-To: with VERP-ed address?’
201 $params['override_verp'] = !$params['override_verp'];
202
203 $ids['mailing_id'] = $this->get('mailing_id');
204
205 // update mailing
206 CRM_Mailing_BAO_Mailing::create($params, $ids);
207
208 if ($qf_Settings_submit) {
209 //when user perform mailing from search context
210 //redirect it to search result CRM-3711.
211 $ssID = $this->get('ssID');
212 if ($ssID && $this->_searchBasedMailing) {
213 if ($this->_action == CRM_Core_Action::BASIC) {
214 $fragment = 'search';
215 }
216 elseif ($this->_action == CRM_Core_Action::PROFILE) {
217 $fragment = 'search/builder';
218 }
219 elseif ($this->_action == CRM_Core_Action::ADVANCED) {
220 $fragment = 'search/advanced';
221 }
222 else {
223 $fragment = 'search/custom';
224 }
225
226 $context = $this->get('context');
227 if (!CRM_Contact_Form_Search::isSearchContext($context)) {
228 $context = 'search';
229 }
230 $urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}";
231 $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
232 if (CRM_Utils_Rule::qfKey($qfKey)) {
233 $urlParams .= "&qfKey=$qfKey";
234 }
235
236 $draftURL = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
237 $status = ts("You can continue later by clicking the 'Continue' action to resume working on it.<br />From <a href='%1'>Draft and Unscheduled Mailings</a>.", array(1 => $draftURL));
238
239 // Redirect user to search.
240 $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $urlParams);
241 }
242 else {
243 $status = ts("Click the 'Continue' action to resume working on it.");
244 $url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
245 }
246 CRM_Core_Session::setStatus($status, ts('Mailing Saved'), 'success');
247 CRM_Utils_System::redirect($url);
248 }
249 }
250
251 /**
252 * Display Name of the form.
253 *
254 *
255 * @return string
256 */
257 public function getTitle() {
258 return ts('Track and Respond');
259 }
260
261 }