You are here

function regcode_admin_list_action_export in Registration codes 6

Regcode Action: Exports to CSV

_state

Parameters

array $form:

1 string reference to 'regcode_admin_list_action_export'
regcode_admin_list_getactions in ./regcode.admin.php
Build form elmeents for all of the actions available

File

./regcode.admin.php, line 730
Functions and pages needed for the administration interface for the regcode module.

Code

function regcode_admin_list_action_export() {
  module_load_include('regcode.api', 'regcode', 'php');
  $result = regcode_admin_list_getresource();

  // Write a temporary file
  $filename = file_create_filename('regcode.csv', file_directory_temp());
  $fh = fopen($filename, 'w+');
  fputcsv($fh, array_keys(regcode_get_fields()));
  $i = 0;
  while ($row = db_fetch_array($result)) {
    $i++;
    fputcsv($fh, $row);
  }
  fclose($fh);

  // Output the right headers
  $headers = array(
    'Content-Type: text/csv',
    'Content-Disposition: attachment; filename="regcode.csv"',
  );
  file_transfer($filename, $headers);

  // Export
  drupal_set_message(t('#count records exported.', array(
    '#count' => $i,
  )));
}