You are here

function webform_results_download in Webform 7.3

Same name and namespace in other branches
  1. 5.2 webform_report.inc \webform_results_download()
  2. 6.3 includes/webform.report.inc \webform_results_download()
  3. 6.2 webform_report.inc \webform_results_download()
  4. 7.4 includes/webform.report.inc \webform_results_download()

Send a generated webform results file to the user's browser.

Parameters

$node: The webform node.

$export_info: Export information array retrieved from webform_results_export().

1 call to webform_results_download()
webform_results_download_form_submit in includes/webform.report.inc
Validate handler for webform_results_download_form().

File

includes/webform.report.inc, line 837
This file includes helper functions for creating reports for webform.module.

Code

function webform_results_download($node, $export_info) {
  global $user;

  // $exporter, $file_name, $row_count
  $export_name = _webform_safe_name($node->title);
  $export_info['exporter']
    ->set_headers($export_name);

  // The @ makes it silent.
  @readfile($export_info['file_name']);

  // Clean up, the @ makes it silent.
  @unlink($export_info['file_name']);

  // Update user last downloaded sid if required.
  if ($export_info['options']['range_type'] != 'range' && $export_info['row_count'] > 0) {

    // Delete existing record.
    db_delete('webform_last_download')
      ->condition('nid', $node->nid)
      ->condition('uid', $user->uid)
      ->execute();

    // Write new record.
    db_insert('webform_last_download')
      ->fields(array(
      'nid' => $node->nid,
      'uid' => $user->uid,
      'sid' => $export_info['last_sid'],
      'requested' => REQUEST_TIME,
    ))
      ->execute();
  }
  exit;
}