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