3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
37 * This class generates form components for Message templates
38 * used by membership, contributions, event registrations, etc.
41 class CRM_Admin_Form_MessageTemplates
extends CRM_Admin_Form
{
42 // which (and whether) mailing workflow this template belongs to
43 protected $_workflow_id = NULL;
45 function preProcess() {
46 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
47 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String',
50 $this->assign('action', $this->_action
);
52 $this->_BAOName
= 'CRM_Core_BAO_MessageTemplate';
53 $this->set('BAOName', $this->_BAOName
);
58 * This function sets the default values for the form.
59 * The default values are retrieved from the database.
65 public function setDefaultValues() {
66 $defaults = $this->_values
;
68 if (empty($defaults['pdf_format_id'])) {
69 $defaults['pdf_format_id'] = 'null';
72 $this->_workflow_id
= CRM_Utils_Array
::value('workflow_id', $defaults);
73 $this->assign('workflow_id', $this->_workflow_id
);
74 if ($this->_action
& CRM_Core_Action
::ADD
) {
75 $defaults['is_active'] = 1;
76 //set the context for redirection after form submit or cancel
77 $session = CRM_Core_Session
::singleton();
78 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/admin/messageTemplates',
79 'selectedChild=user&reset=1'
83 // FIXME: we need to fix the Cancel button here as we don’t know whether it’s a workflow template in buildQuickForm()
84 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
85 if ($this->_workflow_id
) {
86 $selectedChild = 'workflow';
89 $selectedChild = 'user';
91 $cancelURL = CRM_Utils_System
::url('civicrm/admin/messageTemplates', "selectedChild={$selectedChild}&reset=1");
92 $cancelURL = str_replace('&', '&', $cancelURL);
102 'name' => ts('Cancel'),
103 'js' => array('onclick' => "location.href='{$cancelURL}'; return false;"),
113 * Function to build the form
118 public function buildQuickForm() {
120 // For VIEW we only want Done button
121 if ($this->_action
& CRM_Core_Action
::VIEW
) {
122 // currently, the above action is used solely for previewing default workflow templates
123 $cancelURL = CRM_Utils_System
::url('civicrm/admin/messageTemplates', 'selectedChild=workflow&reset=1');
124 $cancelURL = str_replace('&', '&', $cancelURL);
125 $this->addButtons(array(
128 'name' => ts('Done'),
129 'js' => array('onclick' => "location.href='{$cancelURL}'; return false;"),
136 parent
::buildQuickForm();
139 if ($this->_action
& CRM_Core_Action
::DELETE
) {
143 $breadCrumb = array(array('title' => ts('Message Templates'),
144 'url' => CRM_Utils_System
::url('civicrm/admin/messageTemplates',
145 'action=browse&reset=1'
148 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
150 $this->applyFilter('__ALL__', 'trim');
151 $this->add('text', 'msg_title', ts('Message Title'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_MessageTemplate', 'msg_title'), TRUE);
153 $this->add('text', 'msg_subject',
154 ts('Message Subject'),
155 CRM_Core_DAO
::getAttribute('CRM_Core_DAO_MessageTemplate', 'msg_subject')
159 $tokens = CRM_Core_SelectValues
::contactTokens();
161 $this->assign('tokens', CRM_Utils_Token
::formatTokensForDisplay($tokens));
163 $this->add('textarea', 'msg_text', ts('Text Message'),
167 // if not a system message use a wysiwyg editor, CRM-5971
169 CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_MessageTemplate',
174 $this->add('textarea', 'msg_html', ts('HTML Message'),
179 $this->addWysiwyg('msg_html', ts('HTML Message'),
181 'cols' => '80', 'rows' => '8',
182 'onkeyup' => "return verify(this)",
187 $this->add('select', 'pdf_format_id', ts('PDF Page Format'),
189 'null' => ts('- default -')) + CRM_Core_BAO_PdfFormat
::getList(TRUE), FALSE
192 $this->add('checkbox', 'is_active', ts('Enabled?'));
194 if ($this->_action
& CRM_Core_Action
::VIEW
) {
196 CRM_Utils_System
::setTitle(ts('View System Default Message Template'));
201 * Function to process the form
207 public function postProcess() {
208 if ($this->_action
& CRM_Core_Action
::DELETE
) {
209 CRM_Core_BAO_MessageTemplate
::del($this->_id
);
211 elseif ($this->_action
& CRM_Core_Action
::VIEW
) {
212 // currently, the above action is used solely for previewing default workflow templates
213 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/admin/messageTemplates', 'selectedChild=workflow&reset=1'));
218 // store the submitted values in an array
219 $params = $this->exportValues();
221 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
222 $params['id'] = $this->_id
;
225 if ($this->_workflow_id
) {
226 $params['workflow_id'] = $this->_workflow_id
;
227 $params['is_active'] = TRUE;
230 $messageTemplate = CRM_Core_BAO_MessageTemplate
::add($params);
231 CRM_Core_Session
::setStatus(ts('The Message Template \'%1\' has been saved.', array(1 => $messageTemplate->msg_title
)), ts('Saved'), 'success');
233 if ($this->_workflow_id
) {
234 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/admin/messageTemplates', 'selectedChild=workflow&reset=1'));
237 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/admin/messageTemplates', 'selectedChild=user&reset=1'));