8658e79dd42387e5e0faa0dc5630f5e7529d228e
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
39 class CRM_Mailing_Form_Approve
extends CRM_Core_Form
{
41 public function redirectToListing() {
42 $url = CRM_Utils_System
::url('civicrm/mailing/browse/scheduled', 'reset=1&scheduled=true');
43 CRM_Utils_System
::redirect($url);
47 * Set variables up before form is built.
51 public function preProcess() {
52 if (CRM_Mailing_Info
::workflowEnabled()) {
53 if (!CRM_Core_Permission
::check('approve mailings') && !CRM_Core_Permission
::check('access CiviMail')) {
54 $this->redirectToListing();
58 $this->redirectToListing();
61 // when user come from search context.
62 $this->_searchBasedMailing
= CRM_Contact_Form_Search
::isSearchContext($this->get('context'));
64 //retrieve mid from different wizard and url contexts
65 $this->_mailingID
= $this->get('mailing_id');
66 $this->_approveFormOnly
= FALSE;
67 if (!$this->_mailingID
) {
68 $this->_mailingID
= CRM_Utils_Request
::retrieve('mid', 'Integer', $this, TRUE);
69 $this->_approveFormOnly
= TRUE;
72 $session = CRM_Core_Session
::singleton();
73 $this->_contactID
= $session->get('userID');
75 $this->_mailing
= new CRM_Mailing_BAO_Mailing();
76 $this->_mailing
->id
= $this->_mailingID
;
77 if (!$this->_mailing
->find(TRUE)) {
78 $this->redirectToListing();
83 * Set default values for the form.
88 public function setDefaultValues() {
90 if ($this->_mailingID
) {
91 $defaults['approval_status_id'] = $this->_mailing
->approval_status_id
;
92 $defaults['approval_note'] = $this->_mailing
->approval_note
;
99 * Build the form object for the approval/rejection mailing
105 public function buildQuickform() {
106 $title = ts('Approve/Reject Mailing') . " - {$this->_mailing->name}";
107 CRM_Utils_System
::setTitle($title);
109 $this->addElement('textarea', 'approval_note', ts('Approve/Reject Note'));
111 $mailApprovalStatus = CRM_Core_OptionGroup
::values('mail_approval_status');
113 // eliminate the none option
114 $noneOptionID = CRM_Core_OptionGroup
::getValue('mail_approval_status',
119 unset($mailApprovalStatus[$noneOptionID]);
122 $this->addRadio('approval_status_id', ts('Approval Status'), $mailApprovalStatus, array(), NULL, TRUE);
127 'name' => ts('Save'),
128 'spacing' => ' ',
133 'name' => ts('Cancel'),
137 $this->addButtons($buttons);
139 // add the preview elements
142 $preview['subject'] = CRM_Core_DAO
::getFieldValue('CRM_Mailing_DAO_Mailing',
147 $mailingKey = $this->_mailingID
;
148 if ($hash = CRM_Mailing_BAO_Mailing
::getMailingHash($mailingKey)) {
152 $preview['viewURL'] = CRM_Utils_System
::url('civicrm/mailing/view', "reset=1&id={$mailingKey}");
153 $preview['type'] = $this->_mailing
->body_html ?
'html' : 'text';
154 $preview['attachment'] = CRM_Core_BAO_File
::attachmentInfo('civicrm_mailing', $this->_mailingID
);
156 $this->assign_by_ref('preview', $preview);
160 * Process the posted form values. Approve /reject a mailing.
166 public function postProcess() {
167 // get the submitted form values.
168 $params = $this->controller
->exportValues($this->_name
);
171 if (isset($this->_mailingID
)) {
172 $ids['mailing_id'] = $this->_mailingID
;
175 $ids['mailing_id'] = $this->get('mailing_id');
178 if (!$ids['mailing_id']) {
179 CRM_Core_Error
::fatal();
182 $params['approver_id'] = $this->_contactID
;
183 $params['approval_date'] = date('YmdHis');
185 // if rejected, then we need to reset the scheduled date and scheduled id
186 $rejectOptionID = CRM_Core_OptionGroup
::getValue('mail_approval_status',
190 if ($rejectOptionID &&
191 $params['approval_status_id'] == $rejectOptionID
193 $params['scheduled_id'] = 'null';
194 $params['scheduled_date'] = 'null';
196 // also delete any jobs associated with this mailing
197 $job = new CRM_Mailing_BAO_MailingJob();
198 $job->mailing_id
= $ids['mailing_id'];
202 $mailing = new CRM_Mailing_BAO_Mailing();
203 $mailing->id
= $ids['mailing_id'];
204 $mailing->find(TRUE);
206 $params['scheduled_date'] = CRM_Utils_Date
::processDate($mailing->scheduled_date
);
209 CRM_Mailing_BAO_Mailing
::create($params, $ids);
211 //when user perform mailing from search context
212 //redirect it to search result CRM-3711
213 $ssID = $this->get('ssID');
214 if ($ssID && $this->_searchBasedMailing
) {
215 if ($this->_action
== CRM_Core_Action
::BASIC
) {
216 $fragment = 'search';
218 elseif ($this->_action
== CRM_Core_Action
::PROFILE
) {
219 $fragment = 'search/builder';
221 elseif ($this->_action
== CRM_Core_Action
::ADVANCED
) {
222 $fragment = 'search/advanced';
225 $fragment = 'search/custom';
227 $context = $this->get('context');
228 if (!CRM_Contact_Form_Search
::isSearchContext($context)) {
231 $urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}";
232 $qfKey = CRM_Utils_Request
::retrieve('qfKey', 'String', $this);
233 if (CRM_Utils_Rule
::qfKey($qfKey)) {
234 $urlParams .= "&qfKey=$qfKey";
237 $url = CRM_Utils_System
::url('civicrm/contact/' . $fragment, $urlParams);
238 return $this->controller
->setDestination($url);
241 $session = CRM_Core_Session
::singleton();
242 $session->pushUserContext(CRM_Utils_System
::url('civicrm/mailing/browse/scheduled',
243 'reset=1&scheduled=true'
248 * Display Name of the form.
253 public function getTitle() {
254 return ts('Approve/Reject Mailing');