3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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-2017
35 * This class handles mail account settings.
38 class CRM_Admin_Form_MailSettings
extends CRM_Admin_Form
{
41 * Build the form object.
43 public function buildQuickForm() {
44 parent
::buildQuickForm();
45 $this->setPageTitle(ts('Mail Account'));
47 if ($this->_action
& CRM_Core_Action
::DELETE
) {
51 $this->applyFilter('__ALL__', 'trim');
54 $attributes = CRM_Core_DAO
::getAttribute('CRM_Core_DAO_MailSettings');
57 $this->add('text', 'name', ts('Name'), $attributes['name'], TRUE);
59 $this->add('text', 'domain', ts('Email Domain'), $attributes['domain'], TRUE);
60 $this->addRule('domain', ts('Email domain must use a valid internet domain format (e.g. \'example.org\').'), 'domain');
62 $this->add('text', 'localpart', ts('Localpart'), $attributes['localpart']);
64 $this->add('text', 'return_path', ts('Return-Path'), $attributes['return_path']);
65 $this->addRule('return_path', ts('Return-Path must use a valid email address format.'), 'email');
67 $this->add('select', 'protocol',
69 array('' => ts('- select -')) + CRM_Core_PseudoConstant
::get('CRM_Core_DAO_MailSettings', 'protocol'),
73 $this->add('text', 'server', ts('Server'), $attributes['server']);
75 $this->add('text', 'username', ts('Username'), array('autocomplete' => 'off'));
77 $this->add('password', 'password', ts('Password'), array('autocomplete' => 'off'));
79 $this->add('text', 'source', ts('Source'), $attributes['source']);
81 $this->add('checkbox', 'is_ssl', ts('Use SSL?'));
84 1 => ts('Bounce Processing'),
85 0 => ts('Email-to-Activity Processing'),
87 $this->add('select', 'is_default', ts('Used For?'), $usedfor);
91 * Add local and global form rules.
93 public function addRules() {
94 $this->addFormRule(array('CRM_Admin_Form_MailSettings', 'formRule'));
98 * Global validation rules for the form.
100 * @param array $fields
101 * Posted values of the form.
104 * list of errors to be posted back to the form
106 public static function formRule($fields) {
108 // Check for default from email address and organization (domain) name. Force them to change it.
109 if ($fields['domain'] == 'EXAMPLE.ORG') {
110 $errors['domain'] = ts('Please enter a valid domain for this mailbox account (the part after @).');
113 return empty($errors) ?
TRUE : $errors;
117 * Process the form submission.
119 public function postProcess() {
120 if ($this->_action
& CRM_Core_Action
::DELETE
) {
121 CRM_Core_BAO_MailSettings
::deleteMailSettings($this->_id
);
122 CRM_Core_Session
::setStatus("", ts('Mail Setting Deleted.'), "success");
126 //get the submitted form values.
127 $formValues = $this->controller
->exportValues($this->_name
);
146 foreach ($fields as $f) {
147 if (in_array($f, array(
151 $params[$f] = CRM_Utils_Array
::value($f, $formValues, FALSE);
154 $params[$f] = CRM_Utils_Array
::value($f, $formValues);
158 $params['domain_id'] = CRM_Core_Config
::domainID();
160 // assign id only in update mode
161 $status = ts('Your New Email Settings have been saved.');
162 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
163 $params['id'] = $this->_id
;
164 $status = ts('Your Email Settings have been updated.');
167 $mailSettings = CRM_Core_BAO_MailSettings
::create($params);
169 if ($mailSettings->id
) {
170 CRM_Core_Session
::setStatus($status, ts("Saved"), "success");
173 CRM_Core_Session
::setStatus("", ts('Changes Not Saved.'), "info");