Merge pull request #4764 from rohankatkar/CRM-15615
[civicrm-core.git] / CRM / Admin / Form / Preferences / Display.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06b69b18 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06b69b18 6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
06b69b18 31 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
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 */
40class CRM_Admin_Form_Preferences_Display extends CRM_Admin_Form_Preferences {
41 function preProcess() {
42 CRM_Utils_System::setTitle(ts('Settings - Display Preferences'));
43
6a488035 44 $this->_varNames = array(
9d72cede 45 CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME => array(
6a488035
TO
46 'contact_view_options' => array(
47 'html_type' => 'checkboxes',
48 'title' => ts('Viewing Contacts'),
49 'weight' => 1,
50 ),
65f9bd70
KJ
51 'contact_smart_group_display' => array(
52 'html_type' => 'radio',
53 'title' => ts('Viewing Smart Groups'),
54 'weight' => 2,
55 ),
6a488035
TO
56 'contact_edit_options' => array(
57 'html_type' => 'checkboxes',
58 'title' => ts('Editing Contacts'),
65f9bd70 59 'weight' => 3,
6a488035
TO
60 ),
61 'advanced_search_options' => array(
62 'html_type' => 'checkboxes',
63 'title' => ts('Contact Search'),
65f9bd70 64 'weight' => 4,
6a488035
TO
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'),
65f9bd70 74 'weight' => 6,
6a488035
TO
75 ),
76 'contact_ajax_check_similar' => array(
77 'html_type' => 'checkbox',
78 'title' => ts('Check for Similar Contacts'),
65f9bd70 79 'weight' => 7,
6a488035
TO
80 ),
81 'user_dashboard_options' => array(
82 'html_type' => 'checkboxes',
83 'title' => ts('Contact Dashboard'),
65f9bd70 84 'weight' => 8,
6a488035
TO
85 ),
86 'display_name_format' => array(
87 'html_type' => 'textarea',
88 'title' => ts('Individual Display Name Format'),
65f9bd70 89 'weight' => 9,
6a488035
TO
90 ),
91 'sort_name_format' => array(
92 'html_type' => 'textarea',
93 'title' => ts('Individual Sort Name Format'),
65f9bd70 94 'weight' => 10,
6a488035
TO
95 ),
96 'editor_id' => array(
97 'html_type' => NULL,
65f9bd70 98 'weight' => 11,
6a488035 99 ),
53f2643c 100 'ajaxPopupsEnabled' => array(
f1cf499b
CW
101 'html_type' => 'checkbox',
102 'title' => ts('Enable Popup Forms'),
103 'weight' => 12,
104 ),
6a488035
TO
105 ),
106 );
107
6a488035
TO
108 parent::preProcess();
109 }
110
e0ef6999
EM
111 /**
112 * @return array
113 */
6a488035
TO
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)) {
68679c0d
KJ
122 $defaults['display_name_format'] =
123 "{contact.individual_prefix}{ }{contact.first_name}{ }{contact.last_name}{ }{contact.individual_suffix}";
6a488035
TO
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();
68679c0d 137 if ($config->userSystem->is_drupal == '1' && module_exists("wysiwyg")) {
6a488035
TO
138 $defaults['wysiwyg_input_format'] = variable_get('civicrm_wysiwyg_input_format', 0);
139 }
140
141 return $defaults;
142 }
143
144 /**
c490a46a 145 * Build the form object
6a488035 146 *
355ba699 147 * @return void
6a488035
TO
148 * @access public
149 */
150 public function buildQuickForm() {
cbf48754 151 $wysiwyg_options = array('' => ts('Textarea')) + CRM_Core_OptionGroup::values('wysiwyg_editor');
6a488035 152
e0d683cf 153 //changes for freezing the invoices/credit notes checkbox if invoicing is uncheck
9148c277 154 $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
e0d683cf
PB
155 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
156 $this->assign('invoicing', $invoicing);
6a488035
TO
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;
68679c0d 166 if (!$config->userSystem->is_drupal || !module_exists("wysiwyg")) {
6a488035
TO
167 unset($wysiwyg_options[4]);
168 }
169 else {
68679c0d
KJ
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 }';
6a488035
TO
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 }
68679c0d 190
6a488035
TO
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
8b49cb50
OB
197 $nameFields = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 2');
198 $this->assign('nameFields', $nameFields);
199
6a488035
TO
200 $this->addElement('hidden', 'contact_edit_preferences', NULL, array('id' => 'contact_edit_preferences'));
201
9148c277 202 $optionValues = CRM_Core_OptionGroup::values('user_dashboard_options', FALSE, FALSE, FALSE, NULL, 'name');
e0d683cf
PB
203 $invoicesKey = array_search('Invoices / Credit Notes', $optionValues);
204 $this->assign('invoicesKey', $invoicesKey);
6a488035
TO
205 parent::buildQuickForm();
206 }
207
208 /**
c490a46a 209 * Process the form submission
6a488035
TO
210 *
211 * @access public
212 *
355ba699 213 * @return void
6a488035
TO
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
a7488080 222 if (!empty($this->_params['contact_edit_preferences'])) {
6a488035
TO
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();
68679c0d 234 if ($config->userSystem->is_drupal == '1' && module_exists("wysiwyg")) {
6a488035
TO
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 }
6a488035
TO
246}
247