Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2013-11-27-05-47-07
[civicrm-core.git] / CRM / Admin / Form / Preferences / Display.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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 if (defined('CIVICRM_ACTIVITY_ASSIGNEE_MAIL') && CIVICRM_ACTIVITY_ASSIGNEE_MAIL) {
45 CRM_Core_Session::setStatus(ts('Your civicrm.settings.php file contains CIVICRM_ACTIVITY_ASSIGNEE_MAIL but this
46 constant is no longer used. Please remove this from your config file and set your "Notify Activity Assignees"
47 preference below.'), ts("Deprecated Constant"), "alert");
48 }
49
50 $this->_varNames = array(
51 CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME =>
52 array(
53 'contact_view_options' => array(
54 'html_type' => 'checkboxes',
55 'title' => ts('Viewing Contacts'),
56 'weight' => 1,
57 ),
58 'contact_smart_group_display' => array(
59 'html_type' => 'radio',
60 'title' => ts('Viewing Smart Groups'),
61 'weight' => 2,
62 ),
63 'contact_edit_options' => array(
64 'html_type' => 'checkboxes',
65 'title' => ts('Editing Contacts'),
66 'weight' => 3,
67 ),
68 'advanced_search_options' => array(
69 'html_type' => 'checkboxes',
70 'title' => ts('Contact Search'),
71 'weight' => 4,
72 ),
73 'activity_assignee_notification' => array(
74 'html_type' => 'checkbox',
75 'title' => ts('Notify Activity Assignees'),
76 'weight' => 5,
77 ),
78 'activity_assignee_notification_ics' => array(
79 'html_type' => 'checkbox',
80 'title' => ts('Include ICal Invite to Activity Assignees'),
81 'weight' => 6,
82 ),
83 'contact_ajax_check_similar' => array(
84 'html_type' => 'checkbox',
85 'title' => ts('Check for Similar Contacts'),
86 'weight' => 7,
87 ),
88 'user_dashboard_options' => array(
89 'html_type' => 'checkboxes',
90 'title' => ts('Contact Dashboard'),
91 'weight' => 8,
92 ),
93 'display_name_format' => array(
94 'html_type' => 'textarea',
95 'title' => ts('Individual Display Name Format'),
96 'weight' => 9,
97 ),
98 'sort_name_format' => array(
99 'html_type' => 'textarea',
100 'title' => ts('Individual Sort Name Format'),
101 'weight' => 10,
102 ),
103 'editor_id' => array(
104 'html_type' => NULL,
105 'weight' => 11,
106 ),
107 ),
108 );
109
110 parent::preProcess();
111 }
112
113 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 (empty($this->_config->display_name_format)) {
121 $defaults['display_name_format'] =
122 "{contact.individual_prefix}{ }{contact.first_name}{ }{contact.last_name}{ }{contact.individual_suffix}";
123 }
124 else {
125 $defaults['display_name_format'] = $this->_config->display_name_format;
126 }
127
128 if (empty($this->_config->sort_name_format)) {
129 $defaults['sort_name_format'] = "{contact.last_name}{, }{contact.first_name}";
130 }
131 else {
132 $defaults['sort_name_format'] = $this->_config->sort_name_format;
133 }
134
135 $config = CRM_Core_Config::singleton();
136 if ($config->userSystem->is_drupal == '1' && module_exists("wysiwyg")) {
137 $defaults['wysiwyg_input_format'] = variable_get('civicrm_wysiwyg_input_format', 0);
138 }
139
140 return $defaults;
141 }
142
143 /**
144 * Function to build the form
145 *
146 * @return None
147 * @access public
148 */
149 public function buildQuickForm() {
150 $wysiwyg_options = array('' => ts('Textarea')) + CRM_Core_OptionGroup::values('wysiwyg_editor');
151
152 $config = CRM_Core_Config::singleton();
153 $extra = array();
154
155 //if not using Joomla, remove Joomla default editor option
156 if ($config->userFramework != 'Joomla') {
157 unset($wysiwyg_options[3]);
158 }
159
160 $drupal_wysiwyg = FALSE;
161 if (!$config->userSystem->is_drupal || !module_exists("wysiwyg")) {
162 unset($wysiwyg_options[4]);
163 }
164 else {
165 $extra['onchange'] = '
166 if (this.value==4) {
167 cj("#crm-preferences-display-form-block-wysiwyg_input_format").show();
168 }
169 else {
170 cj("#crm-preferences-display-form-block-wysiwyg_input_format").hide()
171 }';
172
173 $formats = filter_formats();
174 $format_options = array();
175 foreach ($formats as $id => $format) {
176 $format_options[$id] = $format->name;
177 }
178 $drupal_wysiwyg = TRUE;
179 }
180 $this->addElement('select', 'editor_id', ts('WYSIWYG Editor'), $wysiwyg_options, $extra);
181
182 if ($drupal_wysiwyg) {
183 $this->addElement('select', 'wysiwyg_input_format', ts('Input Format'), $format_options, NULL);
184 }
185
186 $editOptions = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 0');
187 $this->assign('editOptions', $editOptions);
188
189 $contactBlocks = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 1');
190 $this->assign('contactBlocks', $contactBlocks);
191
192 $nameFields = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 2');
193 $this->assign('nameFields', $nameFields);
194
195 $this->addElement('hidden', 'contact_edit_preferences', NULL, array('id' => 'contact_edit_preferences'));
196
197 parent::buildQuickForm();
198 }
199
200 /**
201 * Function to process the form
202 *
203 * @access public
204 *
205 * @return None
206 */
207 public function postProcess() {
208 if ($this->_action == CRM_Core_Action::VIEW) {
209 return;
210 }
211
212 $this->_params = $this->controller->exportValues($this->_name);
213
214 if (CRM_Utils_Array::value('contact_edit_preferences', $this->_params)) {
215 $preferenceWeights = explode(',', $this->_params['contact_edit_preferences']);
216 foreach ($preferenceWeights as $key => $val) {
217 if (!$val) {
218 unset($preferenceWeights[$key]);
219 }
220 }
221 $opGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'contact_edit_options', 'id', 'name');
222 CRM_Core_BAO_OptionValue::updateOptionWeights($opGroupId, array_flip($preferenceWeights));
223 }
224
225 $config = CRM_Core_Config::singleton();
226 if ($config->userSystem->is_drupal == '1' && module_exists("wysiwyg")) {
227 variable_set('civicrm_wysiwyg_input_format', $this->_params['wysiwyg_input_format']);
228 }
229
230 $this->_config->editor_id = $this->_params['editor_id'];
231
232 // set default editor to session if changed
233 $session = CRM_Core_Session::singleton();
234 $session->set('defaultWysiwygEditor', $this->_params['editor_id']);
235
236 $this->postProcessCommon();
237 }
238 //end of function
239 }
240