You are here

function uc_coupon_display in Ubercart Discount Coupons 7.3

Same name and namespace in other branches
  1. 5 uc_coupon.module \uc_coupon_display()
  2. 6 uc_coupon.admin.inc \uc_coupon_display()
  3. 7.2 uc_coupon.admin.inc \uc_coupon_display()

Display a brief overview of system coupons

Parameters

$view_type: 'active' or 'inactive'

1 string reference to 'uc_coupon_display'
uc_coupon_menu in ./uc_coupon.module
Implements hook_menu().

File

./uc_coupon.admin.inc, line 124
Discount Coupons administration pages.

Code

function uc_coupon_display($view_type = 'active') {
  _uc_coupon_paypal_check();
  $header = array(
    array(
      'data' => t('Actions'),
    ),
    array(
      'data' => t('Name'),
      'field' => 'name',
    ),
    array(
      'data' => t('Code'),
      'field' => 'code',
      'sort' => 'asc',
    ),
    array(
      'data' => t('Value'),
      'field' => 'value',
    ),
    array(
      'data' => t('Created'),
      'field' => 'created',
    ),
    array(
      'data' => t('Valid from'),
      'field' => 'valid_from',
    ),
    array(
      'data' => t('Valid until'),
      'field' => 'valid_until',
    ),
  );
  $query = db_select('uc_coupons', 'c')
    ->extend('TableSort')
    ->extend('PagerDefault')
    ->orderByHeader($header);
  $query
    ->condition('c.status', $view_type == 'inactive' ? 0 : 1)
    ->fields('c');
  $rows = array();
  $result = $query
    ->execute();
  foreach ($result as $coupon) {
    $coupon->data = $coupon->data ? unserialize($coupon->data) : array();
    $rows[] = array(
      theme('uc_coupon_actions', array(
        'coupon' => $coupon,
      )),
      check_plain($coupon->name),
      check_plain($coupon->code) . ($coupon->bulk ? '* ' . t('(bulk)') : ''),
      theme('uc_coupon_discount', array(
        'coupon' => $coupon,
      )),
      _uc_coupon_format_date($coupon->created, variable_get('date_format_uc_store', 'm/d/Y')),
      $coupon->valid_from ? _uc_coupon_format_date($coupon->valid_from, variable_get('date_format_uc_store', 'm/d/Y H:iT')) : '-',
      $coupon->valid_until ? _uc_coupon_format_date($coupon->valid_until, variable_get('date_format_uc_store', 'm/d/Y H:iT')) : '-',
    );
  }
  if (count($rows)) {
    $output = theme('table', array(
      'header' => $header,
      'rows' => $rows,
      'attributes' => array(
        'width' => '100%',
      ),
    ));
    $output .= theme('pager', array(
      'tags' => NULL,
    ));
  }
  else {
    switch ($view_type) {
      case 'active':
        $output = '<p>' . t('There are currently no active coupons in the system.') . '</p>';
        break;
      case 'inactive':
        $output = '<p>' . t('There are currently no inactive coupons in the system.') . '</p>';
        break;
    }
  }
  $output .= '<p>' . l(t('Add a new coupon.'), 'admin/store/coupons/add') . '</p>';
  return $output;
}