3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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 * Function to set variables up before form is built
52 public function preProcess() {
53 if (CRM_Mailing_Info
::workflowEnabled()) {
54 if (!CRM_Core_Permission
::check('approve mailings')) {
55 $this->redirectToListing();
59 $this->redirectToListing();
63 // when user come from search context.
64 $this->_searchBasedMailing
= CRM_Contact_Form_Search
::isSearchContext($this->get('context'));
66 //retrieve mid from different wizard and url contexts
67 $this->_mailingID
= $this->get('mailing_id');
68 $this->_approveFormOnly
= FALSE;
69 if (!$this->_mailingID
) {
70 $this->_mailingID
= CRM_Utils_Request
::retrieve('mid', 'Integer', $this, TRUE);
71 $this->_approveFormOnly
= TRUE;
74 $session = CRM_Core_Session
::singleton();
75 $this->_contactID
= $session->get('userID');
77 $this->_mailing
= new CRM_Mailing_BAO_Mailing();
78 $this->_mailing
->id
= $this->_mailingID
;
79 if (!$this->_mailing
->find(TRUE)) {
80 $this->redirectToListing();
85 * This function sets the default values for the form.
91 function setDefaultValues() {
93 if ($this->_mailingID
) {
94 $defaults['approval_status_id'] = $this->_mailing
->approval_status_id
;
95 $defaults['approval_note'] = $this->_mailing
->approval_note
;
102 * Build the form for the approval/rejection mailing
109 public function buildQuickform() {
110 $title = ts('Approve/Reject Mailing') . " - {$this->_mailing->name}";
111 CRM_Utils_System
::setTitle($title);
113 $this->addElement('textarea', 'approval_note', ts('Approve/Reject Note'));
115 $mailApprovalStatus = CRM_Core_OptionGroup
::values('mail_approval_status');
117 // eliminate the none option
118 $noneOptionID = CRM_Core_OptionGroup
::getValue('mail_approval_status',
123 unset($mailApprovalStatus[$noneOptionID]);
126 $this->addRadio('approval_status_id', ts('Approval Status'), $mailApprovalStatus, TRUE, NULL, TRUE);
129 array('type' => 'next',
130 'name' => ts('Save'),
131 'spacing' => ' ',
136 'name' => ts('Cancel'),
140 $this->addButtons($buttons);
142 // add the preview elements
145 $preview['subject'] = CRM_Core_DAO
::getFieldValue('CRM_Mailing_DAO_Mailing',
149 $preview['viewURL'] = CRM_Utils_System
::url('civicrm/mailing/view', "reset=1&id={$this->_mailingID}");
150 $preview['type'] = $this->_mailing
->body_html ?
'html' : 'text';
151 $preview['attachment'] = CRM_Core_BAO_File
::attachmentInfo('civicrm_mailing', $this->_mailingID
);
153 $this->assign_by_ref('preview', $preview);
157 * Process the posted form values. Approve /reject a mailing.
164 public function postProcess() {
165 // get the submitted form values.
166 $params = $this->controller
->exportValues($this->_name
);
169 if (isset($this->_mailingID
)) {
170 $ids['mailing_id'] = $this->_mailingID
;
173 $ids['mailing_id'] = $this->get('mailing_id');
176 if (!$ids['mailing_id']) {
177 CRM_Core_Error
::fatal();
180 $params['approver_id'] = $this->_contactID
;
181 $params['approval_date'] = date('YmdHis');
183 // if rejected, then we need to reset the scheduled date and scheduled id
184 $rejectOptionID = CRM_Core_OptionGroup
::getValue('mail_approval_status',
188 if ($rejectOptionID &&
189 $params['approval_status_id'] == $rejectOptionID
191 $params['scheduled_id'] = 'null';
192 $params['scheduled_date'] = 'null';
194 // also delete any jobs associated with this mailing
195 $job = new CRM_Mailing_BAO_MailingJob();
196 $job->mailing_id
= $ids['mailing_id'];
200 $mailing = new CRM_Mailing_BAO_Mailing();
201 $mailing->id
= $ids['mailing_id'];
202 $mailing->find(TRUE);
204 $params['scheduled_date'] = CRM_Utils_Date
::processDate($mailing->scheduled_date
);
207 CRM_Mailing_BAO_Mailing
::create($params, $ids);
210 //when user perform mailing from search context
211 //redirect it to search result CRM-3711
212 $ssID = $this->get('ssID');
213 if ($ssID && $this->_searchBasedMailing
) {
214 if ($this->_action
== CRM_Core_Action
::BASIC
) {
215 $fragment = 'search';
217 elseif ($this->_action
== CRM_Core_Action
::PROFILE
) {
218 $fragment = 'search/builder';
220 elseif ($this->_action
== CRM_Core_Action
::ADVANCED
) {
221 $fragment = 'search/advanced';
224 $fragment = 'search/custom';
226 $context = $this->get('context');
227 if (!CRM_Contact_Form_Search
::isSearchContext($context)) {
230 $urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}";
231 $qfKey = CRM_Utils_Request
::retrieve('qfKey', 'String', $this);
232 if (CRM_Utils_Rule
::qfKey($qfKey)) {
233 $urlParams .= "&qfKey=$qfKey";
236 $url = CRM_Utils_System
::url('civicrm/contact/' . $fragment, $urlParams);
237 return $this->controller
->setDestination($url);
240 $session = CRM_Core_Session
::singleton();
241 $session->pushUserContext(CRM_Utils_System
::url('civicrm/mailing/browse/scheduled',
242 'reset=1&scheduled=true'
247 * Display Name of the form
253 public function getTitle() {
254 return ts('Approve/Reject Mailing');