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
35 * This class generates form components for Message templates
36 * used by membership, contributions, event registrations, etc.
38 class CRM_Admin_Form_MessageTemplates
extends CRM_Admin_Form
{
39 // which (and whether) mailing workflow this template belongs to
40 protected $_workflow_id = NULL;
42 public function preProcess() {
43 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
44 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String',
47 $this->assign('action', $this->_action
);
49 $this->_BAOName
= 'CRM_Core_BAO_MessageTemplate';
50 $this->set('BAOName', $this->_BAOName
);
55 * Set default values for the form.
57 * The default values are retrieved from the database.
59 public function setDefaultValues() {
60 $defaults = $this->_values
;
62 if (empty($defaults['pdf_format_id'])) {
63 $defaults['pdf_format_id'] = 'null';
66 $this->_workflow_id
= CRM_Utils_Array
::value('workflow_id', $defaults);
67 $this->assign('workflow_id', $this->_workflow_id
);
68 if ($this->_action
& CRM_Core_Action
::ADD
) {
69 $defaults['is_active'] = 1;
70 //set the context for redirection after form submit or cancel
71 $session = CRM_Core_Session
::singleton();
72 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/admin/messageTemplates',
73 'selectedChild=user&reset=1'
77 // FIXME: we need to fix the Cancel button here as we don’t know whether it’s a workflow template in buildQuickForm()
78 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
79 if ($this->_workflow_id
) {
80 $selectedChild = 'workflow';
83 $selectedChild = 'user';
85 $cancelURL = CRM_Utils_System
::url('civicrm/admin/messageTemplates', "selectedChild={$selectedChild}&reset=1");
86 $cancelURL = str_replace('&', '&', $cancelURL);
96 'name' => ts('Cancel'),
97 'js' => array('onclick' => "location.href='{$cancelURL}'; return false;"),
107 * Build the form object.
109 public function buildQuickForm() {
111 // For VIEW we only want Done button
112 if ($this->_action
& CRM_Core_Action
::VIEW
) {
113 // currently, the above action is used solely for previewing default workflow templates
114 $cancelURL = CRM_Utils_System
::url('civicrm/admin/messageTemplates', 'selectedChild=workflow&reset=1');
115 $cancelURL = str_replace('&', '&', $cancelURL);
116 $this->addButtons(array(
119 'name' => ts('Done'),
120 'js' => array('onclick' => "location.href='{$cancelURL}'; return false;"),
127 parent
::buildQuickForm();
130 if ($this->_action
& CRM_Core_Action
::DELETE
) {
136 'title' => ts('Message Templates'),
137 'url' => CRM_Utils_System
::url('civicrm/admin/messageTemplates',
138 'action=browse&reset=1'
142 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
144 $this->applyFilter('__ALL__', 'trim');
145 $this->add('text', 'msg_title', ts('Message Title'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_MessageTemplate', 'msg_title'), TRUE);
147 $this->add('text', 'msg_subject',
148 ts('Message Subject'),
149 CRM_Core_DAO
::getAttribute('CRM_Core_DAO_MessageTemplate', 'msg_subject')
153 $tokens = CRM_Core_SelectValues
::contactTokens();
155 $this->assign('tokens', CRM_Utils_Token
::formatTokensForDisplay($tokens));
157 // if not a system message use a wysiwyg editor, CRM-5971
159 CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_MessageTemplate',
164 $this->add('textarea', 'msg_html', ts('HTML Message'),
169 $this->add('wysiwyg', 'msg_html', ts('HTML Message'),
173 'onkeyup' => "return verify(this)",
178 $this->add('textarea', 'msg_text', ts('Text Message'),
182 $this->add('select', 'pdf_format_id', ts('PDF Page Format'),
184 'null' => ts('- default -'),
185 ) + CRM_Core_BAO_PdfFormat
::getList(TRUE), FALSE
188 $this->add('checkbox', 'is_active', ts('Enabled?'));
190 if ($this->_action
& CRM_Core_Action
::VIEW
) {
192 CRM_Utils_System
::setTitle(ts('View System Default Message Template'));
197 * Process the form submission.
199 public function postProcess() {
200 if ($this->_action
& CRM_Core_Action
::DELETE
) {
201 CRM_Core_BAO_MessageTemplate
::del($this->_id
);
203 elseif ($this->_action
& CRM_Core_Action
::VIEW
) {
204 // currently, the above action is used solely for previewing default workflow templates
205 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/admin/messageTemplates', 'selectedChild=workflow&reset=1'));
210 // store the submitted values in an array
211 $params = $this->exportValues();
213 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
214 $params['id'] = $this->_id
;
217 if ($this->_workflow_id
) {
218 $params['workflow_id'] = $this->_workflow_id
;
219 $params['is_active'] = TRUE;
222 $messageTemplate = CRM_Core_BAO_MessageTemplate
::add($params);
223 CRM_Core_Session
::setStatus(ts('The Message Template \'%1\' has been saved.', array(1 => $messageTemplate->msg_title
)), ts('Saved'), 'success');
225 if ($this->_workflow_id
) {
226 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/admin/messageTemplates', 'selectedChild=workflow&reset=1'));
229 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/admin/messageTemplates', 'selectedChild=user&reset=1'));