Projet

Général

Profil

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

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

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
  $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 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
  $form['email']['webform_default_from_name']  = array(
50
    '#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
  $form['email']['webform_default_subject']  = array(
57
    '#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 a45e4bc1 Assos Assos
  $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 85ad3d82 Assos Assos
  $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 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
  $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 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 a45e4bc1 Assos Assos
  $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 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 a45e4bc1 Assos Assos
  $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 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
  $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 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 85ad3d82 Assos Assos
  $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 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 a45e4bc1 Assos Assos
  $form['advanced']['webform_email_select_max'] = array(
241
    '#type' => 'textfield',
242
    '#title' => t("Select email mapping limit"),
243
    '#default_value' => webform_variable_get('webform_email_select_max'),
244
    '#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.'),
245
  );
246
247 85ad3d82 Assos Assos
  $form = system_settings_form($form);
248
  $form['#theme'] = 'webform_admin_settings';
249
  array_unshift($form['#submit'], 'webform_admin_settings_submit');
250
251
  return $form;
252
}
253
254
/**
255
 * Submit handler for the webform_admin_settings() form.
256
 */
257
function webform_admin_settings_submit($form, &$form_state) {
258
  $disabled_components = array();
259
  foreach ($form_state['values']['components'] as $name => $enabled) {
260
    if (!$enabled) {
261
      $disabled_components[] = $name;
262
    }
263
  }
264
  // Update $form_state and let system_settings_form_submit() handle saving.
265
  $form_state['values']['webform_disabled_components'] = $disabled_components;
266
  unset($form_state['values']['components']);
267
268 a45e4bc1 Assos Assos
  // Trim out empty options in the progress bar options.
269
  $form_state['values']['webform_progressbar_style'] = array_keys(array_filter($form_state['values']['webform_progressbar_style']));
270 85ad3d82 Assos Assos
}
271
272
/**
273
 * Theme the output of the webform_admin_settings() form.
274
 */
275
function theme_webform_admin_settings($variables) {
276
  $form = $variables['form'];
277
278
  // Format the components into a table.
279
  foreach (element_children($form['components']) as $key) {
280
    $row = array();
281
    $row[] = $form['components'][$key]['#title'];
282
    $row[] = $form['components'][$key]['#description'];
283
    $form['components'][$key]['#title'] = NULL;
284
    $form['components'][$key]['#description'] = NULL;
285
    $row[] = array('data' => drupal_render($form['components'][$key]), 'align' => 'center');
286
    $rows[] = $row;
287
  }
288
  $header = array(t('Name'), t('Description'), array('data' => t('Enabled'), 'class' => array('checkbox')));
289
290
  // Create the table inside the form.
291
  $form['components']['table'] = array(
292
    '#theme' => 'table',
293
    '#header' => $header,
294
    '#rows' => $rows,
295
  );
296
297
  return drupal_render_children($form);
298
}
299
300
/**
301
 * Menu callback for admin/content/webform. Displays all webforms on the site.
302
 */
303
function webform_admin_content() {
304 a45e4bc1 Assos Assos
  // Determine whether views or hard-coded tables should be used for the webforms table.
305
  if (!webform_variable_get('webform_table')) {
306
    $view = views_get_view('webform_webforms');
307
    return $view->preview('default');
308
  }
309
310 3753f249 Assos Assos
  $query = db_select('webform', 'w');
311
  $query->join('node', 'n', 'w.nid = n.nid');
312
  $query->fields('n');
313
  $nodes = $query->execute()->fetchAllAssoc('nid');
314 85ad3d82 Assos Assos
  return theme('webform_admin_content', array('nodes' => $nodes));
315
}
316
317
/**
318
 * Create a comma-separate list of content types that are webform enabled.
319
 */
320
function webform_admin_type_list() {
321 a45e4bc1 Assos Assos
  $webform_types = webform_node_types();
322 85ad3d82 Assos Assos
  $webform_type_list = '';
323
  $webform_type_count = count($webform_types);
324
  foreach ($webform_types as $n => $type) {
325 a45e4bc1 Assos Assos
    $webform_type_list .= l(node_type_get_name($type), 'node/add/' . str_replace('_', '-', $type));
326 85ad3d82 Assos Assos
    if ($n + 1 < $webform_type_count) {
327
      $webform_type_list .= $webform_type_count == 2 ? ' ' : ', ';
328
    }
329
    if ($n + 2 == $webform_type_count) {
330
      $webform_type_list .= t('or') . ' ';
331
    }
332
  }
333
334
  return $webform_type_list;
335
}
336
337
/**
338
 * Generate a list of all webforms avaliable on this site.
339
 */
340
function theme_webform_admin_content($variables) {
341
  $nodes = $variables['nodes'];
342
  $header = array(
343
    t('Title'),
344
    array('data' => t('View'), 'colspan' => '4'),
345 3753f249 Assos Assos
    array('data' => t('Operations'), 'colspan' => '3')
346 85ad3d82 Assos Assos
  );
347
348
  $rows = array();
349
  foreach ($nodes as $node) {
350
    $rows[] = array(
351
      l($node->title, 'node/' . $node->nid),
352
      l(t('Submissions'), 'node/' . $node->nid . '/webform-results'),
353
      l(t('Analysis'), 'node/' . $node->nid . '/webform-results/analysis'),
354
      l(t('Table'), 'node/' . $node->nid . '/webform-results/table'),
355
      l(t('Download'), 'node/' . $node->nid . '/webform-results/download'),
356
      node_access('update', $node) ? l(t('Edit'), 'node/' . $node->nid . '/edit') : '',
357 3753f249 Assos Assos
      node_access('update', $node) ? l(t('Components'), 'node/' . $node->nid . '/webform') : '',
358 85ad3d82 Assos Assos
      user_access('delete all webform submissions') ? l(t('Clear'), 'node/' . $node->nid . '/webform-results/clear') : '',
359
    );
360
  }
361
362
  if (empty($rows)) {
363 a45e4bc1 Assos Assos
    $webform_types = webform_node_types();
364 85ad3d82 Assos Assos
    if (empty($webform_types)) {
365
      $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')));
366
    }
367
    else {
368
      $webform_type_list = webform_admin_type_list();
369
      $message = t('There are currently no webforms on your site. Create a !types piece of content.', array('!types' => $webform_type_list));
370
    }
371
372
    $rows[] = array(
373
      array('data' => $message, 'colspan' => 7),
374
    );
375
  }
376
377
  return theme('table', array('header' => $header, 'rows' => $rows));
378
}