3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
37 * This implements the profile page for all contacts. It uses a selector
38 * object to do the actual dispay. The fields displayd are controlled by
41 class CRM_Mailing_Page_Browse
extends CRM_Core_Page
{
44 * All the fields that are listings related
51 * The mailing id of the mailing we're operating on
55 protected $_mailingId;
58 * The action that we are performing (in CRM_Core_Action terms)
64 public $_sortByCharacter;
79 * Heart of the viewing process. The runner gets all the meta data for
80 * the contact and calls the appropriate type of page to view.
84 public function preProcess() {
85 $this->_unscheduled
= $this->_archived
= $archiveLinks = FALSE;
86 $this->_mailingId
= CRM_Utils_Request
::retrieve('mid', 'Positive', $this);
87 $this->_sms
= CRM_Utils_Request
::retrieve('sms', 'Positive', $this);
88 $this->assign('sms', $this->_sms
);
89 // check that the user has permission to access mailing id
90 CRM_Mailing_BAO_Mailing
::checkPermission($this->_mailingId
);
92 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this);
93 $this->assign('action', $this->_action
);
96 if (CRM_Mailing_Info
::workflowEnabled()) {
97 if (CRM_Core_Permission
::check('create mailings')) {
100 if (!CRM_Core_Permission
::check('access CiviMail') &&
101 !CRM_Core_Permission
::check('create mailings')
106 $this->assign('showLinks', $showLinks);
107 if (CRM_Core_Permission
::check('access CiviMail')) {
108 $archiveLinks = TRUE;
110 if ($archiveLinks == TRUE) {
111 $this->assign('archiveLinks', $archiveLinks);
116 * Run this page (figure out the action needed and perform it).
120 public function run() {
123 $newArgs = func_get_args();
124 // since we want only first function argument
125 $newArgs = $newArgs[0];
126 if (isset($_GET['runJobs']) || CRM_Utils_Array
::value('2', $newArgs) == 'queue') {
127 $config = CRM_Core_Config
::singleton();
128 CRM_Mailing_BAO_MailingJob
::runJobs_pre($config->mailerJobSize
);
129 CRM_Mailing_BAO_MailingJob
::runJobs();
130 CRM_Mailing_BAO_MailingJob
::runJobs_post();
133 $this->_sortByCharacter
=
134 CRM_Utils_Request
::retrieve('sortByCharacter', 'String', $this);
136 // CRM-11920 all should set sortByCharacter to null, not empty string
137 if (strtolower($this->_sortByCharacter
) == 'all' ||
!empty($_POST)) {
138 $this->_sortByCharacter
= NULL;
139 $this->set('sortByCharacter', NULL);
142 if (CRM_Utils_Array
::value(3, $newArgs) == 'unscheduled') {
143 $this->_unscheduled
= TRUE;
145 $this->set('unscheduled', $this->_unscheduled
);
147 if (CRM_Utils_Array
::value(3, $newArgs) == 'archived') {
148 $this->_archived
= TRUE;
150 $this->set('archived', $this->_archived
);
152 if (CRM_Utils_Array
::value(3, $newArgs) == 'scheduled') {
153 $this->_scheduled
= TRUE;
155 $this->set('scheduled', $this->_scheduled
);
157 $this->_createdId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, FALSE, 0);
158 if ($this->_createdId
) {
159 $this->set('createdId', $this->_createdId
);
163 $this->set('sms', $this->_sms
);
166 $session = CRM_Core_Session
::singleton();
167 $context = $session->readUserContext();
169 if ($this->_action
& CRM_Core_Action
::DISABLE
) {
170 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean', $this)) {
171 CRM_Mailing_BAO_MailingJob
::cancel($this->_mailingId
);
172 CRM_Utils_System
::redirect($context);
175 $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse',
176 ts('Cancel Mailing'),
179 $controller->setEmbedded(TRUE);
183 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
184 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean', $this)) {
186 // check for action permissions.
187 if (!CRM_Core_Permission
::checkActionPermission('CiviMail', $this->_action
)) {
188 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
191 CRM_Mailing_BAO_Mailing
::del($this->_mailingId
);
192 CRM_Utils_System
::redirect($context);
195 $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse',
196 ts('Delete Mailing'),
199 $controller->setEmbedded(TRUE);
203 elseif ($this->_action
& CRM_Core_Action
::RENEW
) {
204 //archive this mailing, CRM-3752.
205 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean', $this)) {
206 //set is_archived to 1
207 CRM_Core_DAO
::setFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingId
, 'is_archived', TRUE);
208 CRM_Utils_System
::redirect($context);
211 $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse',
212 ts('Archive Mailing'),
215 $controller->setEmbedded(TRUE);
220 $selector = new CRM_Mailing_Selector_Browse();
221 $selector->setParent($this);
223 $controller = new CRM_Core_Selector_Controller(
225 $this->get(CRM_Utils_Pager
::PAGE_ID
),
226 $this->get(CRM_Utils_Sort
::SORT_ID
) . $this->get(CRM_Utils_Sort
::SORT_DIRECTION
),
227 CRM_Core_Action
::VIEW
,
229 CRM_Core_Selector_Controller
::TEMPLATE
232 $controller->setEmbedded(TRUE);
235 //hack to display results as per search
236 $rows = $controller->getRows($controller);
238 $this->assign('rows', $rows);
240 $urlParams = 'reset=1';
241 $urlString = 'civicrm/mailing/browse';
242 if ($this->get('sms')) {
243 $urlParams .= '&sms=1';
245 if (CRM_Utils_Array
::value(3, $newArgs) == 'unscheduled') {
246 $urlString .= '/unscheduled';
247 $urlParams .= '&scheduled=false';
248 $this->assign('unscheduled', TRUE);
250 elseif (CRM_Utils_Array
::value(3, $newArgs) == 'archived') {
251 $urlString .= '/archived';
252 $this->assign('archived', TRUE);
254 elseif (CRM_Utils_Array
::value(3, $newArgs) == 'scheduled') {
255 $urlString .= '/scheduled';
256 $urlParams .= '&scheduled=true';
258 if ($this->get('sms')) {
259 CRM_Utils_System
::setTitle(ts('Find Mass SMS'));
262 $crmRowCount = CRM_Utils_Request
::retrieve('crmRowCount', 'Integer', CRM_Core_DAO
::$_nullObject);
263 $crmPID = CRM_Utils_Request
::retrieve('crmPID', 'Integer', CRM_Core_DAO
::$_nullObject);
264 if ($crmRowCount ||
$crmPID) {
265 $urlParams .= '&force=1';
266 $urlParams .= $crmRowCount ?
'&crmRowCount=' . $crmRowCount : '';
267 $urlParams .= $crmPID ?
'&crmPID=' . $crmPID : '';
270 $crmSID = CRM_Utils_Request
::retrieve('crmSID', 'Integer', CRM_Core_DAO
::$_nullObject);
272 $urlParams .= '&crmSID=' . $crmSID;
275 $session = CRM_Core_Session
::singleton();
276 $url = CRM_Utils_System
::url($urlString, $urlParams);
277 $session->pushUserContext($url);
279 //CRM-6862 -run form cotroller after
280 //selector, since it erase $_POST
283 return parent
::run();
286 public function search() {
287 if ($this->_action
& (CRM_Core_Action
::ADD |
288 CRM_Core_Action
::UPDATE
294 $form = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Search',
295 ts('Search Mailings'),
298 $form->setEmbedded(TRUE);
299 $form->setParent($this);
305 * @param array $params
306 * @param bool $sortBy
310 public function whereClause(&$params, $sortBy = TRUE) {
314 $title = $this->get('mailing_name');
315 //echo " name=$title ";
317 $clauses[] = 'name LIKE %1';
318 if (strpos($title, '%') !== FALSE) {
319 $params[1] = array($title, 'String', FALSE);
322 $params[1] = array($title, 'String', TRUE);
327 $this->_sortByCharacter
!== NULL
329 $clauses[] = "name LIKE '" . strtolower(CRM_Core_DAO
::escapeWildCardString($this->_sortByCharacter
)) . "%'";
332 $campainIds = $this->get('campaign_id');
333 if (!CRM_Utils_System
::isNull($campainIds)) {
334 if (!is_array($campainIds)) {
335 $campaignIds = array($campaignIds);
337 $clauses[] = '( campaign_id IN ( ' . implode(' , ', array_values($campainIds)) . ' ) )';
340 return implode(' AND ', $clauses);