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);
138 // CRM-11920 all should set sortByCharacter to null, not empty string
139 if (strtolower($this->_sortByCharacter
) == 'all' ||
!empty($_POST)) {
140 $this->_sortByCharacter
= NULL;
141 $this->set('sortByCharacter', NULL);
144 if (CRM_Utils_Array
::value(3, $newArgs) == 'unscheduled') {
145 $this->_unscheduled
= TRUE;
147 $this->set('unscheduled', $this->_unscheduled
);
149 if (CRM_Utils_Array
::value(3, $newArgs) == 'archived') {
150 $this->_archived
= TRUE;
152 $this->set('archived', $this->_archived
);
154 if (CRM_Utils_Array
::value(3, $newArgs) == 'scheduled') {
155 $this->_scheduled
= TRUE;
157 $this->set('scheduled', $this->_scheduled
);
159 $this->_createdId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, FALSE, 0);
160 if ($this->_createdId
) {
161 $this->set('createdId', $this->_createdId
);
165 $this->set('sms', $this->_sms
);
168 $session = CRM_Core_Session
::singleton();
169 $context = $session->readUserContext();
171 if ($this->_action
& CRM_Core_Action
::DISABLE
) {
172 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean', $this)) {
173 CRM_Mailing_BAO_MailingJob
::cancel($this->_mailingId
);
174 CRM_Utils_System
::redirect($context);
177 $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse',
178 ts('Cancel Mailing'),
181 $controller->setEmbedded(TRUE);
185 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
186 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean', $this)) {
188 // check for action permissions.
189 if (!CRM_Core_Permission
::checkActionPermission('CiviMail', $this->_action
)) {
190 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
193 CRM_Mailing_BAO_Mailing
::del($this->_mailingId
);
194 CRM_Utils_System
::redirect($context);
197 $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse',
198 ts('Delete Mailing'),
201 $controller->setEmbedded(TRUE);
205 elseif ($this->_action
& CRM_Core_Action
::RENEW
) {
206 //archive this mailing, CRM-3752.
207 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean', $this)) {
208 //set is_archived to 1
209 CRM_Core_DAO
::setFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingId
, 'is_archived', TRUE);
210 CRM_Utils_System
::redirect($context);
213 $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse',
214 ts('Archive Mailing'),
217 $controller->setEmbedded(TRUE);
222 $selector = new CRM_Mailing_Selector_Browse();
223 $selector->setParent($this);
225 $controller = new CRM_Core_Selector_Controller(
227 $this->get(CRM_Utils_Pager
::PAGE_ID
),
228 $this->get(CRM_Utils_Sort
::SORT_ID
) . $this->get(CRM_Utils_Sort
::SORT_DIRECTION
),
229 CRM_Core_Action
::VIEW
,
231 CRM_Core_Selector_Controller
::TEMPLATE
234 $controller->setEmbedded(TRUE);
237 //hack to display results as per search
238 $rows = $controller->getRows($controller);
240 $this->assign('rows', $rows);
242 $urlParams = 'reset=1';
243 $urlString = 'civicrm/mailing/browse';
244 if ($this->get('sms')) {
245 $urlParams .= '&sms=1';
247 if (CRM_Utils_Array
::value(3, $newArgs) == 'unscheduled') {
248 $urlString .= '/unscheduled';
249 $urlParams .= '&scheduled=false';
250 $this->assign('unscheduled', TRUE);
252 elseif (CRM_Utils_Array
::value(3, $newArgs) == 'archived') {
253 $urlString .= '/archived';
254 $this->assign('archived', TRUE);
256 elseif (CRM_Utils_Array
::value(3, $newArgs) == 'scheduled') {
257 $urlString .= '/scheduled';
258 $urlParams .= '&scheduled=true';
260 if ($this->get('sms')) {
261 CRM_Utils_System
::setTitle(ts('Find Mass SMS'));
264 $crmRowCount = CRM_Utils_Request
::retrieve('crmRowCount', 'Integer', CRM_Core_DAO
::$_nullObject);
265 $crmPID = CRM_Utils_Request
::retrieve('crmPID', 'Integer', CRM_Core_DAO
::$_nullObject);
266 if ($crmRowCount ||
$crmPID) {
267 $urlParams .= '&force=1';
268 $urlParams .= $crmRowCount ?
'&crmRowCount=' . $crmRowCount : '';
269 $urlParams .= $crmPID ?
'&crmPID=' . $crmPID : '';
272 $crmSID = CRM_Utils_Request
::retrieve('crmSID', 'Integer', CRM_Core_DAO
::$_nullObject);
274 $urlParams .= '&crmSID=' . $crmSID;
277 $session = CRM_Core_Session
::singleton();
278 $url = CRM_Utils_System
::url($urlString, $urlParams);
279 $session->pushUserContext($url);
281 //CRM-6862 -run form cotroller after
282 //selector, since it erase $_POST
285 return parent
::run();
288 public function search() {
289 if ($this->_action
& (CRM_Core_Action
::ADD |
290 CRM_Core_Action
::UPDATE
296 $form = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Search',
297 ts('Search Mailings'),
300 $form->setEmbedded(TRUE);
301 $form->setParent($this);
307 * @param array $params
308 * @param bool $sortBy
312 public function whereClause(&$params, $sortBy = TRUE) {
316 $title = $this->get('mailing_name');
317 //echo " name=$title ";
319 $clauses[] = 'name LIKE %1';
320 if (strpos($title, '%') !== FALSE) {
321 $params[1] = array($title, 'String', FALSE);
324 $params[1] = array($title, 'String', TRUE);
329 $this->_sortByCharacter
!== NULL
331 $clauses[] = "name LIKE '" . strtolower(CRM_Core_DAO
::escapeWildCardString($this->_sortByCharacter
)) . "%'";
334 $campainIds = $this->get('campaign_id');
335 if (!CRM_Utils_System
::isNull($campainIds)) {
336 if (!is_array($campainIds)) {
337 $campaignIds = array($campaignIds);
339 $clauses[] = '( campaign_id IN ( ' . implode(' , ', array_values($campainIds)) . ' ) )';
342 return implode(' AND ', $clauses);