uc_stock_report()contributions/ubercart/uc_stock/uc_stock.module, line 221
<?php
function uc_stock_report() {
drupal_add_css(drupal_get_path('module', 'uc_stock') .'/uc_stock.css');
$page_size = (!is_null($_GET['nopage'])) ? UC_REPORTS_MAX_RECORDS : variable_get('uc_reports_table_size', 30);
$csv_rows = array();
$rows = array();
$header = array(
array('data' => t('SKU'), 'field' => 'sku', 'sort' => 'asc'),
array('data' => t('Product'), 'field' => 'title'),
array('data' => t('Stock'), 'field' => 'stock'),
array('data' => t('Threshold'), 'field' => 'threshold'),
array('data' => t('Operations')),
);
$csv_rows[] = array(t('SKU'), t('Product'), t('Stock'), t('Threshold'));
$sql = "SELECT s.nid, sku, title, stock, threshold FROM {uc_product_stock} as s LEFT JOIN {node} as n ON s.nid = n.nid WHERE active = 1 AND title <> ''";
if (arg(4) == 'threshold') {
$sql .= ' AND threshold >= stock';
}
$result = pager_query($sql . tablesort_sql($header), $page_size, 0, NULL);
while ($stock = db_fetch_object($result)) {
$op = array();
if (user_access('administer products')) {
$op[] = l(t('edit'), 'node/'. $stock->nid .'/edit/stock', array(), 'destination=admin/store/reports/stock');
}
// Add the data to a table row for display.
$rows[] = array(
'data' => array(
array('data' => $stock->sku),
array('data' => l($stock->title, 'node/'. $stock->nid)),
array('data' => $stock->stock),
array('data' => $stock->threshold),
array('data' => implode(' ', $op)),
),
'class' => ($stock->threshold >= $stock->stock) ? 'uc-stock-below-threshold' : 'uc-stock-above-threshold',
);
// Add the data to the CSV contents for export.
$csv_rows[] = array($stock->sku, $stock->title, $stock->stock, $stock->threshold);
}
$csv_data = uc_reports_store_csv('uc_stock', $csv_rows);
$output = drupal_get_form('uc_stock_report_form')
. theme('table', $header, $rows, array('width' => '100%', 'class' => 'uc-stock-table'))
. theme_pager(NULL, $page_size);
$output .= '<div class="uc-reports-links">'. l(t('Export to CSV file'), 'admin/store/reports/getcsv/'. $csv_data['report'] .'/'. $csv_data['user']) .' '. ((!is_null($_GET['nopage'])) ? l(t('Show paged records'), 'admin/store/reports/stock') : l(t('Show all records'), 'admin/store/reports/stock', array(), 'nopage=1')) .'</div>';
return $output;
}
?>