Projet

Général

Profil

Paste
Télécharger (15,7 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / webform / includes / webform.admin.inc @ 651307cd

1
<?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
  $form['components'] = array('#tree' => TRUE);
24
  $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
  $form['email']['webform_default_from_address']  = array(
43
    '#type' => 'textfield',
44
    '#title' => t('From address'),
45
    '#default_value' => webform_variable_get('webform_default_from_address'),
46
    '#description' => t('The default sender address for emailed webform results; often the e-mail address of the maintainer of your forms.'),
47
  );
48

    
49
  $form['email']['webform_default_from_name']  = array(
50
    '#type' => 'textfield',
51
    '#title' => t('From name'),
52
    '#default_value' => webform_variable_get('webform_default_from_name'),
53
    '#description' => t('The default sender name which is used along with the default from address.'),
54
  );
55

    
56
  $form['email']['webform_default_subject']  = array(
57
    '#type' => 'textfield',
58
    '#title' => t('Default subject'),
59
    '#default_value' => webform_variable_get('webform_default_subject'),
60
    '#description' => t('The default subject line of any e-mailed results.'),
61
  );
62

    
63
  $form['email']['webform_email_replyto']  = array(
64
    '#type' => 'checkbox',
65
    '#title' => t('Use Reply-To header'),
66
    '#default_value' => webform_variable_get('webform_email_replyto'),
67
    '#description' => t('Sends all e-mail from the domain of the default address above and sets the "Reply-To" header to the actual sender. Helps prevent e-mail from being flagged as spam.'),
68
  );
69

    
70
  $form['email']['webform_email_html_capable']  = array(
71
    '#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
  $form['email']['webform_default_format']  = array(
78
    '#type' => 'radios',
79
    '#title' => t('Format'),
80
    '#options' => array(
81
      0 => t('Plain text'),
82
      1 => t('HTML'),
83
    ),
84
    '#default_value' => webform_variable_get('webform_default_format'),
85
    '#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
    '#states' => array(
87
      'visible' => array(
88
        ':input[name="webform_email_html_capable"]' => array('checked' => TRUE),
89
      ),
90
    ),
91
  );
92

    
93
  $form['email']['webform_format_override']  = array(
94
    '#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
    '#default_value' => webform_variable_get('webform_format_override'),
101
    '#description' => t('Force all webform e-mails to be sent in the default format.'),
102
    '#states' => array(
103
      'visible' => array(
104
        ':input[name="webform_email_html_capable"]' => array('checked' => TRUE),
105
      ),
106
    ),
107
  );
108

    
109
  $form['progressbar'] = array(
110
    '#type' => 'fieldset',
111
    '#title' => t('Progress bar'),
112
    '#collapsible' => TRUE,
113
    '#collapsed' => TRUE,
114
  );
115
  $form['progressbar']['webform_progressbar_style']  = array(
116
    '#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

    
141
  $form['advanced'] = array(
142
    '#type' => 'fieldset',
143
    '#title' => t('Advanced options'),
144
    '#collapsible' => TRUE,
145
    '#collapsed' => TRUE,
146
    '#weight' => 20,
147
  );
148

    
149
  $form['advanced']['webform_tracking_mode']  = array(
150
    '#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
  );
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
    '#default_value' => webform_variable_get('webform_email_address_format'),
169
    '#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
  $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
  $form['advanced']['webform_export_format'] = array(
196
    '#type' => 'radios',
197
    '#title' => t('Default export format'),
198
    '#options' => webform_export_list(),
199
    '#default_value' => webform_variable_get('webform_export_format'),
200
  );
201

    
202
  $form['advanced']['webform_csv_delimiter']  = array(
203
    '#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
    '#default_value' => webform_variable_get('webform_csv_delimiter'),
207
    '#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
  $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
  $form['advanced']['webform_submission_access_control']  = array(
230
    '#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
    '#default_value' => webform_variable_get('webform_submission_access_control'),
237
    '#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
  $form['advanced']['webform_token_access']  = array(
241
    '#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
  $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
  $form = system_settings_form($form);
259
  $form['#theme'] = 'webform_admin_settings';
260
  array_unshift($form['#submit'], 'webform_admin_settings_submit');
261

    
262
  return $form;
263
}
264

    
265
/**
266
 * Submit handler for the webform_admin_settings() form.
267
 */
268
function webform_admin_settings_submit($form, &$form_state) {
269
  $disabled_components = array();
270
  foreach ($form_state['values']['components'] as $name => $enabled) {
271
    if (!$enabled) {
272
      $disabled_components[] = $name;
273
    }
274
  }
275
  // Update $form_state and let system_settings_form_submit() handle saving.
276
  $form_state['values']['webform_disabled_components'] = $disabled_components;
277
  unset($form_state['values']['components']);
278

    
279
  // Trim out empty options in the progress bar options.
280
  $form_state['values']['webform_progressbar_style'] = array_keys(array_filter($form_state['values']['webform_progressbar_style']));
281
}
282

    
283
/**
284
 * Theme the output of the webform_admin_settings() form.
285
 */
286
function theme_webform_admin_settings($variables) {
287
  $form = $variables['form'];
288

    
289
  // Format the components into a table.
290
  foreach (element_children($form['components']) as $key) {
291
    $row = array();
292
    $row[] = $form['components'][$key]['#title'];
293
    $row[] = $form['components'][$key]['#description'];
294
    $form['components'][$key]['#title'] = NULL;
295
    $form['components'][$key]['#description'] = NULL;
296
    $row[] = array('data' => drupal_render($form['components'][$key]), 'align' => 'center');
297
    $rows[] = $row;
298
  }
299
  $header = array(t('Name'), t('Description'), array('data' => t('Enabled'), 'class' => array('checkbox')));
300

    
301
  // Create the table inside the form.
302
  $form['components']['table'] = array(
303
    '#theme' => 'table',
304
    '#header' => $header,
305
    '#rows' => $rows,
306
  );
307

    
308
  return drupal_render_children($form);
309
}
310

    
311
/**
312
 * Menu callback for admin/content/webform. Displays all webforms on the site.
313
 */
314
function webform_admin_content() {
315
  // Determine whether views or hard-coded tables should be used for the webforms table.
316
  if (!webform_variable_get('webform_table')) {
317
    $view = views_get_view('webform_webforms');
318
    return $view->preview('default');
319
  }
320

    
321
  $query = db_select('webform', 'w');
322
  $query->join('node', 'n', 'w.nid = n.nid');
323
  $query->fields('n');
324
  $nodes = $query->execute()->fetchAllAssoc('nid');
325
  return theme('webform_admin_content', array('nodes' => $nodes));
326
}
327

    
328
/**
329
 * Create a comma-separate list of content types that are webform enabled.
330
 */
331
function webform_admin_type_list() {
332
  $webform_types = webform_node_types();
333
  $webform_type_list = '';
334
  $webform_type_count = count($webform_types);
335
  foreach ($webform_types as $n => $type) {
336
    $webform_type_list .= l(node_type_get_name($type), 'node/add/' . str_replace('_', '-', $type));
337
    if ($n + 1 < $webform_type_count) {
338
      $webform_type_list .= $webform_type_count == 2 ? ' ' : ', ';
339
    }
340
    if ($n + 2 == $webform_type_count) {
341
      $webform_type_list .= t('or') . ' ';
342
    }
343
  }
344

    
345
  return $webform_type_list;
346
}
347

    
348
/**
349
 * Generate a list of all webforms avaliable on this site.
350
 */
351
function theme_webform_admin_content($variables) {
352
  $nodes = $variables['nodes'];
353
  $header = array(
354
    t('Title'),
355
    array('data' => t('View'), 'colspan' => '4'),
356
    array('data' => t('Operations'), 'colspan' => '3')
357
  );
358

    
359
  $rows = array();
360
  foreach ($nodes as $node) {
361
    $rows[] = array(
362
      l($node->title, 'node/' . $node->nid),
363
      l(t('Submissions'), 'node/' . $node->nid . '/webform-results'),
364
      l(t('Analysis'), 'node/' . $node->nid . '/webform-results/analysis'),
365
      l(t('Table'), 'node/' . $node->nid . '/webform-results/table'),
366
      l(t('Download'), 'node/' . $node->nid . '/webform-results/download'),
367
      node_access('update', $node) ? l(t('Edit'), 'node/' . $node->nid . '/edit') : '',
368
      node_access('update', $node) ? l(t('Components'), 'node/' . $node->nid . '/webform') : '',
369
      user_access('delete all webform submissions') ? l(t('Clear'), 'node/' . $node->nid . '/webform-results/clear') : '',
370
    );
371
  }
372

    
373
  if (empty($rows)) {
374
    $webform_types = webform_node_types();
375
    if (empty($webform_types)) {
376
      $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')));
377
    }
378
    else {
379
      $webform_type_list = webform_admin_type_list();
380
      $message = t('There are currently no webforms on your site. Create a !types piece of content.', array('!types' => $webform_type_list));
381
    }
382

    
383
    $rows[] = array(
384
      array('data' => $message, 'colspan' => 7),
385
    );
386
  }
387

    
388
  return theme('table', array('header' => $header, 'rows' => $rows));
389
}