3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This implements the profile page for all contacts. It uses a selector
20 * object to do the actual dispay. The fields displayd are controlled by
23 class CRM_Mailing_Page_Browse
extends CRM_Core_Page
{
26 * All the fields that are listings related.
33 * The mailing id of the mailing we're operating on
37 protected $_mailingId;
40 * The action that we are performing (in CRM_Core_Action terms)
46 public $_sortByCharacter;
61 * Heart of the viewing process. The runner gets all the meta data for
62 * the contact and calls the appropriate type of page to view.
64 public function preProcess() {
65 Civi
::resources()->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header');
67 $this->_unscheduled
= $this->_archived
= $archiveLinks = FALSE;
68 $this->_mailingId
= CRM_Utils_Request
::retrieve('mid', 'Positive', $this);
69 $this->_sms
= CRM_Utils_Request
::retrieve('sms', 'Positive', $this);
72 // if this is an SMS page, check that the user has permission to browse SMS
73 if (!CRM_Core_Permission
::check('send SMS')) {
74 CRM_Core_Error
::statusBounce(ts('You do not have permission to send SMS'));
78 // If this is not an SMS page, check that the user has an appropriate
79 // permission (specific permissions have been copied from
80 // CRM/Mailing/xml/Menu/Mailing.xml)
81 if (!CRM_Core_Permission
::check([['access CiviMail', 'approve mailings', 'create mailings', 'schedule mailings']])) {
82 CRM_Core_Error
::statusBounce(ts('You do not have permission to view this page.'));
86 $this->assign('sms', $this->_sms
);
87 // check that the user has permission to access mailing id
88 CRM_Mailing_BAO_Mailing
::checkPermission($this->_mailingId
);
90 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this);
91 $this->assign('action', $this->_action
);
94 if (CRM_Mailing_Info
::workflowEnabled()) {
95 if (CRM_Core_Permission
::check('create mailings')) {
98 if (!CRM_Core_Permission
::check('access CiviMail') &&
99 !CRM_Core_Permission
::check('create mailings')
104 $this->assign('showLinks', $showLinks);
105 if (CRM_Core_Permission
::check('access CiviMail')) {
106 $archiveLinks = TRUE;
108 if ($archiveLinks == TRUE) {
109 $this->assign('archiveLinks', $archiveLinks);
114 * Run this page (figure out the action needed and perform it).
116 public function run() {
119 $newArgs = func_get_args();
120 // since we want only first function argument
121 $newArgs = $newArgs[0];
122 if (isset($_GET['runJobs']) || CRM_Utils_Array
::value('2', $newArgs) == 'queue') {
123 $mailerJobSize = Civi
::settings()->get('mailerJobSize');
124 CRM_Mailing_BAO_MailingJob
::runJobs_pre($mailerJobSize);
125 CRM_Mailing_BAO_MailingJob
::runJobs();
126 CRM_Mailing_BAO_MailingJob
::runJobs_post();
129 $this->_sortByCharacter
130 = CRM_Utils_Request
::retrieve('sortByCharacter', 'String', $this);
132 // CRM-11920 all should set sortByCharacter to null, not empty string
133 if (strtolower($this->_sortByCharacter
) == 'all' ||
!empty($_POST)) {
134 $this->_sortByCharacter
= NULL;
135 $this->set('sortByCharacter', NULL);
138 if (CRM_Utils_Array
::value(3, $newArgs) == 'unscheduled') {
139 $this->_unscheduled
= TRUE;
141 $this->set('unscheduled', $this->_unscheduled
);
143 if (CRM_Utils_Array
::value(3, $newArgs) == 'archived') {
144 $this->_archived
= TRUE;
146 $this->set('archived', $this->_archived
);
148 if (CRM_Utils_Array
::value(3, $newArgs) == 'scheduled') {
149 $this->_scheduled
= TRUE;
151 $this->set('scheduled', $this->_scheduled
);
153 $this->_createdId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, FALSE, 0);
154 if ($this->_createdId
) {
155 $this->set('createdId', $this->_createdId
);
159 $this->set('sms', $this->_sms
);
162 $session = CRM_Core_Session
::singleton();
163 $context = $session->readUserContext();
165 if ($this->_action
& CRM_Core_Action
::DISABLE
) {
166 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean', $this)) {
167 CRM_Mailing_BAO_MailingJob
::cancel($this->_mailingId
);
168 CRM_Core_Session
::setStatus(ts('The mailing has been canceled.'), ts('Canceled'), 'success');
169 CRM_Utils_System
::redirect($context);
172 $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse',
173 ts('Cancel Mailing'),
176 $controller->setEmbedded(TRUE);
180 elseif ($this->_action
& CRM_Core_Action
::CLOSE
) {
181 if (!CRM_Core_Permission
::checkActionPermission('CiviMail', CRM_Core_Action
::CLOSE
)) {
182 CRM_Core_Error
::statusBounce(ts('You do not have permission to access this page.'));
184 CRM_Mailing_BAO_MailingJob
::pause($this->_mailingId
);
185 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');
186 CRM_Utils_System
::redirect($context);
188 elseif ($this->_action
& CRM_Core_Action
::REOPEN
) {
189 if (!CRM_Core_Permission
::checkActionPermission('CiviMail', CRM_Core_Action
::CLOSE
)) {
190 CRM_Core_Error
::statusBounce(ts('You do not have permission to access this page.'));
192 CRM_Mailing_BAO_MailingJob
::resume($this->_mailingId
);
193 CRM_Core_Session
::setStatus(ts('The mailing has been resumed.'), ts('Resumed'), 'success');
194 CRM_Utils_System
::redirect($context);
196 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
197 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean', $this)) {
199 // check for action permissions.
200 if (!CRM_Core_Permission
::checkActionPermission('CiviMail', $this->_action
)) {
201 CRM_Core_Error
::statusBounce(ts('You do not have permission to access this page.'));
204 CRM_Mailing_BAO_Mailing
::del($this->_mailingId
);
205 CRM_Utils_System
::redirect($context);
208 $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse',
209 ts('Delete Mailing'),
212 $controller->setEmbedded(TRUE);
216 elseif ($this->_action
& CRM_Core_Action
::RENEW
) {
217 // archive this mailing, CRM-3752.
218 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean', $this)) {
219 // set is_archived to 1
220 CRM_Core_DAO
::setFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingId
, 'is_archived', TRUE);
221 CRM_Utils_System
::redirect($context);
224 $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse',
225 ts('Archive Mailing'),
228 $controller->setEmbedded(TRUE);
233 $selector = new CRM_Mailing_Selector_Browse();
234 $selector->setParent($this);
236 $controller = new CRM_Core_Selector_Controller(
238 $this->get(CRM_Utils_Pager
::PAGE_ID
),
239 $this->get(CRM_Utils_Sort
::SORT_ID
) . $this->get(CRM_Utils_Sort
::SORT_DIRECTION
),
240 CRM_Core_Action
::VIEW
,
242 CRM_Core_Selector_Controller
::TEMPLATE
245 $controller->setEmbedded(TRUE);
248 // hack to display results as per search
249 $rows = $controller->getRows($controller);
251 $this->assign('rows', $rows);
253 $urlParams = 'reset=1';
254 $urlString = 'civicrm/mailing/browse';
255 if ($this->get('sms')) {
256 $urlParams .= '&sms=1';
258 if (CRM_Utils_Array
::value(3, $newArgs) == 'unscheduled') {
259 $urlString .= '/unscheduled';
260 $urlParams .= '&scheduled=false';
261 $this->assign('unscheduled', TRUE);
263 elseif (CRM_Utils_Array
::value(3, $newArgs) == 'archived') {
264 $urlString .= '/archived';
265 $this->assign('archived', TRUE);
267 elseif (CRM_Utils_Array
::value(3, $newArgs) == 'scheduled') {
268 $urlString .= '/scheduled';
269 $urlParams .= '&scheduled=true';
271 if ($this->get('sms')) {
272 CRM_Utils_System
::setTitle(ts('Find Mass SMS'));
275 $crmRowCount = CRM_Utils_Request
::retrieve('crmRowCount', 'Integer');
276 $crmPID = CRM_Utils_Request
::retrieve('crmPID', 'Integer');
277 if ($crmRowCount ||
$crmPID) {
278 $urlParams .= '&force=1';
279 $urlParams .= $crmRowCount ?
'&crmRowCount=' . $crmRowCount : '';
280 $urlParams .= $crmPID ?
'&crmPID=' . $crmPID : '';
283 $crmSID = CRM_Utils_Request
::retrieve('crmSID', 'Integer');
285 $urlParams .= '&crmSID=' . $crmSID;
288 $session = CRM_Core_Session
::singleton();
289 $url = CRM_Utils_System
::url($urlString, $urlParams);
290 $session->pushUserContext($url);
292 // CRM-6862 -run form cotroller after
293 // selector, since it erase $_POST
296 return parent
::run();
299 public function search() {
300 if ($this->_action
& (CRM_Core_Action
::ADD |
301 CRM_Core_Action
::UPDATE
307 $form = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Search',
308 ts('Search Mailings'),
311 $form->setEmbedded(TRUE);
312 $form->setParent($this);
318 * @param array $params
319 * @param bool $sortBy
323 public function whereClause(&$params, $sortBy = TRUE) {
327 $title = $this->get('mailing_name');
328 // echo " name=$title ";
330 $clauses[] = 'name LIKE %1';
331 if (strpos($title, '%') !== FALSE) {
332 $params[1] = [$title, 'String', FALSE];
335 $params[1] = [$title, 'String', TRUE];
340 $this->_sortByCharacter
!== NULL
342 $clauses[] = "name LIKE '" . strtolower(CRM_Core_DAO
::escapeWildCardString($this->_sortByCharacter
)) . "%'";
345 $campainIds = $this->get('campaign_id');
346 if (!CRM_Utils_System
::isNull($campainIds)) {
347 if (!is_array($campainIds)) {
348 $campaignIds = [$campaignIds];
350 $clauses[] = '( campaign_id IN ( ' . implode(' , ', array_values($campainIds)) . ' ) )';
353 return implode(' AND ', $clauses);