4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.6 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
32 * @copyright CiviCRM LLC (c) 2004-2014
38 * This implements the profile page for all contacts. It uses a selector
39 * object to do the actual dispay. The fields displayd are controlled by
42 class CRM_Mailing_Page_Browse
extends CRM_Core_Page
{
45 * All the fields that are listings related
52 * The mailing id of the mailing we're operating on
56 protected $_mailingId;
59 * The action that we are performing (in CRM_Core_Action terms)
65 public $_sortByCharacter;
80 * Heart of the viewing process. The runner gets all the meta data for
81 * the contact and calls the appropriate type of page to view.
86 public function preProcess() {
87 $this->_unscheduled
= $this->_archived
= $archiveLinks = FALSE;
88 $this->_mailingId
= CRM_Utils_Request
::retrieve('mid', 'Positive', $this);
89 $this->_sms
= CRM_Utils_Request
::retrieve('sms', 'Positive', $this);
90 $this->assign('sms', $this->_sms
);
91 // check that the user has permission to access mailing id
92 CRM_Mailing_BAO_Mailing
::checkPermission($this->_mailingId
);
94 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this);
95 $this->assign('action', $this->_action
);
98 if (CRM_Mailing_Info
::workflowEnabled()) {
99 if (CRM_Core_Permission
::check('create mailings')) {
100 $archiveLinks = TRUE;
102 if (!CRM_Core_Permission
::check('access CiviMail') &&
103 !CRM_Core_Permission
::check('create mailings')
108 $this->assign('showLinks', $showLinks);
109 if (CRM_Core_Permission
::check('access CiviMail')) {
110 $archiveLinks = TRUE;
112 if ($archiveLinks == TRUE) {
113 $this->assign('archiveLinks', $archiveLinks);
118 * Run this page (figure out the action needed and perform it).
122 public function run() {
125 $newArgs = func_get_args();
126 // since we want only first function argument
127 $newArgs = $newArgs[0];
128 if (isset($_GET['runJobs']) || CRM_Utils_Array
::value('2', $newArgs) == 'queue') {
129 $config = CRM_Core_Config
::singleton();
130 CRM_Mailing_BAO_MailingJob
::runJobs_pre($config->mailerJobSize
);
131 CRM_Mailing_BAO_MailingJob
::runJobs();
132 CRM_Mailing_BAO_MailingJob
::runJobs_post();
135 $this->_sortByCharacter
=
136 CRM_Utils_Request
::retrieve('sortByCharacter', 'String', $this);
139 // CRM-11920 all should set sortByCharacter to null, not empty string
140 if (strtolower($this->_sortByCharacter
) == 'all' ||
!empty($_POST)) {
141 $this->_sortByCharacter
= null;
142 $this->set('sortByCharacter', null);
145 if (CRM_Utils_Array
::value(3, $newArgs) == 'unscheduled') {
146 $this->_unscheduled
= TRUE;
148 $this->set('unscheduled', $this->_unscheduled
);
150 if (CRM_Utils_Array
::value(3, $newArgs) == 'archived') {
151 $this->_archived
= TRUE;
153 $this->set('archived', $this->_archived
);
155 if (CRM_Utils_Array
::value(3, $newArgs) == 'scheduled') {
156 $this->_scheduled
= TRUE;
158 $this->set('scheduled', $this->_scheduled
);
160 $this->_createdId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, FALSE, 0);
161 if ($this->_createdId
) {
162 $this->set('createdId', $this->_createdId
);
166 $this->set('sms', $this->_sms
);
169 $session = CRM_Core_Session
::singleton();
170 $context = $session->readUserContext();
172 if ($this->_action
& CRM_Core_Action
::DISABLE
) {
173 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean', $this)) {
174 CRM_Mailing_BAO_MailingJob
::cancel($this->_mailingId
);
175 CRM_Utils_System
::redirect($context);
178 $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse',
179 ts('Cancel Mailing'),
182 $controller->setEmbedded(TRUE);
186 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
187 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean', $this)) {
189 // check for action permissions.
190 if (!CRM_Core_Permission
::checkActionPermission('CiviMail', $this->_action
)) {
191 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
194 CRM_Mailing_BAO_Mailing
::del($this->_mailingId
);
195 CRM_Utils_System
::redirect($context);
198 $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse',
199 ts('Delete Mailing'),
202 $controller->setEmbedded(TRUE);
206 elseif ($this->_action
& CRM_Core_Action
::RENEW
) {
207 //archive this mailing, CRM-3752.
208 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean', $this)) {
209 //set is_archived to 1
210 CRM_Core_DAO
::setFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingId
, 'is_archived', TRUE);
211 CRM_Utils_System
::redirect($context);
214 $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse',
215 ts('Archive Mailing'),
218 $controller->setEmbedded(TRUE);
223 $selector = new CRM_Mailing_Selector_Browse();
224 $selector->setParent($this);
226 $controller = new CRM_Core_Selector_Controller(
228 $this->get(CRM_Utils_Pager
::PAGE_ID
),
229 $this->get(CRM_Utils_Sort
::SORT_ID
) . $this->get(CRM_Utils_Sort
::SORT_DIRECTION
),
230 CRM_Core_Action
::VIEW
,
232 CRM_Core_Selector_Controller
::TEMPLATE
236 $controller->setEmbedded(TRUE);
239 //hack to display results as per search
240 $rows = $controller->getRows($controller);
242 $this->assign('rows', $rows);
244 $urlParams = 'reset=1';
245 $urlString = 'civicrm/mailing/browse';
246 if ($this->get('sms')) {
247 $urlParams .= '&sms=1';
249 if (CRM_Utils_Array
::value(3, $newArgs) == 'unscheduled') {
250 $urlString .= '/unscheduled';
251 $urlParams .= '&scheduled=false';
252 $this->assign('unscheduled', TRUE);
254 elseif (CRM_Utils_Array
::value(3, $newArgs) == 'archived') {
255 $urlString .= '/archived';
256 $this->assign('archived', TRUE);
258 elseif (CRM_Utils_Array
::value(3, $newArgs) == 'scheduled') {
259 $urlString .= '/scheduled';
260 $urlParams .= '&scheduled=true';
262 if ($this->get('sms')) {
263 CRM_Utils_System
::setTitle(ts('Find Mass SMS'));
266 $crmRowCount = CRM_Utils_Request
::retrieve('crmRowCount', 'Integer', CRM_Core_DAO
::$_nullObject);
267 $crmPID = CRM_Utils_Request
::retrieve('crmPID', 'Integer', CRM_Core_DAO
::$_nullObject);
268 if ($crmRowCount ||
$crmPID) {
269 $urlParams .= '&force=1';
270 $urlParams .= $crmRowCount ?
'&crmRowCount=' . $crmRowCount : '';
271 $urlParams .= $crmPID ?
'&crmPID=' . $crmPID : '';
274 $crmSID = CRM_Utils_Request
::retrieve('crmSID', 'Integer', CRM_Core_DAO
::$_nullObject);
276 $urlParams .= '&crmSID=' . $crmSID;
279 $session = CRM_Core_Session
::singleton();
280 $url = CRM_Utils_System
::url($urlString, $urlParams);
281 $session->pushUserContext($url);
283 //CRM-6862 -run form cotroller after
284 //selector, since it erase $_POST
287 return parent
::run();
290 public function search() {
292 (CRM_Core_Action
::ADD |
293 CRM_Core_Action
::UPDATE
299 $form = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Search',
300 ts('Search Mailings'),
303 $form->setEmbedded(TRUE);
304 $form->setParent($this);
310 * @param array $params
311 * @param bool $sortBy
315 public function whereClause(&$params, $sortBy = TRUE) {
319 $title = $this->get('mailing_name');
320 //echo " name=$title ";
322 $clauses[] = 'name LIKE %1';
323 if (strpos($title, '%') !== FALSE) {
324 $params[1] = array($title, 'String', FALSE);
327 $params[1] = array($title, 'String', TRUE);
332 $this->_sortByCharacter
!== NULL
334 $clauses[] = "name LIKE '" . strtolower(CRM_Core_DAO
::escapeWildCardString($this->_sortByCharacter
)) . "%'";
337 $campainIds = $this->get('campaign_id');
338 if (!CRM_Utils_System
::isNull($campainIds)) {
339 if (!is_array($campainIds)) {
340 $campaignIds = array($campaignIds);
342 $clauses[] = '( campaign_id IN ( ' . implode(' , ', array_values($campainIds)) . ' ) )';
345 return implode(' AND ', $clauses);