Make `formal_title` field optional
[civicrm-core.git] / CRM / Admin / Form / Preferences / Display.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
232624b1 4 | CiviCRM version 4.4 |
6a488035
TO
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2013
32 * $Id: Display.php 45499 2013-02-08 12:31:05Z kurund $
33 *
34 */
35
36/**r
37 * This class generates form components for the display preferences
38 *
39 */
40class CRM_Admin_Form_Preferences_Display extends CRM_Admin_Form_Preferences {
41 function preProcess() {
42 CRM_Utils_System::setTitle(ts('Settings - Display Preferences'));
43
44 if (defined('CIVICRM_ACTIVITY_ASSIGNEE_MAIL') && CIVICRM_ACTIVITY_ASSIGNEE_MAIL) {
68679c0d
KJ
45 CRM_Core_Session::setStatus(ts('Your civicrm.settings.php file contains CIVICRM_ACTIVITY_ASSIGNEE_MAIL but this
46 constant is no longer used. Please remove this from your config file and set your "Notify Activity Assignees"
47 preference below.'), ts("Deprecated Constant"), "alert");
6a488035
TO
48 }
49
50 $this->_varNames = array(
51 CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME =>
52 array(
53 'contact_view_options' => array(
54 'html_type' => 'checkboxes',
55 'title' => ts('Viewing Contacts'),
56 'weight' => 1,
57 ),
65f9bd70
KJ
58 'contact_smart_group_display' => array(
59 'html_type' => 'radio',
60 'title' => ts('Viewing Smart Groups'),
61 'weight' => 2,
62 ),
6a488035
TO
63 'contact_edit_options' => array(
64 'html_type' => 'checkboxes',
65 'title' => ts('Editing Contacts'),
65f9bd70 66 'weight' => 3,
6a488035
TO
67 ),
68 'advanced_search_options' => array(
69 'html_type' => 'checkboxes',
70 'title' => ts('Contact Search'),
65f9bd70 71 'weight' => 4,
6a488035
TO
72 ),
73 'activity_assignee_notification' => array(
74 'html_type' => 'checkbox',
75 'title' => ts('Notify Activity Assignees'),
76 'weight' => 5,
77 ),
78 'activity_assignee_notification_ics' => array(
79 'html_type' => 'checkbox',
80 'title' => ts('Include ICal Invite to Activity Assignees'),
65f9bd70 81 'weight' => 6,
6a488035
TO
82 ),
83 'contact_ajax_check_similar' => array(
84 'html_type' => 'checkbox',
85 'title' => ts('Check for Similar Contacts'),
65f9bd70 86 'weight' => 7,
6a488035
TO
87 ),
88 'user_dashboard_options' => array(
89 'html_type' => 'checkboxes',
90 'title' => ts('Contact Dashboard'),
65f9bd70 91 'weight' => 8,
6a488035
TO
92 ),
93 'display_name_format' => array(
94 'html_type' => 'textarea',
95 'title' => ts('Individual Display Name Format'),
65f9bd70 96 'weight' => 9,
6a488035
TO
97 ),
98 'sort_name_format' => array(
99 'html_type' => 'textarea',
100 'title' => ts('Individual Sort Name Format'),
65f9bd70 101 'weight' => 10,
6a488035
TO
102 ),
103 'editor_id' => array(
104 'html_type' => NULL,
65f9bd70 105 'weight' => 11,
6a488035 106 ),
5b5217d7
OB
107 'formal_title' => array(
108 'html_type' => 'checkbox',
109 'title' => ts('Use Formal Title Field'),
110 'weight' => 12,
111 ),
6a488035
TO
112 ),
113 );
114
6a488035
TO
115 parent::preProcess();
116 }
117
118 function setDefaultValues() {
119 $defaults = parent::setDefaultValues();
120 parent::cbsDefaultValues($defaults);
121
122 if ($this->_config->editor_id) {
123 $defaults['editor_id'] = $this->_config->editor_id;
124 }
125 if (empty($this->_config->display_name_format)) {
68679c0d
KJ
126 $defaults['display_name_format'] =
127 "{contact.individual_prefix}{ }{contact.first_name}{ }{contact.last_name}{ }{contact.individual_suffix}";
6a488035
TO
128 }
129 else {
130 $defaults['display_name_format'] = $this->_config->display_name_format;
131 }
132
133 if (empty($this->_config->sort_name_format)) {
134 $defaults['sort_name_format'] = "{contact.last_name}{, }{contact.first_name}";
135 }
136 else {
137 $defaults['sort_name_format'] = $this->_config->sort_name_format;
138 }
139
140 $config = CRM_Core_Config::singleton();
68679c0d 141 if ($config->userSystem->is_drupal == '1' && module_exists("wysiwyg")) {
6a488035
TO
142 $defaults['wysiwyg_input_format'] = variable_get('civicrm_wysiwyg_input_format', 0);
143 }
144
145 return $defaults;
146 }
147
148 /**
149 * Function to build the form
150 *
151 * @return None
152 * @access public
153 */
154 public function buildQuickForm() {
cbf48754 155 $wysiwyg_options = array('' => ts('Textarea')) + CRM_Core_OptionGroup::values('wysiwyg_editor');
6a488035
TO
156
157 $config = CRM_Core_Config::singleton();
158 $extra = array();
159
160 //if not using Joomla, remove Joomla default editor option
161 if ($config->userFramework != 'Joomla') {
162 unset($wysiwyg_options[3]);
163 }
164
165 $drupal_wysiwyg = FALSE;
68679c0d 166 if (!$config->userSystem->is_drupal || !module_exists("wysiwyg")) {
6a488035
TO
167 unset($wysiwyg_options[4]);
168 }
169 else {
68679c0d
KJ
170 $extra['onchange'] = '
171 if (this.value==4) {
172 cj("#crm-preferences-display-form-block-wysiwyg_input_format").show();
173 }
174 else {
175 cj("#crm-preferences-display-form-block-wysiwyg_input_format").hide()
176 }';
6a488035
TO
177
178 $formats = filter_formats();
179 $format_options = array();
180 foreach ($formats as $id => $format) {
181 $format_options[$id] = $format->name;
182 }
183 $drupal_wysiwyg = TRUE;
184 }
185 $this->addElement('select', 'editor_id', ts('WYSIWYG Editor'), $wysiwyg_options, $extra);
186
187 if ($drupal_wysiwyg) {
188 $this->addElement('select', 'wysiwyg_input_format', ts('Input Format'), $format_options, NULL);
189 }
68679c0d 190
6a488035
TO
191 $editOptions = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 0');
192 $this->assign('editOptions', $editOptions);
193
194 $contactBlocks = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 1');
195 $this->assign('contactBlocks', $contactBlocks);
196
197 $this->addElement('hidden', 'contact_edit_preferences', NULL, array('id' => 'contact_edit_preferences'));
198
199 parent::buildQuickForm();
200 }
201
202 /**
203 * Function to process the form
204 *
205 * @access public
206 *
207 * @return None
208 */
209 public function postProcess() {
210 if ($this->_action == CRM_Core_Action::VIEW) {
211 return;
212 }
213
214 $this->_params = $this->controller->exportValues($this->_name);
215
216 if (CRM_Utils_Array::value('contact_edit_preferences', $this->_params)) {
217 $preferenceWeights = explode(',', $this->_params['contact_edit_preferences']);
218 foreach ($preferenceWeights as $key => $val) {
219 if (!$val) {
220 unset($preferenceWeights[$key]);
221 }
222 }
223 $opGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'contact_edit_options', 'id', 'name');
224 CRM_Core_BAO_OptionValue::updateOptionWeights($opGroupId, array_flip($preferenceWeights));
225 }
226
227 $config = CRM_Core_Config::singleton();
68679c0d 228 if ($config->userSystem->is_drupal == '1' && module_exists("wysiwyg")) {
6a488035
TO
229 variable_set('civicrm_wysiwyg_input_format', $this->_params['wysiwyg_input_format']);
230 }
231
232 $this->_config->editor_id = $this->_params['editor_id'];
233
234 // set default editor to session if changed
235 $session = CRM_Core_Session::singleton();
236 $session->set('defaultWysiwygEditor', $this->_params['editor_id']);
237
238 $this->postProcessCommon();
239 }
240 //end of function
241}
242