3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
35 * This implements the profile page for all contacts. It uses a selector
36 * object to do the actual dispay. The fields displayd are controlled by
39 class CRM_Mailing_Page_Browse
extends CRM_Core_Page
{
42 * All the fields that are listings related.
49 * The mailing id of the mailing we're operating on
53 protected $_mailingId;
56 * The action that we are performing (in CRM_Core_Action terms)
62 public $_sortByCharacter;
77 * Heart of the viewing process. The runner gets all the meta data for
78 * the contact and calls the appropriate type of page to view.
80 public function preProcess() {
81 Civi
::resources()->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header');
83 $this->_unscheduled
= $this->_archived
= $archiveLinks = FALSE;
84 $this->_mailingId
= CRM_Utils_Request
::retrieve('mid', 'Positive', $this);
85 $this->_sms
= CRM_Utils_Request
::retrieve('sms', 'Positive', $this);
88 // if this is an SMS page, check that the user has permission to browse SMS
89 if (!CRM_Core_Permission
::check('send SMS')) {
90 CRM_Core_Error
::statusBounce(ts('You do not have permission to send SMS'));
94 // If this is not an SMS page, check that the user has an appropriate
95 // permission (specific permissions have been copied from
96 // CRM/Mailing/xml/Menu/Mailing.xml)
97 if (!CRM_Core_Permission
::check([['access CiviMail', 'approve mailings', 'create mailings', 'schedule mailings']])) {
98 CRM_Core_Error
::statusBounce(ts('You do not have permission to view this page.'));
102 $this->assign('sms', $this->_sms
);
103 // check that the user has permission to access mailing id
104 CRM_Mailing_BAO_Mailing
::checkPermission($this->_mailingId
);
106 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this);
107 $this->assign('action', $this->_action
);
110 if (CRM_Mailing_Info
::workflowEnabled()) {
111 if (CRM_Core_Permission
::check('create mailings')) {
112 $archiveLinks = TRUE;
114 if (!CRM_Core_Permission
::check('access CiviMail') &&
115 !CRM_Core_Permission
::check('create mailings')
120 $this->assign('showLinks', $showLinks);
121 if (CRM_Core_Permission
::check('access CiviMail')) {
122 $archiveLinks = TRUE;
124 if ($archiveLinks == TRUE) {
125 $this->assign('archiveLinks', $archiveLinks);
130 * Run this page (figure out the action needed and perform it).
132 public function run() {
135 $newArgs = func_get_args();
136 // since we want only first function argument
137 $newArgs = $newArgs[0];
138 if (isset($_GET['runJobs']) || CRM_Utils_Array
::value('2', $newArgs) == 'queue') {
139 $mailerJobSize = Civi
::settings()->get('mailerJobSize');
140 CRM_Mailing_BAO_MailingJob
::runJobs_pre($mailerJobSize);
141 CRM_Mailing_BAO_MailingJob
::runJobs();
142 CRM_Mailing_BAO_MailingJob
::runJobs_post();
145 $this->_sortByCharacter
146 = CRM_Utils_Request
::retrieve('sortByCharacter', 'String', $this);
148 // CRM-11920 all should set sortByCharacter to null, not empty string
149 if (strtolower($this->_sortByCharacter
) == 'all' ||
!empty($_POST)) {
150 $this->_sortByCharacter
= NULL;
151 $this->set('sortByCharacter', NULL);
154 if (CRM_Utils_Array
::value(3, $newArgs) == 'unscheduled') {
155 $this->_unscheduled
= TRUE;
157 $this->set('unscheduled', $this->_unscheduled
);
159 if (CRM_Utils_Array
::value(3, $newArgs) == 'archived') {
160 $this->_archived
= TRUE;
162 $this->set('archived', $this->_archived
);
164 if (CRM_Utils_Array
::value(3, $newArgs) == 'scheduled') {
165 $this->_scheduled
= TRUE;
167 $this->set('scheduled', $this->_scheduled
);
169 $this->_createdId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, FALSE, 0);
170 if ($this->_createdId
) {
171 $this->set('createdId', $this->_createdId
);
175 $this->set('sms', $this->_sms
);
178 $session = CRM_Core_Session
::singleton();
179 $context = $session->readUserContext();
181 if ($this->_action
& CRM_Core_Action
::DISABLE
) {
182 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean', $this)) {
183 CRM_Mailing_BAO_MailingJob
::cancel($this->_mailingId
);
184 CRM_Core_Session
::setStatus(ts('The mailing has been canceled.'), ts('Canceled'), 'success');
185 CRM_Utils_System
::redirect($context);
188 $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse',
189 ts('Cancel Mailing'),
192 $controller->setEmbedded(TRUE);
196 elseif ($this->_action
& CRM_Core_Action
::CLOSE
) {
197 if (!CRM_Core_Permission
::checkActionPermission('CiviMail', CRM_Core_Action
::CLOSE
)) {
198 CRM_Core_Error
::statusBounce(ts('You do not have permission to access this page.'));
200 CRM_Mailing_BAO_MailingJob
::pause($this->_mailingId
);
201 CRM_Core_Session
::setStatus(ts('The mailing has been paused. Active message deliveries may continue for a few minutes, but CiviMail will not begin delivery of any more batches.'), ts('Paused'), 'success');
202 CRM_Utils_System
::redirect($context);
204 elseif ($this->_action
& CRM_Core_Action
::REOPEN
) {
205 if (!CRM_Core_Permission
::checkActionPermission('CiviMail', CRM_Core_Action
::CLOSE
)) {
206 CRM_Core_Error
::statusBounce(ts('You do not have permission to access this page.'));
208 CRM_Mailing_BAO_MailingJob
::resume($this->_mailingId
);
209 CRM_Core_Session
::setStatus(ts('The mailing has been resumed.'), ts('Resumed'), 'success');
210 CRM_Utils_System
::redirect($context);
212 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
213 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean', $this)) {
215 // check for action permissions.
216 if (!CRM_Core_Permission
::checkActionPermission('CiviMail', $this->_action
)) {
217 CRM_Core_Error
::statusBounce(ts('You do not have permission to access this page.'));
220 CRM_Mailing_BAO_Mailing
::del($this->_mailingId
);
221 CRM_Utils_System
::redirect($context);
224 $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse',
225 ts('Delete Mailing'),
228 $controller->setEmbedded(TRUE);
232 elseif ($this->_action
& CRM_Core_Action
::RENEW
) {
233 // archive this mailing, CRM-3752.
234 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean', $this)) {
235 // set is_archived to 1
236 CRM_Core_DAO
::setFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingId
, 'is_archived', TRUE);
237 CRM_Utils_System
::redirect($context);
240 $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse',
241 ts('Archive Mailing'),
244 $controller->setEmbedded(TRUE);
249 $selector = new CRM_Mailing_Selector_Browse();
250 $selector->setParent($this);
252 $controller = new CRM_Core_Selector_Controller(
254 $this->get(CRM_Utils_Pager
::PAGE_ID
),
255 $this->get(CRM_Utils_Sort
::SORT_ID
) . $this->get(CRM_Utils_Sort
::SORT_DIRECTION
),
256 CRM_Core_Action
::VIEW
,
258 CRM_Core_Selector_Controller
::TEMPLATE
261 $controller->setEmbedded(TRUE);
264 // hack to display results as per search
265 $rows = $controller->getRows($controller);
267 $this->assign('rows', $rows);
269 $urlParams = 'reset=1';
270 $urlString = 'civicrm/mailing/browse';
271 if ($this->get('sms')) {
272 $urlParams .= '&sms=1';
274 if (CRM_Utils_Array
::value(3, $newArgs) == 'unscheduled') {
275 $urlString .= '/unscheduled';
276 $urlParams .= '&scheduled=false';
277 $this->assign('unscheduled', TRUE);
279 elseif (CRM_Utils_Array
::value(3, $newArgs) == 'archived') {
280 $urlString .= '/archived';
281 $this->assign('archived', TRUE);
283 elseif (CRM_Utils_Array
::value(3, $newArgs) == 'scheduled') {
284 $urlString .= '/scheduled';
285 $urlParams .= '&scheduled=true';
287 if ($this->get('sms')) {
288 CRM_Utils_System
::setTitle(ts('Find Mass SMS'));
291 $crmRowCount = CRM_Utils_Request
::retrieve('crmRowCount', 'Integer');
292 $crmPID = CRM_Utils_Request
::retrieve('crmPID', 'Integer');
293 if ($crmRowCount ||
$crmPID) {
294 $urlParams .= '&force=1';
295 $urlParams .= $crmRowCount ?
'&crmRowCount=' . $crmRowCount : '';
296 $urlParams .= $crmPID ?
'&crmPID=' . $crmPID : '';
299 $crmSID = CRM_Utils_Request
::retrieve('crmSID', 'Integer');
301 $urlParams .= '&crmSID=' . $crmSID;
304 $session = CRM_Core_Session
::singleton();
305 $url = CRM_Utils_System
::url($urlString, $urlParams);
306 $session->pushUserContext($url);
308 // CRM-6862 -run form cotroller after
309 // selector, since it erase $_POST
312 return parent
::run();
315 public function search() {
316 if ($this->_action
& (CRM_Core_Action
::ADD |
317 CRM_Core_Action
::UPDATE
323 $form = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Search',
324 ts('Search Mailings'),
327 $form->setEmbedded(TRUE);
328 $form->setParent($this);
334 * @param array $params
335 * @param bool $sortBy
339 public function whereClause(&$params, $sortBy = TRUE) {
343 $title = $this->get('mailing_name');
344 // echo " name=$title ";
346 $clauses[] = 'name LIKE %1';
347 if (strpos($title, '%') !== FALSE) {
348 $params[1] = [$title, 'String', FALSE];
351 $params[1] = [$title, 'String', TRUE];
356 $this->_sortByCharacter
!== NULL
358 $clauses[] = "name LIKE '" . strtolower(CRM_Core_DAO
::escapeWildCardString($this->_sortByCharacter
)) . "%'";
361 $campainIds = $this->get('campaign_id');
362 if (!CRM_Utils_System
::isNull($campainIds)) {
363 if (!is_array($campainIds)) {
364 $campaignIds = [$campaignIds];
366 $clauses[] = '( campaign_id IN ( ' . implode(' , ', array_values($campainIds)) . ' ) )';
369 return implode(' AND ', $clauses);