Merge branch '4.6' into master
[civicrm-core.git] / CRM / Admin / Form / Preferences / Display.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
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
e7112fa7 31 * @copyright CiviCRM LLC (c) 2004-2015
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
TO
39 CRM_Utils_System::setTitle(ts('Settings - Display Preferences'));
40
6a488035 41 $this->_varNames = array(
9d72cede 42 CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME => array(
6a488035
TO
43 'contact_view_options' => array(
44 'html_type' => 'checkboxes',
45 'title' => ts('Viewing Contacts'),
46 'weight' => 1,
47 ),
65f9bd70
KJ
48 'contact_smart_group_display' => array(
49 'html_type' => 'radio',
50 'title' => ts('Viewing Smart Groups'),
51 'weight' => 2,
52 ),
6a488035
TO
53 'contact_edit_options' => array(
54 'html_type' => 'checkboxes',
55 'title' => ts('Editing Contacts'),
65f9bd70 56 'weight' => 3,
6a488035
TO
57 ),
58 'advanced_search_options' => array(
59 'html_type' => 'checkboxes',
60 'title' => ts('Contact Search'),
65f9bd70 61 'weight' => 4,
6a488035
TO
62 ),
63 'activity_assignee_notification' => array(
64 'html_type' => 'checkbox',
65 'title' => ts('Notify Activity Assignees'),
66 'weight' => 5,
67 ),
68 'activity_assignee_notification_ics' => array(
69 'html_type' => 'checkbox',
70 'title' => ts('Include ICal Invite to Activity Assignees'),
65f9bd70 71 'weight' => 6,
6a488035
TO
72 ),
73 'contact_ajax_check_similar' => array(
74 'html_type' => 'checkbox',
75 'title' => ts('Check for Similar Contacts'),
65f9bd70 76 'weight' => 7,
6a488035
TO
77 ),
78 'user_dashboard_options' => array(
79 'html_type' => 'checkboxes',
80 'title' => ts('Contact Dashboard'),
65f9bd70 81 'weight' => 8,
6a488035
TO
82 ),
83 'display_name_format' => array(
84 'html_type' => 'textarea',
85 'title' => ts('Individual Display Name Format'),
65f9bd70 86 'weight' => 9,
6a488035
TO
87 ),
88 'sort_name_format' => array(
89 'html_type' => 'textarea',
90 'title' => ts('Individual Sort Name Format'),
65f9bd70 91 'weight' => 10,
6a488035
TO
92 ),
93 'editor_id' => array(
94 'html_type' => NULL,
65f9bd70 95 'weight' => 11,
6a488035 96 ),
53f2643c 97 'ajaxPopupsEnabled' => array(
f1cf499b
CW
98 'html_type' => 'checkbox',
99 'title' => ts('Enable Popup Forms'),
100 'weight' => 12,
101 ),
6a488035
TO
102 ),
103 );
104
6a488035
TO
105 parent::preProcess();
106 }
107
e0ef6999
EM
108 /**
109 * @return array
110 */
00be9182 111 public function setDefaultValues() {
6a488035
TO
112 $defaults = parent::setDefaultValues();
113 parent::cbsDefaultValues($defaults);
114
f5276b10 115 if ($this->_config->display_name_format) {
6a488035
TO
116 $defaults['display_name_format'] = $this->_config->display_name_format;
117 }
f5276b10 118 if ($this->_config->sort_name_format) {
6a488035
TO
119 $defaults['sort_name_format'] = $this->_config->sort_name_format;
120 }
121
6a488035
TO
122 return $defaults;
123 }
124
125 /**
eceb18cc 126 * Build the form object.
6a488035
TO
127 */
128 public function buildQuickForm() {
72f03b4f 129 $wysiwyg_options = CRM_Core_OptionGroup::values('wysiwyg_editor', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name');
6a488035 130
e0d683cf 131 //changes for freezing the invoices/credit notes checkbox if invoicing is uncheck
9148c277 132 $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
e0d683cf
PB
133 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
134 $this->assign('invoicing', $invoicing);
6a488035
TO
135 $extra = array();
136
6a488035 137 $this->addElement('select', 'editor_id', ts('WYSIWYG Editor'), $wysiwyg_options, $extra);
7266e09b 138 $this->addElement('submit', 'ckeditor_config', ts('Configure CKEditor'));
6a488035 139
6a488035
TO
140 $editOptions = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 0');
141 $this->assign('editOptions', $editOptions);
142
143 $contactBlocks = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 1');
144 $this->assign('contactBlocks', $contactBlocks);
145
8b49cb50
OB
146 $nameFields = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 2');
147 $this->assign('nameFields', $nameFields);
148
6a488035
TO
149 $this->addElement('hidden', 'contact_edit_preferences', NULL, array('id' => 'contact_edit_preferences'));
150
9148c277 151 $optionValues = CRM_Core_OptionGroup::values('user_dashboard_options', FALSE, FALSE, FALSE, NULL, 'name');
e0d683cf
PB
152 $invoicesKey = array_search('Invoices / Credit Notes', $optionValues);
153 $this->assign('invoicesKey', $invoicesKey);
6a488035
TO
154 parent::buildQuickForm();
155 }
156
157 /**
eceb18cc 158 * Process the form submission.
6a488035
TO
159 */
160 public function postProcess() {
161 if ($this->_action == CRM_Core_Action::VIEW) {
162 return;
163 }
164
165 $this->_params = $this->controller->exportValues($this->_name);
166
a7488080 167 if (!empty($this->_params['contact_edit_preferences'])) {
6a488035
TO
168 $preferenceWeights = explode(',', $this->_params['contact_edit_preferences']);
169 foreach ($preferenceWeights as $key => $val) {
170 if (!$val) {
171 unset($preferenceWeights[$key]);
172 }
173 }
174 $opGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'contact_edit_options', 'id', 'name');
175 CRM_Core_BAO_OptionValue::updateOptionWeights($opGroupId, array_flip($preferenceWeights));
176 }
177
6a488035
TO
178 $this->_config->editor_id = $this->_params['editor_id'];
179
6a488035 180 $this->postProcessCommon();
7266e09b
CW
181
182 // If "Configure CKEditor" button was clicked
183 if (!empty($this->_params['ckeditor_config'])) {
184 // Suppress the "Saved" status message and redirect to the CKEditor Config page
185 $session = CRM_Core_Session::singleton();
186 $session->getStatus(TRUE);
187 $url = CRM_Utils_System::url('civicrm/admin/ckeditor', 'reset=1');
188 $session->pushUserContext($url);
189 }
6a488035 190 }
96025800 191
6a488035 192}