Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This implements the profile page for all contacts. It uses a selector | |
38 | * object to do the actual dispay. The fields displayd are controlled by | |
39 | * the admin | |
40 | */ | |
41 | class CRM_Mailing_Page_Browse extends CRM_Core_Page { | |
42 | ||
43 | /** | |
fe482240 | 44 | * All the fields that are listings related. |
6a488035 TO |
45 | * |
46 | * @var array | |
6a488035 TO |
47 | */ |
48 | protected $_fields; | |
49 | ||
50 | /** | |
100fef9d | 51 | * The mailing id of the mailing we're operating on |
6a488035 TO |
52 | * |
53 | * @int | |
6a488035 TO |
54 | */ |
55 | protected $_mailingId; | |
56 | ||
57 | /** | |
100fef9d | 58 | * The action that we are performing (in CRM_Core_Action terms) |
6a488035 TO |
59 | * |
60 | * @int | |
6a488035 TO |
61 | */ |
62 | protected $_action; | |
63 | ||
64 | public $_sortByCharacter; | |
65 | ||
66 | public $_unscheduled; | |
67 | public $_archived; | |
68 | ||
69 | /** | |
fe482240 | 70 | * Scheduled mailing. |
6a488035 TO |
71 | * |
72 | * @boolean | |
6a488035 TO |
73 | */ |
74 | public $_scheduled; | |
75 | ||
76 | public $_sms; | |
77 | ||
78 | /** | |
79 | * Heart of the viewing process. The runner gets all the meta data for | |
80 | * the contact and calls the appropriate type of page to view. | |
81 | * | |
82 | * @return void | |
6a488035 | 83 | */ |
00be9182 | 84 | public function preProcess() { |
6a488035 | 85 | $this->_unscheduled = $this->_archived = $archiveLinks = FALSE; |
353ffa53 TO |
86 | $this->_mailingId = CRM_Utils_Request::retrieve('mid', 'Positive', $this); |
87 | $this->_sms = CRM_Utils_Request::retrieve('sms', 'Positive', $this); | |
6a488035 TO |
88 | $this->assign('sms', $this->_sms); |
89 | // check that the user has permission to access mailing id | |
90 | CRM_Mailing_BAO_Mailing::checkPermission($this->_mailingId); | |
91 | ||
92 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this); | |
93 | $this->assign('action', $this->_action); | |
94 | ||
95 | $showLinks = TRUE; | |
96 | if (CRM_Mailing_Info::workflowEnabled()) { | |
97 | if (CRM_Core_Permission::check('create mailings')) { | |
98 | $archiveLinks = TRUE; | |
99 | } | |
100 | if (!CRM_Core_Permission::check('access CiviMail') && | |
101 | !CRM_Core_Permission::check('create mailings') | |
102 | ) { | |
103 | $showLinks = FALSE; | |
104 | } | |
105 | } | |
106 | $this->assign('showLinks', $showLinks); | |
107 | if (CRM_Core_Permission::check('access CiviMail')) { | |
108 | $archiveLinks = TRUE; | |
109 | } | |
110 | if ($archiveLinks == TRUE) { | |
111 | $this->assign('archiveLinks', $archiveLinks); | |
112 | } | |
113 | } | |
114 | ||
115 | /** | |
100fef9d | 116 | * Run this page (figure out the action needed and perform it). |
6a488035 TO |
117 | * |
118 | * @return void | |
119 | */ | |
00be9182 | 120 | public function run() { |
6a488035 TO |
121 | $this->preProcess(); |
122 | ||
39eb89f4 | 123 | $newArgs = func_get_args(); |
78e6cd48 RN |
124 | // since we want only first function argument |
125 | $newArgs = $newArgs[0]; | |
6a488035 TO |
126 | if (isset($_GET['runJobs']) || CRM_Utils_Array::value('2', $newArgs) == 'queue') { |
127 | $config = CRM_Core_Config::singleton(); | |
9da8dc8c | 128 | CRM_Mailing_BAO_MailingJob::runJobs_pre($config->mailerJobSize); |
129 | CRM_Mailing_BAO_MailingJob::runJobs(); | |
130 | CRM_Mailing_BAO_MailingJob::runJobs_post(); | |
6a488035 TO |
131 | } |
132 | ||
e7483cbe J |
133 | $this->_sortByCharacter |
134 | = CRM_Utils_Request::retrieve('sortByCharacter', 'String', $this); | |
6a488035 | 135 | |
6a488035 TO |
136 | // CRM-11920 all should set sortByCharacter to null, not empty string |
137 | if (strtolower($this->_sortByCharacter) == 'all' || !empty($_POST)) { | |
35f7561f TO |
138 | $this->_sortByCharacter = NULL; |
139 | $this->set('sortByCharacter', NULL); | |
6a488035 TO |
140 | } |
141 | ||
142 | if (CRM_Utils_Array::value(3, $newArgs) == 'unscheduled') { | |
143 | $this->_unscheduled = TRUE; | |
144 | } | |
145 | $this->set('unscheduled', $this->_unscheduled); | |
146 | ||
147 | if (CRM_Utils_Array::value(3, $newArgs) == 'archived') { | |
148 | $this->_archived = TRUE; | |
149 | } | |
150 | $this->set('archived', $this->_archived); | |
151 | ||
152 | if (CRM_Utils_Array::value(3, $newArgs) == 'scheduled') { | |
153 | $this->_scheduled = TRUE; | |
154 | } | |
155 | $this->set('scheduled', $this->_scheduled); | |
156 | ||
157 | $this->_createdId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE, 0); | |
158 | if ($this->_createdId) { | |
159 | $this->set('createdId', $this->_createdId); | |
160 | } | |
161 | ||
162 | if ($this->_sms) { | |
163 | $this->set('sms', $this->_sms); | |
164 | } | |
165 | ||
166 | $session = CRM_Core_Session::singleton(); | |
167 | $context = $session->readUserContext(); | |
168 | ||
169 | if ($this->_action & CRM_Core_Action::DISABLE) { | |
170 | if (CRM_Utils_Request::retrieve('confirmed', 'Boolean', $this)) { | |
9da8dc8c | 171 | CRM_Mailing_BAO_MailingJob::cancel($this->_mailingId); |
6a488035 TO |
172 | CRM_Utils_System::redirect($context); |
173 | } | |
174 | else { | |
175 | $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse', | |
176 | ts('Cancel Mailing'), | |
177 | $this->_action | |
178 | ); | |
179 | $controller->setEmbedded(TRUE); | |
180 | $controller->run(); | |
181 | } | |
182 | } | |
183 | elseif ($this->_action & CRM_Core_Action::DELETE) { | |
184 | if (CRM_Utils_Request::retrieve('confirmed', 'Boolean', $this)) { | |
185 | ||
186 | // check for action permissions. | |
187 | if (!CRM_Core_Permission::checkActionPermission('CiviMail', $this->_action)) { | |
0499b0ad | 188 | CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); |
6a488035 TO |
189 | } |
190 | ||
191 | CRM_Mailing_BAO_Mailing::del($this->_mailingId); | |
192 | CRM_Utils_System::redirect($context); | |
193 | } | |
194 | else { | |
195 | $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse', | |
196 | ts('Delete Mailing'), | |
197 | $this->_action | |
198 | ); | |
199 | $controller->setEmbedded(TRUE); | |
200 | $controller->run(); | |
201 | } | |
202 | } | |
203 | elseif ($this->_action & CRM_Core_Action::RENEW) { | |
204 | //archive this mailing, CRM-3752. | |
205 | if (CRM_Utils_Request::retrieve('confirmed', 'Boolean', $this)) { | |
206 | //set is_archived to 1 | |
207 | CRM_Core_DAO::setFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingId, 'is_archived', TRUE); | |
208 | CRM_Utils_System::redirect($context); | |
209 | } | |
210 | else { | |
211 | $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse', | |
212 | ts('Archive Mailing'), | |
213 | $this->_action | |
214 | ); | |
215 | $controller->setEmbedded(TRUE); | |
216 | $controller->run(); | |
217 | } | |
218 | } | |
219 | ||
220 | $selector = new CRM_Mailing_Selector_Browse(); | |
221 | $selector->setParent($this); | |
222 | ||
223 | $controller = new CRM_Core_Selector_Controller( | |
224 | $selector, | |
225 | $this->get(CRM_Utils_Pager::PAGE_ID), | |
226 | $this->get(CRM_Utils_Sort::SORT_ID) . $this->get(CRM_Utils_Sort::SORT_DIRECTION), | |
227 | CRM_Core_Action::VIEW, | |
228 | $this, | |
229 | CRM_Core_Selector_Controller::TEMPLATE | |
230 | ); | |
231 | ||
6a488035 TO |
232 | $controller->setEmbedded(TRUE); |
233 | $controller->run(); | |
234 | ||
235 | //hack to display results as per search | |
236 | $rows = $controller->getRows($controller); | |
237 | ||
238 | $this->assign('rows', $rows); | |
239 | ||
240 | $urlParams = 'reset=1'; | |
241 | $urlString = 'civicrm/mailing/browse'; | |
242 | if ($this->get('sms')) { | |
243 | $urlParams .= '&sms=1'; | |
244 | } | |
245 | if (CRM_Utils_Array::value(3, $newArgs) == 'unscheduled') { | |
246 | $urlString .= '/unscheduled'; | |
247 | $urlParams .= '&scheduled=false'; | |
248 | $this->assign('unscheduled', TRUE); | |
6a488035 TO |
249 | } |
250 | elseif (CRM_Utils_Array::value(3, $newArgs) == 'archived') { | |
251 | $urlString .= '/archived'; | |
252 | $this->assign('archived', TRUE); | |
6a488035 TO |
253 | } |
254 | elseif (CRM_Utils_Array::value(3, $newArgs) == 'scheduled') { | |
255 | $urlString .= '/scheduled'; | |
256 | $urlParams .= '&scheduled=true'; | |
6a488035 | 257 | } |
f6df2c32 DS |
258 | if ($this->get('sms')) { |
259 | CRM_Utils_System::setTitle(ts('Find Mass SMS')); | |
6a488035 TO |
260 | } |
261 | ||
262 | $crmRowCount = CRM_Utils_Request::retrieve('crmRowCount', 'Integer', CRM_Core_DAO::$_nullObject); | |
263 | $crmPID = CRM_Utils_Request::retrieve('crmPID', 'Integer', CRM_Core_DAO::$_nullObject); | |
264 | if ($crmRowCount || $crmPID) { | |
265 | $urlParams .= '&force=1'; | |
266 | $urlParams .= $crmRowCount ? '&crmRowCount=' . $crmRowCount : ''; | |
267 | $urlParams .= $crmPID ? '&crmPID=' . $crmPID : ''; | |
268 | } | |
269 | ||
270 | $crmSID = CRM_Utils_Request::retrieve('crmSID', 'Integer', CRM_Core_DAO::$_nullObject); | |
271 | if ($crmSID) { | |
272 | $urlParams .= '&crmSID=' . $crmSID; | |
273 | } | |
274 | ||
275 | $session = CRM_Core_Session::singleton(); | |
276 | $url = CRM_Utils_System::url($urlString, $urlParams); | |
277 | $session->pushUserContext($url); | |
278 | ||
279 | //CRM-6862 -run form cotroller after | |
280 | //selector, since it erase $_POST | |
281 | $this->search(); | |
282 | ||
283 | return parent::run(); | |
284 | } | |
285 | ||
00be9182 | 286 | public function search() { |
35f7561f | 287 | if ($this->_action & (CRM_Core_Action::ADD | |
6a488035 TO |
288 | CRM_Core_Action::UPDATE |
289 | ) | |
290 | ) { | |
291 | return; | |
292 | } | |
293 | ||
294 | $form = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Search', | |
295 | ts('Search Mailings'), | |
296 | CRM_Core_Action::ADD | |
297 | ); | |
298 | $form->setEmbedded(TRUE); | |
299 | $form->setParent($this); | |
300 | $form->process(); | |
301 | $form->run(); | |
302 | } | |
303 | ||
e0ef6999 | 304 | /** |
c490a46a | 305 | * @param array $params |
e0ef6999 EM |
306 | * @param bool $sortBy |
307 | * | |
308 | * @return string | |
309 | */ | |
00be9182 | 310 | public function whereClause(&$params, $sortBy = TRUE) { |
6a488035 TO |
311 | $values = array(); |
312 | ||
313 | $clauses = array(); | |
314 | $title = $this->get('mailing_name'); | |
315 | //echo " name=$title "; | |
316 | if ($title) { | |
317 | $clauses[] = 'name LIKE %1'; | |
318 | if (strpos($title, '%') !== FALSE) { | |
319 | $params[1] = array($title, 'String', FALSE); | |
320 | } | |
321 | else { | |
322 | $params[1] = array($title, 'String', TRUE); | |
323 | } | |
324 | } | |
325 | ||
326 | if ($sortBy && | |
327 | $this->_sortByCharacter !== NULL | |
328 | ) { | |
329 | $clauses[] = "name LIKE '" . strtolower(CRM_Core_DAO::escapeWildCardString($this->_sortByCharacter)) . "%'"; | |
330 | } | |
331 | ||
332 | $campainIds = $this->get('campaign_id'); | |
333 | if (!CRM_Utils_System::isNull($campainIds)) { | |
334 | if (!is_array($campainIds)) { | |
335 | $campaignIds = array($campaignIds); | |
336 | } | |
337 | $clauses[] = '( campaign_id IN ( ' . implode(' , ', array_values($campainIds)) . ' ) )'; | |
338 | } | |
339 | ||
340 | return implode(' AND ', $clauses); | |
341 | } | |
96025800 | 342 | |
6a488035 | 343 | } |