Projet

Général

Profil

Paste
Télécharger (16,2 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / webform / includes / webform.admin.inc @ 389fb945

1 85ad3d82 Assos Assos
<?php
2
3
/**
4
 * @file
5
 * Administration pages provided by Webform module.
6
 */
7
8
/**
9
 * Menu callback for admin/config/content/webform.
10
 */
11
function webform_admin_settings() {
12
  module_load_include('inc', 'webform', 'includes/webform.export');
13
14
  $form['components'] = array(
15
    '#type' => 'fieldset',
16
    '#title' => t('Available components'),
17
    '#collapsible' => TRUE,
18
    '#collapsed' => FALSE,
19
    '#description' => t('These are the available field types for your installation of Webform. You may disable any of these components by unchecking its corresponding box. Only checked components will be available in existing or new webforms.'),
20
  );
21
22
  // Add each component to the form:
23 389fb945 Assos Assos
  $form['components'] += array('#tree' => TRUE);
24 85ad3d82 Assos Assos
  $component_types = webform_components(TRUE);
25
  foreach ($component_types as $key => $component) {
26
    $form['components'][$key] = array(
27
      '#title' => $component['label'],
28
      '#description' => $component['description'],
29
      '#type' => 'checkbox',
30
      '#return_value' => 1,
31
      '#default_value' => $component['enabled'],
32
    );
33
  }
34
35
  $form['email'] = array(
36
    '#type' => 'fieldset',
37
    '#title' => t('Default e-mail values'),
38
    '#collapsible' => TRUE,
39
    '#collapsed' => FALSE,
40
  );
41
42 feca1e4a Assos Assos
  $form['email']['webform_default_from_address'] = array(
43 85ad3d82 Assos Assos
    '#type' => 'textfield',
44
    '#title' => t('From address'),
45 a45e4bc1 Assos Assos
    '#default_value' => webform_variable_get('webform_default_from_address'),
46 85ad3d82 Assos Assos
    '#description' => t('The default sender address for emailed webform results; often the e-mail address of the maintainer of your forms.'),
47
  );
48
49 feca1e4a Assos Assos
  $form['email']['webform_default_from_name'] = array(
50 85ad3d82 Assos Assos
    '#type' => 'textfield',
51
    '#title' => t('From name'),
52 a45e4bc1 Assos Assos
    '#default_value' => webform_variable_get('webform_default_from_name'),
53 85ad3d82 Assos Assos
    '#description' => t('The default sender name which is used along with the default from address.'),
54
  );
55
56 feca1e4a Assos Assos
  $form['email']['webform_default_subject'] = array(
57 85ad3d82 Assos Assos
    '#type' => 'textfield',
58
    '#title' => t('Default subject'),
59 a45e4bc1 Assos Assos
    '#default_value' => webform_variable_get('webform_default_subject'),
60 85ad3d82 Assos Assos
    '#description' => t('The default subject line of any e-mailed results.'),
61
  );
62
63 feca1e4a Assos Assos
  $form['email']['webform_email_replyto'] = array(
64 a45e4bc1 Assos Assos
    '#type' => 'checkbox',
65
    '#title' => t('Use Reply-To header'),
66
    '#default_value' => webform_variable_get('webform_email_replyto'),
67 76bdcd04 Assos Assos
    '#description' => t('If the default from name and address are set above, send all e-mail from the default address set the "Reply-To" header to the actual sender. This helps prevent e-mail from being flagged as spam.'),
68 a45e4bc1 Assos Assos
  );
69
70 feca1e4a Assos Assos
  $form['email']['webform_email_html_capable'] = array(
71 a45e4bc1 Assos Assos
    '#type' => 'checkbox',
72
    '#title' => t('HTML mail system'),
73
    '#default_value' => webform_variable_get('webform_email_html_capable'),
74
    '#description' => t('Whether the mail system configured for webform is capable of sending mail in HTML format.'),
75
  );
76
77 feca1e4a Assos Assos
  $form['email']['webform_default_format'] = array(
78 85ad3d82 Assos Assos
    '#type' => 'radios',
79
    '#title' => t('Format'),
80
    '#options' => array(
81
      0 => t('Plain text'),
82
      1 => t('HTML'),
83
    ),
84 a45e4bc1 Assos Assos
    '#default_value' => webform_variable_get('webform_default_format'),
85 85ad3d82 Assos Assos
    '#description' => t('The default format for new e-mail settings. Webform e-mail options take precedence over the settings for system-wide e-mails configured in MIME mail.'),
86 a45e4bc1 Assos Assos
    '#states' => array(
87
      'visible' => array(
88
        ':input[name="webform_email_html_capable"]' => array('checked' => TRUE),
89
      ),
90
    ),
91 85ad3d82 Assos Assos
  );
92
93 feca1e4a Assos Assos
  $form['email']['webform_format_override'] = array(
94 85ad3d82 Assos Assos
    '#type' => 'radios',
95
    '#title' => t('Format override'),
96
    '#options' => array(
97
      0 => t('Per-webform configuration of e-mail format'),
98
      1 => t('Send all e-mails in the default format'),
99
    ),
100 a45e4bc1 Assos Assos
    '#default_value' => webform_variable_get('webform_format_override'),
101 85ad3d82 Assos Assos
    '#description' => t('Force all webform e-mails to be sent in the default format.'),
102 a45e4bc1 Assos Assos
    '#states' => array(
103
      'visible' => array(
104
        ':input[name="webform_email_html_capable"]' => array('checked' => TRUE),
105
      ),
106
    ),
107 85ad3d82 Assos Assos
  );
108
109 a45e4bc1 Assos Assos
  $form['progressbar'] = array(
110 85ad3d82 Assos Assos
    '#type' => 'fieldset',
111 a45e4bc1 Assos Assos
    '#title' => t('Progress bar'),
112 85ad3d82 Assos Assos
    '#collapsible' => TRUE,
113
    '#collapsed' => TRUE,
114
  );
115 feca1e4a Assos Assos
  $form['progressbar']['webform_progressbar_style'] = array(
116 a45e4bc1 Assos Assos
    '#type' => 'checkboxes',
117
    '#title' => t('Progress bar style'),
118
    '#options' => array(
119
      'progressbar_bar' => t('Show progress bar'),
120
      'progressbar_page_number' => t('Show page number as number of completed (i.e. Page 1 of 10)'),
121
      'progressbar_percent' => t('Show percentage completed (i.e. 10%)'),
122
      'progressbar_pagebreak_labels' => t('Show page labels from page break components'),
123
      'progressbar_include_confirmation' => t('Include confirmation page in progress bar'),
124
    ),
125
    '#default_value' => webform_variable_get('webform_progressbar_style'),
126
    '#description' => t('Choose how the progress bar should be displayed for multi-page forms.'),
127
  );
128
  $form['progressbar']['webform_progressbar_label_first'] = array(
129
    '#type' => 'textfield',
130
    '#title' => t('First page label'),
131
    '#default_value' => webform_variable_get('webform_progressbar_label_first'),
132
    '#maxlength' => 255,
133
  );
134
  $form['progressbar']['webform_progressbar_label_confirmation'] = array(
135
    '#type' => 'textfield',
136
    '#title' => t('Confirmation page label'),
137
    '#default_value' => webform_variable_get('webform_progressbar_label_confirmation'),
138
    '#maxlength' => 255,
139
  );
140 85ad3d82 Assos Assos
141 a45e4bc1 Assos Assos
  $form['advanced'] = array(
142
    '#type' => 'fieldset',
143
    '#title' => t('Advanced options'),
144
    '#collapsible' => TRUE,
145
    '#collapsed' => TRUE,
146
    '#weight' => 20,
147 85ad3d82 Assos Assos
  );
148
149 feca1e4a Assos Assos
  $form['advanced']['webform_tracking_mode'] = array(
150 a45e4bc1 Assos Assos
    '#type' => 'radios',
151
    '#title' => t('Track anonymous users by:'),
152
    '#options' => array(
153
      'cookie' => t('Cookie only (least strict)'),
154
      'ip_address' => t('IP address only'),
155
      'strict' => t('Both cookie and IP address (most strict)'),
156
    ),
157
    '#default_value' => webform_variable_get('webform_tracking_mode'),
158
    '#description' => t('<a href="http://www.wikipedia.org/wiki/HTTP_cookie">Cookies</a> can be used to help prevent the same user from repeatedly submitting a webform. Limiting by IP address is more effective against repeated submissions, but may result in unintentional blocking of users sharing the same address. Confidential submissions are tracked by cookie only. Logged-in users are always tracked by their user ID and are not affected by this option.'),
159 85ad3d82 Assos Assos
  );
160
161
  $form['advanced']['webform_email_address_format'] = array(
162
    '#type' => 'radios',
163
    '#title' => t('E-mail address format'),
164
    '#options' => array(
165
      'long' => t('Long format: "Example Name" &lt;name@example.com&gt;'),
166
      'short' => t('Short format: name@example.com'),
167
    ),
168 a45e4bc1 Assos Assos
    '#default_value' => webform_variable_get('webform_email_address_format'),
169 85ad3d82 Assos Assos
    '#description' => t('Most servers support the "long" format which will allow for more friendly From addresses in e-mails sent. However many Windows-based servers are unable to send in the long format. Change this option if experiencing problems sending e-mails with Webform.'),
170
  );
171
172 a45e4bc1 Assos Assos
  $form['advanced']['webform_email_address_individual'] = array(
173
    '#type' => 'radios',
174
    '#title' => t('E-mailing multiple recipients'),
175
    '#options' => array(
176
      '0' => t('Send a single e-mail to all recipients'),
177
      '1' => t('Send individual e-mails to each recipient'),
178
    ),
179
    '#default_value' => webform_variable_get('webform_email_address_individual'),
180
    '#description' => t('Individual e-mails increases privacy by not revealing the addresses of other recipients. A single e-mail to all recipients lets them use "Reply All" to communicate.'),
181
  );
182
183
  $date_format_options = array();
184
  foreach (system_get_date_types() as $type => $type_info) {
185
    $date_format_options[$type] = t('@title — @sample', array('@title' => $type_info['title'], '@sample' => format_date(REQUEST_TIME, 'custom', webform_date_format($type))));
186
  }
187
  $form['advanced']['webform_date_type'] = array(
188
    '#type' => 'select',
189
    '#title' => t('Date format'),
190
    '#options' => $date_format_options,
191
    '#default_value' => webform_variable_get('webform_date_type'),
192
    '#description' => t('Choose the format for the display of date components. Only the date portion of the format is used. Reporting and export use the short format.'),
193
  );
194
195 85ad3d82 Assos Assos
  $form['advanced']['webform_export_format'] = array(
196
    '#type' => 'radios',
197
    '#title' => t('Default export format'),
198
    '#options' => webform_export_list(),
199 a45e4bc1 Assos Assos
    '#default_value' => webform_variable_get('webform_export_format'),
200 85ad3d82 Assos Assos
  );
201
202 feca1e4a Assos Assos
  $form['advanced']['webform_csv_delimiter'] = array(
203 85ad3d82 Assos Assos
    '#type' => 'select',
204
    '#title' => t('Default export delimiter'),
205
    '#description' => t('This is the delimiter used in the CSV/TSV file when downloading Webform results. Using tabs in the export is the most reliable method for preserving non-latin characters. You may want to change this to another character depending on the program with which you anticipate importing results.'),
206 a45e4bc1 Assos Assos
    '#default_value' => webform_variable_get('webform_csv_delimiter'),
207 85ad3d82 Assos Assos
    '#options' => array(
208
      ','  => t('Comma (,)'),
209
      '\t' => t('Tab (\t)'),
210
      ';'  => t('Semicolon (;)'),
211
      ':'  => t('Colon (:)'),
212
      '|'  => t('Pipe (|)'),
213
      '.'  => t('Period (.)'),
214
      ' '  => t('Space ( )'),
215
    ),
216
  );
217
218 a45e4bc1 Assos Assos
  $form['advanced']['webform_export_wordwrap'] = array(
219
    '#type' => 'radios',
220
    '#title' => t('Export word-wrap'),
221
    '#options' => array(
222
      '0' => t('Only text containing return characters'),
223
      '1' => t('All text'),
224
    ),
225
    '#default_value' => webform_variable_get('webform_export_wordwrap'),
226
    '#description' => t('Some export formats, such as Microsoft Excel, support word-wrapped text cells.'),
227
  );
228
229 feca1e4a Assos Assos
  $form['advanced']['webform_submission_access_control'] = array(
230 85ad3d82 Assos Assos
    '#type' => 'radios',
231
    '#title' => t('Submission access control'),
232
    '#options' => array(
233
      '1' => t('Select the user roles that may submit each individual webform'),
234
      '0' => t('Disable Webform submission access control'),
235
    ),
236 a45e4bc1 Assos Assos
    '#default_value' => webform_variable_get('webform_submission_access_control'),
237 85ad3d82 Assos Assos
    '#description' => t('By default, the configuration form for each webform allows the administrator to choose which roles may submit the form. You may want to allow users to always submit the form if you are using a separate node access module to control access to webform nodes themselves.'),
238
  );
239
240 feca1e4a Assos Assos
  $form['advanced']['webform_token_access'] = array(
241 ba09eb79 Assos Assos
    '#type' => 'radios',
242
    '#title' => t('Token access'),
243
    '#options' => array(
244
      '1' => t('Allow tokens to be used in Webforms.'),
245
      '0' => t('Disable tokens in Webforms'),
246
    ),
247
    '#default_value' => webform_variable_get('webform_token_access'),
248
    '#description' => t('Tokens can be used to reveal sensitive information. Allow tokens if Webform creators are trusted.'),
249
  );
250
251 a45e4bc1 Assos Assos
  $form['advanced']['webform_email_select_max'] = array(
252
    '#type' => 'textfield',
253
    '#title' => t("Select email mapping limit"),
254
    '#default_value' => webform_variable_get('webform_email_select_max'),
255
    '#description' => t('When mapping emails addresses to a select component, limit the choice to components with less than the amount of options indicated. This is to avoid flooding the email settings form.'),
256
  );
257
258 389fb945 Assos Assos
  $form['advanced']['webform_fieldset_wrap'] = array(
259
    '#type' => 'checkbox',
260
    '#title' => t('Use fieldsets for grouped components'),
261
    '#default_value' => webform_variable_get('webform_fieldset_wrap'),
262
    '#description' => t('Components containing multiple fields, such as checkboxes and radio buttons, will be wrapped in fieldsets. This improves the accessibility of webforms and helps them conform to web standards, but may require updates to the CSS of the active theme.'),
263
  );
264
265 85ad3d82 Assos Assos
  $form = system_settings_form($form);
266
  $form['#theme'] = 'webform_admin_settings';
267
  array_unshift($form['#submit'], 'webform_admin_settings_submit');
268
269
  return $form;
270
}
271
272
/**
273
 * Submit handler for the webform_admin_settings() form.
274
 */
275
function webform_admin_settings_submit($form, &$form_state) {
276
  $disabled_components = array();
277
  foreach ($form_state['values']['components'] as $name => $enabled) {
278
    if (!$enabled) {
279
      $disabled_components[] = $name;
280
    }
281
  }
282
  // Update $form_state and let system_settings_form_submit() handle saving.
283
  $form_state['values']['webform_disabled_components'] = $disabled_components;
284
  unset($form_state['values']['components']);
285
286 a45e4bc1 Assos Assos
  // Trim out empty options in the progress bar options.
287
  $form_state['values']['webform_progressbar_style'] = array_keys(array_filter($form_state['values']['webform_progressbar_style']));
288 85ad3d82 Assos Assos
}
289
290
/**
291
 * Theme the output of the webform_admin_settings() form.
292
 */
293
function theme_webform_admin_settings($variables) {
294
  $form = $variables['form'];
295
296
  // Format the components into a table.
297
  foreach (element_children($form['components']) as $key) {
298
    $row = array();
299
    $row[] = $form['components'][$key]['#title'];
300
    $row[] = $form['components'][$key]['#description'];
301
    $form['components'][$key]['#title'] = NULL;
302
    $form['components'][$key]['#description'] = NULL;
303
    $row[] = array('data' => drupal_render($form['components'][$key]), 'align' => 'center');
304
    $rows[] = $row;
305
  }
306
  $header = array(t('Name'), t('Description'), array('data' => t('Enabled'), 'class' => array('checkbox')));
307
308
  // Create the table inside the form.
309
  $form['components']['table'] = array(
310
    '#theme' => 'table',
311
    '#header' => $header,
312
    '#rows' => $rows,
313
  );
314
315
  return drupal_render_children($form);
316
}
317
318
/**
319
 * Menu callback for admin/content/webform. Displays all webforms on the site.
320
 */
321
function webform_admin_content() {
322 76bdcd04 Assos Assos
  // Determine whether views or hard-coded tables should be used for the
323
  // webforms table.
324 a45e4bc1 Assos Assos
  if (!webform_variable_get('webform_table')) {
325
    $view = views_get_view('webform_webforms');
326
    return $view->preview('default');
327
  }
328
329 3753f249 Assos Assos
  $query = db_select('webform', 'w');
330
  $query->join('node', 'n', 'w.nid = n.nid');
331
  $query->fields('n');
332
  $nodes = $query->execute()->fetchAllAssoc('nid');
333 85ad3d82 Assos Assos
  return theme('webform_admin_content', array('nodes' => $nodes));
334
}
335
336
/**
337
 * Create a comma-separate list of content types that are webform enabled.
338
 */
339
function webform_admin_type_list() {
340 a45e4bc1 Assos Assos
  $webform_types = webform_node_types();
341 85ad3d82 Assos Assos
  $webform_type_list = '';
342
  $webform_type_count = count($webform_types);
343
  foreach ($webform_types as $n => $type) {
344 a45e4bc1 Assos Assos
    $webform_type_list .= l(node_type_get_name($type), 'node/add/' . str_replace('_', '-', $type));
345 85ad3d82 Assos Assos
    if ($n + 1 < $webform_type_count) {
346
      $webform_type_list .= $webform_type_count == 2 ? ' ' : ', ';
347
    }
348
    if ($n + 2 == $webform_type_count) {
349
      $webform_type_list .= t('or') . ' ';
350
    }
351
  }
352
353
  return $webform_type_list;
354
}
355
356
/**
357 feca1e4a Assos Assos
 * Generate a list of all webforms available on this site.
358 85ad3d82 Assos Assos
 */
359
function theme_webform_admin_content($variables) {
360
  $nodes = $variables['nodes'];
361
  $header = array(
362
    t('Title'),
363
    array('data' => t('View'), 'colspan' => '4'),
364 feca1e4a Assos Assos
    array('data' => t('Operations'), 'colspan' => '3'),
365 85ad3d82 Assos Assos
  );
366
367
  $rows = array();
368
  foreach ($nodes as $node) {
369
    $rows[] = array(
370
      l($node->title, 'node/' . $node->nid),
371
      l(t('Submissions'), 'node/' . $node->nid . '/webform-results'),
372
      l(t('Analysis'), 'node/' . $node->nid . '/webform-results/analysis'),
373
      l(t('Table'), 'node/' . $node->nid . '/webform-results/table'),
374
      l(t('Download'), 'node/' . $node->nid . '/webform-results/download'),
375
      node_access('update', $node) ? l(t('Edit'), 'node/' . $node->nid . '/edit') : '',
376 3753f249 Assos Assos
      node_access('update', $node) ? l(t('Components'), 'node/' . $node->nid . '/webform') : '',
377 85ad3d82 Assos Assos
      user_access('delete all webform submissions') ? l(t('Clear'), 'node/' . $node->nid . '/webform-results/clear') : '',
378
    );
379
  }
380
381
  if (empty($rows)) {
382 a45e4bc1 Assos Assos
    $webform_types = webform_node_types();
383 85ad3d82 Assos Assos
    if (empty($webform_types)) {
384
      $message = t('Webform is currently not enabled on any content types.') . ' ' . t('Visit the <a href="!url">Webform settings</a> page and enable Webform on at least one content type.', array('!url' => url('admin/config/content/webform')));
385
    }
386
    else {
387
      $webform_type_list = webform_admin_type_list();
388
      $message = t('There are currently no webforms on your site. Create a !types piece of content.', array('!types' => $webform_type_list));
389
    }
390
391
    $rows[] = array(
392
      array('data' => $message, 'colspan' => 7),
393
    );
394
  }
395
396
  return theme('table', array('header' => $header, 'rows' => $rows));
397
}