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