Merge pull request #13890 from aydun/joomla#6
[civicrm-core.git] / CRM / Admin / Form / Preferences / Display.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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-2019
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
39 protected $_settings = [
40 'contact_view_options' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
41 'contact_smart_group_display' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
42 'contact_edit_options' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
43 'advanced_search_options' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
44 'user_dashboard_options' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
45 'contact_ajax_check_similar' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
46 'activity_assignee_notification' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
47 'activity_assignee_notification_ics' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
48 'do_not_notify_assignees_for' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
49 'preserve_activity_tab_filter' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
50 'editor_id' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
51 'ajaxPopupsEnabled' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
52 'display_name_format' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
53 'sort_name_format' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
54 'menubar_position' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
55 'menubar_color' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
56 ];
57
58 /**
59 * Build the form object.
60 */
61 public function buildQuickForm() {
62
63 //changes for freezing the invoices/credit notes checkbox if invoicing is uncheck
64 $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
65 $this->assign('invoicing', CRM_Invoicing_Utils::isInvoicingEnabled());
66
67 $this->addElement('submit', 'ckeditor_config', ts('Configure CKEditor'));
68
69 $editOptions = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 0');
70 $this->assign('editOptions', $editOptions);
71
72 $contactBlocks = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 1');
73 $this->assign('contactBlocks', $contactBlocks);
74
75 $nameFields = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 2');
76 $this->assign('nameFields', $nameFields);
77
78 $this->addElement('hidden', 'contact_edit_preferences', NULL, ['id' => 'contact_edit_preferences']);
79
80 $optionValues = CRM_Core_OptionGroup::values('user_dashboard_options', FALSE, FALSE, FALSE, NULL, 'name');
81 $invoicesKey = array_search('Invoices / Credit Notes', $optionValues);
82 $this->assign('invoicesKey', $invoicesKey);
83 parent::buildQuickForm();
84 }
85
86 /**
87 * Process the form submission.
88 */
89 public function postProcess() {
90 if ($this->_action == CRM_Core_Action::VIEW) {
91 return;
92 }
93
94 $this->_params = $this->controller->exportValues($this->_name);
95
96 if (!empty($this->_params['contact_edit_preferences'])) {
97 $preferenceWeights = explode(',', $this->_params['contact_edit_preferences']);
98 foreach ($preferenceWeights as $key => $val) {
99 if (!$val) {
100 unset($preferenceWeights[$key]);
101 }
102 }
103 $opGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'contact_edit_options', 'id', 'name');
104 CRM_Core_BAO_OptionValue::updateOptionWeights($opGroupId, array_flip($preferenceWeights));
105 }
106
107 $this->postProcessCommon();
108
109 // If "Configure CKEditor" button was clicked
110 if (!empty($this->_params['ckeditor_config'])) {
111 // Suppress the "Saved" status message and redirect to the CKEditor Config page
112 $session = CRM_Core_Session::singleton();
113 $session->getStatus(TRUE);
114 $url = CRM_Utils_System::url('civicrm/admin/ckeditor', 'reset=1');
115 $session->pushUserContext($url);
116 }
117 }
118
119 }