function pay_admin_pay_form_list in Pay 6
Same name and namespace in other branches
- 7 includes/pay.admin.inc \pay_admin_pay_form_list()
List payment forms
File
- includes/
pay.admin.inc, line 88 - Administration form settings and related functions.
Code
function pay_admin_pay_form_list($handler = NULL, $uid = NULL) {
$hdrs = array(
array(
'data' => t('Title'),
'field' => 'Title',
),
array(
'data' => t('Owner'),
'field' => 'uid',
),
array(
'data' => t('Handler'),
'field' => 'handler',
),
array(
'data' => t('Status'),
'field' => 'status',
),
array(
'data' => t('Total'),
'field' => 'total',
),
array(
'data' => t('Total paid'),
'field' => 'total_paid',
),
array(),
);
$sql = 'SELECT f.*, SUM(t.total) AS total, SUM(t.total_paid) AS total_paid
FROM {pay_form} f
LEFT JOIN {pay_transaction} t USING ( pfid ) ';
$count_sql = 'SELECT count(pfid) FROM {pay_form} f';
if ($handler) {
$subclasses = array();
foreach (pay_handlers('pay_form') as $name => $info) {
if ($pay_form = pay_form_load($name)) {
if (is_subclass_of($pay_form, $handler)) {
$subclasses[] = $name;
}
}
}
if ($subclasses) {
$subclasses[] = $handler;
$subclasses = "'" . join("', '", $subclasses) . "'";
$sql .= " WHERE f.handler IN (" . $subclasses . ")";
$count_sql .= " WHERE f.handler IN (" . $subclasses . ")";
}
else {
$sql .= " WHERE f.handler = '" . check_plain($handler) . "'";
$count_sql .= " Where f.handler= '" . check_plain($handler) . "'";
}
unset($hdrs[2]);
}
$sql .= ' GROUP BY f.pfid';
$res = pager_query($sql . tablesort_sql($hdrs), 20, 0, $count_sql);
$path = $_GET['q'];
$rows = array();
$pay_forms = array();
while ($data = db_fetch_object($res)) {
$pay_form = pay_form_load($data);
$row = array(
$pay_form
->menu_path() ? l($pay_form
->title(), $pay_form
->menu_path()) : $pay_form
->title(),
theme('username', $pay_form
->user()),
$pay_form
->handler_title(),
$pay_form->status ? t('active') : t('disabled'),
round($data->total),
round($data->total_paid),
l(t('edit'), $path . '/' . $pay_form->pfid . '/edit', array(
'query' => 'destination=' . $path,
)),
);
if ($handler) {
unset($row[2]);
}
$rows[] = $row;
}
if (empty($rows)) {
$rows[] = array();
}
$output = '';
$output .= theme('table', $hdrs, $rows);
$output .= theme('pager');
return $output;
}