4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.5 |
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
53 * The mailing id of the mailing we're operating on
58 protected $_mailingId;
61 * The action that we are performing (in CRM_Core_Action terms)
68 public $_sortByCharacter;
84 * Heart of the viewing process. The runner gets all the meta data for
85 * the contact and calls the appropriate type of page to view.
91 function preProcess() {
92 $this->_unscheduled
= $this->_archived
= $archiveLinks = FALSE;
93 $this->_mailingId
= CRM_Utils_Request
::retrieve('mid', 'Positive', $this);
94 $this->_sms
= CRM_Utils_Request
::retrieve('sms', 'Positive', $this);
95 $this->assign('sms', $this->_sms
);
96 // check that the user has permission to access mailing id
97 CRM_Mailing_BAO_Mailing
::checkPermission($this->_mailingId
);
99 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this);
100 $this->assign('action', $this->_action
);
103 if (CRM_Mailing_Info
::workflowEnabled()) {
104 if (CRM_Core_Permission
::check('create mailings')) {
105 $archiveLinks = TRUE;
107 if (!CRM_Core_Permission
::check('access CiviMail') &&
108 !CRM_Core_Permission
::check('create mailings')
113 $this->assign('showLinks', $showLinks);
114 if (CRM_Core_Permission
::check('access CiviMail')) {
115 $archiveLinks = TRUE;
117 if ($archiveLinks == TRUE) {
118 $this->assign('archiveLinks', $archiveLinks);
123 * Run this page (figure out the action needed and perform it).
130 $newArgs = func_get_args();
131 // since we want only first function argument
132 $newArgs = $newArgs[0];
133 if (isset($_GET['runJobs']) || CRM_Utils_Array
::value('2', $newArgs) == 'queue') {
134 $config = CRM_Core_Config
::singleton();
135 CRM_Mailing_BAO_MailingJob
::runJobs_pre($config->mailerJobSize
);
136 CRM_Mailing_BAO_MailingJob
::runJobs();
137 CRM_Mailing_BAO_MailingJob
::runJobs_post();
140 $this->_sortByCharacter
=
141 CRM_Utils_Request
::retrieve('sortByCharacter', 'String', $this);
144 // CRM-11920 all should set sortByCharacter to null, not empty string
145 if (strtolower($this->_sortByCharacter
) == 'all' ||
!empty($_POST)) {
146 $this->_sortByCharacter
= null;
147 $this->set('sortByCharacter', null);
150 if (CRM_Utils_Array
::value(3, $newArgs) == 'unscheduled') {
151 $this->_unscheduled
= TRUE;
153 $this->set('unscheduled', $this->_unscheduled
);
155 if (CRM_Utils_Array
::value(3, $newArgs) == 'archived') {
156 $this->_archived
= TRUE;
158 $this->set('archived', $this->_archived
);
160 if (CRM_Utils_Array
::value(3, $newArgs) == 'scheduled') {
161 $this->_scheduled
= TRUE;
163 $this->set('scheduled', $this->_scheduled
);
165 $this->_createdId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, FALSE, 0);
166 if ($this->_createdId
) {
167 $this->set('createdId', $this->_createdId
);
171 $this->set('sms', $this->_sms
);
174 $session = CRM_Core_Session
::singleton();
175 $context = $session->readUserContext();
177 if ($this->_action
& CRM_Core_Action
::DISABLE
) {
178 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean', $this)) {
179 CRM_Mailing_BAO_MailingJob
::cancel($this->_mailingId
);
180 CRM_Utils_System
::redirect($context);
183 $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse',
184 ts('Cancel Mailing'),
187 $controller->setEmbedded(TRUE);
191 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
192 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean', $this)) {
194 // check for action permissions.
195 if (!CRM_Core_Permission
::checkActionPermission('CiviMail', $this->_action
)) {
196 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
199 CRM_Mailing_BAO_Mailing
::del($this->_mailingId
);
200 CRM_Utils_System
::redirect($context);
203 $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse',
204 ts('Delete Mailing'),
207 $controller->setEmbedded(TRUE);
211 elseif ($this->_action
& CRM_Core_Action
::RENEW
) {
212 //archive this mailing, CRM-3752.
213 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean', $this)) {
214 //set is_archived to 1
215 CRM_Core_DAO
::setFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingId
, 'is_archived', TRUE);
216 CRM_Utils_System
::redirect($context);
219 $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse',
220 ts('Archive Mailing'),
223 $controller->setEmbedded(TRUE);
228 $selector = new CRM_Mailing_Selector_Browse();
229 $selector->setParent($this);
231 $controller = new CRM_Core_Selector_Controller(
233 $this->get(CRM_Utils_Pager
::PAGE_ID
),
234 $this->get(CRM_Utils_Sort
::SORT_ID
) . $this->get(CRM_Utils_Sort
::SORT_DIRECTION
),
235 CRM_Core_Action
::VIEW
,
237 CRM_Core_Selector_Controller
::TEMPLATE
241 $controller->setEmbedded(TRUE);
244 //hack to display results as per search
245 $rows = $controller->getRows($controller);
247 $this->assign('rows', $rows);
249 $urlParams = 'reset=1';
250 $urlString = 'civicrm/mailing/browse';
251 if ($this->get('sms')) {
252 $urlParams .= '&sms=1';
254 if (CRM_Utils_Array
::value(3, $newArgs) == 'unscheduled') {
255 $urlString .= '/unscheduled';
256 $urlParams .= '&scheduled=false';
257 $this->assign('unscheduled', TRUE);
259 elseif (CRM_Utils_Array
::value(3, $newArgs) == 'archived') {
260 $urlString .= '/archived';
261 $this->assign('archived', TRUE);
263 elseif (CRM_Utils_Array
::value(3, $newArgs) == 'scheduled') {
264 $urlString .= '/scheduled';
265 $urlParams .= '&scheduled=true';
267 if ($this->get('sms')) {
268 CRM_Utils_System
::setTitle(ts('Find Mass SMS'));
271 $crmRowCount = CRM_Utils_Request
::retrieve('crmRowCount', 'Integer', CRM_Core_DAO
::$_nullObject);
272 $crmPID = CRM_Utils_Request
::retrieve('crmPID', 'Integer', CRM_Core_DAO
::$_nullObject);
273 if ($crmRowCount ||
$crmPID) {
274 $urlParams .= '&force=1';
275 $urlParams .= $crmRowCount ?
'&crmRowCount=' . $crmRowCount : '';
276 $urlParams .= $crmPID ?
'&crmPID=' . $crmPID : '';
279 $crmSID = CRM_Utils_Request
::retrieve('crmSID', 'Integer', CRM_Core_DAO
::$_nullObject);
281 $urlParams .= '&crmSID=' . $crmSID;
284 $session = CRM_Core_Session
::singleton();
285 $url = CRM_Utils_System
::url($urlString, $urlParams);
286 $session->pushUserContext($url);
288 //CRM-6862 -run form cotroller after
289 //selector, since it erase $_POST
292 return parent
::run();
297 (CRM_Core_Action
::ADD |
298 CRM_Core_Action
::UPDATE
304 $form = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Search',
305 ts('Search Mailings'),
308 $form->setEmbedded(TRUE);
309 $form->setParent($this);
315 * @param array $params
316 * @param bool $sortBy
320 function whereClause(&$params, $sortBy = TRUE) {
324 $title = $this->get('mailing_name');
325 //echo " name=$title ";
327 $clauses[] = 'name LIKE %1';
328 if (strpos($title, '%') !== FALSE) {
329 $params[1] = array($title, 'String', FALSE);
332 $params[1] = array($title, 'String', TRUE);
337 $this->_sortByCharacter
!== NULL
339 $clauses[] = "name LIKE '" . strtolower(CRM_Core_DAO
::escapeWildCardString($this->_sortByCharacter
)) . "%'";
342 $campainIds = $this->get('campaign_id');
343 if (!CRM_Utils_System
::isNull($campainIds)) {
344 if (!is_array($campainIds)) {
345 $campaignIds = array($campaignIds);
347 $clauses[] = '( campaign_id IN ( ' . implode(' , ', array_values($campainIds)) . ' ) )';
350 return implode(' AND ', $clauses);