You are here

function dba_export_tables in Database Administration 7

Perform an export.

1 string reference to 'dba_export_tables'
dba_menu in ./dba.module
Implements hook_menu().

File

./dba.admin.inc, line 239

Code

function dba_export_tables() {
  if ($tables = _dba_active_tables()) {
    $quantity = count($tables);
    if ($quantity == 1) {
      $filename = reset($tables);
    }
    else {
      $filename = variable_get('dba_default_filename', 'database');
    }
    $all_tables = db_find_tables('%');
    $form['tables'] = array(
      '#type' => 'fieldset',
      '#title' => t('Tables'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['tables']['export_tables'] = array(
      '#type' => 'select',
      '#title' => t('Select one or more tables'),
      '#options' => $all_tables,
      '#default_value' => $tables,
      '#multiple' => TRUE,
      '#required' => TRUE,
    );
    $form['filename'] = array(
      '#type' => 'textfield',
      '#title' => t('Filename'),
      '#default_value' => $filename,
      '#size' => 40,
      '#required' => TRUE,
      '#maxlength' => 255,
      '#description' => t("Please specify the filename you wish to give your database export.  A file extension will automatically be added to your filename based on the format of the export you select.  Once you click 'Export' below your web browser will allow you to save the database export to your local computer."),
    );
    $form['format'] = array(
      '#type' => 'radios',
      '#title' => t('Format'),
      '#options' => array(
        DBA_EXPORT_CSV => t('CSV'),
        DBA_EXPORT_HTML => t('HTML'),
        DBA_EXPORT_MYSQLDUMP => t('mysqldump'),
        DBA_EXPORT_OOCALC => t('OpenOffice Spreadsheet'),
        DBA_EXPORT_OOWRITE => 'OpenOffice Document',
        DBA_EXPORT_MSEXCEL => t('Microsoft Excel'),
        DBA_EXPORT_MSWORD => t('Microsoft Word'),
      ),
      '#default_value' => DBA_EXPORT_CSV,
      '#description' => t("Select the format of your export."),
    );

    // TODO: Only display this option when mysqldump format is selected
    $form['droptable'] = array(
      '#type' => 'checkbox',
      '#title' => t('Add DROP TABLE'),
      '#default_value' => 1,
      '#description' => t('Check this box if you wish to add DROP TABLE IF EXISTS before each table schema in mysqldump formatted exports.  This will allow you to quickly restore from an export without having to manually drop all tables first.'),
    );

    // TODO: Only display this option when CSV format is selected
    $form['header'] = array(
      '#type' => 'checkbox',
      '#title' => t('Include header in export'),
      '#default_value' => 1,
      '#description' => t('Check this box if you wish to include the name of each field as the first row of CSV formatted exports.'),
    );
    $form['tablename'] = array(
      '#type' => 'checkbox',
      '#title' => t('Include table name in export'),
      '#default_value' => 1,
      '#description' => t('Check this box if you wish to include the name of the table before the the first row of HTML, OpenOffice and Microsoft formatted exports.'),
    );
    $form['export'] = array(
      '#type' => 'submit',
      '#value' => t('Export'),
    );
    $form['#redirect'] = 'admin/structure/dba';
    return $form;
  }
  drupal_goto('admin/structure/dba');
}