function uc_coupon_display in Ubercart Discount Coupons 5
Same name and namespace in other branches
- 6 uc_coupon.admin.inc \uc_coupon_display()
- 7.3 uc_coupon.admin.inc \uc_coupon_display()
- 7.2 uc_coupon.admin.inc \uc_coupon_display()
Display a brief over view of system coupons
Parameters
$view_type: pass in an argument to filter out active/inactive coupons
1 string reference to 'uc_coupon_display'
- uc_coupon_menu in ./
uc_coupon.module - Implementation of hook_menu().
File
- ./
uc_coupon.module, line 144 - Provides discount coupons for Ubercart.
Code
function uc_coupon_display($view_type = 'active') {
_uc_coupon_paypal_check();
$header[] = array(
'data' => t('Name'),
'field' => 'name',
);
$header[] = array(
'data' => t('Code'),
'field' => 'code',
'sort' => 'asc',
);
$header[] = array(
'data' => t('Value'),
'field' => 'value',
);
$header[] = array(
'data' => t('Valid from'),
'field' => 'valid_from',
);
$header[] = array(
'data' => t('Valid until'),
'field' => 'valid_until',
);
$header[] = array(
'data' => t('Actions'),
);
$result = pager_query('SELECT cid, name, value, code, type, valid_from, valid_until, bulk, data FROM {uc_coupons} WHERE status = %d' . tablesort_sql($header), 50, 0, NULL, $view_type == 'inactive' ? 0 : 1);
$rows = array();
while ($row = db_fetch_object($result)) {
$data = unserialize($row->data);
$name = $row->name;
if (user_access('view all orders') && $data['order_id']) {
$name .= ' (' . l(t('Order !id', array(
'!id' => $data['order_id'],
)), 'admin/store/orders/' . $data['order_id']) . ')';
}
if ($row->type == 'percentage') {
$value = $row->value . '%';
}
else {
$value = uc_currency_format($row->value);
}
$code = $row->code;
$actions = l(t('edit'), "admin/store/customers/coupon/{$row->cid}/edit");
if ($row->bulk) {
$code .= '* ' . t('(bulk)');
$actions .= ' ' . l(t('codes'), "admin/store/customers/coupon/{$row->cid}/codes");
}
$actions .= ' ' . l(t('delete'), "admin/store/customers/coupon/{$row->cid}/delete");
$valid_from = format_date($row->valid_from, 'custom', variable_get('uc_date_format_default', 'm/d/Y'));
$valid_until = format_date($row->valid_until, 'custom', variable_get('uc_date_format_default', 'm/d/Y'));
$rows[] = array(
$name,
$code,
$value,
$valid_from,
$valid_until,
$actions,
);
}
if (count($rows)) {
$output = theme('table', $header, $rows, array(
'width' => '100%',
));
$output .= theme('pager', NULL, 50);
}
else {
$output = '<p>' . t('There are currently no coupons in the system.') . '</p>';
}
return $output;
}