775fa2c04ec57cd741a37d0f837fc4884a88ce70
[civicrm-core.git] / CRM / Admin / Form / Preferences / Display.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This class generates form components for the display preferences.
20 */
21 class CRM_Admin_Form_Preferences_Display extends CRM_Admin_Form_Preferences {
22
23 protected $_settings = [
24 'contact_view_options' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
25 'contact_smart_group_display' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
26 'contact_edit_options' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
27 'advanced_search_options' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
28 'user_dashboard_options' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
29 'contact_ajax_check_similar' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
30 'activity_assignee_notification' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
31 'activity_assignee_notification_ics' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
32 'do_not_notify_assignees_for' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
33 'preserve_activity_tab_filter' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
34 'editor_id' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
35 'ajaxPopupsEnabled' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
36 'display_name_format' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
37 'sort_name_format' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
38 'menubar_position' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
39 'menubar_color' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
40 'theme_backend' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
41 'theme_frontend' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
42 ];
43
44 /**
45 * Build the form object.
46 */
47 public function buildQuickForm() {
48
49 //changes for freezing the invoices/credit notes checkbox if invoicing is uncheck
50 $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
51 $this->assign('invoicing', CRM_Invoicing_Utils::isInvoicingEnabled());
52
53 $this->addElement('submit', 'ckeditor_config', ts('Configure CKEditor'));
54
55 $editOptions = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 0');
56 $this->assign('editOptions', $editOptions);
57
58 $contactBlocks = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 1');
59 $this->assign('contactBlocks', $contactBlocks);
60
61 $nameFields = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 2');
62 $this->assign('nameFields', $nameFields);
63
64 $this->addElement('hidden', 'contact_edit_preferences', NULL, ['id' => 'contact_edit_preferences']);
65
66 $optionValues = CRM_Core_OptionGroup::values('user_dashboard_options', FALSE, FALSE, FALSE, NULL, 'name');
67 $invoicesKey = array_search('Invoices / Credit Notes', $optionValues);
68 $this->assign('invoicesKey', $invoicesKey);
69 parent::buildQuickForm();
70 }
71
72 /**
73 * Process the form submission.
74 */
75 public function postProcess() {
76 if ($this->_action == CRM_Core_Action::VIEW) {
77 return;
78 }
79
80 $this->_params = $this->controller->exportValues($this->_name);
81
82 if (!empty($this->_params['contact_edit_preferences'])) {
83 $preferenceWeights = explode(',', $this->_params['contact_edit_preferences']);
84 foreach ($preferenceWeights as $key => $val) {
85 if (!$val) {
86 unset($preferenceWeights[$key]);
87 }
88 }
89 $opGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'contact_edit_options', 'id', 'name');
90 CRM_Core_BAO_OptionValue::updateOptionWeights($opGroupId, array_flip($preferenceWeights));
91 }
92
93 $this->postProcessCommon();
94
95 // If "Configure CKEditor" button was clicked
96 if (!empty($this->_params['ckeditor_config'])) {
97 // Suppress the "Saved" status message and redirect to the CKEditor Config page
98 $session = CRM_Core_Session::singleton();
99 $session->getStatus(TRUE);
100 $url = CRM_Utils_System::url('civicrm/admin/ckeditor', 'reset=1');
101 $session->pushUserContext($url);
102 }
103 }
104
105 }