Merge pull request #12868 from mattwire/updatesubscription_datepicker
[civicrm-core.git] / CRM / Admin / Form / Preferences / Display.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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-2018
32 */
33
34 /**
35 * This class generates form components for the display preferences.
36 */
37 class CRM_Admin_Form_Preferences_Display extends CRM_Admin_Form_Preferences {
38 public function preProcess() {
39 CRM_Utils_System::setTitle(ts('Settings - Display Preferences'));
40 $optionValues = CRM_Activity_BAO_Activity::buildOptions('activity_type_id');
41
42 $this->_varNames = array(
43 CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME => array(
44 'contact_view_options' => array(
45 'html_type' => 'checkboxes',
46 'title' => ts('Viewing Contacts'),
47 'weight' => 1,
48 ),
49 'contact_smart_group_display' => array(
50 'html_type' => 'radio',
51 'title' => ts('Viewing Smart Groups'),
52 'weight' => 2,
53 ),
54 'contact_edit_options' => array(
55 'html_type' => 'checkboxes',
56 'title' => ts('Editing Contacts'),
57 'weight' => 3,
58 ),
59 'advanced_search_options' => array(
60 'html_type' => 'checkboxes',
61 'title' => ts('Contact Search'),
62 'weight' => 4,
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'),
72 'weight' => 6,
73 ),
74 'preserve_activity_tab_filter' => array(
75 'html_type' => 'checkbox',
76 'title' => ts('Preserve activity filters as a user preference'),
77 'weight' => 7,
78 ),
79 'contact_ajax_check_similar' => array(
80 'title' => ts('Check for Similar Contacts'),
81 'weight' => 8,
82 'html_type' => NULL,
83 ),
84 'user_dashboard_options' => array(
85 'html_type' => 'checkboxes',
86 'title' => ts('Contact Dashboard'),
87 'weight' => 9,
88 ),
89 'display_name_format' => array(
90 'html_type' => 'textarea',
91 'title' => ts('Individual Display Name Format'),
92 'weight' => 10,
93 ),
94 'sort_name_format' => array(
95 'html_type' => 'textarea',
96 'title' => ts('Individual Sort Name Format'),
97 'weight' => 11,
98 ),
99 'editor_id' => array(
100 'html_type' => NULL,
101 'weight' => 12,
102 ),
103 'ajaxPopupsEnabled' => array(
104 'html_type' => 'checkbox',
105 'title' => ts('Enable Popup Forms'),
106 'weight' => 13,
107 ),
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'),
113 'weight' => 14,
114 ),
115 ),
116 );
117
118 parent::preProcess();
119 }
120
121 /**
122 * @return array
123 */
124 public function setDefaultValues() {
125 $defaults = parent::setDefaultValues();
126 parent::cbsDefaultValues($defaults);
127
128 if ($this->_config->display_name_format) {
129 $defaults['display_name_format'] = $this->_config->display_name_format;
130 }
131 if ($this->_config->sort_name_format) {
132 $defaults['sort_name_format'] = $this->_config->sort_name_format;
133 }
134
135 return $defaults;
136 }
137
138 /**
139 * Build the form object.
140 */
141 public function buildQuickForm() {
142 $wysiwyg_options = CRM_Core_OptionGroup::values('wysiwyg_editor', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name');
143
144 //changes for freezing the invoices/credit notes checkbox if invoicing is uncheck
145 $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
146 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
147 $this->assign('invoicing', $invoicing);
148 $extra = array();
149
150 $this->addElement('select', 'editor_id', ts('WYSIWYG Editor'), $wysiwyg_options, $extra);
151 $this->addElement('submit', 'ckeditor_config', ts('Configure CKEditor'));
152
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
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
165 $nameFields = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 2');
166 $this->assign('nameFields', $nameFields);
167
168 $this->addElement('hidden', 'contact_edit_preferences', NULL, array('id' => 'contact_edit_preferences'));
169
170 $optionValues = CRM_Core_OptionGroup::values('user_dashboard_options', FALSE, FALSE, FALSE, NULL, 'name');
171 $invoicesKey = array_search('Invoices / Credit Notes', $optionValues);
172 $this->assign('invoicesKey', $invoicesKey);
173 parent::buildQuickForm();
174 }
175
176 /**
177 * Process the form submission.
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
186 if (!empty($this->_params['contact_edit_preferences'])) {
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
197 $this->_config->editor_id = $this->_params['editor_id'];
198
199 $this->postProcessCommon();
200
201 // Fixme - shouldn't be needed
202 Civi::settings()->set('contact_ajax_check_similar', $this->_params['contact_ajax_check_similar']);
203
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 }
212 }
213
214 }