Merge pull request #4771 from pratikshad/CRM-15409
[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-2014 |
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-2014
32 * $Id: Display.php 45499 2013-02-08 12:31:05Z kurund $
33 *
34 */
35
36 /**r
37 * This class generates form components for the display preferences
38 *
39 */
40 class CRM_Admin_Form_Preferences_Display extends CRM_Admin_Form_Preferences {
41 function preProcess() {
42 CRM_Utils_System::setTitle(ts('Settings - Display Preferences'));
43
44 $this->_varNames = array(
45 CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME => array(
46 'contact_view_options' => array(
47 'html_type' => 'checkboxes',
48 'title' => ts('Viewing Contacts'),
49 'weight' => 1,
50 ),
51 'contact_smart_group_display' => array(
52 'html_type' => 'radio',
53 'title' => ts('Viewing Smart Groups'),
54 'weight' => 2,
55 ),
56 'contact_edit_options' => array(
57 'html_type' => 'checkboxes',
58 'title' => ts('Editing Contacts'),
59 'weight' => 3,
60 ),
61 'advanced_search_options' => array(
62 'html_type' => 'checkboxes',
63 'title' => ts('Contact Search'),
64 'weight' => 4,
65 ),
66 'activity_assignee_notification' => array(
67 'html_type' => 'checkbox',
68 'title' => ts('Notify Activity Assignees'),
69 'weight' => 5,
70 ),
71 'activity_assignee_notification_ics' => array(
72 'html_type' => 'checkbox',
73 'title' => ts('Include ICal Invite to Activity Assignees'),
74 'weight' => 6,
75 ),
76 'contact_ajax_check_similar' => array(
77 'html_type' => 'checkbox',
78 'title' => ts('Check for Similar Contacts'),
79 'weight' => 7,
80 ),
81 'user_dashboard_options' => array(
82 'html_type' => 'checkboxes',
83 'title' => ts('Contact Dashboard'),
84 'weight' => 8,
85 ),
86 'display_name_format' => array(
87 'html_type' => 'textarea',
88 'title' => ts('Individual Display Name Format'),
89 'weight' => 9,
90 ),
91 'sort_name_format' => array(
92 'html_type' => 'textarea',
93 'title' => ts('Individual Sort Name Format'),
94 'weight' => 10,
95 ),
96 'editor_id' => array(
97 'html_type' => NULL,
98 'weight' => 11,
99 ),
100 'ajaxPopupsEnabled' => array(
101 'html_type' => 'checkbox',
102 'title' => ts('Enable Popup Forms'),
103 'weight' => 12,
104 ),
105 ),
106 );
107
108 parent::preProcess();
109 }
110
111 /**
112 * @return array
113 */
114 function setDefaultValues() {
115 $defaults = parent::setDefaultValues();
116 parent::cbsDefaultValues($defaults);
117
118 if ($this->_config->editor_id) {
119 $defaults['editor_id'] = $this->_config->editor_id;
120 }
121 if (empty($this->_config->display_name_format)) {
122 $defaults['display_name_format'] =
123 "{contact.individual_prefix}{ }{contact.first_name}{ }{contact.last_name}{ }{contact.individual_suffix}";
124 }
125 else {
126 $defaults['display_name_format'] = $this->_config->display_name_format;
127 }
128
129 if (empty($this->_config->sort_name_format)) {
130 $defaults['sort_name_format'] = "{contact.last_name}{, }{contact.first_name}";
131 }
132 else {
133 $defaults['sort_name_format'] = $this->_config->sort_name_format;
134 }
135
136 $config = CRM_Core_Config::singleton();
137 if ($config->userSystem->is_drupal == '1' && module_exists("wysiwyg")) {
138 $defaults['wysiwyg_input_format'] = variable_get('civicrm_wysiwyg_input_format', 0);
139 }
140
141 return $defaults;
142 }
143
144 /**
145 * Build the form object
146 *
147 * @return void
148 * @access public
149 */
150 public function buildQuickForm() {
151 $wysiwyg_options = array('' => ts('Textarea')) + CRM_Core_OptionGroup::values('wysiwyg_editor');
152
153 //changes for freezing the invoices/credit notes checkbox if invoicing is uncheck
154 $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
155 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
156 $this->assign('invoicing', $invoicing);
157 $config = CRM_Core_Config::singleton();
158 $extra = array();
159
160 //if not using Joomla, remove Joomla default editor option
161 if ($config->userFramework != 'Joomla') {
162 unset($wysiwyg_options[3]);
163 }
164
165 $drupal_wysiwyg = FALSE;
166 if (!$config->userSystem->is_drupal || !module_exists("wysiwyg")) {
167 unset($wysiwyg_options[4]);
168 }
169 else {
170 $extra['onchange'] = '
171 if (this.value==4) {
172 cj("#crm-preferences-display-form-block-wysiwyg_input_format").show();
173 }
174 else {
175 cj("#crm-preferences-display-form-block-wysiwyg_input_format").hide()
176 }';
177
178 $formats = filter_formats();
179 $format_options = array();
180 foreach ($formats as $id => $format) {
181 $format_options[$id] = $format->name;
182 }
183 $drupal_wysiwyg = TRUE;
184 }
185 $this->addElement('select', 'editor_id', ts('WYSIWYG Editor'), $wysiwyg_options, $extra);
186
187 if ($drupal_wysiwyg) {
188 $this->addElement('select', 'wysiwyg_input_format', ts('Input Format'), $format_options, NULL);
189 }
190
191 $editOptions = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 0');
192 $this->assign('editOptions', $editOptions);
193
194 $contactBlocks = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 1');
195 $this->assign('contactBlocks', $contactBlocks);
196
197 $nameFields = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 2');
198 $this->assign('nameFields', $nameFields);
199
200 $this->addElement('hidden', 'contact_edit_preferences', NULL, array('id' => 'contact_edit_preferences'));
201
202 $optionValues = CRM_Core_OptionGroup::values('user_dashboard_options', FALSE, FALSE, FALSE, NULL, 'name');
203 $invoicesKey = array_search('Invoices / Credit Notes', $optionValues);
204 $this->assign('invoicesKey', $invoicesKey);
205 parent::buildQuickForm();
206 }
207
208 /**
209 * Process the form submission
210 *
211 * @access public
212 *
213 * @return void
214 */
215 public function postProcess() {
216 if ($this->_action == CRM_Core_Action::VIEW) {
217 return;
218 }
219
220 $this->_params = $this->controller->exportValues($this->_name);
221
222 if (!empty($this->_params['contact_edit_preferences'])) {
223 $preferenceWeights = explode(',', $this->_params['contact_edit_preferences']);
224 foreach ($preferenceWeights as $key => $val) {
225 if (!$val) {
226 unset($preferenceWeights[$key]);
227 }
228 }
229 $opGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'contact_edit_options', 'id', 'name');
230 CRM_Core_BAO_OptionValue::updateOptionWeights($opGroupId, array_flip($preferenceWeights));
231 }
232
233 $config = CRM_Core_Config::singleton();
234 if ($config->userSystem->is_drupal == '1' && module_exists("wysiwyg")) {
235 variable_set('civicrm_wysiwyg_input_format', $this->_params['wysiwyg_input_format']);
236 }
237
238 $this->_config->editor_id = $this->_params['editor_id'];
239
240 // set default editor to session if changed
241 $session = CRM_Core_Session::singleton();
242 $session->set('defaultWysiwygEditor', $this->_params['editor_id']);
243
244 $this->postProcessCommon();
245 }
246 }
247