You are here

function uc_discounts_admin_generate_codes_form in Ubercart Discounts (Alternative) 7.2

Generate an admin form used to automatically create discount codes.

_state

Parameters

array $form:

int $discount_id:

Return value

string

See also

uc_discounts_admin_generate_codes()

uc_discounts_admin_generate_codes_form_submit()

uc_discounts_admin_generate_codes_form_validate()

1 string reference to 'uc_discounts_admin_generate_codes_form'
uc_discounts_menu in uc_discounts/uc_discounts.module
Implements hook_menu().

File

uc_discounts/uc_discounts.admin.inc, line 1438
Admin forms and functions for uc_discounts module.

Code

function uc_discounts_admin_generate_codes_form($form, &$form_state, $discount_id) {
  $form['about'] = array(
    '#markup' => '<p>' . t('Generate unqiue codes for this discount.  After generating them simply copy and paste them into the Codes textarea for your discount.') . '</p>',
  );
  $form['discount_link'] = array(
    '#markup' => '<p>' . t('Discount') . '#: ' . l($discount_id, 'admin/store/uc_discounts/edit/' . $discount_id) . '</p>',
  );
  $form['num'] = array(
    '#title' => t('Number of codes'),
    '#type' => 'textfield',
    '#default_value' => isset($form_state['values']['num']) ? $form_state['values']['num'] : '',
    '#required' => TRUE,
    '#size' => 5,
  );
  $form['pattern'] = array(
    '#title' => t('Code pattern'),
    '#description' => t('The pattern for generating the codes.  %d will be replaced with a random digit, %s will be replaced with a random letter.'),
    '#default_value' => isset($form_state['values']['pattern']) ? $form_state['values']['pattern'] : 'code%d%s%d',
    '#type' => 'textfield',
    '#required' => TRUE,
    '#size' => 15,
  );
  $form['discount_id'] = array(
    '#type' => 'value',
    '#value' => $discount_id,
  );
  $form['submit'] = array(
    '#value' => t('Generate codes'),
    '#type' => 'submit',
  );
  if (!empty($_SESSION['codes'])) {
    $form['codes'] = array(
      '#markup' => '<p><em>' . t('Copy these codes into the Codes textarea for your discount. Note that this list also contains any existing codes for the discount.') . '</em></p><code class="uc-discounts-generated-codes">' . $_SESSION['codes'] . '</code>',
    );
    unset($_SESSION['codes']);
  }
  return $form;
}