Projet

Général

Profil

Paste
Télécharger (11,5 ko) Statistiques
| Branche: | Révision:

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

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
  $node_types = node_type_get_names();
15
  $form['node_types'] = array(
16
    '#type' => 'checkboxes',
17
    '#title' => t('Webform-enabled content types'),
18
    '#description' => t('Webform allows you to enable the webform components for any content type.  Choose the types on which you would like to associate webform components.'),
19
    '#options' => $node_types,
20
    '#default_value' => webform_variable_get('webform_node_types'),
21
  );
22

    
23
  $form['components'] = array(
24
    '#type' => 'fieldset',
25
    '#title' => t('Available components'),
26
    '#collapsible' => TRUE,
27
    '#collapsed' => FALSE,
28
    '#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.'),
29
  );
30

    
31
  // Add each component to the form:
32
  $form['components'] = array('#tree' => TRUE);
33
  $component_types = webform_components(TRUE);
34
  foreach ($component_types as $key => $component) {
35
    $form['components'][$key] = array(
36
      '#title' => $component['label'],
37
      '#description' => $component['description'],
38
      '#type' => 'checkbox',
39
      '#return_value' => 1,
40
      '#default_value' => $component['enabled'],
41
    );
42
  }
43

    
44
  $form['email'] = array(
45
    '#type' => 'fieldset',
46
    '#title' => t('Default e-mail values'),
47
    '#collapsible' => TRUE,
48
    '#collapsed' => FALSE,
49
  );
50

    
51
  $form['email']['webform_default_from_address']  = array(
52
    '#type' => 'textfield',
53
    '#title' => t('From address'),
54
    '#default_value' => variable_get('webform_default_from_address', variable_get('site_mail', ini_get('sendmail_from'))),
55
    '#description' => t('The default sender address for emailed webform results; often the e-mail address of the maintainer of your forms.'),
56
  );
57

    
58
  $form['email']['webform_default_from_name']  = array(
59
    '#type' => 'textfield',
60
    '#title' => t('From name'),
61
    '#default_value' => variable_get('webform_default_from_name', variable_get('site_name', '')),
62
    '#description' => t('The default sender name which is used along with the default from address.'),
63
  );
64

    
65
  $form['email']['webform_default_subject']  = array(
66
    '#type' => 'textfield',
67
    '#title' => t('Default subject'),
68
    '#default_value' => variable_get('webform_default_subject', t('Form submission from: %title')),
69
    '#description' => t('The default subject line of any e-mailed results.'),
70
  );
71

    
72
  $form['email']['webform_default_format']  = array(
73
    '#type' => 'radios',
74
    '#title' => t('Format'),
75
    '#options' => array(
76
      0 => t('Plain text'),
77
      1 => t('HTML'),
78
    ),
79
    '#default_value' => variable_get('webform_default_format', 0),
80
    '#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.'),
81
    '#access' => webform_email_html_capable(),
82
  );
83

    
84
  $form['email']['webform_format_override']  = array(
85
    '#type' => 'radios',
86
    '#title' => t('Format override'),
87
    '#options' => array(
88
      0 => t('Per-webform configuration of e-mail format'),
89
      1 => t('Send all e-mails in the default format'),
90
    ),
91
    '#default_value' => variable_get('webform_format_override', 0),
92
    '#description' => t('Force all webform e-mails to be sent in the default format.'),
93
    '#access' => webform_email_html_capable(),
94
  );
95

    
96
  $form['advanced'] = array(
97
    '#type' => 'fieldset',
98
    '#title' => t('Advanced options'),
99
    '#collapsible' => TRUE,
100
    '#collapsed' => TRUE,
101
  );
102

    
103
  $form['advanced']['webform_use_cookies']  = array(
104
    '#type' => 'checkbox',
105
    '#checked_value' => 1,
106
    '#title' => t('Allow cookies for tracking submissions'),
107
    '#default_value' => variable_get('webform_use_cookies', 0),
108
    '#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. This feature is not needed for limiting submissions per user, though it can increase accuracy in some situations. Besides cookies, Webform also uses IP addresses and site usernames to prevent repeated submissions.'),
109
  );
110

    
111
  $form['advanced']['webform_search_index']  = array(
112
    '#type' => 'checkbox',
113
    '#checked_value' => 1,
114
    '#title' => t('Include webform forms in search index'),
115
    '#default_value' => variable_get('webform_search_index', 1),
116
    '#description' => t('When selected, all Webform nodes will have their form components indexed by the search engine.'),
117
    '#access' => module_exists('search'),
118
  );
119

    
120
  $form['advanced']['webform_email_address_format'] = array(
121
    '#type' => 'radios',
122
    '#title' => t('E-mail address format'),
123
    '#options' => array(
124
      'long' => t('Long format: "Example Name" &lt;name@example.com&gt;'),
125
      'short' => t('Short format: name@example.com'),
126
    ),
127
    '#default_value' => variable_get('webform_email_address_format', 'long'),
128
    '#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.'),
129
  );
130

    
131
  $form['advanced']['webform_export_format'] = array(
132
    '#type' => 'radios',
133
    '#title' => t('Default export format'),
134
    '#options' => webform_export_list(),
135
    '#default_value' => variable_get('webform_export_format', 'delimited'),
136
  );
137

    
138
  $form['advanced']['webform_csv_delimiter']  = array(
139
    '#type' => 'select',
140
    '#title' => t('Default export delimiter'),
141
    '#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.'),
142
    '#default_value' => variable_get('webform_csv_delimiter', '\t'),
143
    '#options' => array(
144
      ','  => t('Comma (,)'),
145
      '\t' => t('Tab (\t)'),
146
      ';'  => t('Semicolon (;)'),
147
      ':'  => t('Colon (:)'),
148
      '|'  => t('Pipe (|)'),
149
      '.'  => t('Period (.)'),
150
      ' '  => t('Space ( )'),
151
    ),
