3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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 Location Type
40 class CRM_Mailing_Form_Component
extends CRM_Core_Form
{
43 * The id of the object being edited / created
50 * The name of the BAO object for this form.
56 public function preProcess() {
57 $this->_id
= $this->get('id');
58 $this->_BAOName
= $this->get('BAOName');
62 * Build the form object.
66 public function buildQuickForm() {
67 $this->applyFilter('__ALL__', 'trim');
69 $this->add('text', 'name', ts('Name'),
70 CRM_Core_DAO
::getAttribute('CRM_Mailing_DAO_Component', 'name'), TRUE
72 $this->addRule('name', ts('Name already exists in Database.'), 'objectExists', array(
73 'CRM_Mailing_DAO_Component',
77 $this->add('select', 'component_type', ts('Component Type'), CRM_Core_SelectValues
::mailingComponents());
79 $this->add('text', 'subject', ts('Subject'),
80 CRM_Core_DAO
::getAttribute('CRM_Mailing_DAO_Component', 'subject'),
83 $this->add('textarea', 'body_text', ts('Body - TEXT Format'),
84 CRM_Core_DAO
::getAttribute('CRM_Mailing_DAO_Component', 'body_text'),
87 $this->add('textarea', 'body_html', ts('Body - HTML Format'),
88 CRM_Core_DAO
::getAttribute('CRM_Mailing_DAO_Component', 'body_html')
91 $this->add('checkbox', 'is_default', ts('Default?'));
92 $this->add('checkbox', 'is_active', ts('Enabled?'));
94 $this->addFormRule(array('CRM_Mailing_Form_Component', 'dataRule'));
96 $this->addButtons(array(
104 'name' => ts('Cancel'),
111 * Set default values for the form.
116 public function setDefaultValues() {
120 if (isset($this->_id
)) {
121 $params = array('id' => $this->_id
);
122 $baoName = $this->_BAOName
;
123 $baoName::retrieve($params, $defaults);
125 $defaults['is_active'] = 1;
131 * Process the form submission.
136 public function postProcess() {
137 // store the submitted values in an array
138 $params = $this->controller
->exportValues($this->_name
);
140 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
141 $params['id'] = $this->_id
;
144 $component = CRM_Mailing_BAO_Component
::add($params);
145 CRM_Core_Session
::setStatus(ts('The mailing component \'%1\' has been saved.', array(
146 1 => $component->name
,
148 ), ts('Saved'), 'success');
155 * @param array $params
156 * (ref.) an assoc array of name/value pairs.
162 * mixed true or array of errors
164 public static function dataRule($params, $files, $options) {
165 if ($params['component_type'] == 'Header' ||
$params['component_type'] == 'Footer') {
166 $InvalidTokens = array();
169 $InvalidTokens = array('action.forward' => ts("This token can only be used in send mailing context (body, header, footer).."));
176 $dataErrors = array();
177 foreach ($InvalidTokens as $token => $desc) {
178 if ($params['body_' . $type]) {
179 if (preg_match('/' . preg_quote('{' . $token . '}') . '/', $params['body_' . $type])) {
180 $dataErrors[] = '<li>' . ts('This message is having a invalid token - %1: %2', array(
187 if (!empty($dataErrors)) {
188 $errors['body_' . $type] = ts('The following errors were detected in %1 message:', array(
190 )) . '<ul>' . implode('', $dataErrors) . '</ul><br /><a href="' . CRM_Utils_System
::docURL2('Tokens', TRUE, NULL, NULL, NULL, "wiki") . '">' . ts('More information on tokens...') . '</a>';
194 return empty($errors) ?
TRUE : $errors;