function tripal_bulk_loader_import_export_template_form_submit

1.x tripal_bulk_loader.admin.templates.inc tripal_bulk_loader_import_export_template_form_submit($form, &$form_state)

Import/Export Template Form Submit

Parameters

$form: The form that was submitted

$form_state: The values and storage that were submitted

Related topics

File

tripal_bulk_loader/includes/tripal_bulk_loader.admin.templates.inc, line 637
All functions in this file pertain to administrative management of bulk loader templates

Code

function tripal_bulk_loader_import_export_template_form_submit($form, &$form_state) {
  switch ($form_state['values']['mode']) {
    case 'export':
      $record = db_fetch_object(db_query("SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d", $form_state['values']['template_id']));
      //$form_state['storage']['template_array'] = $record->template_array;
      $t = var_export(unserialize($record->template_array), TRUE);
      $t = preg_replace("/\n\s+array/", "array", $t); // move array( to previous line
      $t = preg_replace("/true/", "TRUE", $t); // upper case true
      $t = preg_replace("/false/", "FALSE", $t); // upper case false
      $t = preg_replace("/array\(/", "array (", $t); // put a space between array and paren

      $form_state['storage']['template_array'] = $t;
      $form_state['storage']['template_id'] = $form_state['values']['template_id'];
      break;
    case 'import':
      // get the template array, and convert from text into an array.
      $t = array();
      eval("\$t = " . $form_state['values']['template_array'] . ";");
      $record = array(
        'name' => $form_state['values']['new_template_name'],
        'template_array' => serialize($t),
      );
      drupal_write_record('tripal_bulk_loader_template', $record);
      if ($record->template_id) {
        drupal_set_message(t('Successfully imported Tripal Bulk Loader Template.'));
      }
      break;
  }
}