Index: uc_auction.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/uc_auction/uc_auction.module,v retrieving revision 1.1.2.25 diff -u -r1.1.2.25 uc_auction.module --- uc_auction.module 24 Apr 2009 00:06:21 -0000 1.1.2.25 +++ uc_auction.module 3 Jul 2009 13:35:20 -0000 @@ -104,7 +104,7 @@ */ function uc_auction_perm() { - return array('place bid', 'view bids', 'delete bids'); + return array('place bid', 'view bids', 'view own bids', 'delete bids'); } /** @@ -764,6 +764,36 @@ } } +/** + * Implementation of hook_block(). + */ + +function uc_auction_block($op = 'list', $delta = 0, $edit = array()) { + switch($op) { + case 'list': + $block[0]['info'] = t('User bidding history'); + break; + + case 'view': + switch($delta){ + case 0: + global $user; + if ($user->uid == 0 || user_access('view own bids')) { + if (arg(0) == 'node' && is_numeric(arg(1))) { + $node = node_load(array('nid' => arg(1))); + if ($node->uc_auction) { + $block['subject'] = t('Your bidding history for this item'); + $block['content'] = uc_auction_bid_history($node, $user->uid); + } + } + } + break; + } + break; + } + if (isset($block)) { + return $block; + } +} /* drupal_get_form() callbacks ********************************************** */ @@ -1209,35 +1241,60 @@ * A themed table of bids. */ -function uc_auction_bid_history($node) { - $rows = array(); - $del = user_access('delete bids'); - $rez = db_query('SELECT * FROM {uc_auction_bids} WHERE nid = %d', $node->nid); - while ($bid = db_fetch_array($rez)) { - $user = user_load($bid['uid']); - $row = array( - theme('username', $user), - t('@time ago', array('@time' => format_interval(time() - $bid['time'], variable_get('uc_auction_time_gran', 2)))), - uc_currency_format($bid['amount']), - ); - if ($del) { - $row[] = l(t('Delete this and later bids'), "node/{$node->nid}/bids/delete/{$bid['bid']}"); - } - $rows[] = $row; - } - if (count($rows) === 0) { - $rows[] = array( - array( - 'data' => t('No bids have been placed on this product.'), - 'colspan' => 3, - ), - ); - } - $header = array(t('User'), t('Time'), t('Bid')); - if ($del) { - $header[] = t('Delete bids'); - } - return theme('table', $header, $rows); +function uc_auction_bid_history($node, $uid = NULL) { + global $user; + + $rows = array(); + $urow = array(); + $rez = NULL; + $del = user_access('delete bids'); + $sql = 'SELECT * FROM {uc_auction_bids} WHERE nid = %d'; + + // only show bid history by user to admin or user himself + if (isset($uid) && is_numeric($uid) && ($user->uid == 0 || $user->uid == $uid)) { + $sql .= ' AND uid = %d'; + $rez = db_query($sql, $node->nid, $uid); + } + else { + // unset for non-admin or not user himself + unset($uid); + $rez = db_query($sql, $node->nid); + } + + while ($bid = db_fetch_array($rez)) { + if (!isset($uid)) { + $user = user_load($bid['uid']); + $urow = array( + theme('username', $user), + ); + } + $row = $urow + array( + t('@time ago', array('@time' => format_interval(time() - $bid['time'], variable_get('uc_auction_time_gran', 2)))), + uc_currency_format($bid['amount']), + ); + if ($del) { + $row[] = l(t('Delete this and later bids'), "node/{$node->nid}/bids/delete/{$bid['bid']}"); + } + $rows[] = $row; + } + if (count($rows) === 0) { + $rows[] = array( + array( + 'data' => t('No bids have been placed on this product.'), + 'colspan' => 3, + ), + ); + } + if (isset($uid)) { + $header = array(t('Time'), t('Bid')); + } + else { + $header = array(t('User'), t('Time'), t('Bid')); + } + if ($del) { + $header[] = t('Delete bids'); + } + return theme('table', $header, $rows); } /* Permission callbacks ***************************************************** */