check_auth('u_item_list');
$filter = "";
if (isset($_GET['filter']))
{
$filter = "item_name like '%" . $db->escape($_GET['filter']) . "%'";
}
//
// Item Values (unique items)
//
if ( (!isset($_GET[URI_PAGE])) || ($_GET[URI_PAGE] == 'values') )
{
$sort_order = array(
0 => array('item_date desc', 'item_date'),
1 => array('item_buyer', 'item_buyer desc'),
2 => array('item_name', 'item_name desc'),
3 => array('raid_name', 'raid_name desc'),
4 => array('item_value desc', 'item_value')
);
$current_order = switch_order($sort_order);
$u_list_items = 'listitems.php'.$SID.'&';
$page_title = sprintf($user->lang['title_prefix'], $eqdkp->config['guildtag'], $eqdkp->config['dkp_name']).': '.$user->lang['listitems_title'];
$total_items = $db->num_rows($db->query('SELECT item_id FROM ' . ITEMS_TABLE . ($filter ? " WHERE $filter" : '') . ' GROUP BY item_name'));
$start = ( isset($_GET['start']) ) ? $_GET['start'] : 0;
// We don't care about history; ignore making the items unique
$s_history = false;
$sql = 'SELECT i.item_id, i.item_name, i.item_buyer, i.item_date, i.raid_id, min(i.item_value) AS item_value, r.raid_name
FROM ' . ITEMS_TABLE . ' i, ' . RAIDS_TABLE . ' r
WHERE i.raid_id = r.raid_id ' . ($filter ? "AND $filter" : '') . '
GROUP BY item_name
ORDER BY '.$current_order['sql']. '
LIMIT '.$start.','.$user->data['user_ilimit'];
$listitems_footcount = sprintf($user->lang['listitems_footcount'], $total_items, $user->data['user_ilimit']);
$pagination = generate_pagination('listitems.php'.$SID.'&o='.$current_order['uri']['current'] . ($filter ? '&filter=' . $_GET['filter'] : ''),
$total_items, $user->data['user_ilimit'], $start);
}
//
// Item Purchase History (all items)
//
elseif ( $_GET[URI_PAGE] == 'history' )
{
$sort_order = array(
0 => array('item_date desc', 'item_date'),
1 => array('item_buyer', 'item_buyer desc'),
2 => array('item_name', 'item_name desc'),
3 => array('raid_name', 'raid_name desc'),
4 => array('item_value desc', 'item_value')
);
$current_order = switch_order($sort_order);
$u_list_items = 'listitems.php'.$SID.'&' . URI_PAGE . '=history&';
$page_title = sprintf($user->lang['title_prefix'], $eqdkp->config['guildtag'], $eqdkp->config['dkp_name']).': '.$user->lang['listpurchased_title'];
$total_items = $db->query_first('SELECT count(*) FROM ' . ITEMS_TABLE . ($filter ? " WHERE $filter" : ''));
$start = ( isset($_GET['start']) ) ? $_GET['start'] : 0;
$s_history = true;
$sql = 'SELECT i.item_id, i.item_name, i.item_buyer, i.item_date, i.raid_id, i.item_value, r.raid_name
FROM ' . ITEMS_TABLE . ' i, ' . RAIDS_TABLE . ' r
WHERE r.raid_id=i.raid_id ' . ($filter ? "AND $filter" : '') . '
ORDER BY '.$current_order['sql']. '
LIMIT '.$start.','.$user->data['user_ilimit'];
$listitems_footcount = sprintf($user->lang['listpurchased_footcount'], $total_items, $user->data['user_ilimit']);
$pagination = generate_pagination('listitems.php'.$SID.'&' . URI_PAGE . '=history&o='.$current_order['uri']['current'] . ($filter ? '&filter=' . $_GET['filter'] : ''),
$total_items, $user->data['user_ilimit'], $start);
}
// Regardless of which listitem page they're on, we're essentially
// outputting the same stuff. Purchase History just has a buyer column.
if ( !($items_result = $db->query($sql)) )
{
message_die('Could not obtain item information', '', __FILE__, __LINE__, $sql);
}
while ( $item = $db->fetch_record($items_result) )
{
$tpl->assign_block_vars('items_row', array(
'ROW_CLASS' => $eqdkp->switch_row_class(),
'DATE' => ( !empty($item['item_date']) ) ? date($user->style['date_notime_short'], $item['item_date']) : ' ',
'BUYER' => ( !empty($item['item_buyer']) ) ? $item['item_buyer'] : '<Not Found>',
'U_VIEW_BUYER' => 'viewmember.php'.$SID.'&' . URI_NAME . '='.$item['item_buyer'],
'NAME' => stripslashes($item['item_name']),
'U_VIEW_ITEM' => 'viewitem.php'.$SID.'&' . URI_ITEM . '='.$item['item_id'],
'RAID' => ( !empty($item['raid_name']) ) ? stripslashes($item['raid_name']) : '<Not Found>',
'U_VIEW_RAID' => 'viewraid.php'.$SID.'&' . URI_RAID . '='.$item['raid_id'],
'VALUE' => $item['item_value'])
);
}
$db->free_result($items_result);
$tpl->assign_vars(array(
'F_ITEMS' => 'listitems.php',
'V_SID' => str_replace('?' . URI_SESSION . '=', '', $SID),
'V_FILTER' => $_GET['filter'],
'L_FILTER' => $user->lang['filter'],
'L_DATE' => $user->lang['date'],
'L_BUYER' => $user->lang['buyer'],
'L_ITEM' => $user->lang['item'],
'L_RAID' => $user->lang['raid'],
'L_VALUE' => $user->lang['value'],
'O_DATE' => $current_order['uri'][0],
'O_BUYER' => $current_order['uri'][1],
'O_NAME' => $current_order['uri'][2],
'O_RAID' => $current_order['uri'][3],
'O_VALUE' => $current_order['uri'][4],
'U_LIST_ITEMS' => $u_list_items,
'START' => $start,
'S_HISTORY' => $s_history,
'LISTITEMS_FOOTCOUNT' => $listitems_footcount,
'ITEM_PAGINATION' => $pagination)
);
$eqdkp->set_vars(array(
'page_title' => $page_title,
'template_file' => 'listitems.html',
'display' => true)
);
?>