1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Menu callbacks and functions for configuring and editing webforms.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Main configuration form for editing a webform node.
|
10 |
|
|
*/
|
11 |
|
|
function webform_configure_form($form, &$form_state, $node) {
|
12 |
a45e4bc1
|
Assos Assos
|
form_load_include($form_state, 'inc', 'webform', 'includes/webform.components');
|
13 |
|
|
|
14 |
85ad3d82
|
Assos Assos
|
$form['#attached']['library'][] = array('webform', 'admin');
|
15 |
|
|
|
16 |
feca1e4a
|
Assos Assos
|
// Refresh the entity cache to get the latest submission number.
|
17 |
a45e4bc1
|
Assos Assos
|
$nid = $node->nid;
|
18 |
|
|
entity_get_controller('node')->resetCache(array($nid));
|
19 |
|
|
$node = node_load($nid);
|
20 |
|
|
|
21 |
85ad3d82
|
Assos Assos
|
$form['#node'] = $node;
|
22 |
|
|
|
23 |
|
|
$form['#submit'] = array(
|
24 |
|
|
'webform_configure_form_submit',
|
25 |
|
|
'webform_configure_form_submit_save',
|
26 |
|
|
);
|
27 |
|
|
|
28 |
|
|
$form['nid'] = array(
|
29 |
|
|
'#type' => 'value',
|
30 |
|
|
'#value' => $node->nid,
|
31 |
|
|
);
|
32 |
|
|
|
33 |
|
|
/* Start Edit Form */
|
34 |
|
|
$form['submission'] = array(
|
35 |
|
|
'#type' => 'fieldset',
|
36 |
|
|
'#title' => t('Submission settings'),
|
37 |
|
|
'#collapsible' => TRUE,
|
38 |
|
|
'#collapsed' => FALSE,
|
39 |
|
|
'#weight' => -4,
|
40 |
|
|
);
|
41 |
|
|
|
42 |
|
|
$form['submission']['confirmation'] = array(
|
43 |
|
|
'#type' => 'text_format',
|
44 |
|
|
'#title' => t('Confirmation message'),
|
45 |
a45e4bc1
|
Assos Assos
|
'#description' => t('Message to be shown upon successful submission. If the redirection location is set to <em>Confirmation page</em> it will be shown on its own page, otherwise this displays as a message. Supports Webform token replacements.') . ' ' . theme('webform_token_help', array('groups' => array('node', 'submission'))),
|
46 |
85ad3d82
|
Assos Assos
|
'#default_value' => $node->webform['confirmation'],
|
47 |
|
|
'#cols' => 40,
|
48 |
|
|
'#rows' => 10,
|
49 |
|
|
'#format' => $node->webform['confirmation_format'],
|
50 |
|
|
'#parents' => array('confirmation'),
|
51 |
|
|
);
|
52 |
|
|
|
53 |
|
|
// Redirection settings.
|
54 |
|
|
if (strpos($node->webform['redirect_url'], '<') === 0) {
|
55 |
|
|
$redirect = trim($node->webform['redirect_url'], '<>');
|
56 |
|
|
// Redirection is set to front page.
|
57 |
|
|
if ($redirect == 'front') {
|
58 |
|
|
$redirect = 'url';
|
59 |
|
|
$redirect_url = $node->webform['redirect_url'];
|
60 |
|
|
}
|
61 |
|
|
else {
|
62 |
|
|
$redirect_url = '';
|
63 |
|
|
}
|
64 |
|
|
}
|
65 |
|
|
else {
|
66 |
|
|
$redirect = 'url';
|
67 |
|
|
$redirect_url = $node->webform['redirect_url'];
|
68 |
|
|
}
|
69 |
|
|
$form['submission']['redirection'] = array(
|
70 |
|
|
'#type' => 'item',
|
71 |
|
|
'#title' => t('Redirection location'),
|
72 |
|
|
'#theme' => 'webform_advanced_redirection_form',
|
73 |
a45e4bc1
|
Assos Assos
|
'#description' => t('Choose where to redirect the user upon successful submission.') . ' ' . t('The <em>Custom URL</em> option supports Webform token replacements.') . ' ' . theme('webform_token_help', array('groups' => array('node', 'submission'))),
|
74 |
85ad3d82
|
Assos Assos
|
);
|
75 |
feca1e4a
|
Assos Assos
|
$form['submission']['redirection']['redirect'] = array(
|
76 |
85ad3d82
|
Assos Assos
|
'#type' => 'radios',
|
77 |
|
|
'#default_value' => $redirect,
|
78 |
|
|
'#options' => array(
|
79 |
|
|
'confirmation' => t('Confirmation page'),
|
80 |
|
|
'url' => t('Custom URL'),
|
81 |
|
|
'none' => t('No redirect (reload current page)'),
|
82 |
|
|
),
|
83 |
a45e4bc1
|
Assos Assos
|
'#parents' => array('redirect'),
|
84 |
85ad3d82
|
Assos Assos
|
);
|
85 |
|
|
$form['submission']['redirection']['redirect_url'] = array(
|
86 |
|
|
'#type' => 'textfield',
|
87 |
|
|
'#title' => t('Redirect URL'),
|
88 |
|
|
'#description' => t('URL to redirect the user to upon successful submission.'),
|
89 |
|
|
'#default_value' => $redirect_url,
|
90 |
a45e4bc1
|
Assos Assos
|
'#maxlength' => 2048,
|
91 |
|
|
'#parents' => array('redirect_url'),
|
92 |
|
|
'#attributes' => array('title' => t('Custom URL value')),
|
93 |
85ad3d82
|
Assos Assos
|
);
|
94 |
|
|
|
95 |
|
|
// Submission limit settings for all submissions.
|
96 |
|
|
$form['submission']['total_submit_limit'] = array(
|
97 |
|
|
'#type' => 'item',
|
98 |
|
|
'#title' => t('Total submissions limit'),
|
99 |
|
|
'#theme' => 'webform_advanced_total_submit_limit_form',
|
100 |
|
|
'#description' => t('Limit the total number of allowed submissions.'),
|
101 |
|
|
);
|
102 |
|
|
$form['submission']['total_submit_limit']['enforce_total_limit'] = array(
|
103 |
|
|
'#type' => 'radios',
|
104 |
|
|
'#options' => array('no' => t('Unlimited'), 'yes' => 'Limit to !count total submission(s) !timespan'),
|
105 |
|
|
'#default_value' => $node->webform['total_submit_limit'] == -1 ? 'no' : 'yes',
|
106 |
|
|
'#parents' => array('enforce_total_limit'),
|
107 |
|
|
);
|
108 |
|
|
$form['submission']['total_submit_limit']['total_submit_limit'] = array(
|
109 |
|
|
'#type' => 'textfield',
|
110 |
|
|
'#maxlength' => 8,
|
111 |
|
|
'#size' => 8,
|
112 |
|
|
'#default_value' => $node->webform['total_submit_limit'] != -1 ? $node->webform['total_submit_limit'] : '',
|
113 |
|
|
'#parents' => array('total_submit_limit'),
|
114 |
|
|
);
|
115 |
a45e4bc1
|
Assos Assos
|
$interval_options = array(
|
116 |
feca1e4a
|
Assos Assos
|
'-1' => t('ever'),
|
117 |
|
|
'60' => t('every minute'),
|
118 |
|
|
'300' => t('every 5 minutes'),
|
119 |
|
|
'3600' => t('every hour'),
|
120 |
|
|
'86400' => t('every day'),
|
121 |
|
|
'604800' => t('every week'),
|
122 |
|
|
);
|
123 |
a45e4bc1
|
Assos Assos
|
$form['submission']['total_submit_limit']['total_submit_interval'] = array(
|
124 |
|
|
'#type' => 'select',
|
125 |
|
|
'#options' => $interval_options,
|
126 |
85ad3d82
|
Assos Assos
|
'#default_value' => $node->webform['total_submit_interval'],
|
127 |
|
|
'#parents' => array('total_submit_interval'),
|
128 |
|
|
);
|
129 |
|
|
|
130 |
|
|
// Submission limit per user settings.
|
131 |
|
|
$form['submission']['submit_limit'] = array(
|
132 |
|
|
'#type' => 'item',
|
133 |
|
|
'#title' => t('Per user submission limit'),
|
134 |
|
|
'#theme' => 'webform_advanced_submit_limit_form',
|
135 |
|
|
'#description' => t('Limit the number of submissions <em>per user</em>. A user is identified by their user login if logged-in, or by their IP Address and Cookie if anonymous. Use of cookies may be modified in the global <a href="!url">Webform settings</a>.', array('!url' => url('admin/config/content/webform'))),
|
136 |
|
|
);
|
137 |
|
|
$form['submission']['submit_limit']['enforce_limit'] = array(
|
138 |
|
|
'#type' => 'radios',
|
139 |
|
|
'#options' => array('no' => t('Unlimited'), 'yes' => 'Limit each user to !count submission(s) !timespan'),
|
140 |
|
|
'#default_value' => $node->webform['submit_limit'] == -1 ? 'no' : 'yes',
|
141 |
|
|
'#parents' => array('enforce_limit'),
|
142 |
|
|
);
|
143 |
|
|
$form['submission']['submit_limit']['submit_limit'] = array(
|
144 |
|
|
'#type' => 'textfield',
|
145 |
|
|
'#maxlength' => 2,
|
146 |
|
|
'#size' => 2,
|
147 |
|
|
'#default_value' => $node->webform['submit_limit'] != -1 ? $node->webform['submit_limit'] : '',
|
148 |
|
|
'#parents' => array('submit_limit'),
|
149 |
|
|
);
|
150 |
|
|
$form['submission']['submit_limit']['submit_interval'] = array(
|
151 |
|
|
'#type' => 'select',
|
152 |
a45e4bc1
|
Assos Assos
|
'#options' => $interval_options,
|
153 |
85ad3d82
|
Assos Assos
|
'#default_value' => $node->webform['submit_interval'],
|
154 |
|
|
'#parents' => array('submit_interval'),
|
155 |
|
|
);
|
156 |
|
|
|
157 |
|
|
$form['submission']['status'] = array(
|
158 |
|
|
'#type' => 'radios',
|
159 |
|
|
'#title' => t('Status of this form'),
|
160 |
|
|
'#default_value' => $node->webform['status'] == 0 ? 0 : 1,
|
161 |
|
|
'#description' => t('Closing a form prevents any further submissions by any users.'),
|
162 |
|
|
'#parents' => array('status'),
|
163 |
|
|
'#options' => array(1 => t('Open'), 0 => t('Closed')),
|
164 |
|
|
);
|
165 |
|
|
/* End Edit Form */
|
166 |
|
|
|
167 |
|
|
/* Start per-role submission control */
|
168 |
|
|
$form['role_control'] = array(
|
169 |
|
|
'#type' => 'fieldset',
|
170 |
|
|
'#title' => t('Submission access'),
|
171 |
|
|
'#collapsible' => TRUE,
|
172 |
|
|
'#collapsed' => FALSE,
|
173 |
|
|
'#description' => t('These permissions affect which roles can submit this webform. It does not prevent access to the webform page. If needing to prevent access to the webform page entirely, use a content access module such as <a href="http://drupal.org/project/taxonomy_access">Taxonomy Access</a> or <a href="http://drupal.org/project/node_privacy_byrole">Node Privacy by Role</a>.'),
|
174 |
a45e4bc1
|
Assos Assos
|
'#access' => webform_variable_get('webform_submission_access_control'),
|
175 |
|
|
'#weight' => 10,
|
176 |
|
|
'#states' => array(
|
177 |
|
|
'invisible' => array(
|
178 |
|
|
':input[name="confidential"]' => array('checked' => TRUE),
|
179 |
|
|
),
|
180 |
|
|
),
|
181 |
85ad3d82
|
Assos Assos
|
);
|
182 |
|
|
$user_roles = user_roles();
|
183 |
|
|
foreach ($user_roles as $rid => $rname) {
|
184 |
|
|
if ($rid == DRUPAL_ANONYMOUS_RID || $rid == DRUPAL_AUTHENTICATED_RID) {
|
185 |
|
|
continue;
|
186 |
|
|
}
|
187 |
|
|
$user_roles[$rid] = webform_tt("user:rid:$rid:name", $rname);
|
188 |
|
|
}
|
189 |
|
|
$form['role_control']['roles'] = array(
|
190 |
|
|
'#default_value' => $node->webform['roles'],
|
191 |
|
|
'#options' => $user_roles,
|
192 |
|
|
'#type' => 'checkboxes',
|
193 |
|
|
'#title' => t('Roles that can submit this webform'),
|
194 |
|
|
'#description' => t('The %authenticated role applies to any user signed into the site, regardless of other assigned roles.', array('%authenticated' => $user_roles[2])),
|
195 |
|
|
);
|
196 |
|
|
/* End per-role submission control */
|
197 |
|
|
|
198 |
a45e4bc1
|
Assos Assos
|
/* Start progress bar settings form */
|
199 |
|
|
$form['progressbar'] = array(
|
200 |
|
|
'#type' => 'fieldset',
|
201 |
|
|
'#title' => t('Progress bar'),
|
202 |
|
|
'#collapsible' => TRUE,
|
203 |
|
|
'#collapsed' => TRUE,
|
204 |
|
|
'#weight' => 15,
|
205 |
|
|
);
|
206 |
|
|
$progress_bar_style = array_filter(array(
|
207 |
|
|
$node->webform['progressbar_page_number'] ? 'progressbar_page_number' : NULL,
|
208 |
|
|
$node->webform['progressbar_percent'] ? 'progressbar_percent' : NULL,
|
209 |
|
|
$node->webform['progressbar_bar'] ? 'progressbar_bar' : NULL,
|
210 |
|
|
$node->webform['progressbar_pagebreak_labels'] ? 'progressbar_pagebreak_labels' : NULL,
|
211 |
|
|
$node->webform['progressbar_include_confirmation'] ? 'progressbar_include_confirmation' : NULL,
|
212 |
|
|
));
|
213 |
feca1e4a
|
Assos Assos
|
$form['progressbar']['webform_progressbar_style'] = array(
|
214 |
a45e4bc1
|
Assos Assos
|
'#type' => 'checkboxes',
|
215 |
|
|
'#title' => t('Progress bar style'),
|
216 |
|
|
'#options' => array(
|
217 |
|
|
'progressbar_bar' => t('Show progress bar'),
|
218 |
|
|
'progressbar_page_number' => t('Show page number as number of completed (i.e. Page 1 of 10)'),
|
219 |
|
|
'progressbar_percent' => t('Show percentage completed (i.e. 10%)'),
|
220 |
|
|
'progressbar_pagebreak_labels' => t('Show page labels from page break components'),
|
221 |
|
|
'progressbar_include_confirmation' => t('Include confirmation page in progress bar'),
|
222 |
|
|
),
|
223 |
|
|
'#default_value' => $progress_bar_style,
|
224 |
|
|
'#description' => t('Choose how the progress bar should be displayed for multi-page forms.'),
|
225 |
|
|
);
|
226 |
|
|
$form['progressbar']['progressbar_label_first'] = array(
|
227 |
|
|
'#type' => 'textfield',
|
228 |
|
|
'#title' => t('First page label'),
|
229 |
|
|
'#default_value' => $node->webform['progressbar_label_first'],
|
230 |
|
|
'#maxlength' => 255,
|
231 |
|
|
'#description' => t('The first page label in the progress bar. Subseqent pages are titled by their page break label.'),
|
232 |
|
|
'#states' => array(
|
233 |
|
|
'visible' => array(
|
234 |
|
|
':input[name="webform_progressbar_style[progressbar_pagebreak_labels]"]' => array('checked' => TRUE),
|
235 |
|
|
),
|
236 |
|
|
),
|
237 |
|
|
);
|
238 |
|
|
$form['progressbar']['progressbar_label_confirmation'] = array(
|
239 |
|
|
'#type' => 'textfield',
|
240 |
|
|
'#title' => t('Confirmation page label'),
|
241 |
|
|
'#default_value' => $node->webform['progressbar_label_confirmation'],
|
242 |
|
|
'#maxlength' => 255,
|
243 |
|
|
'#states' => array(
|
244 |
|
|
'visible' => array(
|
245 |
|
|
':input[name="webform_progressbar_style[progressbar_pagebreak_labels]"]' => array('checked' => TRUE),
|
246 |
|
|
':input[name="webform_progressbar_style[progressbar_include_confirmation]"]' => array('checked' => TRUE),
|
247 |
|
|
),
|
248 |
|
|
),
|
249 |
|
|
);
|
250 |
|
|
/* End progress bar settings form */
|
251 |
|
|
|
252 |
|
|
/* Preview page settings form */
|
253 |
|
|
$form['preview'] = array(
|
254 |
|
|
'#type' => 'fieldset',
|
255 |
|
|
'#title' => t('Preview page'),
|
256 |
|
|
'#collapsible' => TRUE,
|
257 |
|
|
'#collapsed' => TRUE,
|
258 |
|
|
'#weight' => 18,
|
259 |
|
|
'#id' => 'webform-preview-fieldset',
|
260 |
|
|
);
|
261 |
|
|
|
262 |
|
|
$form['preview']['preview'] = array(
|
263 |
|
|
'#type' => 'checkbox',
|
264 |
|
|
'#title' => t('Enable preview page'),
|
265 |
|
|
'#description' => t('Add a page for previewing the form before submitting.'),
|
266 |
|
|
'#default_value' => $node->webform['preview'],
|
267 |
feca1e4a
|
Assos Assos
|
'#id' => 'webform-preview-enable',
|
268 |
a45e4bc1
|
Assos Assos
|
);
|
269 |
|
|
$form['preview']['settings'] = array(
|
270 |
|
|
'#type' => 'container',
|
271 |
|
|
'#states' => array(
|
272 |
|
|
'visible' => array(
|
273 |
|
|
'#webform-preview-enable' => array('checked' => TRUE),
|
274 |
|
|
),
|
275 |
|
|
),
|
276 |
|
|
'#id' => 'webform-preview-settings',
|
277 |
|
|
'#theme_wrappers' => array('container'),
|
278 |
|
|
);
|
279 |
|
|
$form['preview']['settings']['preview_title'] = array(
|
280 |
|
|
'#type' => 'textfield',
|
281 |
|
|
'#title' => t('Preview page title'),
|
282 |
|
|
'#default_value' => $node->webform['preview_title'],
|
283 |
|
|
'#description' => t('The page title will be used in the progress bar (if enabled). If left blank, the default title %preview will be used.', array('%preview' => t('Preview'))),
|
284 |
|
|
);
|
285 |
|
|
$form['preview']['settings']['preview_next_button_label'] = array(
|
286 |
|
|
'#type' => 'textfield',
|
287 |
|
|
'#title' => t('Preview button label'),
|
288 |
|
|
'#default_value' => $node->webform['preview_next_button_label'],
|
289 |
|
|
'#description' => t('The text for the button that will proceed to the preview page. If left blank, the default label %preview will be used.', array('%preview' => t('Preview'))),
|
290 |
|
|
'#size' => 20,
|
291 |
|
|
);
|
292 |
|
|
$form['preview']['settings']['preview_prev_button_label'] = array(
|
293 |
|
|
'#type' => 'textfield',
|
294 |
|
|
'#title' => t('Previous page button label'),
|
295 |
|
|
'#default_value' => $node->webform['preview_prev_button_label'],
|
296 |
|
|
'#description' => t('The text for the button to go backwards from the preview page. If left blank, the default label %previous will be used.', array('%previous' => t('< Previous'))),
|
297 |
|
|
'#size' => 20,
|
298 |
|
|
);
|
299 |
|
|
$submit_button_text = $node->webform['submit_text'] ? t($node->webform['submit_text']) : t('Submit');
|
300 |
|
|
$preview_default_message = t('Please review your submission. Your submission is not complete until you press the "@button" button!', array('@button' => $submit_button_text));
|
301 |
|
|
$form['preview']['settings']['preview_message'] = array(
|
302 |
|
|
'#type' => 'text_format',
|
303 |
|
|
'#title' => t('Preview message'),
|
304 |
|
|
'#default_value' => $node->webform['preview_message'],
|
305 |
|
|
'#format' => $node->webform['preview_message_format'],
|
306 |
|
|
'#description' => t('A message to be displayed on the preview page. If left blank, the message "!default" will be used. Supports Webform token replacements.', array('!default' => $preview_default_message)) . ' ' . theme('webform_token_help', array('groups' => array('node', 'submission'))),
|
307 |
|
|
);
|
308 |
|
|
$form['preview']['settings']['preview_components'] = array(
|
309 |
|
|
'#type' => 'select',
|
310 |
|
|
'#title' => t('Included preview values'),
|
311 |
|
|
'#options' => webform_component_list($node, 'email', TRUE),
|
312 |
|
|
'#default_value' => array_diff(array_keys($node->webform['components']), $node->webform['preview_excluded_components']),
|
313 |
|
|
'#multiple' => TRUE,
|
314 |
|
|
'#size' => 10,
|
315 |
|
|
'#description' => t('If you wish to include only parts of the submission in the preview, select the components that should be included.'),
|
316 |
|
|
'#process' => array('webform_component_select'),
|
317 |
|
|
);
|
318 |
|
|
/* End preview page settings form */
|
319 |
|
|
|
320 |
85ad3d82
|
Assos Assos
|
/* Start advanced settings form */
|
321 |
|
|
$form['advanced'] = array(
|
322 |
|
|
'#type' => 'fieldset',
|
323 |
|
|
'#title' => t('Advanced settings'),
|
324 |
|
|
'#collapsible' => TRUE,
|
325 |
|
|
'#collapsed' => TRUE,
|
326 |
a45e4bc1
|
Assos Assos
|
'#weight' => 20,
|
327 |
85ad3d82
|
Assos Assos
|
);
|
328 |
|
|
$form['advanced']['block'] = array(
|
329 |
|
|
'#type' => 'checkbox',
|
330 |
|
|
'#title' => t('Available as block'),
|
331 |
|
|
'#default_value' => $node->webform['block'],
|
332 |
|
|
'#description' => t('If enabled this webform will be available as a block.'),
|
333 |
|
|
'#access' => user_access('administer blocks') || user_access('administer site configuration') || user_access('use panels dashboard'),
|
334 |
|
|
);
|
335 |
|
|
$form['advanced']['allow_draft'] = array(
|
336 |
|
|
'#type' => 'checkbox',
|
337 |
|
|
'#title' => t('Show "Save draft" button'),
|
338 |
|
|
'#default_value' => $node->webform['allow_draft'],
|
339 |
|
|
'#description' => t('Allow your users to save and finish the form later. This option is available only for authenticated users.'),
|
340 |
|
|
);
|
341 |
|
|
$form['advanced']['auto_save'] = array(
|
342 |
|
|
'#type' => 'checkbox',
|
343 |
a45e4bc1
|
Assos Assos
|
'#title' => t('Automatically save as draft between pages and when there are validation errors'),
|
344 |
85ad3d82
|
Assos Assos
|
'#default_value' => $node->webform['auto_save'],
|
345 |
a45e4bc1
|
Assos Assos
|
'#description' => t('Automatically save partial submissions when users click the "Next" or "Previous" buttons in a multipage form or when validation errors prevent form submission.'),
|
346 |
85ad3d82
|
Assos Assos
|
);
|
347 |
|
|
$form['advanced']['submit_notice'] = array(
|
348 |
|
|
'#type' => 'checkbox',
|
349 |
a45e4bc1
|
Assos Assos
|
'#title' => t('Show the notification about previous submissions'),
|
350 |
85ad3d82
|
Assos Assos
|
'#default_value' => $node->webform['submit_notice'],
|
351 |
|
|
'#description' => t('Show the previous submissions notification that appears when users have previously submitted this form.'),
|
352 |
|
|
);
|
353 |
a45e4bc1
|
Assos Assos
|
$form['advanced']['confidential'] = array(
|
354 |
|
|
'#type' => 'checkbox',
|
355 |
|
|
'#title' => t('Confidential submissions'),
|
356 |
|
|
'#default_value' => $node->webform['confidential'],
|
357 |
|
|
'#description' => t('Confidential submissions have no recorded IP address and must be submitted while logged out.'),
|
358 |
|
|
);
|
359 |
85ad3d82
|
Assos Assos
|
$form['advanced']['submit_text'] = array(
|
360 |
|
|
'#type' => 'textfield',
|
361 |
a45e4bc1
|
Assos Assos
|
'#title' => t('Submit button label'),
|
362 |
85ad3d82
|
Assos Assos
|
'#default_value' => $node->webform['submit_text'],
|
363 |
|
|
'#description' => t('By default the submit button on this form will have the label <em>Submit</em>. Enter a new title here to override the default.'),
|
364 |
a45e4bc1
|
Assos Assos
|
'#size' => 20,
|
365 |
|
|
);
|
366 |
|
|
$form['advanced']['next_serial'] = array(
|
367 |
|
|
'#type' => 'textfield',
|
368 |
|
|
'#title' => t('Next submission number'),
|
369 |
|
|
'#default_value' => $node->webform['next_serial'],
|
370 |
|
|
'#description' => t('The value of the next submission number. This is usually 1 when you start and will go up with each form submission.'),
|
371 |
|
|
'#size' => 8,
|
372 |
|
|
'#maxlength' => 8,
|
373 |
85ad3d82
|
Assos Assos
|
);
|
374 |
|
|
/* End Advanced Settings Form */
|
375 |
|
|
|
376 |
|
|
$form['actions'] = array(
|
377 |
|
|
'#type' => 'actions',
|
378 |
|
|
'#weight' => 300,
|
379 |
|
|
);
|
380 |
|
|
|
381 |
|
|
$form['actions']['submit'] = array(
|
382 |
|
|
'#type' => 'submit',
|
383 |
|
|
'#value' => t('Save configuration'),
|
384 |
|
|
);
|
385 |
|
|
|
386 |
|
|
return $form;
|
387 |
|
|
}
|
388 |
|
|
|
389 |
|
|
/**
|
390 |
|
|
* Validate handler for webform_configure_form().
|
391 |
|
|
*/
|
392 |
|
|
function webform_configure_form_validate($form, &$form_state) {
|
393 |
|
|
// Ensure the entered redirect URL is valid.
|
394 |
|
|
if ($form_state['values']['redirect'] == 'url') {
|
395 |
|
|
$redirect_url = trim($form_state['values']['redirect_url']);
|
396 |
|
|
if (empty($redirect_url)) {
|
397 |
|
|
form_error($form['submission']['redirection']['redirect_url'], t('A valid URL is required for custom redirection.'));
|
398 |
|
|
}
|
399 |
a45e4bc1
|
Assos Assos
|
elseif (strpos($redirect_url, 'http') === 0 && !valid_url(webform_replace_tokens($redirect_url, $form['#node']), TRUE)) {
|
400 |
85ad3d82
|
Assos Assos
|
form_error($form['submission']['redirection']['redirect_url'], t('The entered URL is not a valid address.'));
|
401 |
|
|
}
|
402 |
|
|
else {
|
403 |
|
|
form_set_value($form['submission']['redirection']['redirect_url'], $redirect_url, $form_state);
|
404 |
|
|
}
|
405 |
|
|
}
|
406 |
|
|
elseif ($form_state['values']['redirect'] == 'confirmation') {
|
407 |
|
|
form_set_value($form['submission']['redirection']['redirect_url'], '<confirmation>', $form_state);
|
408 |
|
|
}
|
409 |
|
|
else {
|
410 |
|
|
form_set_value($form['submission']['redirection']['redirect_url'], '<none>', $form_state);
|
411 |
|
|
}
|
412 |
a45e4bc1
|
Assos Assos
|
|
413 |
|
|
// Ensure only positive integers are entered as submission limits.
|
414 |
8c72e82a
|
Assos Assos
|
foreach (array('total_submit_limit' => 'enforce_total_limit', 'submit_limit' => 'enforce_limit') as $field => $enforce_fk) {
|
415 |
a45e4bc1
|
Assos Assos
|
$limit = $form['submission'][$field][$field]['#value'];
|
416 |
8c72e82a
|
Assos Assos
|
if ($form['submission'][$field][$enforce_fk]['#value'] !== 'no' && $limit !== '' && (int) $limit < 1 && (int) $limit !== -1) {
|
417 |
a45e4bc1
|
Assos Assos
|
form_error($form['submission'][$field][$field], t('The submission limit must be at least 1.'));
|
418 |
|
|
}
|
419 |
|
|
}
|
420 |
|
|
|
421 |
|
|
// Prohibit the combination of confidential + per-user limit + ip-only
|
422 |
|
|
// submission tracking for anonymous users as it would not be enforceable.
|
423 |
|
|
if (webform_variable_get('webform_tracking_mode') == 'ip_address' &&
|
424 |
|
|
$form_state['values']['confidential'] &&
|
425 |
|
|
$form_state['values']['enforce_limit'] == 'yes') {
|
426 |
|
|
// Note that FAPI doesn't actually support error highlighting on radio or
|
427 |
|
|
// checkbox form elements.
|
428 |
|
|
form_error($form['advanced']['confidential'],
|
429 |
8c72e82a
|
Assos Assos
|
t('Choose a "Per user submission limit" or "Confidential submissions", but not both. Or ask the adminstrator to track anonymous users by cookie, rather than IP address only.'));
|
430 |
a45e4bc1
|
Assos Assos
|
}
|
431 |
85ad3d82
|
Assos Assos
|
}
|
432 |
|
|
|
433 |
|
|
/**
|
434 |
|
|
* Submit handler for webform_configure_form().
|
435 |
|
|
*/
|
436 |
|
|
function webform_configure_form_submit($form, &$form_state) {
|
437 |
|
|
// Edit the node by reference just to shorten it up.
|
438 |
|
|
$node = &$form['#node'];
|
439 |
|
|
|
440 |
|
|
// Save the confirmation.
|
441 |
|
|
$node->webform['confirmation'] = $form_state['values']['confirmation']['value'];
|
442 |
|
|
$node->webform['confirmation_format'] = $form_state['values']['confirmation']['format'];
|
443 |
|
|
|
444 |
feca1e4a
|
Assos Assos
|
// Save the redirect URL.
|
445 |
85ad3d82
|
Assos Assos
|
$node->webform['redirect_url'] = $form_state['values']['redirect_url'];
|
446 |
|
|
|
447 |
|
|
// Overall form status.
|
448 |
|
|
$node->webform['status'] = $form_state['values']['status'];
|
449 |
|
|
|
450 |
|
|
// Save roles.
|
451 |
|
|
$node->webform['roles'] = array_keys(array_filter($form_state['values']['roles']));
|
452 |
|
|
|
453 |
|
|
// Set the block option.
|
454 |
|
|
$node->webform['block'] = $form_state['values']['block'];
|
455 |
|
|
|
456 |
|
|
// Set the draft option.
|
457 |
|
|
$node->webform['allow_draft'] = $form_state['values']['allow_draft'];
|
458 |
|
|
|
459 |
|
|
// Set the auto-save draft option.
|
460 |
|
|
$node->webform['auto_save'] = $form_state['values']['auto_save'];
|
461 |
|
|
|
462 |
|
|
// Set the submit limit to -1 if set to unlimited.
|
463 |
|
|
if ($form_state['values']['enforce_limit'] == 'no') {
|
464 |
|
|
$node->webform['submit_limit'] = -1;
|
465 |
|
|
$node->webform['submit_interval'] = -1;
|
466 |
|
|
}
|
467 |
|
|
else {
|
468 |
a45e4bc1
|
Assos Assos
|
$node->webform['submit_limit'] = (int) $form_state['values']['submit_limit'];
|
469 |
|
|
$node->webform['submit_interval'] = (int) $form_state['values']['submit_interval'];
|
470 |
85ad3d82
|
Assos Assos
|
}
|
471 |
|
|
|
472 |
|
|
// Set the total submit limit to -1 if set to unlimited.
|
473 |
|
|
if ($form_state['values']['enforce_total_limit'] == 'no') {
|
474 |
|
|
$node->webform['total_submit_limit'] = -1;
|
475 |
|
|
$node->webform['total_submit_interval'] = -1;
|
476 |
|
|
}
|
477 |
|
|
else {
|
478 |
a45e4bc1
|
Assos Assos
|
$node->webform['total_submit_limit'] = (int) $form_state['values']['total_submit_limit'];
|
479 |
|
|
$node->webform['total_submit_interval'] = (int) $form_state['values']['total_submit_interval'];
|
480 |
85ad3d82
|
Assos Assos
|
}
|
481 |
|
|
|
482 |
a45e4bc1
|
Assos Assos
|
// Set the progress bar preferences.
|
483 |
|
|
$progress_bar_settings = array_filter($form_state['values']['webform_progressbar_style']);
|
484 |
|
|
$node->webform['progressbar_page_number'] = in_array('progressbar_page_number', $progress_bar_settings);
|
485 |
|
|
$node->webform['progressbar_percent'] = in_array('progressbar_percent', $progress_bar_settings);
|
486 |
|
|
$node->webform['progressbar_bar'] = in_array('progressbar_bar', $progress_bar_settings);
|
487 |
|
|
$node->webform['progressbar_pagebreak_labels'] = in_array('progressbar_pagebreak_labels', $progress_bar_settings);
|
488 |
|
|
$node->webform['progressbar_include_confirmation'] = in_array('progressbar_include_confirmation', $progress_bar_settings);
|
489 |
|
|
$node->webform['progressbar_label_first'] = $form_state['values']['progressbar_label_first'];
|
490 |
|
|
$node->webform['progressbar_label_confirmation'] = $form_state['values']['progressbar_label_confirmation'];
|
491 |
|
|
|
492 |
|
|
// Set the preview settings.
|
493 |
|
|
$node->webform['preview'] = (int) $form_state['values']['preview'];
|
494 |
|
|
$node->webform['preview_next_button_label'] = $form_state['values']['preview_next_button_label'];
|
495 |
|
|
$node->webform['preview_prev_button_label'] = $form_state['values']['preview_prev_button_label'];
|
496 |
|
|
$node->webform['preview_title'] = $form_state['values']['preview_title'];
|
497 |
|
|
$node->webform['preview_message'] = $form_state['values']['preview_message']['value'];
|
498 |
|
|
$node->webform['preview_message_format'] = $form_state['values']['preview_message']['format'];
|
499 |
|
|
|
500 |
|
|
// Save the list of included preview components.
|
501 |
|
|
// We actually maintain an *exclusion* list, so any new components will
|
502 |
|
|
// default to being included in the preview until unchecked.
|
503 |
|
|
$included = array_keys(array_filter((array) $form_state['values']['preview_components']));
|
504 |
|
|
$excluded = array_diff(array_keys($node->webform['components']), $included);
|
505 |
|
|
$node->webform['preview_excluded_components'] = $excluded;
|
506 |
|
|
|
507 |
85ad3d82
|
Assos Assos
|
// Set submit notice.
|
508 |
|
|
$node->webform['submit_notice'] = $form_state['values']['submit_notice'];
|
509 |
|
|
|
510 |
a45e4bc1
|
Assos Assos
|
// Set confidential.
|
511 |
|
|
$node->webform['confidential'] = $form_state['values']['confidential'];
|
512 |
|
|
|
513 |
85ad3d82
|
Assos Assos
|
// Set submit button text.
|
514 |
|
|
$node->webform['submit_text'] = $form_state['values']['submit_text'];
|
515 |
a45e4bc1
|
Assos Assos
|
|
516 |
|
|
// Set next serial number. It must be a positive integer greater than any
|
517 |
|
|
// existing serial number, which could have increased while this form was
|
518 |
|
|
// being edited.
|
519 |
|
|
$next_min = _webform_submission_serial_next_value_used($node->nid);
|
520 |
feca1e4a
|
Assos Assos
|
$next_serial = (int) $form_state['values']['next_serial'];
|
521 |
a45e4bc1
|
Assos Assos
|
if ($next_serial < $next_min) {
|
522 |
|
|
drupal_set_message(t('The next submission number was increased to @min to make it higher than existing submissions.',
|
523 |
8c72e82a
|
Assos Assos
|
array('@min' => $next_min)));
|
524 |
a45e4bc1
|
Assos Assos
|
$next_serial = $next_min;
|
525 |
|
|
}
|
526 |
|
|
$node->webform['next_serial'] = $next_serial;
|
527 |
85ad3d82
|
Assos Assos
|
}
|
528 |
|
|
|
529 |
|
|
/**
|
530 |
|
|
* Submit handler for webform_configure_form() that saves the node.
|
531 |
|
|
*
|
532 |
|
|
* This is separate from webform_configure_form_submit() to allow other modules
|
533 |
|
|
* to add properties if needed into the $form['#node'] object before save.
|
534 |
|
|
*/
|
535 |
|
|
function webform_configure_form_submit_save($form, &$form_state) {
|
536 |
|
|
node_save($form['#node']);
|
537 |
|
|
drupal_set_message(t('The form settings have been updated.'));
|
538 |
a45e4bc1
|
Assos Assos
|
|
539 |
|
|
$node = &$form['#node'];
|
540 |
8c72e82a
|
Assos Assos
|
if (!$node->webform['block'] && function_exists('block_load') &&
|
541 |
a45e4bc1
|
Assos Assos
|
($block = block_load('webform', 'client-block-' . $node->nid)) &&
|
542 |
|
|
!empty($block->bid)) {
|
543 |
|
|
// An existing block for this not-currently-available block was already configured.
|
544 |
|
|
// See https://www.drupal.org/node/2365825
|
545 |
|
|
// The core block module contains a bug which causes it to not remove blocks
|
546 |
|
|
// which are no longer available in code. Therefore, to prevent the block from
|
547 |
|
|
// being processed, it must be removed manually here.
|
548 |
|
|
// Remove the block for all themes.
|
549 |
|
|
db_delete('block')
|
550 |
|
|
->condition('module', 'webform')
|
551 |
|
|
->condition('delta', $block->delta)
|
552 |
|
|
->execute();
|
553 |
feca1e4a
|
Assos Assos
|
// Remove any roles associated with the block.
|
554 |
a45e4bc1
|
Assos Assos
|
db_delete('block_role')
|
555 |
|
|
->condition('module', 'webform')
|
556 |
|
|
->condition('delta', $block->delta)
|
557 |
|
|
->execute();
|
558 |
|
|
drupal_set_message(t('The block %info was deleted.', array('%info' => t('Webform: !title', array('!title' => $node->title)))));
|
559 |
|
|
cache_clear_all();
|
560 |
|
|
}
|
561 |
85ad3d82
|
Assos Assos
|
}
|
562 |
|
|
|
563 |
|
|
/**
|
564 |
|
|
* Theme the redirection setting on the webform node form.
|
565 |
|
|
*/
|
566 |
|
|
function theme_webform_advanced_redirection_form($variables) {
|
567 |
|
|
$form = $variables['form'];
|
568 |
|
|
// Add special class for setting the active radio button.
|
569 |
3753f249
|
Assos Assos
|
$form['redirect_url']['#attributes']['class'][] = 'webform-set-active';
|
570 |
85ad3d82
|
Assos Assos
|
|
571 |
a45e4bc1
|
Assos Assos
|
// Remove wrappers around the inline Redirect URL field.
|
572 |
|
|
$form['redirect_url']['#theme_wrappers'] = array();
|
573 |
85ad3d82
|
Assos Assos
|
|
574 |
|
|
$form['redirect']['confirmation']['#theme_wrappers'] = array('webform_inline_radio');
|
575 |
|
|
$form['redirect']['url']['#theme_wrappers'] = array('webform_inline_radio');
|
576 |
|
|
$form['redirect']['none']['#theme_wrappers'] = array('webform_inline_radio');
|
577 |
a45e4bc1
|
Assos Assos
|
$form['redirect']['url']['#title'] = t('Custom URL: !redirect_url', array('!redirect_url' => drupal_render($form['redirect_url'])));
|
578 |
85ad3d82
|
Assos Assos
|
|
579 |
|
|
return drupal_render_children($form);
|
580 |
|
|
}
|
581 |
|
|
|
582 |
|
|
/**
|
583 |
|
|
* Theme the submit limit fieldset on the webform node form.
|
584 |
|
|
*/
|
585 |
|
|
function theme_webform_advanced_submit_limit_form($variables) {
|
586 |
|
|
$form = $variables['form'];
|
587 |
3753f249
|
Assos Assos
|
$form['submit_limit']['#attributes']['class'][] = 'webform-set-active';
|
588 |
|
|
$form['submit_interval']['#attributes']['class'][] = 'webform-set-active';
|
589 |
85ad3d82
|
Assos Assos
|
// Remove div wrappers around limit options.
|
590 |
|
|
$form['submit_limit']['#theme_wrappers'] = array();
|
591 |
|
|
$form['submit_interval']['#theme_wrappers'] = array();
|
592 |
|
|
|
593 |
|
|
$form['enforce_limit']['no']['#theme_wrappers'] = array('webform_inline_radio');
|
594 |
|
|
$form['enforce_limit']['yes']['#theme_wrappers'] = array('webform_inline_radio');
|
595 |
a45e4bc1
|
Assos Assos
|
$form['enforce_limit']['yes']['#title'] = t('Limit each user to !count submission(s) !timespan', array('!count' => drupal_render($form['submit_limit']), '!timespan' => drupal_render($form['submit_interval'])));
|
596 |
85ad3d82
|
Assos Assos
|
|
597 |
|
|
return drupal_render_children($form);
|
598 |
|
|
}
|
599 |
|
|
|
600 |
|
|
/**
|
601 |
|
|
* Theme the total submit limit fieldset on the webform node form.
|
602 |
|
|
*/
|
603 |
|
|
function theme_webform_advanced_total_submit_limit_form($variables) {
|
604 |
|
|
$form = $variables['form'];
|
605 |
3753f249
|
Assos Assos
|
$form['total_submit_limit']['#attributes']['class'][] = 'webform-set-active';
|
606 |
|
|
$form['total_submit_interval']['#attributes']['class'][] = 'webform-set-active';
|
607 |
85ad3d82
|
Assos Assos
|
// Remove div wrappers around limit options.
|
608 |
|
|
$form['total_submit_limit']['#theme_wrappers'] = array();
|
609 |
|
|
$form['total_submit_interval']['#theme_wrappers'] = array();
|
610 |
|
|
|
611 |
|
|
$form['enforce_total_limit']['no']['#theme_wrappers'] = array('webform_inline_radio');
|
612 |
|
|
$form['enforce_total_limit']['yes']['#theme_wrappers'] = array('webform_inline_radio');
|
613 |
a45e4bc1
|
Assos Assos
|
$form['enforce_total_limit']['yes']['#title'] = t('Limit to !count total submission(s) !timespan', array('!count' => drupal_render($form['total_submit_limit']), '!timespan' => drupal_render($form['total_submit_interval'])));
|
614 |
85ad3d82
|
Assos Assos
|
|
615 |
|
|
return drupal_render_children($form);
|
616 |
|
|
} |