empty is valid value for display and sort_name_format
[civicrm-core.git] / CRM / Admin / Form / Preferences / Display.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
e7112fa7 31 * @copyright CiviCRM LLC (c) 2004-2015
6a488035
TO
32 * $Id: Display.php 45499 2013-02-08 12:31:05Z kurund $
33 *
34 */
35
c866eb5f
TO
36/**
37 * This class generates form components for the display preferences.
6a488035
TO
38 */
39class CRM_Admin_Form_Preferences_Display extends CRM_Admin_Form_Preferences {
00be9182 40 public function preProcess() {
6a488035
TO
41 CRM_Utils_System::setTitle(ts('Settings - Display Preferences'));
42
6a488035 43 $this->_varNames = array(
9d72cede 44 CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME => array(
6a488035
TO
45 'contact_view_options' => array(
46 'html_type' => 'checkboxes',
47 'title' => ts('Viewing Contacts'),
48 'weight' => 1,
49 ),
65f9bd70
KJ
50 'contact_smart_group_display' => array(
51 'html_type' => 'radio',
52 'title' => ts('Viewing Smart Groups'),
53 'weight' => 2,
54 ),
6a488035
TO
55 'contact_edit_options' => array(
56 'html_type' => 'checkboxes',
57 'title' => ts('Editing Contacts'),
65f9bd70 58 'weight' => 3,
6a488035
TO
59 ),
60 'advanced_search_options' => array(
61 'html_type' => 'checkboxes',
62 'title' => ts('Contact Search'),
65f9bd70 63 'weight' => 4,
6a488035
TO
64 ),
65 'activity_assignee_notification' => array(
66 'html_type' => 'checkbox',
67 'title' => ts('Notify Activity Assignees'),
68 'weight' => 5,
69 ),
70 'activity_assignee_notification_ics' => array(
71 'html_type' => 'checkbox',
72 'title' => ts('Include ICal Invite to Activity Assignees'),
65f9bd70 73 'weight' => 6,
6a488035
TO
74 ),
75 'contact_ajax_check_similar' => array(
76 'html_type' => 'checkbox',
77 'title' => ts('Check for Similar Contacts'),
65f9bd70 78 'weight' => 7,
6a488035
TO
79 ),
80 'user_dashboard_options' => array(
81 'html_type' => 'checkboxes',
82 'title' => ts('Contact Dashboard'),
65f9bd70 83 'weight' => 8,
6a488035
TO
84 ),
85 'display_name_format' => array(
86 'html_type' => 'textarea',
87 'title' => ts('Individual Display Name Format'),
65f9bd70 88 'weight' => 9,
6a488035
TO
89 ),
90 'sort_name_format' => array(
91 'html_type' => 'textarea',
92 'title' => ts('Individual Sort Name Format'),
65f9bd70 93 'weight' => 10,
6a488035
TO
94 ),
95 'editor_id' => array(
96 'html_type' => NULL,
65f9bd70 97 'weight' => 11,
6a488035 98 ),
53f2643c 99 'ajaxPopupsEnabled' => array(
f1cf499b
CW
100 'html_type' => 'checkbox',
101 'title' => ts('Enable Popup Forms'),
102 'weight' => 12,
103 ),
6a488035
TO
104 ),
105 );
106
6a488035
TO
107 parent::preProcess();
108 }
109
e0ef6999
EM
110 /**
111 * @return array
112 */
00be9182 113 public function setDefaultValues() {
6a488035
TO
114 $defaults = parent::setDefaultValues();
115 parent::cbsDefaultValues($defaults);
116
117 if ($this->_config->editor_id) {
118 $defaults['editor_id'] = $this->_config->editor_id;
119 }
f5276b10 120 if ($this->_config->display_name_format) {
6a488035
TO
121 $defaults['display_name_format'] = $this->_config->display_name_format;
122 }
f5276b10 123 if ($this->_config->sort_name_format) {
6a488035
TO
124 $defaults['sort_name_format'] = $this->_config->sort_name_format;
125 }
126
6a488035
TO
127 return $defaults;
128 }
129
130 /**
eceb18cc 131 * Build the form object.
6a488035 132 *
355ba699 133 * @return void
6a488035
TO
134 */
135 public function buildQuickForm() {
6cc25669 136 $wysiwyg_options = CRM_Core_OptionGroup::values('wysiwyg_editor');
6a488035 137
e0d683cf 138 //changes for freezing the invoices/credit notes checkbox if invoicing is uncheck
9148c277 139 $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
e0d683cf
PB
140 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
141 $this->assign('invoicing', $invoicing);
6a488035
TO
142 $config = CRM_Core_Config::singleton();
143 $extra = array();
144
6a488035
TO
145 $this->addElement('select', 'editor_id', ts('WYSIWYG Editor'), $wysiwyg_options, $extra);
146
6a488035
TO
147 $editOptions = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 0');
148 $this->assign('editOptions', $editOptions);
149
150 $contactBlocks = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 1');
151 $this->assign('contactBlocks', $contactBlocks);
152
8b49cb50
OB
153 $nameFields = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 2');
154 $this->assign('nameFields', $nameFields);
155
6a488035
TO
156 $this->addElement('hidden', 'contact_edit_preferences', NULL, array('id' => 'contact_edit_preferences'));
157
9148c277 158 $optionValues = CRM_Core_OptionGroup::values('user_dashboard_options', FALSE, FALSE, FALSE, NULL, 'name');
e0d683cf
PB
159 $invoicesKey = array_search('Invoices / Credit Notes', $optionValues);
160 $this->assign('invoicesKey', $invoicesKey);
6a488035
TO
161 parent::buildQuickForm();
162 }
163
164 /**
eceb18cc 165 * Process the form submission.
6a488035 166 *
6a488035 167 *
355ba699 168 * @return void
6a488035
TO
169 */
170 public function postProcess() {
171 if ($this->_action == CRM_Core_Action::VIEW) {
172 return;
173 }
174
175 $this->_params = $this->controller->exportValues($this->_name);
176
a7488080 177 if (!empty($this->_params['contact_edit_preferences'])) {
6a488035
TO
178 $preferenceWeights = explode(',', $this->_params['contact_edit_preferences']);
179 foreach ($preferenceWeights as $key => $val) {
180 if (!$val) {
181 unset($preferenceWeights[$key]);
182 }
183 }
184 $opGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'contact_edit_options', 'id', 'name');
185 CRM_Core_BAO_OptionValue::updateOptionWeights($opGroupId, array_flip($preferenceWeights));
186 }
187
6a488035
TO
188 $this->_config->editor_id = $this->_params['editor_id'];
189
6a488035
TO
190 $this->postProcessCommon();
191 }
96025800 192
6a488035 193}