1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Webform module textarea component.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements _webform_defaults_component().
|
10
|
*/
|
11
|
function _webform_defaults_textarea() {
|
12
|
return array(
|
13
|
'name' => '',
|
14
|
'form_key' => NULL,
|
15
|
'pid' => 0,
|
16
|
'weight' => 0,
|
17
|
'value' => '',
|
18
|
'required' => 0,
|
19
|
'extra' => array(
|
20
|
'cols' => '',
|
21
|
'rows' => '',
|
22
|
'title_display' => 0,
|
23
|
'resizable' => 1,
|
24
|
'disabled' => 0,
|
25
|
'description' => '',
|
26
|
'description_above' => FALSE,
|
27
|
'placeholder' => '',
|
28
|
'attributes' => array(),
|
29
|
'private' => FALSE,
|
30
|
'analysis' => FALSE,
|
31
|
),
|
32
|
);
|
33
|
}
|
34
|
|
35
|
/**
|
36
|
* Implements _webform_theme_component().
|
37
|
*/
|
38
|
function _webform_theme_textarea() {
|
39
|
return array(
|
40
|
'webform_display_textarea' => array(
|
41
|
'render element' => 'element',
|
42
|
'file' => 'components/textarea.inc',
|
43
|
),
|
44
|
);
|
45
|
}
|
46
|
|
47
|
/**
|
48
|
* Implements _webform_edit_component().
|
49
|
*/
|
50
|
function _webform_edit_textarea($component) {
|
51
|
$form = array();
|
52
|
$form['value'] = array(
|
53
|
'#type' => 'textarea',
|
54
|
'#title' => t('Default value'),
|
55
|
'#default_value' => $component['value'],
|
56
|
'#description' => t('The default value of the field.') . ' ' . theme('webform_token_help'),
|
57
|
'#cols' => 60,
|
58
|
'#rows' => 5,
|
59
|
'#weight' => 0,
|
60
|
);
|
61
|
$form['display']['cols'] = array(
|
62
|
'#type' => 'textfield',
|
63
|
'#title' => t('Width'),
|
64
|
'#default_value' => $component['extra']['cols'],
|
65
|
'#description' => t('Width of the textarea in columns. This property might not have a visual impact depending on the CSS of your site.') . ' ' . t('Leaving blank will use the default size.'),
|
66
|
'#size' => 5,
|
67
|
'#maxlength' => 10,
|
68
|
'#parents' => array('extra', 'cols'),
|
69
|
);
|
70
|
$form['display']['rows'] = array(
|
71
|
'#type' => 'textfield',
|
72
|
'#title' => t('Height'),
|
73
|
'#default_value' => $component['extra']['rows'],
|
74
|
'#description' => t('Height of the textarea in rows.') . ' ' . t('Leaving blank will use the default size.'),
|
75
|
'#size' => 5,
|
76
|
'#maxlength' => 10,
|
77
|
'#parents' => array('extra', 'rows'),
|
78
|
);
|
79
|
$form['display']['resizable'] = array(
|
80
|
'#type' => 'checkbox',
|
81
|
'#title' => t('Resizable'),
|
82
|
'#description' => t('Make this field resizable by the user.'),
|
83
|
'#weight' => 2,
|
84
|
'#default_value' => $component['extra']['resizable'],
|
85
|
'#parents' => array('extra', 'resizable'),
|
86
|
);
|
87
|
$form['display']['placeholder'] = array(
|
88
|
'#type' => 'textfield',
|
89
|
'#title' => t('Placeholder'),
|
90
|
'#default_value' => $component['extra']['placeholder'],
|
91
|
'#description' => t('The placeholder will be shown in the field until the user starts entering a value.'),
|
92
|
'#parents' => array('extra', 'placeholder'),
|
93
|
);
|
94
|
$form['display']['disabled'] = array(
|
95
|
'#type' => 'checkbox',
|
96
|
'#title' => t('Disabled'),
|
97
|
'#return_value' => 1,
|
98
|
'#description' => t('Make this field non-editable. Useful for displaying default value. Changeable via JavaScript or developer tools.'),
|
99
|
'#weight' => 11,
|
100
|
'#default_value' => $component['extra']['disabled'],
|
101
|
'#parents' => array('extra', 'disabled'),
|
102
|
);
|
103
|
return $form;
|
104
|
}
|
105
|
|
106
|
/**
|
107
|
* Implements _webform_render_component().
|
108
|
*/
|
109
|
function _webform_render_textarea($component, $value = NULL, $filter = TRUE, $submission = NULL) {
|
110
|
$node = isset($component['nid']) ? node_load($component['nid']) : NULL;
|
111
|
|
112
|
$element = array(
|
113
|
'#type' => 'textarea',
|
114
|
'#title' => $filter ? webform_filter_xss($component['name']) : $component['name'],
|
115
|
'#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
|
116
|
'#default_value' => $filter ? webform_replace_tokens($component['value'], $node) : $component['value'],
|
117
|
'#required' => $component['required'],
|
118
|
'#weight' => $component['weight'],
|
119
|
'#description' => $filter ? webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'],
|
120
|
'#rows' => !empty($component['extra']['rows']) ? $component['extra']['rows'] : 5,
|
121
|
'#cols' => !empty($component['extra']['cols']) ? $component['extra']['cols'] : 60,
|
122
|
'#attributes' => $component['extra']['attributes'],
|
123
|
// MUST be FALSE to disable.
|
124
|
'#resizable' => (bool) $component['extra']['resizable'],
|
125
|
'#theme_wrappers' => array('webform_element'),
|
126
|
'#translatable' => array('title', 'description'),
|
127
|
);
|
128
|
|
129
|
if ($component['required']) {
|
130
|
$element['#attributes']['required'] = 'required';
|
131
|
}
|
132
|
|
133
|
if ($component['extra']['placeholder']) {
|
134
|
$element['#attributes']['placeholder'] = $component['extra']['placeholder'];
|
135
|
}
|
136
|
|
137
|
if ($component['extra']['disabled']) {
|
138
|
if ($filter) {
|
139
|
$element['#attributes']['readonly'] = 'readonly';
|
140
|
}
|
141
|
else {
|
142
|
$element['#disabled'] = TRUE;
|
143
|
}
|
144
|
}
|
145
|
|
146
|
if (isset($value[0])) {
|
147
|
$element['#default_value'] = $value[0];
|
148
|
}
|
149
|
|
150
|
return $element;
|
151
|
}
|
152
|
|
153
|
/**
|
154
|
* Implements _webform_display_component().
|
155
|
*/
|
156
|
function _webform_display_textarea($component, $value, $format = 'html', $submission = array()) {
|
157
|
return array(
|
158
|
'#title' => $component['name'],
|
159
|
'#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
|
160
|
'#weight' => $component['weight'],
|
161
|
'#theme' => 'webform_display_textarea',
|
162
|
'#theme_wrappers' => $format == 'html' ? array('webform_element') : array('webform_element_text'),
|
163
|
'#format' => $format,
|
164
|
'#value' => isset($value[0]) ? $value[0] : '',
|
165
|
'#translatable' => array('title'),
|
166
|
);
|
167
|
}
|
168
|
|
169
|
/**
|
170
|
* Format the output of data for this component.
|
171
|
*/
|
172
|
function theme_webform_display_textarea($variables) {
|
173
|
$element = $variables['element'];
|
174
|
$output = $element['#format'] == 'html' ? nl2br(check_plain($element['#value'])) : $element['#value'];
|
175
|
if (drupal_strlen($output) > 80) {
|
176
|
$output = ($element['#format'] == 'html') ? '<div class="webform-long-answer">' . $output . '</div>' : $output;
|
177
|
}
|
178
|
return $output !== '' ? $output : ' ';
|
179
|
}
|
180
|
|
181
|
/**
|
182
|
* Implements _webform_analysis_component().
|
183
|
*/
|
184
|
function _webform_analysis_textarea($component, $sids = array(), $single = FALSE, $join = NULL) {
|
185
|
$query = db_select('webform_submitted_data', 'wsd', array('fetch' => PDO::FETCH_ASSOC))
|
186
|
->fields('wsd', array('no', 'data'))
|
187
|
->condition('wsd.nid', $component['nid'])
|
188
|
->condition('wsd.cid', $component['cid']);
|
189
|
|
190
|
if (count($sids)) {
|
191
|
$query->condition('wsd.sid', $sids, 'IN');
|
192
|
}
|
193
|
|
194
|
if ($join) {
|
195
|
$query->innerJoin($join, 'ws2_', 'wsd.sid = ws2_.sid');
|
196
|
}
|
197
|
|
198
|
$nonblanks = 0;
|
199
|
$submissions = 0;
|
200
|
$wordcount = 0;
|
201
|
|
202
|
$result = $query->execute();
|
203
|
foreach ($result as $data) {
|
204
|
if (drupal_strlen(trim($data['data'])) > 0) {
|
205
|
$nonblanks++;
|
206
|
$wordcount += str_word_count(trim($data['data']));
|
207
|
}
|
208
|
$submissions++;
|
209
|
}
|
210
|
|
211
|
$rows[0] = array(t('Left Blank'), ($submissions - $nonblanks));
|
212
|
$rows[1] = array(t('User entered value'), $nonblanks);
|
213
|
|
214
|
$other[] = array(
|
215
|
t('Average submission length in words (ex blanks)'),
|
216
|
$nonblanks != 0 ? number_format($wordcount / $nonblanks, 2) : '0',
|
217
|
);
|
218
|
|
219
|
return array(
|
220
|
'table_rows' => $rows,
|
221
|
'other_data' => $other,
|
222
|
);
|
223
|
}
|
224
|
|
225
|
/**
|
226
|
* Implements _webform_table_component().
|
227
|
*/
|
228
|
function _webform_table_textarea($component, $value) {
|
229
|
return empty($value[0]) ? '' : check_plain($value[0]);
|
230
|
}
|
231
|
|
232
|
/**
|
233
|
* Implements _webform_action_set_component().
|
234
|
*/
|
235
|
function _webform_action_set_textarea($component, &$element, &$form_state, $value) {
|
236
|
$element['#value'] = $value;
|
237
|
form_set_value($element, $value, $form_state);
|
238
|
}
|
239
|
|
240
|
/**
|
241
|
* Implements _webform_csv_headers_component().
|
242
|
*/
|
243
|
function _webform_csv_headers_textarea($component, $export_options) {
|
244
|
$header = array();
|
245
|
$header[0] = '';
|
246
|
$header[1] = '';
|
247
|
$header[2] = $export_options['header_keys'] ? $component['form_key'] : $component['name'];
|
248
|
return $header;
|
249
|
}
|
250
|
|
251
|
/**
|
252
|
* Implements _webform_csv_data_component().
|
253
|
*/
|
254
|
function _webform_csv_data_textarea($component, $export_options, $value) {
|
255
|
return empty($value[0]) ? '' : $value[0];
|
256
|
}
|