3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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-2018
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
::fatal(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(array(array('access CiviMail', 'approve mailings', 'create mailings', 'schedule mailings')))) {
98 CRM_Core_Error
::fatal(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_Utils_System
::redirect($context);
187 $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse',
188 ts('Cancel Mailing'),
191 $controller->setEmbedded(TRUE);
195 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
196 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean', $this)) {
198 // check for action permissions.
199 if (!CRM_Core_Permission
::checkActionPermission('CiviMail', $this->_action
)) {
200 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
203 CRM_Mailing_BAO_Mailing
::del($this->_mailingId
);
204 CRM_Utils_System
::redirect($context);
207 $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse',
208 ts('Delete Mailing'),
211 $controller->setEmbedded(TRUE);
215 elseif ($this->_action
& CRM_Core_Action
::RENEW
) {
216 // archive this mailing, CRM-3752.
217 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean', $this)) {
218 // set is_archived to 1
219 CRM_Core_DAO
::setFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingId
, 'is_archived', TRUE);
220 CRM_Utils_System
::redirect($context);
223 $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse',
224 ts('Archive Mailing'),
227 $controller->setEmbedded(TRUE);
232 $selector = new CRM_Mailing_Selector_Browse();
233 $selector->setParent($this);
235 $controller = new CRM_Core_Selector_Controller(
237 $this->get(CRM_Utils_Pager
::PAGE_ID
),
238 $this->get(CRM_Utils_Sort
::SORT_ID
) . $this->get(CRM_Utils_Sort
::SORT_DIRECTION
),
239 CRM_Core_Action
::VIEW
,
241 CRM_Core_Selector_Controller
::TEMPLATE
244 $controller->setEmbedded(TRUE);
247 // hack to display results as per search
248 $rows = $controller->getRows($controller);
250 $this->assign('rows', $rows);
252 $urlParams = 'reset=1';
253 $urlString = 'civicrm/mailing/browse';
254 if ($this->get('sms')) {
255 $urlParams .= '&sms=1';
257 if (CRM_Utils_Array
::value(3, $newArgs) == 'unscheduled') {
258 $urlString .= '/unscheduled';
259 $urlParams .= '&scheduled=false';
260 $this->assign('unscheduled', TRUE);
262 elseif (CRM_Utils_Array
::value(3, $newArgs) == 'archived') {
263 $urlString .= '/archived';
264 $this->assign('archived', TRUE);
266 elseif (CRM_Utils_Array
::value(3, $newArgs) == 'scheduled') {
267 $urlString .= '/scheduled';
268 $urlParams .= '&scheduled=true';
270 if ($this->get('sms')) {
271 CRM_Utils_System
::setTitle(ts('Find Mass SMS'));
274 $crmRowCount = CRM_Utils_Request
::retrieve('crmRowCount', 'Integer');
275 $crmPID = CRM_Utils_Request
::retrieve('crmPID', 'Integer');
276 if ($crmRowCount ||
$crmPID) {
277 $urlParams .= '&force=1';
278 $urlParams .= $crmRowCount ?
'&crmRowCount=' . $crmRowCount : '';
279 $urlParams .= $crmPID ?
'&crmPID=' . $crmPID : '';
282 $crmSID = CRM_Utils_Request
::retrieve('crmSID', 'Integer');
284 $urlParams .= '&crmSID=' . $crmSID;
287 $session = CRM_Core_Session
::singleton();
288 $url = CRM_Utils_System
::url($urlString, $urlParams);
289 $session->pushUserContext($url);
291 // CRM-6862 -run form cotroller after
292 // selector, since it erase $_POST
295 return parent
::run();
298 public function search() {
299 if ($this->_action
& (CRM_Core_Action
::ADD |
300 CRM_Core_Action
::UPDATE
306 $form = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Search',
307 ts('Search Mailings'),
310 $form->setEmbedded(TRUE);
311 $form->setParent($this);
317 * @param array $params
318 * @param bool $sortBy
322 public function whereClause(&$params, $sortBy = TRUE) {
326 $title = $this->get('mailing_name');
327 // echo " name=$title ";
329 $clauses[] = 'name LIKE %1';
330 if (strpos($title, '%') !== FALSE) {
331 $params[1] = array($title, 'String', FALSE);
334 $params[1] = array($title, 'String', TRUE);
339 $this->_sortByCharacter
!== NULL
341 $clauses[] = "name LIKE '" . strtolower(CRM_Core_DAO
::escapeWildCardString($this->_sortByCharacter
)) . "%'";
344 $campainIds = $this->get('campaign_id');
345 if (!CRM_Utils_System
::isNull($campainIds)) {
346 if (!is_array($campainIds)) {
347 $campaignIds = array($campaignIds);
349 $clauses[] = '( campaign_id IN ( ' . implode(' , ', array_values($campainIds)) . ' ) )';
352 return implode(' AND ', $clauses);