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 handles mail account settings.
40 class CRM_Admin_Form_MailSettings
extends CRM_Admin_Form
{
43 * Build the form object
47 public function buildQuickForm() {
48 parent
::buildQuickForm();
49 $this->setPageTitle(ts('Mail Account'));
51 if ($this->_action
& CRM_Core_Action
::DELETE
) {
55 $this->applyFilter('__ALL__', 'trim');
58 $attributes = CRM_Core_DAO
::getAttribute('CRM_Core_DAO_MailSettings');
61 $this->add('text', 'name', ts('Name'), $attributes['name'], TRUE);
63 $this->add('text', 'domain', ts('Email Domain'), $attributes['domain'], TRUE);
64 $this->addRule('domain', ts('Email domain must use a valid internet domain format (e.g. \'example.org\').'), 'domain');
66 $this->add('text', 'localpart', ts('Localpart'), $attributes['localpart']);
68 $this->add('text', 'return_path', ts('Return-Path'), $attributes['return_path']);
69 $this->addRule('return_path', ts('Return-Path must use a valid email address format.'), 'email');
71 $this->add('select', 'protocol',
73 array('' => ts('- select -')) + CRM_Core_PseudoConstant
::get('CRM_Core_DAO_MailSettings', 'protocol'),
77 $this->add('text', 'server', ts('Server'), $attributes['server']);
79 $this->add('text', 'username', ts('Username'), array('autocomplete' => 'off'));
81 $this->add('password', 'password', ts('Password'), array('autocomplete' => 'off'));
83 $this->add('text', 'source', ts('Source'), $attributes['source']);
85 $this->add('checkbox', 'is_ssl', ts('Use SSL?'));
87 $usedfor = array(1 => ts('Bounce Processing'),
88 0 => ts('Email-to-Activity Processing'),
90 $this->add('select', 'is_default', ts('Used For?'), $usedfor);
94 * Add local and global form rules
99 public function addRules() {
100 $this->addFormRule(array('CRM_Admin_Form_MailSettings', 'formRule'));
104 * Global validation rules for the form
106 * @param array $fields posted values of the form
108 * @return array list of errors to be posted back to the form
111 public static function formRule($fields) {
113 // Check for default from email address and organization (domain) name. Force them to change it.
114 if ($fields['domain'] == 'EXAMPLE.ORG') {
115 $errors['domain'] = ts('Please enter a valid domain for this mailbox account (the part after @).');
118 return empty($errors) ?
TRUE : $errors;
122 * Process the form submission
127 public function postProcess() {
128 if ($this->_action
& CRM_Core_Action
::DELETE
) {
129 CRM_Core_BAO_MailSettings
::deleteMailSettings($this->_id
);
130 CRM_Core_Session
::setStatus("", ts('Mail Setting Deleted.'), "success");
134 //get the submitted form values.
135 $formValues = $this->controller
->exportValues($this->_name
);
154 foreach ($fields as $f) {
155 if (in_array($f, array(
156 'is_default', 'is_ssl'))) {
157 $params[$f] = CRM_Utils_Array
::value($f, $formValues, FALSE);
160 $params[$f] = CRM_Utils_Array
::value($f, $formValues);
164 $params['domain_id'] = CRM_Core_Config
::domainID();
166 // assign id only in update mode
167 $status = ts('Your New Email Settings have been saved.');
168 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
169 $params['id'] = $this->_id
;
170 $status = ts('Your Email Settings have been updated.');
173 $mailSettings = CRM_Core_BAO_MailSettings
::create($params);
175 if ($mailSettings->id
) {
176 CRM_Core_Session
::setStatus($status, ts("Saved"), "success");
179 CRM_Core_Session
::setStatus("", ts('Changes Not Saved.'), "info");