Convert Contact Search to metadata driven
[civicrm-core.git] / CRM / Admin / Form / Preferences / Display.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
8c9251b3 6 | Copyright CiviCRM LLC (c) 2004-2018 |
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
8c9251b3 31 * @copyright CiviCRM LLC (c) 2004-2018
6a488035
TO
32 */
33
c866eb5f
TO
34/**
35 * This class generates form components for the display preferences.
6a488035
TO
36 */
37class CRM_Admin_Form_Preferences_Display extends CRM_Admin_Form_Preferences {
a55c9b35 38
39 protected $_settings = array(
40 'contact_view_options' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
c5af8245 41 'contact_smart_group_display' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
2e94f477 42 'advanced_search_options' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
a55c9b35 43 );
44
00be9182 45 public function preProcess() {
6a488035 46 CRM_Utils_System::setTitle(ts('Settings - Display Preferences'));
e680ea41 47 $optionValues = CRM_Activity_BAO_Activity::buildOptions('activity_type_id');
6a488035 48
6a488035 49 $this->_varNames = array(
9d72cede 50 CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME => array(
6a488035
TO
51 'contact_edit_options' => array(
52 'html_type' => 'checkboxes',
53 'title' => ts('Editing Contacts'),
65f9bd70 54 'weight' => 3,
6a488035 55 ),
6a488035
TO
56 'activity_assignee_notification' => array(
57 'html_type' => 'checkbox',
58 'title' => ts('Notify Activity Assignees'),
59 'weight' => 5,
60 ),
61 'activity_assignee_notification_ics' => array(
62 'html_type' => 'checkbox',
63 'title' => ts('Include ICal Invite to Activity Assignees'),
65f9bd70 64 'weight' => 6,
6a488035 65 ),
a6d192c8 66 'preserve_activity_tab_filter' => array(
67 'html_type' => 'checkbox',
68 'title' => ts('Preserve activity filters as a user preference'),
69 'weight' => 7,
70 ),
6a488035 71 'contact_ajax_check_similar' => array(
6a488035 72 'title' => ts('Check for Similar Contacts'),
a6d192c8 73 'weight' => 8,
d6def514 74 'html_type' => NULL,
6a488035
TO
75 ),
76 'user_dashboard_options' => array(
77 'html_type' => 'checkboxes',
78 'title' => ts('Contact Dashboard'),
a6d192c8 79 'weight' => 9,
6a488035
TO
80 ),
81 'display_name_format' => array(
82 'html_type' => 'textarea',
83 'title' => ts('Individual Display Name Format'),
a6d192c8 84 'weight' => 10,
6a488035
TO
85 ),
86 'sort_name_format' => array(
87 'html_type' => 'textarea',
88 'title' => ts('Individual Sort Name Format'),
a6d192c8 89 'weight' => 11,
6a488035
TO
90 ),
91 'editor_id' => array(
92 'html_type' => NULL,
a6d192c8 93 'weight' => 12,
6a488035 94 ),
53f2643c 95 'ajaxPopupsEnabled' => array(
f1cf499b
CW
96 'html_type' => 'checkbox',
97 'title' => ts('Enable Popup Forms'),
a6d192c8 98 'weight' => 13,
f1cf499b 99 ),
b5407aa9
JP
100 'do_not_notify_assignees_for' => array(
101 'html_type' => 'select',
102 'option_values' => $optionValues,
103 'attributes' => array('multiple' => 1, "class" => "huge crm-select2"),
104 'title' => ts('Do not notify assignees for'),
ac983377
JP
105 'weight' => 14,
106 ),
6a488035
TO
107 ),
108 );
109
6a488035
TO
110 parent::preProcess();
111 }
112
e0ef6999
EM
113 /**
114 * @return array
115 */
00be9182 116 public function setDefaultValues() {
6a488035
TO
117 $defaults = parent::setDefaultValues();
118 parent::cbsDefaultValues($defaults);
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
TO
132 */
133 public function buildQuickForm() {
72f03b4f 134 $wysiwyg_options = CRM_Core_OptionGroup::values('wysiwyg_editor', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name');
6a488035 135
e0d683cf 136 //changes for freezing the invoices/credit notes checkbox if invoicing is uncheck
aaffa79f 137 $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
e0d683cf
PB
138 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
139 $this->assign('invoicing', $invoicing);
6a488035
TO
140 $extra = array();
141
6a488035 142 $this->addElement('select', 'editor_id', ts('WYSIWYG Editor'), $wysiwyg_options, $extra);
7266e09b 143 $this->addElement('submit', 'ckeditor_config', ts('Configure CKEditor'));
6a488035 144
d6def514
CW
145 $this->addRadio('contact_ajax_check_similar', ts('Check for Similar Contacts'), array(
146 '1' => ts('While Typing'),
147 '0' => ts('When Saving'),
148 '2' => ts('Never'),
149 ));
150
6a488035
TO
151 $editOptions = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 0');
152 $this->assign('editOptions', $editOptions);
153
154 $contactBlocks = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 1');
155 $this->assign('contactBlocks', $contactBlocks);
156
8b49cb50
OB
157 $nameFields = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 2');
158 $this->assign('nameFields', $nameFields);
159
6a488035
TO
160 $this->addElement('hidden', 'contact_edit_preferences', NULL, array('id' => 'contact_edit_preferences'));
161
9148c277 162 $optionValues = CRM_Core_OptionGroup::values('user_dashboard_options', FALSE, FALSE, FALSE, NULL, 'name');
e0d683cf
PB
163 $invoicesKey = array_search('Invoices / Credit Notes', $optionValues);
164 $this->assign('invoicesKey', $invoicesKey);
6a488035
TO
165 parent::buildQuickForm();
166 }
167
168 /**
eceb18cc 169 * Process the form submission.
6a488035
TO
170 */
171 public function postProcess() {
172 if ($this->_action == CRM_Core_Action::VIEW) {
173 return;
174 }
175
176 $this->_params = $this->controller->exportValues($this->_name);
177
a7488080 178 if (!empty($this->_params['contact_edit_preferences'])) {
6a488035
TO
179 $preferenceWeights = explode(',', $this->_params['contact_edit_preferences']);
180 foreach ($preferenceWeights as $key => $val) {
181 if (!$val) {
182 unset($preferenceWeights[$key]);
183 }
184 }
185 $opGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'contact_edit_options', 'id', 'name');
186 CRM_Core_BAO_OptionValue::updateOptionWeights($opGroupId, array_flip($preferenceWeights));
187 }
188
6a488035
TO
189 $this->_config->editor_id = $this->_params['editor_id'];
190
6a488035 191 $this->postProcessCommon();
7266e09b 192
d6def514
CW
193 // Fixme - shouldn't be needed
194 Civi::settings()->set('contact_ajax_check_similar', $this->_params['contact_ajax_check_similar']);
195
7266e09b
CW
196 // If "Configure CKEditor" button was clicked
197 if (!empty($this->_params['ckeditor_config'])) {
198 // Suppress the "Saved" status message and redirect to the CKEditor Config page
199 $session = CRM_Core_Session::singleton();
200 $session->getStatus(TRUE);
201 $url = CRM_Utils_System::url('civicrm/admin/ckeditor', 'reset=1');
202 $session->pushUserContext($url);
203 }
6a488035 204 }
96025800 205
6a488035 206}