function dba_export_tables_submit in Database Administration 7
Perform export of one or more tables.
File
- ./
dba.admin.inc, line 312
Code
function dba_export_tables_submit($form, &$form_state) {
// Increase execution time to minimize browser timeouts.
ini_set('max_execution_time', 300);
switch ($form_state['input']['format']) {
case DBA_EXPORT_MYSQLDUMP:
Header("Content-Type: text/plain");
Header("Content-Disposition: attachment; filename=" . $form_state['input']['filename'] . '.sql');
echo "-- Drupal dba.module database dump\n\n";
echo "-- Date: " . format_date(time(), 'large') . "\n\n";
break;
case DBA_EXPORT_CSV:
Header("Content-Type: text/csv");
Header("Content-Disposition: attachment; filename=" . $form_state['input']['filename'] . '.csv');
break;
case DBA_EXPORT_HTML:
Header("Content-Type: text/html; charset=utf-8");
Header("Content-Disposition: attachment; filename=" . $form_state['input']['filename'] . '.html');
echo "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />\r\n</head>\r\n<body>\r\n";
break;
case DBA_EXPORT_OOCALC:
Header("Content-Type: application/vnd.oasis.opendocument.spreadsheet; charset=utf-8");
Header("Content-Disposition: attachment; filename=" . $form_state['input']['filename'] . '.ods');
echo "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />\r\n</head>\r\n<body>\r\n";
break;
case DBA_EXPORT_OOWRITE:
Header("Content-Type: application/vnd.oasis.opendocument.text; charset=utf-8");
Header("Content-Disposition: attachment; filename=" . $form_state['input']['filename'] . '.odt');
echo "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />\r\n</head>\r\n<body>\r\n";
break;
case DBA_EXPORT_MSEXCEL:
Header("Content-Type: application/vnd.ms-excel; charset=utf-8");
Header("Content-Disposition: attachment; filename=" . $form_state['input']['filename'] . '.xls');
echo "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />\r\n</head>\r\n<body>\r\n";
break;
case DBA_EXPORT_MSWORD:
Header("Content-Type: application/msword; charset=utf-8");
Header("Content-Disposition: attachment; filename=" . $form_state['input']['filename'] . '.doc');
echo "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />\r\n</head>\r\n<body>\r\n";
break;
}
// Turn off output buffering to minimize browser timeouts.
while (@ob_end_flush()) {
}
foreach ($form_state['input']['export_tables'] as $table) {
dba_export_table($table, $form_state['input']);
}
switch ($form_state['input']['format']) {
case DBA_EXPORT_HTML:
case DBA_EXPORT_OOCALC:
case DBA_EXPORT_OOWRITE:
case DBA_EXPORT_MSEXCEL:
case DBA_EXPORT_MSWORD:
echo "</body></html>\r\n";
break;
case DBA_EXPORT_MYSQLDUMP:
echo "-- Dump completed on: " . format_date(time(), 'large') . "\n";
break;
}
$table_list = implode(', ', $form_state['input']['export_tables']);
drupal_set_message(t("Saved %tables to %filename.", array(
'%filename' => $form_state['input']['filename'],
'%tables' => $table_list,
)));
unset($_SESSION['dba_tables']);
unset($_SESSION['dba_action']);
exit(0);
// TODO: Redirect and then download...
}