152
  );
153

    
154
  $form['advanced']['webform_submission_access_control']  = array(
155
    '#type' => 'radios',
156
    '#title' => t('Submission access control'),
157
    '#options' => array(
158
      '1' => t('Select the user roles that may submit each individual webform'),
159
      '0' => t('Disable Webform submission access control'),
160
    ),
161
    '#default_value' => variable_get('webform_submission_access_control', 1),
162
    '#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.'),
163
  );
164

    
165
  $form = system_settings_form($form);
166
  $form['#theme'] = 'webform_admin_settings';
167
  array_unshift($form['#submit'], 'webform_admin_settings_submit');
168

    
169
  return $form;
170
}
171

    
172
/**
173
 * Submit handler for the webform_admin_settings() form.
174
 */
175
function webform_admin_settings_submit($form, &$form_state) {
176
  $disabled_components = array();
177
  foreach ($form_state['values']['components'] as $name => $enabled) {
178
    if (!$enabled) {
179
      $disabled_components[] = $name;
180
    }
181
  }
182
  // Update $form_state and let system_settings_form_submit() handle saving.
183
  $form_state['values']['webform_disabled_components'] = $disabled_components;
184
  unset($form_state['values']['components']);
185

    
186
  // Change the name of the node type variable and clean it up.
187
  $form_state['values']['webform_node_types'] = array_keys(array_filter($form_state['values']['node_types']));
188
  unset($form_state['values']['node_types']);
189
}
190

    
191
/**
192
 * Theme the output of the webform_admin_settings() form.
193
 */
194
function theme_webform_admin_settings($variables) {
195
  $form = $variables['form'];
196

    
197
  // Format the components into a table.
198
  foreach (element_children($form['components']) as $key) {
199
    $row = array();
200
    $row[] = $form['components'][$key]['#title'];
201
    $row[] = $form['components'][$key]['#description'];
202
    $form['components'][$key]['#title'] = NULL;
203
    $form['components'][$key]['#description'] = NULL;
204
    $row[] = array('data' => drupal_render($form['components'][$key]), 'align' => 'center');
205
    $rows[] = $row;
206
  }
207
  $header = array(t('Name'), t('Description'), array('data' => t('Enabled'), 'class' => array('checkbox')));
208

    
209
  // Create the table inside the form.
210
  $form['components']['table'] = array(
211
    '#theme' => 'table',
212
    '#header' => $header,
213
    '#rows' => $rows,
214
  );
215

    
216
  return drupal_render_children($form);
217
}
218

    
219
/**
220
 * Menu callback for admin/content/webform. Displays all webforms on the site.
221
 */
222
function webform_admin_content() {
223
  $query = db_select('webform', 'w');
224
  $query->join('node', 'n', 'w.nid = n.nid');
225
  $query->fields('n');
226
  $nodes = $query->execute()->fetchAllAssoc('nid');
227
  return theme('webform_admin_content', array('nodes' => $nodes));
228
}
229

    
230
/**
231
 * Create a comma-separate list of content types that are webform enabled.
232
 */
233
function webform_admin_type_list() {
234
  $webform_types = webform_variable_get('webform_node_types');
235
  $webform_type_list = '';
236
  $webform_type_count = count($webform_types);
237
  foreach ($webform_types as $n => $type) {
238
    $webform_type_list .= l(node_type_get_name($type), 'node/add/' . $type);
239
    if ($n + 1 < $webform_type_count) {
240
      $webform_type_list .= $webform_type_count == 2 ? ' ' : ', ';
241
    }
242
    if ($n + 2 == $webform_type_count) {
243
      $webform_type_list .= t('or') . ' ';
244
    }
245
  }
246

    
247
  return $webform_type_list;
248
}
249

    
250
/**
251
 * Generate a list of all webforms avaliable on this site.
252
 */
253
function theme_webform_admin_content($variables) {
254
  $nodes = $variables['nodes'];
255
  $header = array(
256
    t('Title'),
257
    array('data' => t('View'), 'colspan' => '4'),
258
    array('data' => t('Operations'), 'colspan' => '3')
259
  );
260

    
261
  $rows = array();
262
  foreach ($nodes as $node) {
263
    $rows[] = array(
264
      l($node->title, 'node/' . $node->nid),
265
      l(t('Submissions'), 'node/' . $node->nid . '/webform-results'),
266
      l(t('Analysis'), 'node/' . $node->nid . '/webform-results/analysis'),
267
      l(t('Table'), 'node/' . $node->nid . '/webform-results/table'),
268
      l(t('Download'), 'node/' . $node->nid . '/webform-results/download'),
269
      node_access('update', $node) ? l(t('Edit'), 'node/' . $node->nid . '/edit') : '',
270
      node_access('update', $node) ? l(t('Components'), 'node/' . $node->nid . '/webform') : '',
271
      user_access('delete all webform submissions') ? l(t('Clear'), 'node/' . $node->nid . '/webform-results/clear') : '',
272
    );
273
  }
274

    
275
  if (empty($rows)) {
276
    $webform_types = webform_variable_get('webform_node_types');
277
    if (empty($webform_types)) {
278
      $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')));
279
    }
280
    else {
281
      $webform_type_list = webform_admin_type_list();
282
      $message = t('There are currently no webforms on your site. Create a !types piece of content.', array('!types' => $webform_type_list));
283
    }
284

    
285
    $rows[] = array(
286
      array('data' => $message, 'colspan' => 7),
287
    );
288
  }
289

    
290
  return theme('table', array('header' => $header, 'rows' => $rows));
291
}