1 |
85ad3d82
|
Assos Assos
|
<?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 |
|
|
'mandatory' => 0,
|
19 |
|
|
'extra' => array(
|
20 |
|
|
'cols' => '',
|
21 |
|
|
'rows' => '',
|
22 |
|
|
'title_display' => 0,
|
23 |
|
|
'resizable' => 1,
|
24 |
|
|
'disabled' => 0,
|
25 |
|
|
'description' => '',
|
26 |
|
|
'attributes' => array(),
|
27 |
|
|
'private' => FALSE,
|
28 |
|
|
),
|
29 |
|
|
);
|
30 |
|
|
}
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/**
|
34 |
|
|
* Implements _webform_theme_component().
|
35 |
|
|
*/
|
36 |
|
|
function _webform_theme_textarea() {
|
37 |
|
|
return array(
|
38 |
|
|
'webform_display_textarea' => array(
|
39 |
|
|
'render element' => 'element',
|
40 |
|
|
'file' => 'components/textarea.inc',
|
41 |
|
|
),
|
42 |
|
|
);
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
/**
|
46 |
|
|
* Implements _webform_edit_component().
|
47 |
|
|
*/
|
48 |
|
|
function _webform_edit_textarea($component) {
|
49 |
|
|
$form = array();
|
50 |
|
|
$form['value'] = array(
|
51 |
|
|
'#type' => 'textarea',
|
52 |
|
|
'#title' => t('Default value'),
|
53 |
|
|
'#default_value' => $component['value'],
|
54 |
|
|
'#description' => t('The default value of the field.') . theme('webform_token_help'),
|
55 |
|
|
'#cols' => 60,
|
56 |
|
|
'#rows' => 5,
|
57 |
|
|
'#weight' => 0,
|
58 |
|
|
);
|
59 |
|
|
$form['display']['cols'] = array(
|
60 |
|
|
'#type' => 'textfield',
|
61 |
|
|
'#title' => t('Width'),
|
62 |
|
|
'#default_value' => $component['extra']['cols'],
|
63 |
|
|
'#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.'),
|
64 |
|
|
'#size' => 5,
|
65 |
|
|
'#maxlength' => 10,
|
66 |
|
|
'#parents' => array('extra', 'cols'),
|
67 |
|
|
);
|
68 |
|
|
$form['display']['rows'] = array(
|
69 |
|
|
'#type' => 'textfield',
|
70 |
|
|
'#title' => t('Height'),
|
71 |
|
|
'#default_value' => $component['extra']['rows'],
|
72 |
|
|
'#description' => t('Height of the textarea in rows.') . ' ' . t('Leaving blank will use the default size.'),
|
73 |
|
|
'#size' => 5,
|
74 |
|
|
'#maxlength' => 10,
|
75 |
|
|
'#parents' => array('extra', 'rows'),
|
76 |
|
|
);
|
77 |
|
|
$form['display']['resizable'] = array(
|
78 |
|
|
'#type' => 'checkbox',
|
79 |
|
|
'#title' => t('Resizable'),
|
80 |
|
|
'#description' => t('Make this field resizable by the user.'),
|
81 |
|
|
'#weight' => 2,
|
82 |
|
|
'#default_value' => $component['extra']['resizable'],
|
83 |
|
|
'#parents' => array('extra', 'resizable'),
|
84 |
|
|
);
|
85 |
|
|
$form['display']['disabled'] = array(
|
86 |
|
|
'#type' => 'checkbox',
|
87 |
|
|
'#title' => t('Disabled'),
|
88 |
|
|
'#return_value' => 1,
|
89 |
|
|
'#description' => t('Make this field non-editable. Useful for setting an unchangeable default value.'),
|
90 |
|
|
'#weight' => 11,
|
91 |
|
|
'#default_value' => $component['extra']['disabled'],
|
92 |
|
|
'#parents' => array('extra', 'disabled'),
|
93 |
|
|
);
|
94 |
|
|
return $form;
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
/**
|
98 |
|
|
* Implements _webform_render_component().
|
99 |
|
|
*/
|
100 |
|
|
function _webform_render_textarea($component, $value = NULL, $filter = TRUE) {
|
101 |
|
|
$node = isset($component['nid']) ? node_load($component['nid']) : NULL;
|
102 |
|
|
|
103 |
|
|
$element = array(
|
104 |
|
|
'#type' => 'textarea',
|
105 |
|
|
'#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
|
106 |
|
|
'#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
|
107 |
|
|
'#default_value' => $filter ? _webform_filter_values($component['value'], $node) : $component['value'],
|
108 |
|
|
'#required' => $component['mandatory'],
|
109 |
|
|
'#weight' => $component['weight'],
|
110 |
|
|
'#description' => $filter ? _webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'],
|
111 |
|
|
'#rows' => !empty($component['extra']['rows']) ? $component['extra']['rows'] : 5,
|
112 |
|
|
'#cols' => !empty($component['extra']['cols']) ? $component['extra']['cols'] : 60,
|
113 |
|
|
'#attributes' => $component['extra']['attributes'],
|
114 |
|
|
'#resizable' => (bool) $component['extra']['resizable'], // MUST be FALSE to disable.
|
115 |
|
|
'#theme_wrappers' => array('webform_element'),
|
116 |
|
|
'#translatable' => array('title', 'description'),
|
117 |
|
|
);
|
118 |
|
|
|
119 |
|
|
if ($component['extra']['disabled']) {
|
120 |
|
|
if ($filter) {
|
121 |
|
|
$element['#attributes']['readonly'] = 'readonly';
|
122 |
|
|
}
|
123 |
|
|
else {
|
124 |
|
|
$element['#disabled'] = TRUE;
|
125 |
|
|
}
|
126 |
|
|
}
|
127 |
|
|
|
128 |
|
|
if (isset($value)) {
|
129 |
|
|
$element['#default_value'] = $value[0];
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
return $element;
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
/**
|
136 |
|
|
* Implements _webform_display_component().
|
137 |
|
|
*/
|
138 |
|
|
function _webform_display_textarea($component, $value, $format = 'html') {
|
139 |
|
|
return array(
|
140 |
|
|
'#title' => $component['name'],
|
141 |
|
|
'#weight' => $component['weight'],
|
142 |
|
|
'#theme' => 'webform_display_textarea',
|
143 |
|
|
'#theme_wrappers' => $format == 'html' ? array('webform_element') : array('webform_element_text'),
|
144 |
|
|
'#format' => $format,
|
145 |
|
|
'#value' => isset($value[0]) ? $value[0] : '',
|
146 |
|
|
'#translatable' => array('title'),
|
147 |
|
|
);
|
148 |
|
|
}
|
149 |
|
|
|
150 |
|
|
/**
|
151 |
|
|
* Format the output of data for this component.
|
152 |
|
|
*/
|
153 |
|
|
function theme_webform_display_textarea($variables) {
|
154 |
|
|
$element = $variables['element'];
|
155 |
|
|
$output = $element['#format'] == 'html' ? nl2br(check_plain($element['#value'])) : $element['#value'];
|
156 |
|
|
if (drupal_strlen($output) > 80) {
|
157 |
|
|
$output = ($element['#format'] == 'html') ? '<div class="webform-long-answer">' . $output . '</div>' : $output;
|
158 |
|
|
}
|
159 |
|
|
return $output !== '' ? $output : ' ';
|
160 |
|
|
}
|
161 |
|
|
|
162 |
|
|
/**
|
163 |
|
|
* Implements _webform_analysis_component().
|
164 |
|
|
*/
|
165 |
|
|
function _webform_analysis_textarea($component, $sids = array()) {
|
166 |
|
|
$query = db_select('webform_submitted_data', 'wsd', array('fetch' => PDO::FETCH_ASSOC))
|
167 |
|
|
->fields('wsd', array('no', 'data'))
|
168 |
|
|
->condition('nid', $component['nid'])
|
169 |
|
|
->condition('cid', $component['cid']);
|
170 |
|
|
|
171 |
|
|
if (count($sids)) {
|
172 |
|
|
$query->condition('sid', $sids, 'IN');
|
173 |
|
|
}
|
174 |
|
|
|
175 |
|
|
$nonblanks = 0;
|
176 |
|
|
$submissions = 0;
|
177 |
|
|
$wordcount = 0;
|
178 |
|
|
|
179 |
|
|
$result = $query->execute();
|
180 |
|
|
foreach ($result as $data) {
|
181 |
|
|
if (drupal_strlen(trim($data['data'])) > 0) {
|
182 |
|
|
$nonblanks++;
|
183 |
|
|
$wordcount += str_word_count(trim($data['data']));
|
184 |
|
|
}
|
185 |
|
|
$submissions++;
|
186 |
|
|
}
|
187 |
|
|
|
188 |
|
|
$rows[0] = array(t('Left Blank'), ($submissions - $nonblanks));
|
189 |
|
|
$rows[1] = array(t('User entered value'), $nonblanks);
|
190 |
|
|
$rows[2] = array(t('Average submission length in words (ex blanks)'), ($nonblanks != 0 ? number_format($wordcount/$nonblanks, 2) : '0'));
|
191 |
|
|
return $rows;
|
192 |
|
|
}
|
193 |
|
|
|
194 |
|
|
/**
|
195 |
|
|
* Implements _webform_table_component().
|
196 |
|
|
*/
|
197 |
|
|
function _webform_table_textarea($component, $value) {
|
198 |
|
|
return empty($value[0]) ? '' : check_plain($value[0]);
|
199 |
|
|
}
|
200 |
|
|
|
201 |
|
|
/**
|
202 |
|
|
* Implements _webform_csv_headers_component().
|
203 |
|
|
*/
|
204 |
|
|
function _webform_csv_headers_textarea($component, $export_options) {
|
205 |
|
|
$header = array();
|
206 |
|
|
$header[0] = '';
|
207 |
|
|
$header[1] = '';
|
208 |
|
|
$header[2] = $component['name'];
|
209 |
|
|
return $header;
|
210 |
|
|
}
|
211 |
|
|
|
212 |
|
|
/**
|
213 |
|
|
* Implements _webform_csv_data_component().
|
214 |
|
|
*/
|
215 |
|
|
function _webform_csv_data_textarea($component, $export_options, $value) {
|
216 |
|
|
return empty($value[0]) ? '' : $value[0];
|
217 |
|
|
} |