Merge pull request #12285 from eileenmcnaughton/master
[civicrm-core.git] / CRM / Mailing / Form / Browse.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2018
32 */
33
34 /**
35 * Build the form object for disable mail feature
36 */
37 class CRM_Mailing_Form_Browse extends CRM_Core_Form {
38
39 /**
40 * Heart of the viewing process. The runner gets all the meta data for
41 * the contact and calls the appropriate type of page to view.
42 */
43 public function preProcess() {
44 $this->_mailingId = CRM_Utils_Request::retrieve('mid', 'Positive', $this);
45 $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this);
46
47 // check for action permissions.
48 if (!CRM_Core_Permission::checkActionPermission('CiviMail', $this->_action)) {
49 CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
50 }
51
52 $mailing = new CRM_Mailing_BAO_Mailing();
53 $mailing->id = $this->_mailingId;
54 $subject = '';
55 if ($mailing->find(TRUE)) {
56 $subject = $mailing->subject;
57 }
58 $this->assign('subject', $subject);
59 }
60
61 /**
62 * Build the form object.
63 */
64 public function buildQuickForm() {
65 $this->addButtons(array(
66 array(
67 'type' => 'next',
68 'name' => ts('Confirm'),
69 'isDefault' => TRUE,
70 ),
71 array(
72 'type' => 'cancel',
73 'name' => ts('Cancel'),
74 ),
75 )
76 );
77 }
78
79 public function postProcess() {
80 if ($this->_action & CRM_Core_Action::DELETE) {
81 CRM_Mailing_BAO_Mailing::del($this->_mailingId);
82 }
83 elseif ($this->_action & CRM_Core_Action::DISABLE) {
84 CRM_Mailing_BAO_MailingJob::cancel($this->_mailingId);
85 CRM_Core_Session::setStatus(ts('The mailing has been canceled.'), ts('Canceled'), 'success');
86 }
87 elseif ($this->_action & CRM_Core_Action::RENEW) {
88 //set is_archived to 1
89 CRM_Core_DAO::setFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingId, 'is_archived', TRUE);
90 }
91 }
92
93 }