You are here

function uc_roles_feature_form_submit in Ubercart 6.2

Same name and namespace in other branches
  1. 5 uc_roles/uc_roles.module \uc_roles_feature_form_submit()
  2. 7.3 uc_roles/uc_roles.module \uc_roles_feature_form_submit()

Submission handler for uc_roles_feature_form().

See also

uc_roles_feature_form()

uc_roles_feature_form_validate()

File

uc_roles/uc_roles.module, line 847

Code

function uc_roles_feature_form_submit($form, &$form_state) {
  $product_role = array(
    'pfid' => isset($form_state['values']['pfid']) ? $form_state['values']['pfid'] : NULL,
    'rpid' => isset($form_state['values']['rpid']) ? $form_state['values']['rpid'] : NULL,
    'nid' => $form_state['values']['nid'],
    'model' => $form_state['values']['uc_roles_model'],
    'rid' => $form_state['values']['uc_roles_role'],
    'duration' => $form_state['values']['uc_roles_expire_relative_granularity'] != 'never' ? $form_state['values']['uc_roles_expire_relative_duration'] : NULL,
    'granularity' => $form_state['values']['uc_roles_expire_relative_granularity'],
    'by_quantity' => $form_state['values']['uc_roles_by_quantity'],
    'shippable' => $form_state['values']['uc_roles_shippable'],
    // We should be setting NULL, but drupal_write_record() ...
    'end_override' => $form_state['values']['end_override'],
    'end_time' => $form_state['values']['expiration'] === 'abs' ? $form_state['values']['uc_roles_expire_absolute'] : NULL,
  );
  $description = empty($product_role['model']) ? t('<strong>SKU:</strong> Any<br />') : t('<strong>SKU:</strong> !sku<br />', array(
    '!sku' => $product_role['model'],
  ));
  $description .= t('<strong>Role:</strong> @role_name<br />', array(
    '@role_name' => _uc_roles_get_name($product_role['rid']),
  ));
  if ($product_role['end_override']) {
    if ($product_role['end_time']) {
      $description .= t('<strong>Expiration:</strong> !date<br />', array(
        '!date' => format_date($product_role['end_time']),
      ));
    }
    else {
      switch ($product_role['granularity']) {
        case 'never':
          $description .= t('<strong>Expiration:</strong> never<br />');
          break;
        case 'day':
          $description .= t('<strong>Expiration:</strong> !qty day(s)<br />', array(
            '!qty' => $product_role['duration'],
          ));
          break;
        case 'week':
          $description .= t('<strong>Expiration:</strong> !qty week(s)<br />', array(
            '!qty' => $product_role['duration'],
          ));
          break;
        case 'month':
          $description .= t('<strong>Expiration:</strong> !qty month(s)<br />', array(
            '!qty' => $product_role['duration'],
          ));
          break;
        case 'year':
          $description .= t('<strong>Expiration:</strong> !qty year(s)<br />', array(
            '!qty' => $product_role['duration'],
          ));
          break;
        default:
          break;
      }
    }
  }
  else {
    $description .= t('<strong>Expiration:</strong> !link (not overridden)<br />', array(
      '!link' => l(t('Global expiration'), 'admin/store/settings/products/edit/features'),
    ));
  }
  $description .= $product_role['shippable'] ? t('<strong>Shippable:</strong> Yes<br />') : t('<strong>Shippable:</strong> No<br />');
  $description .= $product_role['by_quantity'] ? t('<strong>Multiply by quantity:</strong> Yes') : t('<strong>Multiply by quantity:</strong> No');
  $data = array(
    'pfid' => $product_role['pfid'],
    'nid' => $product_role['nid'],
    'fid' => 'role',
    'description' => $description,
  );
  $form_state['redirect'] = uc_product_feature_save($data);

  // Insert or update uc_file_product table
  if (empty($product_role['pfid'])) {
    $product_role['pfid'] = db_last_insert_id('uc_product_features', 'pfid');
  }
  uc_roles_product_write_record($product_role);
}