INFRA-132 - Trailing commas for multiline arrays
[civicrm-core.git] / CRM / Admin / Form / Preferences / Display.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
06b69b18 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
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
06b69b18 31 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
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 {
00be9182 41 public function preProcess() {
6a488035
TO
42 CRM_Utils_System::setTitle(ts('Settings - Display Preferences'));
43
6a488035 44 $this->_varNames = array(
9d72cede 45 CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME => array(
6a488035
TO
46 'contact_view_options' => array(
47 'html_type' => 'checkboxes',
48 'title' => ts('Viewing Contacts'),
49 'weight' => 1,
50 ),
65f9bd70
KJ
51 'contact_smart_group_display' => array(
52 'html_type' => 'radio',
53 'title' => ts('Viewing Smart Groups'),
54 'weight' => 2,
55 ),
6a488035
TO
56 'contact_edit_options' => array(
57 'html_type' => 'checkboxes',
58 'title' => ts('Editing Contacts'),
65f9bd70 59 'weight' => 3,
6a488035
TO
60 ),
61 'advanced_search_options' => array(
62 'html_type' => 'checkboxes',
63 'title' => ts('Contact Search'),
65f9bd70 64 'weight' => 4,
6a488035
TO
65 ),
66 'activity_assignee_notification' => array(
67 'html_type' => 'checkbox',
68 'title' => ts('Notify Activity Assignees'),
69 'weight' => 5,
70 ),
71 'activity_assignee_notification_ics' => array(
72 'html_type' => 'checkbox',
73 'title' => ts('Include ICal Invite to Activity Assignees'),
65f9bd70 74 'weight' => 6,
6a488035
TO
75 ),
76 'contact_ajax_check_similar' => array(
77 'html_type' => 'checkbox',
78 'title' => ts('Check for Similar Contacts'),
65f9bd70 79 'weight' => 7,
6a488035
TO
80 ),
81 'user_dashboard_options' => array(
82 'html_type' => 'checkboxes',
83 'title' => ts('Contact Dashboard'),
65f9bd70 84 'weight' => 8,
6a488035
TO
85 ),
86 'display_name_format' => array(
87 'html_type' => 'textarea',
88 'title' => ts('Individual Display Name Format'),
65f9bd70 89 'weight' => 9,
6a488035
TO
90 ),
91 'sort_name_format' => array(
92 'html_type' => 'textarea',
93 'title' => ts('Individual Sort Name Format'),
65f9bd70 94 'weight' => 10,
6a488035
TO
95 ),
96 'editor_id' => array(
97 'html_type' => NULL,
65f9bd70 98 'weight' => 11,
6a488035 99 ),
53f2643c 100 'ajaxPopupsEnabled' => array(
f1cf499b
CW
101 'html_type' => 'checkbox',
102 'title' => ts('Enable Popup Forms'),
103 'weight' => 12,
104 ),
6a488035
TO
105 ),
106 );
107
6a488035
TO
108 parent::preProcess();
109 }
110
e0ef6999
EM
111 /**
112 * @return array
113 */
00be9182 114 public function setDefaultValues() {
6a488035
TO
115 $defaults = parent::setDefaultValues();
116 parent::cbsDefaultValues($defaults);
117
118 if ($this->_config->editor_id) {
119 $defaults['editor_id'] = $this->_config->editor_id;
120 }
121 if (empty($this->_config->display_name_format)) {
68679c0d
KJ
122 $defaults['display_name_format'] =
123 "{contact.individual_prefix}{ }{contact.first_name}{ }{contact.last_name}{ }{contact.individual_suffix}";
6a488035
TO
124 }
125 else {
126 $defaults['display_name_format'] = $this->_config->display_name_format;
127 }
128
129 if (empty($this->_config->sort_name_format)) {
130 $defaults['sort_name_format'] = "{contact.last_name}{, }{contact.first_name}";
131 }
132 else {
133 $defaults['sort_name_format'] = $this->_config->sort_name_format;
134 }
135
136 $config = CRM_Core_Config::singleton();
68679c0d 137 if ($config->userSystem->is_drupal == '1' && module_exists("wysiwyg")) {
6a488035
TO
138 $defaults['wysiwyg_input_format'] = variable_get('civicrm_wysiwyg_input_format', 0);
139 }
140
141 return $defaults;
142 }
143
144 /**
c490a46a 145 * Build the form object
6a488035 146 *
355ba699 147 * @return void
6a488035
TO
148 */
149 public function buildQuickForm() {
cbf48754 150 $wysiwyg_options = array('' => ts('Textarea')) + CRM_Core_OptionGroup::values('wysiwyg_editor');
6a488035 151
e0d683cf 152 //changes for freezing the invoices/credit notes checkbox if invoicing is uncheck
9148c277 153 $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
e0d683cf
PB
154 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
155 $this->assign('invoicing', $invoicing);
6a488035
TO
156 $config = CRM_Core_Config::singleton();
157 $extra = array();
158
159 //if not using Joomla, remove Joomla default editor option
160 if ($config->userFramework != 'Joomla') {
161 unset($wysiwyg_options[3]);
162 }
163
164 $drupal_wysiwyg = FALSE;
68679c0d 165 if (!$config->userSystem->is_drupal || !module_exists("wysiwyg")) {
6a488035
TO
166 unset($wysiwyg_options[4]);
167 }
168 else {
68679c0d
KJ
169 $extra['onchange'] = '
170 if (this.value==4) {
171 cj("#crm-preferences-display-form-block-wysiwyg_input_format").show();
172 }
173 else {
174 cj("#crm-preferences-display-form-block-wysiwyg_input_format").hide()
175 }';
6a488035
TO
176
177 $formats = filter_formats();
178 $format_options = array();
179 foreach ($formats as $id => $format) {
180 $format_options[$id] = $format->name;
181 }
182 $drupal_wysiwyg = TRUE;
183 }
184 $this->addElement('select', 'editor_id', ts('WYSIWYG Editor'), $wysiwyg_options, $extra);
185
186 if ($drupal_wysiwyg) {
187 $this->addElement('select', 'wysiwyg_input_format', ts('Input Format'), $format_options, NULL);
188 }
68679c0d 189
6a488035
TO
190 $editOptions = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 0');
191 $this->assign('editOptions', $editOptions);
192
193 $contactBlocks = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 1');
194 $this->assign('contactBlocks', $contactBlocks);
195
8b49cb50
OB
196 $nameFields = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 2');
197 $this->assign('nameFields', $nameFields);
198
6a488035
TO
199 $this->addElement('hidden', 'contact_edit_preferences', NULL, array('id' => 'contact_edit_preferences'));
200
9148c277 201 $optionValues = CRM_Core_OptionGroup::values('user_dashboard_options', FALSE, FALSE, FALSE, NULL, 'name');
e0d683cf
PB
202 $invoicesKey = array_search('Invoices / Credit Notes', $optionValues);
203 $this->assign('invoicesKey', $invoicesKey);
6a488035
TO
204 parent::buildQuickForm();
205 }
206
207 /**
c490a46a 208 * Process the form submission
6a488035 209 *
6a488035 210 *
355ba699 211 * @return void
6a488035
TO
212 */
213 public function postProcess() {
214 if ($this->_action == CRM_Core_Action::VIEW) {
215 return;
216 }
217
218 $this->_params = $this->controller->exportValues($this->_name);
219
a7488080 220 if (!empty($this->_params['contact_edit_preferences'])) {
6a488035
TO
221 $preferenceWeights = explode(',', $this->_params['contact_edit_preferences']);
222 foreach ($preferenceWeights as $key => $val) {
223 if (!$val) {
224 unset($preferenceWeights[$key]);
225 }
226 }
227 $opGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'contact_edit_options', 'id', 'name');
228 CRM_Core_BAO_OptionValue::updateOptionWeights($opGroupId, array_flip($preferenceWeights));
229 }
230
231 $config = CRM_Core_Config::singleton();
68679c0d 232 if ($config->userSystem->is_drupal == '1' && module_exists("wysiwyg")) {
6a488035
TO
233 variable_set('civicrm_wysiwyg_input_format', $this->_params['wysiwyg_input_format']);
234 }
235
236 $this->_config->editor_id = $this->_params['editor_id'];
237
238 // set default editor to session if changed
239 $session = CRM_Core_Session::singleton();
240 $session->set('defaultWysiwygEditor', $this->_params['editor_id']);
241
242 $this->postProcessCommon();
243 }
6a488035 244}