You are here

function uc_importer_export_buffer_form_submit in Ubercart 5

Submit handler for uc_importer_export_buffer_form().

Generate an XML file from the products listed and upload it to the user.

File

uc_importer/uc_importer.module, line 299
XML product importer and exporter.

Code

function uc_importer_export_buffer_form_submit($form_id, $form_values) {
  $item = menu_get_item(menu_get_active_item());

  //drupal_set_message(print_r($form_values, true));
  if ($form_values['op'] == t('Reset')) {
    return $item['path'];
  }
  else {
    $products = array_filter(explode('/', $form_values['products']));

    //drupal_set_message('<pre>'. print_r($products, true) .'</pre>');
    $xml = uc_importer_export($products);
    if ($file = file_save_data($xml, file_directory_temp() . '/uc_export.xml', FILE_EXISTS_REPLACE)) {

      //drupal_set_message(print_r($file, true));
      file_transfer($file, array(
        'Content-Type: application/xml',
        'Content-Length: ' . filesize($file),
        'Content-Disposition: attachment; filename="' . $file . '"',
      ));
    }
  }
}