You are here

function webform_invitation_download_file in Webform Invitation 7

Same name and namespace in other branches
  1. 7.2 webform_invitation.module \webform_invitation_download_file()
1 string reference to 'webform_invitation_download_file'
webform_invitation_menu in ./webform_invitation.module
Implements hook_menu().

File

./webform_invitation.module, line 386

Code

function webform_invitation_download_file($nid) {
  global $base_url;

  //this is the XLS header:
  $xlshead = pack("s*", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);

  //this is the XLS footer:
  $xlsfoot = pack("s*", 0xa, 0x0);
  $codes = db_select('webform_invitation_codes', 'c')
    ->fields('c')
    ->condition('nid', $nid, '=')
    ->execute();
  $node = node_load($nid);
  $data = "";
  $row = 0;
  while ($code = $codes
    ->fetchAssoc()) {
    $data .= webform_invitation_xlsCell($row, 0, $base_url . "/" . drupal_get_path_alias("node/" . $nid) . '?code=' . $code['code']);
    $row++;
  }
  $filename = "codes-" . $nid . ".xls";
  header("Content-Type: application/force-download");
  header("Content-Type: application/octet-stream");
  header("Content-Type: application/download");
  header("Content-Disposition: attachment;filename={$filename}");
  header("Content-Transfer-Encoding: binary ");
  echo $xlshead . $data . $xlsfoot;
  exit;

  //this is important!
}