diff --git a/components/date.inc b/components/date.inc index 40d6ded..f9b5fb5 100644 --- a/components/date.inc +++ b/components/date.inc @@ -414,7 +414,7 @@ function _webform_csv_headers_date($component, $export_options) { $header = array(); $header[0] = ''; $header[1] = ''; - $header[2] = $component['name']; + $header[2] = $component['export_name']; return $header; } diff --git a/components/email.inc b/components/email.inc index 9a65e7f..beee65c 100644 --- a/components/email.inc +++ b/components/email.inc @@ -273,7 +273,7 @@ function _webform_csv_headers_email($component, $export_options) { $header = array(); $header[0] = ''; $header[1] = ''; - $header[2] = $component['name']; + $header[2] = $component['export_name']; return $header; } diff --git a/components/file.inc b/components/file.inc index 4a5654f..25dd0f4 100644 --- a/components/file.inc +++ b/components/file.inc @@ -466,7 +466,7 @@ function _webform_csv_headers_file($component, $export_options) { $header = array(); // Two columns in header. $header[0] = array('', ''); - $header[1] = array($component['name'], ''); + $header[1] = array($component['export_name'], ''); $header[2] = array(t('Name'), t('Filesize (KB)')); return $header; } diff --git a/components/grid.inc b/components/grid.inc index 0ddcf11..9ca9ef6 100644 --- a/components/grid.inc +++ b/components/grid.inc @@ -363,7 +363,7 @@ function _webform_table_grid($component, $value) { function _webform_csv_headers_grid($component, $export_options) { $header = array(); $header[0] = array(''); - $header[1] = array($component['name']); + $header[1] = array($component['export_name']); $items = _webform_select_options_from_text($component['extra']['questions'], TRUE); $count = 0; foreach ($items as $key => $item) { @@ -373,7 +373,7 @@ function _webform_csv_headers_grid($component, $export_options) { $header[1][] = ''; } // The value for this option. - $header[2][] = $item; + $header[2][] = $export_options['header_keys'] ? $key : $item; $count++; } diff --git a/components/hidden.inc b/components/hidden.inc index e173c29..7e9d49a 100644 --- a/components/hidden.inc +++ b/components/hidden.inc @@ -161,13 +161,13 @@ function _webform_table_hidden($component, $value) { } /** - * Implements _webform_csv_data_component(). + * Implements _webform_csv_headers_component(). */ function _webform_csv_headers_hidden($component, $export_options) { $header = array(); $header[0] = ''; $header[1] = ''; - $header[2] = $component['name']; + $header[2] = $component['export_name']; return $header; } diff --git a/components/number.inc b/components/number.inc index 00bc7ab..8c77a6d 100644 --- a/components/number.inc +++ b/components/number.inc @@ -501,7 +501,7 @@ function _webform_csv_headers_number($component, $export_options) { $header = array(); $header[0] = ''; $header[1] = ''; - $header[2] = $component['name']; + $header[2] = $component['export_name']; return $header; } diff --git a/components/select.inc b/components/select.inc index aeeb41d..9b82170 100644 --- a/components/select.inc +++ b/components/select.inc @@ -705,10 +705,15 @@ function _webform_csv_headers_select($component, $export_options) { if ($component['extra']['multiple'] && $export_options['select_format'] == 'separate') { $headers[0][] = ''; - $headers[1][] = $component['name']; + $headers[1][] = $component['export_name']; $items = _webform_select_options($component, TRUE, FALSE); if ($component['extra']['other_option']) { - $other_label = !empty($component['extra']['other_text']) ? check_plain($component['extra']['other_text']) : t('Other...'); + if ($export_options['header_keys']) { + $other_label = $component['form_key'] . '_other'; + } + else { + $other_label = !empty($component['extra']['other_text']) ? check_plain($component['extra']['other_text']) : t('Other...'); + } $items[$other_label] = $other_label; } $count = 0; @@ -730,7 +735,7 @@ function _webform_csv_headers_select($component, $export_options) { else { $headers[0][] = ''; $headers[1][] = ''; - $headers[2][] = $component['name']; + $headers[2][] = $component['export_name']; } return $headers; } diff --git a/components/textarea.inc b/components/textarea.inc index eb56ec7..671a3ec 100644 --- a/components/textarea.inc +++ b/components/textarea.inc @@ -205,7 +205,7 @@ function _webform_csv_headers_textarea($component, $export_options) { $header = array(); $header[0] = ''; $header[1] = ''; - $header[2] = $component['name']; + $header[2] = $component['export_name']; return $header; } diff --git a/components/textfield.inc b/components/textfield.inc index 11e11ab..5e69ad6 100644 --- a/components/textfield.inc +++ b/components/textfield.inc @@ -242,7 +242,7 @@ function _webform_csv_headers_textfield($component, $export_options) { $header = array(); $header[0] = ''; $header[1] = ''; - $header[2] = $component['name']; + $header[2] = $component['export_name']; return $header; } diff --git a/components/time.inc b/components/time.inc index f1489a9..cfe0a9a 100644 --- a/components/time.inc +++ b/components/time.inc @@ -374,7 +374,7 @@ function _webform_csv_headers_time($component, $export_options) { $header = array(); $header[0] = ''; $header[1] = ''; - $header[2] = $component['name']; + $header[2] = $component['export_name']; return $header; } diff --git a/includes/webform.report.inc b/includes/webform.report.inc index 8ceb920..3123f3e 100644 --- a/includes/webform.report.inc +++ b/includes/webform.report.inc @@ -341,6 +341,17 @@ function webform_results_download_form($form, &$form_state, $node) { ), ); + $form['header_keys'] = array( + '#type' => 'radios', + '#title' => t('Column header format'), + '#options' => array( + 0 => t('Label'), + 1 => t('Field Key'), + ), + '#default_value' => isset($form_state['values']['header_keys']) ? $form_state['values']['header_keys'] : 0, + '#description' => t('Choose whether to show the label or field key in each column header.'), + ); + $form['select_options'] = array( '#type' => 'fieldset', '#title' => t('Select list options'), @@ -515,6 +526,7 @@ function webform_results_download_form_submit(&$form, &$form_state) { $options = array( 'delimiter' => $form_state['values']['delimiter'], 'components' => array_keys(array_filter($form_state['values']['components'])), + 'header_keys' => $form_state['values']['header_keys'], 'select_keys' => $form_state['values']['select_keys'], 'select_format' => $form_state['values']['select_format'], 'range_type' => $form_state['values']['range']['range_type'], @@ -691,6 +703,7 @@ function webform_results_export($node, $format = 'delimited', $options = array() $options = array( 'delimiter' => variable_get('webform_csv_delimiter', '\t'), 'components' => array_merge(array_keys($submission_information), array_keys(webform_component_list($node, 'csv', TRUE))), + 'header_keys' => 0, 'select_keys' => 0, 'select_format' => 'separate', 'range_type' => 'all', @@ -715,8 +728,16 @@ function webform_results_export($node, $format = 'delimited', $options = array() $header[2] = $header[1] = $header[0] = count($submission_information) ? array_fill(0, count($submission_information), '') : array(); if (count($submission_information)) { $header[0][0] = $node->title; - $header[1][0] = t('Submission Details'); - foreach (array_values($submission_information) as $column => $label) { + + if ($options['header_keys']) { + $header[1][0] = t('submission_details'); + $submission_information_headers = array_keys($submission_information); + } + else { + $header[1][0] = t('Submission Details'); + $submission_information_headers = array_values($submission_information); + } + foreach ($submission_information_headers as $column => $label) { $header[2][$column] = $label; } } @@ -728,6 +749,12 @@ function webform_results_export($node, $format = 'delimited', $options = array() // Let each component determine its headers. if (webform_component_feature($component['type'], 'csv')) { + if ($options['header_keys']) { + $component['export_name'] = $component['form_key']; + } + else { + $component['export_name'] = $component['name']; + } $component_header = (array) webform_component_invoke($component['type'], 'csv_headers', $component, $options); $header[0] = array_merge($header[0], (array) $component_header[0]); $header[1] = array_merge($header[1], (array) $component_header[1]); diff --git a/webform.api.php b/webform.api.php index 7a21ba4..82702b3 100644 --- a/webform.api.php +++ b/webform.api.php @@ -320,9 +320,9 @@ function hook_webform_component_delete($component) { * - spam_analysis * - group * - * Note that most of these features do not indicate the default state, but + * Note that most of these features do not indicate the default state, but * determine if the component can have this property at all. Setting - * "required" to TRUE does not mean that a component's fields will always be + * "required" to TRUE does not mean that a component's fields will always be * required, but instead give the option to the administrator to choose the * requiredness. See the example implementation for details on how these * features may be set. @@ -398,7 +398,7 @@ function hook_webform_component_info() { // Defaults to TRUE. 'conditional' => TRUE, - // If this component allows other components to be grouped within it + // If this component allows other components to be grouped within it // (like a fieldset or tabs). Defaults to FALSE. 'group' => FALSE, @@ -612,11 +612,11 @@ function _webform_display_component($component, $value, $format = 'html') { /** * A hook for changing the input values before saving to the database. * - * Webform expects a component to consist of a single field, or a single array + * Webform expects a component to consist of a single field, or a single array * of fields. If you have a component that requires a deeper form tree - * you must flatten the data into a single array using this callback + * you must flatten the data into a single array using this callback * or by setting #parents on each field to avoid data loss and/or unexpected - * behavior. + * behavior. * * Note that Webform will save the result of this function directly into the * database. @@ -809,7 +809,7 @@ function _webform_table_component($component, $value) { function _webform_csv_headers_component($component, $export_options) { $header = array(); $header[0] = array(''); - $header[1] = array($component['name']); + $header[1] = array($component['export_name']); $items = _webform_component_options($component['extra']['questions']); $count = 0; foreach ($items as $key => $item) {