$rate->name))); ctools_include('export'); $code = ctools_export_object('uc_taxes', $rate); return ctools_export_form($form_state, $code, t('Exported code')); } /** * Import tax rate. */ function uc_taxes_import_rates() { $form['machine_name'] = array( '#type' => 'textfield', '#title' => t('Machine name'), '#description' => t('Optional. Use this machine name instead the provided in the import code.'), ); $form['name'] = array( '#type' => 'textfield', '#title' => t('Name'), '#description' => t('Optional. Use this name instead the provided in the import code.'), ); $form['import'] = array( '#type' => 'textarea', '#title' => t('Import code'), '#rows' => 10, '#description' => t('Paste here the code to import. If Name and Machine Name are provided, they will be used overriding values pasted here.'), ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Import'), ); return $form; } /** * Validate tax import. */ function uc_taxes_import_rates_validate($form, &$form_state) { ob_start(); eval($form_state['values']['import']); ob_end_clean(); if (!isset($rate)) { drupal_set_message(t('An error has occured and the tax rate could not be imported.'), 'error'); return; } if (!empty($form_state['values']['machine_name'])) { $rate->machine = $form_state['values']['machine_name']; } if (!empty($form_state['values']['name'])) { $rate->name = $form_state['values']['name']; } if (db_result(db_query("SELECT 1 FROM {exportables} WHERE machine = '%s' AND type = 'uc_taxes'", $rate->machine))) { $place = 'import'; if (!empty($form_state['values']['machine_name'])) { $place = 'machine_name'; } return form_error($form[$place], t('Tax rate names needs to be unique. A tax with the machine name %name already exists.', array('%name' => $rate->machine))); } if (db_result(db_query("SELECT 1 FROM {uc_taxes} WHERE name = '%s'", $rate->name))) { $place = 'import'; if (!empty($form_state['values']['name'])) { $place = 'name'; } return form_error($form[$place], t('Tax rate names needs to be unique. A tax named %name already exists.', array('%name' => $rate->name))); } $form_state['values']['import_parsed'] = $rate; } /** * Submit tax import. */ function uc_taxes_import_rates_submit($form, &$form_state) { uc_taxes_rate_save($form_state['values']['import_parsed']); if ($rate->name) { drupal_set_message(t('Rate %name imported', array('%name' => $rate->name))); } else { drupal_set_message(t('Failed to import the rate.'), 'warning'); } $form_state['redirect'] = 'admin/store/settings/taxes'; }