You are here

function uc_weightquote_admin_method_edit_form_submit in Ubercart 5

Same name and namespace in other branches
  1. 6.2 shipping/uc_weightquote/uc_weightquote.admin.inc \uc_weightquote_admin_method_edit_form_submit()
  2. 7.3 shipping/uc_weightquote/uc_weightquote.admin.inc \uc_weightquote_admin_method_edit_form_submit()

File

shipping/uc_weightquote/uc_weightquote.module, line 283
Shipping quote module that defines a shipping rate for each product based on weight.

Code

function uc_weightquote_admin_method_edit_form_submit($form_id, $form_values) {
  if ($form_values['op'] == t('Delete')) {
    drupal_goto('admin/store/settings/quotes/methods/weightquote/' . $form_values['mid'] . '/delete');
  }
  if ($form_values['mid']) {
    db_query("UPDATE {uc_weightquote_methods} SET title = '%s', label = '%s', base_rate = %f, unit_rate = %f WHERE mid = %d", $form_values['title'], $form_values['label'], $form_values['base_rate'], $form_values['unit_rate'], $form_values['mid']);
    drupal_set_message("Weight quote shipping method was updated.");
  }
  else {
    $mid = db_next_id("{uc_weightquote_methods}_mid");
    db_query("INSERT INTO {uc_weightquote_methods} (mid, title, label, base_rate, unit_rate) VALUES (%d, '%s', '%s', %f, %f)", $mid, $form_values['title'], $form_values['label'], $form_values['base_rate'], $form_values['unit_rate']);
    $enabled = variable_get('uc_quote_enabled', array());
    $enabled['weightquote_' . $mid] = true;
    variable_set('uc_quote_enabled', $enabled);
    $weight = variable_get('uc_quote_method_weight', array());
    $weight['weightquote_' . $mid] = 0;
    variable_set('uc_quote_method_weight', $weight);
    drupal_set_message("Created and enabled new weight quote shipping method.");
  }
  return 'admin/store/settings/quotes/methods/weightquote';
}